1
22
23 package com.liferay.portlet.softwarecatalog.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
27 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
28 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
29 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
30 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
31 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
32 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
33 import com.liferay.portal.kernel.dao.orm.Query;
34 import com.liferay.portal.kernel.dao.orm.QueryPos;
35 import com.liferay.portal.kernel.dao.orm.QueryUtil;
36 import com.liferay.portal.kernel.dao.orm.SQLQuery;
37 import com.liferay.portal.kernel.dao.orm.Session;
38 import com.liferay.portal.kernel.dao.orm.Type;
39 import com.liferay.portal.kernel.util.GetterUtil;
40 import com.liferay.portal.kernel.util.ListUtil;
41 import com.liferay.portal.kernel.util.OrderByComparator;
42 import com.liferay.portal.kernel.util.StringPool;
43 import com.liferay.portal.kernel.util.StringUtil;
44 import com.liferay.portal.model.ModelListener;
45 import com.liferay.portal.service.persistence.BatchSessionUtil;
46 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
47
48 import com.liferay.portlet.softwarecatalog.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 {
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 if (BatchSessionUtil.isEnabled()) {
149 Object staleObject = session.get(SCLicenseImpl.class,
150 scLicense.getPrimaryKeyObj());
151
152 if (staleObject != null) {
153 session.evict(staleObject);
154 }
155 }
156
157 session.delete(scLicense);
158
159 session.flush();
160
161 return scLicense;
162 }
163 catch (Exception e) {
164 throw processException(e);
165 }
166 finally {
167 closeSession(session);
168
169 FinderCacheUtil.clearCache(SCLicense.class.getName());
170 }
171 }
172
173
176 public SCLicense update(SCLicense scLicense) throws SystemException {
177 if (_log.isWarnEnabled()) {
178 _log.warn(
179 "Using the deprecated update(SCLicense scLicense) method. Use update(SCLicense scLicense, boolean merge) instead.");
180 }
181
182 return update(scLicense, false);
183 }
184
185
198 public SCLicense update(SCLicense scLicense, boolean merge)
199 throws SystemException {
200 boolean isNew = scLicense.isNew();
201
202 if (_listeners.length > 0) {
203 for (ModelListener listener : _listeners) {
204 if (isNew) {
205 listener.onBeforeCreate(scLicense);
206 }
207 else {
208 listener.onBeforeUpdate(scLicense);
209 }
210 }
211 }
212
213 scLicense = updateImpl(scLicense, merge);
214
215 if (_listeners.length > 0) {
216 for (ModelListener listener : _listeners) {
217 if (isNew) {
218 listener.onAfterCreate(scLicense);
219 }
220 else {
221 listener.onAfterUpdate(scLicense);
222 }
223 }
224 }
225
226 return scLicense;
227 }
228
229 public SCLicense updateImpl(
230 com.liferay.portlet.softwarecatalog.model.SCLicense scLicense,
231 boolean merge) throws SystemException {
232 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
233
234 Session session = null;
235
236 try {
237 session = openSession();
238
239 BatchSessionUtil.update(session, scLicense, merge);
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 = null;
894
895 if (obc == null) {
896 list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
897 start, end, false);
898
899 Collections.sort(list);
900 }
901 else {
902 list = (List<SCLicense>)QueryUtil.list(q, getDialect(),
903 start, end);
904 }
905
906 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
907 finderClassName, finderMethodName, finderParams,
908 finderArgs, list);
909
910 return list;
911 }
912 catch (Exception e) {
913 throw processException(e);
914 }
915 finally {
916 closeSession(session);
917 }
918 }
919 else {
920 return (List<SCLicense>)result;
921 }
922 }
923
924 public void removeByActive(boolean active) throws SystemException {
925 for (SCLicense scLicense : findByActive(active)) {
926 remove(scLicense);
927 }
928 }
929
930 public void removeByA_R(boolean active, boolean recommended)
931 throws SystemException {
932 for (SCLicense scLicense : findByA_R(active, recommended)) {
933 remove(scLicense);
934 }
935 }
936
937 public void removeAll() throws SystemException {
938 for (SCLicense scLicense : findAll()) {
939 remove(scLicense);
940 }
941 }
942
943 public int countByActive(boolean active) throws SystemException {
944 boolean finderClassNameCacheEnabled = SCLicenseModelImpl.CACHE_ENABLED;
945 String finderClassName = SCLicense.class.getName();
946 String finderMethodName = "countByActive";
947 String[] finderParams = new String[] { Boolean.class.getName() };
948 Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
949
950 Object result = null;
951
952 if (finderClassNameCacheEnabled) {
953 result = FinderCacheUtil.getResult(finderClassName,
954 finderMethodName, finderParams, finderArgs, this);
955 }
956
957 if (result == null) {
958 Session session = null;
959
960 try {
961 session = openSession();
962
963 StringBuilder query = new StringBuilder();
964
965 query.append("SELECT COUNT(*) ");
966 query.append(
967 "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
968
969 query.append("active_ = ?");
970
971 query.append(" ");
972
973 Query q = session.createQuery(query.toString());
974
975 QueryPos qPos = QueryPos.getInstance(q);
976
977 qPos.add(active);
978
979 Long count = null;
980
981 Iterator<Long> itr = q.list().iterator();
982
983 if (itr.hasNext()) {
984 count = itr.next();
985 }
986
987 if (count == null) {
988 count = new Long(0);
989 }
990
991 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
992 finderClassName, finderMethodName, finderParams,
993 finderArgs, count);
994
995 return count.intValue();
996 }
997 catch (Exception e) {
998 throw processException(e);
999 }
1000 finally {
1001 closeSession(session);
1002 }
1003 }
1004 else {
1005 return ((Long)result).intValue();
1006 }
1007 }
1008
1009 public int countByA_R(boolean active, boolean recommended)
1010 throws SystemException {
1011 boolean finderClassNameCacheEnabled = SCLicenseModelImpl.CACHE_ENABLED;
1012 String finderClassName = SCLicense.class.getName();
1013 String finderMethodName = "countByA_R";
1014 String[] finderParams = new String[] {
1015 Boolean.class.getName(), Boolean.class.getName()
1016 };
1017 Object[] finderArgs = new Object[] {
1018 Boolean.valueOf(active), Boolean.valueOf(recommended)
1019 };
1020
1021 Object result = null;
1022
1023 if (finderClassNameCacheEnabled) {
1024 result = FinderCacheUtil.getResult(finderClassName,
1025 finderMethodName, finderParams, finderArgs, this);
1026 }
1027
1028 if (result == null) {
1029 Session session = null;
1030
1031 try {
1032 session = openSession();
1033
1034 StringBuilder query = new StringBuilder();
1035
1036 query.append("SELECT COUNT(*) ");
1037 query.append(
1038 "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
1039
1040 query.append("active_ = ?");
1041
1042 query.append(" AND ");
1043
1044 query.append("recommended = ?");
1045
1046 query.append(" ");
1047
1048 Query q = session.createQuery(query.toString());
1049
1050 QueryPos qPos = QueryPos.getInstance(q);
1051
1052 qPos.add(active);
1053
1054 qPos.add(recommended);
1055
1056 Long count = null;
1057
1058 Iterator<Long> itr = q.list().iterator();
1059
1060 if (itr.hasNext()) {
1061 count = itr.next();
1062 }
1063
1064 if (count == null) {
1065 count = new Long(0);
1066 }
1067
1068 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1069 finderClassName, finderMethodName, finderParams,
1070 finderArgs, count);
1071
1072 return count.intValue();
1073 }
1074 catch (Exception e) {
1075 throw processException(e);
1076 }
1077 finally {
1078 closeSession(session);
1079 }
1080 }
1081 else {
1082 return ((Long)result).intValue();
1083 }
1084 }
1085
1086 public int countAll() throws SystemException {
1087 boolean finderClassNameCacheEnabled = SCLicenseModelImpl.CACHE_ENABLED;
1088 String finderClassName = SCLicense.class.getName();
1089 String finderMethodName = "countAll";
1090 String[] finderParams = new String[] { };
1091 Object[] finderArgs = new Object[] { };
1092
1093 Object result = null;
1094
1095 if (finderClassNameCacheEnabled) {
1096 result = FinderCacheUtil.getResult(finderClassName,
1097 finderMethodName, finderParams, finderArgs, this);
1098 }
1099
1100 if (result == null) {
1101 Session session = null;
1102
1103 try {
1104 session = openSession();
1105
1106 Query q = session.createQuery(
1107 "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCLicense");
1108
1109 Long count = null;
1110
1111 Iterator<Long> itr = q.list().iterator();
1112
1113 if (itr.hasNext()) {
1114 count = itr.next();
1115 }
1116
1117 if (count == null) {
1118 count = new Long(0);
1119 }
1120
1121 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1122 finderClassName, finderMethodName, finderParams,
1123 finderArgs, count);
1124
1125 return count.intValue();
1126 }
1127 catch (Exception e) {
1128 throw processException(e);
1129 }
1130 finally {
1131 closeSession(session);
1132 }
1133 }
1134 else {
1135 return ((Long)result).intValue();
1136 }
1137 }
1138
1139 public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1140 long pk) throws SystemException {
1141 return getSCProductEntries(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1142 }
1143
1144 public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1145 long pk, int start, int end) throws SystemException {
1146 return getSCProductEntries(pk, start, end, null);
1147 }
1148
1149 public List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> getSCProductEntries(
1150 long pk, int start, int end, OrderByComparator obc)
1151 throws SystemException {
1152 boolean finderClassNameCacheEnabled = SCLicenseModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1153
1154 String finderClassName = "SCLicenses_SCProductEntries";
1155
1156 String finderMethodName = "getSCProductEntries";
1157 String[] finderParams = new String[] {
1158 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1159 "com.liferay.portal.kernel.util.OrderByComparator"
1160 };
1161 Object[] finderArgs = new Object[] {
1162 new Long(pk), String.valueOf(start), String.valueOf(end),
1163 String.valueOf(obc)
1164 };
1165
1166 Object result = null;
1167
1168 if (finderClassNameCacheEnabled) {
1169 result = FinderCacheUtil.getResult(finderClassName,
1170 finderMethodName, finderParams, finderArgs, this);
1171 }
1172
1173 if (result == null) {
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 StringBuilder sb = new StringBuilder();
1180
1181 sb.append(_SQL_GETSCPRODUCTENTRIES);
1182
1183 if (obc != null) {
1184 sb.append("ORDER BY ");
1185 sb.append(obc.getOrderBy());
1186 }
1187
1188 else {
1189 sb.append("ORDER BY ");
1190
1191 sb.append("SCProductEntry.modifiedDate DESC, ");
1192 sb.append("SCProductEntry.name DESC");
1193 }
1194
1195 String sql = sb.toString();
1196
1197 SQLQuery q = session.createSQLQuery(sql);
1198
1199 q.addEntity("SCProductEntry",
1200 com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl.class);
1201
1202 QueryPos qPos = QueryPos.getInstance(q);
1203
1204 qPos.add(pk);
1205
1206 List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> list =
1207 (List<com.liferay.portlet.softwarecatalog.model.SCProductEntry>)QueryUtil.list(q,
1208 getDialect(), start, end);
1209
1210 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1211 finderClassName, finderMethodName, finderParams,
1212 finderArgs, list);
1213
1214 return list;
1215 }
1216 catch (Exception e) {
1217 throw processException(e);
1218 }
1219 finally {
1220 closeSession(session);
1221 }
1222 }
1223 else {
1224 return (List<com.liferay.portlet.softwarecatalog.model.SCProductEntry>)result;
1225 }
1226 }
1227
1228 public int getSCProductEntriesSize(long pk) throws SystemException {
1229 boolean finderClassNameCacheEnabled = SCLicenseModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1230
1231 String finderClassName = "SCLicenses_SCProductEntries";
1232
1233 String finderMethodName = "getSCProductEntriesSize";
1234 String[] finderParams = new String[] { Long.class.getName() };
1235 Object[] finderArgs = new Object[] { new Long(pk) };
1236
1237 Object result = null;
1238
1239 if (finderClassNameCacheEnabled) {
1240 result = FinderCacheUtil.getResult(finderClassName,
1241 finderMethodName, finderParams, finderArgs, this);
1242 }
1243
1244 if (result == null) {
1245 Session session = null;
1246
1247 try {
1248 session = openSession();
1249
1250 SQLQuery q = session.createSQLQuery(_SQL_GETSCPRODUCTENTRIESSIZE);
1251
1252 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1253
1254 QueryPos qPos = QueryPos.getInstance(q);
1255
1256 qPos.add(pk);
1257
1258 Long count = null;
1259
1260 Iterator<Long> itr = q.list().iterator();
1261
1262 if (itr.hasNext()) {
1263 count = itr.next();
1264 }
1265
1266 if (count == null) {
1267 count = new Long(0);
1268 }
1269
1270 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1271 finderClassName, finderMethodName, finderParams,
1272 finderArgs, count);
1273
1274 return count.intValue();
1275 }
1276 catch (Exception e) {
1277 throw processException(e);
1278 }
1279 finally {
1280 closeSession(session);
1281 }
1282 }
1283 else {
1284 return ((Long)result).intValue();
1285 }
1286 }
1287
1288 public boolean containsSCProductEntry(long pk, long scProductEntryPK)
1289 throws SystemException {
1290 boolean finderClassNameCacheEnabled = SCLicenseModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1291
1292 String finderClassName = "SCLicenses_SCProductEntries";
1293
1294 String finderMethodName = "containsSCProductEntries";
1295 String[] finderParams = new String[] {
1296 Long.class.getName(),
1297
1298 Long.class.getName()
1299 };
1300 Object[] finderArgs = new Object[] {
1301 new Long(pk),
1302
1303 new Long(scProductEntryPK)
1304 };
1305
1306 Object result = null;
1307
1308 if (finderClassNameCacheEnabled) {
1309 result = FinderCacheUtil.getResult(finderClassName,
1310 finderMethodName, finderParams, finderArgs, this);
1311 }
1312
1313 if (result == null) {
1314 try {
1315 Boolean value = Boolean.valueOf(containsSCProductEntry.contains(
1316 pk, scProductEntryPK));
1317
1318 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1319 finderClassName, finderMethodName, finderParams,
1320 finderArgs, value);
1321
1322 return value.booleanValue();
1323 }
1324 catch (Exception e) {
1325 throw processException(e);
1326 }
1327 }
1328 else {
1329 return ((Boolean)result).booleanValue();
1330 }
1331 }
1332
1333 public boolean containsSCProductEntries(long pk) throws SystemException {
1334 if (getSCProductEntriesSize(pk) > 0) {
1335 return true;
1336 }
1337 else {
1338 return false;
1339 }
1340 }
1341
1342 public void addSCProductEntry(long pk, long scProductEntryPK)
1343 throws SystemException {
1344 try {
1345 addSCProductEntry.add(pk, scProductEntryPK);
1346 }
1347 catch (Exception e) {
1348 throw processException(e);
1349 }
1350 finally {
1351 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1352 }
1353 }
1354
1355 public void addSCProductEntry(long pk,
1356 com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
1357 throws SystemException {
1358 try {
1359 addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1360 }
1361 catch (Exception e) {
1362 throw processException(e);
1363 }
1364 finally {
1365 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1366 }
1367 }
1368
1369 public void addSCProductEntries(long pk, long[] scProductEntryPKs)
1370 throws SystemException {
1371 try {
1372 for (long scProductEntryPK : scProductEntryPKs) {
1373 addSCProductEntry.add(pk, scProductEntryPK);
1374 }
1375 }
1376 catch (Exception e) {
1377 throw processException(e);
1378 }
1379 finally {
1380 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1381 }
1382 }
1383
1384 public void addSCProductEntries(long pk,
1385 List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1386 throws SystemException {
1387 try {
1388 for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1389 addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1390 }
1391 }
1392 catch (Exception e) {
1393 throw processException(e);
1394 }
1395 finally {
1396 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1397 }
1398 }
1399
1400 public void clearSCProductEntries(long pk) throws SystemException {
1401 try {
1402 clearSCProductEntries.clear(pk);
1403 }
1404 catch (Exception e) {
1405 throw processException(e);
1406 }
1407 finally {
1408 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1409 }
1410 }
1411
1412 public void removeSCProductEntry(long pk, long scProductEntryPK)
1413 throws SystemException {
1414 try {
1415 removeSCProductEntry.remove(pk, scProductEntryPK);
1416 }
1417 catch (Exception e) {
1418 throw processException(e);
1419 }
1420 finally {
1421 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1422 }
1423 }
1424
1425 public void removeSCProductEntry(long pk,
1426 com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry)
1427 throws SystemException {
1428 try {
1429 removeSCProductEntry.remove(pk, scProductEntry.getPrimaryKey());
1430 }
1431 catch (Exception e) {
1432 throw processException(e);
1433 }
1434 finally {
1435 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1436 }
1437 }
1438
1439 public void removeSCProductEntries(long pk, long[] scProductEntryPKs)
1440 throws SystemException {
1441 try {
1442 for (long scProductEntryPK : scProductEntryPKs) {
1443 removeSCProductEntry.remove(pk, scProductEntryPK);
1444 }
1445 }
1446 catch (Exception e) {
1447 throw processException(e);
1448 }
1449 finally {
1450 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1451 }
1452 }
1453
1454 public void removeSCProductEntries(long pk,
1455 List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1456 throws SystemException {
1457 try {
1458 for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1459 removeSCProductEntry.remove(pk, scProductEntry.getPrimaryKey());
1460 }
1461 }
1462 catch (Exception e) {
1463 throw processException(e);
1464 }
1465 finally {
1466 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1467 }
1468 }
1469
1470 public void setSCProductEntries(long pk, long[] scProductEntryPKs)
1471 throws SystemException {
1472 try {
1473 clearSCProductEntries.clear(pk);
1474
1475 for (long scProductEntryPK : scProductEntryPKs) {
1476 addSCProductEntry.add(pk, scProductEntryPK);
1477 }
1478 }
1479 catch (Exception e) {
1480 throw processException(e);
1481 }
1482 finally {
1483 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1484 }
1485 }
1486
1487 public void setSCProductEntries(long pk,
1488 List<com.liferay.portlet.softwarecatalog.model.SCProductEntry> scProductEntries)
1489 throws SystemException {
1490 try {
1491 clearSCProductEntries.clear(pk);
1492
1493 for (com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry : scProductEntries) {
1494 addSCProductEntry.add(pk, scProductEntry.getPrimaryKey());
1495 }
1496 }
1497 catch (Exception e) {
1498 throw processException(e);
1499 }
1500 finally {
1501 FinderCacheUtil.clearCache("SCLicenses_SCProductEntries");
1502 }
1503 }
1504
1505 public void registerListener(ModelListener listener) {
1506 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1507
1508 listeners.add(listener);
1509
1510 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1511 }
1512
1513 public void unregisterListener(ModelListener listener) {
1514 List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1515
1516 listeners.remove(listener);
1517
1518 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1519 }
1520
1521 public void afterPropertiesSet() {
1522 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1523 com.liferay.portal.util.PropsUtil.get(
1524 "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCLicense")));
1525
1526 if (listenerClassNames.length > 0) {
1527 try {
1528 List<ModelListener> listeners = new ArrayList<ModelListener>();
1529
1530 for (String listenerClassName : listenerClassNames) {
1531 listeners.add((ModelListener)Class.forName(
1532 listenerClassName).newInstance());
1533 }
1534
1535 _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1536 }
1537 catch (Exception e) {
1538 _log.error(e);
1539 }
1540 }
1541
1542 containsSCProductEntry = new ContainsSCProductEntry(this);
1543
1544 addSCProductEntry = new AddSCProductEntry(this);
1545 clearSCProductEntries = new ClearSCProductEntries(this);
1546 removeSCProductEntry = new RemoveSCProductEntry(this);
1547 }
1548
1549 protected ContainsSCProductEntry containsSCProductEntry;
1550 protected AddSCProductEntry addSCProductEntry;
1551 protected ClearSCProductEntries clearSCProductEntries;
1552 protected RemoveSCProductEntry removeSCProductEntry;
1553
1554 protected class ContainsSCProductEntry {
1555 protected ContainsSCProductEntry(
1556 SCLicensePersistenceImpl persistenceImpl) {
1557 super();
1558
1559 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
1560 _SQL_CONTAINSSCPRODUCTENTRY,
1561 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
1562 }
1563
1564 protected boolean contains(long licenseId, long productEntryId) {
1565 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
1566 new Long(licenseId), new Long(productEntryId)
1567 });
1568
1569 if (results.size() > 0) {
1570 Integer count = results.get(0);
1571
1572 if (count.intValue() > 0) {
1573 return true;
1574 }
1575 }
1576
1577 return false;
1578 }
1579
1580 private MappingSqlQuery _mappingSqlQuery;
1581 }
1582
1583 protected class AddSCProductEntry {
1584 protected AddSCProductEntry(SCLicensePersistenceImpl persistenceImpl) {
1585 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1586 "INSERT INTO SCLicenses_SCProductEntries (licenseId, productEntryId) VALUES (?, ?)",
1587 new int[] { Types.BIGINT, Types.BIGINT });
1588 _persistenceImpl = persistenceImpl;
1589 }
1590
1591 protected void add(long licenseId, long productEntryId) {
1592 if (!_persistenceImpl.containsSCProductEntry.contains(licenseId,
1593 productEntryId)) {
1594 _sqlUpdate.update(new Object[] {
1595 new Long(licenseId), new Long(productEntryId)
1596 });
1597 }
1598 }
1599
1600 private SqlUpdate _sqlUpdate;
1601 private SCLicensePersistenceImpl _persistenceImpl;
1602 }
1603
1604 protected class ClearSCProductEntries {
1605 protected ClearSCProductEntries(
1606 SCLicensePersistenceImpl persistenceImpl) {
1607 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1608 "DELETE FROM SCLicenses_SCProductEntries WHERE licenseId = ?",
1609 new int[] { Types.BIGINT });
1610 }
1611
1612 protected void clear(long licenseId) {
1613 _sqlUpdate.update(new Object[] { new Long(licenseId) });
1614 }
1615
1616 private SqlUpdate _sqlUpdate;
1617 }
1618
1619 protected class RemoveSCProductEntry {
1620 protected RemoveSCProductEntry(SCLicensePersistenceImpl persistenceImpl) {
1621 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
1622 "DELETE FROM SCLicenses_SCProductEntries WHERE licenseId = ? AND productEntryId = ?",
1623 new int[] { Types.BIGINT, Types.BIGINT });
1624 }
1625
1626 protected void remove(long licenseId, long productEntryId) {
1627 _sqlUpdate.update(new Object[] {
1628 new Long(licenseId), new Long(productEntryId)
1629 });
1630 }
1631
1632 private SqlUpdate _sqlUpdate;
1633 }
1634
1635 private static final String _SQL_GETSCPRODUCTENTRIES = "SELECT {SCProductEntry.*} FROM SCProductEntry INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.productEntryId = SCProductEntry.productEntryId) WHERE (SCLicenses_SCProductEntries.licenseId = ?)";
1636 private static final String _SQL_GETSCPRODUCTENTRIESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE licenseId = ?";
1637 private static final String _SQL_CONTAINSSCPRODUCTENTRY = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE licenseId = ? AND productEntryId = ?";
1638 private static Log _log = LogFactory.getLog(SCLicensePersistenceImpl.class);
1639 private ModelListener[] _listeners = new ModelListener[0];
1640}