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