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