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.NoSuchUserGroupRoleException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.model.UserGroupRole;
40  import com.liferay.portal.model.impl.UserGroupRoleImpl;
41  import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
42  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
43  
44  import org.apache.commons.logging.Log;
45  import org.apache.commons.logging.LogFactory;
46  
47  import java.util.ArrayList;
48  import java.util.Collections;
49  import java.util.Iterator;
50  import java.util.List;
51  
52  /**
53   * <a href="UserGroupRolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
54   *
55   * @author Brian Wing Shun Chan
56   *
57   */
58  public class UserGroupRolePersistenceImpl extends BasePersistenceImpl
59      implements UserGroupRolePersistence {
60      public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
61          UserGroupRole userGroupRole = new UserGroupRoleImpl();
62  
63          userGroupRole.setNew(true);
64          userGroupRole.setPrimaryKey(userGroupRolePK);
65  
66          return userGroupRole;
67      }
68  
69      public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
70          throws NoSuchUserGroupRoleException, SystemException {
71          Session session = null;
72  
73          try {
74              session = openSession();
75  
76              UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
77                      userGroupRolePK);
78  
79              if (userGroupRole == null) {
80                  if (_log.isWarnEnabled()) {
81                      _log.warn("No UserGroupRole exists with the primary key " +
82                          userGroupRolePK);
83                  }
84  
85                  throw new NoSuchUserGroupRoleException(
86                      "No UserGroupRole exists with the primary key " +
87                      userGroupRolePK);
88              }
89  
90              return remove(userGroupRole);
91          }
92          catch (NoSuchUserGroupRoleException nsee) {
93              throw nsee;
94          }
95          catch (Exception e) {
96              throw processException(e);
97          }
98          finally {
99              closeSession(session);
100         }
101     }
102 
103     public UserGroupRole remove(UserGroupRole userGroupRole)
104         throws SystemException {
105         if (_listeners.length > 0) {
106             for (ModelListener listener : _listeners) {
107                 listener.onBeforeRemove(userGroupRole);
108             }
109         }
110 
111         userGroupRole = removeImpl(userGroupRole);
112 
113         if (_listeners.length > 0) {
114             for (ModelListener listener : _listeners) {
115                 listener.onAfterRemove(userGroupRole);
116             }
117         }
118 
119         return userGroupRole;
120     }
121 
122     protected UserGroupRole removeImpl(UserGroupRole userGroupRole)
123         throws SystemException {
124         Session session = null;
125 
126         try {
127             session = openSession();
128 
129             session.delete(userGroupRole);
130 
131             session.flush();
132 
133             return userGroupRole;
134         }
135         catch (Exception e) {
136             throw processException(e);
137         }
138         finally {
139             closeSession(session);
140 
141             FinderCacheUtil.clearCache(UserGroupRole.class.getName());
142         }
143     }
144 
145     /**
146      * @deprecated Use <code>update(UserGroupRole userGroupRole, boolean merge)</code>.
147      */
148     public UserGroupRole update(UserGroupRole userGroupRole)
149         throws SystemException {
150         if (_log.isWarnEnabled()) {
151             _log.warn(
152                 "Using the deprecated update(UserGroupRole userGroupRole) method. Use update(UserGroupRole userGroupRole, boolean merge) instead.");
153         }
154 
155         return update(userGroupRole, false);
156     }
157 
158     /**
159      * Add, update, or merge, the entity. This method also calls the model
160      * listeners to trigger the proper events associated with adding, deleting,
161      * or updating an entity.
162      *
163      * @param        userGroupRole the entity to add, update, or merge
164      * @param        merge boolean value for whether to merge the entity. The
165      *                default value is false. Setting merge to true is more
166      *                expensive and should only be true when userGroupRole is
167      *                transient. See LEP-5473 for a detailed discussion of this
168      *                method.
169      * @return        true if the portlet can be displayed via Ajax
170      */
171     public UserGroupRole update(UserGroupRole userGroupRole, boolean merge)
172         throws SystemException {
173         boolean isNew = userGroupRole.isNew();
174 
175         if (_listeners.length > 0) {
176             for (ModelListener listener : _listeners) {
177                 if (isNew) {
178                     listener.onBeforeCreate(userGroupRole);
179                 }
180                 else {
181                     listener.onBeforeUpdate(userGroupRole);
182                 }
183             }
184         }
185 
186         userGroupRole = updateImpl(userGroupRole, merge);
187 
188         if (_listeners.length > 0) {
189             for (ModelListener listener : _listeners) {
190                 if (isNew) {
191                     listener.onAfterCreate(userGroupRole);
192                 }
193                 else {
194                     listener.onAfterUpdate(userGroupRole);
195                 }
196             }
197         }
198 
199         return userGroupRole;
200     }
201 
202     public UserGroupRole updateImpl(
203         com.liferay.portal.model.UserGroupRole userGroupRole, boolean merge)
204         throws SystemException {
205         Session session = null;
206 
207         try {
208             session = openSession();
209 
210             if (merge) {
211                 session.merge(userGroupRole);
212             }
213             else {
214                 if (userGroupRole.isNew()) {
215                     session.save(userGroupRole);
216                 }
217             }
218 
219             session.flush();
220 
221             userGroupRole.setNew(false);
222 
223             return userGroupRole;
224         }
225         catch (Exception e) {
226             throw processException(e);
227         }
228         finally {
229             closeSession(session);
230 
231             FinderCacheUtil.clearCache(UserGroupRole.class.getName());
232         }
233     }
234 
235     public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
236         throws NoSuchUserGroupRoleException, SystemException {
237         UserGroupRole userGroupRole = fetchByPrimaryKey(userGroupRolePK);
238 
239         if (userGroupRole == null) {
240             if (_log.isWarnEnabled()) {
241                 _log.warn("No UserGroupRole exists with the primary key " +
242                     userGroupRolePK);
243             }
244 
245             throw new NoSuchUserGroupRoleException(
246                 "No UserGroupRole exists with the primary key " +
247                 userGroupRolePK);
248         }
249 
250         return userGroupRole;
251     }
252 
253     public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK)
254         throws SystemException {
255         Session session = null;
256 
257         try {
258             session = openSession();
259 
260             return (UserGroupRole)session.get(UserGroupRoleImpl.class,
261                 userGroupRolePK);
262         }
263         catch (Exception e) {
264             throw processException(e);
265         }
266         finally {
267             closeSession(session);
268         }
269     }
270 
271     public List<UserGroupRole> findByUserId(long userId)
272         throws SystemException {
273         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
274         String finderClassName = UserGroupRole.class.getName();
275         String finderMethodName = "findByUserId";
276         String[] finderParams = new String[] { Long.class.getName() };
277         Object[] finderArgs = new Object[] { new Long(userId) };
278 
279         Object result = null;
280 
281         if (finderClassNameCacheEnabled) {
282             result = FinderCacheUtil.getResult(finderClassName,
283                     finderMethodName, finderParams, finderArgs, this);
284         }
285 
286         if (result == null) {
287             Session session = null;
288 
289             try {
290                 session = openSession();
291 
292                 StringBuilder query = new StringBuilder();
293 
294                 query.append(
295                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
296 
297                 query.append("userId = ?");
298 
299                 query.append(" ");
300 
301                 Query q = session.createQuery(query.toString());
302 
303                 QueryPos qPos = QueryPos.getInstance(q);
304 
305                 qPos.add(userId);
306 
307                 List<UserGroupRole> list = q.list();
308 
309                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
310                     finderClassName, finderMethodName, finderParams,
311                     finderArgs, list);
312 
313                 return list;
314             }
315             catch (Exception e) {
316                 throw processException(e);
317             }
318             finally {
319                 closeSession(session);
320             }
321         }
322         else {
323             return (List<UserGroupRole>)result;
324         }
325     }
326 
327     public List<UserGroupRole> findByUserId(long userId, int start, int end)
328         throws SystemException {
329         return findByUserId(userId, start, end, null);
330     }
331 
332     public List<UserGroupRole> findByUserId(long userId, int start, int end,
333         OrderByComparator obc) throws SystemException {
334         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
335         String finderClassName = UserGroupRole.class.getName();
336         String finderMethodName = "findByUserId";
337         String[] finderParams = new String[] {
338                 Long.class.getName(),
339                 
340                 "java.lang.Integer", "java.lang.Integer",
341                 "com.liferay.portal.kernel.util.OrderByComparator"
342             };
343         Object[] finderArgs = new Object[] {
344                 new Long(userId),
345                 
346                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
347             };
348 
349         Object result = null;
350 
351         if (finderClassNameCacheEnabled) {
352             result = FinderCacheUtil.getResult(finderClassName,
353                     finderMethodName, finderParams, finderArgs, this);
354         }
355 
356         if (result == null) {
357             Session session = null;
358 
359             try {
360                 session = openSession();
361 
362                 StringBuilder query = new StringBuilder();
363 
364                 query.append(
365                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
366 
367                 query.append("userId = ?");
368 
369                 query.append(" ");
370 
371                 if (obc != null) {
372                     query.append("ORDER BY ");
373                     query.append(obc.getOrderBy());
374                 }
375 
376                 Query q = session.createQuery(query.toString());
377 
378                 QueryPos qPos = QueryPos.getInstance(q);
379 
380                 qPos.add(userId);
381 
382                 List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
383                         getDialect(), start, end);
384 
385                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
386                     finderClassName, finderMethodName, finderParams,
387                     finderArgs, list);
388 
389                 return list;
390             }
391             catch (Exception e) {
392                 throw processException(e);
393             }
394             finally {
395                 closeSession(session);
396             }
397         }
398         else {
399             return (List<UserGroupRole>)result;
400         }
401     }
402 
403     public UserGroupRole findByUserId_First(long userId, OrderByComparator obc)
404         throws NoSuchUserGroupRoleException, SystemException {
405         List<UserGroupRole> list = findByUserId(userId, 0, 1, obc);
406 
407         if (list.size() == 0) {
408             StringBuilder msg = new StringBuilder();
409 
410             msg.append("No UserGroupRole exists with the key {");
411 
412             msg.append("userId=" + userId);
413 
414             msg.append(StringPool.CLOSE_CURLY_BRACE);
415 
416             throw new NoSuchUserGroupRoleException(msg.toString());
417         }
418         else {
419             return list.get(0);
420         }
421     }
422 
423     public UserGroupRole findByUserId_Last(long userId, OrderByComparator obc)
424         throws NoSuchUserGroupRoleException, SystemException {
425         int count = countByUserId(userId);
426 
427         List<UserGroupRole> list = findByUserId(userId, count - 1, count, obc);
428 
429         if (list.size() == 0) {
430             StringBuilder msg = new StringBuilder();
431 
432             msg.append("No UserGroupRole exists with the key {");
433 
434             msg.append("userId=" + userId);
435 
436             msg.append(StringPool.CLOSE_CURLY_BRACE);
437 
438             throw new NoSuchUserGroupRoleException(msg.toString());
439         }
440         else {
441             return list.get(0);
442         }
443     }
444 
445     public UserGroupRole[] findByUserId_PrevAndNext(
446         UserGroupRolePK userGroupRolePK, long userId, OrderByComparator obc)
447         throws NoSuchUserGroupRoleException, SystemException {
448         UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
449 
450         int count = countByUserId(userId);
451 
452         Session session = null;
453 
454         try {
455             session = openSession();
456 
457             StringBuilder query = new StringBuilder();
458 
459             query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
460 
461             query.append("userId = ?");
462 
463             query.append(" ");
464 
465             if (obc != null) {
466                 query.append("ORDER BY ");
467                 query.append(obc.getOrderBy());
468             }
469 
470             Query q = session.createQuery(query.toString());
471 
472             QueryPos qPos = QueryPos.getInstance(q);
473 
474             qPos.add(userId);
475 
476             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
477                     userGroupRole);
478 
479             UserGroupRole[] array = new UserGroupRoleImpl[3];
480 
481             array[0] = (UserGroupRole)objArray[0];
482             array[1] = (UserGroupRole)objArray[1];
483             array[2] = (UserGroupRole)objArray[2];
484 
485             return array;
486         }
487         catch (Exception e) {
488             throw processException(e);
489         }
490         finally {
491             closeSession(session);
492         }
493     }
494 
495     public List<UserGroupRole> findByGroupId(long groupId)
496         throws SystemException {
497         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
498         String finderClassName = UserGroupRole.class.getName();
499         String finderMethodName = "findByGroupId";
500         String[] finderParams = new String[] { Long.class.getName() };
501         Object[] finderArgs = new Object[] { new Long(groupId) };
502 
503         Object result = null;
504 
505         if (finderClassNameCacheEnabled) {
506             result = FinderCacheUtil.getResult(finderClassName,
507                     finderMethodName, finderParams, finderArgs, this);
508         }
509 
510         if (result == null) {
511             Session session = null;
512 
513             try {
514                 session = openSession();
515 
516                 StringBuilder query = new StringBuilder();
517 
518                 query.append(
519                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
520 
521                 query.append("groupId = ?");
522 
523                 query.append(" ");
524 
525                 Query q = session.createQuery(query.toString());
526 
527                 QueryPos qPos = QueryPos.getInstance(q);
528 
529                 qPos.add(groupId);
530 
531                 List<UserGroupRole> list = q.list();
532 
533                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
534                     finderClassName, finderMethodName, finderParams,
535                     finderArgs, list);
536 
537                 return list;
538             }
539             catch (Exception e) {
540                 throw processException(e);
541             }
542             finally {
543                 closeSession(session);
544             }
545         }
546         else {
547             return (List<UserGroupRole>)result;
548         }
549     }
550 
551     public List<UserGroupRole> findByGroupId(long groupId, int start, int end)
552         throws SystemException {
553         return findByGroupId(groupId, start, end, null);
554     }
555 
556     public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
557         OrderByComparator obc) throws SystemException {
558         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
559         String finderClassName = UserGroupRole.class.getName();
560         String finderMethodName = "findByGroupId";
561         String[] finderParams = new String[] {
562                 Long.class.getName(),
563                 
564                 "java.lang.Integer", "java.lang.Integer",
565                 "com.liferay.portal.kernel.util.OrderByComparator"
566             };
567         Object[] finderArgs = new Object[] {
568                 new Long(groupId),
569                 
570                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
571             };
572 
573         Object result = null;
574 
575         if (finderClassNameCacheEnabled) {
576             result = FinderCacheUtil.getResult(finderClassName,
577                     finderMethodName, finderParams, finderArgs, this);
578         }
579 
580         if (result == null) {
581             Session session = null;
582 
583             try {
584                 session = openSession();
585 
586                 StringBuilder query = new StringBuilder();
587 
588                 query.append(
589                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
590 
591                 query.append("groupId = ?");
592 
593                 query.append(" ");
594 
595                 if (obc != null) {
596                     query.append("ORDER BY ");
597                     query.append(obc.getOrderBy());
598                 }
599 
600                 Query q = session.createQuery(query.toString());
601 
602                 QueryPos qPos = QueryPos.getInstance(q);
603 
604                 qPos.add(groupId);
605 
606                 List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
607                         getDialect(), start, end);
608 
609                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
610                     finderClassName, finderMethodName, finderParams,
611                     finderArgs, list);
612 
613                 return list;
614             }
615             catch (Exception e) {
616                 throw processException(e);
617             }
618             finally {
619                 closeSession(session);
620             }
621         }
622         else {
623             return (List<UserGroupRole>)result;
624         }
625     }
626 
627     public UserGroupRole findByGroupId_First(long groupId, OrderByComparator obc)
628         throws NoSuchUserGroupRoleException, SystemException {
629         List<UserGroupRole> list = findByGroupId(groupId, 0, 1, obc);
630 
631         if (list.size() == 0) {
632             StringBuilder msg = new StringBuilder();
633 
634             msg.append("No UserGroupRole exists with the key {");
635 
636             msg.append("groupId=" + groupId);
637 
638             msg.append(StringPool.CLOSE_CURLY_BRACE);
639 
640             throw new NoSuchUserGroupRoleException(msg.toString());
641         }
642         else {
643             return list.get(0);
644         }
645     }
646 
647     public UserGroupRole findByGroupId_Last(long groupId, OrderByComparator obc)
648         throws NoSuchUserGroupRoleException, SystemException {
649         int count = countByGroupId(groupId);
650 
651         List<UserGroupRole> list = findByGroupId(groupId, count - 1, count, obc);
652 
653         if (list.size() == 0) {
654             StringBuilder msg = new StringBuilder();
655 
656             msg.append("No UserGroupRole exists with the key {");
657 
658             msg.append("groupId=" + groupId);
659 
660             msg.append(StringPool.CLOSE_CURLY_BRACE);
661 
662             throw new NoSuchUserGroupRoleException(msg.toString());
663         }
664         else {
665             return list.get(0);
666         }
667     }
668 
669     public UserGroupRole[] findByGroupId_PrevAndNext(
670         UserGroupRolePK userGroupRolePK, long groupId, OrderByComparator obc)
671         throws NoSuchUserGroupRoleException, SystemException {
672         UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
673 
674         int count = countByGroupId(groupId);
675 
676         Session session = null;
677 
678         try {
679             session = openSession();
680 
681             StringBuilder query = new StringBuilder();
682 
683             query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
684 
685             query.append("groupId = ?");
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(groupId);
699 
700             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
701                     userGroupRole);
702 
703             UserGroupRole[] array = new UserGroupRoleImpl[3];
704 
705             array[0] = (UserGroupRole)objArray[0];
706             array[1] = (UserGroupRole)objArray[1];
707             array[2] = (UserGroupRole)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<UserGroupRole> findByRoleId(long roleId)
720         throws SystemException {
721         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
722         String finderClassName = UserGroupRole.class.getName();
723         String finderMethodName = "findByRoleId";
724         String[] finderParams = new String[] { Long.class.getName() };
725         Object[] finderArgs = new Object[] { new Long(roleId) };
726 
727         Object result = null;
728 
729         if (finderClassNameCacheEnabled) {
730             result = FinderCacheUtil.getResult(finderClassName,
731                     finderMethodName, finderParams, finderArgs, this);
732         }
733 
734         if (result == null) {
735             Session session = null;
736 
737             try {
738                 session = openSession();
739 
740                 StringBuilder query = new StringBuilder();
741 
742                 query.append(
743                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
744 
745                 query.append("roleId = ?");
746 
747                 query.append(" ");
748 
749                 Query q = session.createQuery(query.toString());
750 
751                 QueryPos qPos = QueryPos.getInstance(q);
752 
753                 qPos.add(roleId);
754 
755                 List<UserGroupRole> list = q.list();
756 
757                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
758                     finderClassName, finderMethodName, finderParams,
759                     finderArgs, list);
760 
761                 return list;
762             }
763             catch (Exception e) {
764                 throw processException(e);
765             }
766             finally {
767                 closeSession(session);
768             }
769         }
770         else {
771             return (List<UserGroupRole>)result;
772         }
773     }
774 
775     public List<UserGroupRole> findByRoleId(long roleId, int start, int end)
776         throws SystemException {
777         return findByRoleId(roleId, start, end, null);
778     }
779 
780     public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
781         OrderByComparator obc) throws SystemException {
782         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
783         String finderClassName = UserGroupRole.class.getName();
784         String finderMethodName = "findByRoleId";
785         String[] finderParams = new String[] {
786                 Long.class.getName(),
787                 
788                 "java.lang.Integer", "java.lang.Integer",
789                 "com.liferay.portal.kernel.util.OrderByComparator"
790             };
791         Object[] finderArgs = new Object[] {
792                 new Long(roleId),
793                 
794                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
795             };
796 
797         Object result = null;
798 
799         if (finderClassNameCacheEnabled) {
800             result = FinderCacheUtil.getResult(finderClassName,
801                     finderMethodName, finderParams, finderArgs, this);
802         }
803 
804         if (result == null) {
805             Session session = null;
806 
807             try {
808                 session = openSession();
809 
810                 StringBuilder query = new StringBuilder();
811 
812                 query.append(
813                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
814 
815                 query.append("roleId = ?");
816 
817                 query.append(" ");
818 
819                 if (obc != null) {
820                     query.append("ORDER BY ");
821                     query.append(obc.getOrderBy());
822                 }
823 
824                 Query q = session.createQuery(query.toString());
825 
826                 QueryPos qPos = QueryPos.getInstance(q);
827 
828                 qPos.add(roleId);
829 
830                 List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
831                         getDialect(), start, end);
832 
833                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
834                     finderClassName, finderMethodName, finderParams,
835                     finderArgs, list);
836 
837                 return list;
838             }
839             catch (Exception e) {
840                 throw processException(e);
841             }
842             finally {
843                 closeSession(session);
844             }
845         }
846         else {
847             return (List<UserGroupRole>)result;
848         }
849     }
850 
851     public UserGroupRole findByRoleId_First(long roleId, OrderByComparator obc)
852         throws NoSuchUserGroupRoleException, SystemException {
853         List<UserGroupRole> list = findByRoleId(roleId, 0, 1, obc);
854 
855         if (list.size() == 0) {
856             StringBuilder msg = new StringBuilder();
857 
858             msg.append("No UserGroupRole exists with the key {");
859 
860             msg.append("roleId=" + roleId);
861 
862             msg.append(StringPool.CLOSE_CURLY_BRACE);
863 
864             throw new NoSuchUserGroupRoleException(msg.toString());
865         }
866         else {
867             return list.get(0);
868         }
869     }
870 
871     public UserGroupRole findByRoleId_Last(long roleId, OrderByComparator obc)
872         throws NoSuchUserGroupRoleException, SystemException {
873         int count = countByRoleId(roleId);
874 
875         List<UserGroupRole> list = findByRoleId(roleId, count - 1, count, obc);
876 
877         if (list.size() == 0) {
878             StringBuilder msg = new StringBuilder();
879 
880             msg.append("No UserGroupRole exists with the key {");
881 
882             msg.append("roleId=" + roleId);
883 
884             msg.append(StringPool.CLOSE_CURLY_BRACE);
885 
886             throw new NoSuchUserGroupRoleException(msg.toString());
887         }
888         else {
889             return list.get(0);
890         }
891     }
892 
893     public UserGroupRole[] findByRoleId_PrevAndNext(
894         UserGroupRolePK userGroupRolePK, long roleId, OrderByComparator obc)
895         throws NoSuchUserGroupRoleException, SystemException {
896         UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
897 
898         int count = countByRoleId(roleId);
899 
900         Session session = null;
901 
902         try {
903             session = openSession();
904 
905             StringBuilder query = new StringBuilder();
906 
907             query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
908 
909             query.append("roleId = ?");
910 
911             query.append(" ");
912 
913             if (obc != null) {
914                 query.append("ORDER BY ");
915                 query.append(obc.getOrderBy());
916             }
917 
918             Query q = session.createQuery(query.toString());
919 
920             QueryPos qPos = QueryPos.getInstance(q);
921 
922             qPos.add(roleId);
923 
924             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
925                     userGroupRole);
926 
927             UserGroupRole[] array = new UserGroupRoleImpl[3];
928 
929             array[0] = (UserGroupRole)objArray[0];
930             array[1] = (UserGroupRole)objArray[1];
931             array[2] = (UserGroupRole)objArray[2];
932 
933             return array;
934         }
935         catch (Exception e) {
936             throw processException(e);
937         }
938         finally {
939             closeSession(session);
940         }
941     }
942 
943     public List<UserGroupRole> findByU_G(long userId, long groupId)
944         throws SystemException {
945         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
946         String finderClassName = UserGroupRole.class.getName();
947         String finderMethodName = "findByU_G";
948         String[] finderParams = new String[] {
949                 Long.class.getName(), Long.class.getName()
950             };
951         Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
952 
953         Object result = null;
954 
955         if (finderClassNameCacheEnabled) {
956             result = FinderCacheUtil.getResult(finderClassName,
957                     finderMethodName, finderParams, finderArgs, this);
958         }
959 
960         if (result == null) {
961             Session session = null;
962 
963             try {
964                 session = openSession();
965 
966                 StringBuilder query = new StringBuilder();
967 
968                 query.append(
969                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
970 
971                 query.append("userId = ?");
972 
973                 query.append(" AND ");
974 
975                 query.append("groupId = ?");
976 
977                 query.append(" ");
978 
979                 Query q = session.createQuery(query.toString());
980 
981                 QueryPos qPos = QueryPos.getInstance(q);
982 
983                 qPos.add(userId);
984 
985                 qPos.add(groupId);
986 
987                 List<UserGroupRole> list = q.list();
988 
989                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
990                     finderClassName, finderMethodName, finderParams,
991                     finderArgs, list);
992 
993                 return list;
994             }
995             catch (Exception e) {
996                 throw processException(e);
997             }
998             finally {
999                 closeSession(session);
1000            }
1001        }
1002        else {
1003            return (List<UserGroupRole>)result;
1004        }
1005    }
1006
1007    public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1008        int end) throws SystemException {
1009        return findByU_G(userId, groupId, start, end, null);
1010    }
1011
1012    public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1013        int end, OrderByComparator obc) throws SystemException {
1014        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1015        String finderClassName = UserGroupRole.class.getName();
1016        String finderMethodName = "findByU_G";
1017        String[] finderParams = new String[] {
1018                Long.class.getName(), Long.class.getName(),
1019                
1020                "java.lang.Integer", "java.lang.Integer",
1021                "com.liferay.portal.kernel.util.OrderByComparator"
1022            };
1023        Object[] finderArgs = new Object[] {
1024                new Long(userId), new Long(groupId),
1025                
1026                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1027            };
1028
1029        Object result = null;
1030
1031        if (finderClassNameCacheEnabled) {
1032            result = FinderCacheUtil.getResult(finderClassName,
1033                    finderMethodName, finderParams, finderArgs, this);
1034        }
1035
1036        if (result == null) {
1037            Session session = null;
1038
1039            try {
1040                session = openSession();
1041
1042                StringBuilder query = new StringBuilder();
1043
1044                query.append(
1045                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1046
1047                query.append("userId = ?");
1048
1049                query.append(" AND ");
1050
1051                query.append("groupId = ?");
1052
1053                query.append(" ");
1054
1055                if (obc != null) {
1056                    query.append("ORDER BY ");
1057                    query.append(obc.getOrderBy());
1058                }
1059
1060                Query q = session.createQuery(query.toString());
1061
1062                QueryPos qPos = QueryPos.getInstance(q);
1063
1064                qPos.add(userId);
1065
1066                qPos.add(groupId);
1067
1068                List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
1069                        getDialect(), start, end);
1070
1071                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1072                    finderClassName, finderMethodName, finderParams,
1073                    finderArgs, list);
1074
1075                return list;
1076            }
1077            catch (Exception e) {
1078                throw processException(e);
1079            }
1080            finally {
1081                closeSession(session);
1082            }
1083        }
1084        else {
1085            return (List<UserGroupRole>)result;
1086        }
1087    }
1088
1089    public UserGroupRole findByU_G_First(long userId, long groupId,
1090        OrderByComparator obc)
1091        throws NoSuchUserGroupRoleException, SystemException {
1092        List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1, obc);
1093
1094        if (list.size() == 0) {
1095            StringBuilder msg = new StringBuilder();
1096
1097            msg.append("No UserGroupRole exists with the key {");
1098
1099            msg.append("userId=" + userId);
1100
1101            msg.append(", ");
1102            msg.append("groupId=" + groupId);
1103
1104            msg.append(StringPool.CLOSE_CURLY_BRACE);
1105
1106            throw new NoSuchUserGroupRoleException(msg.toString());
1107        }
1108        else {
1109            return list.get(0);
1110        }
1111    }
1112
1113    public UserGroupRole findByU_G_Last(long userId, long groupId,
1114        OrderByComparator obc)
1115        throws NoSuchUserGroupRoleException, SystemException {
1116        int count = countByU_G(userId, groupId);
1117
1118        List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1119                obc);
1120
1121        if (list.size() == 0) {
1122            StringBuilder msg = new StringBuilder();
1123
1124            msg.append("No UserGroupRole exists with the key {");
1125
1126            msg.append("userId=" + userId);
1127
1128            msg.append(", ");
1129            msg.append("groupId=" + groupId);
1130
1131            msg.append(StringPool.CLOSE_CURLY_BRACE);
1132
1133            throw new NoSuchUserGroupRoleException(msg.toString());
1134        }
1135        else {
1136            return list.get(0);
1137        }
1138    }
1139
1140    public UserGroupRole[] findByU_G_PrevAndNext(
1141        UserGroupRolePK userGroupRolePK, long userId, long groupId,
1142        OrderByComparator obc)
1143        throws NoSuchUserGroupRoleException, SystemException {
1144        UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1145
1146        int count = countByU_G(userId, groupId);
1147
1148        Session session = null;
1149
1150        try {
1151            session = openSession();
1152
1153            StringBuilder query = new StringBuilder();
1154
1155            query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1156
1157            query.append("userId = ?");
1158
1159            query.append(" AND ");
1160
1161            query.append("groupId = ?");
1162
1163            query.append(" ");
1164
1165            if (obc != null) {
1166                query.append("ORDER BY ");
1167                query.append(obc.getOrderBy());
1168            }
1169
1170            Query q = session.createQuery(query.toString());
1171
1172            QueryPos qPos = QueryPos.getInstance(q);
1173
1174            qPos.add(userId);
1175
1176            qPos.add(groupId);
1177
1178            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1179                    userGroupRole);
1180
1181            UserGroupRole[] array = new UserGroupRoleImpl[3];
1182
1183            array[0] = (UserGroupRole)objArray[0];
1184            array[1] = (UserGroupRole)objArray[1];
1185            array[2] = (UserGroupRole)objArray[2];
1186
1187            return array;
1188        }
1189        catch (Exception e) {
1190            throw processException(e);
1191        }
1192        finally {
1193            closeSession(session);
1194        }
1195    }
1196
1197    public List<UserGroupRole> findByG_R(long groupId, long roleId)
1198        throws SystemException {
1199        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1200        String finderClassName = UserGroupRole.class.getName();
1201        String finderMethodName = "findByG_R";
1202        String[] finderParams = new String[] {
1203                Long.class.getName(), Long.class.getName()
1204            };
1205        Object[] finderArgs = new Object[] { new Long(groupId), new Long(roleId) };
1206
1207        Object result = null;
1208
1209        if (finderClassNameCacheEnabled) {
1210            result = FinderCacheUtil.getResult(finderClassName,
1211                    finderMethodName, finderParams, finderArgs, this);
1212        }
1213
1214        if (result == null) {
1215            Session session = null;
1216
1217            try {
1218                session = openSession();
1219
1220                StringBuilder query = new StringBuilder();
1221
1222                query.append(
1223                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1224
1225                query.append("groupId = ?");
1226
1227                query.append(" AND ");
1228
1229                query.append("roleId = ?");
1230
1231                query.append(" ");
1232
1233                Query q = session.createQuery(query.toString());
1234
1235                QueryPos qPos = QueryPos.getInstance(q);
1236
1237                qPos.add(groupId);
1238
1239                qPos.add(roleId);
1240
1241                List<UserGroupRole> list = q.list();
1242
1243                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1244                    finderClassName, finderMethodName, finderParams,
1245                    finderArgs, list);
1246
1247                return list;
1248            }
1249            catch (Exception e) {
1250                throw processException(e);
1251            }
1252            finally {
1253                closeSession(session);
1254            }
1255        }
1256        else {
1257            return (List<UserGroupRole>)result;
1258        }
1259    }
1260
1261    public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
1262        int end) throws SystemException {
1263        return findByG_R(groupId, roleId, start, end, null);
1264    }
1265
1266    public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
1267        int end, OrderByComparator obc) throws SystemException {
1268        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1269        String finderClassName = UserGroupRole.class.getName();
1270        String finderMethodName = "findByG_R";
1271        String[] finderParams = new String[] {
1272                Long.class.getName(), Long.class.getName(),
1273                
1274                "java.lang.Integer", "java.lang.Integer",
1275                "com.liferay.portal.kernel.util.OrderByComparator"
1276            };
1277        Object[] finderArgs = new Object[] {
1278                new Long(groupId), new Long(roleId),
1279                
1280                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1281            };
1282
1283        Object result = null;
1284
1285        if (finderClassNameCacheEnabled) {
1286            result = FinderCacheUtil.getResult(finderClassName,
1287                    finderMethodName, finderParams, finderArgs, this);
1288        }
1289
1290        if (result == null) {
1291            Session session = null;
1292
1293            try {
1294                session = openSession();
1295
1296                StringBuilder query = new StringBuilder();
1297
1298                query.append(
1299                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1300
1301                query.append("groupId = ?");
1302
1303                query.append(" AND ");
1304
1305                query.append("roleId = ?");
1306
1307                query.append(" ");
1308
1309                if (obc != null) {
1310                    query.append("ORDER BY ");
1311                    query.append(obc.getOrderBy());
1312                }
1313
1314                Query q = session.createQuery(query.toString());
1315
1316                QueryPos qPos = QueryPos.getInstance(q);
1317
1318                qPos.add(groupId);
1319
1320                qPos.add(roleId);
1321
1322                List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
1323                        getDialect(), start, end);
1324
1325                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1326                    finderClassName, finderMethodName, finderParams,
1327                    finderArgs, list);
1328
1329                return list;
1330            }
1331            catch (Exception e) {
1332                throw processException(e);
1333            }
1334            finally {
1335                closeSession(session);
1336            }
1337        }
1338        else {
1339            return (List<UserGroupRole>)result;
1340        }
1341    }
1342
1343    public UserGroupRole findByG_R_First(long groupId, long roleId,
1344        OrderByComparator obc)
1345        throws NoSuchUserGroupRoleException, SystemException {
1346        List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1, obc);
1347
1348        if (list.size() == 0) {
1349            StringBuilder msg = new StringBuilder();
1350
1351            msg.append("No UserGroupRole exists with the key {");
1352
1353            msg.append("groupId=" + groupId);
1354
1355            msg.append(", ");
1356            msg.append("roleId=" + roleId);
1357
1358            msg.append(StringPool.CLOSE_CURLY_BRACE);
1359
1360            throw new NoSuchUserGroupRoleException(msg.toString());
1361        }
1362        else {
1363            return list.get(0);
1364        }
1365    }
1366
1367    public UserGroupRole findByG_R_Last(long groupId, long roleId,
1368        OrderByComparator obc)
1369        throws NoSuchUserGroupRoleException, SystemException {
1370        int count = countByG_R(groupId, roleId);
1371
1372        List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
1373                obc);
1374
1375        if (list.size() == 0) {
1376            StringBuilder msg = new StringBuilder();
1377
1378            msg.append("No UserGroupRole exists with the key {");
1379
1380            msg.append("groupId=" + groupId);
1381
1382            msg.append(", ");
1383            msg.append("roleId=" + roleId);
1384
1385            msg.append(StringPool.CLOSE_CURLY_BRACE);
1386
1387            throw new NoSuchUserGroupRoleException(msg.toString());
1388        }
1389        else {
1390            return list.get(0);
1391        }
1392    }
1393
1394    public UserGroupRole[] findByG_R_PrevAndNext(
1395        UserGroupRolePK userGroupRolePK, long groupId, long roleId,
1396        OrderByComparator obc)
1397        throws NoSuchUserGroupRoleException, SystemException {
1398        UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1399
1400        int count = countByG_R(groupId, roleId);
1401
1402        Session session = null;
1403
1404        try {
1405            session = openSession();
1406
1407            StringBuilder query = new StringBuilder();
1408
1409            query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1410
1411            query.append("groupId = ?");
1412
1413            query.append(" AND ");
1414
1415            query.append("roleId = ?");
1416
1417            query.append(" ");
1418
1419            if (obc != null) {
1420                query.append("ORDER BY ");
1421                query.append(obc.getOrderBy());
1422            }
1423
1424            Query q = session.createQuery(query.toString());
1425
1426            QueryPos qPos = QueryPos.getInstance(q);
1427
1428            qPos.add(groupId);
1429
1430            qPos.add(roleId);
1431
1432            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1433                    userGroupRole);
1434
1435            UserGroupRole[] array = new UserGroupRoleImpl[3];
1436
1437            array[0] = (UserGroupRole)objArray[0];
1438            array[1] = (UserGroupRole)objArray[1];
1439            array[2] = (UserGroupRole)objArray[2];
1440
1441            return array;
1442        }
1443        catch (Exception e) {
1444            throw processException(e);
1445        }
1446        finally {
1447            closeSession(session);
1448        }
1449    }
1450
1451    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1452        throws SystemException {
1453        Session session = null;
1454
1455        try {
1456            session = openSession();
1457
1458            dynamicQuery.compile(session);
1459
1460            return dynamicQuery.list();
1461        }
1462        catch (Exception e) {
1463            throw processException(e);
1464        }
1465        finally {
1466            closeSession(session);
1467        }
1468    }
1469
1470    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1471        int start, int end) throws SystemException {
1472        Session session = null;
1473
1474        try {
1475            session = openSession();
1476
1477            dynamicQuery.setLimit(start, end);
1478
1479            dynamicQuery.compile(session);
1480
1481            return dynamicQuery.list();
1482        }
1483        catch (Exception e) {
1484            throw processException(e);
1485        }
1486        finally {
1487            closeSession(session);
1488        }
1489    }
1490
1491    public List<UserGroupRole> findAll() throws SystemException {
1492        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1493    }
1494
1495    public List<UserGroupRole> findAll(int start, int end)
1496        throws SystemException {
1497        return findAll(start, end, null);
1498    }
1499
1500    public List<UserGroupRole> findAll(int start, int end, OrderByComparator obc)
1501        throws SystemException {
1502        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1503        String finderClassName = UserGroupRole.class.getName();
1504        String finderMethodName = "findAll";
1505        String[] finderParams = new String[] {
1506                "java.lang.Integer", "java.lang.Integer",
1507                "com.liferay.portal.kernel.util.OrderByComparator"
1508            };
1509        Object[] finderArgs = new Object[] {
1510                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1511            };
1512
1513        Object result = null;
1514
1515        if (finderClassNameCacheEnabled) {
1516            result = FinderCacheUtil.getResult(finderClassName,
1517                    finderMethodName, finderParams, finderArgs, this);
1518        }
1519
1520        if (result == null) {
1521            Session session = null;
1522
1523            try {
1524                session = openSession();
1525
1526                StringBuilder query = new StringBuilder();
1527
1528                query.append("FROM com.liferay.portal.model.UserGroupRole ");
1529
1530                if (obc != null) {
1531                    query.append("ORDER BY ");
1532                    query.append(obc.getOrderBy());
1533                }
1534
1535                Query q = session.createQuery(query.toString());
1536
1537                List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
1538                        getDialect(), start, end);
1539
1540                if (obc == null) {
1541                    Collections.sort(list);
1542                }
1543
1544                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1545                    finderClassName, finderMethodName, finderParams,
1546                    finderArgs, list);
1547
1548                return list;
1549            }
1550            catch (Exception e) {
1551                throw processException(e);
1552            }
1553            finally {
1554                closeSession(session);
1555            }
1556        }
1557        else {
1558            return (List<UserGroupRole>)result;
1559        }
1560    }
1561
1562    public void removeByUserId(long userId) throws SystemException {
1563        for (UserGroupRole userGroupRole : findByUserId(userId)) {
1564            remove(userGroupRole);
1565        }
1566    }
1567
1568    public void removeByGroupId(long groupId) throws SystemException {
1569        for (UserGroupRole userGroupRole : findByGroupId(groupId)) {
1570            remove(userGroupRole);
1571        }
1572    }
1573
1574    public void removeByRoleId(long roleId) throws SystemException {
1575        for (UserGroupRole userGroupRole : findByRoleId(roleId)) {
1576            remove(userGroupRole);
1577        }
1578    }
1579
1580    public void removeByU_G(long userId, long groupId)
1581        throws SystemException {
1582        for (UserGroupRole userGroupRole : findByU_G(userId, groupId)) {
1583            remove(userGroupRole);
1584        }
1585    }
1586
1587    public void removeByG_R(long groupId, long roleId)
1588        throws SystemException {
1589        for (UserGroupRole userGroupRole : findByG_R(groupId, roleId)) {
1590            remove(userGroupRole);
1591        }
1592    }
1593
1594    public void removeAll() throws SystemException {
1595        for (UserGroupRole userGroupRole : findAll()) {
1596            remove(userGroupRole);
1597        }
1598    }
1599
1600    public int countByUserId(long userId) throws SystemException {
1601        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1602        String finderClassName = UserGroupRole.class.getName();
1603        String finderMethodName = "countByUserId";
1604        String[] finderParams = new String[] { Long.class.getName() };
1605        Object[] finderArgs = new Object[] { new Long(userId) };
1606
1607        Object result = null;
1608
1609        if (finderClassNameCacheEnabled) {
1610            result = FinderCacheUtil.getResult(finderClassName,
1611                    finderMethodName, finderParams, finderArgs, this);
1612        }
1613
1614        if (result == null) {
1615            Session session = null;
1616
1617            try {
1618                session = openSession();
1619
1620                StringBuilder query = new StringBuilder();
1621
1622                query.append("SELECT COUNT(*) ");
1623                query.append(
1624                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1625
1626                query.append("userId = ?");
1627
1628                query.append(" ");
1629
1630                Query q = session.createQuery(query.toString());
1631
1632                QueryPos qPos = QueryPos.getInstance(q);
1633
1634                qPos.add(userId);
1635
1636                Long count = null;
1637
1638                Iterator<Long> itr = q.list().iterator();
1639
1640                if (itr.hasNext()) {
1641                    count = itr.next();
1642                }
1643
1644                if (count == null) {
1645                    count = new Long(0);
1646                }
1647
1648                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1649                    finderClassName, finderMethodName, finderParams,
1650                    finderArgs, count);
1651
1652                return count.intValue();
1653            }
1654            catch (Exception e) {
1655                throw processException(e);
1656            }
1657            finally {
1658                closeSession(session);
1659            }
1660        }
1661        else {
1662            return ((Long)result).intValue();
1663        }
1664    }
1665
1666    public int countByGroupId(long groupId) throws SystemException {
1667        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1668        String finderClassName = UserGroupRole.class.getName();
1669        String finderMethodName = "countByGroupId";
1670        String[] finderParams = new String[] { Long.class.getName() };
1671        Object[] finderArgs = new Object[] { new Long(groupId) };
1672
1673        Object result = null;
1674
1675        if (finderClassNameCacheEnabled) {
1676            result = FinderCacheUtil.getResult(finderClassName,
1677                    finderMethodName, finderParams, finderArgs, this);
1678        }
1679
1680        if (result == null) {
1681            Session session = null;
1682
1683            try {
1684                session = openSession();
1685
1686                StringBuilder query = new StringBuilder();
1687
1688                query.append("SELECT COUNT(*) ");
1689                query.append(
1690                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1691
1692                query.append("groupId = ?");
1693
1694                query.append(" ");
1695
1696                Query q = session.createQuery(query.toString());
1697
1698                QueryPos qPos = QueryPos.getInstance(q);
1699
1700                qPos.add(groupId);
1701
1702                Long count = null;
1703
1704                Iterator<Long> itr = q.list().iterator();
1705
1706                if (itr.hasNext()) {
1707                    count = itr.next();
1708                }
1709
1710                if (count == null) {
1711                    count = new Long(0);
1712                }
1713
1714                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1715                    finderClassName, finderMethodName, finderParams,
1716                    finderArgs, count);
1717
1718                return count.intValue();
1719            }
1720            catch (Exception e) {
1721                throw processException(e);
1722            }
1723            finally {
1724                closeSession(session);
1725            }
1726        }
1727        else {
1728            return ((Long)result).intValue();
1729        }
1730    }
1731
1732    public int countByRoleId(long roleId) throws SystemException {
1733        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1734        String finderClassName = UserGroupRole.class.getName();
1735        String finderMethodName = "countByRoleId";
1736        String[] finderParams = new String[] { Long.class.getName() };
1737        Object[] finderArgs = new Object[] { new Long(roleId) };
1738
1739        Object result = null;
1740
1741        if (finderClassNameCacheEnabled) {
1742            result = FinderCacheUtil.getResult(finderClassName,
1743                    finderMethodName, finderParams, finderArgs, this);
1744        }
1745
1746        if (result == null) {
1747            Session session = null;
1748
1749            try {
1750                session = openSession();
1751
1752                StringBuilder query = new StringBuilder();
1753
1754                query.append("SELECT COUNT(*) ");
1755                query.append(
1756                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1757
1758                query.append("roleId = ?");
1759
1760                query.append(" ");
1761
1762                Query q = session.createQuery(query.toString());
1763
1764                QueryPos qPos = QueryPos.getInstance(q);
1765
1766                qPos.add(roleId);
1767
1768                Long count = null;
1769
1770                Iterator<Long> itr = q.list().iterator();
1771
1772                if (itr.hasNext()) {
1773                    count = itr.next();
1774                }
1775
1776                if (count == null) {
1777                    count = new Long(0);
1778                }
1779
1780                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1781                    finderClassName, finderMethodName, finderParams,
1782                    finderArgs, count);
1783
1784                return count.intValue();
1785            }
1786            catch (Exception e) {
1787                throw processException(e);
1788            }
1789            finally {
1790                closeSession(session);
1791            }
1792        }
1793        else {
1794            return ((Long)result).intValue();
1795        }
1796    }
1797
1798    public int countByU_G(long userId, long groupId) throws SystemException {
1799        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1800        String finderClassName = UserGroupRole.class.getName();
1801        String finderMethodName = "countByU_G";
1802        String[] finderParams = new String[] {
1803                Long.class.getName(), Long.class.getName()
1804            };
1805        Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
1806
1807        Object result = null;
1808
1809        if (finderClassNameCacheEnabled) {
1810            result = FinderCacheUtil.getResult(finderClassName,
1811                    finderMethodName, finderParams, finderArgs, this);
1812        }
1813
1814        if (result == null) {
1815            Session session = null;
1816
1817            try {
1818                session = openSession();
1819
1820                StringBuilder query = new StringBuilder();
1821
1822                query.append("SELECT COUNT(*) ");
1823                query.append(
1824                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1825
1826                query.append("userId = ?");
1827
1828                query.append(" AND ");
1829
1830                query.append("groupId = ?");
1831
1832                query.append(" ");
1833
1834                Query q = session.createQuery(query.toString());
1835
1836                QueryPos qPos = QueryPos.getInstance(q);
1837
1838                qPos.add(userId);
1839
1840                qPos.add(groupId);
1841
1842                Long count = null;
1843
1844                Iterator<Long> itr = q.list().iterator();
1845
1846                if (itr.hasNext()) {
1847                    count = itr.next();
1848                }
1849
1850                if (count == null) {
1851                    count = new Long(0);
1852                }
1853
1854                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1855                    finderClassName, finderMethodName, finderParams,
1856                    finderArgs, count);
1857
1858                return count.intValue();
1859            }
1860            catch (Exception e) {
1861                throw processException(e);
1862            }
1863            finally {
1864                closeSession(session);
1865            }
1866        }
1867        else {
1868            return ((Long)result).intValue();
1869        }
1870    }
1871
1872    public int countByG_R(long groupId, long roleId) throws SystemException {
1873        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1874        String finderClassName = UserGroupRole.class.getName();
1875        String finderMethodName = "countByG_R";
1876        String[] finderParams = new String[] {
1877                Long.class.getName(), Long.class.getName()
1878            };
1879        Object[] finderArgs = new Object[] { new Long(groupId), new Long(roleId) };
1880
1881        Object result = null;
1882
1883        if (finderClassNameCacheEnabled) {
1884            result = FinderCacheUtil.getResult(finderClassName,
1885                    finderMethodName, finderParams, finderArgs, this);
1886        }
1887
1888        if (result == null) {
1889            Session session = null;
1890
1891            try {
1892                session = openSession();
1893
1894                StringBuilder query = new StringBuilder();
1895
1896                query.append("SELECT COUNT(*) ");
1897                query.append(
1898                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1899
1900                query.append("groupId = ?");
1901
1902                query.append(" AND ");
1903
1904                query.append("roleId = ?");
1905
1906                query.append(" ");
1907
1908                Query q = session.createQuery(query.toString());
1909
1910                QueryPos qPos = QueryPos.getInstance(q);
1911
1912                qPos.add(groupId);
1913
1914                qPos.add(roleId);
1915
1916                Long count = null;
1917
1918                Iterator<Long> itr = q.list().iterator();
1919
1920                if (itr.hasNext()) {
1921                    count = itr.next();
1922                }
1923
1924                if (count == null) {
1925                    count = new Long(0);
1926                }
1927
1928                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1929                    finderClassName, finderMethodName, finderParams,
1930                    finderArgs, count);
1931
1932                return count.intValue();
1933            }
1934            catch (Exception e) {
1935                throw processException(e);
1936            }
1937            finally {
1938                closeSession(session);
1939            }
1940        }
1941        else {
1942            return ((Long)result).intValue();
1943        }
1944    }
1945
1946    public int countAll() throws SystemException {
1947        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1948        String finderClassName = UserGroupRole.class.getName();
1949        String finderMethodName = "countAll";
1950        String[] finderParams = new String[] {  };
1951        Object[] finderArgs = new Object[] {  };
1952
1953        Object result = null;
1954
1955        if (finderClassNameCacheEnabled) {
1956            result = FinderCacheUtil.getResult(finderClassName,
1957                    finderMethodName, finderParams, finderArgs, this);
1958        }
1959
1960        if (result == null) {
1961            Session session = null;
1962
1963            try {
1964                session = openSession();
1965
1966                Query q = session.createQuery(
1967                        "SELECT COUNT(*) FROM com.liferay.portal.model.UserGroupRole");
1968
1969                Long count = null;
1970
1971                Iterator<Long> itr = q.list().iterator();
1972
1973                if (itr.hasNext()) {
1974                    count = itr.next();
1975                }
1976
1977                if (count == null) {
1978                    count = new Long(0);
1979                }
1980
1981                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1982                    finderClassName, finderMethodName, finderParams,
1983                    finderArgs, count);
1984
1985                return count.intValue();
1986            }
1987            catch (Exception e) {
1988                throw processException(e);
1989            }
1990            finally {
1991                closeSession(session);
1992            }
1993        }
1994        else {
1995            return ((Long)result).intValue();
1996        }
1997    }
1998
1999    public void registerListener(ModelListener listener) {
2000        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2001
2002        listeners.add(listener);
2003
2004        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2005    }
2006
2007    public void unregisterListener(ModelListener listener) {
2008        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2009
2010        listeners.remove(listener);
2011
2012        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2013    }
2014
2015    public void afterPropertiesSet() {
2016        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2017                    com.liferay.portal.util.PropsUtil.get(
2018                        "value.object.listener.com.liferay.portal.model.UserGroupRole")));
2019
2020        if (listenerClassNames.length > 0) {
2021            try {
2022                List<ModelListener> listeners = new ArrayList<ModelListener>();
2023
2024                for (String listenerClassName : listenerClassNames) {
2025                    listeners.add((ModelListener)Class.forName(
2026                            listenerClassName).newInstance());
2027                }
2028
2029                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2030            }
2031            catch (Exception e) {
2032                _log.error(e);
2033            }
2034        }
2035    }
2036
2037    private static Log _log = LogFactory.getLog(UserGroupRolePersistenceImpl.class);
2038    private ModelListener[] _listeners = new ModelListener[0];
2039}