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