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