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.NoSuchProductEntryException;
40  import com.liferay.portlet.softwarecatalog.model.SCProductEntry;
41  import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryImpl;
42  import com.liferay.portlet.softwarecatalog.model.impl.SCProductEntryModelImpl;
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="SCProductEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
72   *
73   * @author Brian Wing Shun Chan
74   *
75   */
76  public class SCProductEntryPersistenceImpl extends BasePersistence
77      implements SCProductEntryPersistence {
78      public SCProductEntry create(long productEntryId) {
79          SCProductEntry scProductEntry = new SCProductEntryImpl();
80  
81          scProductEntry.setNew(true);
82          scProductEntry.setPrimaryKey(productEntryId);
83  
84          return scProductEntry;
85      }
86  
87      public SCProductEntry remove(long productEntryId)
88          throws NoSuchProductEntryException, SystemException {
89          Session session = null;
90  
91          try {
92              session = openSession();
93  
94              SCProductEntry scProductEntry = (SCProductEntry)session.get(SCProductEntryImpl.class,
95                      new Long(productEntryId));
96  
97              if (scProductEntry == null) {
98                  if (_log.isWarnEnabled()) {
99                      _log.warn("No SCProductEntry exists with the primary key " +
100                         productEntryId);
101                 }
102 
103                 throw new NoSuchProductEntryException(
104                     "No SCProductEntry exists with the primary key " +
105                     productEntryId);
106             }
107 
108             return remove(scProductEntry);
109         }
110         catch (NoSuchProductEntryException nsee) {
111             throw nsee;
112         }
113         catch (Exception e) {
114             throw HibernateUtil.processException(e);
115         }
116         finally {
117             closeSession(session);
118         }
119     }
120 
121     public SCProductEntry remove(SCProductEntry scProductEntry)
122         throws SystemException {
123         if (_listeners != null) {
124             for (ModelListener listener : _listeners) {
125                 listener.onBeforeRemove(scProductEntry);
126             }
127         }
128 
129         scProductEntry = removeImpl(scProductEntry);
130 
131         if (_listeners != null) {
132             for (ModelListener listener : _listeners) {
133                 listener.onAfterRemove(scProductEntry);
134             }
135         }
136 
137         return scProductEntry;
138     }
139 
140     protected SCProductEntry removeImpl(SCProductEntry scProductEntry)
141         throws SystemException {
142         try {
143             clearSCLicenses.clear(scProductEntry.getPrimaryKey());
144         }
145         catch (Exception e) {
146             throw HibernateUtil.processException(e);
147         }
148         finally {
149             FinderCache.clearCache("SCLicenses_SCProductEntries");
150         }
151 
152         Session session = null;
153 
154         try {
155             session = openSession();
156 
157             session.delete(scProductEntry);
158 
159             session.flush();
160 
161             return scProductEntry;
162         }
163         catch (Exception e) {
164             throw HibernateUtil.processException(e);
165         }
166         finally {
167             closeSession(session);
168 
169             FinderCache.clearCache(SCProductEntry.class.getName());
170         }
171     }
172 
173     /**
174      * @deprecated Use <code>update(SCProductEntry scProductEntry, boolean merge)</code>.
175      */
176     public SCProductEntry update(SCProductEntry scProductEntry)
177         throws SystemException {
178         if (_log.isWarnEnabled()) {
179             _log.warn(
180                 "Using the deprecated update(SCProductEntry scProductEntry) method. Use update(SCProductEntry scProductEntry, boolean merge) instead.");
181         }
182 
183         return update(scProductEntry, false);
184     }
185 
186     /**
187      * Add, update, or merge, the entity. This method also calls the model
188      * listeners to trigger the proper events associated with adding, deleting,
189      * or updating an entity.
190      *
191      * @param        scProductEntry the entity to add, update, or merge
192      * @param        merge boolean value for whether to merge the entity. The
193      *                default value is false. Setting merge to true is more
194      *                expensive and should only be true when scProductEntry is
195      *                transient. See LEP-5473 for a detailed discussion of this
196      *                method.
197      * @return        true if the portlet can be displayed via Ajax
198      */
199     public SCProductEntry update(SCProductEntry scProductEntry, boolean merge)
200         throws SystemException {
201         boolean isNew = scProductEntry.isNew();
202 
203         if (_listeners != null) {
204             for (ModelListener listener : _listeners) {
205                 if (isNew) {
206                     listener.onBeforeCreate(scProductEntry);
207                 }
208                 else {
209                     listener.onBeforeUpdate(scProductEntry);
210                 }
211             }
212         }
213 
214         scProductEntry = updateImpl(scProductEntry, merge);
215 
216         if (_listeners != null) {
217             for (ModelListener listener : _listeners) {
218                 if (isNew) {
219                     listener.onAfterCreate(scProductEntry);
220                 }
221                 else {
222                     listener.onAfterUpdate(scProductEntry);
223                 }
224             }
225         }
226 
227         return scProductEntry;
228     }
229 
230     public SCProductEntry updateImpl(
231         com.liferay.portlet.softwarecatalog.model.SCProductEntry scProductEntry,
232         boolean merge) throws SystemException {
233         FinderCache.clearCache("SCLicenses_SCProductEntries");
234 
235         Session session = null;
236 
237         try {
238             session = openSession();
239 
240             if (merge) {
241                 session.merge(scProductEntry);
242             }
243             else {
244                 if (scProductEntry.isNew()) {
245                     session.save(scProductEntry);
246                 }
247             }
248 
249             session.flush();
250 
251             scProductEntry.setNew(false);
252 
253             return scProductEntry;
254         }
255         catch (Exception e) {
256             throw HibernateUtil.processException(e);
257         }
258         finally {
259             closeSession(session);
260 
261             FinderCache.clearCache(SCProductEntry.class.getName());
262         }
263     }
264 
265     public SCProductEntry findByPrimaryKey(long productEntryId)
266         throws NoSuchProductEntryException, SystemException {
267         SCProductEntry scProductEntry = fetchByPrimaryKey(productEntryId);
268 
269         if (scProductEntry == null) {
270             if (_log.isWarnEnabled()) {
271                 _log.warn("No SCProductEntry exists with the primary key " +
272                     productEntryId);
273             }
274 
275             throw new NoSuchProductEntryException(
276                 "No SCProductEntry exists with the primary key " +
277                 productEntryId);
278         }
279 
280         return scProductEntry;
281     }
282 
283     public SCProductEntry fetchByPrimaryKey(long productEntryId)
284         throws SystemException {
285         Session session = null;
286 
287         try {
288             session = openSession();
289 
290             return (SCProductEntry)session.get(SCProductEntryImpl.class,
291                 new Long(productEntryId));
292         }
293         catch (Exception e) {
294             throw HibernateUtil.processException(e);
295         }
296         finally {
297             closeSession(session);
298         }
299     }
300 
301     public List<SCProductEntry> findByGroupId(long groupId)
302         throws SystemException {
303         boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
304         String finderClassName = SCProductEntry.class.getName();
305         String finderMethodName = "findByGroupId";
306         String[] finderParams = new String[] { Long.class.getName() };
307         Object[] finderArgs = new Object[] { new Long(groupId) };
308 
309         Object result = null;
310 
311         if (finderClassNameCacheEnabled) {
312             result = FinderCache.getResult(finderClassName, finderMethodName,
313                     finderParams, finderArgs, getSessionFactory());
314         }
315 
316         if (result == null) {
317             Session session = null;
318 
319             try {
320                 session = openSession();
321 
322                 StringMaker query = new StringMaker();
323 
324                 query.append(
325                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
326 
327                 query.append("groupId = ?");
328 
329                 query.append(" ");
330 
331                 query.append("ORDER BY ");
332 
333                 query.append("modifiedDate DESC, ");
334                 query.append("name DESC");
335 
336                 Query q = session.createQuery(query.toString());
337 
338                 int queryPos = 0;
339 
340                 q.setLong(queryPos++, groupId);
341 
342                 List<SCProductEntry> list = q.list();
343 
344                 FinderCache.putResult(finderClassNameCacheEnabled,
345                     finderClassName, finderMethodName, finderParams,
346                     finderArgs, list);
347 
348                 return list;
349             }
350             catch (Exception e) {
351                 throw HibernateUtil.processException(e);
352             }
353             finally {
354                 closeSession(session);
355             }
356         }
357         else {
358             return (List<SCProductEntry>)result;
359         }
360     }
361 
362     public List<SCProductEntry> findByGroupId(long groupId, int begin, int end)
363         throws SystemException {
364         return findByGroupId(groupId, begin, end, null);
365     }
366 
367     public List<SCProductEntry> findByGroupId(long groupId, int begin, int end,
368         OrderByComparator obc) throws SystemException {
369         boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
370         String finderClassName = SCProductEntry.class.getName();
371         String finderMethodName = "findByGroupId";
372         String[] finderParams = new String[] {
373                 Long.class.getName(),
374                 
375                 "java.lang.Integer", "java.lang.Integer",
376                 "com.liferay.portal.kernel.util.OrderByComparator"
377             };
378         Object[] finderArgs = new Object[] {
379                 new Long(groupId),
380                 
381                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
382             };
383 
384         Object result = null;
385 
386         if (finderClassNameCacheEnabled) {
387             result = FinderCache.getResult(finderClassName, finderMethodName,
388                     finderParams, finderArgs, getSessionFactory());
389         }
390 
391         if (result == null) {
392             Session session = null;
393 
394             try {
395                 session = openSession();
396 
397                 StringMaker query = new StringMaker();
398 
399                 query.append(
400                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
401 
402                 query.append("groupId = ?");
403 
404                 query.append(" ");
405 
406                 if (obc != null) {
407                     query.append("ORDER BY ");
408                     query.append(obc.getOrderBy());
409                 }
410 
411                 else {
412                     query.append("ORDER BY ");
413 
414                     query.append("modifiedDate DESC, ");
415                     query.append("name DESC");
416                 }
417 
418                 Query q = session.createQuery(query.toString());
419 
420                 int queryPos = 0;
421 
422                 q.setLong(queryPos++, groupId);
423 
424                 List<SCProductEntry> list = (List<SCProductEntry>)QueryUtil.list(q,
425                         getDialect(), begin, end);
426 
427                 FinderCache.putResult(finderClassNameCacheEnabled,
428                     finderClassName, finderMethodName, finderParams,
429                     finderArgs, list);
430 
431                 return list;
432             }
433             catch (Exception e) {
434                 throw HibernateUtil.processException(e);
435             }
436             finally {
437                 closeSession(session);
438             }
439         }
440         else {
441             return (List<SCProductEntry>)result;
442         }
443     }
444 
445     public SCProductEntry findByGroupId_First(long groupId,
446         OrderByComparator obc)
447         throws NoSuchProductEntryException, SystemException {
448         List<SCProductEntry> list = findByGroupId(groupId, 0, 1, obc);
449 
450         if (list.size() == 0) {
451             StringMaker msg = new StringMaker();
452 
453             msg.append("No SCProductEntry exists with the key {");
454 
455             msg.append("groupId=" + groupId);
456 
457             msg.append(StringPool.CLOSE_CURLY_BRACE);
458 
459             throw new NoSuchProductEntryException(msg.toString());
460         }
461         else {
462             return list.get(0);
463         }
464     }
465 
466     public SCProductEntry findByGroupId_Last(long groupId, OrderByComparator obc)
467         throws NoSuchProductEntryException, SystemException {
468         int count = countByGroupId(groupId);
469 
470         List<SCProductEntry> list = findByGroupId(groupId, count - 1, count, obc);
471 
472         if (list.size() == 0) {
473             StringMaker msg = new StringMaker();
474 
475             msg.append("No SCProductEntry exists with the key {");
476 
477             msg.append("groupId=" + groupId);
478 
479             msg.append(StringPool.CLOSE_CURLY_BRACE);
480 
481             throw new NoSuchProductEntryException(msg.toString());
482         }
483         else {
484             return list.get(0);
485         }
486     }
487 
488     public SCProductEntry[] findByGroupId_PrevAndNext(long productEntryId,
489         long groupId, OrderByComparator obc)
490         throws NoSuchProductEntryException, SystemException {
491         SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
492 
493         int count = countByGroupId(groupId);
494 
495         Session session = null;
496 
497         try {
498             session = openSession();
499 
500             StringMaker query = new StringMaker();
501 
502             query.append(
503                 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
504 
505             query.append("groupId = ?");
506 
507             query.append(" ");
508 
509             if (obc != null) {
510                 query.append("ORDER BY ");
511                 query.append(obc.getOrderBy());
512             }
513 
514             else {
515                 query.append("ORDER BY ");
516 
517                 query.append("modifiedDate DESC, ");
518                 query.append("name DESC");
519             }
520 
521             Query q = session.createQuery(query.toString());
522 
523             int queryPos = 0;
524 
525             q.setLong(queryPos++, groupId);
526 
527             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
528                     scProductEntry);
529 
530             SCProductEntry[] array = new SCProductEntryImpl[3];
531 
532             array[0] = (SCProductEntry)objArray[0];
533             array[1] = (SCProductEntry)objArray[1];
534             array[2] = (SCProductEntry)objArray[2];
535 
536             return array;
537         }
538         catch (Exception e) {
539             throw HibernateUtil.processException(e);
540         }
541         finally {
542             closeSession(session);
543         }
544     }
545 
546     public List<SCProductEntry> findByCompanyId(long companyId)
547         throws SystemException {
548         boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
549         String finderClassName = SCProductEntry.class.getName();
550         String finderMethodName = "findByCompanyId";
551         String[] finderParams = new String[] { Long.class.getName() };
552         Object[] finderArgs = new Object[] { new Long(companyId) };
553 
554         Object result = null;
555 
556         if (finderClassNameCacheEnabled) {
557             result = FinderCache.getResult(finderClassName, finderMethodName,
558                     finderParams, finderArgs, getSessionFactory());
559         }
560 
561         if (result == null) {
562             Session session = null;
563 
564             try {
565                 session = openSession();
566 
567                 StringMaker query = new StringMaker();
568 
569                 query.append(
570                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
571 
572                 query.append("companyId = ?");
573 
574                 query.append(" ");
575 
576                 query.append("ORDER BY ");
577 
578                 query.append("modifiedDate DESC, ");
579                 query.append("name DESC");
580 
581                 Query q = session.createQuery(query.toString());
582 
583                 int queryPos = 0;
584 
585                 q.setLong(queryPos++, companyId);
586 
587                 List<SCProductEntry> 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<SCProductEntry>)result;
604         }
605     }
606 
607     public List<SCProductEntry> findByCompanyId(long companyId, int begin,
608         int end) throws SystemException {
609         return findByCompanyId(companyId, begin, end, null);
610     }
611 
612     public List<SCProductEntry> findByCompanyId(long companyId, int begin,
613         int end, OrderByComparator obc) throws SystemException {
614         boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
615         String finderClassName = SCProductEntry.class.getName();
616         String finderMethodName = "findByCompanyId";
617         String[] finderParams = new String[] {
618                 Long.class.getName(),
619                 
620                 "java.lang.Integer", "java.lang.Integer",
621                 "com.liferay.portal.kernel.util.OrderByComparator"
622             };
623         Object[] finderArgs = new Object[] {
624                 new Long(companyId),
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.SCProductEntry WHERE ");
646 
647                 query.append("companyId = ?");
648 
649                 query.append(" ");
650 
651                 if (obc != null) {
652                     query.append("ORDER BY ");
653                     query.append(obc.getOrderBy());
654                 }
655 
656                 else {
657                     query.append("ORDER BY ");
658 
659                     query.append("modifiedDate DESC, ");
660                     query.append("name DESC");
661                 }
662 
663                 Query q = session.createQuery(query.toString());
664 
665                 int queryPos = 0;
666 
667                 q.setLong(queryPos++, companyId);
668 
669                 List<SCProductEntry> list = (List<SCProductEntry>)QueryUtil.list(q,
670                         getDialect(), begin, end);
671 
672                 FinderCache.putResult(finderClassNameCacheEnabled,
673                     finderClassName, finderMethodName, finderParams,
674                     finderArgs, list);
675 
676                 return list;
677             }
678             catch (Exception e) {
679                 throw HibernateUtil.processException(e);
680             }
681             finally {
682                 closeSession(session);
683             }
684         }
685         else {
686             return (List<SCProductEntry>)result;
687         }
688     }
689 
690     public SCProductEntry findByCompanyId_First(long companyId,
691         OrderByComparator obc)
692         throws NoSuchProductEntryException, SystemException {
693         List<SCProductEntry> list = findByCompanyId(companyId, 0, 1, obc);
694 
695         if (list.size() == 0) {
696             StringMaker msg = new StringMaker();
697 
698             msg.append("No SCProductEntry exists with the key {");
699 
700             msg.append("companyId=" + companyId);
701 
702             msg.append(StringPool.CLOSE_CURLY_BRACE);
703 
704             throw new NoSuchProductEntryException(msg.toString());
705         }
706         else {
707             return list.get(0);
708         }
709     }
710 
711     public SCProductEntry findByCompanyId_Last(long companyId,
712         OrderByComparator obc)
713         throws NoSuchProductEntryException, SystemException {
714         int count = countByCompanyId(companyId);
715 
716         List<SCProductEntry> list = findByCompanyId(companyId, count - 1,
717                 count, obc);
718 
719         if (list.size() == 0) {
720             StringMaker msg = new StringMaker();
721 
722             msg.append("No SCProductEntry exists with the key {");
723 
724             msg.append("companyId=" + companyId);
725 
726             msg.append(StringPool.CLOSE_CURLY_BRACE);
727 
728             throw new NoSuchProductEntryException(msg.toString());
729         }
730         else {
731             return list.get(0);
732         }
733     }
734 
735     public SCProductEntry[] findByCompanyId_PrevAndNext(long productEntryId,
736         long companyId, OrderByComparator obc)
737         throws NoSuchProductEntryException, SystemException {
738         SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
739 
740         int count = countByCompanyId(companyId);
741 
742         Session session = null;
743 
744         try {
745             session = openSession();
746 
747             StringMaker query = new StringMaker();
748 
749             query.append(
750                 "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
751 
752             query.append("companyId = ?");
753 
754             query.append(" ");
755 
756             if (obc != null) {
757                 query.append("ORDER BY ");
758                 query.append(obc.getOrderBy());
759             }
760 
761             else {
762                 query.append("ORDER BY ");
763 
764                 query.append("modifiedDate DESC, ");
765                 query.append("name DESC");
766             }
767 
768             Query q = session.createQuery(query.toString());
769 
770             int queryPos = 0;
771 
772             q.setLong(queryPos++, companyId);
773 
774             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
775                     scProductEntry);
776 
777             SCProductEntry[] array = new SCProductEntryImpl[3];
778 
779             array[0] = (SCProductEntry)objArray[0];
780             array[1] = (SCProductEntry)objArray[1];
781             array[2] = (SCProductEntry)objArray[2];
782 
783             return array;
784         }
785         catch (Exception e) {
786             throw HibernateUtil.processException(e);
787         }
788         finally {
789             closeSession(session);
790         }
791     }
792 
793     public List<SCProductEntry> findByG_U(long groupId, long userId)
794         throws SystemException {
795         boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
796         String finderClassName = SCProductEntry.class.getName();
797         String finderMethodName = "findByG_U";
798         String[] finderParams = new String[] {
799                 Long.class.getName(), Long.class.getName()
800             };
801         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
802 
803         Object result = null;
804 
805         if (finderClassNameCacheEnabled) {
806             result = FinderCache.getResult(finderClassName, finderMethodName,
807                     finderParams, finderArgs, getSessionFactory());
808         }
809 
810         if (result == null) {
811             Session session = null;
812 
813             try {
814                 session = openSession();
815 
816                 StringMaker query = new StringMaker();
817 
818                 query.append(
819                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
820 
821                 query.append("groupId = ?");
822 
823                 query.append(" AND ");
824 
825                 query.append("userId = ?");
826 
827                 query.append(" ");
828 
829                 query.append("ORDER BY ");
830 
831                 query.append("modifiedDate DESC, ");
832                 query.append("name DESC");
833 
834                 Query q = session.createQuery(query.toString());
835 
836                 int queryPos = 0;
837 
838                 q.setLong(queryPos++, groupId);
839 
840                 q.setLong(queryPos++, userId);
841 
842                 List<SCProductEntry> list = q.list();
843 
844                 FinderCache.putResult(finderClassNameCacheEnabled,
845                     finderClassName, finderMethodName, finderParams,
846                     finderArgs, list);
847 
848                 return list;
849             }
850             catch (Exception e) {
851                 throw HibernateUtil.processException(e);
852             }
853             finally {
854                 closeSession(session);
855             }
856         }
857         else {
858             return (List<SCProductEntry>)result;
859         }
860     }
861 
862     public List<SCProductEntry> findByG_U(long groupId, long userId, int begin,
863         int end) throws SystemException {
864         return findByG_U(groupId, userId, begin, end, null);
865     }
866 
867     public List<SCProductEntry> findByG_U(long groupId, long userId, int begin,
868         int end, OrderByComparator obc) throws SystemException {
869         boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
870         String finderClassName = SCProductEntry.class.getName();
871         String finderMethodName = "findByG_U";
872         String[] finderParams = new String[] {
873                 Long.class.getName(), Long.class.getName(),
874                 
875                 "java.lang.Integer", "java.lang.Integer",
876                 "com.liferay.portal.kernel.util.OrderByComparator"
877             };
878         Object[] finderArgs = new Object[] {
879                 new Long(groupId), new Long(userId),
880                 
881                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
882             };
883 
884         Object result = null;
885 
886         if (finderClassNameCacheEnabled) {
887             result = FinderCache.getResult(finderClassName, finderMethodName,
888                     finderParams, finderArgs, getSessionFactory());
889         }
890 
891         if (result == null) {
892             Session session = null;
893 
894             try {
895                 session = openSession();
896 
897                 StringMaker query = new StringMaker();
898 
899                 query.append(
900                     "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
901 
902                 query.append("groupId = ?");
903 
904                 query.append(" AND ");
905 
906                 query.append("userId = ?");
907 
908                 query.append(" ");
909 
910                 if (obc != null) {
911                     query.append("ORDER BY ");
912                     query.append(obc.getOrderBy());
913                 }
914 
915                 else {
916                     query.append("ORDER BY ");
917 
918                     query.append("modifiedDate DESC, ");
919                     query.append("name DESC");
920                 }
921 
922                 Query q = session.createQuery(query.toString());
923 
924                 int queryPos = 0;
925 
926                 q.setLong(queryPos++, groupId);
927 
928                 q.setLong(queryPos++, userId);
929 
930                 List<SCProductEntry> list = (List<SCProductEntry>)QueryUtil.list(q,
931                         getDialect(), begin, end);
932 
933                 FinderCache.putResult(finderClassNameCacheEnabled,
934                     finderClassName, finderMethodName, finderParams,
935                     finderArgs, list);
936 
937                 return list;
938             }
939             catch (Exception e) {
940                 throw HibernateUtil.processException(e);
941             }
942             finally {
943                 closeSession(session);
944             }
945         }
946         else {
947             return (List<SCProductEntry>)result;
948         }
949     }
950 
951     public SCProductEntry findByG_U_First(long groupId, long userId,
952         OrderByComparator obc)
953         throws NoSuchProductEntryException, SystemException {
954         List<SCProductEntry> list = findByG_U(groupId, userId, 0, 1, obc);
955 
956         if (list.size() == 0) {
957             StringMaker msg = new StringMaker();
958 
959             msg.append("No SCProductEntry exists with the key {");
960 
961             msg.append("groupId=" + groupId);
962 
963             msg.append(", ");
964             msg.append("userId=" + userId);
965 
966             msg.append(StringPool.CLOSE_CURLY_BRACE);
967 
968             throw new NoSuchProductEntryException(msg.toString());
969         }
970         else {
971             return list.get(0);
972         }
973     }
974 
975     public SCProductEntry findByG_U_Last(long groupId, long userId,
976         OrderByComparator obc)
977         throws NoSuchProductEntryException, SystemException {
978         int count = countByG_U(groupId, userId);
979 
980         List<SCProductEntry> list = findByG_U(groupId, userId, count - 1,
981                 count, obc);
982 
983         if (list.size() == 0) {
984             StringMaker msg = new StringMaker();
985 
986             msg.append("No SCProductEntry exists with the key {");
987 
988             msg.append("groupId=" + groupId);
989 
990             msg.append(", ");
991             msg.append("userId=" + userId);
992 
993             msg.append(StringPool.CLOSE_CURLY_BRACE);
994 
995             throw new NoSuchProductEntryException(msg.toString());
996         }
997         else {
998             return list.get(0);
999         }
1000    }
1001
1002    public SCProductEntry[] findByG_U_PrevAndNext(long productEntryId,
1003        long groupId, long userId, OrderByComparator obc)
1004        throws NoSuchProductEntryException, SystemException {
1005        SCProductEntry scProductEntry = findByPrimaryKey(productEntryId);
1006
1007        int count = countByG_U(groupId, userId);
1008
1009        Session session = null;
1010
1011        try {
1012            session = openSession();
1013
1014            StringMaker query = new StringMaker();
1015
1016            query.append(
1017                "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1018
1019            query.append("groupId = ?");
1020
1021            query.append(" AND ");
1022
1023            query.append("userId = ?");
1024
1025            query.append(" ");
1026
1027            if (obc != null) {
1028                query.append("ORDER BY ");
1029                query.append(obc.getOrderBy());
1030            }
1031
1032            else {
1033                query.append("ORDER BY ");
1034
1035                query.append("modifiedDate DESC, ");
1036                query.append("name DESC");
1037            }
1038
1039            Query q = session.createQuery(query.toString());
1040
1041            int queryPos = 0;
1042
1043            q.setLong(queryPos++, groupId);
1044
1045            q.setLong(queryPos++, userId);
1046
1047            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1048                    scProductEntry);
1049
1050            SCProductEntry[] array = new SCProductEntryImpl[3];
1051
1052            array[0] = (SCProductEntry)objArray[0];
1053            array[1] = (SCProductEntry)objArray[1];
1054            array[2] = (SCProductEntry)objArray[2];
1055
1056            return array;
1057        }
1058        catch (Exception e) {
1059            throw HibernateUtil.processException(e);
1060        }
1061        finally {
1062            closeSession(session);
1063        }
1064    }
1065
1066    public SCProductEntry findByRG_RA(String repoGroupId, String repoArtifactId)
1067        throws NoSuchProductEntryException, SystemException {
1068        SCProductEntry scProductEntry = fetchByRG_RA(repoGroupId, repoArtifactId);
1069
1070        if (scProductEntry == null) {
1071            StringMaker msg = new StringMaker();
1072
1073            msg.append("No SCProductEntry exists with the key {");
1074
1075            msg.append("repoGroupId=" + repoGroupId);
1076
1077            msg.append(", ");
1078            msg.append("repoArtifactId=" + repoArtifactId);
1079
1080            msg.append(StringPool.CLOSE_CURLY_BRACE);
1081
1082            if (_log.isWarnEnabled()) {
1083                _log.warn(msg.toString());
1084            }
1085
1086            throw new NoSuchProductEntryException(msg.toString());
1087        }
1088
1089        return scProductEntry;
1090    }
1091
1092    public SCProductEntry fetchByRG_RA(String repoGroupId, String repoArtifactId)
1093        throws SystemException {
1094        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1095        String finderClassName = SCProductEntry.class.getName();
1096        String finderMethodName = "fetchByRG_RA";
1097        String[] finderParams = new String[] {
1098                String.class.getName(), String.class.getName()
1099            };
1100        Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1101
1102        Object result = null;
1103
1104        if (finderClassNameCacheEnabled) {
1105            result = FinderCache.getResult(finderClassName, finderMethodName,
1106                    finderParams, finderArgs, getSessionFactory());
1107        }
1108
1109        if (result == null) {
1110            Session session = null;
1111
1112            try {
1113                session = openSession();
1114
1115                StringMaker query = new StringMaker();
1116
1117                query.append(
1118                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1119
1120                if (repoGroupId == null) {
1121                    query.append("repoGroupId IS NULL");
1122                }
1123                else {
1124                    query.append("lower(repoGroupId) = ?");
1125                }
1126
1127                query.append(" AND ");
1128
1129                if (repoArtifactId == null) {
1130                    query.append("repoArtifactId IS NULL");
1131                }
1132                else {
1133                    query.append("lower(repoArtifactId) = ?");
1134                }
1135
1136                query.append(" ");
1137
1138                query.append("ORDER BY ");
1139
1140                query.append("modifiedDate DESC, ");
1141                query.append("name DESC");
1142
1143                Query q = session.createQuery(query.toString());
1144
1145                int queryPos = 0;
1146
1147                if (repoGroupId != null) {
1148                    q.setString(queryPos++, repoGroupId);
1149                }
1150
1151                if (repoArtifactId != null) {
1152                    q.setString(queryPos++, repoArtifactId);
1153                }
1154
1155                List<SCProductEntry> list = q.list();
1156
1157                FinderCache.putResult(finderClassNameCacheEnabled,
1158                    finderClassName, finderMethodName, finderParams,
1159                    finderArgs, list);
1160
1161                if (list.size() == 0) {
1162                    return null;
1163                }
1164                else {
1165                    return list.get(0);
1166                }
1167            }
1168            catch (Exception e) {
1169                throw HibernateUtil.processException(e);
1170            }
1171            finally {
1172                closeSession(session);
1173            }
1174        }
1175        else {
1176            List<SCProductEntry> list = (List<SCProductEntry>)result;
1177
1178            if (list.size() == 0) {
1179                return null;
1180            }
1181            else {
1182                return list.get(0);
1183            }
1184        }
1185    }
1186
1187    public List<SCProductEntry> findWithDynamicQuery(
1188        DynamicQueryInitializer queryInitializer) throws SystemException {
1189        Session session = null;
1190
1191        try {
1192            session = openSession();
1193
1194            DynamicQuery query = queryInitializer.initialize(session);
1195
1196            return query.list();
1197        }
1198        catch (Exception e) {
1199            throw HibernateUtil.processException(e);
1200        }
1201        finally {
1202            closeSession(session);
1203        }
1204    }
1205
1206    public List<SCProductEntry> findWithDynamicQuery(
1207        DynamicQueryInitializer queryInitializer, int begin, int end)
1208        throws SystemException {
1209        Session session = null;
1210
1211        try {
1212            session = openSession();
1213
1214            DynamicQuery query = queryInitializer.initialize(session);
1215
1216            query.setLimit(begin, end);
1217
1218            return query.list();
1219        }
1220        catch (Exception e) {
1221            throw HibernateUtil.processException(e);
1222        }
1223        finally {
1224            closeSession(session);
1225        }
1226    }
1227
1228    public List<SCProductEntry> findAll() throws SystemException {
1229        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1230    }
1231
1232    public List<SCProductEntry> findAll(int begin, int end)
1233        throws SystemException {
1234        return findAll(begin, end, null);
1235    }
1236
1237    public List<SCProductEntry> findAll(int begin, int end,
1238        OrderByComparator obc) throws SystemException {
1239        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1240        String finderClassName = SCProductEntry.class.getName();
1241        String finderMethodName = "findAll";
1242        String[] finderParams = new String[] {
1243                "java.lang.Integer", "java.lang.Integer",
1244                "com.liferay.portal.kernel.util.OrderByComparator"
1245            };
1246        Object[] finderArgs = new Object[] {
1247                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1248            };
1249
1250        Object result = null;
1251
1252        if (finderClassNameCacheEnabled) {
1253            result = FinderCache.getResult(finderClassName, finderMethodName,
1254                    finderParams, finderArgs, getSessionFactory());
1255        }
1256
1257        if (result == null) {
1258            Session session = null;
1259
1260            try {
1261                session = openSession();
1262
1263                StringMaker query = new StringMaker();
1264
1265                query.append(
1266                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry ");
1267
1268                if (obc != null) {
1269                    query.append("ORDER BY ");
1270                    query.append(obc.getOrderBy());
1271                }
1272
1273                else {
1274                    query.append("ORDER BY ");
1275
1276                    query.append("modifiedDate DESC, ");
1277                    query.append("name DESC");
1278                }
1279
1280                Query q = session.createQuery(query.toString());
1281
1282                List<SCProductEntry> list = (List<SCProductEntry>)QueryUtil.list(q,
1283                        getDialect(), begin, end);
1284
1285                if (obc == null) {
1286                    Collections.sort(list);
1287                }
1288
1289                FinderCache.putResult(finderClassNameCacheEnabled,
1290                    finderClassName, finderMethodName, finderParams,
1291                    finderArgs, list);
1292
1293                return list;
1294            }
1295            catch (Exception e) {
1296                throw HibernateUtil.processException(e);
1297            }
1298            finally {
1299                closeSession(session);
1300            }
1301        }
1302        else {
1303            return (List<SCProductEntry>)result;
1304        }
1305    }
1306
1307    public void removeByGroupId(long groupId) throws SystemException {
1308        for (SCProductEntry scProductEntry : findByGroupId(groupId)) {
1309            remove(scProductEntry);
1310        }
1311    }
1312
1313    public void removeByCompanyId(long companyId) throws SystemException {
1314        for (SCProductEntry scProductEntry : findByCompanyId(companyId)) {
1315            remove(scProductEntry);
1316        }
1317    }
1318
1319    public void removeByG_U(long groupId, long userId)
1320        throws SystemException {
1321        for (SCProductEntry scProductEntry : findByG_U(groupId, userId)) {
1322            remove(scProductEntry);
1323        }
1324    }
1325
1326    public void removeByRG_RA(String repoGroupId, String repoArtifactId)
1327        throws NoSuchProductEntryException, SystemException {
1328        SCProductEntry scProductEntry = findByRG_RA(repoGroupId, repoArtifactId);
1329
1330        remove(scProductEntry);
1331    }
1332
1333    public void removeAll() throws SystemException {
1334        for (SCProductEntry scProductEntry : findAll()) {
1335            remove(scProductEntry);
1336        }
1337    }
1338
1339    public int countByGroupId(long groupId) throws SystemException {
1340        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1341        String finderClassName = SCProductEntry.class.getName();
1342        String finderMethodName = "countByGroupId";
1343        String[] finderParams = new String[] { Long.class.getName() };
1344        Object[] finderArgs = new Object[] { new Long(groupId) };
1345
1346        Object result = null;
1347
1348        if (finderClassNameCacheEnabled) {
1349            result = FinderCache.getResult(finderClassName, finderMethodName,
1350                    finderParams, finderArgs, getSessionFactory());
1351        }
1352
1353        if (result == null) {
1354            Session session = null;
1355
1356            try {
1357                session = openSession();
1358
1359                StringMaker query = new StringMaker();
1360
1361                query.append("SELECT COUNT(*) ");
1362                query.append(
1363                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1364
1365                query.append("groupId = ?");
1366
1367                query.append(" ");
1368
1369                Query q = session.createQuery(query.toString());
1370
1371                int queryPos = 0;
1372
1373                q.setLong(queryPos++, groupId);
1374
1375                Long count = null;
1376
1377                Iterator<Long> itr = q.list().iterator();
1378
1379                if (itr.hasNext()) {
1380                    count = itr.next();
1381                }
1382
1383                if (count == null) {
1384                    count = new Long(0);
1385                }
1386
1387                FinderCache.putResult(finderClassNameCacheEnabled,
1388                    finderClassName, finderMethodName, finderParams,
1389                    finderArgs, count);
1390
1391                return count.intValue();
1392            }
1393            catch (Exception e) {
1394                throw HibernateUtil.processException(e);
1395            }
1396            finally {
1397                closeSession(session);
1398            }
1399        }
1400        else {
1401            return ((Long)result).intValue();
1402        }
1403    }
1404
1405    public int countByCompanyId(long companyId) throws SystemException {
1406        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1407        String finderClassName = SCProductEntry.class.getName();
1408        String finderMethodName = "countByCompanyId";
1409        String[] finderParams = new String[] { Long.class.getName() };
1410        Object[] finderArgs = new Object[] { new Long(companyId) };
1411
1412        Object result = null;
1413
1414        if (finderClassNameCacheEnabled) {
1415            result = FinderCache.getResult(finderClassName, finderMethodName,
1416                    finderParams, finderArgs, getSessionFactory());
1417        }
1418
1419        if (result == null) {
1420            Session session = null;
1421
1422            try {
1423                session = openSession();
1424
1425                StringMaker query = new StringMaker();
1426
1427                query.append("SELECT COUNT(*) ");
1428                query.append(
1429                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1430
1431                query.append("companyId = ?");
1432
1433                query.append(" ");
1434
1435                Query q = session.createQuery(query.toString());
1436
1437                int queryPos = 0;
1438
1439                q.setLong(queryPos++, companyId);
1440
1441                Long count = null;
1442
1443                Iterator<Long> itr = q.list().iterator();
1444
1445                if (itr.hasNext()) {
1446                    count = itr.next();
1447                }
1448
1449                if (count == null) {
1450                    count = new Long(0);
1451                }
1452
1453                FinderCache.putResult(finderClassNameCacheEnabled,
1454                    finderClassName, finderMethodName, finderParams,
1455                    finderArgs, count);
1456
1457                return count.intValue();
1458            }
1459            catch (Exception e) {
1460                throw HibernateUtil.processException(e);
1461            }
1462            finally {
1463                closeSession(session);
1464            }
1465        }
1466        else {
1467            return ((Long)result).intValue();
1468        }
1469    }
1470
1471    public int countByG_U(long groupId, long userId) throws SystemException {
1472        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1473        String finderClassName = SCProductEntry.class.getName();
1474        String finderMethodName = "countByG_U";
1475        String[] finderParams = new String[] {
1476                Long.class.getName(), Long.class.getName()
1477            };
1478        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1479
1480        Object result = null;
1481
1482        if (finderClassNameCacheEnabled) {
1483            result = FinderCache.getResult(finderClassName, finderMethodName,
1484                    finderParams, finderArgs, getSessionFactory());
1485        }
1486
1487        if (result == null) {
1488            Session session = null;
1489
1490            try {
1491                session = openSession();
1492
1493                StringMaker query = new StringMaker();
1494
1495                query.append("SELECT COUNT(*) ");
1496                query.append(
1497                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1498
1499                query.append("groupId = ?");
1500
1501                query.append(" AND ");
1502
1503                query.append("userId = ?");
1504
1505                query.append(" ");
1506
1507                Query q = session.createQuery(query.toString());
1508
1509                int queryPos = 0;
1510
1511                q.setLong(queryPos++, groupId);
1512
1513                q.setLong(queryPos++, userId);
1514
1515                Long count = null;
1516
1517                Iterator<Long> itr = q.list().iterator();
1518
1519                if (itr.hasNext()) {
1520                    count = itr.next();
1521                }
1522
1523                if (count == null) {
1524                    count = new Long(0);
1525                }
1526
1527                FinderCache.putResult(finderClassNameCacheEnabled,
1528                    finderClassName, finderMethodName, finderParams,
1529                    finderArgs, count);
1530
1531                return count.intValue();
1532            }
1533            catch (Exception e) {
1534                throw HibernateUtil.processException(e);
1535            }
1536            finally {
1537                closeSession(session);
1538            }
1539        }
1540        else {
1541            return ((Long)result).intValue();
1542        }
1543    }
1544
1545    public int countByRG_RA(String repoGroupId, String repoArtifactId)
1546        throws SystemException {
1547        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1548        String finderClassName = SCProductEntry.class.getName();
1549        String finderMethodName = "countByRG_RA";
1550        String[] finderParams = new String[] {
1551                String.class.getName(), String.class.getName()
1552            };
1553        Object[] finderArgs = new Object[] { repoGroupId, repoArtifactId };
1554
1555        Object result = null;
1556
1557        if (finderClassNameCacheEnabled) {
1558            result = FinderCache.getResult(finderClassName, finderMethodName,
1559                    finderParams, finderArgs, getSessionFactory());
1560        }
1561
1562        if (result == null) {
1563            Session session = null;
1564
1565            try {
1566                session = openSession();
1567
1568                StringMaker query = new StringMaker();
1569
1570                query.append("SELECT COUNT(*) ");
1571                query.append(
1572                    "FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry WHERE ");
1573
1574                if (repoGroupId == null) {
1575                    query.append("repoGroupId IS NULL");
1576                }
1577                else {
1578                    query.append("lower(repoGroupId) = ?");
1579                }
1580
1581                query.append(" AND ");
1582
1583                if (repoArtifactId == null) {
1584                    query.append("repoArtifactId IS NULL");
1585                }
1586                else {
1587                    query.append("lower(repoArtifactId) = ?");
1588                }
1589
1590                query.append(" ");
1591
1592                Query q = session.createQuery(query.toString());
1593
1594                int queryPos = 0;
1595
1596                if (repoGroupId != null) {
1597                    q.setString(queryPos++, repoGroupId);
1598                }
1599
1600                if (repoArtifactId != null) {
1601                    q.setString(queryPos++, repoArtifactId);
1602                }
1603
1604                Long count = null;
1605
1606                Iterator<Long> itr = q.list().iterator();
1607
1608                if (itr.hasNext()) {
1609                    count = itr.next();
1610                }
1611
1612                if (count == null) {
1613                    count = new Long(0);
1614                }
1615
1616                FinderCache.putResult(finderClassNameCacheEnabled,
1617                    finderClassName, finderMethodName, finderParams,
1618                    finderArgs, count);
1619
1620                return count.intValue();
1621            }
1622            catch (Exception e) {
1623                throw HibernateUtil.processException(e);
1624            }
1625            finally {
1626                closeSession(session);
1627            }
1628        }
1629        else {
1630            return ((Long)result).intValue();
1631        }
1632    }
1633
1634    public int countAll() throws SystemException {
1635        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED;
1636        String finderClassName = SCProductEntry.class.getName();
1637        String finderMethodName = "countAll";
1638        String[] finderParams = new String[] {  };
1639        Object[] finderArgs = new Object[] {  };
1640
1641        Object result = null;
1642
1643        if (finderClassNameCacheEnabled) {
1644            result = FinderCache.getResult(finderClassName, finderMethodName,
1645                    finderParams, finderArgs, getSessionFactory());
1646        }
1647
1648        if (result == null) {
1649            Session session = null;
1650
1651            try {
1652                session = openSession();
1653
1654                Query q = session.createQuery(
1655                        "SELECT COUNT(*) FROM com.liferay.portlet.softwarecatalog.model.SCProductEntry");
1656
1657                Long count = null;
1658
1659                Iterator<Long> itr = q.list().iterator();
1660
1661                if (itr.hasNext()) {
1662                    count = itr.next();
1663                }
1664
1665                if (count == null) {
1666                    count = new Long(0);
1667                }
1668
1669                FinderCache.putResult(finderClassNameCacheEnabled,
1670                    finderClassName, finderMethodName, finderParams,
1671                    finderArgs, count);
1672
1673                return count.intValue();
1674            }
1675            catch (Exception e) {
1676                throw HibernateUtil.processException(e);
1677            }
1678            finally {
1679                closeSession(session);
1680            }
1681        }
1682        else {
1683            return ((Long)result).intValue();
1684        }
1685    }
1686
1687    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1688        long pk) throws NoSuchProductEntryException, SystemException {
1689        return getSCLicenses(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1690    }
1691
1692    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1693        long pk, int begin, int end)
1694        throws NoSuchProductEntryException, SystemException {
1695        return getSCLicenses(pk, begin, end, null);
1696    }
1697
1698    public List<com.liferay.portlet.softwarecatalog.model.SCLicense> getSCLicenses(
1699        long pk, int begin, int end, OrderByComparator obc)
1700        throws NoSuchProductEntryException, SystemException {
1701        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1702
1703        String finderClassName = "SCLicenses_SCProductEntries";
1704
1705        String finderMethodName = "getSCLicenses";
1706        String[] finderParams = new String[] {
1707                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1708                "com.liferay.portal.kernel.util.OrderByComparator"
1709            };
1710        Object[] finderArgs = new Object[] {
1711                new Long(pk), String.valueOf(begin), String.valueOf(end),
1712                String.valueOf(obc)
1713            };
1714
1715        Object result = null;
1716
1717        if (finderClassNameCacheEnabled) {
1718            result = FinderCache.getResult(finderClassName, finderMethodName,
1719                    finderParams, finderArgs, getSessionFactory());
1720        }
1721
1722        if (result == null) {
1723            Session session = null;
1724
1725            try {
1726                session = HibernateUtil.openSession();
1727
1728                StringMaker sm = new StringMaker();
1729
1730                sm.append(_SQL_GETSCLICENSES);
1731
1732                if (obc != null) {
1733                    sm.append("ORDER BY ");
1734                    sm.append(obc.getOrderBy());
1735                }
1736
1737                else {
1738                    sm.append("ORDER BY ");
1739
1740                    sm.append("SCLicense.name ASC");
1741                }
1742
1743                String sql = sm.toString();
1744
1745                SQLQuery q = session.createSQLQuery(sql);
1746
1747                q.addEntity("SCLicense",
1748                    com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl.class);
1749
1750                QueryPos qPos = QueryPos.getInstance(q);
1751
1752                qPos.add(pk);
1753
1754                List<com.liferay.portlet.softwarecatalog.model.SCLicense> list = (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)QueryUtil.list(q,
1755                        getDialect(), begin, end);
1756
1757                FinderCache.putResult(finderClassNameCacheEnabled,
1758                    finderClassName, finderMethodName, finderParams,
1759                    finderArgs, list);
1760
1761                return list;
1762            }
1763            catch (Exception e) {
1764                throw new SystemException(e);
1765            }
1766            finally {
1767                closeSession(session);
1768            }
1769        }
1770        else {
1771            return (List<com.liferay.portlet.softwarecatalog.model.SCLicense>)result;
1772        }
1773    }
1774
1775    public int getSCLicensesSize(long pk) throws SystemException {
1776        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1777
1778        String finderClassName = "SCLicenses_SCProductEntries";
1779
1780        String finderMethodName = "getSCLicensesSize";
1781        String[] finderParams = new String[] { Long.class.getName() };
1782        Object[] finderArgs = new Object[] { new Long(pk) };
1783
1784        Object result = null;
1785
1786        if (finderClassNameCacheEnabled) {
1787            result = FinderCache.getResult(finderClassName, finderMethodName,
1788                    finderParams, finderArgs, getSessionFactory());
1789        }
1790
1791        if (result == null) {
1792            Session session = null;
1793
1794            try {
1795                session = openSession();
1796
1797                SQLQuery q = session.createSQLQuery(_SQL_GETSCLICENSESSIZE);
1798
1799                q.addScalar(HibernateUtil.getCountColumnName(), Hibernate.LONG);
1800
1801                QueryPos qPos = QueryPos.getInstance(q);
1802
1803                qPos.add(pk);
1804
1805                Long count = null;
1806
1807                Iterator<Long> itr = q.list().iterator();
1808
1809                if (itr.hasNext()) {
1810                    count = itr.next();
1811                }
1812
1813                if (count == null) {
1814                    count = new Long(0);
1815                }
1816
1817                FinderCache.putResult(finderClassNameCacheEnabled,
1818                    finderClassName, finderMethodName, finderParams,
1819                    finderArgs, count);
1820
1821                return count.intValue();
1822            }
1823            catch (Exception e) {
1824                throw HibernateUtil.processException(e);
1825            }
1826            finally {
1827                closeSession(session);
1828            }
1829        }
1830        else {
1831            return ((Long)result).intValue();
1832        }
1833    }
1834
1835    public boolean containsSCLicense(long pk, long scLicensePK)
1836        throws SystemException {
1837        boolean finderClassNameCacheEnabled = SCProductEntryModelImpl.CACHE_ENABLED_SCLICENSES_SCPRODUCTENTRIES;
1838
1839        String finderClassName = "SCLicenses_SCProductEntries";
1840
1841        String finderMethodName = "containsSCLicenses";
1842        String[] finderParams = new String[] {
1843                Long.class.getName(),
1844                
1845                Long.class.getName()
1846            };
1847        Object[] finderArgs = new Object[] { new Long(pk), new Long(scLicensePK) };
1848
1849        Object result = null;
1850
1851        if (finderClassNameCacheEnabled) {
1852            result = FinderCache.getResult(finderClassName, finderMethodName,
1853                    finderParams, finderArgs, getSessionFactory());
1854        }
1855
1856        if (result == null) {
1857            try {
1858                Boolean value = Boolean.valueOf(containsSCLicense.contains(pk,
1859                            scLicensePK));
1860
1861                FinderCache.putResult(finderClassNameCacheEnabled,
1862                    finderClassName, finderMethodName, finderParams,
1863                    finderArgs, value);
1864
1865                return value.booleanValue();
1866            }
1867            catch (DataAccessException dae) {
1868                throw new SystemException(dae);
1869            }
1870        }
1871        else {
1872            return ((Boolean)result).booleanValue();
1873        }
1874    }
1875
1876    public boolean containsSCLicenses(long pk) throws SystemException {
1877        if (getSCLicensesSize(pk) > 0) {
1878            return true;
1879        }
1880        else {
1881            return false;
1882        }
1883    }
1884
1885    public void addSCLicense(long pk, long scLicensePK)
1886        throws NoSuchProductEntryException,
1887            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1888            SystemException {
1889        try {
1890            addSCLicense.add(pk, scLicensePK);
1891        }
1892        catch (DataAccessException dae) {
1893            throw new SystemException(dae);
1894        }
1895        finally {
1896            FinderCache.clearCache("SCLicenses_SCProductEntries");
1897        }
1898    }
1899
1900    public void addSCLicense(long pk,
1901        com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1902        throws NoSuchProductEntryException,
1903            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1904            SystemException {
1905        try {
1906            addSCLicense.add(pk, scLicense.getPrimaryKey());
1907        }
1908        catch (DataAccessException dae) {
1909            throw new SystemException(dae);
1910        }
1911        finally {
1912            FinderCache.clearCache("SCLicenses_SCProductEntries");
1913        }
1914    }
1915
1916    public void addSCLicenses(long pk, long[] scLicensePKs)
1917        throws NoSuchProductEntryException,
1918            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1919            SystemException {
1920        try {
1921            for (long scLicensePK : scLicensePKs) {
1922                addSCLicense.add(pk, scLicensePK);
1923            }
1924        }
1925        catch (DataAccessException dae) {
1926            throw new SystemException(dae);
1927        }
1928        finally {
1929            FinderCache.clearCache("SCLicenses_SCProductEntries");
1930        }
1931    }
1932
1933    public void addSCLicenses(long pk,
1934        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
1935        throws NoSuchProductEntryException,
1936            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1937            SystemException {
1938        try {
1939            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
1940                addSCLicense.add(pk, scLicense.getPrimaryKey());
1941            }
1942        }
1943        catch (DataAccessException dae) {
1944            throw new SystemException(dae);
1945        }
1946        finally {
1947            FinderCache.clearCache("SCLicenses_SCProductEntries");
1948        }
1949    }
1950
1951    public void clearSCLicenses(long pk)
1952        throws NoSuchProductEntryException, SystemException {
1953        try {
1954            clearSCLicenses.clear(pk);
1955        }
1956        catch (DataAccessException dae) {
1957            throw new SystemException(dae);
1958        }
1959        finally {
1960            FinderCache.clearCache("SCLicenses_SCProductEntries");
1961        }
1962    }
1963
1964    public void removeSCLicense(long pk, long scLicensePK)
1965        throws NoSuchProductEntryException,
1966            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1967            SystemException {
1968        try {
1969            removeSCLicense.remove(pk, scLicensePK);
1970        }
1971        catch (DataAccessException dae) {
1972            throw new SystemException(dae);
1973        }
1974        finally {
1975            FinderCache.clearCache("SCLicenses_SCProductEntries");
1976        }
1977    }
1978
1979    public void removeSCLicense(long pk,
1980        com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
1981        throws NoSuchProductEntryException,
1982            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1983            SystemException {
1984        try {
1985            removeSCLicense.remove(pk, scLicense.getPrimaryKey());
1986        }
1987        catch (DataAccessException dae) {
1988            throw new SystemException(dae);
1989        }
1990        finally {
1991            FinderCache.clearCache("SCLicenses_SCProductEntries");
1992        }
1993    }
1994
1995    public void removeSCLicenses(long pk, long[] scLicensePKs)
1996        throws NoSuchProductEntryException,
1997            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
1998            SystemException {
1999        try {
2000            for (long scLicensePK : scLicensePKs) {
2001                removeSCLicense.remove(pk, scLicensePK);
2002            }
2003        }
2004        catch (DataAccessException dae) {
2005            throw new SystemException(dae);
2006        }
2007        finally {
2008            FinderCache.clearCache("SCLicenses_SCProductEntries");
2009        }
2010    }
2011
2012    public void removeSCLicenses(long pk,
2013        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
2014        throws NoSuchProductEntryException,
2015            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
2016            SystemException {
2017        try {
2018            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
2019                removeSCLicense.remove(pk, scLicense.getPrimaryKey());
2020            }
2021        }
2022        catch (DataAccessException dae) {
2023            throw new SystemException(dae);
2024        }
2025        finally {
2026            FinderCache.clearCache("SCLicenses_SCProductEntries");
2027        }
2028    }
2029
2030    public void setSCLicenses(long pk, long[] scLicensePKs)
2031        throws NoSuchProductEntryException,
2032            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
2033            SystemException {
2034        try {
2035            clearSCLicenses.clear(pk);
2036
2037            for (long scLicensePK : scLicensePKs) {
2038                addSCLicense.add(pk, scLicensePK);
2039            }
2040        }
2041        catch (DataAccessException dae) {
2042            throw new SystemException(dae);
2043        }
2044        finally {
2045            FinderCache.clearCache("SCLicenses_SCProductEntries");
2046        }
2047    }
2048
2049    public void setSCLicenses(long pk,
2050        List<com.liferay.portlet.softwarecatalog.model.SCLicense> scLicenses)
2051        throws NoSuchProductEntryException,
2052            com.liferay.portlet.softwarecatalog.NoSuchLicenseException,
2053            SystemException {
2054        try {
2055            clearSCLicenses.clear(pk);
2056
2057            for (com.liferay.portlet.softwarecatalog.model.SCLicense scLicense : scLicenses) {
2058                addSCLicense.add(pk, scLicense.getPrimaryKey());
2059            }
2060        }
2061        catch (DataAccessException dae) {
2062            throw new SystemException(dae);
2063        }
2064        finally {
2065            FinderCache.clearCache("SCLicenses_SCProductEntries");
2066        }
2067    }
2068
2069    protected void initDao() {
2070        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2071                    PropsUtil.get(
2072                        "value.object.listener.com.liferay.portlet.softwarecatalog.model.SCProductEntry")));
2073
2074        if (listenerClassNames.length > 0) {
2075            try {
2076                List<ModelListener> listeners = new ArrayList<ModelListener>();
2077
2078                for (String listenerClassName : listenerClassNames) {
2079                    listeners.add((ModelListener)Class.forName(
2080                            listenerClassName).newInstance());
2081                }
2082
2083                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2084            }
2085            catch (Exception e) {
2086                _log.error(e);
2087            }
2088        }
2089
2090        containsSCLicense = new ContainsSCLicense(this);
2091
2092        addSCLicense = new AddSCLicense(this);
2093        clearSCLicenses = new ClearSCLicenses(this);
2094        removeSCLicense = new RemoveSCLicense(this);
2095    }
2096
2097    protected ContainsSCLicense containsSCLicense;
2098    protected AddSCLicense addSCLicense;
2099    protected ClearSCLicenses clearSCLicenses;
2100    protected RemoveSCLicense removeSCLicense;
2101
2102    protected class ContainsSCLicense extends MappingSqlQuery {
2103        protected ContainsSCLicense(
2104            SCProductEntryPersistenceImpl persistenceImpl) {
2105            super(persistenceImpl.getDataSource(), _SQL_CONTAINSSCLICENSE);
2106
2107            declareParameter(new SqlParameter(Types.BIGINT));
2108            declareParameter(new SqlParameter(Types.BIGINT));
2109
2110            compile();
2111        }
2112
2113        protected Object mapRow(ResultSet rs, int rowNumber)
2114            throws SQLException {
2115            return new Integer(rs.getInt("COUNT_VALUE"));
2116        }
2117
2118        protected boolean contains(long productEntryId, long licenseId) {
2119            List<Integer> results = execute(new Object[] {
2120                        new Long(productEntryId), new Long(licenseId)
2121                    });
2122
2123            if (results.size() > 0) {
2124                Integer count = results.get(0);
2125
2126                if (count.intValue() > 0) {
2127                    return true;
2128                }
2129            }
2130
2131            return false;
2132        }
2133    }
2134
2135    protected class AddSCLicense extends SqlUpdate {
2136        protected AddSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2137            super(persistenceImpl.getDataSource(),
2138                "INSERT INTO SCLicenses_SCProductEntries (productEntryId, licenseId) VALUES (?, ?)");
2139
2140            _persistenceImpl = persistenceImpl;
2141
2142            declareParameter(new SqlParameter(Types.BIGINT));
2143            declareParameter(new SqlParameter(Types.BIGINT));
2144
2145            compile();
2146        }
2147
2148        protected void add(long productEntryId, long licenseId) {
2149            if (!_persistenceImpl.containsSCLicense.contains(productEntryId,
2150                        licenseId)) {
2151                update(new Object[] {
2152                        new Long(productEntryId), new Long(licenseId)
2153                    });
2154            }
2155        }
2156
2157        private SCProductEntryPersistenceImpl _persistenceImpl;
2158    }
2159
2160    protected class ClearSCLicenses extends SqlUpdate {
2161        protected ClearSCLicenses(SCProductEntryPersistenceImpl persistenceImpl) {
2162            super(persistenceImpl.getDataSource(),
2163                "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?");
2164
2165            declareParameter(new SqlParameter(Types.BIGINT));
2166
2167            compile();
2168        }
2169
2170        protected void clear(long productEntryId) {
2171            update(new Object[] { new Long(productEntryId) });
2172        }
2173    }
2174
2175    protected class RemoveSCLicense extends SqlUpdate {
2176        protected RemoveSCLicense(SCProductEntryPersistenceImpl persistenceImpl) {
2177            super(persistenceImpl.getDataSource(),
2178                "DELETE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?");
2179
2180            declareParameter(new SqlParameter(Types.BIGINT));
2181            declareParameter(new SqlParameter(Types.BIGINT));
2182
2183            compile();
2184        }
2185
2186        protected void remove(long productEntryId, long licenseId) {
2187            update(new Object[] { new Long(productEntryId), new Long(licenseId) });
2188        }
2189    }
2190
2191    private static final String _SQL_GETSCLICENSES = "SELECT {SCLicense.*} FROM SCLicense INNER JOIN SCLicenses_SCProductEntries ON (SCLicenses_SCProductEntries.licenseId = SCLicense.licenseId) WHERE (SCLicenses_SCProductEntries.productEntryId = ?)";
2192    private static final String _SQL_GETSCLICENSESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ?";
2193    private static final String _SQL_CONTAINSSCLICENSE = "SELECT COUNT(*) AS COUNT_VALUE FROM SCLicenses_SCProductEntries WHERE productEntryId = ? AND licenseId = ?";
2194    private static Log _log = LogFactory.getLog(SCProductEntryPersistenceImpl.class);
2195    private ModelListener[] _listeners;
2196}