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