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