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