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.NoSuchUserGroupException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.CacheModel;
046    import com.liferay.portal.model.ModelListener;
047    import com.liferay.portal.model.UserGroup;
048    import com.liferay.portal.model.impl.UserGroupImpl;
049    import com.liferay.portal.model.impl.UserGroupModelImpl;
050    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
051    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
052    
053    import java.io.Serializable;
054    
055    import java.util.ArrayList;
056    import java.util.Collections;
057    import java.util.List;
058    import java.util.Set;
059    
060    /**
061     * The persistence implementation for the user group service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see UserGroupPersistence
069     * @see UserGroupUtil
070     * @generated
071     */
072    public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
073            implements UserGroupPersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * Never modify or reference this class directly. Always use {@link UserGroupUtil} to access the user group persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
085                    new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
086                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
088                            new String[] {
089                                    Long.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
095                    new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
096                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
098                            new String[] { Long.class.getName() },
099                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK);
100            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
101                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
103                            new String[] { Long.class.getName() });
104            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
105                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
107                            new String[] {
108                                    Long.class.getName(), Long.class.getName(),
109                                    
110                            "java.lang.Integer", "java.lang.Integer",
111                                    "com.liferay.portal.kernel.util.OrderByComparator"
112                            });
113            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
114                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
116                            new String[] { Long.class.getName(), Long.class.getName() },
117                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK |
118                            UserGroupModelImpl.PARENTUSERGROUPID_COLUMN_BITMASK);
119            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
120                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
122                            new String[] { Long.class.getName(), Long.class.getName() });
123            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
124                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
125                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
126                            new String[] { Long.class.getName(), String.class.getName() },
127                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK |
128                            UserGroupModelImpl.NAME_COLUMN_BITMASK);
129            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
130                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
132                            new String[] { Long.class.getName(), String.class.getName() });
133            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
134                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
135                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
136            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
137                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
139            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
140                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
141                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
142    
143            /**
144             * Caches the user group in the entity cache if it is enabled.
145             *
146             * @param userGroup the user group
147             */
148            public void cacheResult(UserGroup userGroup) {
149                    EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
150                            UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
151    
152                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
153                            new Object[] {
154                                    Long.valueOf(userGroup.getCompanyId()),
155                                    
156                            userGroup.getName()
157                            }, userGroup);
158    
159                    userGroup.resetOriginalValues();
160            }
161    
162            /**
163             * Caches the user groups in the entity cache if it is enabled.
164             *
165             * @param userGroups the user groups
166             */
167            public void cacheResult(List<UserGroup> userGroups) {
168                    for (UserGroup userGroup : userGroups) {
169                            if (EntityCacheUtil.getResult(
170                                                    UserGroupModelImpl.ENTITY_CACHE_ENABLED,
171                                                    UserGroupImpl.class, userGroup.getPrimaryKey()) == null) {
172                                    cacheResult(userGroup);
173                            }
174                            else {
175                                    userGroup.resetOriginalValues();
176                            }
177                    }
178            }
179    
180            /**
181             * Clears the cache for all user groups.
182             *
183             * <p>
184             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
185             * </p>
186             */
187            @Override
188            public void clearCache() {
189                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
190                            CacheRegistryUtil.clear(UserGroupImpl.class.getName());
191                    }
192    
193                    EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
194    
195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
196                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
197                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
198            }
199    
200            /**
201             * Clears the cache for the user group.
202             *
203             * <p>
204             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
205             * </p>
206             */
207            @Override
208            public void clearCache(UserGroup userGroup) {
209                    EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
210                            UserGroupImpl.class, userGroup.getPrimaryKey());
211    
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
214    
215                    clearUniqueFindersCache(userGroup);
216            }
217    
218            @Override
219            public void clearCache(List<UserGroup> userGroups) {
220                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
221                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
222    
223                    for (UserGroup userGroup : userGroups) {
224                            EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
225                                    UserGroupImpl.class, userGroup.getPrimaryKey());
226    
227                            clearUniqueFindersCache(userGroup);
228                    }
229            }
230    
231            protected void cacheUniqueFindersCache(UserGroup userGroup) {
232                    if (userGroup.isNew()) {
233                            Object[] args = new Object[] {
234                                            Long.valueOf(userGroup.getCompanyId()),
235                                            
236                                            userGroup.getName()
237                                    };
238    
239                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
240                                    Long.valueOf(1));
241                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, userGroup);
242                    }
243                    else {
244                            UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
245    
246                            if ((userGroupModelImpl.getColumnBitmask() &
247                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
248                                    Object[] args = new Object[] {
249                                                    Long.valueOf(userGroup.getCompanyId()),
250                                                    
251                                                    userGroup.getName()
252                                            };
253    
254                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
255                                            Long.valueOf(1));
256                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
257                                            userGroup);
258                            }
259                    }
260            }
261    
262            protected void clearUniqueFindersCache(UserGroup userGroup) {
263                    UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
264    
265                    Object[] args = new Object[] {
266                                    Long.valueOf(userGroup.getCompanyId()),
267                                    
268                                    userGroup.getName()
269                            };
270    
271                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
272                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
273    
274                    if ((userGroupModelImpl.getColumnBitmask() &
275                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
276                            args = new Object[] {
277                                            Long.valueOf(userGroupModelImpl.getOriginalCompanyId()),
278                                            
279                                            userGroupModelImpl.getOriginalName()
280                                    };
281    
282                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
283                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
284                    }
285            }
286    
287            /**
288             * Creates a new user group with the primary key. Does not add the user group to the database.
289             *
290             * @param userGroupId the primary key for the new user group
291             * @return the new user group
292             */
293            public UserGroup create(long userGroupId) {
294                    UserGroup userGroup = new UserGroupImpl();
295    
296                    userGroup.setNew(true);
297                    userGroup.setPrimaryKey(userGroupId);
298    
299                    return userGroup;
300            }
301    
302            /**
303             * Removes the user group with the primary key from the database. Also notifies the appropriate model listeners.
304             *
305             * @param userGroupId the primary key of the user group
306             * @return the user group that was removed
307             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            public UserGroup remove(long userGroupId)
311                    throws NoSuchUserGroupException, SystemException {
312                    return remove(Long.valueOf(userGroupId));
313            }
314    
315            /**
316             * Removes the user group with the primary key from the database. Also notifies the appropriate model listeners.
317             *
318             * @param primaryKey the primary key of the user group
319             * @return the user group that was removed
320             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
321             * @throws SystemException if a system exception occurred
322             */
323            @Override
324            public UserGroup remove(Serializable primaryKey)
325                    throws NoSuchUserGroupException, SystemException {
326                    Session session = null;
327    
328                    try {
329                            session = openSession();
330    
331                            UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
332                                            primaryKey);
333    
334                            if (userGroup == null) {
335                                    if (_log.isWarnEnabled()) {
336                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
337                                    }
338    
339                                    throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
340                                            primaryKey);
341                            }
342    
343                            return remove(userGroup);
344                    }
345                    catch (NoSuchUserGroupException nsee) {
346                            throw nsee;
347                    }
348                    catch (Exception e) {
349                            throw processException(e);
350                    }
351                    finally {
352                            closeSession(session);
353                    }
354            }
355    
356            @Override
357            protected UserGroup removeImpl(UserGroup userGroup)
358                    throws SystemException {
359                    userGroup = toUnwrappedModel(userGroup);
360    
361                    try {
362                            clearGroups.clear(userGroup.getPrimaryKey());
363                    }
364                    catch (Exception e) {
365                            throw processException(e);
366                    }
367                    finally {
368                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
369                    }
370    
371                    try {
372                            clearTeams.clear(userGroup.getPrimaryKey());
373                    }
374                    catch (Exception e) {
375                            throw processException(e);
376                    }
377                    finally {
378                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
379                    }
380    
381                    try {
382                            clearUsers.clear(userGroup.getPrimaryKey());
383                    }
384                    catch (Exception e) {
385                            throw processException(e);
386                    }
387                    finally {
388                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
389                    }
390    
391                    Session session = null;
392    
393                    try {
394                            session = openSession();
395    
396                            BatchSessionUtil.delete(session, userGroup);
397                    }
398                    catch (Exception e) {
399                            throw processException(e);
400                    }
401                    finally {
402                            closeSession(session);
403                    }
404    
405                    clearCache(userGroup);
406    
407                    return userGroup;
408            }
409    
410            @Override
411            public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup,
412                    boolean merge) throws SystemException {
413                    userGroup = toUnwrappedModel(userGroup);
414    
415                    boolean isNew = userGroup.isNew();
416    
417                    UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
418    
419                    Session session = null;
420    
421                    try {
422                            session = openSession();
423    
424                            BatchSessionUtil.update(session, userGroup, merge);
425    
426                            userGroup.setNew(false);
427                    }
428                    catch (Exception e) {
429                            throw processException(e);
430                    }
431                    finally {
432                            closeSession(session);
433                    }
434    
435                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
436    
437                    if (isNew || !UserGroupModelImpl.COLUMN_BITMASK_ENABLED) {
438                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
439                    }
440    
441                    else {
442                            if ((userGroupModelImpl.getColumnBitmask() &
443                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
444                                    Object[] args = new Object[] {
445                                                    Long.valueOf(userGroupModelImpl.getOriginalCompanyId())
446                                            };
447    
448                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
449                                            args);
450                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
451                                            args);
452    
453                                    args = new Object[] {
454                                                    Long.valueOf(userGroupModelImpl.getCompanyId())
455                                            };
456    
457                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
458                                            args);
459                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
460                                            args);
461                            }
462    
463                            if ((userGroupModelImpl.getColumnBitmask() &
464                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
465                                    Object[] args = new Object[] {
466                                                    Long.valueOf(userGroupModelImpl.getOriginalCompanyId()),
467                                                    Long.valueOf(userGroupModelImpl.getOriginalParentUserGroupId())
468                                            };
469    
470                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
471                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
472                                            args);
473    
474                                    args = new Object[] {
475                                                    Long.valueOf(userGroupModelImpl.getCompanyId()),
476                                                    Long.valueOf(userGroupModelImpl.getParentUserGroupId())
477                                            };
478    
479                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
480                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
481                                            args);
482                            }
483                    }
484    
485                    EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
486                            UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
487    
488                    clearUniqueFindersCache(userGroup);
489                    cacheUniqueFindersCache(userGroup);
490    
491                    return userGroup;
492            }
493    
494            protected UserGroup toUnwrappedModel(UserGroup userGroup) {
495                    if (userGroup instanceof UserGroupImpl) {
496                            return userGroup;
497                    }
498    
499                    UserGroupImpl userGroupImpl = new UserGroupImpl();
500    
501                    userGroupImpl.setNew(userGroup.isNew());
502                    userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
503    
504                    userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
505                    userGroupImpl.setCompanyId(userGroup.getCompanyId());
506                    userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
507                    userGroupImpl.setName(userGroup.getName());
508                    userGroupImpl.setDescription(userGroup.getDescription());
509                    userGroupImpl.setAddedByLDAPImport(userGroup.isAddedByLDAPImport());
510    
511                    return userGroupImpl;
512            }
513    
514            /**
515             * Returns the user group with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
516             *
517             * @param primaryKey the primary key of the user group
518             * @return the user group
519             * @throws com.liferay.portal.NoSuchModelException if a user group with the primary key could not be found
520             * @throws SystemException if a system exception occurred
521             */
522            @Override
523            public UserGroup findByPrimaryKey(Serializable primaryKey)
524                    throws NoSuchModelException, SystemException {
525                    return findByPrimaryKey(((Long)primaryKey).longValue());
526            }
527    
528            /**
529             * Returns the user group with the primary key or throws a {@link com.liferay.portal.NoSuchUserGroupException} if it could not be found.
530             *
531             * @param userGroupId the primary key of the user group
532             * @return the user group
533             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
534             * @throws SystemException if a system exception occurred
535             */
536            public UserGroup findByPrimaryKey(long userGroupId)
537                    throws NoSuchUserGroupException, SystemException {
538                    UserGroup userGroup = fetchByPrimaryKey(userGroupId);
539    
540                    if (userGroup == null) {
541                            if (_log.isWarnEnabled()) {
542                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupId);
543                            }
544    
545                            throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
546                                    userGroupId);
547                    }
548    
549                    return userGroup;
550            }
551    
552            /**
553             * Returns the user group with the primary key or returns <code>null</code> if it could not be found.
554             *
555             * @param primaryKey the primary key of the user group
556             * @return the user group, or <code>null</code> if a user group with the primary key could not be found
557             * @throws SystemException if a system exception occurred
558             */
559            @Override
560            public UserGroup fetchByPrimaryKey(Serializable primaryKey)
561                    throws SystemException {
562                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
563            }
564    
565            /**
566             * Returns the user group with the primary key or returns <code>null</code> if it could not be found.
567             *
568             * @param userGroupId the primary key of the user group
569             * @return the user group, or <code>null</code> if a user group with the primary key could not be found
570             * @throws SystemException if a system exception occurred
571             */
572            public UserGroup fetchByPrimaryKey(long userGroupId)
573                    throws SystemException {
574                    UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
575                                    UserGroupImpl.class, userGroupId);
576    
577                    if (userGroup == _nullUserGroup) {
578                            return null;
579                    }
580    
581                    if (userGroup == null) {
582                            Session session = null;
583    
584                            boolean hasException = false;
585    
586                            try {
587                                    session = openSession();
588    
589                                    userGroup = (UserGroup)session.get(UserGroupImpl.class,
590                                                    Long.valueOf(userGroupId));
591                            }
592                            catch (Exception e) {
593                                    hasException = true;
594    
595                                    throw processException(e);
596                            }
597                            finally {
598                                    if (userGroup != null) {
599                                            cacheResult(userGroup);
600                                    }
601                                    else if (!hasException) {
602                                            EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
603                                                    UserGroupImpl.class, userGroupId, _nullUserGroup);
604                                    }
605    
606                                    closeSession(session);
607                            }
608                    }
609    
610                    return userGroup;
611            }
612    
613            /**
614             * Returns all the user groups where companyId = &#63;.
615             *
616             * @param companyId the company ID
617             * @return the matching user groups
618             * @throws SystemException if a system exception occurred
619             */
620            public List<UserGroup> findByCompanyId(long companyId)
621                    throws SystemException {
622                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
623                            null);
624            }
625    
626            /**
627             * Returns a range of all the user groups where companyId = &#63;.
628             *
629             * <p>
630             * 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.
631             * </p>
632             *
633             * @param companyId the company ID
634             * @param start the lower bound of the range of user groups
635             * @param end the upper bound of the range of user groups (not inclusive)
636             * @return the range of matching user groups
637             * @throws SystemException if a system exception occurred
638             */
639            public List<UserGroup> findByCompanyId(long companyId, int start, int end)
640                    throws SystemException {
641                    return findByCompanyId(companyId, start, end, null);
642            }
643    
644            /**
645             * Returns an ordered range of all the user groups where companyId = &#63;.
646             *
647             * <p>
648             * 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.
649             * </p>
650             *
651             * @param companyId the company ID
652             * @param start the lower bound of the range of user groups
653             * @param end the upper bound of the range of user groups (not inclusive)
654             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
655             * @return the ordered range of matching user groups
656             * @throws SystemException if a system exception occurred
657             */
658            public List<UserGroup> findByCompanyId(long companyId, int start, int end,
659                    OrderByComparator orderByComparator) throws SystemException {
660                    FinderPath finderPath = null;
661                    Object[] finderArgs = null;
662    
663                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
664                                    (orderByComparator == null)) {
665                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
666                            finderArgs = new Object[] { companyId };
667                    }
668                    else {
669                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
670                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
671                    }
672    
673                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
674                                    finderArgs, this);
675    
676                    if ((list != null) && !list.isEmpty()) {
677                            for (UserGroup userGroup : list) {
678                                    if ((companyId != userGroup.getCompanyId())) {
679                                            list = null;
680    
681                                            break;
682                                    }
683                            }
684                    }
685    
686                    if (list == null) {
687                            StringBundler query = null;
688    
689                            if (orderByComparator != null) {
690                                    query = new StringBundler(3 +
691                                                    (orderByComparator.getOrderByFields().length * 3));
692                            }
693                            else {
694                                    query = new StringBundler(3);
695                            }
696    
697                            query.append(_SQL_SELECT_USERGROUP_WHERE);
698    
699                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
700    
701                            if (orderByComparator != null) {
702                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
703                                            orderByComparator);
704                            }
705    
706                            else {
707                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
708                            }
709    
710                            String sql = query.toString();
711    
712                            Session session = null;
713    
714                            try {
715                                    session = openSession();
716    
717                                    Query q = session.createQuery(sql);
718    
719                                    QueryPos qPos = QueryPos.getInstance(q);
720    
721                                    qPos.add(companyId);
722    
723                                    list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
724                                                    end);
725                            }
726                            catch (Exception e) {
727                                    throw processException(e);
728                            }
729                            finally {
730                                    if (list == null) {
731                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
732                                    }
733                                    else {
734                                            cacheResult(list);
735    
736                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
737                                    }
738    
739                                    closeSession(session);
740                            }
741                    }
742    
743                    return list;
744            }
745    
746            /**
747             * Returns the first user group in the ordered set where companyId = &#63;.
748             *
749             * @param companyId the company ID
750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
751             * @return the first matching user group
752             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
753             * @throws SystemException if a system exception occurred
754             */
755            public UserGroup findByCompanyId_First(long companyId,
756                    OrderByComparator orderByComparator)
757                    throws NoSuchUserGroupException, SystemException {
758                    UserGroup userGroup = fetchByCompanyId_First(companyId,
759                                    orderByComparator);
760    
761                    if (userGroup != null) {
762                            return userGroup;
763                    }
764    
765                    StringBundler msg = new StringBundler(4);
766    
767                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
768    
769                    msg.append("companyId=");
770                    msg.append(companyId);
771    
772                    msg.append(StringPool.CLOSE_CURLY_BRACE);
773    
774                    throw new NoSuchUserGroupException(msg.toString());
775            }
776    
777            /**
778             * Returns the first user group in the ordered set where companyId = &#63;.
779             *
780             * @param companyId the company ID
781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
782             * @return the first matching user group, or <code>null</code> if a matching user group could not be found
783             * @throws SystemException if a system exception occurred
784             */
785            public UserGroup fetchByCompanyId_First(long companyId,
786                    OrderByComparator orderByComparator) throws SystemException {
787                    List<UserGroup> list = findByCompanyId(companyId, 0, 1,
788                                    orderByComparator);
789    
790                    if (!list.isEmpty()) {
791                            return list.get(0);
792                    }
793    
794                    return null;
795            }
796    
797            /**
798             * Returns the last user group in the ordered set where companyId = &#63;.
799             *
800             * @param companyId the company ID
801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
802             * @return the last matching user group
803             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
804             * @throws SystemException if a system exception occurred
805             */
806            public UserGroup findByCompanyId_Last(long companyId,
807                    OrderByComparator orderByComparator)
808                    throws NoSuchUserGroupException, SystemException {
809                    UserGroup userGroup = fetchByCompanyId_Last(companyId, orderByComparator);
810    
811                    if (userGroup != null) {
812                            return userGroup;
813                    }
814    
815                    StringBundler msg = new StringBundler(4);
816    
817                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
818    
819                    msg.append("companyId=");
820                    msg.append(companyId);
821    
822                    msg.append(StringPool.CLOSE_CURLY_BRACE);
823    
824                    throw new NoSuchUserGroupException(msg.toString());
825            }
826    
827            /**
828             * Returns the last user group in the ordered set where companyId = &#63;.
829             *
830             * @param companyId the company ID
831             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
832             * @return the last matching user group, or <code>null</code> if a matching user group could not be found
833             * @throws SystemException if a system exception occurred
834             */
835            public UserGroup fetchByCompanyId_Last(long companyId,
836                    OrderByComparator orderByComparator) throws SystemException {
837                    int count = countByCompanyId(companyId);
838    
839                    List<UserGroup> list = findByCompanyId(companyId, count - 1, count,
840                                    orderByComparator);
841    
842                    if (!list.isEmpty()) {
843                            return list.get(0);
844                    }
845    
846                    return null;
847            }
848    
849            /**
850             * Returns the user groups before and after the current user group in the ordered set where companyId = &#63;.
851             *
852             * @param userGroupId the primary key of the current user group
853             * @param companyId the company ID
854             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
855             * @return the previous, current, and next user group
856             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
857             * @throws SystemException if a system exception occurred
858             */
859            public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
860                    long companyId, OrderByComparator orderByComparator)
861                    throws NoSuchUserGroupException, SystemException {
862                    UserGroup userGroup = findByPrimaryKey(userGroupId);
863    
864                    Session session = null;
865    
866                    try {
867                            session = openSession();
868    
869                            UserGroup[] array = new UserGroupImpl[3];
870    
871                            array[0] = getByCompanyId_PrevAndNext(session, userGroup,
872                                            companyId, orderByComparator, true);
873    
874                            array[1] = userGroup;
875    
876                            array[2] = getByCompanyId_PrevAndNext(session, userGroup,
877                                            companyId, orderByComparator, false);
878    
879                            return array;
880                    }
881                    catch (Exception e) {
882                            throw processException(e);
883                    }
884                    finally {
885                            closeSession(session);
886                    }
887            }
888    
889            protected UserGroup getByCompanyId_PrevAndNext(Session session,
890                    UserGroup userGroup, long companyId,
891                    OrderByComparator orderByComparator, boolean previous) {
892                    StringBundler query = null;
893    
894                    if (orderByComparator != null) {
895                            query = new StringBundler(6 +
896                                            (orderByComparator.getOrderByFields().length * 6));
897                    }
898                    else {
899                            query = new StringBundler(3);
900                    }
901    
902                    query.append(_SQL_SELECT_USERGROUP_WHERE);
903    
904                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
905    
906                    if (orderByComparator != null) {
907                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
908    
909                            if (orderByConditionFields.length > 0) {
910                                    query.append(WHERE_AND);
911                            }
912    
913                            for (int i = 0; i < orderByConditionFields.length; i++) {
914                                    query.append(_ORDER_BY_ENTITY_ALIAS);
915                                    query.append(orderByConditionFields[i]);
916    
917                                    if ((i + 1) < orderByConditionFields.length) {
918                                            if (orderByComparator.isAscending() ^ previous) {
919                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
920                                            }
921                                            else {
922                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
923                                            }
924                                    }
925                                    else {
926                                            if (orderByComparator.isAscending() ^ previous) {
927                                                    query.append(WHERE_GREATER_THAN);
928                                            }
929                                            else {
930                                                    query.append(WHERE_LESSER_THAN);
931                                            }
932                                    }
933                            }
934    
935                            query.append(ORDER_BY_CLAUSE);
936    
937                            String[] orderByFields = orderByComparator.getOrderByFields();
938    
939                            for (int i = 0; i < orderByFields.length; i++) {
940                                    query.append(_ORDER_BY_ENTITY_ALIAS);
941                                    query.append(orderByFields[i]);
942    
943                                    if ((i + 1) < orderByFields.length) {
944                                            if (orderByComparator.isAscending() ^ previous) {
945                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
946                                            }
947                                            else {
948                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
949                                            }
950                                    }
951                                    else {
952                                            if (orderByComparator.isAscending() ^ previous) {
953                                                    query.append(ORDER_BY_ASC);
954                                            }
955                                            else {
956                                                    query.append(ORDER_BY_DESC);
957                                            }
958                                    }
959                            }
960                    }
961    
962                    else {
963                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
964                    }
965    
966                    String sql = query.toString();
967    
968                    Query q = session.createQuery(sql);
969    
970                    q.setFirstResult(0);
971                    q.setMaxResults(2);
972    
973                    QueryPos qPos = QueryPos.getInstance(q);
974    
975                    qPos.add(companyId);
976    
977                    if (orderByComparator != null) {
978                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
979    
980                            for (Object value : values) {
981                                    qPos.add(value);
982                            }
983                    }
984    
985                    List<UserGroup> list = q.list();
986    
987                    if (list.size() == 2) {
988                            return list.get(1);
989                    }
990                    else {
991                            return null;
992                    }
993            }
994    
995            /**
996             * Returns all the user groups that the user has permission to view where companyId = &#63;.
997             *
998             * @param companyId the company ID
999             * @return the matching user groups that the user has permission to view
1000             * @throws SystemException if a system exception occurred
1001             */
1002            public List<UserGroup> filterFindByCompanyId(long companyId)
1003                    throws SystemException {
1004                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
1005                            QueryUtil.ALL_POS, null);
1006            }
1007    
1008            /**
1009             * Returns a range of all the user groups that the user has permission to view where companyId = &#63;.
1010             *
1011             * <p>
1012             * 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.
1013             * </p>
1014             *
1015             * @param companyId the company ID
1016             * @param start the lower bound of the range of user groups
1017             * @param end the upper bound of the range of user groups (not inclusive)
1018             * @return the range of matching user groups that the user has permission to view
1019             * @throws SystemException if a system exception occurred
1020             */
1021            public List<UserGroup> filterFindByCompanyId(long companyId, int start,
1022                    int end) throws SystemException {
1023                    return filterFindByCompanyId(companyId, start, end, null);
1024            }
1025    
1026            /**
1027             * Returns an ordered range of all the user groups that the user has permissions to view where companyId = &#63;.
1028             *
1029             * <p>
1030             * 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.
1031             * </p>
1032             *
1033             * @param companyId the company ID
1034             * @param start the lower bound of the range of user groups
1035             * @param end the upper bound of the range of user groups (not inclusive)
1036             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1037             * @return the ordered range of matching user groups that the user has permission to view
1038             * @throws SystemException if a system exception occurred
1039             */
1040            public List<UserGroup> filterFindByCompanyId(long companyId, int start,
1041                    int end, OrderByComparator orderByComparator) throws SystemException {
1042                    if (!InlineSQLHelperUtil.isEnabled()) {
1043                            return findByCompanyId(companyId, start, end, orderByComparator);
1044                    }
1045    
1046                    StringBundler query = null;
1047    
1048                    if (orderByComparator != null) {
1049                            query = new StringBundler(3 +
1050                                            (orderByComparator.getOrderByFields().length * 3));
1051                    }
1052                    else {
1053                            query = new StringBundler(3);
1054                    }
1055    
1056                    if (getDB().isSupportsInlineDistinct()) {
1057                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
1058                    }
1059                    else {
1060                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
1061                    }
1062    
1063                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1064    
1065                    if (!getDB().isSupportsInlineDistinct()) {
1066                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
1067                    }
1068    
1069                    if (orderByComparator != null) {
1070                            if (getDB().isSupportsInlineDistinct()) {
1071                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1072                                            orderByComparator);
1073                            }
1074                            else {
1075                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1076                                            orderByComparator);
1077                            }
1078                    }
1079    
1080                    else {
1081                            if (getDB().isSupportsInlineDistinct()) {
1082                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1083                            }
1084                            else {
1085                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
1086                            }
1087                    }
1088    
1089                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1090                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1091    
1092                    Session session = null;
1093    
1094                    try {
1095                            session = openSession();
1096    
1097                            SQLQuery q = session.createSQLQuery(sql);
1098    
1099                            if (getDB().isSupportsInlineDistinct()) {
1100                                    q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
1101                            }
1102                            else {
1103                                    q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
1104                            }
1105    
1106                            QueryPos qPos = QueryPos.getInstance(q);
1107    
1108                            qPos.add(companyId);
1109    
1110                            return (List<UserGroup>)QueryUtil.list(q, getDialect(), start, end);
1111                    }
1112                    catch (Exception e) {
1113                            throw processException(e);
1114                    }
1115                    finally {
1116                            closeSession(session);
1117                    }
1118            }
1119    
1120            /**
1121             * Returns the user groups before and after the current user group in the ordered set of user groups that the user has permission to view where companyId = &#63;.
1122             *
1123             * @param userGroupId the primary key of the current user group
1124             * @param companyId the company ID
1125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1126             * @return the previous, current, and next user group
1127             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
1128             * @throws SystemException if a system exception occurred
1129             */
1130            public UserGroup[] filterFindByCompanyId_PrevAndNext(long userGroupId,
1131                    long companyId, OrderByComparator orderByComparator)
1132                    throws NoSuchUserGroupException, SystemException {
1133                    if (!InlineSQLHelperUtil.isEnabled()) {
1134                            return findByCompanyId_PrevAndNext(userGroupId, companyId,
1135                                    orderByComparator);
1136                    }
1137    
1138                    UserGroup userGroup = findByPrimaryKey(userGroupId);
1139    
1140                    Session session = null;
1141    
1142                    try {
1143                            session = openSession();
1144    
1145                            UserGroup[] array = new UserGroupImpl[3];
1146    
1147                            array[0] = filterGetByCompanyId_PrevAndNext(session, userGroup,
1148                                            companyId, orderByComparator, true);
1149    
1150                            array[1] = userGroup;
1151    
1152                            array[2] = filterGetByCompanyId_PrevAndNext(session, userGroup,
1153                                            companyId, orderByComparator, false);
1154    
1155                            return array;
1156                    }
1157                    catch (Exception e) {
1158                            throw processException(e);
1159                    }
1160                    finally {
1161                            closeSession(session);
1162                    }
1163            }
1164    
1165            protected UserGroup filterGetByCompanyId_PrevAndNext(Session session,
1166                    UserGroup userGroup, long companyId,
1167                    OrderByComparator orderByComparator, boolean previous) {
1168                    StringBundler query = null;
1169    
1170                    if (orderByComparator != null) {
1171                            query = new StringBundler(6 +
1172                                            (orderByComparator.getOrderByFields().length * 6));
1173                    }
1174                    else {
1175                            query = new StringBundler(3);
1176                    }
1177    
1178                    if (getDB().isSupportsInlineDistinct()) {
1179                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
1180                    }
1181                    else {
1182                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
1183                    }
1184    
1185                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1186    
1187                    if (!getDB().isSupportsInlineDistinct()) {
1188                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
1189                    }
1190    
1191                    if (orderByComparator != null) {
1192                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1193    
1194                            if (orderByConditionFields.length > 0) {
1195                                    query.append(WHERE_AND);
1196                            }
1197    
1198                            for (int i = 0; i < orderByConditionFields.length; i++) {
1199                                    if (getDB().isSupportsInlineDistinct()) {
1200                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1201                                    }
1202                                    else {
1203                                            query.append(_ORDER_BY_ENTITY_TABLE);
1204                                    }
1205    
1206                                    query.append(orderByConditionFields[i]);
1207    
1208                                    if ((i + 1) < orderByConditionFields.length) {
1209                                            if (orderByComparator.isAscending() ^ previous) {
1210                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1211                                            }
1212                                            else {
1213                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1214                                            }
1215                                    }
1216                                    else {
1217                                            if (orderByComparator.isAscending() ^ previous) {
1218                                                    query.append(WHERE_GREATER_THAN);
1219                                            }
1220                                            else {
1221                                                    query.append(WHERE_LESSER_THAN);
1222                                            }
1223                                    }
1224                            }
1225    
1226                            query.append(ORDER_BY_CLAUSE);
1227    
1228                            String[] orderByFields = orderByComparator.getOrderByFields();
1229    
1230                            for (int i = 0; i < orderByFields.length; i++) {
1231                                    if (getDB().isSupportsInlineDistinct()) {
1232                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1233                                    }
1234                                    else {
1235                                            query.append(_ORDER_BY_ENTITY_TABLE);
1236                                    }
1237    
1238                                    query.append(orderByFields[i]);
1239    
1240                                    if ((i + 1) < orderByFields.length) {
1241                                            if (orderByComparator.isAscending() ^ previous) {
1242                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1243                                            }
1244                                            else {
1245                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1246                                            }
1247                                    }
1248                                    else {
1249                                            if (orderByComparator.isAscending() ^ previous) {
1250                                                    query.append(ORDER_BY_ASC);
1251                                            }
1252                                            else {
1253                                                    query.append(ORDER_BY_DESC);
1254                                            }
1255                                    }
1256                            }
1257                    }
1258    
1259                    else {
1260                            if (getDB().isSupportsInlineDistinct()) {
1261                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1262                            }
1263                            else {
1264                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
1265                            }
1266                    }
1267    
1268                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1269                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1270    
1271                    SQLQuery q = session.createSQLQuery(sql);
1272    
1273                    q.setFirstResult(0);
1274                    q.setMaxResults(2);
1275    
1276                    if (getDB().isSupportsInlineDistinct()) {
1277                            q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
1278                    }
1279                    else {
1280                            q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
1281                    }
1282    
1283                    QueryPos qPos = QueryPos.getInstance(q);
1284    
1285                    qPos.add(companyId);
1286    
1287                    if (orderByComparator != null) {
1288                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
1289    
1290                            for (Object value : values) {
1291                                    qPos.add(value);
1292                            }
1293                    }
1294    
1295                    List<UserGroup> list = q.list();
1296    
1297                    if (list.size() == 2) {
1298                            return list.get(1);
1299                    }
1300                    else {
1301                            return null;
1302                    }
1303            }
1304    
1305            /**
1306             * Returns all the user groups where companyId = &#63; and parentUserGroupId = &#63;.
1307             *
1308             * @param companyId the company ID
1309             * @param parentUserGroupId the parent user group ID
1310             * @return the matching user groups
1311             * @throws SystemException if a system exception occurred
1312             */
1313            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
1314                    throws SystemException {
1315                    return findByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
1316                            QueryUtil.ALL_POS, null);
1317            }
1318    
1319            /**
1320             * Returns a range of all the user groups where companyId = &#63; and parentUserGroupId = &#63;.
1321             *
1322             * <p>
1323             * 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.
1324             * </p>
1325             *
1326             * @param companyId the company ID
1327             * @param parentUserGroupId the parent user group ID
1328             * @param start the lower bound of the range of user groups
1329             * @param end the upper bound of the range of user groups (not inclusive)
1330             * @return the range of matching user groups
1331             * @throws SystemException if a system exception occurred
1332             */
1333            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
1334                    int start, int end) throws SystemException {
1335                    return findByC_P(companyId, parentUserGroupId, start, end, null);
1336            }
1337    
1338            /**
1339             * Returns an ordered range of all the user groups where companyId = &#63; and parentUserGroupId = &#63;.
1340             *
1341             * <p>
1342             * 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.
1343             * </p>
1344             *
1345             * @param companyId the company ID
1346             * @param parentUserGroupId the parent user group ID
1347             * @param start the lower bound of the range of user groups
1348             * @param end the upper bound of the range of user groups (not inclusive)
1349             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1350             * @return the ordered range of matching user groups
1351             * @throws SystemException if a system exception occurred
1352             */
1353            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
1354                    int start, int end, OrderByComparator orderByComparator)
1355                    throws SystemException {
1356                    FinderPath finderPath = null;
1357                    Object[] finderArgs = null;
1358    
1359                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1360                                    (orderByComparator == null)) {
1361                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
1362                            finderArgs = new Object[] { companyId, parentUserGroupId };
1363                    }
1364                    else {
1365                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
1366                            finderArgs = new Object[] {
1367                                            companyId, parentUserGroupId,
1368                                            
1369                                            start, end, orderByComparator
1370                                    };
1371                    }
1372    
1373                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
1374                                    finderArgs, this);
1375    
1376                    if ((list != null) && !list.isEmpty()) {
1377                            for (UserGroup userGroup : list) {
1378                                    if ((companyId != userGroup.getCompanyId()) ||
1379                                                    (parentUserGroupId != userGroup.getParentUserGroupId())) {
1380                                            list = null;
1381    
1382                                            break;
1383                                    }
1384                            }
1385                    }
1386    
1387                    if (list == null) {
1388                            StringBundler query = null;
1389    
1390                            if (orderByComparator != null) {
1391                                    query = new StringBundler(4 +
1392                                                    (orderByComparator.getOrderByFields().length * 3));
1393                            }
1394                            else {
1395                                    query = new StringBundler(4);
1396                            }
1397    
1398                            query.append(_SQL_SELECT_USERGROUP_WHERE);
1399    
1400                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1401    
1402                            query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1403    
1404                            if (orderByComparator != null) {
1405                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1406                                            orderByComparator);
1407                            }
1408    
1409                            else {
1410                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1411                            }
1412    
1413                            String sql = query.toString();
1414    
1415                            Session session = null;
1416    
1417                            try {
1418                                    session = openSession();
1419    
1420                                    Query q = session.createQuery(sql);
1421    
1422                                    QueryPos qPos = QueryPos.getInstance(q);
1423    
1424                                    qPos.add(companyId);
1425    
1426                                    qPos.add(parentUserGroupId);
1427    
1428                                    list = (List<UserGroup>)QueryUtil.list(q, getDialect(), start,
1429                                                    end);
1430                            }
1431                            catch (Exception e) {
1432                                    throw processException(e);
1433                            }
1434                            finally {
1435                                    if (list == null) {
1436                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1437                                    }
1438                                    else {
1439                                            cacheResult(list);
1440    
1441                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1442                                    }
1443    
1444                                    closeSession(session);
1445                            }
1446                    }
1447    
1448                    return list;
1449            }
1450    
1451            /**
1452             * Returns the first user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
1453             *
1454             * @param companyId the company ID
1455             * @param parentUserGroupId the parent user group ID
1456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1457             * @return the first matching user group
1458             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
1459             * @throws SystemException if a system exception occurred
1460             */
1461            public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
1462                    OrderByComparator orderByComparator)
1463                    throws NoSuchUserGroupException, SystemException {
1464                    UserGroup userGroup = fetchByC_P_First(companyId, parentUserGroupId,
1465                                    orderByComparator);
1466    
1467                    if (userGroup != null) {
1468                            return userGroup;
1469                    }
1470    
1471                    StringBundler msg = new StringBundler(6);
1472    
1473                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1474    
1475                    msg.append("companyId=");
1476                    msg.append(companyId);
1477    
1478                    msg.append(", parentUserGroupId=");
1479                    msg.append(parentUserGroupId);
1480    
1481                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1482    
1483                    throw new NoSuchUserGroupException(msg.toString());
1484            }
1485    
1486            /**
1487             * Returns the first user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
1488             *
1489             * @param companyId the company ID
1490             * @param parentUserGroupId the parent user group ID
1491             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1492             * @return the first matching user group, or <code>null</code> if a matching user group could not be found
1493             * @throws SystemException if a system exception occurred
1494             */
1495            public UserGroup fetchByC_P_First(long companyId, long parentUserGroupId,
1496                    OrderByComparator orderByComparator) throws SystemException {
1497                    List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1,
1498                                    orderByComparator);
1499    
1500                    if (!list.isEmpty()) {
1501                            return list.get(0);
1502                    }
1503    
1504                    return null;
1505            }
1506    
1507            /**
1508             * Returns the last user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
1509             *
1510             * @param companyId the company ID
1511             * @param parentUserGroupId the parent user group ID
1512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1513             * @return the last matching user group
1514             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
1515             * @throws SystemException if a system exception occurred
1516             */
1517            public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
1518                    OrderByComparator orderByComparator)
1519                    throws NoSuchUserGroupException, SystemException {
1520                    UserGroup userGroup = fetchByC_P_Last(companyId, parentUserGroupId,
1521                                    orderByComparator);
1522    
1523                    if (userGroup != null) {
1524                            return userGroup;
1525                    }
1526    
1527                    StringBundler msg = new StringBundler(6);
1528    
1529                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1530    
1531                    msg.append("companyId=");
1532                    msg.append(companyId);
1533    
1534                    msg.append(", parentUserGroupId=");
1535                    msg.append(parentUserGroupId);
1536    
1537                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1538    
1539                    throw new NoSuchUserGroupException(msg.toString());
1540            }
1541    
1542            /**
1543             * Returns the last user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
1544             *
1545             * @param companyId the company ID
1546             * @param parentUserGroupId the parent user group ID
1547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1548             * @return the last matching user group, or <code>null</code> if a matching user group could not be found
1549             * @throws SystemException if a system exception occurred
1550             */
1551            public UserGroup fetchByC_P_Last(long companyId, long parentUserGroupId,
1552                    OrderByComparator orderByComparator) throws SystemException {
1553                    int count = countByC_P(companyId, parentUserGroupId);
1554    
1555                    List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
1556                                    count - 1, count, orderByComparator);
1557    
1558                    if (!list.isEmpty()) {
1559                            return list.get(0);
1560                    }
1561    
1562                    return null;
1563            }
1564    
1565            /**
1566             * Returns the user groups before and after the current user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
1567             *
1568             * @param userGroupId the primary key of the current user group
1569             * @param companyId the company ID
1570             * @param parentUserGroupId the parent user group ID
1571             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1572             * @return the previous, current, and next user group
1573             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
1574             * @throws SystemException if a system exception occurred
1575             */
1576            public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
1577                    long parentUserGroupId, OrderByComparator orderByComparator)
1578                    throws NoSuchUserGroupException, SystemException {
1579                    UserGroup userGroup = findByPrimaryKey(userGroupId);
1580    
1581                    Session session = null;
1582    
1583                    try {
1584                            session = openSession();
1585    
1586                            UserGroup[] array = new UserGroupImpl[3];
1587    
1588                            array[0] = getByC_P_PrevAndNext(session, userGroup, companyId,
1589                                            parentUserGroupId, orderByComparator, true);
1590    
1591                            array[1] = userGroup;
1592    
1593                            array[2] = getByC_P_PrevAndNext(session, userGroup, companyId,
1594                                            parentUserGroupId, orderByComparator, false);
1595    
1596                            return array;
1597                    }
1598                    catch (Exception e) {
1599                            throw processException(e);
1600                    }
1601                    finally {
1602                            closeSession(session);
1603                    }
1604            }
1605    
1606            protected UserGroup getByC_P_PrevAndNext(Session session,
1607                    UserGroup userGroup, long companyId, long parentUserGroupId,
1608                    OrderByComparator orderByComparator, boolean previous) {
1609                    StringBundler query = null;
1610    
1611                    if (orderByComparator != null) {
1612                            query = new StringBundler(6 +
1613                                            (orderByComparator.getOrderByFields().length * 6));
1614                    }
1615                    else {
1616                            query = new StringBundler(3);
1617                    }
1618    
1619                    query.append(_SQL_SELECT_USERGROUP_WHERE);
1620    
1621                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1622    
1623                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1624    
1625                    if (orderByComparator != null) {
1626                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1627    
1628                            if (orderByConditionFields.length > 0) {
1629                                    query.append(WHERE_AND);
1630                            }
1631    
1632                            for (int i = 0; i < orderByConditionFields.length; i++) {
1633                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1634                                    query.append(orderByConditionFields[i]);
1635    
1636                                    if ((i + 1) < orderByConditionFields.length) {
1637                                            if (orderByComparator.isAscending() ^ previous) {
1638                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1639                                            }
1640                                            else {
1641                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1642                                            }
1643                                    }
1644                                    else {
1645                                            if (orderByComparator.isAscending() ^ previous) {
1646                                                    query.append(WHERE_GREATER_THAN);
1647                                            }
1648                                            else {
1649                                                    query.append(WHERE_LESSER_THAN);
1650                                            }
1651                                    }
1652                            }
1653    
1654                            query.append(ORDER_BY_CLAUSE);
1655    
1656                            String[] orderByFields = orderByComparator.getOrderByFields();
1657    
1658                            for (int i = 0; i < orderByFields.length; i++) {
1659                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1660                                    query.append(orderByFields[i]);
1661    
1662                                    if ((i + 1) < orderByFields.length) {
1663                                            if (orderByComparator.isAscending() ^ previous) {
1664                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1665                                            }
1666                                            else {
1667                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1668                                            }
1669                                    }
1670                                    else {
1671                                            if (orderByComparator.isAscending() ^ previous) {
1672                                                    query.append(ORDER_BY_ASC);
1673                                            }
1674                                            else {
1675                                                    query.append(ORDER_BY_DESC);
1676                                            }
1677                                    }
1678                            }
1679                    }
1680    
1681                    else {
1682                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1683                    }
1684    
1685                    String sql = query.toString();
1686    
1687                    Query q = session.createQuery(sql);
1688    
1689                    q.setFirstResult(0);
1690                    q.setMaxResults(2);
1691    
1692                    QueryPos qPos = QueryPos.getInstance(q);
1693    
1694                    qPos.add(companyId);
1695    
1696                    qPos.add(parentUserGroupId);
1697    
1698                    if (orderByComparator != null) {
1699                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
1700    
1701                            for (Object value : values) {
1702                                    qPos.add(value);
1703                            }
1704                    }
1705    
1706                    List<UserGroup> list = q.list();
1707    
1708                    if (list.size() == 2) {
1709                            return list.get(1);
1710                    }
1711                    else {
1712                            return null;
1713                    }
1714            }
1715    
1716            /**
1717             * Returns all the user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
1718             *
1719             * @param companyId the company ID
1720             * @param parentUserGroupId the parent user group ID
1721             * @return the matching user groups that the user has permission to view
1722             * @throws SystemException if a system exception occurred
1723             */
1724            public List<UserGroup> filterFindByC_P(long companyId,
1725                    long parentUserGroupId) throws SystemException {
1726                    return filterFindByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
1727                            QueryUtil.ALL_POS, null);
1728            }
1729    
1730            /**
1731             * Returns a range of all the user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
1732             *
1733             * <p>
1734             * 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.
1735             * </p>
1736             *
1737             * @param companyId the company ID
1738             * @param parentUserGroupId the parent user group ID
1739             * @param start the lower bound of the range of user groups
1740             * @param end the upper bound of the range of user groups (not inclusive)
1741             * @return the range of matching user groups that the user has permission to view
1742             * @throws SystemException if a system exception occurred
1743             */
1744            public List<UserGroup> filterFindByC_P(long companyId,
1745                    long parentUserGroupId, int start, int end) throws SystemException {
1746                    return filterFindByC_P(companyId, parentUserGroupId, start, end, null);
1747            }
1748    
1749            /**
1750             * Returns an ordered range of all the user groups that the user has permissions to view where companyId = &#63; and parentUserGroupId = &#63;.
1751             *
1752             * <p>
1753             * 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.
1754             * </p>
1755             *
1756             * @param companyId the company ID
1757             * @param parentUserGroupId the parent user group ID
1758             * @param start the lower bound of the range of user groups
1759             * @param end the upper bound of the range of user groups (not inclusive)
1760             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1761             * @return the ordered range of matching user groups that the user has permission to view
1762             * @throws SystemException if a system exception occurred
1763             */
1764            public List<UserGroup> filterFindByC_P(long companyId,
1765                    long parentUserGroupId, int start, int end,
1766                    OrderByComparator orderByComparator) throws SystemException {
1767                    if (!InlineSQLHelperUtil.isEnabled()) {
1768                            return findByC_P(companyId, parentUserGroupId, start, end,
1769                                    orderByComparator);
1770                    }
1771    
1772                    StringBundler query = null;
1773    
1774                    if (orderByComparator != null) {
1775                            query = new StringBundler(4 +
1776                                            (orderByComparator.getOrderByFields().length * 3));
1777                    }
1778                    else {
1779                            query = new StringBundler(4);
1780                    }
1781    
1782                    if (getDB().isSupportsInlineDistinct()) {
1783                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
1784                    }
1785                    else {
1786                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
1787                    }
1788    
1789                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1790    
1791                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1792    
1793                    if (!getDB().isSupportsInlineDistinct()) {
1794                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
1795                    }
1796    
1797                    if (orderByComparator != null) {
1798                            if (getDB().isSupportsInlineDistinct()) {
1799                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1800                                            orderByComparator);
1801                            }
1802                            else {
1803                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1804                                            orderByComparator);
1805                            }
1806                    }
1807    
1808                    else {
1809                            if (getDB().isSupportsInlineDistinct()) {
1810                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1811                            }
1812                            else {
1813                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
1814                            }
1815                    }
1816    
1817                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1818                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1819    
1820                    Session session = null;
1821    
1822                    try {
1823                            session = openSession();
1824    
1825                            SQLQuery q = session.createSQLQuery(sql);
1826    
1827                            if (getDB().isSupportsInlineDistinct()) {
1828                                    q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
1829                            }
1830                            else {
1831                                    q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
1832                            }
1833    
1834                            QueryPos qPos = QueryPos.getInstance(q);
1835    
1836                            qPos.add(companyId);
1837    
1838                            qPos.add(parentUserGroupId);
1839    
1840                            return (List<UserGroup>)QueryUtil.list(q, getDialect(), start, end);
1841                    }
1842                    catch (Exception e) {
1843                            throw processException(e);
1844                    }
1845                    finally {
1846                            closeSession(session);
1847                    }
1848            }
1849    
1850            /**
1851             * Returns the user groups before and after the current user group in the ordered set of user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
1852             *
1853             * @param userGroupId the primary key of the current user group
1854             * @param companyId the company ID
1855             * @param parentUserGroupId the parent user group ID
1856             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1857             * @return the previous, current, and next user group
1858             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
1859             * @throws SystemException if a system exception occurred
1860             */
1861            public UserGroup[] filterFindByC_P_PrevAndNext(long userGroupId,
1862                    long companyId, long parentUserGroupId,
1863                    OrderByComparator orderByComparator)
1864                    throws NoSuchUserGroupException, SystemException {
1865                    if (!InlineSQLHelperUtil.isEnabled()) {
1866                            return findByC_P_PrevAndNext(userGroupId, companyId,
1867                                    parentUserGroupId, orderByComparator);
1868                    }
1869    
1870                    UserGroup userGroup = findByPrimaryKey(userGroupId);
1871    
1872                    Session session = null;
1873    
1874                    try {
1875                            session = openSession();
1876    
1877                            UserGroup[] array = new UserGroupImpl[3];
1878    
1879                            array[0] = filterGetByC_P_PrevAndNext(session, userGroup,
1880                                            companyId, parentUserGroupId, orderByComparator, true);
1881    
1882                            array[1] = userGroup;
1883    
1884                            array[2] = filterGetByC_P_PrevAndNext(session, userGroup,
1885                                            companyId, parentUserGroupId, orderByComparator, false);
1886    
1887                            return array;
1888                    }
1889                    catch (Exception e) {
1890                            throw processException(e);
1891                    }
1892                    finally {
1893                            closeSession(session);
1894                    }
1895            }
1896    
1897            protected UserGroup filterGetByC_P_PrevAndNext(Session session,
1898                    UserGroup userGroup, long companyId, long parentUserGroupId,
1899                    OrderByComparator orderByComparator, boolean previous) {
1900                    StringBundler query = null;
1901    
1902                    if (orderByComparator != null) {
1903                            query = new StringBundler(6 +
1904                                            (orderByComparator.getOrderByFields().length * 6));
1905                    }
1906                    else {
1907                            query = new StringBundler(3);
1908                    }
1909    
1910                    if (getDB().isSupportsInlineDistinct()) {
1911                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
1912                    }
1913                    else {
1914                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
1915                    }
1916    
1917                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1918    
1919                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
1920    
1921                    if (!getDB().isSupportsInlineDistinct()) {
1922                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
1923                    }
1924    
1925                    if (orderByComparator != null) {
1926                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1927    
1928                            if (orderByConditionFields.length > 0) {
1929                                    query.append(WHERE_AND);
1930                            }
1931    
1932                            for (int i = 0; i < orderByConditionFields.length; i++) {
1933                                    if (getDB().isSupportsInlineDistinct()) {
1934                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1935                                    }
1936                                    else {
1937                                            query.append(_ORDER_BY_ENTITY_TABLE);
1938                                    }
1939    
1940                                    query.append(orderByConditionFields[i]);
1941    
1942                                    if ((i + 1) < orderByConditionFields.length) {
1943                                            if (orderByComparator.isAscending() ^ previous) {
1944                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1945                                            }
1946                                            else {
1947                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1948                                            }
1949                                    }
1950                                    else {
1951                                            if (orderByComparator.isAscending() ^ previous) {
1952                                                    query.append(WHERE_GREATER_THAN);
1953                                            }
1954                                            else {
1955                                                    query.append(WHERE_LESSER_THAN);
1956                                            }
1957                                    }
1958                            }
1959    
1960                            query.append(ORDER_BY_CLAUSE);
1961    
1962                            String[] orderByFields = orderByComparator.getOrderByFields();
1963    
1964                            for (int i = 0; i < orderByFields.length; i++) {
1965                                    if (getDB().isSupportsInlineDistinct()) {
1966                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1967                                    }
1968                                    else {
1969                                            query.append(_ORDER_BY_ENTITY_TABLE);
1970                                    }
1971    
1972                                    query.append(orderByFields[i]);
1973    
1974                                    if ((i + 1) < orderByFields.length) {
1975                                            if (orderByComparator.isAscending() ^ previous) {
1976                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1977                                            }
1978                                            else {
1979                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1980                                            }
1981                                    }
1982                                    else {
1983                                            if (orderByComparator.isAscending() ^ previous) {
1984                                                    query.append(ORDER_BY_ASC);
1985                                            }
1986                                            else {
1987                                                    query.append(ORDER_BY_DESC);
1988                                            }
1989                                    }
1990                            }
1991                    }
1992    
1993                    else {
1994                            if (getDB().isSupportsInlineDistinct()) {
1995                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1996                            }
1997                            else {
1998                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
1999                            }
2000                    }
2001    
2002                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2003                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2004    
2005                    SQLQuery q = session.createSQLQuery(sql);
2006    
2007                    q.setFirstResult(0);
2008                    q.setMaxResults(2);
2009    
2010                    if (getDB().isSupportsInlineDistinct()) {
2011                            q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
2012                    }
2013                    else {
2014                            q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
2015                    }
2016    
2017                    QueryPos qPos = QueryPos.getInstance(q);
2018    
2019                    qPos.add(companyId);
2020    
2021                    qPos.add(parentUserGroupId);
2022    
2023                    if (orderByComparator != null) {
2024                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
2025    
2026                            for (Object value : values) {
2027                                    qPos.add(value);
2028                            }
2029                    }
2030    
2031                    List<UserGroup> list = q.list();
2032    
2033                    if (list.size() == 2) {
2034                            return list.get(1);
2035                    }
2036                    else {
2037                            return null;
2038                    }
2039            }
2040    
2041            /**
2042             * Returns the user group where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchUserGroupException} if it could not be found.
2043             *
2044             * @param companyId the company ID
2045             * @param name the name
2046             * @return the matching user group
2047             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
2048             * @throws SystemException if a system exception occurred
2049             */
2050            public UserGroup findByC_N(long companyId, String name)
2051                    throws NoSuchUserGroupException, SystemException {
2052                    UserGroup userGroup = fetchByC_N(companyId, name);
2053    
2054                    if (userGroup == null) {
2055                            StringBundler msg = new StringBundler(6);
2056    
2057                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2058    
2059                            msg.append("companyId=");
2060                            msg.append(companyId);
2061    
2062                            msg.append(", name=");
2063                            msg.append(name);
2064    
2065                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2066    
2067                            if (_log.isWarnEnabled()) {
2068                                    _log.warn(msg.toString());
2069                            }
2070    
2071                            throw new NoSuchUserGroupException(msg.toString());
2072                    }
2073    
2074                    return userGroup;
2075            }
2076    
2077            /**
2078             * Returns the user group where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2079             *
2080             * @param companyId the company ID
2081             * @param name the name
2082             * @return the matching user group, or <code>null</code> if a matching user group could not be found
2083             * @throws SystemException if a system exception occurred
2084             */
2085            public UserGroup fetchByC_N(long companyId, String name)
2086                    throws SystemException {
2087                    return fetchByC_N(companyId, name, true);
2088            }
2089    
2090            /**
2091             * Returns the user group where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2092             *
2093             * @param companyId the company ID
2094             * @param name the name
2095             * @param retrieveFromCache whether to use the finder cache
2096             * @return the matching user group, or <code>null</code> if a matching user group could not be found
2097             * @throws SystemException if a system exception occurred
2098             */
2099            public UserGroup fetchByC_N(long companyId, String name,
2100                    boolean retrieveFromCache) throws SystemException {
2101                    Object[] finderArgs = new Object[] { companyId, name };
2102    
2103                    Object result = null;
2104    
2105                    if (retrieveFromCache) {
2106                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2107                                            finderArgs, this);
2108                    }
2109    
2110                    if (result instanceof UserGroup) {
2111                            UserGroup userGroup = (UserGroup)result;
2112    
2113                            if ((companyId != userGroup.getCompanyId()) ||
2114                                            !Validator.equals(name, userGroup.getName())) {
2115                                    result = null;
2116                            }
2117                    }
2118    
2119                    if (result == null) {
2120                            StringBundler query = new StringBundler(4);
2121    
2122                            query.append(_SQL_SELECT_USERGROUP_WHERE);
2123    
2124                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2125    
2126                            if (name == null) {
2127                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2128                            }
2129                            else {
2130                                    if (name.equals(StringPool.BLANK)) {
2131                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
2132                                    }
2133                                    else {
2134                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
2135                                    }
2136                            }
2137    
2138                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
2139    
2140                            String sql = query.toString();
2141    
2142                            Session session = null;
2143    
2144                            try {
2145                                    session = openSession();
2146    
2147                                    Query q = session.createQuery(sql);
2148    
2149                                    QueryPos qPos = QueryPos.getInstance(q);
2150    
2151                                    qPos.add(companyId);
2152    
2153                                    if (name != null) {
2154                                            qPos.add(name);
2155                                    }
2156    
2157                                    List<UserGroup> list = q.list();
2158    
2159                                    result = list;
2160    
2161                                    UserGroup userGroup = null;
2162    
2163                                    if (list.isEmpty()) {
2164                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2165                                                    finderArgs, list);
2166                                    }
2167                                    else {
2168                                            userGroup = list.get(0);
2169    
2170                                            cacheResult(userGroup);
2171    
2172                                            if ((userGroup.getCompanyId() != companyId) ||
2173                                                            (userGroup.getName() == null) ||
2174                                                            !userGroup.getName().equals(name)) {
2175                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2176                                                            finderArgs, userGroup);
2177                                            }
2178                                    }
2179    
2180                                    return userGroup;
2181                            }
2182                            catch (Exception e) {
2183                                    throw processException(e);
2184                            }
2185                            finally {
2186                                    if (result == null) {
2187                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2188                                                    finderArgs);
2189                                    }
2190    
2191                                    closeSession(session);
2192                            }
2193                    }
2194                    else {
2195                            if (result instanceof List<?>) {
2196                                    return null;
2197                            }
2198                            else {
2199                                    return (UserGroup)result;
2200                            }
2201                    }
2202            }
2203    
2204            /**
2205             * Returns all the user groups.
2206             *
2207             * @return the user groups
2208             * @throws SystemException if a system exception occurred
2209             */
2210            public List<UserGroup> findAll() throws SystemException {
2211                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2212            }
2213    
2214            /**
2215             * Returns a range of all the user groups.
2216             *
2217             * <p>
2218             * 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.
2219             * </p>
2220             *
2221             * @param start the lower bound of the range of user groups
2222             * @param end the upper bound of the range of user groups (not inclusive)
2223             * @return the range of user groups
2224             * @throws SystemException if a system exception occurred
2225             */
2226            public List<UserGroup> findAll(int start, int end)
2227                    throws SystemException {
2228                    return findAll(start, end, null);
2229            }
2230    
2231            /**
2232             * Returns an ordered range of all the user groups.
2233             *
2234             * <p>
2235             * 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.
2236             * </p>
2237             *
2238             * @param start the lower bound of the range of user groups
2239             * @param end the upper bound of the range of user groups (not inclusive)
2240             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2241             * @return the ordered range of user groups
2242             * @throws SystemException if a system exception occurred
2243             */
2244            public List<UserGroup> findAll(int start, int end,
2245                    OrderByComparator orderByComparator) throws SystemException {
2246                    FinderPath finderPath = null;
2247                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
2248    
2249                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2250                                    (orderByComparator == null)) {
2251                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2252                            finderArgs = FINDER_ARGS_EMPTY;
2253                    }
2254                    else {
2255                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2256                            finderArgs = new Object[] { start, end, orderByComparator };
2257                    }
2258    
2259                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
2260                                    finderArgs, this);
2261    
2262                    if (list == null) {
2263                            StringBundler query = null;
2264                            String sql = null;
2265    
2266                            if (orderByComparator != null) {
2267                                    query = new StringBundler(2 +
2268                                                    (orderByComparator.getOrderByFields().length * 3));
2269    
2270                                    query.append(_SQL_SELECT_USERGROUP);
2271    
2272                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2273                                            orderByComparator);
2274    
2275                                    sql = query.toString();
2276                            }
2277                            else {
2278                                    sql = _SQL_SELECT_USERGROUP.concat(UserGroupModelImpl.ORDER_BY_JPQL);
2279                            }
2280    
2281                            Session session = null;
2282    
2283                            try {
2284                                    session = openSession();
2285    
2286                                    Query q = session.createQuery(sql);
2287    
2288                                    if (orderByComparator == null) {
2289                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
2290                                                            start, end, false);
2291    
2292                                            Collections.sort(list);
2293                                    }
2294                                    else {
2295                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
2296                                                            start, end);
2297                                    }
2298                            }
2299                            catch (Exception e) {
2300                                    throw processException(e);
2301                            }
2302                            finally {
2303                                    if (list == null) {
2304                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2305                                    }
2306                                    else {
2307                                            cacheResult(list);
2308    
2309                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2310                                    }
2311    
2312                                    closeSession(session);
2313                            }
2314                    }
2315    
2316                    return list;
2317            }
2318    
2319            /**
2320             * Removes all the user groups where companyId = &#63; from the database.
2321             *
2322             * @param companyId the company ID
2323             * @throws SystemException if a system exception occurred
2324             */
2325            public void removeByCompanyId(long companyId) throws SystemException {
2326                    for (UserGroup userGroup : findByCompanyId(companyId)) {
2327                            remove(userGroup);
2328                    }
2329            }
2330    
2331            /**
2332             * Removes all the user groups where companyId = &#63; and parentUserGroupId = &#63; from the database.
2333             *
2334             * @param companyId the company ID
2335             * @param parentUserGroupId the parent user group ID
2336             * @throws SystemException if a system exception occurred
2337             */
2338            public void removeByC_P(long companyId, long parentUserGroupId)
2339                    throws SystemException {
2340                    for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId)) {
2341                            remove(userGroup);
2342                    }
2343            }
2344    
2345            /**
2346             * Removes the user group where companyId = &#63; and name = &#63; from the database.
2347             *
2348             * @param companyId the company ID
2349             * @param name the name
2350             * @return the user group that was removed
2351             * @throws SystemException if a system exception occurred
2352             */
2353            public UserGroup removeByC_N(long companyId, String name)
2354                    throws NoSuchUserGroupException, SystemException {
2355                    UserGroup userGroup = findByC_N(companyId, name);
2356    
2357                    return remove(userGroup);
2358            }
2359    
2360            /**
2361             * Removes all the user groups from the database.
2362             *
2363             * @throws SystemException if a system exception occurred
2364             */
2365            public void removeAll() throws SystemException {
2366                    for (UserGroup userGroup : findAll()) {
2367                            remove(userGroup);
2368                    }
2369            }
2370    
2371            /**
2372             * Returns the number of user groups where companyId = &#63;.
2373             *
2374             * @param companyId the company ID
2375             * @return the number of matching user groups
2376             * @throws SystemException if a system exception occurred
2377             */
2378            public int countByCompanyId(long companyId) throws SystemException {
2379                    Object[] finderArgs = new Object[] { companyId };
2380    
2381                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2382                                    finderArgs, this);
2383    
2384                    if (count == null) {
2385                            StringBundler query = new StringBundler(2);
2386    
2387                            query.append(_SQL_COUNT_USERGROUP_WHERE);
2388    
2389                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2390    
2391                            String sql = query.toString();
2392    
2393                            Session session = null;
2394    
2395                            try {
2396                                    session = openSession();
2397    
2398                                    Query q = session.createQuery(sql);
2399    
2400                                    QueryPos qPos = QueryPos.getInstance(q);
2401    
2402                                    qPos.add(companyId);
2403    
2404                                    count = (Long)q.uniqueResult();
2405                            }
2406                            catch (Exception e) {
2407                                    throw processException(e);
2408                            }
2409                            finally {
2410                                    if (count == null) {
2411                                            count = Long.valueOf(0);
2412                                    }
2413    
2414                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2415                                            finderArgs, count);
2416    
2417                                    closeSession(session);
2418                            }
2419                    }
2420    
2421                    return count.intValue();
2422            }
2423    
2424            /**
2425             * Returns the number of user groups that the user has permission to view where companyId = &#63;.
2426             *
2427             * @param companyId the company ID
2428             * @return the number of matching user groups that the user has permission to view
2429             * @throws SystemException if a system exception occurred
2430             */
2431            public int filterCountByCompanyId(long companyId) throws SystemException {
2432                    if (!InlineSQLHelperUtil.isEnabled()) {
2433                            return countByCompanyId(companyId);
2434                    }
2435    
2436                    StringBundler query = new StringBundler(2);
2437    
2438                    query.append(_FILTER_SQL_COUNT_USERGROUP_WHERE);
2439    
2440                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2441    
2442                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2443                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2444    
2445                    Session session = null;
2446    
2447                    try {
2448                            session = openSession();
2449    
2450                            SQLQuery q = session.createSQLQuery(sql);
2451    
2452                            q.addScalar(COUNT_COLUMN_NAME,
2453                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2454    
2455                            QueryPos qPos = QueryPos.getInstance(q);
2456    
2457                            qPos.add(companyId);
2458    
2459                            Long count = (Long)q.uniqueResult();
2460    
2461                            return count.intValue();
2462                    }
2463                    catch (Exception e) {
2464                            throw processException(e);
2465                    }
2466                    finally {
2467                            closeSession(session);
2468                    }
2469            }
2470    
2471            /**
2472             * Returns the number of user groups where companyId = &#63; and parentUserGroupId = &#63;.
2473             *
2474             * @param companyId the company ID
2475             * @param parentUserGroupId the parent user group ID
2476             * @return the number of matching user groups
2477             * @throws SystemException if a system exception occurred
2478             */
2479            public int countByC_P(long companyId, long parentUserGroupId)
2480                    throws SystemException {
2481                    Object[] finderArgs = new Object[] { companyId, parentUserGroupId };
2482    
2483                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
2484                                    finderArgs, this);
2485    
2486                    if (count == null) {
2487                            StringBundler query = new StringBundler(3);
2488    
2489                            query.append(_SQL_COUNT_USERGROUP_WHERE);
2490    
2491                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2492    
2493                            query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
2494    
2495                            String sql = query.toString();
2496    
2497                            Session session = null;
2498    
2499                            try {
2500                                    session = openSession();
2501    
2502                                    Query q = session.createQuery(sql);
2503    
2504                                    QueryPos qPos = QueryPos.getInstance(q);
2505    
2506                                    qPos.add(companyId);
2507    
2508                                    qPos.add(parentUserGroupId);
2509    
2510                                    count = (Long)q.uniqueResult();
2511                            }
2512                            catch (Exception e) {
2513                                    throw processException(e);
2514                            }
2515                            finally {
2516                                    if (count == null) {
2517                                            count = Long.valueOf(0);
2518                                    }
2519    
2520                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
2521                                            count);
2522    
2523                                    closeSession(session);
2524                            }
2525                    }
2526    
2527                    return count.intValue();
2528            }
2529    
2530            /**
2531             * Returns the number of user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
2532             *
2533             * @param companyId the company ID
2534             * @param parentUserGroupId the parent user group ID
2535             * @return the number of matching user groups that the user has permission to view
2536             * @throws SystemException if a system exception occurred
2537             */
2538            public int filterCountByC_P(long companyId, long parentUserGroupId)
2539                    throws SystemException {
2540                    if (!InlineSQLHelperUtil.isEnabled()) {
2541                            return countByC_P(companyId, parentUserGroupId);
2542                    }
2543    
2544                    StringBundler query = new StringBundler(3);
2545    
2546                    query.append(_FILTER_SQL_COUNT_USERGROUP_WHERE);
2547    
2548                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2549    
2550                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
2551    
2552                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2553                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2554    
2555                    Session session = null;
2556    
2557                    try {
2558                            session = openSession();
2559    
2560                            SQLQuery q = session.createSQLQuery(sql);
2561    
2562                            q.addScalar(COUNT_COLUMN_NAME,
2563                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2564    
2565                            QueryPos qPos = QueryPos.getInstance(q);
2566    
2567                            qPos.add(companyId);
2568    
2569                            qPos.add(parentUserGroupId);
2570    
2571                            Long count = (Long)q.uniqueResult();
2572    
2573                            return count.intValue();
2574                    }
2575                    catch (Exception e) {
2576                            throw processException(e);
2577                    }
2578                    finally {
2579                            closeSession(session);
2580                    }
2581            }
2582    
2583            /**
2584             * Returns the number of user groups where companyId = &#63; and name = &#63;.
2585             *
2586             * @param companyId the company ID
2587             * @param name the name
2588             * @return the number of matching user groups
2589             * @throws SystemException if a system exception occurred
2590             */
2591            public int countByC_N(long companyId, String name)
2592                    throws SystemException {
2593                    Object[] finderArgs = new Object[] { companyId, name };
2594    
2595                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
2596                                    finderArgs, this);
2597    
2598                    if (count == null) {
2599                            StringBundler query = new StringBundler(3);
2600    
2601                            query.append(_SQL_COUNT_USERGROUP_WHERE);
2602    
2603                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2604    
2605                            if (name == null) {
2606                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2607                            }
2608                            else {
2609                                    if (name.equals(StringPool.BLANK)) {
2610                                            query.append(_FINDER_COLUMN_C_N_NAME_3);
2611                                    }
2612                                    else {
2613                                            query.append(_FINDER_COLUMN_C_N_NAME_2);
2614                                    }
2615                            }
2616    
2617                            String sql = query.toString();
2618    
2619                            Session session = null;
2620    
2621                            try {
2622                                    session = openSession();
2623    
2624                                    Query q = session.createQuery(sql);
2625    
2626                                    QueryPos qPos = QueryPos.getInstance(q);
2627    
2628                                    qPos.add(companyId);
2629    
2630                                    if (name != null) {
2631                                            qPos.add(name);
2632                                    }
2633    
2634                                    count = (Long)q.uniqueResult();
2635                            }
2636                            catch (Exception e) {
2637                                    throw processException(e);
2638                            }
2639                            finally {
2640                                    if (count == null) {
2641                                            count = Long.valueOf(0);
2642                                    }
2643    
2644                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
2645                                            count);
2646    
2647                                    closeSession(session);
2648                            }
2649                    }
2650    
2651                    return count.intValue();
2652            }
2653    
2654            /**
2655             * Returns the number of user groups.
2656             *
2657             * @return the number of user groups
2658             * @throws SystemException if a system exception occurred
2659             */
2660            public int countAll() throws SystemException {
2661                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2662                                    FINDER_ARGS_EMPTY, this);
2663    
2664                    if (count == null) {
2665                            Session session = null;
2666    
2667                            try {
2668                                    session = openSession();
2669    
2670                                    Query q = session.createQuery(_SQL_COUNT_USERGROUP);
2671    
2672                                    count = (Long)q.uniqueResult();
2673                            }
2674                            catch (Exception e) {
2675                                    throw processException(e);
2676                            }
2677                            finally {
2678                                    if (count == null) {
2679                                            count = Long.valueOf(0);
2680                                    }
2681    
2682                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2683                                            FINDER_ARGS_EMPTY, count);
2684    
2685                                    closeSession(session);
2686                            }
2687                    }
2688    
2689                    return count.intValue();
2690            }
2691    
2692            /**
2693             * Returns all the groups associated with the user group.
2694             *
2695             * @param pk the primary key of the user group
2696             * @return the groups associated with the user group
2697             * @throws SystemException if a system exception occurred
2698             */
2699            public List<com.liferay.portal.model.Group> getGroups(long pk)
2700                    throws SystemException {
2701                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2702            }
2703    
2704            /**
2705             * Returns a range of all the groups associated with the user group.
2706             *
2707             * <p>
2708             * 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.
2709             * </p>
2710             *
2711             * @param pk the primary key of the user group
2712             * @param start the lower bound of the range of user groups
2713             * @param end the upper bound of the range of user groups (not inclusive)
2714             * @return the range of groups associated with the user group
2715             * @throws SystemException if a system exception occurred
2716             */
2717            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2718                    int end) throws SystemException {
2719                    return getGroups(pk, start, end, null);
2720            }
2721    
2722            public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2723                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
2724                            com.liferay.portal.model.impl.GroupImpl.class,
2725                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
2726                            "getGroups",
2727                            new String[] {
2728                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2729                                    "com.liferay.portal.kernel.util.OrderByComparator"
2730                            });
2731    
2732            static {
2733                    FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
2734            }
2735    
2736            /**
2737             * Returns an ordered range of all the groups associated with the user group.
2738             *
2739             * <p>
2740             * 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.
2741             * </p>
2742             *
2743             * @param pk the primary key of the user group
2744             * @param start the lower bound of the range of user groups
2745             * @param end the upper bound of the range of user groups (not inclusive)
2746             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2747             * @return the ordered range of groups associated with the user group
2748             * @throws SystemException if a system exception occurred
2749             */
2750            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2751                    int end, OrderByComparator orderByComparator) throws SystemException {
2752                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
2753    
2754                    List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
2755                                    finderArgs, this);
2756    
2757                    if (list == null) {
2758                            Session session = null;
2759    
2760                            try {
2761                                    session = openSession();
2762    
2763                                    String sql = null;
2764    
2765                                    if (orderByComparator != null) {
2766                                            sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
2767                                                                                    .concat(orderByComparator.getOrderBy());
2768                                    }
2769                                    else {
2770                                            sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
2771                                    }
2772    
2773                                    SQLQuery q = session.createSQLQuery(sql);
2774    
2775                                    q.addEntity("Group_",
2776                                            com.liferay.portal.model.impl.GroupImpl.class);
2777    
2778                                    QueryPos qPos = QueryPos.getInstance(q);
2779    
2780                                    qPos.add(pk);
2781    
2782                                    list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
2783                                                    getDialect(), start, end);
2784                            }
2785                            catch (Exception e) {
2786                                    throw processException(e);
2787                            }
2788                            finally {
2789                                    if (list == null) {
2790                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
2791                                                    finderArgs);
2792                                    }
2793                                    else {
2794                                            groupPersistence.cacheResult(list);
2795    
2796                                            FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
2797                                                    finderArgs, list);
2798                                    }
2799    
2800                                    closeSession(session);
2801                            }
2802                    }
2803    
2804                    return list;
2805            }
2806    
2807            public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2808                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
2809                            Long.class,
2810                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
2811                            "getGroupsSize", new String[] { Long.class.getName() });
2812    
2813            static {
2814                    FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
2815            }
2816    
2817            /**
2818             * Returns the number of groups associated with the user group.
2819             *
2820             * @param pk the primary key of the user group
2821             * @return the number of groups associated with the user group
2822             * @throws SystemException if a system exception occurred
2823             */
2824            public int getGroupsSize(long pk) throws SystemException {
2825                    Object[] finderArgs = new Object[] { pk };
2826    
2827                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
2828                                    finderArgs, this);
2829    
2830                    if (count == null) {
2831                            Session session = null;
2832    
2833                            try {
2834                                    session = openSession();
2835    
2836                                    SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
2837    
2838                                    q.addScalar(COUNT_COLUMN_NAME,
2839                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
2840    
2841                                    QueryPos qPos = QueryPos.getInstance(q);
2842    
2843                                    qPos.add(pk);
2844    
2845                                    count = (Long)q.uniqueResult();
2846                            }
2847                            catch (Exception e) {
2848                                    throw processException(e);
2849                            }
2850                            finally {
2851                                    if (count == null) {
2852                                            count = Long.valueOf(0);
2853                                    }
2854    
2855                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
2856                                            finderArgs, count);
2857    
2858                                    closeSession(session);
2859                            }
2860                    }
2861    
2862                    return count.intValue();
2863            }
2864    
2865            public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2866                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
2867                            Boolean.class,
2868                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
2869                            "containsGroup",
2870                            new String[] { Long.class.getName(), Long.class.getName() });
2871    
2872            /**
2873             * Returns <code>true</code> if the group is associated with the user group.
2874             *
2875             * @param pk the primary key of the user group
2876             * @param groupPK the primary key of the group
2877             * @return <code>true</code> if the group is associated with the user group; <code>false</code> otherwise
2878             * @throws SystemException if a system exception occurred
2879             */
2880            public boolean containsGroup(long pk, long groupPK)
2881                    throws SystemException {
2882                    Object[] finderArgs = new Object[] { pk, groupPK };
2883    
2884                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
2885                                    finderArgs, this);
2886    
2887                    if (value == null) {
2888                            try {
2889                                    value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
2890                            }
2891                            catch (Exception e) {
2892                                    throw processException(e);
2893                            }
2894                            finally {
2895                                    if (value == null) {
2896                                            value = Boolean.FALSE;
2897                                    }
2898    
2899                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
2900                                            finderArgs, value);
2901                            }
2902                    }
2903    
2904                    return value.booleanValue();
2905            }
2906    
2907            /**
2908             * Returns <code>true</code> if the user group has any groups associated with it.
2909             *
2910             * @param pk the primary key of the user group to check for associations with groups
2911             * @return <code>true</code> if the user group has any groups associated with it; <code>false</code> otherwise
2912             * @throws SystemException if a system exception occurred
2913             */
2914            public boolean containsGroups(long pk) throws SystemException {
2915                    if (getGroupsSize(pk) > 0) {
2916                            return true;
2917                    }
2918                    else {
2919                            return false;
2920                    }
2921            }
2922    
2923            /**
2924             * Adds an association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2925             *
2926             * @param pk the primary key of the user group
2927             * @param groupPK the primary key of the group
2928             * @throws SystemException if a system exception occurred
2929             */
2930            public void addGroup(long pk, long groupPK) throws SystemException {
2931                    try {
2932                            addGroup.add(pk, groupPK);
2933                    }
2934                    catch (Exception e) {
2935                            throw processException(e);
2936                    }
2937                    finally {
2938                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2939                    }
2940            }
2941    
2942            /**
2943             * Adds an association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2944             *
2945             * @param pk the primary key of the user group
2946             * @param group the group
2947             * @throws SystemException if a system exception occurred
2948             */
2949            public void addGroup(long pk, com.liferay.portal.model.Group group)
2950                    throws SystemException {
2951                    try {
2952                            addGroup.add(pk, group.getPrimaryKey());
2953                    }
2954                    catch (Exception e) {
2955                            throw processException(e);
2956                    }
2957                    finally {
2958                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2959                    }
2960            }
2961    
2962            /**
2963             * Adds an association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2964             *
2965             * @param pk the primary key of the user group
2966             * @param groupPKs the primary keys of the groups
2967             * @throws SystemException if a system exception occurred
2968             */
2969            public void addGroups(long pk, long[] groupPKs) throws SystemException {
2970                    try {
2971                            for (long groupPK : groupPKs) {
2972                                    addGroup.add(pk, groupPK);
2973                            }
2974                    }
2975                    catch (Exception e) {
2976                            throw processException(e);
2977                    }
2978                    finally {
2979                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
2980                    }
2981            }
2982    
2983            /**
2984             * Adds an association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2985             *
2986             * @param pk the primary key of the user group
2987             * @param groups the groups
2988             * @throws SystemException if a system exception occurred
2989             */
2990            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
2991                    throws SystemException {
2992                    try {
2993                            for (com.liferay.portal.model.Group group : groups) {
2994                                    addGroup.add(pk, group.getPrimaryKey());
2995                            }
2996                    }
2997                    catch (Exception e) {
2998                            throw processException(e);
2999                    }
3000                    finally {
3001                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3002                    }
3003            }
3004    
3005            /**
3006             * Clears all associations between the user group and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3007             *
3008             * @param pk the primary key of the user group to clear the associated groups from
3009             * @throws SystemException if a system exception occurred
3010             */
3011            public void clearGroups(long pk) throws SystemException {
3012                    try {
3013                            clearGroups.clear(pk);
3014                    }
3015                    catch (Exception e) {
3016                            throw processException(e);
3017                    }
3018                    finally {
3019                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3020                    }
3021            }
3022    
3023            /**
3024             * Removes the association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3025             *
3026             * @param pk the primary key of the user group
3027             * @param groupPK the primary key of the group
3028             * @throws SystemException if a system exception occurred
3029             */
3030            public void removeGroup(long pk, long groupPK) throws SystemException {
3031                    try {
3032                            removeGroup.remove(pk, groupPK);
3033                    }
3034                    catch (Exception e) {
3035                            throw processException(e);
3036                    }
3037                    finally {
3038                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3039                    }
3040            }
3041    
3042            /**
3043             * Removes the association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3044             *
3045             * @param pk the primary key of the user group
3046             * @param group the group
3047             * @throws SystemException if a system exception occurred
3048             */
3049            public void removeGroup(long pk, com.liferay.portal.model.Group group)
3050                    throws SystemException {
3051                    try {
3052                            removeGroup.remove(pk, group.getPrimaryKey());
3053                    }
3054                    catch (Exception e) {
3055                            throw processException(e);
3056                    }
3057                    finally {
3058                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3059                    }
3060            }
3061    
3062            /**
3063             * Removes the association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3064             *
3065             * @param pk the primary key of the user group
3066             * @param groupPKs the primary keys of the groups
3067             * @throws SystemException if a system exception occurred
3068             */
3069            public void removeGroups(long pk, long[] groupPKs)
3070                    throws SystemException {
3071                    try {
3072                            for (long groupPK : groupPKs) {
3073                                    removeGroup.remove(pk, groupPK);
3074                            }
3075                    }
3076                    catch (Exception e) {
3077                            throw processException(e);
3078                    }
3079                    finally {
3080                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3081                    }
3082            }
3083    
3084            /**
3085             * Removes the association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3086             *
3087             * @param pk the primary key of the user group
3088             * @param groups the groups
3089             * @throws SystemException if a system exception occurred
3090             */
3091            public void removeGroups(long pk,
3092                    List<com.liferay.portal.model.Group> groups) throws SystemException {
3093                    try {
3094                            for (com.liferay.portal.model.Group group : groups) {
3095                                    removeGroup.remove(pk, group.getPrimaryKey());
3096                            }
3097                    }
3098                    catch (Exception e) {
3099                            throw processException(e);
3100                    }
3101                    finally {
3102                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3103                    }
3104            }
3105    
3106            /**
3107             * Sets the groups associated with the user group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3108             *
3109             * @param pk the primary key of the user group
3110             * @param groupPKs the primary keys of the groups to be associated with the user group
3111             * @throws SystemException if a system exception occurred
3112             */
3113            public void setGroups(long pk, long[] groupPKs) throws SystemException {
3114                    try {
3115                            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
3116    
3117                            List<com.liferay.portal.model.Group> groups = getGroups(pk);
3118    
3119                            for (com.liferay.portal.model.Group group : groups) {
3120                                    if (!groupPKSet.remove(group.getPrimaryKey())) {
3121                                            removeGroup.remove(pk, group.getPrimaryKey());
3122                                    }
3123                            }
3124    
3125                            for (Long groupPK : groupPKSet) {
3126                                    addGroup.add(pk, groupPK);
3127                            }
3128                    }
3129                    catch (Exception e) {
3130                            throw processException(e);
3131                    }
3132                    finally {
3133                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3134                    }
3135            }
3136    
3137            /**
3138             * Sets the groups associated with the user group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3139             *
3140             * @param pk the primary key of the user group
3141             * @param groups the groups to be associated with the user group
3142             * @throws SystemException if a system exception occurred
3143             */
3144            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
3145                    throws SystemException {
3146                    try {
3147                            long[] groupPKs = new long[groups.size()];
3148    
3149                            for (int i = 0; i < groups.size(); i++) {
3150                                    com.liferay.portal.model.Group group = groups.get(i);
3151    
3152                                    groupPKs[i] = group.getPrimaryKey();
3153                            }
3154    
3155                            setGroups(pk, groupPKs);
3156                    }
3157                    catch (Exception e) {
3158                            throw processException(e);
3159                    }
3160                    finally {
3161                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
3162                    }
3163            }
3164    
3165            /**
3166             * Returns all the teams associated with the user group.
3167             *
3168             * @param pk the primary key of the user group
3169             * @return the teams associated with the user group
3170             * @throws SystemException if a system exception occurred
3171             */
3172            public List<com.liferay.portal.model.Team> getTeams(long pk)
3173                    throws SystemException {
3174                    return getTeams(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3175            }
3176    
3177            /**
3178             * Returns a range of all the teams associated with the user group.
3179             *
3180             * <p>
3181             * 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.
3182             * </p>
3183             *
3184             * @param pk the primary key of the user group
3185             * @param start the lower bound of the range of user groups
3186             * @param end the upper bound of the range of user groups (not inclusive)
3187             * @return the range of teams associated with the user group
3188             * @throws SystemException if a system exception occurred
3189             */
3190            public List<com.liferay.portal.model.Team> getTeams(long pk, int start,
3191                    int end) throws SystemException {
3192                    return getTeams(pk, start, end, null);
3193            }
3194    
3195            public static final FinderPath FINDER_PATH_GET_TEAMS = new FinderPath(com.liferay.portal.model.impl.TeamModelImpl.ENTITY_CACHE_ENABLED,
3196                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
3197                            com.liferay.portal.model.impl.TeamImpl.class,
3198                            UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME, "getTeams",
3199                            new String[] {
3200                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3201                                    "com.liferay.portal.kernel.util.OrderByComparator"
3202                            });
3203    
3204            static {
3205                    FINDER_PATH_GET_TEAMS.setCacheKeyGeneratorCacheName(null);
3206            }
3207    
3208            /**
3209             * Returns an ordered range of all the teams associated with the user group.
3210             *
3211             * <p>
3212             * 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.
3213             * </p>
3214             *
3215             * @param pk the primary key of the user group
3216             * @param start the lower bound of the range of user groups
3217             * @param end the upper bound of the range of user groups (not inclusive)
3218             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3219             * @return the ordered range of teams associated with the user group
3220             * @throws SystemException if a system exception occurred
3221             */
3222            public List<com.liferay.portal.model.Team> getTeams(long pk, int start,
3223                    int end, OrderByComparator orderByComparator) throws SystemException {
3224                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
3225    
3226                    List<com.liferay.portal.model.Team> list = (List<com.liferay.portal.model.Team>)FinderCacheUtil.getResult(FINDER_PATH_GET_TEAMS,
3227                                    finderArgs, this);
3228    
3229                    if (list == null) {
3230                            Session session = null;
3231    
3232                            try {
3233                                    session = openSession();
3234    
3235                                    String sql = null;
3236    
3237                                    if (orderByComparator != null) {
3238                                            sql = _SQL_GETTEAMS.concat(ORDER_BY_CLAUSE)
3239                                                                               .concat(orderByComparator.getOrderBy());
3240                                    }
3241                                    else {
3242                                            sql = _SQL_GETTEAMS.concat(com.liferay.portal.model.impl.TeamModelImpl.ORDER_BY_SQL);
3243                                    }
3244    
3245                                    SQLQuery q = session.createSQLQuery(sql);
3246    
3247                                    q.addEntity("Team", com.liferay.portal.model.impl.TeamImpl.class);
3248    
3249                                    QueryPos qPos = QueryPos.getInstance(q);
3250    
3251                                    qPos.add(pk);
3252    
3253                                    list = (List<com.liferay.portal.model.Team>)QueryUtil.list(q,
3254                                                    getDialect(), start, end);
3255                            }
3256                            catch (Exception e) {
3257                                    throw processException(e);
3258                            }
3259                            finally {
3260                                    if (list == null) {
3261                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_TEAMS,
3262                                                    finderArgs);
3263                                    }
3264                                    else {
3265                                            teamPersistence.cacheResult(list);
3266    
3267                                            FinderCacheUtil.putResult(FINDER_PATH_GET_TEAMS,
3268                                                    finderArgs, list);
3269                                    }
3270    
3271                                    closeSession(session);
3272                            }
3273                    }
3274    
3275                    return list;
3276            }
3277    
3278            public static final FinderPath FINDER_PATH_GET_TEAMS_SIZE = new FinderPath(com.liferay.portal.model.impl.TeamModelImpl.ENTITY_CACHE_ENABLED,
3279                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
3280                            Long.class, UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
3281                            "getTeamsSize", new String[] { Long.class.getName() });
3282    
3283            static {
3284                    FINDER_PATH_GET_TEAMS_SIZE.setCacheKeyGeneratorCacheName(null);
3285            }
3286    
3287            /**
3288             * Returns the number of teams associated with the user group.
3289             *
3290             * @param pk the primary key of the user group
3291             * @return the number of teams associated with the user group
3292             * @throws SystemException if a system exception occurred
3293             */
3294            public int getTeamsSize(long pk) throws SystemException {
3295                    Object[] finderArgs = new Object[] { pk };
3296    
3297                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_TEAMS_SIZE,
3298                                    finderArgs, this);
3299    
3300                    if (count == null) {
3301                            Session session = null;
3302    
3303                            try {
3304                                    session = openSession();
3305    
3306                                    SQLQuery q = session.createSQLQuery(_SQL_GETTEAMSSIZE);
3307    
3308                                    q.addScalar(COUNT_COLUMN_NAME,
3309                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
3310    
3311                                    QueryPos qPos = QueryPos.getInstance(q);
3312    
3313                                    qPos.add(pk);
3314    
3315                                    count = (Long)q.uniqueResult();
3316                            }
3317                            catch (Exception e) {
3318                                    throw processException(e);
3319                            }
3320                            finally {
3321                                    if (count == null) {
3322                                            count = Long.valueOf(0);
3323                                    }
3324    
3325                                    FinderCacheUtil.putResult(FINDER_PATH_GET_TEAMS_SIZE,
3326                                            finderArgs, count);
3327    
3328                                    closeSession(session);
3329                            }
3330                    }
3331    
3332                    return count.intValue();
3333            }
3334    
3335            public static final FinderPath FINDER_PATH_CONTAINS_TEAM = new FinderPath(com.liferay.portal.model.impl.TeamModelImpl.ENTITY_CACHE_ENABLED,
3336                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
3337                            Boolean.class,
3338                            UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
3339                            "containsTeam",
3340                            new String[] { Long.class.getName(), Long.class.getName() });
3341    
3342            /**
3343             * Returns <code>true</code> if the team is associated with the user group.
3344             *
3345             * @param pk the primary key of the user group
3346             * @param teamPK the primary key of the team
3347             * @return <code>true</code> if the team is associated with the user group; <code>false</code> otherwise
3348             * @throws SystemException if a system exception occurred
3349             */
3350            public boolean containsTeam(long pk, long teamPK) throws SystemException {
3351                    Object[] finderArgs = new Object[] { pk, teamPK };
3352    
3353                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_TEAM,
3354                                    finderArgs, this);
3355    
3356                    if (value == null) {
3357                            try {
3358                                    value = Boolean.valueOf(containsTeam.contains(pk, teamPK));
3359                            }
3360                            catch (Exception e) {
3361                                    throw processException(e);
3362                            }
3363                            finally {
3364                                    if (value == null) {
3365                                            value = Boolean.FALSE;
3366                                    }
3367    
3368                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_TEAM,
3369                                            finderArgs, value);
3370                            }
3371                    }
3372    
3373                    return value.booleanValue();
3374            }
3375    
3376            /**
3377             * Returns <code>true</code> if the user group has any teams associated with it.
3378             *
3379             * @param pk the primary key of the user group to check for associations with teams
3380             * @return <code>true</code> if the user group has any teams associated with it; <code>false</code> otherwise
3381             * @throws SystemException if a system exception occurred
3382             */
3383            public boolean containsTeams(long pk) throws SystemException {
3384                    if (getTeamsSize(pk) > 0) {
3385                            return true;
3386                    }
3387                    else {
3388                            return false;
3389                    }
3390            }
3391    
3392            /**
3393             * Adds an association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3394             *
3395             * @param pk the primary key of the user group
3396             * @param teamPK the primary key of the team
3397             * @throws SystemException if a system exception occurred
3398             */
3399            public void addTeam(long pk, long teamPK) throws SystemException {
3400                    try {
3401                            addTeam.add(pk, teamPK);
3402                    }
3403                    catch (Exception e) {
3404                            throw processException(e);
3405                    }
3406                    finally {
3407                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3408                    }
3409            }
3410    
3411            /**
3412             * Adds an association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3413             *
3414             * @param pk the primary key of the user group
3415             * @param team the team
3416             * @throws SystemException if a system exception occurred
3417             */
3418            public void addTeam(long pk, com.liferay.portal.model.Team team)
3419                    throws SystemException {
3420                    try {
3421                            addTeam.add(pk, team.getPrimaryKey());
3422                    }
3423                    catch (Exception e) {
3424                            throw processException(e);
3425                    }
3426                    finally {
3427                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3428                    }
3429            }
3430    
3431            /**
3432             * Adds an association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3433             *
3434             * @param pk the primary key of the user group
3435             * @param teamPKs the primary keys of the teams
3436             * @throws SystemException if a system exception occurred
3437             */
3438            public void addTeams(long pk, long[] teamPKs) throws SystemException {
3439                    try {
3440                            for (long teamPK : teamPKs) {
3441                                    addTeam.add(pk, teamPK);
3442                            }
3443                    }
3444                    catch (Exception e) {
3445                            throw processException(e);
3446                    }
3447                    finally {
3448                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3449                    }
3450            }
3451    
3452            /**
3453             * Adds an association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3454             *
3455             * @param pk the primary key of the user group
3456             * @param teams the teams
3457             * @throws SystemException if a system exception occurred
3458             */
3459            public void addTeams(long pk, List<com.liferay.portal.model.Team> teams)
3460                    throws SystemException {
3461                    try {
3462                            for (com.liferay.portal.model.Team team : teams) {
3463                                    addTeam.add(pk, team.getPrimaryKey());
3464                            }
3465                    }
3466                    catch (Exception e) {
3467                            throw processException(e);
3468                    }
3469                    finally {
3470                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3471                    }
3472            }
3473    
3474            /**
3475             * Clears all associations between the user group and its teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3476             *
3477             * @param pk the primary key of the user group to clear the associated teams from
3478             * @throws SystemException if a system exception occurred
3479             */
3480            public void clearTeams(long pk) throws SystemException {
3481                    try {
3482                            clearTeams.clear(pk);
3483                    }
3484                    catch (Exception e) {
3485                            throw processException(e);
3486                    }
3487                    finally {
3488                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3489                    }
3490            }
3491    
3492            /**
3493             * Removes the association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3494             *
3495             * @param pk the primary key of the user group
3496             * @param teamPK the primary key of the team
3497             * @throws SystemException if a system exception occurred
3498             */
3499            public void removeTeam(long pk, long teamPK) throws SystemException {
3500                    try {
3501                            removeTeam.remove(pk, teamPK);
3502                    }
3503                    catch (Exception e) {
3504                            throw processException(e);
3505                    }
3506                    finally {
3507                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3508                    }
3509            }
3510    
3511            /**
3512             * Removes the association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3513             *
3514             * @param pk the primary key of the user group
3515             * @param team the team
3516             * @throws SystemException if a system exception occurred
3517             */
3518            public void removeTeam(long pk, com.liferay.portal.model.Team team)
3519                    throws SystemException {
3520                    try {
3521                            removeTeam.remove(pk, team.getPrimaryKey());
3522                    }
3523                    catch (Exception e) {
3524                            throw processException(e);
3525                    }
3526                    finally {
3527                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3528                    }
3529            }
3530    
3531            /**
3532             * Removes the association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3533             *
3534             * @param pk the primary key of the user group
3535             * @param teamPKs the primary keys of the teams
3536             * @throws SystemException if a system exception occurred
3537             */
3538            public void removeTeams(long pk, long[] teamPKs) throws SystemException {
3539                    try {
3540                            for (long teamPK : teamPKs) {
3541                                    removeTeam.remove(pk, teamPK);
3542                            }
3543                    }
3544                    catch (Exception e) {
3545                            throw processException(e);
3546                    }
3547                    finally {
3548                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3549                    }
3550            }
3551    
3552            /**
3553             * Removes the association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3554             *
3555             * @param pk the primary key of the user group
3556             * @param teams the teams
3557             * @throws SystemException if a system exception occurred
3558             */
3559            public void removeTeams(long pk, List<com.liferay.portal.model.Team> teams)
3560                    throws SystemException {
3561                    try {
3562                            for (com.liferay.portal.model.Team team : teams) {
3563                                    removeTeam.remove(pk, team.getPrimaryKey());
3564                            }
3565                    }
3566                    catch (Exception e) {
3567                            throw processException(e);
3568                    }
3569                    finally {
3570                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3571                    }
3572            }
3573    
3574            /**
3575             * Sets the teams associated with the user group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3576             *
3577             * @param pk the primary key of the user group
3578             * @param teamPKs the primary keys of the teams to be associated with the user group
3579             * @throws SystemException if a system exception occurred
3580             */
3581            public void setTeams(long pk, long[] teamPKs) throws SystemException {
3582                    try {
3583                            Set<Long> teamPKSet = SetUtil.fromArray(teamPKs);
3584    
3585                            List<com.liferay.portal.model.Team> teams = getTeams(pk);
3586    
3587                            for (com.liferay.portal.model.Team team : teams) {
3588                                    if (!teamPKSet.remove(team.getPrimaryKey())) {
3589                                            removeTeam.remove(pk, team.getPrimaryKey());
3590                                    }
3591                            }
3592    
3593                            for (Long teamPK : teamPKSet) {
3594                                    addTeam.add(pk, teamPK);
3595                            }
3596                    }
3597                    catch (Exception e) {
3598                            throw processException(e);
3599                    }
3600                    finally {
3601                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3602                    }
3603            }
3604    
3605            /**
3606             * Sets the teams associated with the user group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3607             *
3608             * @param pk the primary key of the user group
3609             * @param teams the teams to be associated with the user group
3610             * @throws SystemException if a system exception occurred
3611             */
3612            public void setTeams(long pk, List<com.liferay.portal.model.Team> teams)
3613                    throws SystemException {
3614                    try {
3615                            long[] teamPKs = new long[teams.size()];
3616    
3617                            for (int i = 0; i < teams.size(); i++) {
3618                                    com.liferay.portal.model.Team team = teams.get(i);
3619    
3620                                    teamPKs[i] = team.getPrimaryKey();
3621                            }
3622    
3623                            setTeams(pk, teamPKs);
3624                    }
3625                    catch (Exception e) {
3626                            throw processException(e);
3627                    }
3628                    finally {
3629                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
3630                    }
3631            }
3632    
3633            /**
3634             * Returns all the users associated with the user group.
3635             *
3636             * @param pk the primary key of the user group
3637             * @return the users associated with the user group
3638             * @throws SystemException if a system exception occurred
3639             */
3640            public List<com.liferay.portal.model.User> getUsers(long pk)
3641                    throws SystemException {
3642                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3643            }
3644    
3645            /**
3646             * Returns a range of all the users associated with the user group.
3647             *
3648             * <p>
3649             * 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.
3650             * </p>
3651             *
3652             * @param pk the primary key of the user group
3653             * @param start the lower bound of the range of user groups
3654             * @param end the upper bound of the range of user groups (not inclusive)
3655             * @return the range of users associated with the user group
3656             * @throws SystemException if a system exception occurred
3657             */
3658            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3659                    int end) throws SystemException {
3660                    return getUsers(pk, start, end, null);
3661            }
3662    
3663            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3664                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
3665                            com.liferay.portal.model.impl.UserImpl.class,
3666                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
3667                            new String[] {
3668                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3669                                    "com.liferay.portal.kernel.util.OrderByComparator"
3670                            });
3671    
3672            static {
3673                    FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
3674            }
3675    
3676            /**
3677             * Returns an ordered range of all the users associated with the user group.
3678             *
3679             * <p>
3680             * 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.
3681             * </p>
3682             *
3683             * @param pk the primary key of the user group
3684             * @param start the lower bound of the range of user groups
3685             * @param end the upper bound of the range of user groups (not inclusive)
3686             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3687             * @return the ordered range of users associated with the user group
3688             * @throws SystemException if a system exception occurred
3689             */
3690            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3691                    int end, OrderByComparator orderByComparator) throws SystemException {
3692                    Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
3693    
3694                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
3695                                    finderArgs, this);
3696    
3697                    if (list == null) {
3698                            Session session = null;
3699    
3700                            try {
3701                                    session = openSession();
3702    
3703                                    String sql = null;
3704    
3705                                    if (orderByComparator != null) {
3706                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
3707                                                                               .concat(orderByComparator.getOrderBy());
3708                                    }
3709                                    else {
3710                                            sql = _SQL_GETUSERS;
3711                                    }
3712    
3713                                    SQLQuery q = session.createSQLQuery(sql);
3714    
3715                                    q.addEntity("User_",
3716                                            com.liferay.portal.model.impl.UserImpl.class);
3717    
3718                                    QueryPos qPos = QueryPos.getInstance(q);
3719    
3720                                    qPos.add(pk);
3721    
3722                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
3723                                                    getDialect(), start, end);
3724                            }
3725                            catch (Exception e) {
3726                                    throw processException(e);
3727                            }
3728                            finally {
3729                                    if (list == null) {
3730                                            FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
3731                                                    finderArgs);
3732                                    }
3733                                    else {
3734                                            userPersistence.cacheResult(list);
3735    
3736                                            FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
3737                                                    finderArgs, list);
3738                                    }
3739    
3740                                    closeSession(session);
3741                            }
3742                    }
3743    
3744                    return list;
3745            }
3746    
3747            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3748                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
3749                            Long.class, UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
3750                            "getUsersSize", new String[] { Long.class.getName() });
3751    
3752            static {
3753                    FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
3754            }
3755    
3756            /**
3757             * Returns the number of users associated with the user group.
3758             *
3759             * @param pk the primary key of the user group
3760             * @return the number of users associated with the user group
3761             * @throws SystemException if a system exception occurred
3762             */
3763            public int getUsersSize(long pk) throws SystemException {
3764                    Object[] finderArgs = new Object[] { pk };
3765    
3766                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
3767                                    finderArgs, this);
3768    
3769                    if (count == null) {
3770                            Session session = null;
3771    
3772                            try {
3773                                    session = openSession();
3774    
3775                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
3776    
3777                                    q.addScalar(COUNT_COLUMN_NAME,
3778                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
3779    
3780                                    QueryPos qPos = QueryPos.getInstance(q);
3781    
3782                                    qPos.add(pk);
3783    
3784                                    count = (Long)q.uniqueResult();
3785                            }
3786                            catch (Exception e) {
3787                                    throw processException(e);
3788                            }
3789                            finally {
3790                                    if (count == null) {
3791                                            count = Long.valueOf(0);
3792                                    }
3793    
3794                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
3795                                            finderArgs, count);
3796    
3797                                    closeSession(session);
3798                            }
3799                    }
3800    
3801                    return count.intValue();
3802            }
3803    
3804            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3805                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
3806                            Boolean.class,
3807                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
3808                            "containsUser",
3809                            new String[] { Long.class.getName(), Long.class.getName() });
3810    
3811            /**
3812             * Returns <code>true</code> if the user is associated with the user group.
3813             *
3814             * @param pk the primary key of the user group
3815             * @param userPK the primary key of the user
3816             * @return <code>true</code> if the user is associated with the user group; <code>false</code> otherwise
3817             * @throws SystemException if a system exception occurred
3818             */
3819            public boolean containsUser(long pk, long userPK) throws SystemException {
3820                    Object[] finderArgs = new Object[] { pk, userPK };
3821    
3822                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
3823                                    finderArgs, this);
3824    
3825                    if (value == null) {
3826                            try {
3827                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
3828                            }
3829                            catch (Exception e) {
3830                                    throw processException(e);
3831                            }
3832                            finally {
3833                                    if (value == null) {
3834                                            value = Boolean.FALSE;
3835                                    }
3836    
3837                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
3838                                            finderArgs, value);
3839                            }
3840                    }
3841    
3842                    return value.booleanValue();
3843            }
3844    
3845            /**
3846             * Returns <code>true</code> if the user group has any users associated with it.
3847             *
3848             * @param pk the primary key of the user group to check for associations with users
3849             * @return <code>true</code> if the user group has any users associated with it; <code>false</code> otherwise
3850             * @throws SystemException if a system exception occurred
3851             */
3852            public boolean containsUsers(long pk) throws SystemException {
3853                    if (getUsersSize(pk) > 0) {
3854                            return true;
3855                    }
3856                    else {
3857                            return false;
3858                    }
3859            }
3860    
3861            /**
3862             * Adds an association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3863             *
3864             * @param pk the primary key of the user group
3865             * @param userPK the primary key of the user
3866             * @throws SystemException if a system exception occurred
3867             */
3868            public void addUser(long pk, long userPK) throws SystemException {
3869                    try {
3870                            addUser.add(pk, userPK);
3871                    }
3872                    catch (Exception e) {
3873                            throw processException(e);
3874                    }
3875                    finally {
3876                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3877                    }
3878            }
3879    
3880            /**
3881             * Adds an association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3882             *
3883             * @param pk the primary key of the user group
3884             * @param user the user
3885             * @throws SystemException if a system exception occurred
3886             */
3887            public void addUser(long pk, com.liferay.portal.model.User user)
3888                    throws SystemException {
3889                    try {
3890                            addUser.add(pk, user.getPrimaryKey());
3891                    }
3892                    catch (Exception e) {
3893                            throw processException(e);
3894                    }
3895                    finally {
3896                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3897                    }
3898            }
3899    
3900            /**
3901             * Adds an association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3902             *
3903             * @param pk the primary key of the user group
3904             * @param userPKs the primary keys of the users
3905             * @throws SystemException if a system exception occurred
3906             */
3907            public void addUsers(long pk, long[] userPKs) throws SystemException {
3908                    try {
3909                            for (long userPK : userPKs) {
3910                                    addUser.add(pk, userPK);
3911                            }
3912                    }
3913                    catch (Exception e) {
3914                            throw processException(e);
3915                    }
3916                    finally {
3917                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3918                    }
3919            }
3920    
3921            /**
3922             * Adds an association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3923             *
3924             * @param pk the primary key of the user group
3925             * @param users the users
3926             * @throws SystemException if a system exception occurred
3927             */
3928            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
3929                    throws SystemException {
3930                    try {
3931                            for (com.liferay.portal.model.User user : users) {
3932                                    addUser.add(pk, user.getPrimaryKey());
3933                            }
3934                    }
3935                    catch (Exception e) {
3936                            throw processException(e);
3937                    }
3938                    finally {
3939                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3940                    }
3941            }
3942    
3943            /**
3944             * Clears all associations between the user group and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3945             *
3946             * @param pk the primary key of the user group to clear the associated users from
3947             * @throws SystemException if a system exception occurred
3948             */
3949            public void clearUsers(long pk) throws SystemException {
3950                    try {
3951                            clearUsers.clear(pk);
3952                    }
3953                    catch (Exception e) {
3954                            throw processException(e);
3955                    }
3956                    finally {
3957                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3958                    }
3959            }
3960    
3961            /**
3962             * Removes the association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3963             *
3964             * @param pk the primary key of the user group
3965             * @param userPK the primary key of the user
3966             * @throws SystemException if a system exception occurred
3967             */
3968            public void removeUser(long pk, long userPK) throws SystemException {
3969                    try {
3970                            removeUser.remove(pk, userPK);
3971                    }
3972                    catch (Exception e) {
3973                            throw processException(e);
3974                    }
3975                    finally {
3976                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3977                    }
3978            }
3979    
3980            /**
3981             * Removes the association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3982             *
3983             * @param pk the primary key of the user group
3984             * @param user the user
3985             * @throws SystemException if a system exception occurred
3986             */
3987            public void removeUser(long pk, com.liferay.portal.model.User user)
3988                    throws SystemException {
3989                    try {
3990                            removeUser.remove(pk, user.getPrimaryKey());
3991                    }
3992                    catch (Exception e) {
3993                            throw processException(e);
3994                    }
3995                    finally {
3996                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
3997                    }
3998            }
3999    
4000            /**
4001             * Removes the association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4002             *
4003             * @param pk the primary key of the user group
4004             * @param userPKs the primary keys of the users
4005             * @throws SystemException if a system exception occurred
4006             */
4007            public void removeUsers(long pk, long[] userPKs) throws SystemException {
4008                    try {
4009                            for (long userPK : userPKs) {
4010                                    removeUser.remove(pk, userPK);
4011                            }
4012                    }
4013                    catch (Exception e) {
4014                            throw processException(e);
4015                    }
4016                    finally {
4017                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4018                    }
4019            }
4020    
4021            /**
4022             * Removes the association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4023             *
4024             * @param pk the primary key of the user group
4025             * @param users the users
4026             * @throws SystemException if a system exception occurred
4027             */
4028            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
4029                    throws SystemException {
4030                    try {
4031                            for (com.liferay.portal.model.User user : users) {
4032                                    removeUser.remove(pk, user.getPrimaryKey());
4033                            }
4034                    }
4035                    catch (Exception e) {
4036                            throw processException(e);
4037                    }
4038                    finally {
4039                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4040                    }
4041            }
4042    
4043            /**
4044             * Sets the users associated with the user group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4045             *
4046             * @param pk the primary key of the user group
4047             * @param userPKs the primary keys of the users to be associated with the user group
4048             * @throws SystemException if a system exception occurred
4049             */
4050            public void setUsers(long pk, long[] userPKs) throws SystemException {
4051                    try {
4052                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
4053    
4054                            List<com.liferay.portal.model.User> users = getUsers(pk);
4055    
4056                            for (com.liferay.portal.model.User user : users) {
4057                                    if (!userPKSet.remove(user.getPrimaryKey())) {
4058                                            removeUser.remove(pk, user.getPrimaryKey());
4059                                    }
4060                            }
4061    
4062                            for (Long userPK : userPKSet) {
4063                                    addUser.add(pk, userPK);
4064                            }
4065                    }
4066                    catch (Exception e) {
4067                            throw processException(e);
4068                    }
4069                    finally {
4070                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4071                    }
4072            }
4073    
4074            /**
4075             * Sets the users associated with the user group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
4076             *
4077             * @param pk the primary key of the user group
4078             * @param users the users to be associated with the user group
4079             * @throws SystemException if a system exception occurred
4080             */
4081            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
4082                    throws SystemException {
4083                    try {
4084                            long[] userPKs = new long[users.size()];
4085    
4086                            for (int i = 0; i < users.size(); i++) {
4087                                    com.liferay.portal.model.User user = users.get(i);
4088    
4089                                    userPKs[i] = user.getPrimaryKey();
4090                            }
4091    
4092                            setUsers(pk, userPKs);
4093                    }
4094                    catch (Exception e) {
4095                            throw processException(e);
4096                    }
4097                    finally {
4098                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4099                    }
4100            }
4101    
4102            /**
4103             * Initializes the user group persistence.
4104             */
4105            public void afterPropertiesSet() {
4106                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4107                                            com.liferay.portal.util.PropsUtil.get(
4108                                                    "value.object.listener.com.liferay.portal.model.UserGroup")));
4109    
4110                    if (listenerClassNames.length > 0) {
4111                            try {
4112                                    List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
4113    
4114                                    for (String listenerClassName : listenerClassNames) {
4115                                            Class<?> clazz = getClass();
4116    
4117                                            listenersList.add((ModelListener<UserGroup>)InstanceFactory.newInstance(
4118                                                            clazz.getClassLoader(), listenerClassName));
4119                                    }
4120    
4121                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4122                            }
4123                            catch (Exception e) {
4124                                    _log.error(e);
4125                            }
4126                    }
4127    
4128                    containsGroup = new ContainsGroup();
4129    
4130                    addGroup = new AddGroup();
4131                    clearGroups = new ClearGroups();
4132                    removeGroup = new RemoveGroup();
4133    
4134                    containsTeam = new ContainsTeam();
4135    
4136                    addTeam = new AddTeam();
4137                    clearTeams = new ClearTeams();
4138                    removeTeam = new RemoveTeam();
4139    
4140                    containsUser = new ContainsUser();
4141    
4142                    addUser = new AddUser();
4143                    clearUsers = new ClearUsers();
4144                    removeUser = new RemoveUser();
4145            }
4146    
4147            public void destroy() {
4148                    EntityCacheUtil.removeCache(UserGroupImpl.class.getName());
4149                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4150                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4151            }
4152    
4153            @BeanReference(type = AccountPersistence.class)
4154            protected AccountPersistence accountPersistence;
4155            @BeanReference(type = AddressPersistence.class)
4156            protected AddressPersistence addressPersistence;
4157            @BeanReference(type = BrowserTrackerPersistence.class)
4158            protected BrowserTrackerPersistence browserTrackerPersistence;
4159            @BeanReference(type = ClassNamePersistence.class)
4160            protected ClassNamePersistence classNamePersistence;
4161            @BeanReference(type = ClusterGroupPersistence.class)
4162            protected ClusterGroupPersistence clusterGroupPersistence;
4163            @BeanReference(type = CompanyPersistence.class)
4164            protected CompanyPersistence companyPersistence;
4165            @BeanReference(type = ContactPersistence.class)
4166            protected ContactPersistence contactPersistence;
4167            @BeanReference(type = CountryPersistence.class)
4168            protected CountryPersistence countryPersistence;
4169            @BeanReference(type = EmailAddressPersistence.class)
4170            protected EmailAddressPersistence emailAddressPersistence;
4171            @BeanReference(type = GroupPersistence.class)
4172            protected GroupPersistence groupPersistence;
4173            @BeanReference(type = ImagePersistence.class)
4174            protected ImagePersistence imagePersistence;
4175            @BeanReference(type = LayoutPersistence.class)
4176            protected LayoutPersistence layoutPersistence;
4177            @BeanReference(type = LayoutBranchPersistence.class)
4178            protected LayoutBranchPersistence layoutBranchPersistence;
4179            @BeanReference(type = LayoutPrototypePersistence.class)
4180            protected LayoutPrototypePersistence layoutPrototypePersistence;
4181            @BeanReference(type = LayoutRevisionPersistence.class)
4182            protected LayoutRevisionPersistence layoutRevisionPersistence;
4183            @BeanReference(type = LayoutSetPersistence.class)
4184            protected LayoutSetPersistence layoutSetPersistence;
4185            @BeanReference(type = LayoutSetBranchPersistence.class)
4186            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
4187            @BeanReference(type = LayoutSetPrototypePersistence.class)
4188            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
4189            @BeanReference(type = ListTypePersistence.class)
4190            protected ListTypePersistence listTypePersistence;
4191            @BeanReference(type = LockPersistence.class)
4192            protected LockPersistence lockPersistence;
4193            @BeanReference(type = MembershipRequestPersistence.class)
4194            protected MembershipRequestPersistence membershipRequestPersistence;
4195            @BeanReference(type = OrganizationPersistence.class)
4196            protected OrganizationPersistence organizationPersistence;
4197            @BeanReference(type = OrgGroupPermissionPersistence.class)
4198            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4199            @BeanReference(type = OrgGroupRolePersistence.class)
4200            protected OrgGroupRolePersistence orgGroupRolePersistence;
4201            @BeanReference(type = OrgLaborPersistence.class)
4202            protected OrgLaborPersistence orgLaborPersistence;
4203            @BeanReference(type = PasswordPolicyPersistence.class)
4204            protected PasswordPolicyPersistence passwordPolicyPersistence;
4205            @BeanReference(type = PasswordPolicyRelPersistence.class)
4206            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4207            @BeanReference(type = PasswordTrackerPersistence.class)
4208            protected PasswordTrackerPersistence passwordTrackerPersistence;
4209            @BeanReference(type = PermissionPersistence.class)
4210            protected PermissionPersistence permissionPersistence;
4211            @BeanReference(type = PhonePersistence.class)
4212            protected PhonePersistence phonePersistence;
4213            @BeanReference(type = PluginSettingPersistence.class)
4214            protected PluginSettingPersistence pluginSettingPersistence;
4215            @BeanReference(type = PortalPreferencesPersistence.class)
4216            protected PortalPreferencesPersistence portalPreferencesPersistence;
4217            @BeanReference(type = PortletPersistence.class)
4218            protected PortletPersistence portletPersistence;
4219            @BeanReference(type = PortletItemPersistence.class)
4220            protected PortletItemPersistence portletItemPersistence;
4221            @BeanReference(type = PortletPreferencesPersistence.class)
4222            protected PortletPreferencesPersistence portletPreferencesPersistence;
4223            @BeanReference(type = RegionPersistence.class)
4224            protected RegionPersistence regionPersistence;
4225            @BeanReference(type = ReleasePersistence.class)
4226            protected ReleasePersistence releasePersistence;
4227            @BeanReference(type = RepositoryPersistence.class)
4228            protected RepositoryPersistence repositoryPersistence;
4229            @BeanReference(type = RepositoryEntryPersistence.class)
4230            protected RepositoryEntryPersistence repositoryEntryPersistence;
4231            @BeanReference(type = ResourcePersistence.class)
4232            protected ResourcePersistence resourcePersistence;
4233            @BeanReference(type = ResourceActionPersistence.class)
4234            protected ResourceActionPersistence resourceActionPersistence;
4235            @BeanReference(type = ResourceBlockPersistence.class)
4236            protected ResourceBlockPersistence resourceBlockPersistence;
4237            @BeanReference(type = ResourceBlockPermissionPersistence.class)
4238            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
4239            @BeanReference(type = ResourceCodePersistence.class)
4240            protected ResourceCodePersistence resourceCodePersistence;
4241            @BeanReference(type = ResourcePermissionPersistence.class)
4242            protected ResourcePermissionPersistence resourcePermissionPersistence;
4243            @BeanReference(type = ResourceTypePermissionPersistence.class)
4244            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
4245            @BeanReference(type = RolePersistence.class)
4246            protected RolePersistence rolePersistence;
4247            @BeanReference(type = ServiceComponentPersistence.class)
4248            protected ServiceComponentPersistence serviceComponentPersistence;
4249            @BeanReference(type = ShardPersistence.class)
4250            protected ShardPersistence shardPersistence;
4251            @BeanReference(type = SubscriptionPersistence.class)
4252            protected SubscriptionPersistence subscriptionPersistence;
4253            @BeanReference(type = TeamPersistence.class)
4254            protected TeamPersistence teamPersistence;
4255            @BeanReference(type = TicketPersistence.class)
4256            protected TicketPersistence ticketPersistence;
4257            @BeanReference(type = UserPersistence.class)
4258            protected UserPersistence userPersistence;
4259            @BeanReference(type = UserGroupPersistence.class)
4260            protected UserGroupPersistence userGroupPersistence;
4261            @BeanReference(type = UserGroupGroupRolePersistence.class)
4262            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
4263            @BeanReference(type = UserGroupRolePersistence.class)
4264            protected UserGroupRolePersistence userGroupRolePersistence;
4265            @BeanReference(type = UserIdMapperPersistence.class)
4266            protected UserIdMapperPersistence userIdMapperPersistence;
4267            @BeanReference(type = UserNotificationEventPersistence.class)
4268            protected UserNotificationEventPersistence userNotificationEventPersistence;
4269            @BeanReference(type = UserTrackerPersistence.class)
4270            protected UserTrackerPersistence userTrackerPersistence;
4271            @BeanReference(type = UserTrackerPathPersistence.class)
4272            protected UserTrackerPathPersistence userTrackerPathPersistence;
4273            @BeanReference(type = VirtualHostPersistence.class)
4274            protected VirtualHostPersistence virtualHostPersistence;
4275            @BeanReference(type = WebDAVPropsPersistence.class)
4276            protected WebDAVPropsPersistence webDAVPropsPersistence;
4277            @BeanReference(type = WebsitePersistence.class)
4278            protected WebsitePersistence websitePersistence;
4279            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
4280            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4281            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4282            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4283            protected ContainsGroup containsGroup;
4284            protected AddGroup addGroup;
4285            protected ClearGroups clearGroups;
4286            protected RemoveGroup removeGroup;
4287            protected ContainsTeam containsTeam;
4288            protected AddTeam addTeam;
4289            protected ClearTeams clearTeams;
4290            protected RemoveTeam removeTeam;
4291            protected ContainsUser containsUser;
4292            protected AddUser addUser;
4293            protected ClearUsers clearUsers;
4294            protected RemoveUser removeUser;
4295    
4296            protected class ContainsGroup {
4297                    protected ContainsGroup() {
4298                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4299                                            _SQL_CONTAINSGROUP,
4300                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4301                                            RowMapper.COUNT);
4302                    }
4303    
4304                    protected boolean contains(long userGroupId, long groupId) {
4305                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4306                                                    new Long(userGroupId), new Long(groupId)
4307                                            });
4308    
4309                            if (results.size() > 0) {
4310                                    Integer count = results.get(0);
4311    
4312                                    if (count.intValue() > 0) {
4313                                            return true;
4314                                    }
4315                            }
4316    
4317                            return false;
4318                    }
4319    
4320                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4321            }
4322    
4323            protected class AddGroup {
4324                    protected AddGroup() {
4325                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4326                                            "INSERT INTO Groups_UserGroups (userGroupId, groupId) VALUES (?, ?)",
4327                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4328                    }
4329    
4330                    protected void add(long userGroupId, long groupId)
4331                            throws SystemException {
4332                            if (!containsGroup.contains(userGroupId, groupId)) {
4333                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4334    
4335                                    for (ModelListener<UserGroup> listener : listeners) {
4336                                            listener.onBeforeAddAssociation(userGroupId,
4337                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4338                                    }
4339    
4340                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4341                                            listener.onBeforeAddAssociation(groupId,
4342                                                    UserGroup.class.getName(), userGroupId);
4343                                    }
4344    
4345                                    _sqlUpdate.update(new Object[] {
4346                                                    new Long(userGroupId), new Long(groupId)
4347                                            });
4348    
4349                                    for (ModelListener<UserGroup> listener : listeners) {
4350                                            listener.onAfterAddAssociation(userGroupId,
4351                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4352                                    }
4353    
4354                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4355                                            listener.onAfterAddAssociation(groupId,
4356                                                    UserGroup.class.getName(), userGroupId);
4357                                    }
4358                            }
4359                    }
4360    
4361                    private SqlUpdate _sqlUpdate;
4362            }
4363    
4364            protected class ClearGroups {
4365                    protected ClearGroups() {
4366                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4367                                            "DELETE FROM Groups_UserGroups WHERE userGroupId = ?",
4368                                            new int[] { java.sql.Types.BIGINT });
4369                    }
4370    
4371                    protected void clear(long userGroupId) throws SystemException {
4372                            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4373    
4374                            List<com.liferay.portal.model.Group> groups = null;
4375    
4376                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4377                                    groups = getGroups(userGroupId);
4378    
4379                                    for (com.liferay.portal.model.Group group : groups) {
4380                                            for (ModelListener<UserGroup> listener : listeners) {
4381                                                    listener.onBeforeRemoveAssociation(userGroupId,
4382                                                            com.liferay.portal.model.Group.class.getName(),
4383                                                            group.getPrimaryKey());
4384                                            }
4385    
4386                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4387                                                    listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4388                                                            UserGroup.class.getName(), userGroupId);
4389                                            }
4390                                    }
4391                            }
4392    
4393                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
4394    
4395                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4396                                    for (com.liferay.portal.model.Group group : groups) {
4397                                            for (ModelListener<UserGroup> listener : listeners) {
4398                                                    listener.onAfterRemoveAssociation(userGroupId,
4399                                                            com.liferay.portal.model.Group.class.getName(),
4400                                                            group.getPrimaryKey());
4401                                            }
4402    
4403                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4404                                                    listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4405                                                            UserGroup.class.getName(), userGroupId);
4406                                            }
4407                                    }
4408                            }
4409                    }
4410    
4411                    private SqlUpdate _sqlUpdate;
4412            }
4413    
4414            protected class RemoveGroup {
4415                    protected RemoveGroup() {
4416                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4417                                            "DELETE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?",
4418                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4419                    }
4420    
4421                    protected void remove(long userGroupId, long groupId)
4422                            throws SystemException {
4423                            if (containsGroup.contains(userGroupId, groupId)) {
4424                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4425    
4426                                    for (ModelListener<UserGroup> listener : listeners) {
4427                                            listener.onBeforeRemoveAssociation(userGroupId,
4428                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4429                                    }
4430    
4431                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4432                                            listener.onBeforeRemoveAssociation(groupId,
4433                                                    UserGroup.class.getName(), userGroupId);
4434                                    }
4435    
4436                                    _sqlUpdate.update(new Object[] {
4437                                                    new Long(userGroupId), new Long(groupId)
4438                                            });
4439    
4440                                    for (ModelListener<UserGroup> listener : listeners) {
4441                                            listener.onAfterRemoveAssociation(userGroupId,
4442                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4443                                    }
4444    
4445                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4446                                            listener.onAfterRemoveAssociation(groupId,
4447                                                    UserGroup.class.getName(), userGroupId);
4448                                    }
4449                            }
4450                    }
4451    
4452                    private SqlUpdate _sqlUpdate;
4453            }
4454    
4455            protected class ContainsTeam {
4456                    protected ContainsTeam() {
4457                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4458                                            _SQL_CONTAINSTEAM,
4459                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4460                                            RowMapper.COUNT);
4461                    }
4462    
4463                    protected boolean contains(long userGroupId, long teamId) {
4464                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4465                                                    new Long(userGroupId), new Long(teamId)
4466                                            });
4467    
4468                            if (results.size() > 0) {
4469                                    Integer count = results.get(0);
4470    
4471                                    if (count.intValue() > 0) {
4472                                            return true;
4473                                    }
4474                            }
4475    
4476                            return false;
4477                    }
4478    
4479                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4480            }
4481    
4482            protected class AddTeam {
4483                    protected AddTeam() {
4484                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4485                                            "INSERT INTO UserGroups_Teams (userGroupId, teamId) VALUES (?, ?)",
4486                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4487                    }
4488    
4489                    protected void add(long userGroupId, long teamId)
4490                            throws SystemException {
4491                            if (!containsTeam.contains(userGroupId, teamId)) {
4492                                    ModelListener<com.liferay.portal.model.Team>[] teamListeners = teamPersistence.getListeners();
4493    
4494                                    for (ModelListener<UserGroup> listener : listeners) {
4495                                            listener.onBeforeAddAssociation(userGroupId,
4496                                                    com.liferay.portal.model.Team.class.getName(), teamId);
4497                                    }
4498    
4499                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
4500                                            listener.onBeforeAddAssociation(teamId,
4501                                                    UserGroup.class.getName(), userGroupId);
4502                                    }
4503    
4504                                    _sqlUpdate.update(new Object[] {
4505                                                    new Long(userGroupId), new Long(teamId)
4506                                            });
4507    
4508                                    for (ModelListener<UserGroup> listener : listeners) {
4509                                            listener.onAfterAddAssociation(userGroupId,
4510                                                    com.liferay.portal.model.Team.class.getName(), teamId);
4511                                    }
4512    
4513                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
4514                                            listener.onAfterAddAssociation(teamId,
4515                                                    UserGroup.class.getName(), userGroupId);
4516                                    }
4517                            }
4518                    }
4519    
4520                    private SqlUpdate _sqlUpdate;
4521            }
4522    
4523            protected class ClearTeams {
4524                    protected ClearTeams() {
4525                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4526                                            "DELETE FROM UserGroups_Teams WHERE userGroupId = ?",
4527                                            new int[] { java.sql.Types.BIGINT });
4528                    }
4529    
4530                    protected void clear(long userGroupId) throws SystemException {
4531                            ModelListener<com.liferay.portal.model.Team>[] teamListeners = teamPersistence.getListeners();
4532    
4533                            List<com.liferay.portal.model.Team> teams = null;
4534    
4535                            if ((listeners.length > 0) || (teamListeners.length > 0)) {
4536                                    teams = getTeams(userGroupId);
4537    
4538                                    for (com.liferay.portal.model.Team team : teams) {
4539                                            for (ModelListener<UserGroup> listener : listeners) {
4540                                                    listener.onBeforeRemoveAssociation(userGroupId,
4541                                                            com.liferay.portal.model.Team.class.getName(),
4542                                                            team.getPrimaryKey());
4543                                            }
4544    
4545                                            for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
4546                                                    listener.onBeforeRemoveAssociation(team.getPrimaryKey(),
4547                                                            UserGroup.class.getName(), userGroupId);
4548                                            }
4549                                    }
4550                            }
4551    
4552                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
4553    
4554                            if ((listeners.length > 0) || (teamListeners.length > 0)) {
4555                                    for (com.liferay.portal.model.Team team : teams) {
4556                                            for (ModelListener<UserGroup> listener : listeners) {
4557                                                    listener.onAfterRemoveAssociation(userGroupId,
4558                                                            com.liferay.portal.model.Team.class.getName(),
4559                                                            team.getPrimaryKey());
4560                                            }
4561    
4562                                            for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
4563                                                    listener.onAfterRemoveAssociation(team.getPrimaryKey(),
4564                                                            UserGroup.class.getName(), userGroupId);
4565                                            }
4566                                    }
4567                            }
4568                    }
4569    
4570                    private SqlUpdate _sqlUpdate;
4571            }
4572    
4573            protected class RemoveTeam {
4574                    protected RemoveTeam() {
4575                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4576                                            "DELETE FROM UserGroups_Teams WHERE userGroupId = ? AND teamId = ?",
4577                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4578                    }
4579    
4580                    protected void remove(long userGroupId, long teamId)
4581                            throws SystemException {
4582                            if (containsTeam.contains(userGroupId, teamId)) {
4583                                    ModelListener<com.liferay.portal.model.Team>[] teamListeners = teamPersistence.getListeners();
4584    
4585                                    for (ModelListener<UserGroup> listener : listeners) {
4586                                            listener.onBeforeRemoveAssociation(userGroupId,
4587                                                    com.liferay.portal.model.Team.class.getName(), teamId);
4588                                    }
4589    
4590                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
4591                                            listener.onBeforeRemoveAssociation(teamId,
4592                                                    UserGroup.class.getName(), userGroupId);
4593                                    }
4594    
4595                                    _sqlUpdate.update(new Object[] {
4596                                                    new Long(userGroupId), new Long(teamId)
4597                                            });
4598    
4599                                    for (ModelListener<UserGroup> listener : listeners) {
4600                                            listener.onAfterRemoveAssociation(userGroupId,
4601                                                    com.liferay.portal.model.Team.class.getName(), teamId);
4602                                    }
4603    
4604                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
4605                                            listener.onAfterRemoveAssociation(teamId,
4606                                                    UserGroup.class.getName(), userGroupId);
4607                                    }
4608                            }
4609                    }
4610    
4611                    private SqlUpdate _sqlUpdate;
4612            }
4613    
4614            protected class ContainsUser {
4615                    protected ContainsUser() {
4616                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4617                                            _SQL_CONTAINSUSER,
4618                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4619                                            RowMapper.COUNT);
4620                    }
4621    
4622                    protected boolean contains(long userGroupId, long userId) {
4623                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4624                                                    new Long(userGroupId), new Long(userId)
4625                                            });
4626    
4627                            if (results.size() > 0) {
4628                                    Integer count = results.get(0);
4629    
4630                                    if (count.intValue() > 0) {
4631                                            return true;
4632                                    }
4633                            }
4634    
4635                            return false;
4636                    }
4637    
4638                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4639            }
4640    
4641            protected class AddUser {
4642                    protected AddUser() {
4643                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4644                                            "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
4645                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4646                    }
4647    
4648                    protected void add(long userGroupId, long userId)
4649                            throws SystemException {
4650                            if (!containsUser.contains(userGroupId, userId)) {
4651                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4652    
4653                                    for (ModelListener<UserGroup> listener : listeners) {
4654                                            listener.onBeforeAddAssociation(userGroupId,
4655                                                    com.liferay.portal.model.User.class.getName(), userId);
4656                                    }
4657    
4658                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4659                                            listener.onBeforeAddAssociation(userId,
4660                                                    UserGroup.class.getName(), userGroupId);
4661                                    }
4662    
4663                                    _sqlUpdate.update(new Object[] {
4664                                                    new Long(userGroupId), new Long(userId)
4665                                            });
4666    
4667                                    for (ModelListener<UserGroup> listener : listeners) {
4668                                            listener.onAfterAddAssociation(userGroupId,
4669                                                    com.liferay.portal.model.User.class.getName(), userId);
4670                                    }
4671    
4672                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4673                                            listener.onAfterAddAssociation(userId,
4674                                                    UserGroup.class.getName(), userGroupId);
4675                                    }
4676                            }
4677                    }
4678    
4679                    private SqlUpdate _sqlUpdate;
4680            }
4681    
4682            protected class ClearUsers {
4683                    protected ClearUsers() {
4684                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4685                                            "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
4686                                            new int[] { java.sql.Types.BIGINT });
4687                    }
4688    
4689                    protected void clear(long userGroupId) throws SystemException {
4690                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4691    
4692                            List<com.liferay.portal.model.User> users = null;
4693    
4694                            if ((listeners.length > 0) || (userListeners.length > 0)) {
4695                                    users = getUsers(userGroupId);
4696    
4697                                    for (com.liferay.portal.model.User user : users) {
4698                                            for (ModelListener<UserGroup> listener : listeners) {
4699                                                    listener.onBeforeRemoveAssociation(userGroupId,
4700                                                            com.liferay.portal.model.User.class.getName(),
4701                                                            user.getPrimaryKey());
4702                                            }
4703    
4704                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4705                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4706                                                            UserGroup.class.getName(), userGroupId);
4707                                            }
4708                                    }
4709                            }
4710    
4711                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
4712    
4713                            if ((listeners.length > 0) || (userListeners.length > 0)) {
4714                                    for (com.liferay.portal.model.User user : users) {
4715                                            for (ModelListener<UserGroup> listener : listeners) {
4716                                                    listener.onAfterRemoveAssociation(userGroupId,
4717                                                            com.liferay.portal.model.User.class.getName(),
4718                                                            user.getPrimaryKey());
4719                                            }
4720    
4721                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4722                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
4723                                                            UserGroup.class.getName(), userGroupId);
4724                                            }
4725                                    }
4726                            }
4727                    }
4728    
4729                    private SqlUpdate _sqlUpdate;
4730            }
4731    
4732            protected class RemoveUser {
4733                    protected RemoveUser() {
4734                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4735                                            "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
4736                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4737                    }
4738    
4739                    protected void remove(long userGroupId, long userId)
4740                            throws SystemException {
4741                            if (containsUser.contains(userGroupId, userId)) {
4742                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4743    
4744                                    for (ModelListener<UserGroup> listener : listeners) {
4745                                            listener.onBeforeRemoveAssociation(userGroupId,
4746                                                    com.liferay.portal.model.User.class.getName(), userId);
4747                                    }
4748    
4749                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4750                                            listener.onBeforeRemoveAssociation(userId,
4751                                                    UserGroup.class.getName(), userGroupId);
4752                                    }
4753    
4754                                    _sqlUpdate.update(new Object[] {
4755                                                    new Long(userGroupId), new Long(userId)
4756                                            });
4757    
4758                                    for (ModelListener<UserGroup> listener : listeners) {
4759                                            listener.onAfterRemoveAssociation(userGroupId,
4760                                                    com.liferay.portal.model.User.class.getName(), userId);
4761                                    }
4762    
4763                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4764                                            listener.onAfterRemoveAssociation(userId,
4765                                                    UserGroup.class.getName(), userGroupId);
4766                                    }
4767                            }
4768                    }
4769    
4770                    private SqlUpdate _sqlUpdate;
4771            }
4772    
4773            private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
4774            private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
4775            private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
4776            private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
4777            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_UserGroups ON (Groups_UserGroups.groupId = Group_.groupId) WHERE (Groups_UserGroups.userGroupId = ?)";
4778            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ?";
4779            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?";
4780            private static final String _SQL_GETTEAMS = "SELECT {Team.*} FROM Team INNER JOIN UserGroups_Teams ON (UserGroups_Teams.teamId = Team.teamId) WHERE (UserGroups_Teams.userGroupId = ?)";
4781            private static final String _SQL_GETTEAMSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE userGroupId = ?";
4782            private static final String _SQL_CONTAINSTEAM = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE userGroupId = ? AND teamId = ?";
4783            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
4784            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
4785            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?";
4786            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
4787            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
4788            private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
4789            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
4790            private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
4791            private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
4792            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = ?)";
4793            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "userGroup.userGroupId";
4794            private static final String _FILTER_SQL_SELECT_USERGROUP_WHERE = "SELECT DISTINCT {userGroup.*} FROM UserGroup userGroup WHERE ";
4795            private static final String _FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1 =
4796                    "SELECT {UserGroup.*} FROM (SELECT DISTINCT userGroup.userGroupId FROM UserGroup userGroup WHERE ";
4797            private static final String _FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2 =
4798                    ") TEMP_TABLE INNER JOIN UserGroup ON TEMP_TABLE.userGroupId = UserGroup.userGroupId";
4799            private static final String _FILTER_SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(DISTINCT userGroup.userGroupId) AS COUNT_VALUE FROM UserGroup userGroup WHERE ";
4800            private static final String _FILTER_ENTITY_ALIAS = "userGroup";
4801            private static final String _FILTER_ENTITY_TABLE = "UserGroup";
4802            private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
4803            private static final String _ORDER_BY_ENTITY_TABLE = "UserGroup.";
4804            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
4805            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
4806            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4807            private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
4808            private static UserGroup _nullUserGroup = new UserGroupImpl() {
4809                            @Override
4810                            public Object clone() {
4811                                    return this;
4812                            }
4813    
4814                            @Override
4815                            public CacheModel<UserGroup> toCacheModel() {
4816                                    return _nullUserGroupCacheModel;
4817                            }
4818                    };
4819    
4820            private static CacheModel<UserGroup> _nullUserGroupCacheModel = new CacheModel<UserGroup>() {
4821                            public UserGroup toEntityModel() {
4822                                    return _nullUserGroup;
4823                            }
4824                    };
4825    }