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