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