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