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