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