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