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