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