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