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