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