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.NoSuchLicenseException;
36  import com.liferay.portlet.softwarecatalog.model.SCLicense;
37  import com.liferay.portlet.softwarecatalog.model.impl.SCLicenseImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Query;
45  import org.hibernate.Session;
46  
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="SCLicensePersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class SCLicensePersistenceImpl extends BasePersistence
58      implements SCLicensePersistence {
59      public SCLicense create(long licenseId) {
60          SCLicense scLicense = new SCLicenseImpl();
61          scLicense.setNew(true);
62          scLicense.setPrimaryKey(licenseId);
63  
64          return scLicense;
65      }
66  
67      public SCLicense remove(long licenseId)
68          throws NoSuchLicenseException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              SCLicense scLicense = (SCLicense)session.get(SCLicenseImpl.class,
75                      new Long(licenseId));
76  
77              if (scLicense == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No SCLicense exists with the primary key " +
80                          licenseId);
81                  }
82  
83                  throw new NoSuchLicenseException(
84                      "No SCLicense exists with the primary key " + licenseId);
85              }
86  
87              return remove(scLicense);
88          }
89          catch (NoSuchLicenseException nsee) {
90              throw nsee;
91          }
92          catch (Exception e) {
93              throw HibernateUtil.processException(e);
94          }
95          finally {
96              closeSession(session);
97          }
98      }
99  
100     public SCLicense remove(SCLicense scLicense) throws SystemException {
101         Session session = null;
102 
103         try {
104             session = openSession();
105             session.delete(scLicense);
106             session.flush();
107 
108             return scLicense;
109         }
110         catch (Exception e) {
111             throw HibernateUtil.processException(e);
112         }
113         finally {
114             closeSession(session);
115             FinderCache.clearCache(SCLicense.class.getName());
116         }
117     }
118 
119     public SCLicense update(
120         com.liferay.portlet.softwarecatalog.model.SCLicense scLicense)
121         throws SystemException {
122         return update(scLicense, false);
123     }
124 
125     public SCLicense update(
126         com.liferay.portlet.softwarecatalog.model.SCLicense scLicense,
127         boolean merge) throws SystemException {
128         Session session = null;
129 
130         try {
131             session = openSession();
132 
133             if (merge) {
134                 session.merge(scLicense);
135             }
136             else {
137                 if (scLicense.isNew()) {
138                     session.save(scLicense);
139                 }
140             }
141 
142             session.flush();
143             scLicense.setNew(false);
144 
145             return scLicense;
146         }
147         catch (Exception e) {
148             throw HibernateUtil.processException(e);
149         }
150         finally {
151             closeSession(session);
152             FinderCache.clearCache(SCLicense.class.getName());
153         }
154     }
155 
156     public SCLicense findByPrimaryKey(long licenseId)
157         throws NoSuchLicenseException, SystemException {
158         SCLicense scLicense = fetchByPrimaryKey(licenseId);
159 
160         if (scLicense == null) {
161             if (_log.isWarnEnabled()) {
162                 _log.warn("No SCLicense exists with the primary key " +
163                     licenseId);
164             }
165 
166             throw new NoSuchLicenseException(
167                 "No SCLicense exists with the primary key " + licenseId);
168         }
169 
170         return scLicense;
171     }
172 
173     public SCLicense fetchByPrimaryKey(long licenseId)
174         throws SystemException {
175         Session session = null;
176 
177         try {
178             session = openSession();
179 
180             return (SCLicense)session.get(SCLicenseImpl.class,
181                 new Long(licenseId));
182         }
183         catch (Exception e) {
184             throw HibernateUtil.processException(e);
185         }
186         finally {
187             closeSession(session);
188         }
189     }
190 
191     public List findByActive(boolean active) throws SystemException {
192         String finderClassName = SCLicense.class.getName();
193         String finderMethodName = "findByActive";
194         String[] finderParams = new String[] { Boolean.class.getName() };
195         Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
196         Object result = FinderCache.getResult(finderClassName,
197                 finderMethodName, finderParams, finderArgs, getSessionFactory());
198 
199         if (result == null) {
200             Session session = null;
201 
202             try {
203                 session = openSession();
204 
205                 StringMaker query = new StringMaker();
206                 query.append(
207                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
208                 query.append("active_ = ?");
209                 query.append(" ");
210                 query.append("ORDER BY ");
211                 query.append("name ASC");
212 
213                 Query q = session.createQuery(query.toString());
214                 int queryPos = 0;
215                 q.setBoolean(queryPos++, active);
216 
217                 List list = q.list();
218                 FinderCache.putResult(finderClassName, finderMethodName,
219                     finderParams, finderArgs, list);
220 
221                 return list;
222             }
223             catch (Exception e) {
224                 throw HibernateUtil.processException(e);
225             }
226             finally {
227                 closeSession(session);
228             }
229         }
230         else {
231             return (List)result;
232         }
233     }
234 
235     public List findByActive(boolean active, int begin, int end)
236         throws SystemException {
237         return findByActive(active, begin, end, null);
238     }
239 
240     public List findByActive(boolean active, int begin, int end,
241         OrderByComparator obc) throws SystemException {
242         String finderClassName = SCLicense.class.getName();
243         String finderMethodName = "findByActive";
244         String[] finderParams = new String[] {
245                 Boolean.class.getName(), "java.lang.Integer",
246                 "java.lang.Integer",
247                 "com.liferay.portal.kernel.util.OrderByComparator"
248             };
249         Object[] finderArgs = new Object[] {
250                 Boolean.valueOf(active), String.valueOf(begin),
251                 String.valueOf(end), String.valueOf(obc)
252             };
253         Object result = FinderCache.getResult(finderClassName,
254                 finderMethodName, finderParams, finderArgs, getSessionFactory());
255 
256         if (result == null) {
257             Session session = null;
258 
259             try {
260                 session = openSession();
261 
262                 StringMaker query = new StringMaker();
263                 query.append(
264                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
265                 query.append("active_ = ?");
266                 query.append(" ");
267 
268                 if (obc != null) {
269                     query.append("ORDER BY ");
270                     query.append(obc.getOrderBy());
271                 }
272                 else {
273                     query.append("ORDER BY ");
274                     query.append("name ASC");
275                 }
276 
277                 Query q = session.createQuery(query.toString());
278                 int queryPos = 0;
279                 q.setBoolean(queryPos++, active);
280 
281                 List list = QueryUtil.list(q, getDialect(), begin, end);
282                 FinderCache.putResult(finderClassName, finderMethodName,
283                     finderParams, finderArgs, list);
284 
285                 return list;
286             }
287             catch (Exception e) {
288                 throw HibernateUtil.processException(e);
289             }
290             finally {
291                 closeSession(session);
292             }
293         }
294         else {
295             return (List)result;
296         }
297     }
298 
299     public SCLicense findByActive_First(boolean active, OrderByComparator obc)
300         throws NoSuchLicenseException, SystemException {
301         List list = findByActive(active, 0, 1, obc);
302 
303         if (list.size() == 0) {
304             StringMaker msg = new StringMaker();
305             msg.append("No SCLicense exists with the key ");
306             msg.append(StringPool.OPEN_CURLY_BRACE);
307             msg.append("active=");
308             msg.append(active);
309             msg.append(StringPool.CLOSE_CURLY_BRACE);
310             throw new NoSuchLicenseException(msg.toString());
311         }
312         else {
313             return (SCLicense)list.get(0);
314         }
315     }
316 
317     public SCLicense findByActive_Last(boolean active, OrderByComparator obc)
318         throws NoSuchLicenseException, SystemException {
319         int count = countByActive(active);
320         List list = findByActive(active, count - 1, count, obc);
321 
322         if (list.size() == 0) {
323             StringMaker msg = new StringMaker();
324             msg.append("No SCLicense exists with the key ");
325             msg.append(StringPool.OPEN_CURLY_BRACE);
326             msg.append("active=");
327             msg.append(active);
328             msg.append(StringPool.CLOSE_CURLY_BRACE);
329             throw new NoSuchLicenseException(msg.toString());
330         }
331         else {
332             return (SCLicense)list.get(0);
333         }
334     }
335 
336     public SCLicense[] findByActive_PrevAndNext(long licenseId, boolean active,
337         OrderByComparator obc) throws NoSuchLicenseException, SystemException {
338         SCLicense scLicense = findByPrimaryKey(licenseId);
339         int count = countByActive(active);
340         Session session = null;
341 
342         try {
343             session = openSession();
344 
345             StringMaker query = new StringMaker();
346             query.append(
347                 "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
348             query.append("active_ = ?");
349             query.append(" ");
350 
351             if (obc != null) {
352                 query.append("ORDER BY ");
353                 query.append(obc.getOrderBy());
354             }
355             else {
356                 query.append("ORDER BY ");
357                 query.append("name ASC");
358             }
359 
360             Query q = session.createQuery(query.toString());
361             int queryPos = 0;
362             q.setBoolean(queryPos++, active);
363 
364             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
365                     scLicense);
366             SCLicense[] array = new SCLicenseImpl[3];
367             array[0] = (SCLicense)objArray[0];
368             array[1] = (SCLicense)objArray[1];
369             array[2] = (SCLicense)objArray[2];
370 
371             return array;
372         }
373         catch (Exception e) {
374             throw HibernateUtil.processException(e);
375         }
376         finally {
377             closeSession(session);
378         }
379     }
380 
381     public List findByA_R(boolean active, boolean recommended)
382         throws SystemException {
383         String finderClassName = SCLicense.class.getName();
384         String finderMethodName = "findByA_R";
385         String[] finderParams = new String[] {
386                 Boolean.class.getName(), Boolean.class.getName()
387             };
388         Object[] finderArgs = new Object[] {
389                 Boolean.valueOf(active), Boolean.valueOf(recommended)
390             };
391         Object result = FinderCache.getResult(finderClassName,
392                 finderMethodName, finderParams, finderArgs, getSessionFactory());
393 
394         if (result == null) {
395             Session session = null;
396 
397             try {
398                 session = openSession();
399 
400                 StringMaker query = new StringMaker();
401                 query.append(
402                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
403                 query.append("active_ = ?");
404                 query.append(" AND ");
405                 query.append("recommended = ?");
406                 query.append(" ");
407                 query.append("ORDER BY ");
408                 query.append("name ASC");
409 
410                 Query q = session.createQuery(query.toString());
411                 int queryPos = 0;
412                 q.setBoolean(queryPos++, active);
413                 q.setBoolean(queryPos++, recommended);
414 
415                 List list = q.list();
416                 FinderCache.putResult(finderClassName, finderMethodName,
417                     finderParams, finderArgs, list);
418 
419                 return list;
420             }
421             catch (Exception e) {
422                 throw HibernateUtil.processException(e);
423             }
424             finally {
425                 closeSession(session);
426             }
427         }
428         else {
429             return (List)result;
430         }
431     }
432 
433     public List findByA_R(boolean active, boolean recommended, int begin,
434         int end) throws SystemException {
435         return findByA_R(active, recommended, begin, end, null);
436     }
437 
438     public List findByA_R(boolean active, boolean recommended, int begin,
439         int end, OrderByComparator obc) throws SystemException {
440         String finderClassName = SCLicense.class.getName();
441         String finderMethodName = "findByA_R";
442         String[] finderParams = new String[] {
443                 Boolean.class.getName(), Boolean.class.getName(),
444                 "java.lang.Integer", "java.lang.Integer",
445                 "com.liferay.portal.kernel.util.OrderByComparator"
446             };
447         Object[] finderArgs = new Object[] {
448                 Boolean.valueOf(active), Boolean.valueOf(recommended),
449                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
450             };
451         Object result = FinderCache.getResult(finderClassName,
452                 finderMethodName, finderParams, finderArgs, getSessionFactory());
453 
454         if (result == null) {
455             Session session = null;
456 
457             try {
458                 session = openSession();
459 
460                 StringMaker query = new StringMaker();
461                 query.append(
462                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
463                 query.append("active_ = ?");
464                 query.append(" AND ");
465                 query.append("recommended = ?");
466                 query.append(" ");
467 
468                 if (obc != null) {
469                     query.append("ORDER BY ");
470                     query.append(obc.getOrderBy());
471                 }
472                 else {
473                     query.append("ORDER BY ");
474                     query.append("name ASC");
475                 }
476 
477                 Query q = session.createQuery(query.toString());
478                 int queryPos = 0;
479                 q.setBoolean(queryPos++, active);
480                 q.setBoolean(queryPos++, recommended);
481 
482                 List list = QueryUtil.list(q, getDialect(), begin, end);
483                 FinderCache.putResult(finderClassName, finderMethodName,
484                     finderParams, finderArgs, list);
485 
486                 return list;
487             }
488             catch (Exception e) {
489                 throw HibernateUtil.processException(e);
490             }
491             finally {
492                 closeSession(session);
493             }
494         }
495         else {
496             return (List)result;
497         }
498     }
499 
500     public SCLicense findByA_R_First(boolean active, boolean recommended,
501         OrderByComparator obc) throws NoSuchLicenseException, SystemException {
502         List list = findByA_R(active, recommended, 0, 1, obc);
503 
504         if (list.size() == 0) {
505             StringMaker msg = new StringMaker();
506             msg.append("No SCLicense exists with the key ");
507             msg.append(StringPool.OPEN_CURLY_BRACE);
508             msg.append("active=");
509             msg.append(active);
510             msg.append(", ");
511             msg.append("recommended=");
512             msg.append(recommended);
513             msg.append(StringPool.CLOSE_CURLY_BRACE);
514             throw new NoSuchLicenseException(msg.toString());
515         }
516         else {
517             return (SCLicense)list.get(0);
518         }
519     }
520 
521     public SCLicense findByA_R_Last(boolean active, boolean recommended,
522         OrderByComparator obc) throws NoSuchLicenseException, SystemException {
523         int count = countByA_R(active, recommended);
524         List list = findByA_R(active, recommended, count - 1, count, obc);
525 
526         if (list.size() == 0) {
527             StringMaker msg = new StringMaker();
528             msg.append("No SCLicense exists with the key ");
529             msg.append(StringPool.OPEN_CURLY_BRACE);
530             msg.append("active=");
531             msg.append(active);
532             msg.append(", ");
533             msg.append("recommended=");
534             msg.append(recommended);
535             msg.append(StringPool.CLOSE_CURLY_BRACE);
536             throw new NoSuchLicenseException(msg.toString());
537         }
538         else {
539             return (SCLicense)list.get(0);
540         }
541     }
542 
543     public SCLicense[] findByA_R_PrevAndNext(long licenseId, boolean active,
544         boolean recommended, OrderByComparator obc)
545         throws NoSuchLicenseException, SystemException {
546         SCLicense scLicense = findByPrimaryKey(licenseId);
547         int count = countByA_R(active, recommended);
548         Session session = null;
549 
550         try {
551             session = openSession();
552 
553             StringMaker query = new StringMaker();
554             query.append(
555                 "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
556             query.append("active_ = ?");
557             query.append(" AND ");
558             query.append("recommended = ?");
559             query.append(" ");
560 
561             if (obc != null) {
562                 query.append("ORDER BY ");
563                 query.append(obc.getOrderBy());
564             }
565             else {
566                 query.append("ORDER BY ");
567                 query.append("name ASC");
568             }
569 
570             Query q = session.createQuery(query.toString());
571             int queryPos = 0;
572             q.setBoolean(queryPos++, active);
573             q.setBoolean(queryPos++, recommended);
574 
575             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
576                     scLicense);
577             SCLicense[] array = new SCLicenseImpl[3];
578             array[0] = (SCLicense)objArray[0];
579             array[1] = (SCLicense)objArray[1];
580             array[2] = (SCLicense)objArray[2];
581 
582             return array;
583         }
584         catch (Exception e) {
585             throw HibernateUtil.processException(e);
586         }
587         finally {
588             closeSession(session);
589         }
590     }
591 
592     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
593         throws SystemException {
594         Session session = null;
595 
596         try {
597             session = openSession();
598 
599             DynamicQuery query = queryInitializer.initialize(session);
600 
601             return query.list();
602         }
603         catch (Exception e) {
604             throw HibernateUtil.processException(e);
605         }
606         finally {
607             closeSession(session);
608         }
609     }
610 
611     public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
612         int begin, int end) throws SystemException {
613         Session session = null;
614 
615         try {
616             session = openSession();
617 
618             DynamicQuery query = queryInitializer.initialize(session);
619             query.setLimit(begin, end);
620 
621             return query.list();
622         }
623         catch (Exception e) {
624             throw HibernateUtil.processException(e);
625         }
626         finally {
627             closeSession(session);
628         }
629     }
630 
631     public List findAll() throws SystemException {
632         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
633     }
634 
635     public List findAll(int begin, int end) throws SystemException {
636         return findAll(begin, end, null);
637     }
638 
639     public List findAll(int begin, int end, OrderByComparator obc)
640         throws SystemException {
641         String finderClassName = SCLicense.class.getName();
642         String finderMethodName = "findAll";
643         String[] finderParams = new String[] {
644                 "java.lang.Integer", "java.lang.Integer",
645                 "com.liferay.portal.kernel.util.OrderByComparator"
646             };
647         Object[] finderArgs = new Object[] {
648                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
649             };
650         Object result = FinderCache.getResult(finderClassName,
651                 finderMethodName, finderParams, finderArgs, getSessionFactory());
652 
653         if (result == null) {
654             Session session = null;
655 
656             try {
657                 session = openSession();
658 
659                 StringMaker query = new StringMaker();
660                 query.append(
661                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense ");
662 
663                 if (obc != null) {
664                     query.append("ORDER BY ");
665                     query.append(obc.getOrderBy());
666                 }
667                 else {
668                     query.append("ORDER BY ");
669                     query.append("name ASC");
670                 }
671 
672                 Query q = session.createQuery(query.toString());
673                 List list = QueryUtil.list(q, getDialect(), begin, end);
674 
675                 if (obc == null) {
676                     Collections.sort(list);
677                 }
678 
679                 FinderCache.putResult(finderClassName, finderMethodName,
680                     finderParams, finderArgs, list);
681 
682                 return list;
683             }
684             catch (Exception e) {
685                 throw HibernateUtil.processException(e);
686             }
687             finally {
688                 closeSession(session);
689             }
690         }
691         else {
692             return (List)result;
693         }
694     }
695 
696     public void removeByActive(boolean active) throws SystemException {
697         Iterator itr = findByActive(active).iterator();
698 
699         while (itr.hasNext()) {
700             SCLicense scLicense = (SCLicense)itr.next();
701             remove(scLicense);
702         }
703     }
704 
705     public void removeByA_R(boolean active, boolean recommended)
706         throws SystemException {
707         Iterator itr = findByA_R(active, recommended).iterator();
708 
709         while (itr.hasNext()) {
710             SCLicense scLicense = (SCLicense)itr.next();
711             remove(scLicense);
712         }
713     }
714 
715     public void removeAll() throws SystemException {
716         Iterator itr = findAll().iterator();
717 
718         while (itr.hasNext()) {
719             remove((SCLicense)itr.next());
720         }
721     }
722 
723     public int countByActive(boolean active) throws SystemException {
724         String finderClassName = SCLicense.class.getName();
725         String finderMethodName = "countByActive";
726         String[] finderParams = new String[] { Boolean.class.getName() };
727         Object[] finderArgs = new Object[] { Boolean.valueOf(active) };
728         Object result = FinderCache.getResult(finderClassName,
729                 finderMethodName, finderParams, finderArgs, getSessionFactory());
730 
731         if (result == null) {
732             Session session = null;
733 
734             try {
735                 session = openSession();
736 
737                 StringMaker query = new StringMaker();
738                 query.append("SELECT COUNT(*) ");
739                 query.append(
740                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
741                 query.append("active_ = ?");
742                 query.append(" ");
743 
744                 Query q = session.createQuery(query.toString());
745                 int queryPos = 0;
746                 q.setBoolean(queryPos++, active);
747 
748                 Long count = null;
749                 Iterator itr = q.list().iterator();
750 
751                 if (itr.hasNext()) {
752                     count = (Long)itr.next();
753                 }
754 
755                 if (count == null) {
756                     count = new Long(0);
757                 }
758 
759                 FinderCache.putResult(finderClassName, finderMethodName,
760                     finderParams, finderArgs, count);
761 
762                 return count.intValue();
763             }
764             catch (Exception e) {
765                 throw HibernateUtil.processException(e);
766             }
767             finally {
768                 closeSession(session);
769             }
770         }
771         else {
772             return ((Long)result).intValue();
773         }
774     }
775 
776     public int countByA_R(boolean active, boolean recommended)
777         throws SystemException {
778         String finderClassName = SCLicense.class.getName();
779         String finderMethodName = "countByA_R";
780         String[] finderParams = new String[] {
781                 Boolean.class.getName(), Boolean.class.getName()
782             };
783         Object[] finderArgs = new Object[] {
784                 Boolean.valueOf(active), Boolean.valueOf(recommended)
785             };
786         Object result = FinderCache.getResult(finderClassName,
787                 finderMethodName, finderParams, finderArgs, getSessionFactory());
788 
789         if (result == null) {
790             Session session = null;
791 
792             try {
793                 session = openSession();
794 
795                 StringMaker query = new StringMaker();
796                 query.append("SELECT COUNT(*) ");
797                 query.append(
798                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense WHERE ");
799                 query.append("active_ = ?");
800                 query.append(" AND ");
801                 query.append("recommended = ?");
802                 query.append(" ");
803 
804                 Query q = session.createQuery(query.toString());
805                 int queryPos = 0;
806                 q.setBoolean(queryPos++, active);
807                 q.setBoolean(queryPos++, recommended);
808 
809                 Long count = null;
810                 Iterator itr = q.list().iterator();
811 
812                 if (itr.hasNext()) {
813                     count = (Long)itr.next();
814                 }
815 
816                 if (count == null) {
817                     count = new Long(0);
818                 }
819 
820                 FinderCache.putResult(finderClassName, finderMethodName,
821                     finderParams, finderArgs, count);
822 
823                 return count.intValue();
824             }
825             catch (Exception e) {
826                 throw HibernateUtil.processException(e);
827             }
828             finally {
829                 closeSession(session);
830             }
831         }
832         else {
833             return ((Long)result).intValue();
834         }
835     }
836 
837     public int countAll() throws SystemException {
838         String finderClassName = SCLicense.class.getName();
839         String finderMethodName = "countAll";
840         String[] finderParams = new String[] {  };
841         Object[] finderArgs = new Object[] {  };
842         Object result = FinderCache.getResult(finderClassName,
843                 finderMethodName, finderParams, finderArgs, getSessionFactory());
844 
845         if (result == null) {
846             Session session = null;
847 
848             try {
849                 session = openSession();
850 
851                 StringMaker query = new StringMaker();
852                 query.append("SELECT COUNT(*) ");
853                 query.append(
854                     "FROM com.liferay.portlet.softwarecatalog.model.SCLicense");
855 
856                 Query q = session.createQuery(query.toString());
857                 Long count = null;
858                 Iterator itr = q.list().iterator();
859 
860                 if (itr.hasNext()) {
861                     count = (Long)itr.next();
862                 }
863 
864                 if (count == null) {
865                     count = new Long(0);
866                 }
867 
868                 FinderCache.putResult(finderClassName, finderMethodName,
869                     finderParams, finderArgs, count);
870 
871                 return count.intValue();
872             }
873             catch (Exception e) {
874                 throw HibernateUtil.processException(e);
875             }
876             finally {
877                 closeSession(session);
878             }
879         }
880         else {
881             return ((Long)result).intValue();
882         }
883     }
884 
885     protected void initDao() {
886     }
887 
888     private static Log _log = LogFactory.getLog(SCLicensePersistenceImpl.class);
889 }