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