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