1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.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.GetterUtil;
30  import com.liferay.portal.kernel.util.OrderByComparator;
31  import com.liferay.portal.kernel.util.StringMaker;
32  import com.liferay.portal.kernel.util.StringPool;
33  import com.liferay.portal.kernel.util.StringUtil;
34  import com.liferay.portal.model.ModelListener;
35  import com.liferay.portal.model.OrgGroupPermission;
36  import com.liferay.portal.model.impl.OrgGroupPermissionImpl;
37  import com.liferay.portal.model.impl.OrgGroupPermissionModelImpl;
38  import com.liferay.portal.spring.hibernate.FinderCache;
39  import com.liferay.portal.spring.hibernate.HibernateUtil;
40  import com.liferay.portal.util.PropsUtil;
41  
42  import com.liferay.util.dao.hibernate.QueryUtil;
43  
44  import org.apache.commons.logging.Log;
45  import org.apache.commons.logging.LogFactory;
46  
47  import org.hibernate.Query;
48  import org.hibernate.Session;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.Iterator;
53  import java.util.List;
54  
55  /**
56   * <a href="OrgGroupPermissionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   */
61  public class OrgGroupPermissionPersistenceImpl extends BasePersistence
62      implements OrgGroupPermissionPersistence {
63      public OrgGroupPermission create(OrgGroupPermissionPK orgGroupPermissionPK) {
64          OrgGroupPermission orgGroupPermission = new OrgGroupPermissionImpl();
65  
66          orgGroupPermission.setNew(true);
67          orgGroupPermission.setPrimaryKey(orgGroupPermissionPK);
68  
69          return orgGroupPermission;
70      }
71  
72      public OrgGroupPermission remove(OrgGroupPermissionPK orgGroupPermissionPK)
73          throws NoSuchOrgGroupPermissionException, SystemException {
74          Session session = null;
75  
76          try {
77              session = openSession();
78  
79              OrgGroupPermission orgGroupPermission = (OrgGroupPermission)session.get(OrgGroupPermissionImpl.class,
80                      orgGroupPermissionPK);
81  
82              if (orgGroupPermission == null) {
83                  if (_log.isWarnEnabled()) {
84                      _log.warn(
85                          "No OrgGroupPermission exists with the primary key " +
86                          orgGroupPermissionPK);
87                  }
88  
89                  throw new NoSuchOrgGroupPermissionException(
90                      "No OrgGroupPermission exists with the primary key " +
91                      orgGroupPermissionPK);
92              }
93  
94              return remove(orgGroupPermission);
95          }
96          catch (NoSuchOrgGroupPermissionException nsee) {
97              throw nsee;
98          }
99          catch (Exception e) {
100             throw HibernateUtil.processException(e);
101         }
102         finally {
103             closeSession(session);
104         }
105     }
106 
107     public OrgGroupPermission remove(OrgGroupPermission orgGroupPermission)
108         throws SystemException {
109         if (_listeners != null) {
110             for (ModelListener listener : _listeners) {
111                 listener.onBeforeRemove(orgGroupPermission);
112             }
113         }
114 
115         orgGroupPermission = removeImpl(orgGroupPermission);
116 
117         if (_listeners != null) {
118             for (ModelListener listener : _listeners) {
119                 listener.onAfterRemove(orgGroupPermission);
120             }
121         }
122 
123         return orgGroupPermission;
124     }
125 
126     protected OrgGroupPermission removeImpl(
127         OrgGroupPermission orgGroupPermission) throws SystemException {
128         Session session = null;
129 
130         try {
131             session = openSession();
132 
133             session.delete(orgGroupPermission);
134 
135             session.flush();
136 
137             return orgGroupPermission;
138         }
139         catch (Exception e) {
140             throw HibernateUtil.processException(e);
141         }
142         finally {
143             closeSession(session);
144 
145             FinderCache.clearCache(OrgGroupPermission.class.getName());
146         }
147     }
148 
149     /**
150      * @deprecated Use <code>update(OrgGroupPermission orgGroupPermission, boolean merge)</code>.
151      */
152     public OrgGroupPermission update(OrgGroupPermission orgGroupPermission)
153         throws SystemException {
154         if (_log.isWarnEnabled()) {
155             _log.warn(
156                 "Using the deprecated update(OrgGroupPermission orgGroupPermission) method. Use update(OrgGroupPermission orgGroupPermission, boolean merge) instead.");
157         }
158 
159         return update(orgGroupPermission, false);
160     }
161 
162     /**
163      * Add, update, or merge, the entity. This method also calls the model
164      * listeners to trigger the proper events associated with adding, deleting,
165      * or updating an entity.
166      *
167      * @param        orgGroupPermission the entity to add, update, or merge
168      * @param        merge boolean value for whether to merge the entity. The
169      *                default value is false. Setting merge to true is more
170      *                expensive and should only be true when orgGroupPermission is
171      *                transient. See LEP-5473 for a detailed discussion of this
172      *                method.
173      * @return        true if the portlet can be displayed via Ajax
174      */
175     public OrgGroupPermission update(OrgGroupPermission orgGroupPermission,
176         boolean merge) throws SystemException {
177         boolean isNew = orgGroupPermission.isNew();
178 
179         if (_listeners != null) {
180             for (ModelListener listener : _listeners) {
181                 if (isNew) {
182                     listener.onBeforeCreate(orgGroupPermission);
183                 }
184                 else {
185                     listener.onBeforeUpdate(orgGroupPermission);
186                 }
187             }
188         }
189 
190         orgGroupPermission = updateImpl(orgGroupPermission, merge);
191 
192         if (_listeners != null) {
193             for (ModelListener listener : _listeners) {
194                 if (isNew) {
195                     listener.onAfterCreate(orgGroupPermission);
196                 }
197                 else {
198                     listener.onAfterUpdate(orgGroupPermission);
199                 }
200             }
201         }
202 
203         return orgGroupPermission;
204     }
205 
206     public OrgGroupPermission updateImpl(
207         com.liferay.portal.model.OrgGroupPermission orgGroupPermission,
208         boolean merge) throws SystemException {
209         Session session = null;
210 
211         try {
212             session = openSession();
213 
214             if (merge) {
215                 session.merge(orgGroupPermission);
216             }
217             else {
218                 if (orgGroupPermission.isNew()) {
219                     session.save(orgGroupPermission);
220                 }
221             }
222 
223             session.flush();
224 
225             orgGroupPermission.setNew(false);
226 
227             return orgGroupPermission;
228         }
229         catch (Exception e) {
230             throw HibernateUtil.processException(e);
231         }
232         finally {
233             closeSession(session);
234 
235             FinderCache.clearCache(OrgGroupPermission.class.getName());
236         }
237     }
238 
239     public OrgGroupPermission findByPrimaryKey(
240         OrgGroupPermissionPK orgGroupPermissionPK)
241         throws NoSuchOrgGroupPermissionException, SystemException {
242         OrgGroupPermission orgGroupPermission = fetchByPrimaryKey(orgGroupPermissionPK);
243 
244         if (orgGroupPermission == null) {
245             if (_log.isWarnEnabled()) {
246                 _log.warn("No OrgGroupPermission exists with the primary key " +
247                     orgGroupPermissionPK);
248             }
249 
250             throw new NoSuchOrgGroupPermissionException(
251                 "No OrgGroupPermission exists with the primary key " +
252                 orgGroupPermissionPK);
253         }
254 
255         return orgGroupPermission;
256     }
257 
258     public OrgGroupPermission fetchByPrimaryKey(
259         OrgGroupPermissionPK orgGroupPermissionPK) throws SystemException {
260         Session session = null;
261 
262         try {
263             session = openSession();
264 
265             return (OrgGroupPermission)session.get(OrgGroupPermissionImpl.class,
266                 orgGroupPermissionPK);
267         }
268         catch (Exception e) {
269             throw HibernateUtil.processException(e);
270         }
271         finally {
272             closeSession(session);
273         }
274     }
275 
276     public List<OrgGroupPermission> findByGroupId(long groupId)
277         throws SystemException {
278         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
279         String finderClassName = OrgGroupPermission.class.getName();
280         String finderMethodName = "findByGroupId";
281         String[] finderParams = new String[] { Long.class.getName() };
282         Object[] finderArgs = new Object[] { new Long(groupId) };
283 
284         Object result = null;
285 
286         if (finderClassNameCacheEnabled) {
287             result = FinderCache.getResult(finderClassName, finderMethodName,
288                     finderParams, finderArgs, getSessionFactory());
289         }
290 
291         if (result == null) {
292             Session session = null;
293 
294             try {
295                 session = openSession();
296 
297                 StringMaker query = new StringMaker();
298 
299                 query.append(
300                     "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
301 
302                 query.append("groupId = ?");
303 
304                 query.append(" ");
305 
306                 Query q = session.createQuery(query.toString());
307 
308                 int queryPos = 0;
309 
310                 q.setLong(queryPos++, groupId);
311 
312                 List<OrgGroupPermission> list = q.list();
313 
314                 FinderCache.putResult(finderClassNameCacheEnabled,
315                     finderClassName, finderMethodName, finderParams,
316                     finderArgs, list);
317 
318                 return list;
319             }
320             catch (Exception e) {
321                 throw HibernateUtil.processException(e);
322             }
323             finally {
324                 closeSession(session);
325             }
326         }
327         else {
328             return (List<OrgGroupPermission>)result;
329         }
330     }
331 
332     public List<OrgGroupPermission> findByGroupId(long groupId, int begin,
333         int end) throws SystemException {
334         return findByGroupId(groupId, begin, end, null);
335     }
336 
337     public List<OrgGroupPermission> findByGroupId(long groupId, int begin,
338         int end, OrderByComparator obc) throws SystemException {
339         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
340         String finderClassName = OrgGroupPermission.class.getName();
341         String finderMethodName = "findByGroupId";
342         String[] finderParams = new String[] {
343                 Long.class.getName(),
344                 
345                 "java.lang.Integer", "java.lang.Integer",
346                 "com.liferay.portal.kernel.util.OrderByComparator"
347             };
348         Object[] finderArgs = new Object[] {
349                 new Long(groupId),
350                 
351                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
352             };
353 
354         Object result = null;
355 
356         if (finderClassNameCacheEnabled) {
357             result = FinderCache.getResult(finderClassName, finderMethodName,
358                     finderParams, finderArgs, getSessionFactory());
359         }
360 
361         if (result == null) {
362             Session session = null;
363 
364             try {
365                 session = openSession();
366 
367                 StringMaker query = new StringMaker();
368 
369                 query.append(
370                     "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
371 
372                 query.append("groupId = ?");
373 
374                 query.append(" ");
375 
376                 if (obc != null) {
377                     query.append("ORDER BY ");
378                     query.append(obc.getOrderBy());
379                 }
380 
381                 Query q = session.createQuery(query.toString());
382 
383                 int queryPos = 0;
384 
385                 q.setLong(queryPos++, groupId);
386 
387                 List<OrgGroupPermission> list = (List<OrgGroupPermission>)QueryUtil.list(q,
388                         getDialect(), begin, end);
389 
390                 FinderCache.putResult(finderClassNameCacheEnabled,
391                     finderClassName, finderMethodName, finderParams,
392                     finderArgs, list);
393 
394                 return list;
395             }
396             catch (Exception e) {
397                 throw HibernateUtil.processException(e);
398             }
399             finally {
400                 closeSession(session);
401             }
402         }
403         else {
404             return (List<OrgGroupPermission>)result;
405         }
406     }
407 
408     public OrgGroupPermission findByGroupId_First(long groupId,
409         OrderByComparator obc)
410         throws NoSuchOrgGroupPermissionException, SystemException {
411         List<OrgGroupPermission> list = findByGroupId(groupId, 0, 1, obc);
412 
413         if (list.size() == 0) {
414             StringMaker msg = new StringMaker();
415 
416             msg.append("No OrgGroupPermission exists with the key {");
417 
418             msg.append("groupId=" + groupId);
419 
420             msg.append(StringPool.CLOSE_CURLY_BRACE);
421 
422             throw new NoSuchOrgGroupPermissionException(msg.toString());
423         }
424         else {
425             return list.get(0);
426         }
427     }
428 
429     public OrgGroupPermission findByGroupId_Last(long groupId,
430         OrderByComparator obc)
431         throws NoSuchOrgGroupPermissionException, SystemException {
432         int count = countByGroupId(groupId);
433 
434         List<OrgGroupPermission> list = findByGroupId(groupId, count - 1,
435                 count, obc);
436 
437         if (list.size() == 0) {
438             StringMaker msg = new StringMaker();
439 
440             msg.append("No OrgGroupPermission exists with the key {");
441 
442             msg.append("groupId=" + groupId);
443 
444             msg.append(StringPool.CLOSE_CURLY_BRACE);
445 
446             throw new NoSuchOrgGroupPermissionException(msg.toString());
447         }
448         else {
449             return list.get(0);
450         }
451     }
452 
453     public OrgGroupPermission[] findByGroupId_PrevAndNext(
454         OrgGroupPermissionPK orgGroupPermissionPK, long groupId,
455         OrderByComparator obc)
456         throws NoSuchOrgGroupPermissionException, SystemException {
457         OrgGroupPermission orgGroupPermission = findByPrimaryKey(orgGroupPermissionPK);
458 
459         int count = countByGroupId(groupId);
460 
461         Session session = null;
462 
463         try {
464             session = openSession();
465 
466             StringMaker query = new StringMaker();
467 
468             query.append(
469                 "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
470 
471             query.append("groupId = ?");
472 
473             query.append(" ");
474 
475             if (obc != null) {
476                 query.append("ORDER BY ");
477                 query.append(obc.getOrderBy());
478             }
479 
480             Query q = session.createQuery(query.toString());
481 
482             int queryPos = 0;
483 
484             q.setLong(queryPos++, groupId);
485 
486             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
487                     orgGroupPermission);
488 
489             OrgGroupPermission[] array = new OrgGroupPermissionImpl[3];
490 
491             array[0] = (OrgGroupPermission)objArray[0];
492             array[1] = (OrgGroupPermission)objArray[1];
493             array[2] = (OrgGroupPermission)objArray[2];
494 
495             return array;
496         }
497         catch (Exception e) {
498             throw HibernateUtil.processException(e);
499         }
500         finally {
501             closeSession(session);
502         }
503     }
504 
505     public List<OrgGroupPermission> findByPermissionId(long permissionId)
506         throws SystemException {
507         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
508         String finderClassName = OrgGroupPermission.class.getName();
509         String finderMethodName = "findByPermissionId";
510         String[] finderParams = new String[] { Long.class.getName() };
511         Object[] finderArgs = new Object[] { new Long(permissionId) };
512 
513         Object result = null;
514 
515         if (finderClassNameCacheEnabled) {
516             result = FinderCache.getResult(finderClassName, finderMethodName,
517                     finderParams, finderArgs, getSessionFactory());
518         }
519 
520         if (result == null) {
521             Session session = null;
522 
523             try {
524                 session = openSession();
525 
526                 StringMaker query = new StringMaker();
527 
528                 query.append(
529                     "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
530 
531                 query.append("permissionId = ?");
532 
533                 query.append(" ");
534 
535                 Query q = session.createQuery(query.toString());
536 
537                 int queryPos = 0;
538 
539                 q.setLong(queryPos++, permissionId);
540 
541                 List<OrgGroupPermission> list = q.list();
542 
543                 FinderCache.putResult(finderClassNameCacheEnabled,
544                     finderClassName, finderMethodName, finderParams,
545                     finderArgs, list);
546 
547                 return list;
548             }
549             catch (Exception e) {
550                 throw HibernateUtil.processException(e);
551             }
552             finally {
553                 closeSession(session);
554             }
555         }
556         else {
557             return (List<OrgGroupPermission>)result;
558         }
559     }
560 
561     public List<OrgGroupPermission> findByPermissionId(long permissionId,
562         int begin, int end) throws SystemException {
563         return findByPermissionId(permissionId, begin, end, null);
564     }
565 
566     public List<OrgGroupPermission> findByPermissionId(long permissionId,
567         int begin, int end, OrderByComparator obc) throws SystemException {
568         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
569         String finderClassName = OrgGroupPermission.class.getName();
570         String finderMethodName = "findByPermissionId";
571         String[] finderParams = new String[] {
572                 Long.class.getName(),
573                 
574                 "java.lang.Integer", "java.lang.Integer",
575                 "com.liferay.portal.kernel.util.OrderByComparator"
576             };
577         Object[] finderArgs = new Object[] {
578                 new Long(permissionId),
579                 
580                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
581             };
582 
583         Object result = null;
584 
585         if (finderClassNameCacheEnabled) {
586             result = FinderCache.getResult(finderClassName, finderMethodName,
587                     finderParams, finderArgs, getSessionFactory());
588         }
589 
590         if (result == null) {
591             Session session = null;
592 
593             try {
594                 session = openSession();
595 
596                 StringMaker query = new StringMaker();
597 
598                 query.append(
599                     "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
600 
601                 query.append("permissionId = ?");
602 
603                 query.append(" ");
604 
605                 if (obc != null) {
606                     query.append("ORDER BY ");
607                     query.append(obc.getOrderBy());
608                 }
609 
610                 Query q = session.createQuery(query.toString());
611 
612                 int queryPos = 0;
613 
614                 q.setLong(queryPos++, permissionId);
615 
616                 List<OrgGroupPermission> list = (List<OrgGroupPermission>)QueryUtil.list(q,
617                         getDialect(), begin, end);
618 
619                 FinderCache.putResult(finderClassNameCacheEnabled,
620                     finderClassName, finderMethodName, finderParams,
621                     finderArgs, list);
622 
623                 return list;
624             }
625             catch (Exception e) {
626                 throw HibernateUtil.processException(e);
627             }
628             finally {
629                 closeSession(session);
630             }
631         }
632         else {
633             return (List<OrgGroupPermission>)result;
634         }
635     }
636 
637     public OrgGroupPermission findByPermissionId_First(long permissionId,
638         OrderByComparator obc)
639         throws NoSuchOrgGroupPermissionException, SystemException {
640         List<OrgGroupPermission> list = findByPermissionId(permissionId, 0, 1,
641                 obc);
642 
643         if (list.size() == 0) {
644             StringMaker msg = new StringMaker();
645 
646             msg.append("No OrgGroupPermission exists with the key {");
647 
648             msg.append("permissionId=" + permissionId);
649 
650             msg.append(StringPool.CLOSE_CURLY_BRACE);
651 
652             throw new NoSuchOrgGroupPermissionException(msg.toString());
653         }
654         else {
655             return list.get(0);
656         }
657     }
658 
659     public OrgGroupPermission findByPermissionId_Last(long permissionId,
660         OrderByComparator obc)
661         throws NoSuchOrgGroupPermissionException, SystemException {
662         int count = countByPermissionId(permissionId);
663 
664         List<OrgGroupPermission> list = findByPermissionId(permissionId,
665                 count - 1, count, obc);
666 
667         if (list.size() == 0) {
668             StringMaker msg = new StringMaker();
669 
670             msg.append("No OrgGroupPermission exists with the key {");
671 
672             msg.append("permissionId=" + permissionId);
673 
674             msg.append(StringPool.CLOSE_CURLY_BRACE);
675 
676             throw new NoSuchOrgGroupPermissionException(msg.toString());
677         }
678         else {
679             return list.get(0);
680         }
681     }
682 
683     public OrgGroupPermission[] findByPermissionId_PrevAndNext(
684         OrgGroupPermissionPK orgGroupPermissionPK, long permissionId,
685         OrderByComparator obc)
686         throws NoSuchOrgGroupPermissionException, SystemException {
687         OrgGroupPermission orgGroupPermission = findByPrimaryKey(orgGroupPermissionPK);
688 
689         int count = countByPermissionId(permissionId);
690 
691         Session session = null;
692 
693         try {
694             session = openSession();
695 
696             StringMaker query = new StringMaker();
697 
698             query.append(
699                 "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
700 
701             query.append("permissionId = ?");
702 
703             query.append(" ");
704 
705             if (obc != null) {
706                 query.append("ORDER BY ");
707                 query.append(obc.getOrderBy());
708             }
709 
710             Query q = session.createQuery(query.toString());
711 
712             int queryPos = 0;
713 
714             q.setLong(queryPos++, permissionId);
715 
716             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
717                     orgGroupPermission);
718 
719             OrgGroupPermission[] array = new OrgGroupPermissionImpl[3];
720 
721             array[0] = (OrgGroupPermission)objArray[0];
722             array[1] = (OrgGroupPermission)objArray[1];
723             array[2] = (OrgGroupPermission)objArray[2];
724 
725             return array;
726         }
727         catch (Exception e) {
728             throw HibernateUtil.processException(e);
729         }
730         finally {
731             closeSession(session);
732         }
733     }
734 
735     public List<OrgGroupPermission> findWithDynamicQuery(
736         DynamicQueryInitializer queryInitializer) throws SystemException {
737         Session session = null;
738 
739         try {
740             session = openSession();
741 
742             DynamicQuery query = queryInitializer.initialize(session);
743 
744             return query.list();
745         }
746         catch (Exception e) {
747             throw HibernateUtil.processException(e);
748         }
749         finally {
750             closeSession(session);
751         }
752     }
753 
754     public List<OrgGroupPermission> findWithDynamicQuery(
755         DynamicQueryInitializer queryInitializer, int begin, int end)
756         throws SystemException {
757         Session session = null;
758 
759         try {
760             session = openSession();
761 
762             DynamicQuery query = queryInitializer.initialize(session);
763 
764             query.setLimit(begin, end);
765 
766             return query.list();
767         }
768         catch (Exception e) {
769             throw HibernateUtil.processException(e);
770         }
771         finally {
772             closeSession(session);
773         }
774     }
775 
776     public List<OrgGroupPermission> findAll() throws SystemException {
777         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
778     }
779 
780     public List<OrgGroupPermission> findAll(int begin, int end)
781         throws SystemException {
782         return findAll(begin, end, null);
783     }
784 
785     public List<OrgGroupPermission> findAll(int begin, int end,
786         OrderByComparator obc) throws SystemException {
787         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
788         String finderClassName = OrgGroupPermission.class.getName();
789         String finderMethodName = "findAll";
790         String[] finderParams = new String[] {
791                 "java.lang.Integer", "java.lang.Integer",
792                 "com.liferay.portal.kernel.util.OrderByComparator"
793             };
794         Object[] finderArgs = new Object[] {
795                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
796             };
797 
798         Object result = null;
799 
800         if (finderClassNameCacheEnabled) {
801             result = FinderCache.getResult(finderClassName, finderMethodName,
802                     finderParams, finderArgs, getSessionFactory());
803         }
804 
805         if (result == null) {
806             Session session = null;
807 
808             try {
809                 session = openSession();
810 
811                 StringMaker query = new StringMaker();
812 
813                 query.append(
814                     "FROM com.liferay.portal.model.OrgGroupPermission ");
815 
816                 if (obc != null) {
817                     query.append("ORDER BY ");
818                     query.append(obc.getOrderBy());
819                 }
820 
821                 Query q = session.createQuery(query.toString());
822 
823                 List<OrgGroupPermission> list = (List<OrgGroupPermission>)QueryUtil.list(q,
824                         getDialect(), begin, end);
825 
826                 if (obc == null) {
827                     Collections.sort(list);
828                 }
829 
830                 FinderCache.putResult(finderClassNameCacheEnabled,
831                     finderClassName, finderMethodName, finderParams,
832                     finderArgs, list);
833 
834                 return list;
835             }
836             catch (Exception e) {
837                 throw HibernateUtil.processException(e);
838             }
839             finally {
840                 closeSession(session);
841             }
842         }
843         else {
844             return (List<OrgGroupPermission>)result;
845         }
846     }
847 
848     public void removeByGroupId(long groupId) throws SystemException {
849         for (OrgGroupPermission orgGroupPermission : findByGroupId(groupId)) {
850             remove(orgGroupPermission);
851         }
852     }
853 
854     public void removeByPermissionId(long permissionId)
855         throws SystemException {
856         for (OrgGroupPermission orgGroupPermission : findByPermissionId(
857                 permissionId)) {
858             remove(orgGroupPermission);
859         }
860     }
861 
862     public void removeAll() throws SystemException {
863         for (OrgGroupPermission orgGroupPermission : findAll()) {
864             remove(orgGroupPermission);
865         }
866     }
867 
868     public int countByGroupId(long groupId) throws SystemException {
869         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
870         String finderClassName = OrgGroupPermission.class.getName();
871         String finderMethodName = "countByGroupId";
872         String[] finderParams = new String[] { Long.class.getName() };
873         Object[] finderArgs = new Object[] { new Long(groupId) };
874 
875         Object result = null;
876 
877         if (finderClassNameCacheEnabled) {
878             result = FinderCache.getResult(finderClassName, finderMethodName,
879                     finderParams, finderArgs, getSessionFactory());
880         }
881 
882         if (result == null) {
883             Session session = null;
884 
885             try {
886                 session = openSession();
887 
888                 StringMaker query = new StringMaker();
889 
890                 query.append("SELECT COUNT(*) ");
891                 query.append(
892                     "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
893 
894                 query.append("groupId = ?");
895 
896                 query.append(" ");
897 
898                 Query q = session.createQuery(query.toString());
899 
900                 int queryPos = 0;
901 
902                 q.setLong(queryPos++, groupId);
903 
904                 Long count = null;
905 
906                 Iterator<Long> itr = q.list().iterator();
907 
908                 if (itr.hasNext()) {
909                     count = itr.next();
910                 }
911 
912                 if (count == null) {
913                     count = new Long(0);
914                 }
915 
916                 FinderCache.putResult(finderClassNameCacheEnabled,
917                     finderClassName, finderMethodName, finderParams,
918                     finderArgs, count);
919 
920                 return count.intValue();
921             }
922             catch (Exception e) {
923                 throw HibernateUtil.processException(e);
924             }
925             finally {
926                 closeSession(session);
927             }
928         }
929         else {
930             return ((Long)result).intValue();
931         }
932     }
933 
934     public int countByPermissionId(long permissionId) throws SystemException {
935         boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
936         String finderClassName = OrgGroupPermission.class.getName();
937         String finderMethodName = "countByPermissionId";
938         String[] finderParams = new String[] { Long.class.getName() };
939         Object[] finderArgs = new Object[] { new Long(permissionId) };
940 
941         Object result = null;
942 
943         if (finderClassNameCacheEnabled) {
944             result = FinderCache.getResult(finderClassName, finderMethodName,
945                     finderParams, finderArgs, getSessionFactory());
946         }
947 
948         if (result == null) {
949             Session session = null;
950 
951             try {
952                 session = openSession();
953 
954                 StringMaker query = new StringMaker();
955 
956                 query.append("SELECT COUNT(*) ");
957                 query.append(
958                     "FROM com.liferay.portal.model.OrgGroupPermission WHERE ");
959 
960                 query.append("permissionId = ?");
961 
962                 query.append(" ");
963 
964                 Query q = session.createQuery(query.toString());
965 
966                 int queryPos = 0;
967 
968                 q.setLong(queryPos++, permissionId);
969 
970                 Long count = null;
971 
972                 Iterator<Long> itr = q.list().iterator();
973 
974                 if (itr.hasNext()) {
975                     count = itr.next();
976                 }
977 
978                 if (count == null) {
979                     count = new Long(0);
980                 }
981 
982                 FinderCache.putResult(finderClassNameCacheEnabled,
983                     finderClassName, finderMethodName, finderParams,
984                     finderArgs, count);
985 
986                 return count.intValue();
987             }
988             catch (Exception e) {
989                 throw HibernateUtil.processException(e);
990             }
991             finally {
992                 closeSession(session);
993             }
994         }
995         else {
996             return ((Long)result).intValue();
997         }
998     }
999 
1000    public int countAll() throws SystemException {
1001        boolean finderClassNameCacheEnabled = OrgGroupPermissionModelImpl.CACHE_ENABLED;
1002        String finderClassName = OrgGroupPermission.class.getName();
1003        String finderMethodName = "countAll";
1004        String[] finderParams = new String[] {  };
1005        Object[] finderArgs = new Object[] {  };
1006
1007        Object result = null;
1008
1009        if (finderClassNameCacheEnabled) {
1010            result = FinderCache.getResult(finderClassName, finderMethodName,
1011                    finderParams, finderArgs, getSessionFactory());
1012        }
1013
1014        if (result == null) {
1015            Session session = null;
1016
1017            try {
1018                session = openSession();
1019
1020                Query q = session.createQuery(
1021                        "SELECT COUNT(*) FROM com.liferay.portal.model.OrgGroupPermission");
1022
1023                Long count = null;
1024
1025                Iterator<Long> itr = q.list().iterator();
1026
1027                if (itr.hasNext()) {
1028                    count = itr.next();
1029                }
1030
1031                if (count == null) {
1032                    count = new Long(0);
1033                }
1034
1035                FinderCache.putResult(finderClassNameCacheEnabled,
1036                    finderClassName, finderMethodName, finderParams,
1037                    finderArgs, count);
1038
1039                return count.intValue();
1040            }
1041            catch (Exception e) {
1042                throw HibernateUtil.processException(e);
1043            }
1044            finally {
1045                closeSession(session);
1046            }
1047        }
1048        else {
1049            return ((Long)result).intValue();
1050        }
1051    }
1052
1053    protected void initDao() {
1054        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1055                    PropsUtil.get(
1056                        "value.object.listener.com.liferay.portal.model.OrgGroupPermission")));
1057
1058        if (listenerClassNames.length > 0) {
1059            try {
1060                List<ModelListener> listeners = new ArrayList<ModelListener>();
1061
1062                for (String listenerClassName : listenerClassNames) {
1063                    listeners.add((ModelListener)Class.forName(
1064                            listenerClassName).newInstance());
1065                }
1066
1067                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1068            }
1069            catch (Exception e) {
1070                _log.error(e);
1071            }
1072        }
1073    }
1074
1075    private static Log _log = LogFactory.getLog(OrgGroupPermissionPersistenceImpl.class);
1076    private ModelListener[] _listeners;
1077}