001    /**
002     * Copyright (c) 2000-2010 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.NoSuchModelException;
018    import com.liferay.portal.NoSuchUserGroupGroupRoleException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
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     * @author    Brian Wing Shun Chan
051     * @see       UserGroupGroupRolePersistence
052     * @see       UserGroupGroupRoleUtil
053     * @generated
054     */
055    public class UserGroupGroupRolePersistenceImpl extends BasePersistenceImpl<UserGroupGroupRole>
056            implements UserGroupGroupRolePersistence {
057            public static final String FINDER_CLASS_NAME_ENTITY = UserGroupGroupRoleImpl.class.getName();
058            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
059                    ".List";
060            public static final FinderPath FINDER_PATH_FIND_BY_USERGROUPID = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
061                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
062                            FINDER_CLASS_NAME_LIST, "findByUserGroupId",
063                            new String[] {
064                                    Long.class.getName(),
065                                    
066                            "java.lang.Integer", "java.lang.Integer",
067                                    "com.liferay.portal.kernel.util.OrderByComparator"
068                            });
069            public static final FinderPath FINDER_PATH_COUNT_BY_USERGROUPID = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
070                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
071                            FINDER_CLASS_NAME_LIST, "countByUserGroupId",
072                            new String[] { Long.class.getName() });
073            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
074                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
075                            FINDER_CLASS_NAME_LIST, "findByGroupId",
076                            new String[] {
077                                    Long.class.getName(),
078                                    
079                            "java.lang.Integer", "java.lang.Integer",
080                                    "com.liferay.portal.kernel.util.OrderByComparator"
081                            });
082            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
083                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
084                            FINDER_CLASS_NAME_LIST, "countByGroupId",
085                            new String[] { Long.class.getName() });
086            public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
087                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
088                            FINDER_CLASS_NAME_LIST, "findByRoleId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
096                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
097                            FINDER_CLASS_NAME_LIST, "countByRoleId",
098                            new String[] { Long.class.getName() });
099            public static final FinderPath FINDER_PATH_FIND_BY_U_G = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
100                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
101                            FINDER_CLASS_NAME_LIST, "findByU_G",
102                            new String[] {
103                                    Long.class.getName(), Long.class.getName(),
104                                    
105                            "java.lang.Integer", "java.lang.Integer",
106                                    "com.liferay.portal.kernel.util.OrderByComparator"
107                            });
108            public static final FinderPath FINDER_PATH_COUNT_BY_U_G = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
109                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
110                            FINDER_CLASS_NAME_LIST, "countByU_G",
111                            new String[] { Long.class.getName(), Long.class.getName() });
112            public static final FinderPath FINDER_PATH_FIND_BY_G_R = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
113                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
114                            FINDER_CLASS_NAME_LIST, "findByG_R",
115                            new String[] {
116                                    Long.class.getName(), Long.class.getName(),
117                                    
118                            "java.lang.Integer", "java.lang.Integer",
119                                    "com.liferay.portal.kernel.util.OrderByComparator"
120                            });
121            public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
122                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
123                            FINDER_CLASS_NAME_LIST, "countByG_R",
124                            new String[] { Long.class.getName(), Long.class.getName() });
125            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
126                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
127                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
128            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
129                            UserGroupGroupRoleModelImpl.FINDER_CACHE_ENABLED,
130                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
131    
132            public void cacheResult(UserGroupGroupRole userGroupGroupRole) {
133                    EntityCacheUtil.putResult(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
134                            UserGroupGroupRoleImpl.class, userGroupGroupRole.getPrimaryKey(),
135                            userGroupGroupRole);
136            }
137    
138            public void cacheResult(List<UserGroupGroupRole> userGroupGroupRoles) {
139                    for (UserGroupGroupRole userGroupGroupRole : userGroupGroupRoles) {
140                            if (EntityCacheUtil.getResult(
141                                                    UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
142                                                    UserGroupGroupRoleImpl.class,
143                                                    userGroupGroupRole.getPrimaryKey(), this) == null) {
144                                    cacheResult(userGroupGroupRole);
145                            }
146                    }
147            }
148    
149            public void clearCache() {
150                    CacheRegistryUtil.clear(UserGroupGroupRoleImpl.class.getName());
151                    EntityCacheUtil.clearCache(UserGroupGroupRoleImpl.class.getName());
152                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
153                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
154            }
155    
156            public void clearCache(UserGroupGroupRole userGroupGroupRole) {
157                    EntityCacheUtil.removeResult(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
158                            UserGroupGroupRoleImpl.class, userGroupGroupRole.getPrimaryKey());
159            }
160    
161            public UserGroupGroupRole create(UserGroupGroupRolePK userGroupGroupRolePK) {
162                    UserGroupGroupRole userGroupGroupRole = new UserGroupGroupRoleImpl();
163    
164                    userGroupGroupRole.setNew(true);
165                    userGroupGroupRole.setPrimaryKey(userGroupGroupRolePK);
166    
167                    return userGroupGroupRole;
168            }
169    
170            public UserGroupGroupRole remove(Serializable primaryKey)
171                    throws NoSuchModelException, SystemException {
172                    return remove((UserGroupGroupRolePK)primaryKey);
173            }
174    
175            public UserGroupGroupRole remove(UserGroupGroupRolePK userGroupGroupRolePK)
176                    throws NoSuchUserGroupGroupRoleException, SystemException {
177                    Session session = null;
178    
179                    try {
180                            session = openSession();
181    
182                            UserGroupGroupRole userGroupGroupRole = (UserGroupGroupRole)session.get(UserGroupGroupRoleImpl.class,
183                                            userGroupGroupRolePK);
184    
185                            if (userGroupGroupRole == null) {
186                                    if (_log.isWarnEnabled()) {
187                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
188                                                    userGroupGroupRolePK);
189                                    }
190    
191                                    throw new NoSuchUserGroupGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
192                                            userGroupGroupRolePK);
193                            }
194    
195                            return remove(userGroupGroupRole);
196                    }
197                    catch (NoSuchUserGroupGroupRoleException nsee) {
198                            throw nsee;
199                    }
200                    catch (Exception e) {
201                            throw processException(e);
202                    }
203                    finally {
204                            closeSession(session);
205                    }
206            }
207    
208            protected UserGroupGroupRole removeImpl(
209                    UserGroupGroupRole userGroupGroupRole) throws SystemException {
210                    userGroupGroupRole = toUnwrappedModel(userGroupGroupRole);
211    
212                    Session session = null;
213    
214                    try {
215                            session = openSession();
216    
217                            if (userGroupGroupRole.isCachedModel() ||
218                                            BatchSessionUtil.isEnabled()) {
219                                    Object staleObject = session.get(UserGroupGroupRoleImpl.class,
220                                                    userGroupGroupRole.getPrimaryKeyObj());
221    
222                                    if (staleObject != null) {
223                                            session.evict(staleObject);
224                                    }
225                            }
226    
227                            session.delete(userGroupGroupRole);
228    
229                            session.flush();
230                    }
231                    catch (Exception e) {
232                            throw processException(e);
233                    }
234                    finally {
235                            closeSession(session);
236                    }
237    
238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
239    
240                    EntityCacheUtil.removeResult(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
241                            UserGroupGroupRoleImpl.class, userGroupGroupRole.getPrimaryKey());
242    
243                    return userGroupGroupRole;
244            }
245    
246            public UserGroupGroupRole updateImpl(
247                    com.liferay.portal.model.UserGroupGroupRole userGroupGroupRole,
248                    boolean merge) throws SystemException {
249                    userGroupGroupRole = toUnwrappedModel(userGroupGroupRole);
250    
251                    Session session = null;
252    
253                    try {
254                            session = openSession();
255    
256                            BatchSessionUtil.update(session, userGroupGroupRole, merge);
257    
258                            userGroupGroupRole.setNew(false);
259                    }
260                    catch (Exception e) {
261                            throw processException(e);
262                    }
263                    finally {
264                            closeSession(session);
265                    }
266    
267                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
268    
269                    EntityCacheUtil.putResult(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
270                            UserGroupGroupRoleImpl.class, userGroupGroupRole.getPrimaryKey(),
271                            userGroupGroupRole);
272    
273                    return userGroupGroupRole;
274            }
275    
276            protected UserGroupGroupRole toUnwrappedModel(
277                    UserGroupGroupRole userGroupGroupRole) {
278                    if (userGroupGroupRole instanceof UserGroupGroupRoleImpl) {
279                            return userGroupGroupRole;
280                    }
281    
282                    UserGroupGroupRoleImpl userGroupGroupRoleImpl = new UserGroupGroupRoleImpl();
283    
284                    userGroupGroupRoleImpl.setNew(userGroupGroupRole.isNew());
285                    userGroupGroupRoleImpl.setPrimaryKey(userGroupGroupRole.getPrimaryKey());
286    
287                    userGroupGroupRoleImpl.setUserGroupId(userGroupGroupRole.getUserGroupId());
288                    userGroupGroupRoleImpl.setGroupId(userGroupGroupRole.getGroupId());
289                    userGroupGroupRoleImpl.setRoleId(userGroupGroupRole.getRoleId());
290    
291                    return userGroupGroupRoleImpl;
292            }
293    
294            public UserGroupGroupRole findByPrimaryKey(Serializable primaryKey)
295                    throws NoSuchModelException, SystemException {
296                    return findByPrimaryKey((UserGroupGroupRolePK)primaryKey);
297            }
298    
299            public UserGroupGroupRole findByPrimaryKey(
300                    UserGroupGroupRolePK userGroupGroupRolePK)
301                    throws NoSuchUserGroupGroupRoleException, SystemException {
302                    UserGroupGroupRole userGroupGroupRole = fetchByPrimaryKey(userGroupGroupRolePK);
303    
304                    if (userGroupGroupRole == null) {
305                            if (_log.isWarnEnabled()) {
306                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
307                                            userGroupGroupRolePK);
308                            }
309    
310                            throw new NoSuchUserGroupGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
311                                    userGroupGroupRolePK);
312                    }
313    
314                    return userGroupGroupRole;
315            }
316    
317            public UserGroupGroupRole fetchByPrimaryKey(Serializable primaryKey)
318                    throws SystemException {
319                    return fetchByPrimaryKey((UserGroupGroupRolePK)primaryKey);
320            }
321    
322            public UserGroupGroupRole fetchByPrimaryKey(
323                    UserGroupGroupRolePK userGroupGroupRolePK) throws SystemException {
324                    UserGroupGroupRole userGroupGroupRole = (UserGroupGroupRole)EntityCacheUtil.getResult(UserGroupGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
325                                    UserGroupGroupRoleImpl.class, userGroupGroupRolePK, this);
326    
327                    if (userGroupGroupRole == null) {
328                            Session session = null;
329    
330                            try {
331                                    session = openSession();
332    
333                                    userGroupGroupRole = (UserGroupGroupRole)session.get(UserGroupGroupRoleImpl.class,
334                                                    userGroupGroupRolePK);
335                            }
336                            catch (Exception e) {
337                                    throw processException(e);
338                            }
339                            finally {
340                                    if (userGroupGroupRole != null) {
341                                            cacheResult(userGroupGroupRole);
342                                    }
343    
344                                    closeSession(session);
345                            }
346                    }
347    
348                    return userGroupGroupRole;
349            }
350    
351            public List<UserGroupGroupRole> findByUserGroupId(long userGroupId)
352                    throws SystemException {
353                    return findByUserGroupId(userGroupId, QueryUtil.ALL_POS,
354                            QueryUtil.ALL_POS, null);
355            }
356    
357            public List<UserGroupGroupRole> findByUserGroupId(long userGroupId,
358                    int start, int end) throws SystemException {
359                    return findByUserGroupId(userGroupId, start, end, null);
360            }
361    
362            public List<UserGroupGroupRole> findByUserGroupId(long userGroupId,
363                    int start, int end, OrderByComparator orderByComparator)
364                    throws SystemException {
365                    Object[] finderArgs = new Object[] {
366                                    userGroupId,
367                                    
368                                    String.valueOf(start), String.valueOf(end),
369                                    String.valueOf(orderByComparator)
370                            };
371    
372                    List<UserGroupGroupRole> list = (List<UserGroupGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERGROUPID,
373                                    finderArgs, this);
374    
375                    if (list == null) {
376                            Session session = null;
377    
378                            try {
379                                    session = openSession();
380    
381                                    StringBundler query = null;
382    
383                                    if (orderByComparator != null) {
384                                            query = new StringBundler(3 +
385                                                            (orderByComparator.getOrderByFields().length * 3));
386                                    }
387                                    else {
388                                            query = new StringBundler(2);
389                                    }
390    
391                                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
392    
393                                    query.append(_FINDER_COLUMN_USERGROUPID_USERGROUPID_2);
394    
395                                    if (orderByComparator != null) {
396                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
397                                                    orderByComparator);
398                                    }
399    
400                                    String sql = query.toString();
401    
402                                    Query q = session.createQuery(sql);
403    
404                                    QueryPos qPos = QueryPos.getInstance(q);
405    
406                                    qPos.add(userGroupId);
407    
408                                    list = (List<UserGroupGroupRole>)QueryUtil.list(q,
409                                                    getDialect(), start, end);
410                            }
411                            catch (Exception e) {
412                                    throw processException(e);
413                            }
414                            finally {
415                                    if (list == null) {
416                                            list = new ArrayList<UserGroupGroupRole>();
417                                    }
418    
419                                    cacheResult(list);
420    
421                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERGROUPID,
422                                            finderArgs, list);
423    
424                                    closeSession(session);
425                            }
426                    }
427    
428                    return list;
429            }
430    
431            public UserGroupGroupRole findByUserGroupId_First(long userGroupId,
432                    OrderByComparator orderByComparator)
433                    throws NoSuchUserGroupGroupRoleException, SystemException {
434                    List<UserGroupGroupRole> list = findByUserGroupId(userGroupId, 0, 1,
435                                    orderByComparator);
436    
437                    if (list.isEmpty()) {
438                            StringBundler msg = new StringBundler(4);
439    
440                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
441    
442                            msg.append("userGroupId=");
443                            msg.append(userGroupId);
444    
445                            msg.append(StringPool.CLOSE_CURLY_BRACE);
446    
447                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
448                    }
449                    else {
450                            return list.get(0);
451                    }
452            }
453    
454            public UserGroupGroupRole findByUserGroupId_Last(long userGroupId,
455                    OrderByComparator orderByComparator)
456                    throws NoSuchUserGroupGroupRoleException, SystemException {
457                    int count = countByUserGroupId(userGroupId);
458    
459                    List<UserGroupGroupRole> list = findByUserGroupId(userGroupId,
460                                    count - 1, count, orderByComparator);
461    
462                    if (list.isEmpty()) {
463                            StringBundler msg = new StringBundler(4);
464    
465                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
466    
467                            msg.append("userGroupId=");
468                            msg.append(userGroupId);
469    
470                            msg.append(StringPool.CLOSE_CURLY_BRACE);
471    
472                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
473                    }
474                    else {
475                            return list.get(0);
476                    }
477            }
478    
479            public UserGroupGroupRole[] findByUserGroupId_PrevAndNext(
480                    UserGroupGroupRolePK userGroupGroupRolePK, long userGroupId,
481                    OrderByComparator orderByComparator)
482                    throws NoSuchUserGroupGroupRoleException, SystemException {
483                    UserGroupGroupRole userGroupGroupRole = findByPrimaryKey(userGroupGroupRolePK);
484    
485                    Session session = null;
486    
487                    try {
488                            session = openSession();
489    
490                            UserGroupGroupRole[] array = new UserGroupGroupRoleImpl[3];
491    
492                            array[0] = getByUserGroupId_PrevAndNext(session,
493                                            userGroupGroupRole, userGroupId, orderByComparator, true);
494    
495                            array[1] = userGroupGroupRole;
496    
497                            array[2] = getByUserGroupId_PrevAndNext(session,
498                                            userGroupGroupRole, userGroupId, orderByComparator, false);
499    
500                            return array;
501                    }
502                    catch (Exception e) {
503                            throw processException(e);
504                    }
505                    finally {
506                            closeSession(session);
507                    }
508            }
509    
510            protected UserGroupGroupRole getByUserGroupId_PrevAndNext(Session session,
511                    UserGroupGroupRole userGroupGroupRole, long userGroupId,
512                    OrderByComparator orderByComparator, boolean previous) {
513                    StringBundler query = null;
514    
515                    if (orderByComparator != null) {
516                            query = new StringBundler(6 +
517                                            (orderByComparator.getOrderByFields().length * 6));
518                    }
519                    else {
520                            query = new StringBundler(3);
521                    }
522    
523                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
524    
525                    query.append(_FINDER_COLUMN_USERGROUPID_USERGROUPID_2);
526    
527                    if (orderByComparator != null) {
528                            String[] orderByFields = orderByComparator.getOrderByFields();
529    
530                            if (orderByFields.length > 0) {
531                                    query.append(WHERE_AND);
532                            }
533    
534                            for (int i = 0; i < orderByFields.length; i++) {
535                                    query.append(_ORDER_BY_ENTITY_ALIAS);
536                                    query.append(orderByFields[i]);
537    
538                                    if ((i + 1) < orderByFields.length) {
539                                            if (orderByComparator.isAscending() ^ previous) {
540                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
541                                            }
542                                            else {
543                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
544                                            }
545                                    }
546                                    else {
547                                            if (orderByComparator.isAscending() ^ previous) {
548                                                    query.append(WHERE_GREATER_THAN);
549                                            }
550                                            else {
551                                                    query.append(WHERE_LESSER_THAN);
552                                            }
553                                    }
554                            }
555    
556                            query.append(ORDER_BY_CLAUSE);
557    
558                            for (int i = 0; i < orderByFields.length; i++) {
559                                    query.append(_ORDER_BY_ENTITY_ALIAS);
560                                    query.append(orderByFields[i]);
561    
562                                    if ((i + 1) < orderByFields.length) {
563                                            if (orderByComparator.isAscending() ^ previous) {
564                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
565                                            }
566                                            else {
567                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
568                                            }
569                                    }
570                                    else {
571                                            if (orderByComparator.isAscending() ^ previous) {
572                                                    query.append(ORDER_BY_ASC);
573                                            }
574                                            else {
575                                                    query.append(ORDER_BY_DESC);
576                                            }
577                                    }
578                            }
579                    }
580    
581                    String sql = query.toString();
582    
583                    Query q = session.createQuery(sql);
584    
585                    q.setFirstResult(0);
586                    q.setMaxResults(2);
587    
588                    QueryPos qPos = QueryPos.getInstance(q);
589    
590                    qPos.add(userGroupId);
591    
592                    if (orderByComparator != null) {
593                            Object[] values = orderByComparator.getOrderByValues(userGroupGroupRole);
594    
595                            for (Object value : values) {
596                                    qPos.add(value);
597                            }
598                    }
599    
600                    List<UserGroupGroupRole> list = q.list();
601    
602                    if (list.size() == 2) {
603                            return list.get(1);
604                    }
605                    else {
606                            return null;
607                    }
608            }
609    
610            public List<UserGroupGroupRole> findByGroupId(long groupId)
611                    throws SystemException {
612                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
613            }
614    
615            public List<UserGroupGroupRole> findByGroupId(long groupId, int start,
616                    int end) throws SystemException {
617                    return findByGroupId(groupId, start, end, null);
618            }
619    
620            public List<UserGroupGroupRole> findByGroupId(long groupId, int start,
621                    int end, OrderByComparator orderByComparator) throws SystemException {
622                    Object[] finderArgs = new Object[] {
623                                    groupId,
624                                    
625                                    String.valueOf(start), String.valueOf(end),
626                                    String.valueOf(orderByComparator)
627                            };
628    
629                    List<UserGroupGroupRole> list = (List<UserGroupGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
630                                    finderArgs, this);
631    
632                    if (list == null) {
633                            Session session = null;
634    
635                            try {
636                                    session = openSession();
637    
638                                    StringBundler query = null;
639    
640                                    if (orderByComparator != null) {
641                                            query = new StringBundler(3 +
642                                                            (orderByComparator.getOrderByFields().length * 3));
643                                    }
644                                    else {
645                                            query = new StringBundler(2);
646                                    }
647    
648                                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
649    
650                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
651    
652                                    if (orderByComparator != null) {
653                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
654                                                    orderByComparator);
655                                    }
656    
657                                    String sql = query.toString();
658    
659                                    Query q = session.createQuery(sql);
660    
661                                    QueryPos qPos = QueryPos.getInstance(q);
662    
663                                    qPos.add(groupId);
664    
665                                    list = (List<UserGroupGroupRole>)QueryUtil.list(q,
666                                                    getDialect(), start, end);
667                            }
668                            catch (Exception e) {
669                                    throw processException(e);
670                            }
671                            finally {
672                                    if (list == null) {
673                                            list = new ArrayList<UserGroupGroupRole>();
674                                    }
675    
676                                    cacheResult(list);
677    
678                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
679                                            finderArgs, list);
680    
681                                    closeSession(session);
682                            }
683                    }
684    
685                    return list;
686            }
687    
688            public UserGroupGroupRole findByGroupId_First(long groupId,
689                    OrderByComparator orderByComparator)
690                    throws NoSuchUserGroupGroupRoleException, SystemException {
691                    List<UserGroupGroupRole> list = findByGroupId(groupId, 0, 1,
692                                    orderByComparator);
693    
694                    if (list.isEmpty()) {
695                            StringBundler msg = new StringBundler(4);
696    
697                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
698    
699                            msg.append("groupId=");
700                            msg.append(groupId);
701    
702                            msg.append(StringPool.CLOSE_CURLY_BRACE);
703    
704                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
705                    }
706                    else {
707                            return list.get(0);
708                    }
709            }
710    
711            public UserGroupGroupRole findByGroupId_Last(long groupId,
712                    OrderByComparator orderByComparator)
713                    throws NoSuchUserGroupGroupRoleException, SystemException {
714                    int count = countByGroupId(groupId);
715    
716                    List<UserGroupGroupRole> list = findByGroupId(groupId, count - 1,
717                                    count, orderByComparator);
718    
719                    if (list.isEmpty()) {
720                            StringBundler msg = new StringBundler(4);
721    
722                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
723    
724                            msg.append("groupId=");
725                            msg.append(groupId);
726    
727                            msg.append(StringPool.CLOSE_CURLY_BRACE);
728    
729                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
730                    }
731                    else {
732                            return list.get(0);
733                    }
734            }
735    
736            public UserGroupGroupRole[] findByGroupId_PrevAndNext(
737                    UserGroupGroupRolePK userGroupGroupRolePK, long groupId,
738                    OrderByComparator orderByComparator)
739                    throws NoSuchUserGroupGroupRoleException, SystemException {
740                    UserGroupGroupRole userGroupGroupRole = findByPrimaryKey(userGroupGroupRolePK);
741    
742                    Session session = null;
743    
744                    try {
745                            session = openSession();
746    
747                            UserGroupGroupRole[] array = new UserGroupGroupRoleImpl[3];
748    
749                            array[0] = getByGroupId_PrevAndNext(session, userGroupGroupRole,
750                                            groupId, orderByComparator, true);
751    
752                            array[1] = userGroupGroupRole;
753    
754                            array[2] = getByGroupId_PrevAndNext(session, userGroupGroupRole,
755                                            groupId, orderByComparator, false);
756    
757                            return array;
758                    }
759                    catch (Exception e) {
760                            throw processException(e);
761                    }
762                    finally {
763                            closeSession(session);
764                    }
765            }
766    
767            protected UserGroupGroupRole getByGroupId_PrevAndNext(Session session,
768                    UserGroupGroupRole userGroupGroupRole, long groupId,
769                    OrderByComparator orderByComparator, boolean previous) {
770                    StringBundler query = null;
771    
772                    if (orderByComparator != null) {
773                            query = new StringBundler(6 +
774                                            (orderByComparator.getOrderByFields().length * 6));
775                    }
776                    else {
777                            query = new StringBundler(3);
778                    }
779    
780                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
781    
782                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
783    
784                    if (orderByComparator != null) {
785                            String[] orderByFields = orderByComparator.getOrderByFields();
786    
787                            if (orderByFields.length > 0) {
788                                    query.append(WHERE_AND);
789                            }
790    
791                            for (int i = 0; i < orderByFields.length; i++) {
792                                    query.append(_ORDER_BY_ENTITY_ALIAS);
793                                    query.append(orderByFields[i]);
794    
795                                    if ((i + 1) < orderByFields.length) {
796                                            if (orderByComparator.isAscending() ^ previous) {
797                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
798                                            }
799                                            else {
800                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
801                                            }
802                                    }
803                                    else {
804                                            if (orderByComparator.isAscending() ^ previous) {
805                                                    query.append(WHERE_GREATER_THAN);
806                                            }
807                                            else {
808                                                    query.append(WHERE_LESSER_THAN);
809                                            }
810                                    }
811                            }
812    
813                            query.append(ORDER_BY_CLAUSE);
814    
815                            for (int i = 0; i < orderByFields.length; i++) {
816                                    query.append(_ORDER_BY_ENTITY_ALIAS);
817                                    query.append(orderByFields[i]);
818    
819                                    if ((i + 1) < orderByFields.length) {
820                                            if (orderByComparator.isAscending() ^ previous) {
821                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
822                                            }
823                                            else {
824                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
825                                            }
826                                    }
827                                    else {
828                                            if (orderByComparator.isAscending() ^ previous) {
829                                                    query.append(ORDER_BY_ASC);
830                                            }
831                                            else {
832                                                    query.append(ORDER_BY_DESC);
833                                            }
834                                    }
835                            }
836                    }
837    
838                    String sql = query.toString();
839    
840                    Query q = session.createQuery(sql);
841    
842                    q.setFirstResult(0);
843                    q.setMaxResults(2);
844    
845                    QueryPos qPos = QueryPos.getInstance(q);
846    
847                    qPos.add(groupId);
848    
849                    if (orderByComparator != null) {
850                            Object[] values = orderByComparator.getOrderByValues(userGroupGroupRole);
851    
852                            for (Object value : values) {
853                                    qPos.add(value);
854                            }
855                    }
856    
857                    List<UserGroupGroupRole> list = q.list();
858    
859                    if (list.size() == 2) {
860                            return list.get(1);
861                    }
862                    else {
863                            return null;
864                    }
865            }
866    
867            public List<UserGroupGroupRole> findByRoleId(long roleId)
868                    throws SystemException {
869                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
870            }
871    
872            public List<UserGroupGroupRole> findByRoleId(long roleId, int start, int end)
873                    throws SystemException {
874                    return findByRoleId(roleId, start, end, null);
875            }
876    
877            public List<UserGroupGroupRole> findByRoleId(long roleId, int start,
878                    int end, OrderByComparator orderByComparator) throws SystemException {
879                    Object[] finderArgs = new Object[] {
880                                    roleId,
881                                    
882                                    String.valueOf(start), String.valueOf(end),
883                                    String.valueOf(orderByComparator)
884                            };
885    
886                    List<UserGroupGroupRole> list = (List<UserGroupGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
887                                    finderArgs, this);
888    
889                    if (list == null) {
890                            Session session = null;
891    
892                            try {
893                                    session = openSession();
894    
895                                    StringBundler query = null;
896    
897                                    if (orderByComparator != null) {
898                                            query = new StringBundler(3 +
899                                                            (orderByComparator.getOrderByFields().length * 3));
900                                    }
901                                    else {
902                                            query = new StringBundler(2);
903                                    }
904    
905                                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
906    
907                                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
908    
909                                    if (orderByComparator != null) {
910                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
911                                                    orderByComparator);
912                                    }
913    
914                                    String sql = query.toString();
915    
916                                    Query q = session.createQuery(sql);
917    
918                                    QueryPos qPos = QueryPos.getInstance(q);
919    
920                                    qPos.add(roleId);
921    
922                                    list = (List<UserGroupGroupRole>)QueryUtil.list(q,
923                                                    getDialect(), start, end);
924                            }
925                            catch (Exception e) {
926                                    throw processException(e);
927                            }
928                            finally {
929                                    if (list == null) {
930                                            list = new ArrayList<UserGroupGroupRole>();
931                                    }
932    
933                                    cacheResult(list);
934    
935                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
936                                            finderArgs, list);
937    
938                                    closeSession(session);
939                            }
940                    }
941    
942                    return list;
943            }
944    
945            public UserGroupGroupRole findByRoleId_First(long roleId,
946                    OrderByComparator orderByComparator)
947                    throws NoSuchUserGroupGroupRoleException, SystemException {
948                    List<UserGroupGroupRole> list = findByRoleId(roleId, 0, 1,
949                                    orderByComparator);
950    
951                    if (list.isEmpty()) {
952                            StringBundler msg = new StringBundler(4);
953    
954                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
955    
956                            msg.append("roleId=");
957                            msg.append(roleId);
958    
959                            msg.append(StringPool.CLOSE_CURLY_BRACE);
960    
961                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
962                    }
963                    else {
964                            return list.get(0);
965                    }
966            }
967    
968            public UserGroupGroupRole findByRoleId_Last(long roleId,
969                    OrderByComparator orderByComparator)
970                    throws NoSuchUserGroupGroupRoleException, SystemException {
971                    int count = countByRoleId(roleId);
972    
973                    List<UserGroupGroupRole> list = findByRoleId(roleId, count - 1, count,
974                                    orderByComparator);
975    
976                    if (list.isEmpty()) {
977                            StringBundler msg = new StringBundler(4);
978    
979                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
980    
981                            msg.append("roleId=");
982                            msg.append(roleId);
983    
984                            msg.append(StringPool.CLOSE_CURLY_BRACE);
985    
986                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
987                    }
988                    else {
989                            return list.get(0);
990                    }
991            }
992    
993            public UserGroupGroupRole[] findByRoleId_PrevAndNext(
994                    UserGroupGroupRolePK userGroupGroupRolePK, long roleId,
995                    OrderByComparator orderByComparator)
996                    throws NoSuchUserGroupGroupRoleException, SystemException {
997                    UserGroupGroupRole userGroupGroupRole = findByPrimaryKey(userGroupGroupRolePK);
998    
999                    Session session = null;
1000    
1001                    try {
1002                            session = openSession();
1003    
1004                            UserGroupGroupRole[] array = new UserGroupGroupRoleImpl[3];
1005    
1006                            array[0] = getByRoleId_PrevAndNext(session, userGroupGroupRole,
1007                                            roleId, orderByComparator, true);
1008    
1009                            array[1] = userGroupGroupRole;
1010    
1011                            array[2] = getByRoleId_PrevAndNext(session, userGroupGroupRole,
1012                                            roleId, orderByComparator, false);
1013    
1014                            return array;
1015                    }
1016                    catch (Exception e) {
1017                            throw processException(e);
1018                    }
1019                    finally {
1020                            closeSession(session);
1021                    }
1022            }
1023    
1024            protected UserGroupGroupRole getByRoleId_PrevAndNext(Session session,
1025                    UserGroupGroupRole userGroupGroupRole, long roleId,
1026                    OrderByComparator orderByComparator, boolean previous) {
1027                    StringBundler query = null;
1028    
1029                    if (orderByComparator != null) {
1030                            query = new StringBundler(6 +
1031                                            (orderByComparator.getOrderByFields().length * 6));
1032                    }
1033                    else {
1034                            query = new StringBundler(3);
1035                    }
1036    
1037                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
1038    
1039                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1040    
1041                    if (orderByComparator != null) {
1042                            String[] orderByFields = orderByComparator.getOrderByFields();
1043    
1044                            if (orderByFields.length > 0) {
1045                                    query.append(WHERE_AND);
1046                            }
1047    
1048                            for (int i = 0; i < orderByFields.length; i++) {
1049                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1050                                    query.append(orderByFields[i]);
1051    
1052                                    if ((i + 1) < orderByFields.length) {
1053                                            if (orderByComparator.isAscending() ^ previous) {
1054                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1055                                            }
1056                                            else {
1057                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1058                                            }
1059                                    }
1060                                    else {
1061                                            if (orderByComparator.isAscending() ^ previous) {
1062                                                    query.append(WHERE_GREATER_THAN);
1063                                            }
1064                                            else {
1065                                                    query.append(WHERE_LESSER_THAN);
1066                                            }
1067                                    }
1068                            }
1069    
1070                            query.append(ORDER_BY_CLAUSE);
1071    
1072                            for (int i = 0; i < orderByFields.length; i++) {
1073                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1074                                    query.append(orderByFields[i]);
1075    
1076                                    if ((i + 1) < orderByFields.length) {
1077                                            if (orderByComparator.isAscending() ^ previous) {
1078                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1079                                            }
1080                                            else {
1081                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1082                                            }
1083                                    }
1084                                    else {
1085                                            if (orderByComparator.isAscending() ^ previous) {
1086                                                    query.append(ORDER_BY_ASC);
1087                                            }
1088                                            else {
1089                                                    query.append(ORDER_BY_DESC);
1090                                            }
1091                                    }
1092                            }
1093                    }
1094    
1095                    String sql = query.toString();
1096    
1097                    Query q = session.createQuery(sql);
1098    
1099                    q.setFirstResult(0);
1100                    q.setMaxResults(2);
1101    
1102                    QueryPos qPos = QueryPos.getInstance(q);
1103    
1104                    qPos.add(roleId);
1105    
1106                    if (orderByComparator != null) {
1107                            Object[] values = orderByComparator.getOrderByValues(userGroupGroupRole);
1108    
1109                            for (Object value : values) {
1110                                    qPos.add(value);
1111                            }
1112                    }
1113    
1114                    List<UserGroupGroupRole> list = q.list();
1115    
1116                    if (list.size() == 2) {
1117                            return list.get(1);
1118                    }
1119                    else {
1120                            return null;
1121                    }
1122            }
1123    
1124            public List<UserGroupGroupRole> findByU_G(long userGroupId, long groupId)
1125                    throws SystemException {
1126                    return findByU_G(userGroupId, groupId, QueryUtil.ALL_POS,
1127                            QueryUtil.ALL_POS, null);
1128            }
1129    
1130            public List<UserGroupGroupRole> findByU_G(long userGroupId, long groupId,
1131                    int start, int end) throws SystemException {
1132                    return findByU_G(userGroupId, groupId, start, end, null);
1133            }
1134    
1135            public List<UserGroupGroupRole> findByU_G(long userGroupId, long groupId,
1136                    int start, int end, OrderByComparator orderByComparator)
1137                    throws SystemException {
1138                    Object[] finderArgs = new Object[] {
1139                                    userGroupId, groupId,
1140                                    
1141                                    String.valueOf(start), String.valueOf(end),
1142                                    String.valueOf(orderByComparator)
1143                            };
1144    
1145                    List<UserGroupGroupRole> list = (List<UserGroupGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_G,
1146                                    finderArgs, this);
1147    
1148                    if (list == null) {
1149                            Session session = null;
1150    
1151                            try {
1152                                    session = openSession();
1153    
1154                                    StringBundler query = null;
1155    
1156                                    if (orderByComparator != null) {
1157                                            query = new StringBundler(4 +
1158                                                            (orderByComparator.getOrderByFields().length * 3));
1159                                    }
1160                                    else {
1161                                            query = new StringBundler(3);
1162                                    }
1163    
1164                                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
1165    
1166                                    query.append(_FINDER_COLUMN_U_G_USERGROUPID_2);
1167    
1168                                    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1169    
1170                                    if (orderByComparator != null) {
1171                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1172                                                    orderByComparator);
1173                                    }
1174    
1175                                    String sql = query.toString();
1176    
1177                                    Query q = session.createQuery(sql);
1178    
1179                                    QueryPos qPos = QueryPos.getInstance(q);
1180    
1181                                    qPos.add(userGroupId);
1182    
1183                                    qPos.add(groupId);
1184    
1185                                    list = (List<UserGroupGroupRole>)QueryUtil.list(q,
1186                                                    getDialect(), start, end);
1187                            }
1188                            catch (Exception e) {
1189                                    throw processException(e);
1190                            }
1191                            finally {
1192                                    if (list == null) {
1193                                            list = new ArrayList<UserGroupGroupRole>();
1194                                    }
1195    
1196                                    cacheResult(list);
1197    
1198                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_G, finderArgs,
1199                                            list);
1200    
1201                                    closeSession(session);
1202                            }
1203                    }
1204    
1205                    return list;
1206            }
1207    
1208            public UserGroupGroupRole findByU_G_First(long userGroupId, long groupId,
1209                    OrderByComparator orderByComparator)
1210                    throws NoSuchUserGroupGroupRoleException, SystemException {
1211                    List<UserGroupGroupRole> list = findByU_G(userGroupId, groupId, 0, 1,
1212                                    orderByComparator);
1213    
1214                    if (list.isEmpty()) {
1215                            StringBundler msg = new StringBundler(6);
1216    
1217                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1218    
1219                            msg.append("userGroupId=");
1220                            msg.append(userGroupId);
1221    
1222                            msg.append(", groupId=");
1223                            msg.append(groupId);
1224    
1225                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1226    
1227                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
1228                    }
1229                    else {
1230                            return list.get(0);
1231                    }
1232            }
1233    
1234            public UserGroupGroupRole findByU_G_Last(long userGroupId, long groupId,
1235                    OrderByComparator orderByComparator)
1236                    throws NoSuchUserGroupGroupRoleException, SystemException {
1237                    int count = countByU_G(userGroupId, groupId);
1238    
1239                    List<UserGroupGroupRole> list = findByU_G(userGroupId, groupId,
1240                                    count - 1, count, orderByComparator);
1241    
1242                    if (list.isEmpty()) {
1243                            StringBundler msg = new StringBundler(6);
1244    
1245                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1246    
1247                            msg.append("userGroupId=");
1248                            msg.append(userGroupId);
1249    
1250                            msg.append(", groupId=");
1251                            msg.append(groupId);
1252    
1253                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1254    
1255                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
1256                    }
1257                    else {
1258                            return list.get(0);
1259                    }
1260            }
1261    
1262            public UserGroupGroupRole[] findByU_G_PrevAndNext(
1263                    UserGroupGroupRolePK userGroupGroupRolePK, long userGroupId,
1264                    long groupId, OrderByComparator orderByComparator)
1265                    throws NoSuchUserGroupGroupRoleException, SystemException {
1266                    UserGroupGroupRole userGroupGroupRole = findByPrimaryKey(userGroupGroupRolePK);
1267    
1268                    Session session = null;
1269    
1270                    try {
1271                            session = openSession();
1272    
1273                            UserGroupGroupRole[] array = new UserGroupGroupRoleImpl[3];
1274    
1275                            array[0] = getByU_G_PrevAndNext(session, userGroupGroupRole,
1276                                            userGroupId, groupId, orderByComparator, true);
1277    
1278                            array[1] = userGroupGroupRole;
1279    
1280                            array[2] = getByU_G_PrevAndNext(session, userGroupGroupRole,
1281                                            userGroupId, groupId, orderByComparator, false);
1282    
1283                            return array;
1284                    }
1285                    catch (Exception e) {
1286                            throw processException(e);
1287                    }
1288                    finally {
1289                            closeSession(session);
1290                    }
1291            }
1292    
1293            protected UserGroupGroupRole getByU_G_PrevAndNext(Session session,
1294                    UserGroupGroupRole userGroupGroupRole, long userGroupId, long groupId,
1295                    OrderByComparator orderByComparator, boolean previous) {
1296                    StringBundler query = null;
1297    
1298                    if (orderByComparator != null) {
1299                            query = new StringBundler(6 +
1300                                            (orderByComparator.getOrderByFields().length * 6));
1301                    }
1302                    else {
1303                            query = new StringBundler(3);
1304                    }
1305    
1306                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
1307    
1308                    query.append(_FINDER_COLUMN_U_G_USERGROUPID_2);
1309    
1310                    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1311    
1312                    if (orderByComparator != null) {
1313                            String[] orderByFields = orderByComparator.getOrderByFields();
1314    
1315                            if (orderByFields.length > 0) {
1316                                    query.append(WHERE_AND);
1317                            }
1318    
1319                            for (int i = 0; i < orderByFields.length; i++) {
1320                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1321                                    query.append(orderByFields[i]);
1322    
1323                                    if ((i + 1) < orderByFields.length) {
1324                                            if (orderByComparator.isAscending() ^ previous) {
1325                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1326                                            }
1327                                            else {
1328                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1329                                            }
1330                                    }
1331                                    else {
1332                                            if (orderByComparator.isAscending() ^ previous) {
1333                                                    query.append(WHERE_GREATER_THAN);
1334                                            }
1335                                            else {
1336                                                    query.append(WHERE_LESSER_THAN);
1337                                            }
1338                                    }
1339                            }
1340    
1341                            query.append(ORDER_BY_CLAUSE);
1342    
1343                            for (int i = 0; i < orderByFields.length; i++) {
1344                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1345                                    query.append(orderByFields[i]);
1346    
1347                                    if ((i + 1) < orderByFields.length) {
1348                                            if (orderByComparator.isAscending() ^ previous) {
1349                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1350                                            }
1351                                            else {
1352                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1353                                            }
1354                                    }
1355                                    else {
1356                                            if (orderByComparator.isAscending() ^ previous) {
1357                                                    query.append(ORDER_BY_ASC);
1358                                            }
1359                                            else {
1360                                                    query.append(ORDER_BY_DESC);
1361                                            }
1362                                    }
1363                            }
1364                    }
1365    
1366                    String sql = query.toString();
1367    
1368                    Query q = session.createQuery(sql);
1369    
1370                    q.setFirstResult(0);
1371                    q.setMaxResults(2);
1372    
1373                    QueryPos qPos = QueryPos.getInstance(q);
1374    
1375                    qPos.add(userGroupId);
1376    
1377                    qPos.add(groupId);
1378    
1379                    if (orderByComparator != null) {
1380                            Object[] values = orderByComparator.getOrderByValues(userGroupGroupRole);
1381    
1382                            for (Object value : values) {
1383                                    qPos.add(value);
1384                            }
1385                    }
1386    
1387                    List<UserGroupGroupRole> list = q.list();
1388    
1389                    if (list.size() == 2) {
1390                            return list.get(1);
1391                    }
1392                    else {
1393                            return null;
1394                    }
1395            }
1396    
1397            public List<UserGroupGroupRole> findByG_R(long groupId, long roleId)
1398                    throws SystemException {
1399                    return findByG_R(groupId, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1400                            null);
1401            }
1402    
1403            public List<UserGroupGroupRole> findByG_R(long groupId, long roleId,
1404                    int start, int end) throws SystemException {
1405                    return findByG_R(groupId, roleId, start, end, null);
1406            }
1407    
1408            public List<UserGroupGroupRole> findByG_R(long groupId, long roleId,
1409                    int start, int end, OrderByComparator orderByComparator)
1410                    throws SystemException {
1411                    Object[] finderArgs = new Object[] {
1412                                    groupId, roleId,
1413                                    
1414                                    String.valueOf(start), String.valueOf(end),
1415                                    String.valueOf(orderByComparator)
1416                            };
1417    
1418                    List<UserGroupGroupRole> list = (List<UserGroupGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_R,
1419                                    finderArgs, this);
1420    
1421                    if (list == null) {
1422                            Session session = null;
1423    
1424                            try {
1425                                    session = openSession();
1426    
1427                                    StringBundler query = null;
1428    
1429                                    if (orderByComparator != null) {
1430                                            query = new StringBundler(4 +
1431                                                            (orderByComparator.getOrderByFields().length * 3));
1432                                    }
1433                                    else {
1434                                            query = new StringBundler(3);
1435                                    }
1436    
1437                                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
1438    
1439                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
1440    
1441                                    query.append(_FINDER_COLUMN_G_R_ROLEID_2);
1442    
1443                                    if (orderByComparator != null) {
1444                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1445                                                    orderByComparator);
1446                                    }
1447    
1448                                    String sql = query.toString();
1449    
1450                                    Query q = session.createQuery(sql);
1451    
1452                                    QueryPos qPos = QueryPos.getInstance(q);
1453    
1454                                    qPos.add(groupId);
1455    
1456                                    qPos.add(roleId);
1457    
1458                                    list = (List<UserGroupGroupRole>)QueryUtil.list(q,
1459                                                    getDialect(), start, end);
1460                            }
1461                            catch (Exception e) {
1462                                    throw processException(e);
1463                            }
1464                            finally {
1465                                    if (list == null) {
1466                                            list = new ArrayList<UserGroupGroupRole>();
1467                                    }
1468    
1469                                    cacheResult(list);
1470    
1471                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_R, finderArgs,
1472                                            list);
1473    
1474                                    closeSession(session);
1475                            }
1476                    }
1477    
1478                    return list;
1479            }
1480    
1481            public UserGroupGroupRole findByG_R_First(long groupId, long roleId,
1482                    OrderByComparator orderByComparator)
1483                    throws NoSuchUserGroupGroupRoleException, SystemException {
1484                    List<UserGroupGroupRole> list = findByG_R(groupId, roleId, 0, 1,
1485                                    orderByComparator);
1486    
1487                    if (list.isEmpty()) {
1488                            StringBundler msg = new StringBundler(6);
1489    
1490                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1491    
1492                            msg.append("groupId=");
1493                            msg.append(groupId);
1494    
1495                            msg.append(", roleId=");
1496                            msg.append(roleId);
1497    
1498                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1499    
1500                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
1501                    }
1502                    else {
1503                            return list.get(0);
1504                    }
1505            }
1506    
1507            public UserGroupGroupRole findByG_R_Last(long groupId, long roleId,
1508                    OrderByComparator orderByComparator)
1509                    throws NoSuchUserGroupGroupRoleException, SystemException {
1510                    int count = countByG_R(groupId, roleId);
1511    
1512                    List<UserGroupGroupRole> list = findByG_R(groupId, roleId, count - 1,
1513                                    count, orderByComparator);
1514    
1515                    if (list.isEmpty()) {
1516                            StringBundler msg = new StringBundler(6);
1517    
1518                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1519    
1520                            msg.append("groupId=");
1521                            msg.append(groupId);
1522    
1523                            msg.append(", roleId=");
1524                            msg.append(roleId);
1525    
1526                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1527    
1528                            throw new NoSuchUserGroupGroupRoleException(msg.toString());
1529                    }
1530                    else {
1531                            return list.get(0);
1532                    }
1533            }
1534    
1535            public UserGroupGroupRole[] findByG_R_PrevAndNext(
1536                    UserGroupGroupRolePK userGroupGroupRolePK, long groupId, long roleId,
1537                    OrderByComparator orderByComparator)
1538                    throws NoSuchUserGroupGroupRoleException, SystemException {
1539                    UserGroupGroupRole userGroupGroupRole = findByPrimaryKey(userGroupGroupRolePK);
1540    
1541                    Session session = null;
1542    
1543                    try {
1544                            session = openSession();
1545    
1546                            UserGroupGroupRole[] array = new UserGroupGroupRoleImpl[3];
1547    
1548                            array[0] = getByG_R_PrevAndNext(session, userGroupGroupRole,
1549                                            groupId, roleId, orderByComparator, true);
1550    
1551                            array[1] = userGroupGroupRole;
1552    
1553                            array[2] = getByG_R_PrevAndNext(session, userGroupGroupRole,
1554                                            groupId, roleId, orderByComparator, false);
1555    
1556                            return array;
1557                    }
1558                    catch (Exception e) {
1559                            throw processException(e);
1560                    }
1561                    finally {
1562                            closeSession(session);
1563                    }
1564            }
1565    
1566            protected UserGroupGroupRole getByG_R_PrevAndNext(Session session,
1567                    UserGroupGroupRole userGroupGroupRole, long groupId, long roleId,
1568                    OrderByComparator orderByComparator, boolean previous) {
1569                    StringBundler query = null;
1570    
1571                    if (orderByComparator != null) {
1572                            query = new StringBundler(6 +
1573                                            (orderByComparator.getOrderByFields().length * 6));
1574                    }
1575                    else {
1576                            query = new StringBundler(3);
1577                    }
1578    
1579                    query.append(_SQL_SELECT_USERGROUPGROUPROLE_WHERE);
1580    
1581                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
1582    
1583                    query.append(_FINDER_COLUMN_G_R_ROLEID_2);
1584    
1585                    if (orderByComparator != null) {
1586                            String[] orderByFields = orderByComparator.getOrderByFields();
1587    
1588                            if (orderByFields.length > 0) {
1589                                    query.append(WHERE_AND);
1590                            }
1591    
1592                            for (int i = 0; i < orderByFields.length; i++) {
1593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1594                                    query.append(orderByFields[i]);
1595    
1596                                    if ((i + 1) < orderByFields.length) {
1597                                            if (orderByComparator.isAscending() ^ previous) {
1598                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1599                                            }
1600                                            else {
1601                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1602                                            }
1603                                    }
1604                                    else {
1605                                            if (orderByComparator.isAscending() ^ previous) {
1606                                                    query.append(WHERE_GREATER_THAN);
1607                                            }
1608                                            else {
1609                                                    query.append(WHERE_LESSER_THAN);
1610                                            }
1611                                    }
1612                            }
1613    
1614                            query.append(ORDER_BY_CLAUSE);
1615    
1616                            for (int i = 0; i < orderByFields.length; i++) {
1617                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1618                                    query.append(orderByFields[i]);
1619    
1620                                    if ((i + 1) < orderByFields.length) {
1621                                            if (orderByComparator.isAscending() ^ previous) {
1622                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1623                                            }
1624                                            else {
1625                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1626                                            }
1627                                    }
1628                                    else {
1629                                            if (orderByComparator.isAscending() ^ previous) {
1630                                                    query.append(ORDER_BY_ASC);
1631                                            }
1632                                            else {
1633                                                    query.append(ORDER_BY_DESC);
1634                                            }
1635                                    }
1636                            }
1637                    }
1638    
1639                    String sql = query.toString();
1640    
1641                    Query q = session.createQuery(sql);
1642    
1643                    q.setFirstResult(0);
1644                    q.setMaxResults(2);
1645    
1646                    QueryPos qPos = QueryPos.getInstance(q);
1647    
1648                    qPos.add(groupId);
1649    
1650                    qPos.add(roleId);
1651    
1652                    if (orderByComparator != null) {
1653                            Object[] values = orderByComparator.getOrderByValues(userGroupGroupRole);
1654    
1655                            for (Object value : values) {
1656                                    qPos.add(value);
1657                            }
1658                    }
1659    
1660                    List<UserGroupGroupRole> list = q.list();
1661    
1662                    if (list.size() == 2) {
1663                            return list.get(1);
1664                    }
1665                    else {
1666                            return null;
1667                    }
1668            }
1669    
1670            public List<UserGroupGroupRole> findAll() throws SystemException {
1671                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1672            }
1673    
1674            public List<UserGroupGroupRole> findAll(int start, int end)
1675                    throws SystemException {
1676                    return findAll(start, end, null);
1677            }
1678    
1679            public List<UserGroupGroupRole> findAll(int start, int end,
1680                    OrderByComparator orderByComparator) throws SystemException {
1681                    Object[] finderArgs = new Object[] {
1682                                    String.valueOf(start), String.valueOf(end),
1683                                    String.valueOf(orderByComparator)
1684                            };
1685    
1686                    List<UserGroupGroupRole> list = (List<UserGroupGroupRole>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1687                                    finderArgs, this);
1688    
1689                    if (list == null) {
1690                            Session session = null;
1691    
1692                            try {
1693                                    session = openSession();
1694    
1695                                    StringBundler query = null;
1696                                    String sql = null;
1697    
1698                                    if (orderByComparator != null) {
1699                                            query = new StringBundler(2 +
1700                                                            (orderByComparator.getOrderByFields().length * 3));
1701    
1702                                            query.append(_SQL_SELECT_USERGROUPGROUPROLE);
1703    
1704                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1705                                                    orderByComparator);
1706    
1707                                            sql = query.toString();
1708                                    }
1709                                    else {
1710                                            sql = _SQL_SELECT_USERGROUPGROUPROLE;
1711                                    }
1712    
1713                                    Query q = session.createQuery(sql);
1714    
1715                                    if (orderByComparator == null) {
1716                                            list = (List<UserGroupGroupRole>)QueryUtil.list(q,
1717                                                            getDialect(), start, end, false);
1718    
1719                                            Collections.sort(list);
1720                                    }
1721                                    else {
1722                                            list = (List<UserGroupGroupRole>)QueryUtil.list(q,
1723                                                            getDialect(), start, end);
1724                                    }
1725                            }
1726                            catch (Exception e) {
1727                                    throw processException(e);
1728                            }
1729                            finally {
1730                                    if (list == null) {
1731                                            list = new ArrayList<UserGroupGroupRole>();
1732                                    }
1733    
1734                                    cacheResult(list);
1735    
1736                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1737    
1738                                    closeSession(session);
1739                            }
1740                    }
1741    
1742                    return list;
1743            }
1744    
1745            public void removeByUserGroupId(long userGroupId) throws SystemException {
1746                    for (UserGroupGroupRole userGroupGroupRole : findByUserGroupId(
1747                                    userGroupId)) {
1748                            remove(userGroupGroupRole);
1749                    }
1750            }
1751    
1752            public void removeByGroupId(long groupId) throws SystemException {
1753                    for (UserGroupGroupRole userGroupGroupRole : findByGroupId(groupId)) {
1754                            remove(userGroupGroupRole);
1755                    }
1756            }
1757    
1758            public void removeByRoleId(long roleId) throws SystemException {
1759                    for (UserGroupGroupRole userGroupGroupRole : findByRoleId(roleId)) {
1760                            remove(userGroupGroupRole);
1761                    }
1762            }
1763    
1764            public void removeByU_G(long userGroupId, long groupId)
1765                    throws SystemException {
1766                    for (UserGroupGroupRole userGroupGroupRole : findByU_G(userGroupId,
1767                                    groupId)) {
1768                            remove(userGroupGroupRole);
1769                    }
1770            }
1771    
1772            public void removeByG_R(long groupId, long roleId)
1773                    throws SystemException {
1774                    for (UserGroupGroupRole userGroupGroupRole : findByG_R(groupId, roleId)) {
1775                            remove(userGroupGroupRole);
1776                    }
1777            }
1778    
1779            public void removeAll() throws SystemException {
1780                    for (UserGroupGroupRole userGroupGroupRole : findAll()) {
1781                            remove(userGroupGroupRole);
1782                    }
1783            }
1784    
1785            public int countByUserGroupId(long userGroupId) throws SystemException {
1786                    Object[] finderArgs = new Object[] { userGroupId };
1787    
1788                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERGROUPID,
1789                                    finderArgs, this);
1790    
1791                    if (count == null) {
1792                            Session session = null;
1793    
1794                            try {
1795                                    session = openSession();
1796    
1797                                    StringBundler query = new StringBundler(2);
1798    
1799                                    query.append(_SQL_COUNT_USERGROUPGROUPROLE_WHERE);
1800    
1801                                    query.append(_FINDER_COLUMN_USERGROUPID_USERGROUPID_2);
1802    
1803                                    String sql = query.toString();
1804    
1805                                    Query q = session.createQuery(sql);
1806    
1807                                    QueryPos qPos = QueryPos.getInstance(q);
1808    
1809                                    qPos.add(userGroupId);
1810    
1811                                    count = (Long)q.uniqueResult();
1812                            }
1813                            catch (Exception e) {
1814                                    throw processException(e);
1815                            }
1816                            finally {
1817                                    if (count == null) {
1818                                            count = Long.valueOf(0);
1819                                    }
1820    
1821                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERGROUPID,
1822                                            finderArgs, count);
1823    
1824                                    closeSession(session);
1825                            }
1826                    }
1827    
1828                    return count.intValue();
1829            }
1830    
1831            public int countByGroupId(long groupId) throws SystemException {
1832                    Object[] finderArgs = new Object[] { groupId };
1833    
1834                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1835                                    finderArgs, this);
1836    
1837                    if (count == null) {
1838                            Session session = null;
1839    
1840                            try {
1841                                    session = openSession();
1842    
1843                                    StringBundler query = new StringBundler(2);
1844    
1845                                    query.append(_SQL_COUNT_USERGROUPGROUPROLE_WHERE);
1846    
1847                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1848    
1849                                    String sql = query.toString();
1850    
1851                                    Query q = session.createQuery(sql);
1852    
1853                                    QueryPos qPos = QueryPos.getInstance(q);
1854    
1855                                    qPos.add(groupId);
1856    
1857                                    count = (Long)q.uniqueResult();
1858                            }
1859                            catch (Exception e) {
1860                                    throw processException(e);
1861                            }
1862                            finally {
1863                                    if (count == null) {
1864                                            count = Long.valueOf(0);
1865                                    }
1866    
1867                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1868                                            finderArgs, count);
1869    
1870                                    closeSession(session);
1871                            }
1872                    }
1873    
1874                    return count.intValue();
1875            }
1876    
1877            public int countByRoleId(long roleId) throws SystemException {
1878                    Object[] finderArgs = new Object[] { roleId };
1879    
1880                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1881                                    finderArgs, this);
1882    
1883                    if (count == null) {
1884                            Session session = null;
1885    
1886                            try {
1887                                    session = openSession();
1888    
1889                                    StringBundler query = new StringBundler(2);
1890    
1891                                    query.append(_SQL_COUNT_USERGROUPGROUPROLE_WHERE);
1892    
1893                                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1894    
1895                                    String sql = query.toString();
1896    
1897                                    Query q = session.createQuery(sql);
1898    
1899                                    QueryPos qPos = QueryPos.getInstance(q);
1900    
1901                                    qPos.add(roleId);
1902    
1903                                    count = (Long)q.uniqueResult();
1904                            }
1905                            catch (Exception e) {
1906                                    throw processException(e);
1907                            }
1908                            finally {
1909                                    if (count == null) {
1910                                            count = Long.valueOf(0);
1911                                    }
1912    
1913                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1914                                            finderArgs, count);
1915    
1916                                    closeSession(session);
1917                            }
1918                    }
1919    
1920                    return count.intValue();
1921            }
1922    
1923            public int countByU_G(long userGroupId, long groupId)
1924                    throws SystemException {
1925                    Object[] finderArgs = new Object[] { userGroupId, groupId };
1926    
1927                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_G,
1928                                    finderArgs, this);
1929    
1930                    if (count == null) {
1931                            Session session = null;
1932    
1933                            try {
1934                                    session = openSession();
1935    
1936                                    StringBundler query = new StringBundler(3);
1937    
1938                                    query.append(_SQL_COUNT_USERGROUPGROUPROLE_WHERE);
1939    
1940                                    query.append(_FINDER_COLUMN_U_G_USERGROUPID_2);
1941    
1942                                    query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1943    
1944                                    String sql = query.toString();
1945    
1946                                    Query q = session.createQuery(sql);
1947    
1948                                    QueryPos qPos = QueryPos.getInstance(q);
1949    
1950                                    qPos.add(userGroupId);
1951    
1952                                    qPos.add(groupId);
1953    
1954                                    count = (Long)q.uniqueResult();
1955                            }
1956                            catch (Exception e) {
1957                                    throw processException(e);
1958                            }
1959                            finally {
1960                                    if (count == null) {
1961                                            count = Long.valueOf(0);
1962                                    }
1963    
1964                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_G, finderArgs,
1965                                            count);
1966    
1967                                    closeSession(session);
1968                            }
1969                    }
1970    
1971                    return count.intValue();
1972            }
1973    
1974            public int countByG_R(long groupId, long roleId) throws SystemException {
1975                    Object[] finderArgs = new Object[] { groupId, roleId };
1976    
1977                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_R,
1978                                    finderArgs, this);
1979    
1980                    if (count == null) {
1981                            Session session = null;
1982    
1983                            try {
1984                                    session = openSession();
1985    
1986                                    StringBundler query = new StringBundler(3);
1987    
1988                                    query.append(_SQL_COUNT_USERGROUPGROUPROLE_WHERE);
1989    
1990                                    query.append(_FINDER_COLUMN_G_R_GROUPID_2);
1991    
1992                                    query.append(_FINDER_COLUMN_G_R_ROLEID_2);
1993    
1994                                    String sql = query.toString();
1995    
1996                                    Query q = session.createQuery(sql);
1997    
1998                                    QueryPos qPos = QueryPos.getInstance(q);
1999    
2000                                    qPos.add(groupId);
2001    
2002                                    qPos.add(roleId);
2003    
2004                                    count = (Long)q.uniqueResult();
2005                            }
2006                            catch (Exception e) {
2007                                    throw processException(e);
2008                            }
2009                            finally {
2010                                    if (count == null) {
2011                                            count = Long.valueOf(0);
2012                                    }
2013    
2014                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_R, finderArgs,
2015                                            count);
2016    
2017                                    closeSession(session);
2018                            }
2019                    }
2020    
2021                    return count.intValue();
2022            }
2023    
2024            public int countAll() throws SystemException {
2025                    Object[] finderArgs = new Object[0];
2026    
2027                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2028                                    finderArgs, this);
2029    
2030                    if (count == null) {
2031                            Session session = null;
2032    
2033                            try {
2034                                    session = openSession();
2035    
2036                                    Query q = session.createQuery(_SQL_COUNT_USERGROUPGROUPROLE);
2037    
2038                                    count = (Long)q.uniqueResult();
2039                            }
2040                            catch (Exception e) {
2041                                    throw processException(e);
2042                            }
2043                            finally {
2044                                    if (count == null) {
2045                                            count = Long.valueOf(0);
2046                                    }
2047    
2048                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2049                                            count);
2050    
2051                                    closeSession(session);
2052                            }
2053                    }
2054    
2055                    return count.intValue();
2056            }
2057    
2058            public void afterPropertiesSet() {
2059                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2060                                            com.liferay.portal.util.PropsUtil.get(
2061                                                    "value.object.listener.com.liferay.portal.model.UserGroupGroupRole")));
2062    
2063                    if (listenerClassNames.length > 0) {
2064                            try {
2065                                    List<ModelListener<UserGroupGroupRole>> listenersList = new ArrayList<ModelListener<UserGroupGroupRole>>();
2066    
2067                                    for (String listenerClassName : listenerClassNames) {
2068                                            listenersList.add((ModelListener<UserGroupGroupRole>)InstanceFactory.newInstance(
2069                                                            listenerClassName));
2070                                    }
2071    
2072                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2073                            }
2074                            catch (Exception e) {
2075                                    _log.error(e);
2076                            }
2077                    }
2078            }
2079    
2080            @BeanReference(type = AccountPersistence.class)
2081            protected AccountPersistence accountPersistence;
2082            @BeanReference(type = AddressPersistence.class)
2083            protected AddressPersistence addressPersistence;
2084            @BeanReference(type = BrowserTrackerPersistence.class)
2085            protected BrowserTrackerPersistence browserTrackerPersistence;
2086            @BeanReference(type = ClassNamePersistence.class)
2087            protected ClassNamePersistence classNamePersistence;
2088            @BeanReference(type = CompanyPersistence.class)
2089            protected CompanyPersistence companyPersistence;
2090            @BeanReference(type = ContactPersistence.class)
2091            protected ContactPersistence contactPersistence;
2092            @BeanReference(type = CountryPersistence.class)
2093            protected CountryPersistence countryPersistence;
2094            @BeanReference(type = EmailAddressPersistence.class)
2095            protected EmailAddressPersistence emailAddressPersistence;
2096            @BeanReference(type = GroupPersistence.class)
2097            protected GroupPersistence groupPersistence;
2098            @BeanReference(type = ImagePersistence.class)
2099            protected ImagePersistence imagePersistence;
2100            @BeanReference(type = LayoutPersistence.class)
2101            protected LayoutPersistence layoutPersistence;
2102            @BeanReference(type = LayoutPrototypePersistence.class)
2103            protected LayoutPrototypePersistence layoutPrototypePersistence;
2104            @BeanReference(type = LayoutSetPersistence.class)
2105            protected LayoutSetPersistence layoutSetPersistence;
2106            @BeanReference(type = LayoutSetPrototypePersistence.class)
2107            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2108            @BeanReference(type = ListTypePersistence.class)
2109            protected ListTypePersistence listTypePersistence;
2110            @BeanReference(type = LockPersistence.class)
2111            protected LockPersistence lockPersistence;
2112            @BeanReference(type = MembershipRequestPersistence.class)
2113            protected MembershipRequestPersistence membershipRequestPersistence;
2114            @BeanReference(type = OrganizationPersistence.class)
2115            protected OrganizationPersistence organizationPersistence;
2116            @BeanReference(type = OrgGroupPermissionPersistence.class)
2117            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2118            @BeanReference(type = OrgGroupRolePersistence.class)
2119            protected OrgGroupRolePersistence orgGroupRolePersistence;
2120            @BeanReference(type = OrgLaborPersistence.class)
2121            protected OrgLaborPersistence orgLaborPersistence;
2122            @BeanReference(type = PasswordPolicyPersistence.class)
2123            protected PasswordPolicyPersistence passwordPolicyPersistence;
2124            @BeanReference(type = PasswordPolicyRelPersistence.class)
2125            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2126            @BeanReference(type = PasswordTrackerPersistence.class)
2127            protected PasswordTrackerPersistence passwordTrackerPersistence;
2128            @BeanReference(type = PermissionPersistence.class)
2129            protected PermissionPersistence permissionPersistence;
2130            @BeanReference(type = PhonePersistence.class)
2131            protected PhonePersistence phonePersistence;
2132            @BeanReference(type = PluginSettingPersistence.class)
2133            protected PluginSettingPersistence pluginSettingPersistence;
2134            @BeanReference(type = PortletPersistence.class)
2135            protected PortletPersistence portletPersistence;
2136            @BeanReference(type = PortletItemPersistence.class)
2137            protected PortletItemPersistence portletItemPersistence;
2138            @BeanReference(type = PortletPreferencesPersistence.class)
2139            protected PortletPreferencesPersistence portletPreferencesPersistence;
2140            @BeanReference(type = RegionPersistence.class)
2141            protected RegionPersistence regionPersistence;
2142            @BeanReference(type = ReleasePersistence.class)
2143            protected ReleasePersistence releasePersistence;
2144            @BeanReference(type = ResourcePersistence.class)
2145            protected ResourcePersistence resourcePersistence;
2146            @BeanReference(type = ResourceActionPersistence.class)
2147            protected ResourceActionPersistence resourceActionPersistence;
2148            @BeanReference(type = ResourceCodePersistence.class)
2149            protected ResourceCodePersistence resourceCodePersistence;
2150            @BeanReference(type = ResourcePermissionPersistence.class)
2151            protected ResourcePermissionPersistence resourcePermissionPersistence;
2152            @BeanReference(type = RolePersistence.class)
2153            protected RolePersistence rolePersistence;
2154            @BeanReference(type = ServiceComponentPersistence.class)
2155            protected ServiceComponentPersistence serviceComponentPersistence;
2156            @BeanReference(type = ShardPersistence.class)
2157            protected ShardPersistence shardPersistence;
2158            @BeanReference(type = SubscriptionPersistence.class)
2159            protected SubscriptionPersistence subscriptionPersistence;
2160            @BeanReference(type = TicketPersistence.class)
2161            protected TicketPersistence ticketPersistence;
2162            @BeanReference(type = TeamPersistence.class)
2163            protected TeamPersistence teamPersistence;
2164            @BeanReference(type = UserPersistence.class)
2165            protected UserPersistence userPersistence;
2166            @BeanReference(type = UserGroupPersistence.class)
2167            protected UserGroupPersistence userGroupPersistence;
2168            @BeanReference(type = UserGroupGroupRolePersistence.class)
2169            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2170            @BeanReference(type = UserGroupRolePersistence.class)
2171            protected UserGroupRolePersistence userGroupRolePersistence;
2172            @BeanReference(type = UserIdMapperPersistence.class)
2173            protected UserIdMapperPersistence userIdMapperPersistence;
2174            @BeanReference(type = UserTrackerPersistence.class)
2175            protected UserTrackerPersistence userTrackerPersistence;
2176            @BeanReference(type = UserTrackerPathPersistence.class)
2177            protected UserTrackerPathPersistence userTrackerPathPersistence;
2178            @BeanReference(type = WebDAVPropsPersistence.class)
2179            protected WebDAVPropsPersistence webDAVPropsPersistence;
2180            @BeanReference(type = WebsitePersistence.class)
2181            protected WebsitePersistence websitePersistence;
2182            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2183            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2184            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2185            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2186            private static final String _SQL_SELECT_USERGROUPGROUPROLE = "SELECT userGroupGroupRole FROM UserGroupGroupRole userGroupGroupRole";
2187            private static final String _SQL_SELECT_USERGROUPGROUPROLE_WHERE = "SELECT userGroupGroupRole FROM UserGroupGroupRole userGroupGroupRole WHERE ";
2188            private static final String _SQL_COUNT_USERGROUPGROUPROLE = "SELECT COUNT(userGroupGroupRole) FROM UserGroupGroupRole userGroupGroupRole";
2189            private static final String _SQL_COUNT_USERGROUPGROUPROLE_WHERE = "SELECT COUNT(userGroupGroupRole) FROM UserGroupGroupRole userGroupGroupRole WHERE ";
2190            private static final String _FINDER_COLUMN_USERGROUPID_USERGROUPID_2 = "userGroupGroupRole.id.userGroupId = ?";
2191            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "userGroupGroupRole.id.groupId = ?";
2192            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "userGroupGroupRole.id.roleId = ?";
2193            private static final String _FINDER_COLUMN_U_G_USERGROUPID_2 = "userGroupGroupRole.id.userGroupId = ? AND ";
2194            private static final String _FINDER_COLUMN_U_G_GROUPID_2 = "userGroupGroupRole.id.groupId = ?";
2195            private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "userGroupGroupRole.id.groupId = ? AND ";
2196            private static final String _FINDER_COLUMN_G_R_ROLEID_2 = "userGroupGroupRole.id.roleId = ?";
2197            private static final String _ORDER_BY_ENTITY_ALIAS = "userGroupGroupRole.";
2198            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroupGroupRole exists with the primary key ";
2199            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroupGroupRole exists with the key {";
2200            private static Log _log = LogFactoryUtil.getLog(UserGroupGroupRolePersistenceImpl.class);
2201    }