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