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