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