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