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