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