001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchUserGroupRoleException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.model.UserGroupRole;
039    import com.liferay.portal.model.impl.UserGroupRoleImpl;
040    import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.List;
048    
049    /**
050     * The persistence implementation for the user group role service.
051     *
052     * <p>
053     * Never modify or reference this class directly. Always use {@link UserGroupRoleUtil} to access the user group role persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
054     * </p>
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see UserGroupRolePersistence
062     * @see UserGroupRoleUtil
063     * @generated
064     */
065    public class UserGroupRolePersistenceImpl extends BasePersistenceImpl<UserGroupRole>
066            implements UserGroupRolePersistence {
067            public static final String FINDER_CLASS_NAME_ENTITY = UserGroupRoleImpl.class.getName();
068            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
069                    ".List";
070            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
071                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "findByUserId",
073                            new String[] {
074                                    Long.class.getName(),
075                                    
076                            "java.lang.Integer", "java.lang.Integer",
077                                    "com.liferay.portal.kernel.util.OrderByComparator"
078                            });
079            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
080                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
081                            FINDER_CLASS_NAME_LIST, "countByUserId",
082                            new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
084                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "findByGroupId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
093                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
094                            FINDER_CLASS_NAME_LIST, "countByGroupId",
095                            new String[] { Long.class.getName() });
096            public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
097                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
098                            FINDER_CLASS_NAME_LIST, "findByRoleId",
099                            new String[] {
100                                    Long.class.getName(),
101                                    
102                            "java.lang.Integer", "java.lang.Integer",
103                                    "com.liferay.portal.kernel.util.OrderByComparator"
104                            });
105            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
106                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
107                            FINDER_CLASS_NAME_LIST, "countByRoleId",
108                            new String[] { Long.class.getName() });
109            public static final FinderPath FINDER_PATH_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
110                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
111                            FINDER_CLASS_NAME_LIST, "findByU_G",
112                            new String[] {
113                                    Long.class.getName(), Long.class.getName(),
114                                    
115                            "java.lang.Integer", "java.lang.Integer",
116                                    "com.liferay.portal.kernel.util.OrderByComparator"
117                            });
118            public static final FinderPath FINDER_PATH_COUNT_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
119                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
120                            FINDER_CLASS_NAME_LIST, "countByU_G",
121                            new String[] { Long.class.getName(), Long.class.getName() });
122            public static final FinderPath FINDER_PATH_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
123                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
124                            FINDER_CLASS_NAME_LIST, "findByG_R",
125                            new String[] {
126                                    Long.class.getName(), Long.class.getName(),
127                                    
128                            "java.lang.Integer", "java.lang.Integer",
129                                    "com.liferay.portal.kernel.util.OrderByComparator"
130                            });
131            public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
132                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
133                            FINDER_CLASS_NAME_LIST, "countByG_R",
134                            new String[] { Long.class.getName(), Long.class.getName() });
135            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
136                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
137                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
138            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
139                            UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
140                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
141    
142            /**
143             * Caches the user group role in the entity cache if it is enabled.
144             *
145             * @param userGroupRole the user group role to cache
146             */
147            public void cacheResult(UserGroupRole userGroupRole) {
148                    EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
149                            UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
150                            userGroupRole);
151            }
152    
153            /**
154             * Caches the user group roles in the entity cache if it is enabled.
155             *
156             * @param userGroupRoles the user group roles to cache
157             */
158            public void cacheResult(List<UserGroupRole> userGroupRoles) {
159                    for (UserGroupRole userGroupRole : userGroupRoles) {
160                            if (EntityCacheUtil.getResult(
161                                                    UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
162                                                    UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
163                                                    this) == null) {
164                                    cacheResult(userGroupRole);
165                            }
166                    }
167            }
168    
169            /**
170             * Clears the cache for all user group roles.
171             *
172             * <p>
173             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
174             * </p>
175             */
176            public void clearCache() {
177                    CacheRegistryUtil.clear(UserGroupRoleImpl.class.getName());
178                    EntityCacheUtil.clearCache(UserGroupRoleImpl.class.getName());
179                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
180                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
181            }
182    
183            /**
184             * Clears the cache for the user group role.
185             *
186             * <p>
187             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
188             * </p>
189             */
190            public void clearCache(UserGroupRole userGroupRole) {
191                    EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
192                            UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
193            }
194    
195            /**
196             * Creates a new user group role with the primary key. Does not add the user group role to the database.
197             *
198             * @param userGroupRolePK the primary key for the new user group role
199             * @return the new user group role
200             */
201            public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
202                    UserGroupRole userGroupRole = new UserGroupRoleImpl();
203    
204                    userGroupRole.setNew(true);
205                    userGroupRole.setPrimaryKey(userGroupRolePK);
206    
207                    return userGroupRole;
208            }
209    
210            /**
211             * Removes the user group role with the primary key from the database. Also notifies the appropriate model listeners.
212             *
213             * @param primaryKey the primary key of the user group role to remove
214             * @return the user group role that was removed
215             * @throws com.liferay.portal.NoSuchModelException if a user group role with the primary key could not be found
216             * @throws SystemException if a system exception occurred
217             */
218            public UserGroupRole remove(Serializable primaryKey)
219                    throws NoSuchModelException, SystemException {
220                    return remove((UserGroupRolePK)primaryKey);
221            }
222    
223            /**
224             * Removes the user group role with the primary key from the database. Also notifies the appropriate model listeners.
225             *
226             * @param userGroupRolePK the primary key of the user group role to remove
227             * @return the user group role that was removed
228             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
229             * @throws SystemException if a system exception occurred
230             */
231            public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
232                    throws NoSuchUserGroupRoleException, SystemException {
233                    Session session = null;
234    
235                    try {
236                            session = openSession();
237    
238                            UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
239                                            userGroupRolePK);
240    
241                            if (userGroupRole == null) {
242                                    if (_log.isWarnEnabled()) {
243                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
244                                                    userGroupRolePK);
245                                    }
246    
247                                    throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
248                                            userGroupRolePK);
249                            }
250    
251                            return remove(userGroupRole);
252                    }
253                    catch (NoSuchUserGroupRoleException nsee) {
254                            throw nsee;
255                    }
256                    catch (Exception e) {
257                            throw processException(e);
258                    }
259                    finally {
260                            closeSession(session);
261                    }
262            }
263    
264            protected UserGroupRole removeImpl(UserGroupRole userGroupRole)
265                    throws SystemException {
266                    userGroupRole = toUnwrappedModel(userGroupRole);
267    
268                    Session session = null;
269    
270                    try {
271                            session = openSession();
272    
273                            BatchSessionUtil.delete(session, userGroupRole);
274                    }
275                    catch (Exception e) {
276                            throw processException(e);
277                    }
278                    finally {
279                            closeSession(session);
280                    }
281    
282                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
283    
284                    EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
285                            UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
286    
287                    return userGroupRole;
288            }
289    
290            public UserGroupRole updateImpl(
291                    com.liferay.portal.model.UserGroupRole userGroupRole, boolean merge)
292                    throws SystemException {
293                    userGroupRole = toUnwrappedModel(userGroupRole);
294    
295                    Session session = null;
296    
297                    try {
298                            session = openSession();
299    
300                            BatchSessionUtil.update(session, userGroupRole, merge);
301    
302                            userGroupRole.setNew(false);
303                    }
304                    catch (Exception e) {
305                            throw processException(e);
306                    }
307                    finally {
308                            closeSession(session);
309                    }
310    
311                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
312    
313                    EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
314                            UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
315                            userGroupRole);
316    
317                    return userGroupRole;
318            }
319    
320            protected UserGroupRole toUnwrappedModel(UserGroupRole userGroupRole) {
321                    if (userGroupRole instanceof UserGroupRoleImpl) {
322                            return userGroupRole;
323                    }
324    
325                    UserGroupRoleImpl userGroupRoleImpl = new UserGroupRoleImpl();
326    
327                    userGroupRoleImpl.setNew(userGroupRole.isNew());
328                    userGroupRoleImpl.setPrimaryKey(userGroupRole.getPrimaryKey());
329    
330                    userGroupRoleImpl.setUserId(userGroupRole.getUserId());
331                    userGroupRoleImpl.setGroupId(userGroupRole.getGroupId());
332                    userGroupRoleImpl.setRoleId(userGroupRole.getRoleId());
333    
334                    return userGroupRoleImpl;
335            }
336    
337            /**
338             * Finds the user group role with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
339             *
340             * @param primaryKey the primary key of the user group role to find
341             * @return the user group role
342             * @throws com.liferay.portal.NoSuchModelException if a user group role with the primary key could not be found
343             * @throws SystemException if a system exception occurred
344             */
345            public UserGroupRole findByPrimaryKey(Serializable primaryKey)
346                    throws NoSuchModelException, SystemException {
347                    return findByPrimaryKey((UserGroupRolePK)primaryKey);
348            }
349    
350            /**
351             * Finds the user group role with the primary key or throws a {@link com.liferay.portal.NoSuchUserGroupRoleException} if it could not be found.
352             *
353             * @param userGroupRolePK the primary key of the user group role to find
354             * @return the user group role
355             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
356             * @throws SystemException if a system exception occurred
357             */
358            public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
359                    throws NoSuchUserGroupRoleException, SystemException {
360                    UserGroupRole userGroupRole = fetchByPrimaryKey(userGroupRolePK);
361    
362                    if (userGroupRole == null) {
363                            if (_log.isWarnEnabled()) {
364                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupRolePK);
365                            }
366    
367                            throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
368                                    userGroupRolePK);
369                    }
370    
371                    return userGroupRole;
372            }
373    
374            /**
375             * Finds the user group role with the primary key or returns <code>null</code> if it could not be found.
376             *
377             * @param primaryKey the primary key of the user group role to find
378             * @return the user group role, or <code>null</code> if a user group role with the primary key could not be found
379             * @throws SystemException if a system exception occurred
380             */
381            public UserGroupRole fetchByPrimaryKey(Serializable primaryKey)
382                    throws SystemException {
383                    return fetchByPrimaryKey((UserGroupRolePK)primaryKey);
384            }
385    
386            /**
387             * Finds the user group role with the primary key or returns <code>null</code> if it could not be found.
388             *
389             * @param userGroupRolePK the primary key of the user group role to find
390             * @return the user group role, or <code>null</code> if a user group role with the primary key could not be found
391             * @throws SystemException if a system exception occurred
392             */
393            public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK)
394                    throws SystemException {
395                    UserGroupRole userGroupRole = (UserGroupRole)EntityCacheUtil.getResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
396                                    UserGroupRoleImpl.class, userGroupRolePK, this);
397    
398                    if (userGroupRole == null) {
399                            Session session = null;
400    
401                            try {
402                                    session = openSession();
403    
404                                    userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
405                                                    userGroupRolePK);
406                            }
407                            catch (Exception e) {
408                                    throw processException(e);
409                            }
410                            finally {
411                                    if (userGroupRole != null) {
412                                            cacheResult(userGroupRole);
413                                    }
414    
415                                    closeSession(session);
416                            }
417                    }
418    
419                    return userGroupRole;
420            }
421    
422            /**
423             * Finds all the user group roles where userId = &#63;.
424             *
425             * @param userId the user id to search with
426             * @return the matching user group roles
427             * @throws SystemException if a system exception occurred
428             */
429            public List<UserGroupRole> findByUserId(long userId)
430                    throws SystemException {
431                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
432            }
433    
434            /**
435             * Finds a range of all the user group roles where userId = &#63;.
436             *
437             * <p>
438             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
439             * </p>
440             *
441             * @param userId the user id to search with
442             * @param start the lower bound of the range of user group roles to return
443             * @param end the upper bound of the range of user group roles to return (not inclusive)
444             * @return the range of matching user group roles
445             * @throws SystemException if a system exception occurred
446             */
447            public List<UserGroupRole> findByUserId(long userId, int start, int end)
448                    throws SystemException {
449                    return findByUserId(userId, start, end, null);
450            }
451    
452            /**
453             * Finds an ordered range of all the user group roles where userId = &#63;.
454             *
455             * <p>
456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
457             * </p>
458             *
459             * @param userId the user id to search with
460             * @param start the lower bound of the range of user group roles to return
461             * @param end the upper bound of the range of user group roles to return (not inclusive)
462             * @param orderByComparator the comparator to order the results by
463             * @return the ordered range of matching user group roles
464             * @throws SystemException if a system exception occurred
465             */
466            public List<UserGroupRole> findByUserId(long userId, int start, int end,
467                    OrderByComparator orderByComparator) throws SystemException {
468                    Object[] finderArgs = new Object[] {
469                                    userId,
470                                    
471                                    String.valueOf(start), String.valueOf(end),
472                                    String.valueOf(orderByComparator)
473                            };
474    
475                    List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
476                                    finderArgs, this);
477    
478                    if (list == null) {
479                            Session session = null;
480    
481                            try {
482                                    session = openSession();
483    
484                                    StringBundler query = null;
485    
486                                    if (orderByComparator != null) {
487                                            query = new StringBundler(3 +
488                                                            (orderByComparator.getOrderByFields().length * 3));
489                                    }
490                                    else {
491                                            query = new StringBundler(2);
492                                    }
493    
494                                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
495    
496                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
497    
498                                    if (orderByComparator != null) {
499                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
500                                                    orderByComparator);
501                                    }
502    
503                                    String sql = query.toString();
504    
505                                    Query q = session.createQuery(sql);
506    
507                                    QueryPos qPos = QueryPos.getInstance(q);
508    
509                                    qPos.add(userId);
510    
511                                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
512                                                    start, end);
513                            }
514                            catch (Exception e) {
515                                    throw processException(e);
516                            }
517                            finally {
518                                    if (list == null) {
519                                            list = new ArrayList<UserGroupRole>();
520                                    }
521    
522                                    cacheResult(list);
523    
524                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
525                                            finderArgs, list);
526    
527                                    closeSession(session);
528                            }
529                    }
530    
531                    return list;
532            }
533    
534            /**
535             * Finds the first user group role in the ordered set where userId = &#63;.
536             *
537             * <p>
538             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
539             * </p>
540             *
541             * @param userId the user id to search with
542             * @param orderByComparator the comparator to order the set by
543             * @return the first matching user group role
544             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
545             * @throws SystemException if a system exception occurred
546             */
547            public UserGroupRole findByUserId_First(long userId,
548                    OrderByComparator orderByComparator)
549                    throws NoSuchUserGroupRoleException, SystemException {
550                    List<UserGroupRole> list = findByUserId(userId, 0, 1, orderByComparator);
551    
552                    if (list.isEmpty()) {
553                            StringBundler msg = new StringBundler(4);
554    
555                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
556    
557                            msg.append("userId=");
558                            msg.append(userId);
559    
560                            msg.append(StringPool.CLOSE_CURLY_BRACE);
561    
562                            throw new NoSuchUserGroupRoleException(msg.toString());
563                    }
564                    else {
565                            return list.get(0);
566                    }
567            }
568    
569            /**
570             * Finds the last user group role in the ordered set where userId = &#63;.
571             *
572             * <p>
573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
574             * </p>
575             *
576             * @param userId the user id to search with
577             * @param orderByComparator the comparator to order the set by
578             * @return the last matching user group role
579             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
580             * @throws SystemException if a system exception occurred
581             */
582            public UserGroupRole findByUserId_Last(long userId,
583                    OrderByComparator orderByComparator)
584                    throws NoSuchUserGroupRoleException, SystemException {
585                    int count = countByUserId(userId);
586    
587                    List<UserGroupRole> list = findByUserId(userId, count - 1, count,
588                                    orderByComparator);
589    
590                    if (list.isEmpty()) {
591                            StringBundler msg = new StringBundler(4);
592    
593                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594    
595                            msg.append("userId=");
596                            msg.append(userId);
597    
598                            msg.append(StringPool.CLOSE_CURLY_BRACE);
599    
600                            throw new NoSuchUserGroupRoleException(msg.toString());
601                    }
602                    else {
603                            return list.get(0);
604                    }
605            }
606    
607            /**
608             * Finds the user group roles before and after the current user group role in the ordered set where userId = &#63;.
609             *
610             * <p>
611             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
612             * </p>
613             *
614             * @param userGroupRolePK the primary key of the current user group role
615             * @param userId the user id to search with
616             * @param orderByComparator the comparator to order the set by
617             * @return the previous, current, and next user group role
618             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
619             * @throws SystemException if a system exception occurred
620             */
621            public UserGroupRole[] findByUserId_PrevAndNext(
622                    UserGroupRolePK userGroupRolePK, long userId,
623                    OrderByComparator orderByComparator)
624                    throws NoSuchUserGroupRoleException, SystemException {
625                    UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
626    
627                    Session session = null;
628    
629                    try {
630                            session = openSession();
631    
632                            UserGroupRole[] array = new UserGroupRoleImpl[3];
633    
634                            array[0] = getByUserId_PrevAndNext(session, userGroupRole, userId,
635                                            orderByComparator, true);
636    
637                            array[1] = userGroupRole;
638    
639                            array[2] = getByUserId_PrevAndNext(session, userGroupRole, userId,
640                                            orderByComparator, false);
641    
642                            return array;
643                    }
644                    catch (Exception e) {
645                            throw processException(e);
646                    }
647                    finally {
648                            closeSession(session);
649                    }
650            }
651    
652            protected UserGroupRole getByUserId_PrevAndNext(Session session,
653                    UserGroupRole userGroupRole, long userId,
654                    OrderByComparator orderByComparator, boolean previous) {
655                    StringBundler query = null;
656    
657                    if (orderByComparator != null) {
658                            query = new StringBundler(6 +
659                                            (orderByComparator.getOrderByFields().length * 6));
660                    }
661                    else {
662                            query = new StringBundler(3);
663                    }
664    
665                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
666    
667                    query.append(_FINDER_COLUMN_USERID_USERID_2);
668    
669                    if (orderByComparator != null) {
670                            String[] orderByFields = orderByComparator.getOrderByFields();
671    
672                            if (orderByFields.length > 0) {
673                                    query.append(WHERE_AND);
674                            }
675    
676                            for (int i = 0; i < orderByFields.length; i++) {
677                                    query.append(_ORDER_BY_ENTITY_ALIAS);
678                                    query.append(orderByFields[i]);
679    
680                                    if ((i + 1) < orderByFields.length) {
681                                            if (orderByComparator.isAscending() ^ previous) {
682                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
683                                            }
684                                            else {
685                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
686                                            }
687                                    }
688                                    else {
689                                            if (orderByComparator.isAscending() ^ previous) {
690                                                    query.append(WHERE_GREATER_THAN);
691                                            }
692                                            else {
693                                                    query.append(WHERE_LESSER_THAN);
694                                            }
695                                    }
696                            }
697    
698                            query.append(ORDER_BY_CLAUSE);
699    
700                            for (int i = 0; i < orderByFields.length; i++) {
701                                    query.append(_ORDER_BY_ENTITY_ALIAS);
702                                    query.append(orderByFields[i]);
703    
704                                    if ((i + 1) < orderByFields.length) {
705                                            if (orderByComparator.isAscending() ^ previous) {
706                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
707                                            }
708                                            else {
709                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
710                                            }
711                                    }
712                                    else {
713                                            if (orderByComparator.isAscending() ^ previous) {
714                                                    query.append(ORDER_BY_ASC);
715                                            }
716                                            else {
717                                                    query.append(ORDER_BY_DESC);
718                                            }
719                                    }
720                            }
721                    }
722    
723                    String sql = query.toString();
724    
725                    Query q = session.createQuery(sql);
726    
727                    q.setFirstResult(0);
728                    q.setMaxResults(2);
729    
730                    QueryPos qPos = QueryPos.getInstance(q);
731    
732                    qPos.add(userId);
733    
734                    if (orderByComparator != null) {
735                            Object[] values = orderByComparator.getOrderByValues(userGroupRole);
736    
737                            for (Object value : values) {
738                                    qPos.add(value);
739                            }
740                    }
741    
742                    List<UserGroupRole> list = q.list();
743    
744                    if (list.size() == 2) {
745                            return list.get(1);
746                    }
747                    else {
748                            return null;
749                    }
750            }
751    
752            /**
753             * Finds all the user group roles where groupId = &#63;.
754             *
755             * @param groupId the group id to search with
756             * @return the matching user group roles
757             * @throws SystemException if a system exception occurred
758             */
759            public List<UserGroupRole> findByGroupId(long groupId)
760                    throws SystemException {
761                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
762            }
763    
764            /**
765             * Finds a range of all the user group roles where groupId = &#63;.
766             *
767             * <p>
768             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
769             * </p>
770             *
771             * @param groupId the group id to search with
772             * @param start the lower bound of the range of user group roles to return
773             * @param end the upper bound of the range of user group roles to return (not inclusive)
774             * @return the range of matching user group roles
775             * @throws SystemException if a system exception occurred
776             */
777            public List<UserGroupRole> findByGroupId(long groupId, int start, int end)
778                    throws SystemException {
779                    return findByGroupId(groupId, start, end, null);
780            }
781    
782            /**
783             * Finds an ordered range of all the user group roles where groupId = &#63;.
784             *
785             * <p>
786             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
787             * </p>
788             *
789             * @param groupId the group id to search with
790             * @param start the lower bound of the range of user group roles to return
791             * @param end the upper bound of the range of user group roles to return (not inclusive)
792             * @param orderByComparator the comparator to order the results by
793             * @return the ordered range of matching user group roles
794             * @throws SystemException if a system exception occurred
795             */
796            public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
797                    OrderByComparator orderByComparator) throws SystemException {
798                    Object[] finderArgs = new Object[] {
799                                    groupId,
800                                    
801                                    String.valueOf(start), String.valueOf(end),
802                                    String.valueOf(orderByComparator)
803                            };
804    
805                    List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
806                                    finderArgs, this);
807    
808                    if (list == null) {
809                            Session session = null;
810    
811                            try {
812                                    session = openSession();
813    
814                                    StringBundler query = null;
815    
816                                    if (orderByComparator != null) {
817                                            query = new StringBundler(3 +
818                                                            (orderByComparator.getOrderByFields().length * 3));
819                                    }
820                                    else {
821                                            query = new StringBundler(2);
822                                    }
823    
824                                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
825    
826                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
827    
828                                    if (orderByComparator != null) {
829                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
830                                                    orderByComparator);
831                                    }
832    
833                                    String sql = query.toString();
834    
835                                    Query q = session.createQuery(sql);
836    
837                                    QueryPos qPos = QueryPos.getInstance(q);
838    
839                                    qPos.add(groupId);
840    
841                                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
842                                                    start, end);
843                            }
844                            catch (Exception e) {
845                                    throw processException(e);
846                            }
847                            finally {
848                                    if (list == null) {
849                                            list = new ArrayList<UserGroupRole>();
850                                    }
851    
852                                    cacheResult(list);
853    
854                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
855                                            finderArgs, list);
856    
857                                    closeSession(session);
858                            }
859                    }
860    
861                    return list;
862            }
863    
864            /**
865             * Finds the first user group role in the ordered set where groupId = &#63;.
866             *
867             * <p>
868             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
869             * </p>
870             *
871             * @param groupId the group id to search with
872             * @param orderByComparator the comparator to order the set by
873             * @return the first matching user group role
874             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
875             * @throws SystemException if a system exception occurred
876             */
877            public UserGroupRole findByGroupId_First(long groupId,
878                    OrderByComparator orderByComparator)
879                    throws NoSuchUserGroupRoleException, SystemException {
880                    List<UserGroupRole> list = findByGroupId(groupId, 0, 1,
881                                    orderByComparator);
882    
883                    if (list.isEmpty()) {
884                            StringBundler msg = new StringBundler(4);
885    
886                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
887    
888                            msg.append("groupId=");
889                            msg.append(groupId);
890    
891                            msg.append(StringPool.CLOSE_CURLY_BRACE);
892    
893                            throw new NoSuchUserGroupRoleException(msg.toString());
894                    }
895                    else {
896                            return list.get(0);
897                    }
898            }
899    
900            /**
901             * Finds the last user group role in the ordered set where groupId = &#63;.
902             *
903             * <p>
904             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
905             * </p>
906             *
907             * @param groupId the group id to search with
908             * @param orderByComparator the comparator to order the set by
909             * @return the last matching user group role
910             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
911             * @throws SystemException if a system exception occurred
912             */
913            public UserGroupRole findByGroupId_Last(long groupId,
914                    OrderByComparator orderByComparator)
915                    throws NoSuchUserGroupRoleException, SystemException {
916                    int count = countByGroupId(groupId);
917    
918                    List<UserGroupRole> list = findByGroupId(groupId, count - 1, count,
919                                    orderByComparator);
920    
921                    if (list.isEmpty()) {
922                            StringBundler msg = new StringBundler(4);
923    
924                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
925    
926                            msg.append("groupId=");
927                            msg.append(groupId);
928    
929                            msg.append(StringPool.CLOSE_CURLY_BRACE);
930    
931                            throw new NoSuchUserGroupRoleException(msg.toString());
932                    }
933                    else {
934                            return list.get(0);
935                    }
936            }
937    
938            /**
939             * Finds the user group roles before and after the current user group role in the ordered set where groupId = &#63;.
940             *
941             * <p>
942             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
943             * </p>
944             *
945             * @param userGroupRolePK the primary key of the current user group role
946             * @param groupId the group id to search with
947             * @param orderByComparator the comparator to order the set by
948             * @return the previous, current, and next user group role
949             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
950             * @throws SystemException if a system exception occurred
951             */
952            public UserGroupRole[] findByGroupId_PrevAndNext(
953                    UserGroupRolePK userGroupRolePK, long groupId,
954                    OrderByComparator orderByComparator)
955                    throws NoSuchUserGroupRoleException, SystemException {
956                    UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
957    
958                    Session session = null;
959    
960                    try {
961                            session = openSession();
962    
963                            UserGroupRole[] array = new UserGroupRoleImpl[3];
964    
965                            array[0] = getByGroupId_PrevAndNext(session, userGroupRole,
966                                            groupId, orderByComparator, true);
967    
968                            array[1] = userGroupRole;
969    
970                            array[2] = getByGroupId_PrevAndNext(session, userGroupRole,
971                                            groupId, orderByComparator, false);
972    
973                            return array;
974                    }
975                    catch (Exception e) {
976                            throw processException(e);
977                    }
978                    finally {
979                            closeSession(session);
980                    }
981            }
982    
983            protected UserGroupRole getByGroupId_PrevAndNext(Session session,
984                    UserGroupRole userGroupRole, long groupId,
985                    OrderByComparator orderByComparator, boolean previous) {
986                    StringBundler query = null;
987    
988                    if (orderByComparator != null) {
989                            query = new StringBundler(6 +
990                                            (orderByComparator.getOrderByFields().length * 6));
991                    }
992                    else {
993                            query = new StringBundler(3);
994                    }
995    
996                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
997    
998                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
999    
1000                    if (orderByComparator != null) {
1001                            String[] orderByFields = orderByComparator.getOrderByFields();
1002    
1003                            if (orderByFields.length > 0) {
1004                                    query.append(WHERE_AND);
1005                            }
1006    
1007                            for (int i = 0; i < orderByFields.length; i++) {
1008                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1009                                    query.append(orderByFields[i]);
1010    
1011                                    if ((i + 1) < orderByFields.length) {
1012                                            if (orderByComparator.isAscending() ^ previous) {
1013                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1014                                            }
1015                                            else {
1016                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1017                                            }
1018                                    }
1019                                    else {
1020                                            if (orderByComparator.isAscending() ^ previous) {
1021                                                    query.append(WHERE_GREATER_THAN);
1022                                            }
1023                                            else {
1024                                                    query.append(WHERE_LESSER_THAN);
1025                                            }
1026                                    }
1027                            }
1028    
1029                            query.append(ORDER_BY_CLAUSE);
1030    
1031                            for (int i = 0; i < orderByFields.length; i++) {
1032                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1033                                    query.append(orderByFields[i]);
1034    
1035                                    if ((i + 1) < orderByFields.length) {
1036                                            if (orderByComparator.isAscending() ^ previous) {
1037                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1038                                            }
1039                                            else {
1040                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1041                                            }
1042                                    }
1043                                    else {
1044                                            if (orderByComparator.isAscending() ^ previous) {
1045                                                    query.append(ORDER_BY_ASC);
1046                                            }
1047                                            else {
1048                                                    query.append(ORDER_BY_DESC);
1049                                            }
1050                                    }
1051                            }
1052                    }
1053    
1054                    String sql = query.toString();
1055    
1056                    Query q = session.createQuery(sql);
1057    
1058                    q.setFirstResult(0);
1059                    q.setMaxResults(2);
1060    
1061                    QueryPos qPos = QueryPos.getInstance(q);
1062    
1063                    qPos.add(groupId);
1064    
1065                    if (orderByComparator != null) {
1066                            Object[] values = orderByComparator.getOrderByValues(userGroupRole);
1067    
1068                            for (Object value : values) {
1069                                    qPos.add(value);
1070                            }
1071                    }
1072    
1073                    List<UserGroupRole> list = q.list();
1074    
1075                    if (list.size() == 2) {
1076                            return list.get(1);
1077                    }
1078                    else {
1079                            return null;
1080                    }
1081            }
1082    
1083            /**
1084             * Finds all the user group roles where roleId = &#63;.
1085             *
1086             * @param roleId the role id to search with
1087             * @return the matching user group roles
1088             * @throws SystemException if a system exception occurred
1089             */
1090            public List<UserGroupRole> findByRoleId(long roleId)
1091                    throws SystemException {
1092                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1093            }
1094    
1095            /**
1096             * Finds a range of all the user group roles where roleId = &#63;.
1097             *
1098             * <p>
1099             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1100             * </p>
1101             *
1102             * @param roleId the role id to search with
1103             * @param start the lower bound of the range of user group roles to return
1104             * @param end the upper bound of the range of user group roles to return (not inclusive)
1105             * @return the range of matching user group roles
1106             * @throws SystemException if a system exception occurred
1107             */
1108            public List<UserGroupRole> findByRoleId(long roleId, int start, int end)
1109                    throws SystemException {
1110                    return findByRoleId(roleId, start, end, null);
1111            }
1112    
1113            /**
1114             * Finds an ordered range of all the user group roles where roleId = &#63;.
1115             *
1116             * <p>
1117             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1118             * </p>
1119             *
1120             * @param roleId the role id to search with
1121             * @param start the lower bound of the range of user group roles to return
1122             * @param end the upper bound of the range of user group roles to return (not inclusive)
1123             * @param orderByComparator the comparator to order the results by
1124             * @return the ordered range of matching user group roles
1125             * @throws SystemException if a system exception occurred
1126             */
1127            public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
1128                    OrderByComparator orderByComparator) throws SystemException {
1129                    Object[] finderArgs = new Object[] {
1130                                    roleId,
1131                                    
1132                                    String.valueOf(start), String.valueOf(end),
1133                                    String.valueOf(orderByComparator)
1134                            };
1135    
1136                    List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
1137                                    finderArgs, this);
1138    
1139                    if (list == null) {
1140                            Session session = null;
1141    
1142                            try {
1143                                    session = openSession();
1144    
1145                                    StringBundler query = null;
1146    
1147                                    if (orderByComparator != null) {
1148                                            query = new StringBundler(3 +
1149                                                            (orderByComparator.getOrderByFields().length * 3));
1150                                    }
1151                                    else {
1152                                            query = new StringBundler(2);
1153                                    }
1154    
1155                                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1156    
1157                                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1158    
1159                                    if (orderByComparator != null) {
1160                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1161                                                    orderByComparator);
1162                                    }
1163    
1164                                    String sql = query.toString();
1165    
1166                                    Query q = session.createQuery(sql);
1167    
1168                                    QueryPos qPos = QueryPos.getInstance(q);
1169    
1170                                    qPos.add(roleId);
1171    
1172                                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1173                                                    start, end);
1174                            }
1175                            catch (Exception e) {
1176                                    throw processException(e);
1177                            }
1178                            finally {
1179                                    if (list == null) {
1180                                            list = new ArrayList<UserGroupRole>();
1181                                    }
1182    
1183                                    cacheResult(list);
1184    
1185                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
1186                                            finderArgs, list);
1187    
1188                                    closeSession(session);
1189                            }
1190                    }
1191    
1192                    return list;
1193            }
1194    
1195            /**
1196             * Finds the first user group role in the ordered set where roleId = &#63;.
1197             *
1198             * <p>
1199             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1200             * </p>
1201             *
1202             * @param roleId the role id to search with
1203             * @param orderByComparator the comparator to order the set by
1204             * @return the first matching user group role
1205             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
1206             * @throws SystemException if a system exception occurred
1207             */
1208            public UserGroupRole findByRoleId_First(long roleId,
1209                    OrderByComparator orderByComparator)
1210                    throws NoSuchUserGroupRoleException, SystemException {
1211                    List<UserGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1212    
1213                    if (list.isEmpty()) {
1214                            StringBundler msg = new StringBundler(4);
1215    
1216                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1217    
1218                            msg.append("roleId=");
1219                            msg.append(roleId);
1220    
1221                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1222    
1223                            throw new NoSuchUserGroupRoleException(msg.toString());
1224                    }
1225                    else {
1226                            return list.get(0);
1227                    }
1228            }
1229    
1230            /**
1231             * Finds the last user group role in the ordered set where roleId = &#63;.
1232             *
1233             * <p>
1234             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1235             * </p>
1236             *
1237             * @param roleId the role id to search with
1238             * @param orderByComparator the comparator to order the set by
1239             * @return the last matching user group role
1240             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
1241             * @throws SystemException if a system exception occurred
1242             */
1243            public UserGroupRole findByRoleId_Last(long roleId,
1244                    OrderByComparator orderByComparator)
1245                    throws NoSuchUserGroupRoleException, SystemException {
1246                    int count = countByRoleId(roleId);
1247    
1248                    List<UserGroupRole> list = findByRoleId(roleId, count - 1, count,
1249                                    orderByComparator);
1250    
1251                    if (list.isEmpty()) {
1252                            StringBundler msg = new StringBundler(4);
1253    
1254                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1255    
1256                            msg.append("roleId=");
1257                            msg.append(roleId);
1258    
1259                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1260    
1261                            throw new NoSuchUserGroupRoleException(msg.toString());
1262                    }
1263                    else {
1264                            return list.get(0);
1265                    }
1266            }
1267    
1268            /**
1269             * Finds the user group roles before and after the current user group role in the ordered set where roleId = &#63;.
1270             *
1271             * <p>
1272             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1273             * </p>
1274             *
1275             * @param userGroupRolePK the primary key of the current user group role
1276             * @param roleId the role id to search with
1277             * @param orderByComparator the comparator to order the set by
1278             * @return the previous, current, and next user group role
1279             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
1280             * @throws SystemException if a system exception occurred
1281             */
1282            public UserGroupRole[] findByRoleId_PrevAndNext(
1283                    UserGroupRolePK userGroupRolePK, long roleId,
1284                    OrderByComparator orderByComparator)
1285                    throws NoSuchUserGroupRoleException, SystemException {
1286                    UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1287    
1288                    Session session = null;
1289    
1290                    try {
1291                            session = openSession();
1292    
1293                            UserGroupRole[] array = new UserGroupRoleImpl[3];
1294    
1295                            array[0] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1296                                            orderByComparator, true);
1297    
1298                            array[1] = userGroupRole;
1299    
1300                            array[2] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1301                                            orderByComparator, false);
1302    
1303                            return array;
1304                    }
1305                    catch (Exception e) {
1306                            throw processException(e);
1307                    }
1308                    finally {
1309                            closeSession(session);
1310                    }
1311            }
1312    
1313            protected UserGroupRole getByRoleId_PrevAndNext(Session session,
1314                    UserGroupRole userGroupRole, long roleId,
1315                    OrderByComparator orderByComparator, boolean previous) {
1316                    StringBundler query = null;
1317    
1318                    if (orderByComparator != null) {
1319                            query = new StringBundler(6 +
1320                                            (orderByComparator.getOrderByFields().length * 6));
1321                    }
1322                    else {
1323                            query = new StringBundler(3);
1324                    }
1325    
1326                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1327    
1328                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1329    
1330                    if (orderByComparator != null) {
1331                            String[] orderByFields = orderByComparator.getOrderByFields();
1332    
1333                            if (orderByFields.length > 0) {
1334                                    query.append(WHERE_AND);
1335                            }
1336    
1337                            for (int i = 0; i < orderByFields.length; i++) {
1338                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1339                                    query.append(orderByFields[i]);
1340    
1341                                    if ((i + 1) < orderByFields.length) {
1342                                            if (orderByComparator.isAscending() ^ previous) {
1343                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1344                                            }
1345                                            else {
1346                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1347                                            }
1348                                    }
1349                                    else {
1350                                            if (orderByComparator.isAscending() ^ previous) {
1351                                                    query.append(WHERE_GREATER_THAN);
1352                                            }
1353                                            else {
1354                                                    query.append(WHERE_LESSER_THAN);
1355                                            }
1356                                    }
1357                            }
1358    
1359                            query.append(ORDER_BY_CLAUSE);
1360    
1361                            for (int i = 0; i < orderByFields.length; i++) {
1362                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1363                                    query.append(orderByFields[i]);
1364    
1365                                    if ((i + 1) < orderByFields.length) {
1366                                            if (orderByComparator.isAscending() ^ previous) {
1367                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1368                                            }
1369                                            else {
1370                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1371                                            }
1372                                    }
1373                                    else {
1374                                            if (orderByComparator.isAscending() ^ previous) {
1375                                                    query.append(ORDER_BY_ASC);
1376                                            }
1377                                            else {
1378                                                    query.append(ORDER_BY_DESC);
1379                                            }
1380                                    }
1381                            }
1382                    }
1383    
1384                    String sql = query.toString();
1385    
1386                    Query q = session.createQuery(sql);
1387    
1388                    q.setFirstResult(0);
1389                    q.setMaxResults(2);
1390    
1391                    QueryPos qPos = QueryPos.getInstance(q);
1392    
1393                    qPos.add(roleId);
1394    
1395                    if (orderByComparator != null) {
1396                            Object[] values = orderByComparator.getOrderByValues(userGroupRole);
1397    
1398                            for (Object value : values) {
1399                                    qPos.add(value);
1400                            }
1401                    }
1402    
1403                    List<UserGroupRole> list = q.list();
1404    
1405                    if (list.size() == 2) {
1406                            return list.get(1);
1407                    }
1408                    else {
1409                            return null;
1410                    }
1411            }
1412    
1413            /**
1414             * Finds all the user group roles where userId = &#63; and groupId = &#63;.
1415             *
1416             * @param userId the user id to search with
1417             * @param groupId the group id to search with
1418             * @return the matching user group roles
1419             * @throws SystemException if a system exception occurred
1420             */
1421            public List<UserGroupRole> findByU_G(long userId, long groupId)
1422                    throws SystemException {
1423                    return findByU_G(userId, groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1424                            null);
1425            }
1426    
1427            /**
1428             * Finds a range of all the user group roles where userId = &#63; and groupId = &#63;.
1429             *
1430             * <p>
1431             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1432             * </p>
1433             *
1434             * @param userId the user id to search with
1435             * @param groupId the group id to search with
1436             * @param start the lower bound of the range of user group roles to return
1437             * @param end the upper bound of the range of user group roles to return (not inclusive)
1438             * @return the range of matching user group roles
1439             * @throws SystemException if a system exception occurred
1440             */
1441            public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1442                    int end) throws SystemException {
1443                    return findByU_G(userId, groupId, start, end, null);
1444            }
1445    
1446            /**
1447             * Finds an ordered range of all the user group roles where userId = &#63; and groupId = &#63;.
1448             *
1449             * <p>
1450             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1451             * </p>
1452             *
1453             * @param userId the user id to search with
1454             * @param groupId the group id to search with
1455             * @param start the lower bound of the range of user group roles to return
1456             * @param end the upper bound of the range of user group roles to return (not inclusive)
1457             * @param orderByComparator the comparator to order the results by
1458             * @return the ordered range of matching user group roles
1459             * @throws SystemException if a system exception occurred
1460             */
1461            public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1462                    int end, OrderByComparator orderByComparator) throws SystemException {
1463                    Object[] finderArgs = new Object[] {
1464                                    userId, groupId,
1465                                    
1466                                    String.valueOf(start), String.valueOf(end),
1467                                    String.valueOf(orderByComparator)
1468                            };
1469    
1470                    List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_G,
1471                                    finderArgs, this);
1472    
1473                    if (list == null) {
1474                            Session session = null;
1475    
1476                            try {
1477                                    session = openSession();
1478    
1479                                    StringBundler query = null;
1480    
1481                                    if (orderByComparator != null) {
1482                                            query = new StringBundler(4 +
1483                                                            (orderByComparator.getOrderByFields().length * 3));
1484                                    }
1485                                    else {
1486                                            query = new StringBundler(3);
1487                                    }
1488    
1489                                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1490    
1491                                    query.append(_FINDER_COLUMN_U_G_USERID_2);
1492    
1493                                    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1494    
1495                                    if (orderByComparator != null) {
1496                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1497                                                    orderByComparator);
1498                                    }
1499    
1500                                    String sql = query.toString();
1501    
1502                                    Query q = session.createQuery(sql);
1503    
1504                                    QueryPos qPos = QueryPos.getInstance(q);
1505    
1506                                    qPos.add(userId);
1507    
1508                                    qPos.add(groupId);
1509    
1510                                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1511                                                    start, end);
1512                            }
1513                            catch (Exception e) {
1514                                    throw processException(e);
1515                            }
1516                            finally {
1517                                    if (list == null) {
1518                                            list = new ArrayList<UserGroupRole>();
1519                                    }
1520    
1521                                    cacheResult(list);
1522    
1523                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_G, finderArgs,
1524                                            list);
1525    
1526                                    closeSession(session);
1527                            }
1528                    }
1529    
1530                    return list;
1531            }
1532    
1533            /**
1534             * Finds the first user group role in the ordered set where userId = &#63; and groupId = &#63;.
1535             *
1536             * <p>
1537             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1538             * </p>
1539             *
1540             * @param userId the user id to search with
1541             * @param groupId the group id to search with
1542             * @param orderByComparator the comparator to order the set by
1543             * @return the first matching user group role
1544             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
1545             * @throws SystemException if a system exception occurred
1546             */
1547            public UserGroupRole findByU_G_First(long userId, long groupId,
1548                    OrderByComparator orderByComparator)
1549                    throws NoSuchUserGroupRoleException, SystemException {
1550                    List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1,
1551                                    orderByComparator);
1552    
1553                    if (list.isEmpty()) {
1554                            StringBundler msg = new StringBundler(6);
1555    
1556                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1557    
1558                            msg.append("userId=");
1559                            msg.append(userId);
1560    
1561                            msg.append(", groupId=");
1562                            msg.append(groupId);
1563    
1564                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1565    
1566                            throw new NoSuchUserGroupRoleException(msg.toString());
1567                    }
1568                    else {
1569                            return list.get(0);
1570                    }
1571            }
1572    
1573            /**
1574             * Finds the last user group role in the ordered set where userId = &#63; and groupId = &#63;.
1575             *
1576             * <p>
1577             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1578             * </p>
1579             *
1580             * @param userId the user id to search with
1581             * @param groupId the group id to search with
1582             * @param orderByComparator the comparator to order the set by
1583             * @return the last matching user group role
1584             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
1585             * @throws SystemException if a system exception occurred
1586             */
1587            public UserGroupRole findByU_G_Last(long userId, long groupId,
1588                    OrderByComparator orderByComparator)
1589                    throws NoSuchUserGroupRoleException, SystemException {
1590                    int count = countByU_G(userId, groupId);
1591    
1592                    List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1593                                    orderByComparator);
1594    
1595                    if (list.isEmpty()) {
1596                            StringBundler msg = new StringBundler(6);
1597    
1598                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1599    
1600                            msg.append("userId=");
1601                            msg.append(userId);
1602    
1603                            msg.append(", groupId=");
1604                            msg.append(groupId);
1605    
1606                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1607    
1608                            throw new NoSuchUserGroupRoleException(msg.toString());
1609                    }
1610                    else {
1611                            return list.get(0);
1612                    }
1613            }
1614    
1615            /**
1616             * Finds the user group roles before and after the current user group role in the ordered set where userId = &#63; and groupId = &#63;.
1617             *
1618             * <p>
1619             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1620             * </p>
1621             *
1622             * @param userGroupRolePK the primary key of the current user group role
1623             * @param userId the user id to search with
1624             * @param groupId the group id to search with
1625             * @param orderByComparator the comparator to order the set by
1626             * @return the previous, current, and next user group role
1627             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
1628             * @throws SystemException if a system exception occurred
1629             */
1630            public UserGroupRole[] findByU_G_PrevAndNext(
1631                    UserGroupRolePK userGroupRolePK, long userId, long groupId,
1632                    OrderByComparator orderByComparator)
1633                    throws NoSuchUserGroupRoleException, SystemException {
1634                    UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1635    
1636                    Session session = null;
1637    
1638                    try {
1639                            session = openSession();
1640    
1641                            UserGroupRole[] array = new UserGroupRoleImpl[3];
1642    
1643                            array[0] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1644                                            groupId, orderByComparator, true);
1645    
1646                            array[1] = userGroupRole;
1647    
1648                            array[2] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1649                                            groupId, orderByComparator, false);
1650    
1651                            return array;
1652                    }
1653                    catch (Exception e) {
1654                            throw processException(e);
1655                    }
1656                    finally {
1657                            closeSession(session);
1658                    }
1659            }
1660    
1661            protected UserGroupRole getByU_G_PrevAndNext(Session session,
1662                    UserGroupRole userGroupRole, long userId, long groupId,
1663                    OrderByComparator orderByComparator, boolean previous) {
1664                    StringBundler query = null;
1665    
1666                    if (orderByComparator != null) {
1667                            query = new StringBundler(6 +
1668                                            (orderByComparator.getOrderByFields().length * 6));
1669                    }
1670                    else {
1671                            query = new StringBundler(3);
1672                    }
1673    
1674                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1675    
1676                    query.append(_FINDER_COLUMN_U_G_USERID_2);
1677    
1678                    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1679    
1680                    if (orderByComparator != null) {
1681                            String[] orderByFields = orderByComparator.getOrderByFields();
1682    
1683                            if (orderByFields.length > 0) {
1684                                    query.append(WHERE_AND);
1685                            }
1686    
1687                            for (int i = 0; i < orderByFields.length; i++) {
1688                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1689                                    query.append(orderByFields[i]);
1690    
1691                                    if ((i + 1) < orderByFields.length) {
1692                                            if (orderByComparator.isAscending() ^ previous) {
1693                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1694                                            }
1695                                            else {
1696                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1697                                            }
1698                                    }
1699                                    else {
1700                                            if (orderByComparator.isAscending() ^ previous) {
1701                                                    query.append(WHERE_GREATER_THAN);
1702                                            }
1703                                            else {
1704                                                    query.append(WHERE_LESSER_THAN);
1705                                            }
1706                                    }
1707                            }
1708    
1709                            query.append(ORDER_BY_CLAUSE);
1710    
1711                            for (int i = 0; i < orderByFields.length; i++) {
1712                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1713                                    query.append(orderByFields[i]);
1714    
1715                                    if ((i + 1) < orderByFields.length) {
1716                                            if (orderByComparator.isAscending() ^ previous) {
1717                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1718                                            }
1719                                            else {
1720                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1721                                            }
1722                                    }
1723                                    else {
1724                                            if (orderByComparator.isAscending() ^ previous) {
1725                                                    query.append(ORDER_BY_ASC);
1726                                            }
1727                                            else {
1728                                                    query.append(ORDER_BY_DESC);
1729                                            }
1730                                    }
1731                            }
1732                    }
1733    
1734                    String sql = query.toString();
1735    
1736                    Query q = session.createQuery(sql);
1737    
1738                    q.setFirstResult(0);
1739                    q.setMaxResults(2);
1740    
1741                    QueryPos qPos = QueryPos.getInstance(q);
1742    
1743                    qPos.add(userId);
1744    
1745                    qPos.add(groupId);
1746    
1747                    if (orderByComparator != null) {
1748                            Object[] values = orderByComparator.getOrderByValues(userGroupRole);
1749    
1750                            for (Object value : values) {
1751                                    qPos.add(value);
1752                            }
1753                    }
1754    
1755                    List<UserGroupRole> list = q.list();
1756    
1757                    if (list.size() == 2) {
1758                            return list.get(1);
1759                    }
1760                    else {
1761                            return null;
1762                    }
1763            }
1764    
1765            /**
1766             * Finds all the user group roles where groupId = &#63; and roleId = &#63;.
1767             *
1768             * @param groupId the group id to search with
1769             * @param roleId the role id to search with
1770             * @return the matching user group roles
1771             * @throws SystemException if a system exception occurred
1772             */
1773            public List<UserGroupRole> findByG_R(long groupId, long roleId)
1774                    throws SystemException {
1775                    return findByG_R(groupId, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1776                            null);
1777            }
1778    
1779            /**
1780             * Finds a range of all the user group roles where groupId = &#63; and roleId = &#63;.
1781             *
1782             * <p>
1783             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1784             * </p>
1785             *
1786             * @param groupId the group id to search with
1787             * @param roleId the role id to search with
1788             * @param start the lower bound of the range of user group roles to return
1789             * @param end the upper bound of the range of user group roles to return (not inclusive)
1790             * @return the range of matching user group roles
1791             * @throws SystemException if a system exception occurred
1792             */
1793            public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
1794                    int end) throws SystemException {
1795                    return findByG_R(groupId, roleId, start, end, null);
1796            }
1797    
1798            /**
1799             * Finds an ordered range of all the user group roles where groupId = &#63; and roleId = &#63;.
1800             *
1801             * <p>
1802             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1803             * </p>
1804             *
1805             * @param groupId the group id to search with
1806             * @param roleId the role id to search with
1807             * @param start the lower bound of the range of user group roles to return
1808             * @param end the upper bound of the range of user group roles to return (not inclusive)
1809             * @param orderByComparator the comparator to order the results by
1810             * @return the ordered range of matching user group roles
1811             * @throws SystemException if a system exception occurred
1812             */
1813            public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
1814                    int end, OrderByComparator orderByComparator) throws SystemException {
1815                    Object[] finderArgs = new Object[] {
1816                                    groupId, roleId,
1817                                    
1818                                    String.valueOf(start), String.valueOf(end),
1819                                    String.valueOf(orderByComparator)
1820                            };
1821    
1822                    List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_R,
1823                                    finderArgs, this);
1824    
1825                    if (list == null) {
1826                            Session session = null;
1827    
1828                            try {
1829                                    session = openSession();
1830    
1831                                    StringBundler query = null;
1832    
1833                                    if (orderByComparator != null) {
1834                                            query = new StringBundler(4 +
1835                                                            (orderByComparator.getOrderByFields().length * 3));
1836                                    }
1837                                    else {
1838                                            query = new StringBundler(3);
1839                                    }
1840    
1841                                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1842    
1843                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
1844    
1845                                    query.append(_FINDER_COLUMN_G_R_ROLEID_2);
1846    
1847                                    if (orderByComparator != null) {
1848                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1849                                                    orderByComparator);
1850                                    }
1851    
1852                                    String sql = query.toString();
1853    
1854                                    Query q = session.createQuery(sql);
1855    
1856                                    QueryPos qPos = QueryPos.getInstance(q);
1857    
1858                                    qPos.add(groupId);
1859    
1860                                    qPos.add(roleId);
1861    
1862                                    list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1863                                                    start, end);
1864                            }
1865                            catch (Exception e) {
1866                                    throw processException(e);
1867                            }
1868                            finally {
1869                                    if (list == null) {
1870                                            list = new ArrayList<UserGroupRole>();
1871                                    }
1872    
1873                                    cacheResult(list);
1874    
1875                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_R, finderArgs,
1876                                            list);
1877    
1878                                    closeSession(session);
1879                            }
1880                    }
1881    
1882                    return list;
1883            }
1884    
1885            /**
1886             * Finds the first user group role in the ordered set where groupId = &#63; and roleId = &#63;.
1887             *
1888             * <p>
1889             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1890             * </p>
1891             *
1892             * @param groupId the group id to search with
1893             * @param roleId the role id to search with
1894             * @param orderByComparator the comparator to order the set by
1895             * @return the first matching user group role
1896             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
1897             * @throws SystemException if a system exception occurred
1898             */
1899            public UserGroupRole findByG_R_First(long groupId, long roleId,
1900                    OrderByComparator orderByComparator)
1901                    throws NoSuchUserGroupRoleException, SystemException {
1902                    List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1,
1903                                    orderByComparator);
1904    
1905                    if (list.isEmpty()) {
1906                            StringBundler msg = new StringBundler(6);
1907    
1908                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1909    
1910                            msg.append("groupId=");
1911                            msg.append(groupId);
1912    
1913                            msg.append(", roleId=");
1914                            msg.append(roleId);
1915    
1916                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1917    
1918                            throw new NoSuchUserGroupRoleException(msg.toString());
1919                    }
1920                    else {
1921                            return list.get(0);
1922                    }
1923            }
1924    
1925            /**
1926             * Finds the last user group role in the ordered set where groupId = &#63; and roleId = &#63;.
1927             *
1928             * <p>
1929             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1930             * </p>
1931             *
1932             * @param groupId the group id to search with
1933             * @param roleId the role id to search with
1934             * @param orderByComparator the comparator to order the set by
1935             * @return the last matching user group role
1936             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a matching user group role could not be found
1937             * @throws SystemException if a system exception occurred
1938             */
1939            public UserGroupRole findByG_R_Last(long groupId, long roleId,
1940                    OrderByComparator orderByComparator)
1941                    throws NoSuchUserGroupRoleException, SystemException {
1942                    int count = countByG_R(groupId, roleId);
1943    
1944                    List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
1945                                    orderByComparator);
1946    
1947                    if (list.isEmpty()) {
1948                            StringBundler msg = new StringBundler(6);
1949    
1950                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1951    
1952                            msg.append("groupId=");
1953                            msg.append(groupId);
1954    
1955                            msg.append(", roleId=");
1956                            msg.append(roleId);
1957    
1958                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1959    
1960                            throw new NoSuchUserGroupRoleException(msg.toString());
1961                    }
1962                    else {
1963                            return list.get(0);
1964                    }
1965            }
1966    
1967            /**
1968             * Finds the user group roles before and after the current user group role in the ordered set where groupId = &#63; and roleId = &#63;.
1969             *
1970             * <p>
1971             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1972             * </p>
1973             *
1974             * @param userGroupRolePK the primary key of the current user group role
1975             * @param groupId the group id to search with
1976             * @param roleId the role id to search with
1977             * @param orderByComparator the comparator to order the set by
1978             * @return the previous, current, and next user group role
1979             * @throws com.liferay.portal.NoSuchUserGroupRoleException if a user group role with the primary key could not be found
1980             * @throws SystemException if a system exception occurred
1981             */
1982            public UserGroupRole[] findByG_R_PrevAndNext(
1983                    UserGroupRolePK userGroupRolePK, long groupId, long roleId,
1984                    OrderByComparator orderByComparator)
1985                    throws NoSuchUserGroupRoleException, SystemException {
1986                    UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1987    
1988                    Session session = null;
1989    
1990                    try {
1991                            session = openSession();
1992    
1993                            UserGroupRole[] array = new UserGroupRoleImpl[3];
1994    
1995                            array[0] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
1996                                            roleId, orderByComparator, true);
1997    
1998                            array[1] = userGroupRole;
1999    
2000                            array[2] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2001                                            roleId, orderByComparator, false);
2002    
2003                            return array;
2004                    }
2005                    catch (Exception e) {
2006                            throw processException(e);
2007                    }
2008                    finally {
2009                            closeSession(session);
2010                    }
2011            }
2012    
2013            protected UserGroupRole getByG_R_PrevAndNext(Session session,
2014                    UserGroupRole userGroupRole, long groupId, long roleId,
2015                    OrderByComparator orderByComparator, boolean previous) {
2016                    StringBundler query = null;
2017    
2018                    if (orderByComparator != null) {
2019                            query = new StringBundler(6 +
2020                                            (orderByComparator.getOrderByFields().length * 6));
2021                    }
2022                    else {
2023                            query = new StringBundler(3);
2024                    }
2025    
2026                    query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2027    
2028                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2029    
2030                    query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2031    
2032                    if (orderByComparator != null) {
2033                            String[] orderByFields = orderByComparator.getOrderByFields();
2034    
2035                            if (orderByFields.length > 0) {
2036                                    query.append(WHERE_AND);
2037                            }
2038    
2039                            for (int i = 0; i < orderByFields.length; i++) {
2040                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2041                                    query.append(orderByFields[i]);
2042    
2043                                    if ((i + 1) < orderByFields.length) {
2044                                            if (orderByComparator.isAscending() ^ previous) {
2045                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2046                                            }
2047                                            else {
2048                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2049                                            }
2050                                    }
2051                                    else {
2052                                            if (orderByComparator.isAscending() ^ previous) {
2053                                                    query.append(WHERE_GREATER_THAN);
2054                                            }
2055                                            else {
2056                                                    query.append(WHERE_LESSER_THAN);
2057                                            }
2058                                    }
2059                            }
2060    
2061                            query.append(ORDER_BY_CLAUSE);
2062    
2063                            for (int i = 0; i < orderByFields.length; i++) {
2064                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2065                                    query.append(orderByFields[i]);
2066    
2067                                    if ((i + 1) < orderByFields.length) {
2068                                            if (orderByComparator.isAscending() ^ previous) {
2069                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2070                                            }
2071                                            else {
2072                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2073                                            }
2074                                    }
2075                                    else {
2076                                            if (orderByComparator.isAscending() ^ previous) {
2077                                                    query.append(ORDER_BY_ASC);
2078                                            }
2079                                            else {
2080                                                    query.append(ORDER_BY_DESC);
2081                                            }
2082                                    }
2083                            }
2084                    }
2085    
2086                    String sql = query.toString();
2087    
2088                    Query q = session.createQuery(sql);
2089    
2090                    q.setFirstResult(0);
2091                    q.setMaxResults(2);
2092    
2093                    QueryPos qPos = QueryPos.getInstance(q);
2094    
2095                    qPos.add(groupId);
2096    
2097                    qPos.add(roleId);
2098    
2099                    if (orderByComparator != null) {
2100                            Object[] values = orderByComparator.getOrderByValues(userGroupRole);
2101    
2102                            for (Object value : values) {
2103                                    qPos.add(value);
2104                            }
2105                    }
2106    
2107                    List<UserGroupRole> list = q.list();
2108    
2109                    if (list.size() == 2) {
2110                            return list.get(1);
2111                    }
2112                    else {
2113                            return null;
2114                    }
2115            }
2116    
2117            /**
2118             * Finds all the user group roles.
2119             *
2120             * @return the user group roles
2121             * @throws SystemException if a system exception occurred
2122             */
2123            public List<UserGroupRole> findAll() throws SystemException {
2124                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2125            }
2126    
2127            /**
2128             * Finds a range of all the user group roles.
2129             *
2130             * <p>
2131             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2132             * </p>
2133             *
2134             * @param start the lower bound of the range of user group roles to return
2135             * @param end the upper bound of the range of user group roles to return (not inclusive)
2136             * @return the range of user group roles
2137             * @throws SystemException if a system exception occurred
2138             */
2139            public List<UserGroupRole> findAll(int start, int end)
2140                    throws SystemException {
2141                    return findAll(start, end, null);
2142            }
2143    
2144            /**
2145             * Finds an ordered range of all the user group roles.
2146             *
2147             * <p>
2148             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2149             * </p>
2150             *
2151             * @param start the lower bound of the range of user group roles to return
2152             * @param end the upper bound of the range of user group roles to return (not inclusive)
2153             * @param orderByComparator the comparator to order the results by
2154             * @return the ordered range of user group roles
2155             * @throws SystemException if a system exception occurred
2156             */
2157            public List<UserGroupRole> findAll(int start, int end,
2158                    OrderByComparator orderByComparator) throws SystemException {
2159                    Object[] finderArgs = new Object[] {
2160                                    String.valueOf(start), String.valueOf(end),
2161                                    String.valueOf(orderByComparator)
2162                            };
2163    
2164                    List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2165                                    finderArgs, this);
2166    
2167                    if (list == null) {
2168                            Session session = null;
2169    
2170                            try {
2171                                    session = openSession();
2172    
2173                                    StringBundler query = null;
2174                                    String sql = null;
2175    
2176                                    if (orderByComparator != null) {
2177                                            query = new StringBundler(2 +
2178                                                            (orderByComparator.getOrderByFields().length * 3));
2179    
2180                                            query.append(_SQL_SELECT_USERGROUPROLE);
2181    
2182                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2183                                                    orderByComparator);
2184    
2185                                            sql = query.toString();
2186                                    }
2187                                    else {
2188                                            sql = _SQL_SELECT_USERGROUPROLE;
2189                                    }
2190    
2191                                    Query q = session.createQuery(sql);
2192    
2193                                    if (orderByComparator == null) {
2194                                            list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2195                                                            start, end, false);
2196    
2197                                            Collections.sort(list);
2198                                    }
2199                                    else {
2200                                            list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2201                                                            start, end);
2202                                    }
2203                            }
2204                            catch (Exception e) {
2205                                    throw processException(e);
2206                            }
2207                            finally {
2208                                    if (list == null) {
2209                                            list = new ArrayList<UserGroupRole>();
2210                                    }
2211    
2212                                    cacheResult(list);
2213    
2214                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2215    
2216                                    closeSession(session);
2217                            }
2218                    }
2219    
2220                    return list;
2221            }
2222    
2223            /**
2224             * Removes all the user group roles where userId = &#63; from the database.
2225             *
2226             * @param userId the user id to search with
2227             * @throws SystemException if a system exception occurred
2228             */
2229            public void removeByUserId(long userId) throws SystemException {
2230                    for (UserGroupRole userGroupRole : findByUserId(userId)) {
2231                            remove(userGroupRole);
2232                    }
2233            }
2234    
2235            /**
2236             * Removes all the user group roles where groupId = &#63; from the database.
2237             *
2238             * @param groupId the group id to search with
2239             * @throws SystemException if a system exception occurred
2240             */
2241            public void removeByGroupId(long groupId) throws SystemException {
2242                    for (UserGroupRole userGroupRole : findByGroupId(groupId)) {
2243                            remove(userGroupRole);
2244                    }
2245            }
2246    
2247            /**
2248             * Removes all the user group roles where roleId = &#63; from the database.
2249             *
2250             * @param roleId the role id to search with
2251             * @throws SystemException if a system exception occurred
2252             */
2253            public void removeByRoleId(long roleId) throws SystemException {
2254                    for (UserGroupRole userGroupRole : findByRoleId(roleId)) {
2255                            remove(userGroupRole);
2256                    }
2257            }
2258    
2259            /**
2260             * Removes all the user group roles where userId = &#63; and groupId = &#63; from the database.
2261             *
2262             * @param userId the user id to search with
2263             * @param groupId the group id to search with
2264             * @throws SystemException if a system exception occurred
2265             */
2266            public void removeByU_G(long userId, long groupId)
2267                    throws SystemException {
2268                    for (UserGroupRole userGroupRole : findByU_G(userId, groupId)) {
2269                            remove(userGroupRole);
2270                    }
2271            }
2272    
2273            /**
2274             * Removes all the user group roles where groupId = &#63; and roleId = &#63; from the database.
2275             *
2276             * @param groupId the group id to search with
2277             * @param roleId the role id to search with
2278             * @throws SystemException if a system exception occurred
2279             */
2280            public void removeByG_R(long groupId, long roleId)
2281                    throws SystemException {
2282                    for (UserGroupRole userGroupRole : findByG_R(groupId, roleId)) {
2283                            remove(userGroupRole);
2284                    }
2285            }
2286    
2287            /**
2288             * Removes all the user group roles from the database.
2289             *
2290             * @throws SystemException if a system exception occurred
2291             */
2292            public void removeAll() throws SystemException {
2293                    for (UserGroupRole userGroupRole : findAll()) {
2294                            remove(userGroupRole);
2295                    }
2296            }
2297    
2298            /**
2299             * Counts all the user group roles where userId = &#63;.
2300             *
2301             * @param userId the user id to search with
2302             * @return the number of matching user group roles
2303             * @throws SystemException if a system exception occurred
2304             */
2305            public int countByUserId(long userId) throws SystemException {
2306                    Object[] finderArgs = new Object[] { userId };
2307    
2308                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2309                                    finderArgs, this);
2310    
2311                    if (count == null) {
2312                            Session session = null;
2313    
2314                            try {
2315                                    session = openSession();
2316    
2317                                    StringBundler query = new StringBundler(2);
2318    
2319                                    query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2320    
2321                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2322    
2323                                    String sql = query.toString();
2324    
2325                                    Query q = session.createQuery(sql);
2326    
2327                                    QueryPos qPos = QueryPos.getInstance(q);
2328    
2329                                    qPos.add(userId);
2330    
2331                                    count = (Long)q.uniqueResult();
2332                            }
2333                            catch (Exception e) {
2334                                    throw processException(e);
2335                            }
2336                            finally {
2337                                    if (count == null) {
2338                                            count = Long.valueOf(0);
2339                                    }
2340    
2341                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2342                                            finderArgs, count);
2343    
2344                                    closeSession(session);
2345                            }
2346                    }
2347    
2348                    return count.intValue();
2349            }
2350    
2351            /**
2352             * Counts all the user group roles where groupId = &#63;.
2353             *
2354             * @param groupId the group id to search with
2355             * @return the number of matching user group roles
2356             * @throws SystemException if a system exception occurred
2357             */
2358            public int countByGroupId(long groupId) throws SystemException {
2359                    Object[] finderArgs = new Object[] { groupId };
2360    
2361                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2362                                    finderArgs, this);
2363    
2364                    if (count == null) {
2365                            Session session = null;
2366    
2367                            try {
2368                                    session = openSession();
2369    
2370                                    StringBundler query = new StringBundler(2);
2371    
2372                                    query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2373    
2374                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2375    
2376                                    String sql = query.toString();
2377    
2378                                    Query q = session.createQuery(sql);
2379    
2380                                    QueryPos qPos = QueryPos.getInstance(q);
2381    
2382                                    qPos.add(groupId);
2383    
2384                                    count = (Long)q.uniqueResult();
2385                            }
2386                            catch (Exception e) {
2387                                    throw processException(e);
2388                            }
2389                            finally {
2390                                    if (count == null) {
2391                                            count = Long.valueOf(0);
2392                                    }
2393    
2394                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2395                                            finderArgs, count);
2396    
2397                                    closeSession(session);
2398                            }
2399                    }
2400    
2401                    return count.intValue();
2402            }
2403    
2404            /**
2405             * Counts all the user group roles where roleId = &#63;.
2406             *
2407             * @param roleId the role id to search with
2408             * @return the number of matching user group roles
2409             * @throws SystemException if a system exception occurred
2410             */
2411            public int countByRoleId(long roleId) throws SystemException {
2412                    Object[] finderArgs = new Object[] { roleId };
2413    
2414                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
2415                                    finderArgs, this);
2416    
2417                    if (count == null) {
2418                            Session session = null;
2419    
2420                            try {
2421                                    session = openSession();
2422    
2423                                    StringBundler query = new StringBundler(2);
2424    
2425                                    query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2426    
2427                                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
2428    
2429                                    String sql = query.toString();
2430    
2431                                    Query q = session.createQuery(sql);
2432    
2433                                    QueryPos qPos = QueryPos.getInstance(q);
2434    
2435                                    qPos.add(roleId);
2436    
2437                                    count = (Long)q.uniqueResult();
2438                            }
2439                            catch (Exception e) {
2440                                    throw processException(e);
2441                            }
2442                            finally {
2443                                    if (count == null) {
2444                                            count = Long.valueOf(0);
2445                                    }
2446    
2447                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
2448                                            finderArgs, count);
2449    
2450                                    closeSession(session);
2451                            }
2452                    }
2453    
2454                    return count.intValue();
2455            }
2456    
2457            /**
2458             * Counts all the user group roles where userId = &#63; and groupId = &#63;.
2459             *
2460             * @param userId the user id to search with
2461             * @param groupId the group id to search with
2462             * @return the number of matching user group roles
2463             * @throws SystemException if a system exception occurred
2464             */
2465            public int countByU_G(long userId, long groupId) throws SystemException {
2466                    Object[] finderArgs = new Object[] { userId, groupId };
2467    
2468                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_G,
2469                                    finderArgs, this);
2470    
2471                    if (count == null) {
2472                            Session session = null;
2473    
2474                            try {
2475                                    session = openSession();
2476    
2477                                    StringBundler query = new StringBundler(3);
2478    
2479                                    query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2480    
2481                                    query.append(_FINDER_COLUMN_U_G_USERID_2);
2482    
2483                                    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
2484    
2485                                    String sql = query.toString();
2486    
2487                                    Query q = session.createQuery(sql);
2488    
2489                                    QueryPos qPos = QueryPos.getInstance(q);
2490    
2491                                    qPos.add(userId);
2492    
2493                                    qPos.add(groupId);
2494    
2495                                    count = (Long)q.uniqueResult();
2496                            }
2497                            catch (Exception e) {
2498                                    throw processException(e);
2499                            }
2500                            finally {
2501                                    if (count == null) {
2502                                            count = Long.valueOf(0);
2503                                    }
2504    
2505                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_G, finderArgs,
2506                                            count);
2507    
2508                                    closeSession(session);
2509                            }
2510                    }
2511    
2512                    return count.intValue();
2513            }
2514    
2515            /**
2516             * Counts all the user group roles where groupId = &#63; and roleId = &#63;.
2517             *
2518             * @param groupId the group id to search with
2519             * @param roleId the role id to search with
2520             * @return the number of matching user group roles
2521             * @throws SystemException if a system exception occurred
2522             */
2523            public int countByG_R(long groupId, long roleId) throws SystemException {
2524                    Object[] finderArgs = new Object[] { groupId, roleId };
2525    
2526                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_R,
2527                                    finderArgs, this);
2528    
2529                    if (count == null) {
2530                            Session session = null;
2531    
2532                            try {
2533                                    session = openSession();
2534    
2535                                    StringBundler query = new StringBundler(3);
2536    
2537                                    query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2538    
2539                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2540    
2541                                    query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2542    
2543                                    String sql = query.toString();
2544    
2545                                    Query q = session.createQuery(sql);
2546    
2547                                    QueryPos qPos = QueryPos.getInstance(q);
2548    
2549                                    qPos.add(groupId);
2550    
2551                                    qPos.add(roleId);
2552    
2553                                    count = (Long)q.uniqueResult();
2554                            }
2555                            catch (Exception e) {
2556                                    throw processException(e);
2557                            }
2558                            finally {
2559                                    if (count == null) {
2560                                            count = Long.valueOf(0);
2561                                    }
2562    
2563                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_R, finderArgs,
2564                                            count);
2565    
2566                                    closeSession(session);
2567                            }
2568                    }
2569    
2570                    return count.intValue();
2571            }
2572    
2573            /**
2574             * Counts all the user group roles.
2575             *
2576             * @return the number of user group roles
2577             * @throws SystemException if a system exception occurred
2578             */
2579            public int countAll() throws SystemException {
2580                    Object[] finderArgs = new Object[0];
2581    
2582                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2583                                    finderArgs, this);
2584    
2585                    if (count == null) {
2586                            Session session = null;
2587    
2588                            try {
2589                                    session = openSession();
2590    
2591                                    Query q = session.createQuery(_SQL_COUNT_USERGROUPROLE);
2592    
2593                                    count = (Long)q.uniqueResult();
2594                            }
2595                            catch (Exception e) {
2596                                    throw processException(e);
2597                            }
2598                            finally {
2599                                    if (count == null) {
2600                                            count = Long.valueOf(0);
2601                                    }
2602    
2603                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2604                                            count);
2605    
2606                                    closeSession(session);
2607                            }
2608                    }
2609    
2610                    return count.intValue();
2611            }
2612    
2613            /**
2614             * Initializes the user group role persistence.
2615             */
2616            public void afterPropertiesSet() {
2617                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2618                                            com.liferay.portal.util.PropsUtil.get(
2619                                                    "value.object.listener.com.liferay.portal.model.UserGroupRole")));
2620    
2621                    if (listenerClassNames.length > 0) {
2622                            try {
2623                                    List<ModelListener<UserGroupRole>> listenersList = new ArrayList<ModelListener<UserGroupRole>>();
2624    
2625                                    for (String listenerClassName : listenerClassNames) {
2626                                            listenersList.add((ModelListener<UserGroupRole>)InstanceFactory.newInstance(
2627                                                            listenerClassName));
2628                                    }
2629    
2630                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2631                            }
2632                            catch (Exception e) {
2633                                    _log.error(e);
2634                            }
2635                    }
2636            }
2637    
2638            public void destroy() {
2639                    EntityCacheUtil.removeCache(UserGroupRoleImpl.class.getName());
2640                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2641                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2642            }
2643    
2644            @BeanReference(type = AccountPersistence.class)
2645            protected AccountPersistence accountPersistence;
2646            @BeanReference(type = AddressPersistence.class)
2647            protected AddressPersistence addressPersistence;
2648            @BeanReference(type = BrowserTrackerPersistence.class)
2649            protected BrowserTrackerPersistence browserTrackerPersistence;
2650            @BeanReference(type = ClassNamePersistence.class)
2651            protected ClassNamePersistence classNamePersistence;
2652            @BeanReference(type = ClusterGroupPersistence.class)
2653            protected ClusterGroupPersistence clusterGroupPersistence;
2654            @BeanReference(type = CompanyPersistence.class)
2655            protected CompanyPersistence companyPersistence;
2656            @BeanReference(type = ContactPersistence.class)
2657            protected ContactPersistence contactPersistence;
2658            @BeanReference(type = CountryPersistence.class)
2659            protected CountryPersistence countryPersistence;
2660            @BeanReference(type = EmailAddressPersistence.class)
2661            protected EmailAddressPersistence emailAddressPersistence;
2662            @BeanReference(type = GroupPersistence.class)
2663            protected GroupPersistence groupPersistence;
2664            @BeanReference(type = ImagePersistence.class)
2665            protected ImagePersistence imagePersistence;
2666            @BeanReference(type = LayoutPersistence.class)
2667            protected LayoutPersistence layoutPersistence;
2668            @BeanReference(type = LayoutPrototypePersistence.class)
2669            protected LayoutPrototypePersistence layoutPrototypePersistence;
2670            @BeanReference(type = LayoutSetPersistence.class)
2671            protected LayoutSetPersistence layoutSetPersistence;
2672            @BeanReference(type = LayoutSetPrototypePersistence.class)
2673            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2674            @BeanReference(type = ListTypePersistence.class)
2675            protected ListTypePersistence listTypePersistence;
2676            @BeanReference(type = LockPersistence.class)
2677            protected LockPersistence lockPersistence;
2678            @BeanReference(type = MembershipRequestPersistence.class)
2679            protected MembershipRequestPersistence membershipRequestPersistence;
2680            @BeanReference(type = OrganizationPersistence.class)
2681            protected OrganizationPersistence organizationPersistence;
2682            @BeanReference(type = OrgGroupPermissionPersistence.class)
2683            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2684            @BeanReference(type = OrgGroupRolePersistence.class)
2685            protected OrgGroupRolePersistence orgGroupRolePersistence;
2686            @BeanReference(type = OrgLaborPersistence.class)
2687            protected OrgLaborPersistence orgLaborPersistence;
2688            @BeanReference(type = PasswordPolicyPersistence.class)
2689            protected PasswordPolicyPersistence passwordPolicyPersistence;
2690            @BeanReference(type = PasswordPolicyRelPersistence.class)
2691            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2692            @BeanReference(type = PasswordTrackerPersistence.class)
2693            protected PasswordTrackerPersistence passwordTrackerPersistence;
2694            @BeanReference(type = PermissionPersistence.class)
2695            protected PermissionPersistence permissionPersistence;
2696            @BeanReference(type = PhonePersistence.class)
2697            protected PhonePersistence phonePersistence;
2698            @BeanReference(type = PluginSettingPersistence.class)
2699            protected PluginSettingPersistence pluginSettingPersistence;
2700            @BeanReference(type = PortletPersistence.class)
2701            protected PortletPersistence portletPersistence;
2702            @BeanReference(type = PortletItemPersistence.class)
2703            protected PortletItemPersistence portletItemPersistence;
2704            @BeanReference(type = PortletPreferencesPersistence.class)
2705            protected PortletPreferencesPersistence portletPreferencesPersistence;
2706            @BeanReference(type = RegionPersistence.class)
2707            protected RegionPersistence regionPersistence;
2708            @BeanReference(type = ReleasePersistence.class)
2709            protected ReleasePersistence releasePersistence;
2710            @BeanReference(type = ResourcePersistence.class)
2711            protected ResourcePersistence resourcePersistence;
2712            @BeanReference(type = ResourceActionPersistence.class)
2713            protected ResourceActionPersistence resourceActionPersistence;
2714            @BeanReference(type = ResourceCodePersistence.class)
2715            protected ResourceCodePersistence resourceCodePersistence;
2716            @BeanReference(type = ResourcePermissionPersistence.class)
2717            protected ResourcePermissionPersistence resourcePermissionPersistence;
2718            @BeanReference(type = RolePersistence.class)
2719            protected RolePersistence rolePersistence;
2720            @BeanReference(type = ServiceComponentPersistence.class)
2721            protected ServiceComponentPersistence serviceComponentPersistence;
2722            @BeanReference(type = ShardPersistence.class)
2723            protected ShardPersistence shardPersistence;
2724            @BeanReference(type = SubscriptionPersistence.class)
2725            protected SubscriptionPersistence subscriptionPersistence;
2726            @BeanReference(type = TicketPersistence.class)
2727            protected TicketPersistence ticketPersistence;
2728            @BeanReference(type = TeamPersistence.class)
2729            protected TeamPersistence teamPersistence;
2730            @BeanReference(type = UserPersistence.class)
2731            protected UserPersistence userPersistence;
2732            @BeanReference(type = UserGroupPersistence.class)
2733            protected UserGroupPersistence userGroupPersistence;
2734            @BeanReference(type = UserGroupGroupRolePersistence.class)
2735            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2736            @BeanReference(type = UserGroupRolePersistence.class)
2737            protected UserGroupRolePersistence userGroupRolePersistence;
2738            @BeanReference(type = UserIdMapperPersistence.class)
2739            protected UserIdMapperPersistence userIdMapperPersistence;
2740            @BeanReference(type = UserTrackerPersistence.class)
2741            protected UserTrackerPersistence userTrackerPersistence;
2742            @BeanReference(type = UserTrackerPathPersistence.class)
2743            protected UserTrackerPathPersistence userTrackerPathPersistence;
2744            @BeanReference(type = WebDAVPropsPersistence.class)
2745            protected WebDAVPropsPersistence webDAVPropsPersistence;
2746            @BeanReference(type = WebsitePersistence.class)
2747            protected WebsitePersistence websitePersistence;
2748            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2749            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2750            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2751            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2752            private static final String _SQL_SELECT_USERGROUPROLE = "SELECT userGroupRole FROM UserGroupRole userGroupRole";
2753            private static final String _SQL_SELECT_USERGROUPROLE_WHERE = "SELECT userGroupRole FROM UserGroupRole userGroupRole WHERE ";
2754            private static final String _SQL_COUNT_USERGROUPROLE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole";
2755            private static final String _SQL_COUNT_USERGROUPROLE_WHERE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole WHERE ";
2756            private static final String _FINDER_COLUMN_USERID_USERID_2 = "userGroupRole.id.userId = ?";
2757            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "userGroupRole.id.groupId = ?";
2758            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "userGroupRole.id.roleId = ?";
2759            private static final String _FINDER_COLUMN_U_G_USERID_2 = "userGroupRole.id.userId = ? AND ";
2760            private static final String _FINDER_COLUMN_U_G_GROUPID_2 = "userGroupRole.id.groupId = ?";
2761            private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "userGroupRole.id.groupId = ? AND ";
2762            private static final String _FINDER_COLUMN_G_R_ROLEID_2 = "userGroupRole.id.roleId = ?";
2763            private static final String _ORDER_BY_ENTITY_ALIAS = "userGroupRole.";
2764            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroupRole exists with the primary key ";
2765            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroupRole exists with the key {";
2766            private static Log _log = LogFactoryUtil.getLog(UserGroupRolePersistenceImpl.class);
2767    }