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