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