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