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