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