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