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