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