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