1
22
23 package com.liferay.portlet.softwarecatalog.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.bean.InitializingBean;
27 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
28 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
29 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
30 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
31 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
32 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
33 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
34 import com.liferay.portal.kernel.dao.orm.Query;
35 import com.liferay.portal.kernel.dao.orm.QueryPos;
36 import com.liferay.portal.kernel.dao.orm.QueryUtil;
37 import com.liferay.portal.kernel.dao.orm.SQLQuery;
38 import com.liferay.portal.kernel.dao.orm.Session;
39 import com.liferay.portal.kernel.dao.orm.Type;
40 import com.liferay.portal.kernel.util.GetterUtil;
41 import com.liferay.portal.kernel.util.ListUtil;
42 import com.liferay.portal.kernel.util.OrderByComparator;
43 import com.liferay.portal.kernel.util.StringPool;
44 import com.liferay.portal.kernel.util.StringUtil;
45 import com.liferay.portal.model.ModelListener;
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, InitializingBean {
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 session.delete(scProductVersion);
152
153 session.flush();
154
155 return scProductVersion;
156 }
157 catch (Exception e) {
158 throw processException(e);
159 }
160 finally {
161 closeSession(session);
162
163 FinderCacheUtil.clearCache(SCProductVersion.class.getName());
164 }
165 }
166
167
170 public SCProductVersion update(SCProductVersion scProductVersion)
171 throws SystemException {
172 if (_log.isWarnEnabled()) {
173 _log.warn(
174 "Using the deprecated update(SCProductVersion scProductVersion) method. Use update(SCProductVersion scProductVersion, boolean merge) instead.");
175 }
176
177 return update(scProductVersion, false);
178 }
179
180
193 public SCProductVersion update(SCProductVersion scProductVersion,
194 boolean merge) throws SystemException {
195 boolean isNew = scProductVersion.isNew();
196
197 if (_listeners.length > 0) {
198 for (ModelListener listener : _listeners) {
199 if (isNew) {
200 listener.onBeforeCreate(scProductVersion);
201 }
202 else {
203 listener.onBeforeUpdate(scProductVersion);
204 }
205 }
206 }
207
208 scProductVersion = updateImpl(scProductVersion, merge);
209
210 if (_listeners.length > 0) {
211 for (ModelListener listener : _listeners) {
212 if (isNew) {
213 listener.onAfterCreate(scProductVersion);
214 }
215 else {
216 listener.onAfterUpdate(scProductVersion);
217 }
218 }
219 }
220
221 return scProductVersion;
222 }
223
224 public SCProductVersion updateImpl(
225 com.liferay.portlet.softwarecatalog.model.SCProductVersion scProductVersion,
226 boolean merge) throws SystemException {
227 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
228
229 Session session = null;
230
231 try {
232 session = openSession();
233
234 if (merge) {
235 session.merge(scProductVersion);
236 }
237 else {
238 if (scProductVersion.isNew()) {
239 session.save(scProductVersion);
240 }
241 }
242
243 session.flush();
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 = (List<SCProductVersion>)QueryUtil.list(q,
736 getDialect(), start, end);
737
738 if (obc == null) {
739 Collections.sort(list);
740 }
741
742 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
743 finderClassName, finderMethodName, finderParams,
744 finderArgs, list);
745
746 return list;
747 }
748 catch (Exception e) {
749 throw processException(e);
750 }
751 finally {
752 closeSession(session);
753 }
754 }
755 else {
756 return (List<SCProductVersion>)result;
757 }
758 }
759
760 public void removeByProductEntryId(long productEntryId)
761 throws SystemException {
762 for (SCProductVersion scProductVersion : findByProductEntryId(
763 productEntryId)) {
764 remove(scProductVersion);
765 }
766 }
767
768 public void removeByDirectDownloadURL(String directDownloadURL)
769 throws NoSuchProductVersionException, SystemException {
770 SCProductVersion scProductVersion = findByDirectDownloadURL(directDownloadURL);
771
772 remove(scProductVersion);
773 }
774
775 public void removeAll() throws SystemException {
776 for (SCProductVersion scProductVersion : findAll()) {
777 remove(scProductVersion);
778 }
779 }
780
781 public int countByProductEntryId(long productEntryId)
782 throws SystemException {
783 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
784 String finderClassName = SCProductVersion.class.getName();
785 String finderMethodName = "countByProductEntryId";
786 String[] finderParams = new String[] { Long.class.getName() };
787 Object[] finderArgs = new Object[] { new Long(productEntryId) };
788
789 Object result = null;
790
791 if (finderClassNameCacheEnabled) {
792 result = FinderCacheUtil.getResult(finderClassName,
793 finderMethodName, finderParams, finderArgs, this);
794 }
795
796 if (result == null) {
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 StringBuilder query = new StringBuilder();
803
804 query.append("SELECT COUNT(*) ");
805 query.append(
806 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
807
808 query.append("productEntryId = ?");
809
810 query.append(" ");
811
812 Query q = session.createQuery(query.toString());
813
814 QueryPos qPos = QueryPos.getInstance(q);
815
816 qPos.add(productEntryId);
817
818 Long count = null;
819
820 Iterator<Long> itr = q.list().iterator();
821
822 if (itr.hasNext()) {
823 count = itr.next();
824 }
825
826 if (count == null) {
827 count = new Long(0);
828 }
829
830 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
831 finderClassName, finderMethodName, finderParams,
832 finderArgs, count);
833
834 return count.intValue();
835 }
836 catch (Exception e) {
837 throw processException(e);
838 }
839 finally {
840 closeSession(session);
841 }
842 }
843 else {
844 return ((Long)result).intValue();
845 }
846 }
847
848 public int countByDirectDownloadURL(String directDownloadURL)
849 throws SystemException {
850 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
851 String finderClassName = SCProductVersion.class.getName();
852 String finderMethodName = "countByDirectDownloadURL";
853 String[] finderParams = new String[] { String.class.getName() };
854 Object[] finderArgs = new Object[] { directDownloadURL };
855
856 Object result = null;
857
858 if (finderClassNameCacheEnabled) {
859 result = FinderCacheUtil.getResult(finderClassName,
860 finderMethodName, finderParams, finderArgs, this);
861 }
862
863 if (result == null) {
864 Session session = null;
865
866 try {
867 session = openSession();
868
869 StringBuilder query = new StringBuilder();
870
871 query.append("SELECT COUNT(*) ");
872 query.append(
873 "FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion WHERE ");
874
875 if (directDownloadURL == null) {
876 query.append("directDownloadURL IS NULL");
877 }
878 else {
879 query.append("lower(directDownloadURL) = ?");
880 }
881
882 query.append(" ");
883
884 Query q = session.createQuery(query.toString());
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 if (directDownloadURL != null) {
889 qPos.add(directDownloadURL);
890 }
891
892 Long count = null;
893
894 Iterator<Long> itr = q.list().iterator();
895
896 if (itr.hasNext()) {
897 count = itr.next();
898 }
899
900 if (count == null) {
901 count = new Long(0);
902 }
903
904 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
905 finderClassName, finderMethodName, finderParams,
906 finderArgs, count);
907
908 return count.intValue();
909 }
910 catch (Exception e) {
911 throw processException(e);
912 }
913 finally {
914 closeSession(session);
915 }
916 }
917 else {
918 return ((Long)result).intValue();
919 }
920 }
921
922 public int countAll() throws SystemException {
923 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED;
924 String finderClassName = SCProductVersion.class.getName();
925 String finderMethodName = "countAll";
926 String[] finderParams = new String[] { };
927 Object[] finderArgs = new Object[] { };
928
929 Object result = null;
930
931 if (finderClassNameCacheEnabled) {
932 result = FinderCacheUtil.getResult(finderClassName,
933 finderMethodName, finderParams, finderArgs, this);
934 }
935
936 if (result == null) {
937 Session session = null;
938
939 try {
940 session = openSession();
941
942 Query q = session.createQuery(
943 "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductVersion");
944
945 Long count = null;
946
947 Iterator<Long> itr = q.list().iterator();
948
949 if (itr.hasNext()) {
950 count = itr.next();
951 }
952
953 if (count == null) {
954 count = new Long(0);
955 }
956
957 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
958 finderClassName, finderMethodName, finderParams,
959 finderArgs, count);
960
961 return count.intValue();
962 }
963 catch (Exception e) {
964 throw processException(e);
965 }
966 finally {
967 closeSession(session);
968 }
969 }
970 else {
971 return ((Long)result).intValue();
972 }
973 }
974
975 public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
976 long pk) throws SystemException {
977 return getSCFrameworkVersions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
978 }
979
980 public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
981 long pk, int start, int end) throws SystemException {
982 return getSCFrameworkVersions(pk, start, end, null);
983 }
984
985 public List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> getSCFrameworkVersions(
986 long pk, int start, int end, OrderByComparator obc)
987 throws SystemException {
988 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
989
990 String finderClassName = "SCFrameworkVersi_SCProductVers";
991
992 String finderMethodName = "getSCFrameworkVersions";
993 String[] finderParams = new String[] {
994 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
995 "com.liferay.portal.kernel.util.OrderByComparator"
996 };
997 Object[] finderArgs = new Object[] {
998 new Long(pk), String.valueOf(start), String.valueOf(end),
999 String.valueOf(obc)
1000 };
1001
1002 Object result = null;
1003
1004 if (finderClassNameCacheEnabled) {
1005 result = FinderCacheUtil.getResult(finderClassName,
1006 finderMethodName, finderParams, finderArgs, this);
1007 }
1008
1009 if (result == null) {
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 StringBuilder sb = new StringBuilder();
1016
1017 sb.append(_SQL_GETSCFRAMEWORKVERSIONS);
1018
1019 if (obc != null) {
1020 sb.append("ORDER BY ");
1021 sb.append(obc.getOrderBy());
1022 }
1023
1024 else {
1025 sb.append("ORDER BY ");
1026
1027 sb.append("SCFrameworkVersion.priority ASC, ");
1028 sb.append("SCFrameworkVersion.name ASC");
1029 }
1030
1031 String sql = sb.toString();
1032
1033 SQLQuery q = session.createSQLQuery(sql);
1034
1035 q.addEntity("SCFrameworkVersion",
1036 com.liferay.portlet.softwarecatalog.model.impl.SCFrameworkVersionImpl.class);
1037
1038 QueryPos qPos = QueryPos.getInstance(q);
1039
1040 qPos.add(pk);
1041
1042 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> list =
1043 (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)QueryUtil.list(q,
1044 getDialect(), start, end);
1045
1046 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1047 finderClassName, finderMethodName, finderParams,
1048 finderArgs, list);
1049
1050 return list;
1051 }
1052 catch (Exception e) {
1053 throw processException(e);
1054 }
1055 finally {
1056 closeSession(session);
1057 }
1058 }
1059 else {
1060 return (List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion>)result;
1061 }
1062 }
1063
1064 public int getSCFrameworkVersionsSize(long pk) throws SystemException {
1065 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1066
1067 String finderClassName = "SCFrameworkVersi_SCProductVers";
1068
1069 String finderMethodName = "getSCFrameworkVersionsSize";
1070 String[] finderParams = new String[] { Long.class.getName() };
1071 Object[] finderArgs = new Object[] { new Long(pk) };
1072
1073 Object result = null;
1074
1075 if (finderClassNameCacheEnabled) {
1076 result = FinderCacheUtil.getResult(finderClassName,
1077 finderMethodName, finderParams, finderArgs, this);
1078 }
1079
1080 if (result == null) {
1081 Session session = null;
1082
1083 try {
1084 session = openSession();
1085
1086 SQLQuery q = session.createSQLQuery(_SQL_GETSCFRAMEWORKVERSIONSSIZE);
1087
1088 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1089
1090 QueryPos qPos = QueryPos.getInstance(q);
1091
1092 qPos.add(pk);
1093
1094 Long count = null;
1095
1096 Iterator<Long> itr = q.list().iterator();
1097
1098 if (itr.hasNext()) {
1099 count = itr.next();
1100 }
1101
1102 if (count == null) {
1103 count = new Long(0);
1104 }
1105
1106 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1107 finderClassName, finderMethodName, finderParams,
1108 finderArgs, count);
1109
1110 return count.intValue();
1111 }
1112 catch (Exception e) {
1113 throw processException(e);
1114 }
1115 finally {
1116 closeSession(session);
1117 }
1118 }
1119 else {
1120 return ((Long)result).intValue();
1121 }
1122 }
1123
1124 public boolean containsSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1125 throws SystemException {
1126 boolean finderClassNameCacheEnabled = SCProductVersionModelImpl.CACHE_ENABLED_SCFRAMEWORKVERSI_SCPRODUCTVERS;
1127
1128 String finderClassName = "SCFrameworkVersi_SCProductVers";
1129
1130 String finderMethodName = "containsSCFrameworkVersions";
1131 String[] finderParams = new String[] {
1132 Long.class.getName(),
1133
1134 Long.class.getName()
1135 };
1136 Object[] finderArgs = new Object[] {
1137 new Long(pk),
1138
1139 new Long(scFrameworkVersionPK)
1140 };
1141
1142 Object result = null;
1143
1144 if (finderClassNameCacheEnabled) {
1145 result = FinderCacheUtil.getResult(finderClassName,
1146 finderMethodName, finderParams, finderArgs, this);
1147 }
1148
1149 if (result == null) {
1150 try {
1151 Boolean value = Boolean.valueOf(containsSCFrameworkVersion.contains(
1152 pk, scFrameworkVersionPK));
1153
1154 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1155 finderClassName, finderMethodName, finderParams,
1156 finderArgs, value);
1157
1158 return value.booleanValue();
1159 }
1160 catch (Exception e) {
1161 throw processException(e);
1162 }
1163 }
1164 else {
1165 return ((Boolean)result).booleanValue();
1166 }
1167 }
1168
1169 public boolean containsSCFrameworkVersions(long pk)
1170 throws SystemException {
1171 if (getSCFrameworkVersionsSize(pk) > 0) {
1172 return true;
1173 }
1174 else {
1175 return false;
1176 }
1177 }
1178
1179 public void addSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1180 throws SystemException {
1181 try {
1182 addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1183 }
1184 catch (Exception e) {
1185 throw processException(e);
1186 }
1187 finally {
1188 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1189 }
1190 }
1191
1192 public void addSCFrameworkVersion(long pk,
1193 com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1194 throws SystemException {
1195 try {
1196 addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1197 }
1198 catch (Exception e) {
1199 throw processException(e);
1200 }
1201 finally {
1202 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1203 }
1204 }
1205
1206 public void addSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1207 throws SystemException {
1208 try {
1209 for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1210 addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1211 }
1212 }
1213 catch (Exception e) {
1214 throw processException(e);
1215 }
1216 finally {
1217 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1218 }
1219 }
1220
1221 public void addSCFrameworkVersions(long pk,
1222 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1223 throws SystemException {
1224 try {
1225 for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1226 addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1227 }
1228 }
1229 catch (Exception e) {
1230 throw processException(e);
1231 }
1232 finally {
1233 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1234 }
1235 }
1236
1237 public void clearSCFrameworkVersions(long pk) throws SystemException {
1238 try {
1239 clearSCFrameworkVersions.clear(pk);
1240 }
1241 catch (Exception e) {
1242 throw processException(e);
1243 }
1244 finally {
1245 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1246 }
1247 }
1248
1249 public void removeSCFrameworkVersion(long pk, long scFrameworkVersionPK)
1250 throws SystemException {
1251 try {
1252 removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1253 }
1254 catch (Exception e) {
1255 throw processException(e);
1256 }
1257 finally {
1258 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1259 }
1260 }
1261
1262 public void removeSCFrameworkVersion(long pk,
1263 com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion)
1264 throws SystemException {
1265 try {
1266 removeSCFrameworkVersion.remove(pk,
1267 scFrameworkVersion.getPrimaryKey());
1268 }
1269 catch (Exception e) {
1270 throw processException(e);
1271 }
1272 finally {
1273 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1274 }
1275 }
1276
1277 public void removeSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1278 throws SystemException {
1279 try {
1280 for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1281 removeSCFrameworkVersion.remove(pk, scFrameworkVersionPK);
1282 }
1283 }
1284 catch (Exception e) {
1285 throw processException(e);
1286 }
1287 finally {
1288 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1289 }
1290 }
1291
1292 public void removeSCFrameworkVersions(long pk,
1293 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1294 throws SystemException {
1295 try {
1296 for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1297 removeSCFrameworkVersion.remove(pk,
1298 scFrameworkVersion.getPrimaryKey());
1299 }
1300 }
1301 catch (Exception e) {
1302 throw processException(e);
1303 }
1304 finally {
1305 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1306 }
1307 }
1308
1309 public void setSCFrameworkVersions(long pk, long[] scFrameworkVersionPKs)
1310 throws SystemException {
1311 try {
1312 clearSCFrameworkVersions.clear(pk);
1313
1314 for (long scFrameworkVersionPK : scFrameworkVersionPKs) {
1315 addSCFrameworkVersion.add(pk, scFrameworkVersionPK);
1316 }
1317 }
1318 catch (Exception e) {
1319 throw processException(e);
1320 }
1321 finally {
1322 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1323 }
1324 }
1325
1326 public void setSCFrameworkVersions(long pk,
1327 List<com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion> scFrameworkVersions)
1328 throws SystemException {
1329 try {
1330 clearSCFrameworkVersions.clear(pk);
1331
1332 for (com.liferay.portlet.softwarecatalog.model.SCFrameworkVersion scFrameworkVersion : scFrameworkVersions) {
1333 addSCFrameworkVersion.add(pk, scFrameworkVersion.getPrimaryKey());
1334 }
1335 }
1336 catch (Exception e) {
1337 throw processException(e);
1338 }
1339 finally {
1340 FinderCacheUtil.clearCache("SCFrameworkVersi_SCProductVers");
1341 }
1342 }
1343
1344 public void registerListener(ModelListener listener) {
1345 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1346
1347 listeners.add(listener);
1348
1349 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1350 }
1351
1352 public void unregisterListener(ModelListener listener) {
1353 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1354
1355 listeners.remove(listener);
1356
1357 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1358 }
1359
1360 public void afterPropertiesSet() {
1361 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1362 com.liferay.portal.util.PropsUtil.get(
1363 "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductVersion")));
1364
1365 if (listenerClassNames.length > 0) {
1366 try {
1367 List<ModelListener> listeners = new ArrayList<ModelListener>();
1368
1369 for (String listenerClassName : listenerClassNames) {
1370 listeners.add((ModelListener)Class.forName(
1371 listenerClassName).newInstance());
1372 }
1373
1374 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1375 }
1376 catch (Exception e) {
1377 _log.error(e);
1378 }
1379 }
1380
1381 containsSCFrameworkVersion = new ContainsSCFrameworkVersion(this);
1382
1383 addSCFrameworkVersion = new AddSCFrameworkVersion(this);
1384 clearSCFrameworkVersions = new ClearSCFrameworkVersions(this);
1385 removeSCFrameworkVersion = new RemoveSCFrameworkVersion(this);
1386 }
1387
1388 protected ContainsSCFrameworkVersion containsSCFrameworkVersion;
1389 protected AddSCFrameworkVersion addSCFrameworkVersion;
1390 protected ClearSCFrameworkVersions clearSCFrameworkVersions;
1391 protected RemoveSCFrameworkVersion removeSCFrameworkVersion;
1392
1393 protected class ContainsSCFrameworkVersion {
1394 protected ContainsSCFrameworkVersion(
1395 SCProductVersionPersistenceImpl persistenceImpl) {
1396 super();
1397
1398 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1399 _SQL_CONTAINSSCFRAMEWORKVERSION,
1400 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1401 }
1402
1403 protected boolean contains(long productVersionId,
1404 long frameworkVersionId) {
1405 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1406 new Long(productVersionId), new Long(frameworkVersionId)
1407 });
1408
1409 if (results.size() > 0) {
1410 Integer count = results.get(0);
1411
1412 if (count.intValue() > 0) {
1413 return true;
1414 }
1415 }
1416
1417 return false;
1418 }
1419
1420 private MappingSqlQuery _mappingSqlQuery;
1421 }
1422
1423 protected class AddSCFrameworkVersion {
1424 protected AddSCFrameworkVersion(
1425 SCProductVersionPersistenceImpl persistenceImpl) {
1426 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1427 "INSERT INTO SCFrameworkVersi_SCProductVers (productVersionId, frameworkVersionId) VALUES (?, ?)",
1428 new int[] { Types.BIGINT, Types.BIGINT });
1429 _persistenceImpl = persistenceImpl;
1430 }
1431
1432 protected void add(long productVersionId, long frameworkVersionId) {
1433 if (!_persistenceImpl.containsSCFrameworkVersion.contains(
1434 productVersionId, frameworkVersionId)) {
1435 _sqlUpdate.update(new Object[] {
1436 new Long(productVersionId), new Long(frameworkVersionId)
1437 });
1438 }
1439 }
1440
1441 private SqlUpdate _sqlUpdate;
1442 private SCProductVersionPersistenceImpl _persistenceImpl;
1443 }
1444
1445 protected class ClearSCFrameworkVersions {
1446 protected ClearSCFrameworkVersions(
1447 SCProductVersionPersistenceImpl persistenceImpl) {
1448 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1449 "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?",
1450 new int[] { Types.BIGINT });
1451 }
1452
1453 protected void clear(long productVersionId) {
1454 _sqlUpdate.update(new Object[] { new Long(productVersionId) });
1455 }
1456
1457 private SqlUpdate _sqlUpdate;
1458 }
1459
1460 protected class RemoveSCFrameworkVersion {
1461 protected RemoveSCFrameworkVersion(
1462 SCProductVersionPersistenceImpl persistenceImpl) {
1463 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1464 "DELETE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?",
1465 new int[] { Types.BIGINT, Types.BIGINT });
1466 }
1467
1468 protected void remove(long productVersionId, long frameworkVersionId) {
1469 _sqlUpdate.update(new Object[] {
1470 new Long(productVersionId), new Long(frameworkVersionId)
1471 });
1472 }
1473
1474 private SqlUpdate _sqlUpdate;
1475 }
1476
1477 private static final String _SQL_GETSCFRAMEWORKVERSIONS = "SELECT {SCFrameworkVersion.*} FROM SCFrameworkVersion INNER JOIN SCFrameworkVersi_SCProductVers ON (SCFrameworkVersi_SCProductVers.frameworkVersionId = SCFrameworkVersion.frameworkVersionId) WHERE (SCFrameworkVersi_SCProductVers.productVersionId = ?)";
1478 private static final String _SQL_GETSCFRAMEWORKVERSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ?";
1479 private static final String _SQL_CONTAINSSCFRAMEWORKVERSION = "SELECT COUNT(*) AS COUNT_VALUE FROM SCFrameworkVersi_SCProductVers WHERE productVersionId = ? AND frameworkVersionId = ?";
1480 private static Log _log = LogFactory.getLog(SCProductVersionPersistenceImpl.class);
1481 private ModelListener[] _listeners = new ModelListener[0];
1482}