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             if (BatchSessionUtil.isEnabled()) {
130                 Object staleObject = session.get(UserGroupRoleImpl.class,
131                         userGroupRole.getPrimaryKeyObj());
132 
133                 if (staleObject != null) {
134                     session.evict(staleObject);
135                 }
136             }
137 
138             session.delete(userGroupRole);
139 
140             session.flush();
141 
142             return userGroupRole;
143         }
144         catch (Exception e) {
145             throw processException(e);
146         }
147         finally {
148             closeSession(session);
149 
150             FinderCacheUtil.clearCache(UserGroupRole.class.getName());
151         }
152     }
153 
154     /**
155      * @deprecated Use <code>update(UserGroupRole userGroupRole, boolean merge)</code>.
156      */
157     public UserGroupRole update(UserGroupRole userGroupRole)
158         throws SystemException {
159         if (_log.isWarnEnabled()) {
160             _log.warn(
161                 "Using the deprecated update(UserGroupRole userGroupRole) method. Use update(UserGroupRole userGroupRole, boolean merge) instead.");
162         }
163 
164         return update(userGroupRole, false);
165     }
166 
167     /**
168      * Add, update, or merge, the entity. This method also calls the model
169      * listeners to trigger the proper events associated with adding, deleting,
170      * or updating an entity.
171      *
172      * @param        userGroupRole the entity to add, update, or merge
173      * @param        merge boolean value for whether to merge the entity. The
174      *                default value is false. Setting merge to true is more
175      *                expensive and should only be true when userGroupRole is
176      *                transient. See LEP-5473 for a detailed discussion of this
177      *                method.
178      * @return        true if the portlet can be displayed via Ajax
179      */
180     public UserGroupRole update(UserGroupRole userGroupRole, boolean merge)
181         throws SystemException {
182         boolean isNew = userGroupRole.isNew();
183 
184         if (_listeners.length > 0) {
185             for (ModelListener listener : _listeners) {
186                 if (isNew) {
187                     listener.onBeforeCreate(userGroupRole);
188                 }
189                 else {
190                     listener.onBeforeUpdate(userGroupRole);
191                 }
192             }
193         }
194 
195         userGroupRole = updateImpl(userGroupRole, merge);
196 
197         if (_listeners.length > 0) {
198             for (ModelListener listener : _listeners) {
199                 if (isNew) {
200                     listener.onAfterCreate(userGroupRole);
201                 }
202                 else {
203                     listener.onAfterUpdate(userGroupRole);
204                 }
205             }
206         }
207 
208         return userGroupRole;
209     }
210 
211     public UserGroupRole updateImpl(
212         com.liferay.portal.model.UserGroupRole userGroupRole, boolean merge)
213         throws SystemException {
214         Session session = null;
215 
216         try {
217             session = openSession();
218 
219             BatchSessionUtil.update(session, userGroupRole, merge);
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 = null;
1538
1539                if (obc == null) {
1540                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1541                            start, end, false);
1542
1543                    Collections.sort(list);
1544                }
1545                else {
1546                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1547                            start, end);
1548                }
1549
1550                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1551                    finderClassName, finderMethodName, finderParams,
1552                    finderArgs, list);
1553
1554                return list;
1555            }
1556            catch (Exception e) {
1557                throw processException(e);
1558            }
1559            finally {
1560                closeSession(session);
1561            }
1562        }
1563        else {
1564            return (List<UserGroupRole>)result;
1565        }
1566    }
1567
1568    public void removeByUserId(long userId) throws SystemException {
1569        for (UserGroupRole userGroupRole : findByUserId(userId)) {
1570            remove(userGroupRole);
1571        }
1572    }
1573
1574    public void removeByGroupId(long groupId) throws SystemException {
1575        for (UserGroupRole userGroupRole : findByGroupId(groupId)) {
1576            remove(userGroupRole);
1577        }
1578    }
1579
1580    public void removeByRoleId(long roleId) throws SystemException {
1581        for (UserGroupRole userGroupRole : findByRoleId(roleId)) {
1582            remove(userGroupRole);
1583        }
1584    }
1585
1586    public void removeByU_G(long userId, long groupId)
1587        throws SystemException {
1588        for (UserGroupRole userGroupRole : findByU_G(userId, groupId)) {
1589            remove(userGroupRole);
1590        }
1591    }
1592
1593    public void removeByG_R(long groupId, long roleId)
1594        throws SystemException {
1595        for (UserGroupRole userGroupRole : findByG_R(groupId, roleId)) {
1596            remove(userGroupRole);
1597        }
1598    }
1599
1600    public void removeAll() throws SystemException {
1601        for (UserGroupRole userGroupRole : findAll()) {
1602            remove(userGroupRole);
1603        }
1604    }
1605
1606    public int countByUserId(long userId) throws SystemException {
1607        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1608        String finderClassName = UserGroupRole.class.getName();
1609        String finderMethodName = "countByUserId";
1610        String[] finderParams = new String[] { Long.class.getName() };
1611        Object[] finderArgs = new Object[] { new Long(userId) };
1612
1613        Object result = null;
1614
1615        if (finderClassNameCacheEnabled) {
1616            result = FinderCacheUtil.getResult(finderClassName,
1617                    finderMethodName, finderParams, finderArgs, this);
1618        }
1619
1620        if (result == null) {
1621            Session session = null;
1622
1623            try {
1624                session = openSession();
1625
1626                StringBuilder query = new StringBuilder();
1627
1628                query.append("SELECT COUNT(*) ");
1629                query.append(
1630                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1631
1632                query.append("userId = ?");
1633
1634                query.append(" ");
1635
1636                Query q = session.createQuery(query.toString());
1637
1638                QueryPos qPos = QueryPos.getInstance(q);
1639
1640                qPos.add(userId);
1641
1642                Long count = null;
1643
1644                Iterator<Long> itr = q.list().iterator();
1645
1646                if (itr.hasNext()) {
1647                    count = itr.next();
1648                }
1649
1650                if (count == null) {
1651                    count = new Long(0);
1652                }
1653
1654                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1655                    finderClassName, finderMethodName, finderParams,
1656                    finderArgs, count);
1657
1658                return count.intValue();
1659            }
1660            catch (Exception e) {
1661                throw processException(e);
1662            }
1663            finally {
1664                closeSession(session);
1665            }
1666        }
1667        else {
1668            return ((Long)result).intValue();
1669        }
1670    }
1671
1672    public int countByGroupId(long groupId) throws SystemException {
1673        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1674        String finderClassName = UserGroupRole.class.getName();
1675        String finderMethodName = "countByGroupId";
1676        String[] finderParams = new String[] { Long.class.getName() };
1677        Object[] finderArgs = new Object[] { new Long(groupId) };
1678
1679        Object result = null;
1680
1681        if (finderClassNameCacheEnabled) {
1682            result = FinderCacheUtil.getResult(finderClassName,
1683                    finderMethodName, finderParams, finderArgs, this);
1684        }
1685
1686        if (result == null) {
1687            Session session = null;
1688
1689            try {
1690                session = openSession();
1691
1692                StringBuilder query = new StringBuilder();
1693
1694                query.append("SELECT COUNT(*) ");
1695                query.append(
1696                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1697
1698                query.append("groupId = ?");
1699
1700                query.append(" ");
1701
1702                Query q = session.createQuery(query.toString());
1703
1704                QueryPos qPos = QueryPos.getInstance(q);
1705
1706                qPos.add(groupId);
1707
1708                Long count = null;
1709
1710                Iterator<Long> itr = q.list().iterator();
1711
1712                if (itr.hasNext()) {
1713                    count = itr.next();
1714                }
1715
1716                if (count == null) {
1717                    count = new Long(0);
1718                }
1719
1720                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1721                    finderClassName, finderMethodName, finderParams,
1722                    finderArgs, count);
1723
1724                return count.intValue();
1725            }
1726            catch (Exception e) {
1727                throw processException(e);
1728            }
1729            finally {
1730                closeSession(session);
1731            }
1732        }
1733        else {
1734            return ((Long)result).intValue();
1735        }
1736    }
1737
1738    public int countByRoleId(long roleId) throws SystemException {
1739        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1740        String finderClassName = UserGroupRole.class.getName();
1741        String finderMethodName = "countByRoleId";
1742        String[] finderParams = new String[] { Long.class.getName() };
1743        Object[] finderArgs = new Object[] { new Long(roleId) };
1744
1745        Object result = null;
1746
1747        if (finderClassNameCacheEnabled) {
1748            result = FinderCacheUtil.getResult(finderClassName,
1749                    finderMethodName, finderParams, finderArgs, this);
1750        }
1751
1752        if (result == null) {
1753            Session session = null;
1754
1755            try {
1756                session = openSession();
1757
1758                StringBuilder query = new StringBuilder();
1759
1760                query.append("SELECT COUNT(*) ");
1761                query.append(
1762                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1763
1764                query.append("roleId = ?");
1765
1766                query.append(" ");
1767
1768                Query q = session.createQuery(query.toString());
1769
1770                QueryPos qPos = QueryPos.getInstance(q);
1771
1772                qPos.add(roleId);
1773
1774                Long count = null;
1775
1776                Iterator<Long> itr = q.list().iterator();
1777
1778                if (itr.hasNext()) {
1779                    count = itr.next();
1780                }
1781
1782                if (count == null) {
1783                    count = new Long(0);
1784                }
1785
1786                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1787                    finderClassName, finderMethodName, finderParams,
1788                    finderArgs, count);
1789
1790                return count.intValue();
1791            }
1792            catch (Exception e) {
1793                throw processException(e);
1794            }
1795            finally {
1796                closeSession(session);
1797            }
1798        }
1799        else {
1800            return ((Long)result).intValue();
1801        }
1802    }
1803
1804    public int countByU_G(long userId, long groupId) throws SystemException {
1805        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1806        String finderClassName = UserGroupRole.class.getName();
1807        String finderMethodName = "countByU_G";
1808        String[] finderParams = new String[] {
1809                Long.class.getName(), Long.class.getName()
1810            };
1811        Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
1812
1813        Object result = null;
1814
1815        if (finderClassNameCacheEnabled) {
1816            result = FinderCacheUtil.getResult(finderClassName,
1817                    finderMethodName, finderParams, finderArgs, this);
1818        }
1819
1820        if (result == null) {
1821            Session session = null;
1822
1823            try {
1824                session = openSession();
1825
1826                StringBuilder query = new StringBuilder();
1827
1828                query.append("SELECT COUNT(*) ");
1829                query.append(
1830                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1831
1832                query.append("userId = ?");
1833
1834                query.append(" AND ");
1835
1836                query.append("groupId = ?");
1837
1838                query.append(" ");
1839
1840                Query q = session.createQuery(query.toString());
1841
1842                QueryPos qPos = QueryPos.getInstance(q);
1843
1844                qPos.add(userId);
1845
1846                qPos.add(groupId);
1847
1848                Long count = null;
1849
1850                Iterator<Long> itr = q.list().iterator();
1851
1852                if (itr.hasNext()) {
1853                    count = itr.next();
1854                }
1855
1856                if (count == null) {
1857                    count = new Long(0);
1858                }
1859
1860                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1861                    finderClassName, finderMethodName, finderParams,
1862                    finderArgs, count);
1863
1864                return count.intValue();
1865            }
1866            catch (Exception e) {
1867                throw processException(e);
1868            }
1869            finally {
1870                closeSession(session);
1871            }
1872        }
1873        else {
1874            return ((Long)result).intValue();
1875        }
1876    }
1877
1878    public int countByG_R(long groupId, long roleId) throws SystemException {
1879        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1880        String finderClassName = UserGroupRole.class.getName();
1881        String finderMethodName = "countByG_R";
1882        String[] finderParams = new String[] {
1883                Long.class.getName(), Long.class.getName()
1884            };
1885        Object[] finderArgs = new Object[] { new Long(groupId), new Long(roleId) };
1886
1887        Object result = null;
1888
1889        if (finderClassNameCacheEnabled) {
1890            result = FinderCacheUtil.getResult(finderClassName,
1891                    finderMethodName, finderParams, finderArgs, this);
1892        }
1893
1894        if (result == null) {
1895            Session session = null;
1896
1897            try {
1898                session = openSession();
1899
1900                StringBuilder query = new StringBuilder();
1901
1902                query.append("SELECT COUNT(*) ");
1903                query.append(
1904                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1905
1906                query.append("groupId = ?");
1907
1908                query.append(" AND ");
1909
1910                query.append("roleId = ?");
1911
1912                query.append(" ");
1913
1914                Query q = session.createQuery(query.toString());
1915
1916                QueryPos qPos = QueryPos.getInstance(q);
1917
1918                qPos.add(groupId);
1919
1920                qPos.add(roleId);
1921
1922                Long count = null;
1923
1924                Iterator<Long> itr = q.list().iterator();
1925
1926                if (itr.hasNext()) {
1927                    count = itr.next();
1928                }
1929
1930                if (count == null) {
1931                    count = new Long(0);
1932                }
1933
1934                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1935                    finderClassName, finderMethodName, finderParams,
1936                    finderArgs, count);
1937
1938                return count.intValue();
1939            }
1940            catch (Exception e) {
1941                throw processException(e);
1942            }
1943            finally {
1944                closeSession(session);
1945            }
1946        }
1947        else {
1948            return ((Long)result).intValue();
1949        }
1950    }
1951
1952    public int countAll() throws SystemException {
1953        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1954        String finderClassName = UserGroupRole.class.getName();
1955        String finderMethodName = "countAll";
1956        String[] finderParams = new String[] {  };
1957        Object[] finderArgs = new Object[] {  };
1958
1959        Object result = null;
1960
1961        if (finderClassNameCacheEnabled) {
1962            result = FinderCacheUtil.getResult(finderClassName,
1963                    finderMethodName, finderParams, finderArgs, this);
1964        }
1965
1966        if (result == null) {
1967            Session session = null;
1968
1969            try {
1970                session = openSession();
1971
1972                Query q = session.createQuery(
1973                        "SELECT COUNT(*) FROM com.liferay.portal.model.UserGroupRole");
1974
1975                Long count = null;
1976
1977                Iterator<Long> itr = q.list().iterator();
1978
1979                if (itr.hasNext()) {
1980                    count = itr.next();
1981                }
1982
1983                if (count == null) {
1984                    count = new Long(0);
1985                }
1986
1987                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1988                    finderClassName, finderMethodName, finderParams,
1989                    finderArgs, count);
1990
1991                return count.intValue();
1992            }
1993            catch (Exception e) {
1994                throw processException(e);
1995            }
1996            finally {
1997                closeSession(session);
1998            }
1999        }
2000        else {
2001            return ((Long)result).intValue();
2002        }
2003    }
2004
2005    public void registerListener(ModelListener listener) {
2006        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2007
2008        listeners.add(listener);
2009
2010        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2011    }
2012
2013    public void unregisterListener(ModelListener listener) {
2014        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2015
2016        listeners.remove(listener);
2017
2018        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2019    }
2020
2021    public void afterPropertiesSet() {
2022        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2023                    com.liferay.portal.util.PropsUtil.get(
2024                        "value.object.listener.com.liferay.portal.model.UserGroupRole")));
2025
2026        if (listenerClassNames.length > 0) {
2027            try {
2028                List<ModelListener> listeners = new ArrayList<ModelListener>();
2029
2030                for (String listenerClassName : listenerClassNames) {
2031                    listeners.add((ModelListener)Class.forName(
2032                            listenerClassName).newInstance());
2033                }
2034
2035                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2036            }
2037            catch (Exception e) {
2038                _log.error(e);
2039            }
2040        }
2041    }
2042
2043    private static Log _log = LogFactory.getLog(UserGroupRolePersistenceImpl.class);
2044    private ModelListener[] _listeners = new ModelListener[0];
2045}