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