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