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