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