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