1
22
23 package com.liferay.portlet.softwarecatalog.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
27 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
28 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
29 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
30 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
31 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
32 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.SQLQuery;
37 import com.liferay.portal.kernel.dao.orm.Session;
38 import com.liferay.portal.kernel.dao.orm.Type;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.ListUtil;
41 import com.liferay.portal.kernel.util.OrderByComparator;
42 import com.liferay.portal.kernel.util.StringPool;
43 import com.liferay.portal.kernel.util.StringUtil;
44 import com.liferay.portal.model.ModelListener;
45 import com.liferay.portal.service.persistence.BatchSessionUtil;
46 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47
48 import com.liferay.portlet.softwarecatalog.NoSuchProductVersionException;
49 import com.liferay.portlet.softwarecatalog.model.SCProductVersion;
50 import com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionImpl;
51 import com.liferay.portlet.softwarecatalog.model.impl.SCProductVersionModelImpl;
52
53 import org.apache.commons.logging.Log;
54 import org.apache.commons.logging.LogFactory;
55
56 import java.sql.Types;
57
58 import java.util.ArrayList;
59 import java.util.Collections;
60 import java.util.Iterator;
61 import java.util.List;
62
63
69 public class SCProductVersionPersistenceImpl extends BasePersistenceImpl
70 implements SCProductVersionPersistence {
71 public SCProductVersion create(long productVersionId) {
72 SCProductVersion scProductVersion = new SCProductVersionImpl();
73
74 scProductVersion.setNew(true);
75 scProductVersion.setPrimaryKey(productVersionId);
76
77 return scProductVersion;
78 }
79
80 public SCProductVersion remove(long productVersionId)
81 throws NoSuchProductVersionException, SystemException {
82 Session session = null;
83
84 try {
85 session = openSession();
86
87 SCProductVersion scProductVersion = (SCProductVersion)session.get(SCProductVersionImpl.class,
88 new Long(productVersionId));
89
90 if (scProductVersion == null) {
91 if (_log.isWarnEnabled()) {
92 _log.warn(
93 "No SCProductVersion exists with the primary key " +
94 productVersionId);
95 }
96
97 throw new NoSuchProductVersionException(
98 "No SCProductVersion exists with the primary key " +
99 productVersionId);
100 }
101
102 return remove(scProductVersion);
103 }
104 catch (NoSuchProductVersionException nsee) {
105 throw nsee;
106 }
107 catch (Exception e) {
108 throw processException(e);
109 }
110 finally {
111 closeSession(session);
112 }
113 }
114
115 public SCProductVersion remove(SCProductVersion scProductVersion)
116 throws SystemException {
117 if (_listeners.length > 0) {
118 for (ModelListener listener : _listeners) {
119 listener.onBeforeRemove(scProductVersion);
120 }
121 }
122
123 scProductVersion = removeImpl(scProductVersion);
124
125 if (_listeners.length > 0) {
126 for (ModelListener listener : _listeners) {
127 listener.onAfterRemove(scProductVersion);
128 }
129 }
130
131 return scProductVersion;
132 }
133
134 protected SCProductVersion removeImpl(SCProductVersion scProductVersion)
135 throws SystemException {
136 try {
137 clearSCFrameworkVersions.clear(scProductVersion.getPrimaryKey());
138 }
139 catch (Exception e) {
140 throw processException(e);
141 }
142 finally {
143 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
144 }
145
146 Session session = null;
147
148 try {
149 session = openSession();
150
151 if (BatchSessionUtil.isEnabled()) {
152 Object staleObject = session.get(SCProductVersionImpl.class,
153 scProductVersion.getPrimaryKeyObj());
154
155 if (staleObject != null) {
156 session.evict(staleObject);
157 }
158 }
159
160 session.delete(scProductVersion);
161
162 session.flush();
163
164 return scProductVersion;
165 }
166 catch (Exception e) {
167 throw processException(e);
168 }
169 finally {
170 closeSession(session);
171
172 FinderCacheUtil.clearCache(SCProductVersion.class.getName());
173 }
174 }
175
176
179 public SCProductVersion update(SCProductVersion scProductVersion)
180 throws SystemException {
181 if (_log.isWarnEnabled()) {
182 _log.warn(
183 "Using the deprecated update(SCProductVersion scProductVersion) method. Use update(SCProductVersion scProductVersion, boolean merge) instead.");
184 }
185
186 return update(scProductVersion, false);
187 }
188
189
202 public SCProductVersion update(SCProductVersion scProductVersion,
203 boolean merge) throws SystemException {
204 boolean isNew = scProductVersion.isNew();
205
206 if (_listeners.length > 0) {
207 for (ModelListener listener : _listeners) {
208 if (isNew) {
209 listener.onBeforeCreate(scProductVersion);
210 }
211 else {
212 listener.onBeforeUpdate(scProductVersion);
213 }
214 }
215 }
216
217 scProductVersion = updateImpl(scProductVersion, merge);
218
219 if (_listeners.length > 0) {
220 for (ModelListener listener : _listeners) {
221 if (isNew) {
222 listener.onAfterCreate(scProductVersion);
223 }
224 else {
225 listener.onAfterUpdate(scProductVersion);
226 }
227 }
228 }
229
230 return scProductVersion;
231 }
232
233 public SCProductVersion updateImpl(
234 com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion,
235 boolean merge) throws SystemException {
236 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
237
238 Session session = null;
239
240 try {
241 session = openSession();
242
243 BatchSessionUtil.update(session, scProductVersion, merge);
244
245 scProductVersion.setNew(false);
246
247 return scProductVersion;
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254
255 FinderCacheUtil.clearCache(SCProductVersion.class.getName());
256 }
257 }
258
259 public SCProductVersion findByPrimaryKey(long productVersionId)
260 throws NoSuchProductVersionException, SystemException {
261 SCProductVersion scProductVersion = fetchByPrimaryKey(productVersionId);
262
263 if (scProductVersion == null) {
264 if (_log.isWarnEnabled()) {
265 _log.warn("No SCProductVersion exists with the primary key " +
266 productVersionId);
267 }
268
269 throw new NoSuchProductVersionException(
270 "No SCProductVersion exists with the primary key " +
271 productVersionId);
272 }
273
274 return scProductVersion;
275 }
276
277 public SCProductVersion fetchByPrimaryKey(long productVersionId)
278 throws SystemException {
279 Session session = null;
280
281 try {
282 session = openSession();
283
284 return (SCProductVersion)session.get(SCProductVersionImpl.class,
285 new Long(productVersionId));
286 }
287 catch (Exception e) {
288 throw processException(e);
289 }
290 finally {
291 closeSession(session);
292 }
293 }
294
295 public List<SCProductVersion> findByProductEntryId(long productEntryId)
296 throws SystemException {
297 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
298 String finderClassName = SCProductVersion.class.getName();
299 String finderMethodName = "findByProductEntryId";
300 String[] finderParams = new String[] { Long.class.getName() };
301 Object[] finderArgs = new Object[] { new Long(productEntryId) };
302
303 Object result = null;
304
305 if (finderClassNameCacheEnabled) {
306 result = FinderCacheUtil.getResult(finderClassName,
307 finderMethodName, finderParams, finderArgs, this);
308 }
309
310 if (result == null) {
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 StringBuilder query = new StringBuilder();
317
318 query.append(
319 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
320
321 query.append("productEntryId = ?");
322
323 query.append(" ");
324
325 query.append("ORDER BY ");
326
327 query.append("createDate DESC");
328
329 Query q = session.createQuery(query.toString());
330
331 QueryPos qPos = QueryPos.getInstance(q);
332
333 qPos.add(productEntryId);
334
335 List<SCProductVersion> list = q.list();
336
337 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
338 finderClassName, finderMethodName, finderParams,
339 finderArgs, list);
340
341 return list;
342 }
343 catch (Exception e) {
344 throw processException(e);
345 }
346 finally {
347 closeSession(session);
348 }
349 }
350 else {
351 return (List<SCProductVersion>)result;
352 }
353 }
354
355 public List<SCProductVersion> findByProductEntryId(long productEntryId,
356 int start, int end) throws SystemException {
357 return findByProductEntryId(productEntryId, start, end, null);
358 }
359
360 public List<SCProductVersion> findByProductEntryId(long productEntryId,
361 int start, int end, OrderByComparator obc) throws SystemException {
362 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
363 String finderClassName = SCProductVersion.class.getName();
364 String finderMethodName = "findByProductEntryId";
365 String[] finderParams = new String[] {
366 Long.class.getName(),
367
368 "java.lang.Integer", "java.lang.Integer",
369 "com.liferay.portal.kernel.util.OrderByComparator"
370 };
371 Object[] finderArgs = new Object[] {
372 new Long(productEntryId),
373
374 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
375 };
376
377 Object result = null;
378
379 if (finderClassNameCacheEnabled) {
380 result = FinderCacheUtil.getResult(finderClassName,
381 finderMethodName, finderParams, finderArgs, this);
382 }
383
384 if (result == null) {
385 Session session = null;
386
387 try {
388 session = openSession();
389
390 StringBuilder query = new StringBuilder();
391
392 query.append(
393 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
394
395 query.append("productEntryId = ?");
396
397 query.append(" ");
398
399 if (obc != null) {
400 query.append("ORDER BY ");
401 query.append(obc.getOrderBy());
402 }
403
404 else {
405 query.append("ORDER BY ");
406
407 query.append("createDate DESC");
408 }
409
410 Query q = session.createQuery(query.toString());
411
412 QueryPos qPos = QueryPos.getInstance(q);
413
414 qPos.add(productEntryId);
415
416 List<SCProductVersion> list = (List<SCProductVersion>)QueryUtil.list(q,
417 getDialect(), start, end);
418
419 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
420 finderClassName, finderMethodName, finderParams,
421 finderArgs, list);
422
423 return list;
424 }
425 catch (Exception e) {
426 throw processException(e);
427 }
428 finally {
429 closeSession(session);
430 }
431 }
432 else {
433 return (List<SCProductVersion>)result;
434 }
435 }
436
437 public SCProductVersion findByProductEntryId_First(long productEntryId,
438 OrderByComparator obc)
439 throws NoSuchProductVersionException, SystemException {
440 List<SCProductVersion> list = findByProductEntryId(productEntryId, 0,
441 1, obc);
442
443 if (list.size() == 0) {
444 StringBuilder msg = new StringBuilder();
445
446 msg.append("No SCProductVersion exists with the key {");
447
448 msg.append("productEntryId=" + productEntryId);
449
450 msg.append(StringPool.CLOSE_CURLY_BRACE);
451
452 throw new NoSuchProductVersionException(msg.toString());
453 }
454 else {
455 return list.get(0);
456 }
457 }
458
459 public SCProductVersion findByProductEntryId_Last(long productEntryId,
460 OrderByComparator obc)
461 throws NoSuchProductVersionException, SystemException {
462 int count = countByProductEntryId(productEntryId);
463
464 List<SCProductVersion> list = findByProductEntryId(productEntryId,
465 count - 1, count, obc);
466
467 if (list.size() == 0) {
468 StringBuilder msg = new StringBuilder();
469
470 msg.append("No SCProductVersion exists with the key {");
471
472 msg.append("productEntryId=" + productEntryId);
473
474 msg.append(StringPool.CLOSE_CURLY_BRACE);
475
476 throw new NoSuchProductVersionException(msg.toString());
477 }
478 else {
479 return list.get(0);
480 }
481 }
482
483 public SCProductVersion[] findByProductEntryId_PrevAndNext(
484 long productVersionId, long productEntryId, OrderByComparator obc)
485 throws NoSuchProductVersionException, SystemException {
486 SCProductVersion scProductVersion = findByPrimaryKey(productVersionId);
487
488 int count = countByProductEntryId(productEntryId);
489
490 Session session = null;
491
492 try {
493 session = openSession();
494
495 StringBuilder query = new StringBuilder();
496
497 query.append(
498 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
499
500 query.append("productEntryId = ?");
501
502 query.append(" ");
503
504 if (obc != null) {
505 query.append("ORDER BY ");
506 query.append(obc.getOrderBy());
507 }
508
509 else {
510 query.append("ORDER BY ");
511
512 query.append("createDate DESC");
513 }
514
515 Query q = session.createQuery(query.toString());
516
517 QueryPos qPos = QueryPos.getInstance(q);
518
519 qPos.add(productEntryId);
520
521 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
522 scProductVersion);
523
524 SCProductVersion[] array = new SCProductVersionImpl[3];
525
526 array[0] = (SCProductVersion)objArray[0];
527 array[1] = (SCProductVersion)objArray[1];
528 array[2] = (SCProductVersion)objArray[2];
529
530 return array;
531 }
532 catch (Exception e) {
533 throw processException(e);
534 }
535 finally {
536 closeSession(session);
537 }
538 }
539
540 public SCProductVersion findByDirectDownloadURL(String directDownloadURL)
541 throws NoSuchProductVersionException, SystemException {
542 SCProductVersion scProductVersion = fetchByDirectDownloadURL(directDownloadURL);
543
544 if (scProductVersion == null) {
545 StringBuilder msg = new StringBuilder();
546
547 msg.append("No SCProductVersion exists with the key {");
548
549 msg.append("directDownloadURL=" + directDownloadURL);
550
551 msg.append(StringPool.CLOSE_CURLY_BRACE);
552
553 if (_log.isWarnEnabled()) {
554 _log.warn(msg.toString());
555 }
556
557 throw new NoSuchProductVersionException(msg.toString());
558 }
559
560 return scProductVersion;
561 }
562
563 public SCProductVersion fetchByDirectDownloadURL(String directDownloadURL)
564 throws SystemException {
565 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
566 String finderClassName = SCProductVersion.class.getName();
567 String finderMethodName = "fetchByDirectDownloadURL";
568 String[] finderParams = new String[] { String.class.getName() };
569 Object[] finderArgs = new Object[] { directDownloadURL };
570
571 Object result = null;
572
573 if (finderClassNameCacheEnabled) {
574 result = FinderCacheUtil.getResult(finderClassName,
575 finderMethodName, finderParams, finderArgs, this);
576 }
577
578 if (result == null) {
579 Session session = null;
580
581 try {
582 session = openSession();
583
584 StringBuilder query = new StringBuilder();
585
586 query.append(
587 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
588
589 if (directDownloadURL == null) {
590 query.append("directDownloadURL IS NULL");
591 }
592 else {
593 query.append("lower(directDownloadURL) = ?");
594 }
595
596 query.append(" ");
597
598 query.append("ORDER BY ");
599
600 query.append("createDate DESC");
601
602 Query q = session.createQuery(query.toString());
603
604 QueryPos qPos = QueryPos.getInstance(q);
605
606 if (directDownloadURL != null) {
607 qPos.add(directDownloadURL);
608 }
609
610 List<SCProductVersion> list = q.list();
611
612 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
613 finderClassName, finderMethodName, finderParams,
614 finderArgs, list);
615
616 if (list.size() == 0) {
617 return null;
618 }
619 else {
620 return list.get(0);
621 }
622 }
623 catch (Exception e) {
624 throw processException(e);
625 }
626 finally {
627 closeSession(session);
628 }
629 }
630 else {
631 List<SCProductVersion> list = (List<SCProductVersion>)result;
632
633 if (list.size() == 0) {
634 return null;
635 }
636 else {
637 return list.get(0);
638 }
639 }
640 }
641
642 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
643 throws SystemException {
644 Session session = null;
645
646 try {
647 session = openSession();
648
649 dynamicQuery.compile(session);
650
651 return dynamicQuery.list();
652 }
653 catch (Exception e) {
654 throw processException(e);
655 }
656 finally {
657 closeSession(session);
658 }
659 }
660
661 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
662 int start, int end) throws SystemException {
663 Session session = null;
664
665 try {
666 session = openSession();
667
668 dynamicQuery.setLimit(start, end);
669
670 dynamicQuery.compile(session);
671
672 return dynamicQuery.list();
673 }
674 catch (Exception e) {
675 throw processException(e);
676 }
677 finally {
678 closeSession(session);
679 }
680 }
681
682 public List<SCProductVersion> findAll() throws SystemException {
683 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
684 }
685
686 public List<SCProductVersion> findAll(int start, int end)
687 throws SystemException {
688 return findAll(start, end, null);
689 }
690
691 public List<SCProductVersion> findAll(int start, int end,
692 OrderByComparator obc) throws SystemException {
693 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
694 String finderClassName = SCProductVersion.class.getName();
695 String finderMethodName = "findAll";
696 String[] finderParams = new String[] {
697 "java.lang.Integer", "java.lang.Integer",
698 "com.liferay.portal.kernel.util.OrderByComparator"
699 };
700 Object[] finderArgs = new Object[] {
701 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
702 };
703
704 Object result = null;
705
706 if (finderClassNameCacheEnabled) {
707 result = FinderCacheUtil.getResult(finderClassName,
708 finderMethodName, finderParams, finderArgs, this);
709 }
710
711 if (result == null) {
712 Session session = null;
713
714 try {
715 session = openSession();
716
717 StringBuilder query = new StringBuilder();
718
719 query.append(
720 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion ");
721
722 if (obc != null) {
723 query.append("ORDER BY ");
724 query.append(obc.getOrderBy());
725 }
726
727 else {
728 query.append("ORDER BY ");
729
730 query.append("createDate DESC");
731 }
732
733 Query q = session.createQuery(query.toString());
734
735 List<SCProductVersion> list = null;
736
737 if (obc == null) {
738 list = (List<SCProductVersion>)QueryUtil.list(q,
739 getDialect(), start, end, false);
740
741 Collections.sort(list);
742 }
743 else {
744 list = (List<SCProductVersion>)QueryUtil.list(q,
745 getDialect(), start, end);
746 }
747
748 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
749 finderClassName, finderMethodName, finderParams,
750 finderArgs, list);
751
752 return list;
753 }
754 catch (Exception e) {
755 throw processException(e);
756 }
757 finally {
758 closeSession(session);
759 }
760 }
761 else {
762 return (List<SCProductVersion>)result;
763 }
764 }
765
766 public void removeByProductEntryId(long productEntryId)
767 throws SystemException {
768 for (SCProductVersion scProductVersion : findByProductEntryId(
769 productEntryId)) {
770 remove(scProductVersion);
771 }
772 }
773
774 public void removeByDirectDownloadURL(String directDownloadURL)
775 throws NoSuchProductVersionException, SystemException {
776 SCProductVersion scProductVersion = findByDirectDownloadURL(directDownloadURL);
777
778 remove(scProductVersion);
779 }
780
781 public void removeAll() throws SystemException {
782 for (SCProductVersion scProductVersion : findAll()) {
783 remove(scProductVersion);
784 }
785 }
786
787 public int countByProductEntryId(long productEntryId)
788 throws SystemException {
789 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
790 String finderClassName = SCProductVersion.class.getName();
791 String finderMethodName = "countByProductEntryId";
792 String[] finderParams = new String[] { Long.class.getName() };
793 Object[] finderArgs = new Object[] { new Long(productEntryId) };
794
795 Object result = null;
796
797 if (finderClassNameCacheEnabled) {
798 result = FinderCacheUtil.getResult(finderClassName,
799 finderMethodName, finderParams, finderArgs, this);
800 }
801
802 if (result == null) {
803 Session session = null;
804
805 try {
806 session = openSession();
807
808 StringBuilder query = new StringBuilder();
809
810 query.append("SELECT COUNT(*) ");
811 query.append(
812 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
813
814 query.append("productEntryId = ?");
815
816 query.append(" ");
817
818 Query q = session.createQuery(query.toString());
819
820 QueryPos qPos = QueryPos.getInstance(q);
821
822 qPos.add(productEntryId);
823
824 Long count = null;
825
826 Iterator<Long> itr = q.list().iterator();
827
828 if (itr.hasNext()) {
829 count = itr.next();
830 }
831
832 if (count == null) {
833 count = new Long(0);
834 }
835
836 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
837 finderClassName, finderMethodName, finderParams,
838 finderArgs, count);
839
840 return count.intValue();
841 }
842 catch (Exception e) {
843 throw processException(e);
844 }
845 finally {
846 closeSession(session);
847 }
848 }
849 else {
850 return ((Long)result).intValue();
851 }
852 }
853
854 public int countByDirectDownloadURL(String directDownloadURL)
855 throws SystemException {
856 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
857 String finderClassName = SCProductVersion.class.getName();
858 String finderMethodName = "countByDirectDownloadURL";
859 String[] finderParams = new String[] { String.class.getName() };
860 Object[] finderArgs = new Object[] { directDownloadURL };
861
862 Object result = null;
863
864 if (finderClassNameCacheEnabled) {
865 result = FinderCacheUtil.getResult(finderClassName,
866 finderMethodName, finderParams, finderArgs, this);
867 }
868
869 if (result == null) {
870 Session session = null;
871
872 try {
873 session = openSession();
874
875 StringBuilder query = new StringBuilder();
876
877 query.append("SELECT COUNT(*) ");
878 query.append(
879 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
880
881 if (directDownloadURL == null) {
882 query.append("directDownloadURL IS NULL");
883 }
884 else {
885 query.append("lower(directDownloadURL) = ?");
886 }
887
888 query.append(" ");
889
890 Query q = session.createQuery(query.toString());
891
892 QueryPos qPos = QueryPos.getInstance(q);
893
894 if (directDownloadURL != null) {
895 qPos.add(directDownloadURL);
896 }
897
898 Long count = null;
899
900 Iterator<Long> itr = q.list().iterator();
901
902 if (itr.hasNext()) {
903 count = itr.next();
904 }
905
906 if (count == null) {
907 count = new Long(0);
908 }
909
910 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
911 finderClassName, finderMethodName, finderParams,
912 finderArgs, count);
913
914 return count.intValue();
915 }
916 catch (Exception e) {
917 throw processException(e);
918 }
919 finally {
920 closeSession(session);
921 }
922 }
923 else {
924 return ((Long)result).intValue();
925 }
926 }
927
928 public int countAll() throws SystemException {
929 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
930 String finderClassName = SCProductVersion.class.getName();
931 String finderMethodName = "countAll";
932 String[] finderParams = new String[] { };
933 Object[] finderArgs = new Object[] { };
934
935 Object result = null;
936
937 if (finderClassNameCacheEnabled) {
938 result = FinderCacheUtil.getResult(finderClassName,
939 finderMethodName, finderParams, finderArgs, this);
940 }
941
942 if (result == null) {
943 Session session = null;
944
945 try {
946 session = openSession();
947
948 Query q = session.createQuery(
949 "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion");
950
951 Long count = null;
952
953 Iterator<Long> itr = q.list().iterator();
954
955 if (itr.hasNext()) {
956 count = itr.next();
957 }
958
959 if (count == null) {
960 count = new Long(0);
961 }
962
963 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
964 finderClassName, finderMethodName, finderParams,
965 finderArgs, count);
966
967 return count.intValue();
968 }
969 catch (Exception e) {
970 throw processException(e);
971 }
972 finally {
973 closeSession(session);
974 }
975 }
976 else {
977 return ((Long)result).intValue();
978 }
979 }
980
981 public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
982 long pk) throws SystemException {
983 return getSCFrameworkVersions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
984 }
985
986 public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
987 long pk, int start, int end) throws SystemException {
988 return getSCFrameworkVersions(pk, start, end, null);
989 }
990
991 public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
992 long pk, int start, int end, OrderByComparator obc)
993 throws SystemException {
994 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
995
996 String finderClassName = "SCFrameworkVersi_SCProductVers";
997
998 String finderMethodName = "getSCFrameworkVersions";
999 String[] finderParams = new String[] {
1000 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1001 "com.liferay.portal.kernel.util.OrderByComparator"
1002 };
1003 Object[] finderArgs = new Object[] {
1004 new Long(pk), String.valueOf(start), String.valueOf(end),
1005 String.valueOf(obc)
1006 };
1007
1008 Object result = null;
1009
1010 if (finderClassNameCacheEnabled) {
1011 result = FinderCacheUtil.getResult(finderClassName,
1012 finderMethodName, finderParams, finderArgs, this);
1013 }
1014
1015 if (result == null) {
1016 Session session = null;
1017
1018 try {
1019 session = openSession();
1020
1021 StringBuilder sb = new StringBuilder();
1022
1023 sb.append(_SQL_GETSCFRAMEWORKVERSIONS);
1024
1025 if (obc != null) {
1026 sb.append("ORDER BY ");
1027 sb.append(obc.getOrderBy());
1028 }
1029
1030 else {
1031 sb.append("ORDER BY ");
1032
1033 sb.append("SCFrameworkVersion.name DESC");
1034 }
1035
1036 String sql = sb.toString();
1037
1038 SQLQuery q = session.createSQLQuery(sql);
1039
1040 q.addEntity("SCFrameworkVersion",
1041 com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionImpl.class);
1042
1043 QueryPos qPos = QueryPos.getInstance(q);
1044
1045 qPos.add(pk);
1046
1047 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> list =
1048 (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)QueryUtil.list(q,
1049 getDialect(), start, end);
1050
1051 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1052 finderClassName, finderMethodName, finderParams,
1053 finderArgs, list);
1054
1055 return list;
1056 }
1057 catch (Exception e) {
1058 throw processException(e);
1059 }
1060 finally {
1061 closeSession(session);
1062 }
1063 }
1064 else {
1065 return (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)result;
1066 }
1067 }
1068
1069 public int getSCFrameworkVersionsSize(long pk) throws SystemException {
1070 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1071
1072 String finderClassName = "SCFrameworkVersi_SCProductVers";
1073
1074 String finderMethodName = "getSCFrameworkVersionsSize";
1075 String[] finderParams = new String[] { Long.class.getName() };
1076 Object[] finderArgs = new Object[] { new Long(pk) };
1077
1078 Object result = null;
1079
1080 if (finderClassNameCacheEnabled) {
1081 result = FinderCacheUtil.getResult(finderClassName,
1082 finderMethodName, finderParams, finderArgs, this);
1083 }
1084
1085 if (result == null) {
1086 Session session = null;
1087
1088 try {
1089 session = openSession();
1090
1091 SQLQuery q = session.createSQLQuery(_SQL_GETSCFRAMEWORKVERSIONSSIZE);
1092
1093 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1094
1095 QueryPos qPos = QueryPos.getInstance(q);
1096
1097 qPos.add(pk);
1098
1099 Long count = null;
1100
1101 Iterator<Long> itr = q.list().iterator();
1102
1103 if (itr.hasNext()) {
1104 count = itr.next();
1105 }
1106
1107 if (count == null) {
1108 count = new Long(0);
1109 }
1110
1111 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1112 finderClassName, finderMethodName, finderParams,
1113 finderArgs, count);
1114
1115 return count.intValue();
1116 }
1117 catch (Exception e) {
1118 throw processException(e);
1119 }
1120 finally {
1121 closeSession(session);
1122 }
1123 }
1124 else {
1125 return ((Long)result).intValue();
1126 }
1127 }
1128
1129 public boolean containsSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1130 throws SystemException {
1131 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1132
1133 String finderClassName = "SCFrameworkVersi_SCProductVers";
1134
1135 String finderMethodName = "containsSCFrameworkVersions";
1136 String[] finderParams = new String[] {
1137 Long.class.getName(),
1138
1139 Long.class.getName()
1140 };
1141 Object[] finderArgs = new Object[] {
1142 new Long(pk),
1143
1144 new Long(scFrameworkVersionPK)
1145 };
1146
1147 Object result = null;
1148
1149 if (finderClassNameCacheEnabled) {
1150 result = FinderCacheUtil.getResult(finderClassName,
1151 finderMethodName, finderParams, finderArgs, this);
1152 }
1153
1154 if (result == null) {
1155 try {
1156 Boolean value = Boolean.valueOf(containsSCFrameworkVersion.contains(
1157 pk, scFrameworkVersionPK));
1158
1159 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1160 finderClassName, finderMethodName, finderParams,
1161 finderArgs, value);
1162
1163 return value.booleanValue();
1164 }
1165 catch (Exception e) {
1166 throw processException(e);
1167 }
1168 }
1169 else {
1170 return ((Boolean)result).booleanValue();
1171 }
1172 }
1173
1174 public boolean containsSCFrameworkVersions(long pk)
1175 throws SystemException {
1176 if (getSCFrameworkVersionsSize(pk) > 0) {
1177 return true;
1178 }
1179 else {
1180 return false;
1181 }
1182 }
1183
1184 public void addSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1185 throws SystemException {
1186 try {
1187 addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1188 }
1189 catch (Exception e) {
1190 throw processException(e);
1191 }
1192 finally {
1193 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1194 }
1195 }
1196
1197 public void addSCFrameworkVersion(long pk,
1198 com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1199 throws SystemException {
1200 try {
1201 addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1202 }
1203 catch (Exception e) {
1204 throw processException(e);
1205 }
1206 finally {
1207 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1208 }
1209 }
1210
1211 public void addSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1212 throws SystemException {
1213 try {
1214 for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1215 addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1216 }
1217 }
1218 catch (Exception e) {
1219 throw processException(e);
1220 }
1221 finally {
1222 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1223 }
1224 }
1225
1226 public void addSCFrameworkVersions(long pk,
1227 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1228 throws SystemException {
1229 try {
1230 for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1231 addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1232 }
1233 }
1234 catch (Exception e) {
1235 throw processException(e);
1236 }
1237 finally {
1238 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1239 }
1240 }
1241
1242 public void clearSCFrameworkVersions(long pk) throws SystemException {
1243 try {
1244 clearSCFrameworkVersions.clear(pk);
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1251 }
1252 }
1253
1254 public void removeSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1255 throws SystemException {
1256 try {
1257 removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1258 }
1259 catch (Exception e) {
1260 throw processException(e);
1261 }
1262 finally {
1263 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1264 }
1265 }
1266
1267 public void removeSCFrameworkVersion(long pk,
1268 com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1269 throws SystemException {
1270 try {
1271 removeSCFrameworkVersion.remove(pk,
1272 scFrameworkVersion.getPrimaryKey());
1273 }
1274 catch (Exception e) {
1275 throw processException(e);
1276 }
1277 finally {
1278 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1279 }
1280 }
1281
1282 public void removeSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1283 throws SystemException {
1284 try {
1285 for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1286 removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1287 }
1288 }
1289 catch (Exception e) {
1290 throw processException(e);
1291 }
1292 finally {
1293 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1294 }
1295 }
1296
1297 public void removeSCFrameworkVersions(long pk,
1298 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1299 throws SystemException {
1300 try {
1301 for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1302 removeSCFrameworkVersion.remove(pk,
1303 scFrameworkVersion.getPrimaryKey());
1304 }
1305 }
1306 catch (Exception e) {
1307 throw processException(e);
1308 }
1309 finally {
1310 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1311 }
1312 }
1313
1314 public void setSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1315 throws SystemException {
1316 try {
1317 clearSCFrameworkVersions.clear(pk);
1318
1319 for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1320 addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1321 }
1322 }
1323 catch (Exception e) {
1324 throw processException(e);
1325 }
1326 finally {
1327 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1328 }
1329 }
1330
1331 public void setSCFrameworkVersions(long pk,
1332 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1333 throws SystemException {
1334 try {
1335 clearSCFrameworkVersions.clear(pk);
1336
1337 for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1338 addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1339 }
1340 }
1341 catch (Exception e) {
1342 throw processException(e);
1343 }
1344 finally {
1345 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1346 }
1347 }
1348
1349 public void registerListener(ModelListener listener) {
1350 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1351
1352 listeners.add(listener);
1353
1354 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1355 }
1356
1357 public void unregisterListener(ModelListener listener) {
1358 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1359
1360 listeners.remove(listener);
1361
1362 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1363 }
1364
1365 public void afterPropertiesSet() {
1366 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1367 com.liferay.portal.util.PropsUtil.get(
1368 "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductVersion")));
1369
1370 if (listenerClassNames.length > 0) {
1371 try {
1372 List<ModelListener> listeners = new ArrayList<ModelListener>();
1373
1374 for (String listenerClassName : listenerClassNames) {
1375 listeners.add((ModelListener)Class.forName(
1376 listenerClassName).newInstance());
1377 }
1378
1379 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1380 }
1381 catch (Exception e) {
1382 _log.error(e);
1383 }
1384 }
1385
1386 containsSCFrameworkVersion = new ContainsSCFrameworkVersion(this);
1387
1388 addSCFrameworkVersion = new AddSCFrameworkVersion(this);
1389 clearSCFrameworkVersions = new ClearSCFrameworkVersions(this);
1390 removeSCFrameworkVersion = new RemoveSCFrameworkVersion(this);
1391 }
1392
1393 protected ContainsSCFrameworkVersion containsSCFrameworkVersion;
1394 protected AddSCFrameworkVersion addSCFrameworkVersion;
1395 protected ClearSCFrameworkVersions clearSCFrameworkVersions;
1396 protected RemoveSCFrameworkVersion removeSCFrameworkVersion;
1397
1398 protected class ContainsSCFrameworkVersion {
1399 protected ContainsSCFrameworkVersion(
1400 SCProductVersionPersistenceImpl persistenceImpl) {
1401 super();
1402
1403 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1404 _SQL_CONTAINSSCFRAMEWORKVERSION,
1405 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1406 }
1407
1408 protected boolean contains(long productVersionId,
1409 long frameworkVersionId) {
1410 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1411 new Long(productVersionId), new Long(frameworkVersionId)
1412 });
1413
1414 if (results.size() > 0) {
1415 Integer count = results.get(0);
1416
1417 if (count.intValue() > 0) {
1418 return true;
1419 }
1420 }
1421
1422 return false;
1423 }
1424
1425 private MappingSqlQuery _mappingSqlQuery;
1426 }
1427
1428 protected class AddSCFrameworkVersion {
1429 protected AddSCFrameworkVersion(
1430 SCProductVersionPersistenceImpl persistenceImpl) {
1431 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1432 "INSERT INTO SCFrameworkVersi_SCProductVers (productVersionId, frameworkVersionId) VALUES (?, ?)",
1433 new int[] { Types.BIGINT, Types.BIGINT });
1434 _persistenceImpl = persistenceImpl;
1435 }
1436
1437 protected void add(long productVersionId, long frameworkVersionId) {
1438 if (!_persistenceImpl.containsSCFrameworkVersion.contains(
1439 productVersionId, frameworkVersionId)) {
1440 _sqlUpdate.update(new Object[] {
1441 new Long(productVersionId), new Long(frameworkVersionId)
1442 });
1443 }
1444 }
1445
1446 private SqlUpdate _sqlUpdate;
1447 private SCProductVersionPersistenceImpl _persistenceImpl;
1448 }
1449
1450 protected class ClearSCFrameworkVersions {
1451 protected ClearSCFrameworkVersions(
1452 SCProductVersionPersistenceImpl persistenceImpl) {
1453 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1454 "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?",
1455 new int[] { Types.BIGINT });
1456 }
1457
1458 protected void clear(long productVersionId) {
1459 _sqlUpdate.update(new Object[] { new Long(productVersionId) });
1460 }
1461
1462 private SqlUpdate _sqlUpdate;
1463 }
1464
1465 protected class RemoveSCFrameworkVersion {
1466 protected RemoveSCFrameworkVersion(
1467 SCProductVersionPersistenceImpl persistenceImpl) {
1468 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1469 "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?",
1470 new int[] { Types.BIGINT, Types.BIGINT });
1471 }
1472
1473 protected void remove(long productVersionId, long frameworkVersionId) {
1474 _sqlUpdate.update(new Object[] {
1475 new Long(productVersionId), new Long(frameworkVersionId)
1476 });
1477 }
1478
1479 private SqlUpdate _sqlUpdate;
1480 }
1481
1482 private static final String _SQL_GETSCFRAMEWORKVERSIONS = "SELECT {SCFrameworkVersion.*} FROM SCFrameworkVersion INNER JOIN SCFrameworkVersi_SCProductVers ON (SCFrameworkVersi_SCProductVers.frameworkVersionId = SCFrameworkVersion.frameworkVersionId) WHERE (SCFrameworkVersi_SCProductVers.productVersionId = ?)";
1483 private static final String _SQL_GETSCFRAMEWORKVERSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?";
1484 private static final String _SQL_CONTAINSSCFRAMEWORKVERSION = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?";
1485 private static Log _log = LogFactory.getLog(SCProductVersionPersistenceImpl.class);
1486 private ModelListener[] _listeners = new ModelListener[0];
1487}