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