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