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