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