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