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