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