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