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