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