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