001    /**
002     * Copyright (c) 2000-2013 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.kernel.uuid.PortalUUIDUtil;
046    import com.liferay.portal.model.CacheModel;
047    import com.liferay.portal.model.ModelListener;
048    import com.liferay.portal.model.UserGroup;
049    import com.liferay.portal.model.impl.UserGroupImpl;
050    import com.liferay.portal.model.impl.UserGroupModelImpl;
051    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
052    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    import java.util.Set;
060    
061    /**
062     * The persistence implementation for the user group service.
063     *
064     * <p>
065     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see UserGroupPersistence
070     * @see UserGroupUtil
071     * @generated
072     */
073    public class UserGroupPersistenceImpl extends BasePersistenceImpl<UserGroup>
074            implements UserGroupPersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * Never modify or reference this class directly. Always use {@link UserGroupUtil} to access the user group persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = UserGroupImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
086                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
089                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
092                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
095                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097                            new String[] {
098                                    String.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_UUID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
104                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106                            new String[] { String.class.getName() },
107                            UserGroupModelImpl.UUID_COLUMN_BITMASK |
108                            UserGroupModelImpl.NAME_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
110                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112                            new String[] { String.class.getName() });
113    
114            /**
115             * Returns all the user groups where uuid = &#63;.
116             *
117             * @param uuid the uuid
118             * @return the matching user groups
119             * @throws SystemException if a system exception occurred
120             */
121            @Override
122            public List<UserGroup> findByUuid(String uuid) throws SystemException {
123                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124            }
125    
126            /**
127             * Returns a range of all the user groups where uuid = &#63;.
128             *
129             * <p>
130             * 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.
131             * </p>
132             *
133             * @param uuid the uuid
134             * @param start the lower bound of the range of user groups
135             * @param end the upper bound of the range of user groups (not inclusive)
136             * @return the range of matching user groups
137             * @throws SystemException if a system exception occurred
138             */
139            @Override
140            public List<UserGroup> findByUuid(String uuid, int start, int end)
141                    throws SystemException {
142                    return findByUuid(uuid, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the user groups where uuid = &#63;.
147             *
148             * <p>
149             * 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.
150             * </p>
151             *
152             * @param uuid the uuid
153             * @param start the lower bound of the range of user groups
154             * @param end the upper bound of the range of user groups (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching user groups
157             * @throws SystemException if a system exception occurred
158             */
159            @Override
160            public List<UserGroup> findByUuid(String uuid, 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_UUID;
170                            finderArgs = new Object[] { uuid };
171                    }
172                    else {
173                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
174                            finderArgs = new Object[] { uuid, 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 (!Validator.equals(uuid, userGroup.getUuid())) {
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                            boolean bindUuid = false;
204    
205                            if (uuid == null) {
206                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
207                            }
208                            else if (uuid.equals(StringPool.BLANK)) {
209                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
210                            }
211                            else {
212                                    bindUuid = true;
213    
214                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
215                            }
216    
217                            if (orderByComparator != null) {
218                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
219                                            orderByComparator);
220                            }
221                            else
222                             if (pagination) {
223                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
224                            }
225    
226                            String sql = query.toString();
227    
228                            Session session = null;
229    
230                            try {
231                                    session = openSession();
232    
233                                    Query q = session.createQuery(sql);
234    
235                                    QueryPos qPos = QueryPos.getInstance(q);
236    
237                                    if (bindUuid) {
238                                            qPos.add(uuid);
239                                    }
240    
241                                    if (!pagination) {
242                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
243                                                            start, end, false);
244    
245                                            Collections.sort(list);
246    
247                                            list = new UnmodifiableList<UserGroup>(list);
248                                    }
249                                    else {
250                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
251                                                            start, end);
252                                    }
253    
254                                    cacheResult(list);
255    
256                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
257                            }
258                            catch (Exception e) {
259                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
260    
261                                    throw processException(e);
262                            }
263                            finally {
264                                    closeSession(session);
265                            }
266                    }
267    
268                    return list;
269            }
270    
271            /**
272             * Returns the first user group in the ordered set where uuid = &#63;.
273             *
274             * @param uuid the uuid
275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
276             * @return the first matching user group
277             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
278             * @throws SystemException if a system exception occurred
279             */
280            @Override
281            public UserGroup findByUuid_First(String uuid,
282                    OrderByComparator orderByComparator)
283                    throws NoSuchUserGroupException, SystemException {
284                    UserGroup userGroup = fetchByUuid_First(uuid, orderByComparator);
285    
286                    if (userGroup != null) {
287                            return userGroup;
288                    }
289    
290                    StringBundler msg = new StringBundler(4);
291    
292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293    
294                    msg.append("uuid=");
295                    msg.append(uuid);
296    
297                    msg.append(StringPool.CLOSE_CURLY_BRACE);
298    
299                    throw new NoSuchUserGroupException(msg.toString());
300            }
301    
302            /**
303             * Returns the first user group in the ordered set where uuid = &#63;.
304             *
305             * @param uuid the uuid
306             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
307             * @return the first matching user group, or <code>null</code> if a matching user group could not be found
308             * @throws SystemException if a system exception occurred
309             */
310            @Override
311            public UserGroup fetchByUuid_First(String uuid,
312                    OrderByComparator orderByComparator) throws SystemException {
313                    List<UserGroup> list = findByUuid(uuid, 0, 1, orderByComparator);
314    
315                    if (!list.isEmpty()) {
316                            return list.get(0);
317                    }
318    
319                    return null;
320            }
321    
322            /**
323             * Returns the last user group in the ordered set where uuid = &#63;.
324             *
325             * @param uuid the uuid
326             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
327             * @return the last matching user group
328             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
329             * @throws SystemException if a system exception occurred
330             */
331            @Override
332            public UserGroup findByUuid_Last(String uuid,
333                    OrderByComparator orderByComparator)
334                    throws NoSuchUserGroupException, SystemException {
335                    UserGroup userGroup = fetchByUuid_Last(uuid, orderByComparator);
336    
337                    if (userGroup != null) {
338                            return userGroup;
339                    }
340    
341                    StringBundler msg = new StringBundler(4);
342    
343                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
344    
345                    msg.append("uuid=");
346                    msg.append(uuid);
347    
348                    msg.append(StringPool.CLOSE_CURLY_BRACE);
349    
350                    throw new NoSuchUserGroupException(msg.toString());
351            }
352    
353            /**
354             * Returns the last user group in the ordered set where uuid = &#63;.
355             *
356             * @param uuid the uuid
357             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
358             * @return the last matching user group, or <code>null</code> if a matching user group could not be found
359             * @throws SystemException if a system exception occurred
360             */
361            @Override
362            public UserGroup fetchByUuid_Last(String uuid,
363                    OrderByComparator orderByComparator) throws SystemException {
364                    int count = countByUuid(uuid);
365    
366                    if (count == 0) {
367                            return null;
368                    }
369    
370                    List<UserGroup> list = findByUuid(uuid, count - 1, count,
371                                    orderByComparator);
372    
373                    if (!list.isEmpty()) {
374                            return list.get(0);
375                    }
376    
377                    return null;
378            }
379    
380            /**
381             * Returns the user groups before and after the current user group in the ordered set where uuid = &#63;.
382             *
383             * @param userGroupId the primary key of the current user group
384             * @param uuid the uuid
385             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
386             * @return the previous, current, and next user group
387             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
388             * @throws SystemException if a system exception occurred
389             */
390            @Override
391            public UserGroup[] findByUuid_PrevAndNext(long userGroupId, String uuid,
392                    OrderByComparator orderByComparator)
393                    throws NoSuchUserGroupException, SystemException {
394                    UserGroup userGroup = findByPrimaryKey(userGroupId);
395    
396                    Session session = null;
397    
398                    try {
399                            session = openSession();
400    
401                            UserGroup[] array = new UserGroupImpl[3];
402    
403                            array[0] = getByUuid_PrevAndNext(session, userGroup, uuid,
404                                            orderByComparator, true);
405    
406                            array[1] = userGroup;
407    
408                            array[2] = getByUuid_PrevAndNext(session, userGroup, uuid,
409                                            orderByComparator, false);
410    
411                            return array;
412                    }
413                    catch (Exception e) {
414                            throw processException(e);
415                    }
416                    finally {
417                            closeSession(session);
418                    }
419            }
420    
421            protected UserGroup getByUuid_PrevAndNext(Session session,
422                    UserGroup userGroup, String uuid, OrderByComparator orderByComparator,
423                    boolean previous) {
424                    StringBundler query = null;
425    
426                    if (orderByComparator != null) {
427                            query = new StringBundler(6 +
428                                            (orderByComparator.getOrderByFields().length * 6));
429                    }
430                    else {
431                            query = new StringBundler(3);
432                    }
433    
434                    query.append(_SQL_SELECT_USERGROUP_WHERE);
435    
436                    boolean bindUuid = false;
437    
438                    if (uuid == null) {
439                            query.append(_FINDER_COLUMN_UUID_UUID_1);
440                    }
441                    else if (uuid.equals(StringPool.BLANK)) {
442                            query.append(_FINDER_COLUMN_UUID_UUID_3);
443                    }
444                    else {
445                            bindUuid = true;
446    
447                            query.append(_FINDER_COLUMN_UUID_UUID_2);
448                    }
449    
450                    if (orderByComparator != null) {
451                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
452    
453                            if (orderByConditionFields.length > 0) {
454                                    query.append(WHERE_AND);
455                            }
456    
457                            for (int i = 0; i < orderByConditionFields.length; i++) {
458                                    query.append(_ORDER_BY_ENTITY_ALIAS);
459                                    query.append(orderByConditionFields[i]);
460    
461                                    if ((i + 1) < orderByConditionFields.length) {
462                                            if (orderByComparator.isAscending() ^ previous) {
463                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
464                                            }
465                                            else {
466                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
467                                            }
468                                    }
469                                    else {
470                                            if (orderByComparator.isAscending() ^ previous) {
471                                                    query.append(WHERE_GREATER_THAN);
472                                            }
473                                            else {
474                                                    query.append(WHERE_LESSER_THAN);
475                                            }
476                                    }
477                            }
478    
479                            query.append(ORDER_BY_CLAUSE);
480    
481                            String[] orderByFields = orderByComparator.getOrderByFields();
482    
483                            for (int i = 0; i < orderByFields.length; i++) {
484                                    query.append(_ORDER_BY_ENTITY_ALIAS);
485                                    query.append(orderByFields[i]);
486    
487                                    if ((i + 1) < orderByFields.length) {
488                                            if (orderByComparator.isAscending() ^ previous) {
489                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
490                                            }
491                                            else {
492                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
493                                            }
494                                    }
495                                    else {
496                                            if (orderByComparator.isAscending() ^ previous) {
497                                                    query.append(ORDER_BY_ASC);
498                                            }
499                                            else {
500                                                    query.append(ORDER_BY_DESC);
501                                            }
502                                    }
503                            }
504                    }
505                    else {
506                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
507                    }
508    
509                    String sql = query.toString();
510    
511                    Query q = session.createQuery(sql);
512    
513                    q.setFirstResult(0);
514                    q.setMaxResults(2);
515    
516                    QueryPos qPos = QueryPos.getInstance(q);
517    
518                    if (bindUuid) {
519                            qPos.add(uuid);
520                    }
521    
522                    if (orderByComparator != null) {
523                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
524    
525                            for (Object value : values) {
526                                    qPos.add(value);
527                            }
528                    }
529    
530                    List<UserGroup> list = q.list();
531    
532                    if (list.size() == 2) {
533                            return list.get(1);
534                    }
535                    else {
536                            return null;
537                    }
538            }
539    
540            /**
541             * Returns all the user groups that the user has permission to view where uuid = &#63;.
542             *
543             * @param uuid the uuid
544             * @return the matching user groups that the user has permission to view
545             * @throws SystemException if a system exception occurred
546             */
547            @Override
548            public List<UserGroup> filterFindByUuid(String uuid)
549                    throws SystemException {
550                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
551            }
552    
553            /**
554             * Returns a range of all the user groups that the user has permission to view where uuid = &#63;.
555             *
556             * <p>
557             * 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.
558             * </p>
559             *
560             * @param uuid the uuid
561             * @param start the lower bound of the range of user groups
562             * @param end the upper bound of the range of user groups (not inclusive)
563             * @return the range of matching user groups that the user has permission to view
564             * @throws SystemException if a system exception occurred
565             */
566            @Override
567            public List<UserGroup> filterFindByUuid(String uuid, int start, int end)
568                    throws SystemException {
569                    return filterFindByUuid(uuid, start, end, null);
570            }
571    
572            /**
573             * Returns an ordered range of all the user groups that the user has permissions to view where uuid = &#63;.
574             *
575             * <p>
576             * 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.
577             * </p>
578             *
579             * @param uuid the uuid
580             * @param start the lower bound of the range of user groups
581             * @param end the upper bound of the range of user groups (not inclusive)
582             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
583             * @return the ordered range of matching user groups that the user has permission to view
584             * @throws SystemException if a system exception occurred
585             */
586            @Override
587            public List<UserGroup> filterFindByUuid(String uuid, int start, int end,
588                    OrderByComparator orderByComparator) throws SystemException {
589                    if (!InlineSQLHelperUtil.isEnabled()) {
590                            return findByUuid(uuid, start, end, orderByComparator);
591                    }
592    
593                    StringBundler query = null;
594    
595                    if (orderByComparator != null) {
596                            query = new StringBundler(3 +
597                                            (orderByComparator.getOrderByFields().length * 3));
598                    }
599                    else {
600                            query = new StringBundler(3);
601                    }
602    
603                    if (getDB().isSupportsInlineDistinct()) {
604                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
605                    }
606                    else {
607                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
608                    }
609    
610                    boolean bindUuid = false;
611    
612                    if (uuid == null) {
613                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
614                    }
615                    else if (uuid.equals(StringPool.BLANK)) {
616                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
617                    }
618                    else {
619                            bindUuid = true;
620    
621                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
622                    }
623    
624                    if (!getDB().isSupportsInlineDistinct()) {
625                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
626                    }
627    
628                    if (orderByComparator != null) {
629                            if (getDB().isSupportsInlineDistinct()) {
630                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
631                                            orderByComparator, true);
632                            }
633                            else {
634                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
635                                            orderByComparator, true);
636                            }
637                    }
638                    else {
639                            if (getDB().isSupportsInlineDistinct()) {
640                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
641                            }
642                            else {
643                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
644                            }
645                    }
646    
647                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
648                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
649    
650                    Session session = null;
651    
652                    try {
653                            session = openSession();
654    
655                            SQLQuery q = session.createSQLQuery(sql);
656    
657                            if (getDB().isSupportsInlineDistinct()) {
658                                    q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
659                            }
660                            else {
661                                    q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
662                            }
663    
664                            QueryPos qPos = QueryPos.getInstance(q);
665    
666                            if (bindUuid) {
667                                    qPos.add(uuid);
668                            }
669    
670                            return (List<UserGroup>)QueryUtil.list(q, getDialect(), start, end);
671                    }
672                    catch (Exception e) {
673                            throw processException(e);
674                    }
675                    finally {
676                            closeSession(session);
677                    }
678            }
679    
680            /**
681             * 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 uuid = &#63;.
682             *
683             * @param userGroupId the primary key of the current user group
684             * @param uuid the uuid
685             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
686             * @return the previous, current, and next user group
687             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
688             * @throws SystemException if a system exception occurred
689             */
690            @Override
691            public UserGroup[] filterFindByUuid_PrevAndNext(long userGroupId,
692                    String uuid, OrderByComparator orderByComparator)
693                    throws NoSuchUserGroupException, SystemException {
694                    if (!InlineSQLHelperUtil.isEnabled()) {
695                            return findByUuid_PrevAndNext(userGroupId, uuid, orderByComparator);
696                    }
697    
698                    UserGroup userGroup = findByPrimaryKey(userGroupId);
699    
700                    Session session = null;
701    
702                    try {
703                            session = openSession();
704    
705                            UserGroup[] array = new UserGroupImpl[3];
706    
707                            array[0] = filterGetByUuid_PrevAndNext(session, userGroup, uuid,
708                                            orderByComparator, true);
709    
710                            array[1] = userGroup;
711    
712                            array[2] = filterGetByUuid_PrevAndNext(session, userGroup, uuid,
713                                            orderByComparator, false);
714    
715                            return array;
716                    }
717                    catch (Exception e) {
718                            throw processException(e);
719                    }
720                    finally {
721                            closeSession(session);
722                    }
723            }
724    
725            protected UserGroup filterGetByUuid_PrevAndNext(Session session,
726                    UserGroup userGroup, String uuid, OrderByComparator orderByComparator,
727                    boolean previous) {
728                    StringBundler query = null;
729    
730                    if (orderByComparator != null) {
731                            query = new StringBundler(6 +
732                                            (orderByComparator.getOrderByFields().length * 6));
733                    }
734                    else {
735                            query = new StringBundler(3);
736                    }
737    
738                    if (getDB().isSupportsInlineDistinct()) {
739                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
740                    }
741                    else {
742                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
743                    }
744    
745                    boolean bindUuid = false;
746    
747                    if (uuid == null) {
748                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
749                    }
750                    else if (uuid.equals(StringPool.BLANK)) {
751                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
752                    }
753                    else {
754                            bindUuid = true;
755    
756                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
757                    }
758    
759                    if (!getDB().isSupportsInlineDistinct()) {
760                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
761                    }
762    
763                    if (orderByComparator != null) {
764                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
765    
766                            if (orderByConditionFields.length > 0) {
767                                    query.append(WHERE_AND);
768                            }
769    
770                            for (int i = 0; i < orderByConditionFields.length; i++) {
771                                    if (getDB().isSupportsInlineDistinct()) {
772                                            query.append(_ORDER_BY_ENTITY_ALIAS);
773                                    }
774                                    else {
775                                            query.append(_ORDER_BY_ENTITY_TABLE);
776                                    }
777    
778                                    query.append(orderByConditionFields[i]);
779    
780                                    if ((i + 1) < orderByConditionFields.length) {
781                                            if (orderByComparator.isAscending() ^ previous) {
782                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
783                                            }
784                                            else {
785                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
786                                            }
787                                    }
788                                    else {
789                                            if (orderByComparator.isAscending() ^ previous) {
790                                                    query.append(WHERE_GREATER_THAN);
791                                            }
792                                            else {
793                                                    query.append(WHERE_LESSER_THAN);
794                                            }
795                                    }
796                            }
797    
798                            query.append(ORDER_BY_CLAUSE);
799    
800                            String[] orderByFields = orderByComparator.getOrderByFields();
801    
802                            for (int i = 0; i < orderByFields.length; i++) {
803                                    if (getDB().isSupportsInlineDistinct()) {
804                                            query.append(_ORDER_BY_ENTITY_ALIAS);
805                                    }
806                                    else {
807                                            query.append(_ORDER_BY_ENTITY_TABLE);
808                                    }
809    
810                                    query.append(orderByFields[i]);
811    
812                                    if ((i + 1) < orderByFields.length) {
813                                            if (orderByComparator.isAscending() ^ previous) {
814                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
815                                            }
816                                            else {
817                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
818                                            }
819                                    }
820                                    else {
821                                            if (orderByComparator.isAscending() ^ previous) {
822                                                    query.append(ORDER_BY_ASC);
823                                            }
824                                            else {
825                                                    query.append(ORDER_BY_DESC);
826                                            }
827                                    }
828                            }
829                    }
830                    else {
831                            if (getDB().isSupportsInlineDistinct()) {
832                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
833                            }
834                            else {
835                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
836                            }
837                    }
838    
839                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
840                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
841    
842                    SQLQuery q = session.createSQLQuery(sql);
843    
844                    q.setFirstResult(0);
845                    q.setMaxResults(2);
846    
847                    if (getDB().isSupportsInlineDistinct()) {
848                            q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
849                    }
850                    else {
851                            q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
852                    }
853    
854                    QueryPos qPos = QueryPos.getInstance(q);
855    
856                    if (bindUuid) {
857                            qPos.add(uuid);
858                    }
859    
860                    if (orderByComparator != null) {
861                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
862    
863                            for (Object value : values) {
864                                    qPos.add(value);
865                            }
866                    }
867    
868                    List<UserGroup> list = q.list();
869    
870                    if (list.size() == 2) {
871                            return list.get(1);
872                    }
873                    else {
874                            return null;
875                    }
876            }
877    
878            /**
879             * Removes all the user groups where uuid = &#63; from the database.
880             *
881             * @param uuid the uuid
882             * @throws SystemException if a system exception occurred
883             */
884            @Override
885            public void removeByUuid(String uuid) throws SystemException {
886                    for (UserGroup userGroup : findByUuid(uuid, QueryUtil.ALL_POS,
887                                    QueryUtil.ALL_POS, null)) {
888                            remove(userGroup);
889                    }
890            }
891    
892            /**
893             * Returns the number of user groups where uuid = &#63;.
894             *
895             * @param uuid the uuid
896             * @return the number of matching user groups
897             * @throws SystemException if a system exception occurred
898             */
899            @Override
900            public int countByUuid(String uuid) throws SystemException {
901                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
902    
903                    Object[] finderArgs = new Object[] { uuid };
904    
905                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
906                                    this);
907    
908                    if (count == null) {
909                            StringBundler query = new StringBundler(2);
910    
911                            query.append(_SQL_COUNT_USERGROUP_WHERE);
912    
913                            boolean bindUuid = false;
914    
915                            if (uuid == null) {
916                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
917                            }
918                            else if (uuid.equals(StringPool.BLANK)) {
919                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
920                            }
921                            else {
922                                    bindUuid = true;
923    
924                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
925                            }
926    
927                            String sql = query.toString();
928    
929                            Session session = null;
930    
931                            try {
932                                    session = openSession();
933    
934                                    Query q = session.createQuery(sql);
935    
936                                    QueryPos qPos = QueryPos.getInstance(q);
937    
938                                    if (bindUuid) {
939                                            qPos.add(uuid);
940                                    }
941    
942                                    count = (Long)q.uniqueResult();
943    
944                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
945                            }
946                            catch (Exception e) {
947                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
948    
949                                    throw processException(e);
950                            }
951                            finally {
952                                    closeSession(session);
953                            }
954                    }
955    
956                    return count.intValue();
957            }
958    
959            /**
960             * Returns the number of user groups that the user has permission to view where uuid = &#63;.
961             *
962             * @param uuid the uuid
963             * @return the number of matching user groups that the user has permission to view
964             * @throws SystemException if a system exception occurred
965             */
966            @Override
967            public int filterCountByUuid(String uuid) throws SystemException {
968                    if (!InlineSQLHelperUtil.isEnabled()) {
969                            return countByUuid(uuid);
970                    }
971    
972                    StringBundler query = new StringBundler(2);
973    
974                    query.append(_FILTER_SQL_COUNT_USERGROUP_WHERE);
975    
976                    boolean bindUuid = false;
977    
978                    if (uuid == null) {
979                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
980                    }
981                    else if (uuid.equals(StringPool.BLANK)) {
982                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
983                    }
984                    else {
985                            bindUuid = true;
986    
987                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
988                    }
989    
990                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
991                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
992    
993                    Session session = null;
994    
995                    try {
996                            session = openSession();
997    
998                            SQLQuery q = session.createSQLQuery(sql);
999    
1000                            q.addScalar(COUNT_COLUMN_NAME,
1001                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1002    
1003                            QueryPos qPos = QueryPos.getInstance(q);
1004    
1005                            if (bindUuid) {
1006                                    qPos.add(uuid);
1007                            }
1008    
1009                            Long count = (Long)q.uniqueResult();
1010    
1011                            return count.intValue();
1012                    }
1013                    catch (Exception e) {
1014                            throw processException(e);
1015                    }
1016                    finally {
1017                            closeSession(session);
1018                    }
1019            }
1020    
1021            private static final String _FINDER_COLUMN_UUID_UUID_1 = "userGroup.uuid IS NULL";
1022            private static final String _FINDER_COLUMN_UUID_UUID_2 = "userGroup.uuid = ?";
1023            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(userGroup.uuid IS NULL OR userGroup.uuid = '')";
1024            private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "userGroup.uuid_ IS NULL";
1025            private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "userGroup.uuid_ = ?";
1026            private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(userGroup.uuid_ IS NULL OR userGroup.uuid_ = '')";
1027            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
1028                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
1029                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1030                            new String[] {
1031                                    String.class.getName(), Long.class.getName(),
1032                                    
1033                            Integer.class.getName(), Integer.class.getName(),
1034                                    OrderByComparator.class.getName()
1035                            });
1036            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1037                    new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
1038                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
1039                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1040                            new String[] { String.class.getName(), Long.class.getName() },
1041                            UserGroupModelImpl.UUID_COLUMN_BITMASK |
1042                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK |
1043                            UserGroupModelImpl.NAME_COLUMN_BITMASK);
1044            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
1045                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
1046                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1047                            new String[] { String.class.getName(), Long.class.getName() });
1048    
1049            /**
1050             * Returns all the user groups where uuid = &#63; and companyId = &#63;.
1051             *
1052             * @param uuid the uuid
1053             * @param companyId the company ID
1054             * @return the matching user groups
1055             * @throws SystemException if a system exception occurred
1056             */
1057            @Override
1058            public List<UserGroup> findByUuid_C(String uuid, long companyId)
1059                    throws SystemException {
1060                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1061                            QueryUtil.ALL_POS, null);
1062            }
1063    
1064            /**
1065             * Returns a range of all the user groups where uuid = &#63; and companyId = &#63;.
1066             *
1067             * <p>
1068             * 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.
1069             * </p>
1070             *
1071             * @param uuid the uuid
1072             * @param companyId the company ID
1073             * @param start the lower bound of the range of user groups
1074             * @param end the upper bound of the range of user groups (not inclusive)
1075             * @return the range of matching user groups
1076             * @throws SystemException if a system exception occurred
1077             */
1078            @Override
1079            public List<UserGroup> findByUuid_C(String uuid, long companyId, int start,
1080                    int end) throws SystemException {
1081                    return findByUuid_C(uuid, companyId, start, end, null);
1082            }
1083    
1084            /**
1085             * Returns an ordered range of all the user groups where uuid = &#63; and companyId = &#63;.
1086             *
1087             * <p>
1088             * 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.
1089             * </p>
1090             *
1091             * @param uuid the uuid
1092             * @param companyId the company ID
1093             * @param start the lower bound of the range of user groups
1094             * @param end the upper bound of the range of user groups (not inclusive)
1095             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1096             * @return the ordered range of matching user groups
1097             * @throws SystemException if a system exception occurred
1098             */
1099            @Override
1100            public List<UserGroup> findByUuid_C(String uuid, long companyId, int start,
1101                    int end, OrderByComparator orderByComparator) throws SystemException {
1102                    boolean pagination = true;
1103                    FinderPath finderPath = null;
1104                    Object[] finderArgs = null;
1105    
1106                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1107                                    (orderByComparator == null)) {
1108                            pagination = false;
1109                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1110                            finderArgs = new Object[] { uuid, companyId };
1111                    }
1112                    else {
1113                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1114                            finderArgs = new Object[] {
1115                                            uuid, companyId,
1116                                            
1117                                            start, end, orderByComparator
1118                                    };
1119                    }
1120    
1121                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
1122                                    finderArgs, this);
1123    
1124                    if ((list != null) && !list.isEmpty()) {
1125                            for (UserGroup userGroup : list) {
1126                                    if (!Validator.equals(uuid, userGroup.getUuid()) ||
1127                                                    (companyId != userGroup.getCompanyId())) {
1128                                            list = null;
1129    
1130                                            break;
1131                                    }
1132                            }
1133                    }
1134    
1135                    if (list == null) {
1136                            StringBundler query = null;
1137    
1138                            if (orderByComparator != null) {
1139                                    query = new StringBundler(4 +
1140                                                    (orderByComparator.getOrderByFields().length * 3));
1141                            }
1142                            else {
1143                                    query = new StringBundler(4);
1144                            }
1145    
1146                            query.append(_SQL_SELECT_USERGROUP_WHERE);
1147    
1148                            boolean bindUuid = false;
1149    
1150                            if (uuid == null) {
1151                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1152                            }
1153                            else if (uuid.equals(StringPool.BLANK)) {
1154                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1155                            }
1156                            else {
1157                                    bindUuid = true;
1158    
1159                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1160                            }
1161    
1162                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1163    
1164                            if (orderByComparator != null) {
1165                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1166                                            orderByComparator);
1167                            }
1168                            else
1169                             if (pagination) {
1170                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1171                            }
1172    
1173                            String sql = query.toString();
1174    
1175                            Session session = null;
1176    
1177                            try {
1178                                    session = openSession();
1179    
1180                                    Query q = session.createQuery(sql);
1181    
1182                                    QueryPos qPos = QueryPos.getInstance(q);
1183    
1184                                    if (bindUuid) {
1185                                            qPos.add(uuid);
1186                                    }
1187    
1188                                    qPos.add(companyId);
1189    
1190                                    if (!pagination) {
1191                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1192                                                            start, end, false);
1193    
1194                                            Collections.sort(list);
1195    
1196                                            list = new UnmodifiableList<UserGroup>(list);
1197                                    }
1198                                    else {
1199                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
1200                                                            start, end);
1201                                    }
1202    
1203                                    cacheResult(list);
1204    
1205                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1206                            }
1207                            catch (Exception e) {
1208                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1209    
1210                                    throw processException(e);
1211                            }
1212                            finally {
1213                                    closeSession(session);
1214                            }
1215                    }
1216    
1217                    return list;
1218            }
1219    
1220            /**
1221             * Returns the first user group in the ordered set where uuid = &#63; and companyId = &#63;.
1222             *
1223             * @param uuid the uuid
1224             * @param companyId the company ID
1225             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1226             * @return the first matching user group
1227             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
1228             * @throws SystemException if a system exception occurred
1229             */
1230            @Override
1231            public UserGroup findByUuid_C_First(String uuid, long companyId,
1232                    OrderByComparator orderByComparator)
1233                    throws NoSuchUserGroupException, SystemException {
1234                    UserGroup userGroup = fetchByUuid_C_First(uuid, companyId,
1235                                    orderByComparator);
1236    
1237                    if (userGroup != null) {
1238                            return userGroup;
1239                    }
1240    
1241                    StringBundler msg = new StringBundler(6);
1242    
1243                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1244    
1245                    msg.append("uuid=");
1246                    msg.append(uuid);
1247    
1248                    msg.append(", companyId=");
1249                    msg.append(companyId);
1250    
1251                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1252    
1253                    throw new NoSuchUserGroupException(msg.toString());
1254            }
1255    
1256            /**
1257             * Returns the first user group in the ordered set where uuid = &#63; and companyId = &#63;.
1258             *
1259             * @param uuid the uuid
1260             * @param companyId the company ID
1261             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1262             * @return the first matching user group, or <code>null</code> if a matching user group could not be found
1263             * @throws SystemException if a system exception occurred
1264             */
1265            @Override
1266            public UserGroup fetchByUuid_C_First(String uuid, long companyId,
1267                    OrderByComparator orderByComparator) throws SystemException {
1268                    List<UserGroup> list = findByUuid_C(uuid, companyId, 0, 1,
1269                                    orderByComparator);
1270    
1271                    if (!list.isEmpty()) {
1272                            return list.get(0);
1273                    }
1274    
1275                    return null;
1276            }
1277    
1278            /**
1279             * Returns the last user group in the ordered set where uuid = &#63; and companyId = &#63;.
1280             *
1281             * @param uuid the uuid
1282             * @param companyId the company ID
1283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1284             * @return the last matching user group
1285             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
1286             * @throws SystemException if a system exception occurred
1287             */
1288            @Override
1289            public UserGroup findByUuid_C_Last(String uuid, long companyId,
1290                    OrderByComparator orderByComparator)
1291                    throws NoSuchUserGroupException, SystemException {
1292                    UserGroup userGroup = fetchByUuid_C_Last(uuid, companyId,
1293                                    orderByComparator);
1294    
1295                    if (userGroup != null) {
1296                            return userGroup;
1297                    }
1298    
1299                    StringBundler msg = new StringBundler(6);
1300    
1301                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1302    
1303                    msg.append("uuid=");
1304                    msg.append(uuid);
1305    
1306                    msg.append(", companyId=");
1307                    msg.append(companyId);
1308    
1309                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1310    
1311                    throw new NoSuchUserGroupException(msg.toString());
1312            }
1313    
1314            /**
1315             * Returns the last user group in the ordered set where uuid = &#63; and companyId = &#63;.
1316             *
1317             * @param uuid the uuid
1318             * @param companyId the company ID
1319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1320             * @return the last matching user group, or <code>null</code> if a matching user group could not be found
1321             * @throws SystemException if a system exception occurred
1322             */
1323            @Override
1324            public UserGroup fetchByUuid_C_Last(String uuid, long companyId,
1325                    OrderByComparator orderByComparator) throws SystemException {
1326                    int count = countByUuid_C(uuid, companyId);
1327    
1328                    if (count == 0) {
1329                            return null;
1330                    }
1331    
1332                    List<UserGroup> list = findByUuid_C(uuid, companyId, count - 1, count,
1333                                    orderByComparator);
1334    
1335                    if (!list.isEmpty()) {
1336                            return list.get(0);
1337                    }
1338    
1339                    return null;
1340            }
1341    
1342            /**
1343             * Returns the user groups before and after the current user group in the ordered set where uuid = &#63; and companyId = &#63;.
1344             *
1345             * @param userGroupId the primary key of the current user group
1346             * @param uuid the uuid
1347             * @param companyId the company ID
1348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1349             * @return the previous, current, and next user group
1350             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
1351             * @throws SystemException if a system exception occurred
1352             */
1353            @Override
1354            public UserGroup[] findByUuid_C_PrevAndNext(long userGroupId, String uuid,
1355                    long companyId, OrderByComparator orderByComparator)
1356                    throws NoSuchUserGroupException, SystemException {
1357                    UserGroup userGroup = findByPrimaryKey(userGroupId);
1358    
1359                    Session session = null;
1360    
1361                    try {
1362                            session = openSession();
1363    
1364                            UserGroup[] array = new UserGroupImpl[3];
1365    
1366                            array[0] = getByUuid_C_PrevAndNext(session, userGroup, uuid,
1367                                            companyId, orderByComparator, true);
1368    
1369                            array[1] = userGroup;
1370    
1371                            array[2] = getByUuid_C_PrevAndNext(session, userGroup, uuid,
1372                                            companyId, orderByComparator, false);
1373    
1374                            return array;
1375                    }
1376                    catch (Exception e) {
1377                            throw processException(e);
1378                    }
1379                    finally {
1380                            closeSession(session);
1381                    }
1382            }
1383    
1384            protected UserGroup getByUuid_C_PrevAndNext(Session session,
1385                    UserGroup userGroup, String uuid, long companyId,
1386                    OrderByComparator orderByComparator, boolean previous) {
1387                    StringBundler query = null;
1388    
1389                    if (orderByComparator != null) {
1390                            query = new StringBundler(6 +
1391                                            (orderByComparator.getOrderByFields().length * 6));
1392                    }
1393                    else {
1394                            query = new StringBundler(3);
1395                    }
1396    
1397                    query.append(_SQL_SELECT_USERGROUP_WHERE);
1398    
1399                    boolean bindUuid = false;
1400    
1401                    if (uuid == null) {
1402                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1403                    }
1404                    else if (uuid.equals(StringPool.BLANK)) {
1405                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1406                    }
1407                    else {
1408                            bindUuid = true;
1409    
1410                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1411                    }
1412    
1413                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1414    
1415                    if (orderByComparator != null) {
1416                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1417    
1418                            if (orderByConditionFields.length > 0) {
1419                                    query.append(WHERE_AND);
1420                            }
1421    
1422                            for (int i = 0; i < orderByConditionFields.length; i++) {
1423                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1424                                    query.append(orderByConditionFields[i]);
1425    
1426                                    if ((i + 1) < orderByConditionFields.length) {
1427                                            if (orderByComparator.isAscending() ^ previous) {
1428                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1429                                            }
1430                                            else {
1431                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1432                                            }
1433                                    }
1434                                    else {
1435                                            if (orderByComparator.isAscending() ^ previous) {
1436                                                    query.append(WHERE_GREATER_THAN);
1437                                            }
1438                                            else {
1439                                                    query.append(WHERE_LESSER_THAN);
1440                                            }
1441                                    }
1442                            }
1443    
1444                            query.append(ORDER_BY_CLAUSE);
1445    
1446                            String[] orderByFields = orderByComparator.getOrderByFields();
1447    
1448                            for (int i = 0; i < orderByFields.length; i++) {
1449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1450                                    query.append(orderByFields[i]);
1451    
1452                                    if ((i + 1) < orderByFields.length) {
1453                                            if (orderByComparator.isAscending() ^ previous) {
1454                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1455                                            }
1456                                            else {
1457                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1458                                            }
1459                                    }
1460                                    else {
1461                                            if (orderByComparator.isAscending() ^ previous) {
1462                                                    query.append(ORDER_BY_ASC);
1463                                            }
1464                                            else {
1465                                                    query.append(ORDER_BY_DESC);
1466                                            }
1467                                    }
1468                            }
1469                    }
1470                    else {
1471                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1472                    }
1473    
1474                    String sql = query.toString();
1475    
1476                    Query q = session.createQuery(sql);
1477    
1478                    q.setFirstResult(0);
1479                    q.setMaxResults(2);
1480    
1481                    QueryPos qPos = QueryPos.getInstance(q);
1482    
1483                    if (bindUuid) {
1484                            qPos.add(uuid);
1485                    }
1486    
1487                    qPos.add(companyId);
1488    
1489                    if (orderByComparator != null) {
1490                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
1491    
1492                            for (Object value : values) {
1493                                    qPos.add(value);
1494                            }
1495                    }
1496    
1497                    List<UserGroup> list = q.list();
1498    
1499                    if (list.size() == 2) {
1500                            return list.get(1);
1501                    }
1502                    else {
1503                            return null;
1504                    }
1505            }
1506    
1507            /**
1508             * Returns all the user groups that the user has permission to view where uuid = &#63; and companyId = &#63;.
1509             *
1510             * @param uuid the uuid
1511             * @param companyId the company ID
1512             * @return the matching user groups that the user has permission to view
1513             * @throws SystemException if a system exception occurred
1514             */
1515            @Override
1516            public List<UserGroup> filterFindByUuid_C(String uuid, long companyId)
1517                    throws SystemException {
1518                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1519                            QueryUtil.ALL_POS, null);
1520            }
1521    
1522            /**
1523             * Returns a range of all the user groups that the user has permission to view where uuid = &#63; and companyId = &#63;.
1524             *
1525             * <p>
1526             * 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.
1527             * </p>
1528             *
1529             * @param uuid the uuid
1530             * @param companyId the company ID
1531             * @param start the lower bound of the range of user groups
1532             * @param end the upper bound of the range of user groups (not inclusive)
1533             * @return the range of matching user groups that the user has permission to view
1534             * @throws SystemException if a system exception occurred
1535             */
1536            @Override
1537            public List<UserGroup> filterFindByUuid_C(String uuid, long companyId,
1538                    int start, int end) throws SystemException {
1539                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1540            }
1541    
1542            /**
1543             * Returns an ordered range of all the user groups that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1544             *
1545             * <p>
1546             * 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.
1547             * </p>
1548             *
1549             * @param uuid the uuid
1550             * @param companyId the company ID
1551             * @param start the lower bound of the range of user groups
1552             * @param end the upper bound of the range of user groups (not inclusive)
1553             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1554             * @return the ordered range of matching user groups that the user has permission to view
1555             * @throws SystemException if a system exception occurred
1556             */
1557            @Override
1558            public List<UserGroup> filterFindByUuid_C(String uuid, long companyId,
1559                    int start, int end, OrderByComparator orderByComparator)
1560                    throws SystemException {
1561                    if (!InlineSQLHelperUtil.isEnabled()) {
1562                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1563                    }
1564    
1565                    StringBundler query = null;
1566    
1567                    if (orderByComparator != null) {
1568                            query = new StringBundler(4 +
1569                                            (orderByComparator.getOrderByFields().length * 3));
1570                    }
1571                    else {
1572                            query = new StringBundler(4);
1573                    }
1574    
1575                    if (getDB().isSupportsInlineDistinct()) {
1576                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
1577                    }
1578                    else {
1579                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
1580                    }
1581    
1582                    boolean bindUuid = false;
1583    
1584                    if (uuid == null) {
1585                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1586                    }
1587                    else if (uuid.equals(StringPool.BLANK)) {
1588                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1589                    }
1590                    else {
1591                            bindUuid = true;
1592    
1593                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1594                    }
1595    
1596                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1597    
1598                    if (!getDB().isSupportsInlineDistinct()) {
1599                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
1600                    }
1601    
1602                    if (orderByComparator != null) {
1603                            if (getDB().isSupportsInlineDistinct()) {
1604                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1605                                            orderByComparator, true);
1606                            }
1607                            else {
1608                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1609                                            orderByComparator, true);
1610                            }
1611                    }
1612                    else {
1613                            if (getDB().isSupportsInlineDistinct()) {
1614                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1615                            }
1616                            else {
1617                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
1618                            }
1619                    }
1620    
1621                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1622                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1623    
1624                    Session session = null;
1625    
1626                    try {
1627                            session = openSession();
1628    
1629                            SQLQuery q = session.createSQLQuery(sql);
1630    
1631                            if (getDB().isSupportsInlineDistinct()) {
1632                                    q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
1633                            }
1634                            else {
1635                                    q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
1636                            }
1637    
1638                            QueryPos qPos = QueryPos.getInstance(q);
1639    
1640                            if (bindUuid) {
1641                                    qPos.add(uuid);
1642                            }
1643    
1644                            qPos.add(companyId);
1645    
1646                            return (List<UserGroup>)QueryUtil.list(q, getDialect(), start, end);
1647                    }
1648                    catch (Exception e) {
1649                            throw processException(e);
1650                    }
1651                    finally {
1652                            closeSession(session);
1653                    }
1654            }
1655    
1656            /**
1657             * 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 uuid = &#63; and companyId = &#63;.
1658             *
1659             * @param userGroupId the primary key of the current user group
1660             * @param uuid the uuid
1661             * @param companyId the company ID
1662             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1663             * @return the previous, current, and next user group
1664             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
1665             * @throws SystemException if a system exception occurred
1666             */
1667            @Override
1668            public UserGroup[] filterFindByUuid_C_PrevAndNext(long userGroupId,
1669                    String uuid, long companyId, OrderByComparator orderByComparator)
1670                    throws NoSuchUserGroupException, SystemException {
1671                    if (!InlineSQLHelperUtil.isEnabled()) {
1672                            return findByUuid_C_PrevAndNext(userGroupId, uuid, companyId,
1673                                    orderByComparator);
1674                    }
1675    
1676                    UserGroup userGroup = findByPrimaryKey(userGroupId);
1677    
1678                    Session session = null;
1679    
1680                    try {
1681                            session = openSession();
1682    
1683                            UserGroup[] array = new UserGroupImpl[3];
1684    
1685                            array[0] = filterGetByUuid_C_PrevAndNext(session, userGroup, uuid,
1686                                            companyId, orderByComparator, true);
1687    
1688                            array[1] = userGroup;
1689    
1690                            array[2] = filterGetByUuid_C_PrevAndNext(session, userGroup, uuid,
1691                                            companyId, orderByComparator, false);
1692    
1693                            return array;
1694                    }
1695                    catch (Exception e) {
1696                            throw processException(e);
1697                    }
1698                    finally {
1699                            closeSession(session);
1700                    }
1701            }
1702    
1703            protected UserGroup filterGetByUuid_C_PrevAndNext(Session session,
1704                    UserGroup userGroup, String uuid, long companyId,
1705                    OrderByComparator orderByComparator, boolean previous) {
1706                    StringBundler query = null;
1707    
1708                    if (orderByComparator != null) {
1709                            query = new StringBundler(6 +
1710                                            (orderByComparator.getOrderByFields().length * 6));
1711                    }
1712                    else {
1713                            query = new StringBundler(3);
1714                    }
1715    
1716                    if (getDB().isSupportsInlineDistinct()) {
1717                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
1718                    }
1719                    else {
1720                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
1721                    }
1722    
1723                    boolean bindUuid = false;
1724    
1725                    if (uuid == null) {
1726                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1727                    }
1728                    else if (uuid.equals(StringPool.BLANK)) {
1729                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1730                    }
1731                    else {
1732                            bindUuid = true;
1733    
1734                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1735                    }
1736    
1737                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1738    
1739                    if (!getDB().isSupportsInlineDistinct()) {
1740                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
1741                    }
1742    
1743                    if (orderByComparator != null) {
1744                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1745    
1746                            if (orderByConditionFields.length > 0) {
1747                                    query.append(WHERE_AND);
1748                            }
1749    
1750                            for (int i = 0; i < orderByConditionFields.length; i++) {
1751                                    if (getDB().isSupportsInlineDistinct()) {
1752                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1753                                    }
1754                                    else {
1755                                            query.append(_ORDER_BY_ENTITY_TABLE);
1756                                    }
1757    
1758                                    query.append(orderByConditionFields[i]);
1759    
1760                                    if ((i + 1) < orderByConditionFields.length) {
1761                                            if (orderByComparator.isAscending() ^ previous) {
1762                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1763                                            }
1764                                            else {
1765                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1766                                            }
1767                                    }
1768                                    else {
1769                                            if (orderByComparator.isAscending() ^ previous) {
1770                                                    query.append(WHERE_GREATER_THAN);
1771                                            }
1772                                            else {
1773                                                    query.append(WHERE_LESSER_THAN);
1774                                            }
1775                                    }
1776                            }
1777    
1778                            query.append(ORDER_BY_CLAUSE);
1779    
1780                            String[] orderByFields = orderByComparator.getOrderByFields();
1781    
1782                            for (int i = 0; i < orderByFields.length; i++) {
1783                                    if (getDB().isSupportsInlineDistinct()) {
1784                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1785                                    }
1786                                    else {
1787                                            query.append(_ORDER_BY_ENTITY_TABLE);
1788                                    }
1789    
1790                                    query.append(orderByFields[i]);
1791    
1792                                    if ((i + 1) < orderByFields.length) {
1793                                            if (orderByComparator.isAscending() ^ previous) {
1794                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1795                                            }
1796                                            else {
1797                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1798                                            }
1799                                    }
1800                                    else {
1801                                            if (orderByComparator.isAscending() ^ previous) {
1802                                                    query.append(ORDER_BY_ASC);
1803                                            }
1804                                            else {
1805                                                    query.append(ORDER_BY_DESC);
1806                                            }
1807                                    }
1808                            }
1809                    }
1810                    else {
1811                            if (getDB().isSupportsInlineDistinct()) {
1812                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
1813                            }
1814                            else {
1815                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
1816                            }
1817                    }
1818    
1819                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1820                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1821    
1822                    SQLQuery q = session.createSQLQuery(sql);
1823    
1824                    q.setFirstResult(0);
1825                    q.setMaxResults(2);
1826    
1827                    if (getDB().isSupportsInlineDistinct()) {
1828                            q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
1829                    }
1830                    else {
1831                            q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
1832                    }
1833    
1834                    QueryPos qPos = QueryPos.getInstance(q);
1835    
1836                    if (bindUuid) {
1837                            qPos.add(uuid);
1838                    }
1839    
1840                    qPos.add(companyId);
1841    
1842                    if (orderByComparator != null) {
1843                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
1844    
1845                            for (Object value : values) {
1846                                    qPos.add(value);
1847                            }
1848                    }
1849    
1850                    List<UserGroup> list = q.list();
1851    
1852                    if (list.size() == 2) {
1853                            return list.get(1);
1854                    }
1855                    else {
1856                            return null;
1857                    }
1858            }
1859    
1860            /**
1861             * Removes all the user groups where uuid = &#63; and companyId = &#63; from the database.
1862             *
1863             * @param uuid the uuid
1864             * @param companyId the company ID
1865             * @throws SystemException if a system exception occurred
1866             */
1867            @Override
1868            public void removeByUuid_C(String uuid, long companyId)
1869                    throws SystemException {
1870                    for (UserGroup userGroup : findByUuid_C(uuid, companyId,
1871                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1872                            remove(userGroup);
1873                    }
1874            }
1875    
1876            /**
1877             * Returns the number of user groups where uuid = &#63; and companyId = &#63;.
1878             *
1879             * @param uuid the uuid
1880             * @param companyId the company ID
1881             * @return the number of matching user groups
1882             * @throws SystemException if a system exception occurred
1883             */
1884            @Override
1885            public int countByUuid_C(String uuid, long companyId)
1886                    throws SystemException {
1887                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1888    
1889                    Object[] finderArgs = new Object[] { uuid, companyId };
1890    
1891                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1892                                    this);
1893    
1894                    if (count == null) {
1895                            StringBundler query = new StringBundler(3);
1896    
1897                            query.append(_SQL_COUNT_USERGROUP_WHERE);
1898    
1899                            boolean bindUuid = false;
1900    
1901                            if (uuid == null) {
1902                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1903                            }
1904                            else if (uuid.equals(StringPool.BLANK)) {
1905                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1906                            }
1907                            else {
1908                                    bindUuid = true;
1909    
1910                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1911                            }
1912    
1913                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1914    
1915                            String sql = query.toString();
1916    
1917                            Session session = null;
1918    
1919                            try {
1920                                    session = openSession();
1921    
1922                                    Query q = session.createQuery(sql);
1923    
1924                                    QueryPos qPos = QueryPos.getInstance(q);
1925    
1926                                    if (bindUuid) {
1927                                            qPos.add(uuid);
1928                                    }
1929    
1930                                    qPos.add(companyId);
1931    
1932                                    count = (Long)q.uniqueResult();
1933    
1934                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1935                            }
1936                            catch (Exception e) {
1937                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1938    
1939                                    throw processException(e);
1940                            }
1941                            finally {
1942                                    closeSession(session);
1943                            }
1944                    }
1945    
1946                    return count.intValue();
1947            }
1948    
1949            /**
1950             * Returns the number of user groups that the user has permission to view where uuid = &#63; and companyId = &#63;.
1951             *
1952             * @param uuid the uuid
1953             * @param companyId the company ID
1954             * @return the number of matching user groups that the user has permission to view
1955             * @throws SystemException if a system exception occurred
1956             */
1957            @Override
1958            public int filterCountByUuid_C(String uuid, long companyId)
1959                    throws SystemException {
1960                    if (!InlineSQLHelperUtil.isEnabled()) {
1961                            return countByUuid_C(uuid, companyId);
1962                    }
1963    
1964                    StringBundler query = new StringBundler(3);
1965    
1966                    query.append(_FILTER_SQL_COUNT_USERGROUP_WHERE);
1967    
1968                    boolean bindUuid = false;
1969    
1970                    if (uuid == null) {
1971                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1972                    }
1973                    else if (uuid.equals(StringPool.BLANK)) {
1974                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1975                    }
1976                    else {
1977                            bindUuid = true;
1978    
1979                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1980                    }
1981    
1982                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1983    
1984                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1985                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1986    
1987                    Session session = null;
1988    
1989                    try {
1990                            session = openSession();
1991    
1992                            SQLQuery q = session.createSQLQuery(sql);
1993    
1994                            q.addScalar(COUNT_COLUMN_NAME,
1995                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1996    
1997                            QueryPos qPos = QueryPos.getInstance(q);
1998    
1999                            if (bindUuid) {
2000                                    qPos.add(uuid);
2001                            }
2002    
2003                            qPos.add(companyId);
2004    
2005                            Long count = (Long)q.uniqueResult();
2006    
2007                            return count.intValue();
2008                    }
2009                    catch (Exception e) {
2010                            throw processException(e);
2011                    }
2012                    finally {
2013                            closeSession(session);
2014                    }
2015            }
2016    
2017            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "userGroup.uuid IS NULL AND ";
2018            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "userGroup.uuid = ? AND ";
2019            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(userGroup.uuid IS NULL OR userGroup.uuid = '') AND ";
2020            private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "userGroup.uuid_ IS NULL AND ";
2021            private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "userGroup.uuid_ = ? AND ";
2022            private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(userGroup.uuid_ IS NULL OR userGroup.uuid_ = '') AND ";
2023            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "userGroup.companyId = ?";
2024            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2025                    new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2026                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
2027                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2028                            new String[] {
2029                                    Long.class.getName(),
2030                                    
2031                            Integer.class.getName(), Integer.class.getName(),
2032                                    OrderByComparator.class.getName()
2033                            });
2034            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2035                    new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2036                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
2037                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2038                            new String[] { Long.class.getName() },
2039                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK |
2040                            UserGroupModelImpl.NAME_COLUMN_BITMASK);
2041            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2042                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
2043                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2044                            new String[] { Long.class.getName() });
2045    
2046            /**
2047             * Returns all the user groups where companyId = &#63;.
2048             *
2049             * @param companyId the company ID
2050             * @return the matching user groups
2051             * @throws SystemException if a system exception occurred
2052             */
2053            @Override
2054            public List<UserGroup> findByCompanyId(long companyId)
2055                    throws SystemException {
2056                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2057                            null);
2058            }
2059    
2060            /**
2061             * Returns a range of all the user groups where companyId = &#63;.
2062             *
2063             * <p>
2064             * 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.
2065             * </p>
2066             *
2067             * @param companyId the company ID
2068             * @param start the lower bound of the range of user groups
2069             * @param end the upper bound of the range of user groups (not inclusive)
2070             * @return the range of matching user groups
2071             * @throws SystemException if a system exception occurred
2072             */
2073            @Override
2074            public List<UserGroup> findByCompanyId(long companyId, int start, int end)
2075                    throws SystemException {
2076                    return findByCompanyId(companyId, start, end, null);
2077            }
2078    
2079            /**
2080             * Returns an ordered range of all the user groups where companyId = &#63;.
2081             *
2082             * <p>
2083             * 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.
2084             * </p>
2085             *
2086             * @param companyId the company ID
2087             * @param start the lower bound of the range of user groups
2088             * @param end the upper bound of the range of user groups (not inclusive)
2089             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2090             * @return the ordered range of matching user groups
2091             * @throws SystemException if a system exception occurred
2092             */
2093            @Override
2094            public List<UserGroup> findByCompanyId(long companyId, int start, int end,
2095                    OrderByComparator orderByComparator) throws SystemException {
2096                    boolean pagination = true;
2097                    FinderPath finderPath = null;
2098                    Object[] finderArgs = null;
2099    
2100                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2101                                    (orderByComparator == null)) {
2102                            pagination = false;
2103                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2104                            finderArgs = new Object[] { companyId };
2105                    }
2106                    else {
2107                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2108                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2109                    }
2110    
2111                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
2112                                    finderArgs, this);
2113    
2114                    if ((list != null) && !list.isEmpty()) {
2115                            for (UserGroup userGroup : list) {
2116                                    if ((companyId != userGroup.getCompanyId())) {
2117                                            list = null;
2118    
2119                                            break;
2120                                    }
2121                            }
2122                    }
2123    
2124                    if (list == null) {
2125                            StringBundler query = null;
2126    
2127                            if (orderByComparator != null) {
2128                                    query = new StringBundler(3 +
2129                                                    (orderByComparator.getOrderByFields().length * 3));
2130                            }
2131                            else {
2132                                    query = new StringBundler(3);
2133                            }
2134    
2135                            query.append(_SQL_SELECT_USERGROUP_WHERE);
2136    
2137                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2138    
2139                            if (orderByComparator != null) {
2140                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2141                                            orderByComparator);
2142                            }
2143                            else
2144                             if (pagination) {
2145                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
2146                            }
2147    
2148                            String sql = query.toString();
2149    
2150                            Session session = null;
2151    
2152                            try {
2153                                    session = openSession();
2154    
2155                                    Query q = session.createQuery(sql);
2156    
2157                                    QueryPos qPos = QueryPos.getInstance(q);
2158    
2159                                    qPos.add(companyId);
2160    
2161                                    if (!pagination) {
2162                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
2163                                                            start, end, false);
2164    
2165                                            Collections.sort(list);
2166    
2167                                            list = new UnmodifiableList<UserGroup>(list);
2168                                    }
2169                                    else {
2170                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
2171                                                            start, end);
2172                                    }
2173    
2174                                    cacheResult(list);
2175    
2176                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2177                            }
2178                            catch (Exception e) {
2179                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2180    
2181                                    throw processException(e);
2182                            }
2183                            finally {
2184                                    closeSession(session);
2185                            }
2186                    }
2187    
2188                    return list;
2189            }
2190    
2191            /**
2192             * Returns the first user group in the ordered set where companyId = &#63;.
2193             *
2194             * @param companyId the company ID
2195             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2196             * @return the first matching user group
2197             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
2198             * @throws SystemException if a system exception occurred
2199             */
2200            @Override
2201            public UserGroup findByCompanyId_First(long companyId,
2202                    OrderByComparator orderByComparator)
2203                    throws NoSuchUserGroupException, SystemException {
2204                    UserGroup userGroup = fetchByCompanyId_First(companyId,
2205                                    orderByComparator);
2206    
2207                    if (userGroup != null) {
2208                            return userGroup;
2209                    }
2210    
2211                    StringBundler msg = new StringBundler(4);
2212    
2213                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2214    
2215                    msg.append("companyId=");
2216                    msg.append(companyId);
2217    
2218                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2219    
2220                    throw new NoSuchUserGroupException(msg.toString());
2221            }
2222    
2223            /**
2224             * Returns the first user group in the ordered set where companyId = &#63;.
2225             *
2226             * @param companyId the company ID
2227             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2228             * @return the first matching user group, or <code>null</code> if a matching user group could not be found
2229             * @throws SystemException if a system exception occurred
2230             */
2231            @Override
2232            public UserGroup fetchByCompanyId_First(long companyId,
2233                    OrderByComparator orderByComparator) throws SystemException {
2234                    List<UserGroup> list = findByCompanyId(companyId, 0, 1,
2235                                    orderByComparator);
2236    
2237                    if (!list.isEmpty()) {
2238                            return list.get(0);
2239                    }
2240    
2241                    return null;
2242            }
2243    
2244            /**
2245             * Returns the last user group in the ordered set where companyId = &#63;.
2246             *
2247             * @param companyId the company ID
2248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2249             * @return the last matching user group
2250             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
2251             * @throws SystemException if a system exception occurred
2252             */
2253            @Override
2254            public UserGroup findByCompanyId_Last(long companyId,
2255                    OrderByComparator orderByComparator)
2256                    throws NoSuchUserGroupException, SystemException {
2257                    UserGroup userGroup = fetchByCompanyId_Last(companyId, orderByComparator);
2258    
2259                    if (userGroup != null) {
2260                            return userGroup;
2261                    }
2262    
2263                    StringBundler msg = new StringBundler(4);
2264    
2265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2266    
2267                    msg.append("companyId=");
2268                    msg.append(companyId);
2269    
2270                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2271    
2272                    throw new NoSuchUserGroupException(msg.toString());
2273            }
2274    
2275            /**
2276             * Returns the last user group in the ordered set where companyId = &#63;.
2277             *
2278             * @param companyId the company ID
2279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2280             * @return the last matching user group, or <code>null</code> if a matching user group could not be found
2281             * @throws SystemException if a system exception occurred
2282             */
2283            @Override
2284            public UserGroup fetchByCompanyId_Last(long companyId,
2285                    OrderByComparator orderByComparator) throws SystemException {
2286                    int count = countByCompanyId(companyId);
2287    
2288                    if (count == 0) {
2289                            return null;
2290                    }
2291    
2292                    List<UserGroup> list = findByCompanyId(companyId, count - 1, count,
2293                                    orderByComparator);
2294    
2295                    if (!list.isEmpty()) {
2296                            return list.get(0);
2297                    }
2298    
2299                    return null;
2300            }
2301    
2302            /**
2303             * Returns the user groups before and after the current user group in the ordered set where companyId = &#63;.
2304             *
2305             * @param userGroupId the primary key of the current user group
2306             * @param companyId the company ID
2307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2308             * @return the previous, current, and next user group
2309             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
2310             * @throws SystemException if a system exception occurred
2311             */
2312            @Override
2313            public UserGroup[] findByCompanyId_PrevAndNext(long userGroupId,
2314                    long companyId, OrderByComparator orderByComparator)
2315                    throws NoSuchUserGroupException, SystemException {
2316                    UserGroup userGroup = findByPrimaryKey(userGroupId);
2317    
2318                    Session session = null;
2319    
2320                    try {
2321                            session = openSession();
2322    
2323                            UserGroup[] array = new UserGroupImpl[3];
2324    
2325                            array[0] = getByCompanyId_PrevAndNext(session, userGroup,
2326                                            companyId, orderByComparator, true);
2327    
2328                            array[1] = userGroup;
2329    
2330                            array[2] = getByCompanyId_PrevAndNext(session, userGroup,
2331                                            companyId, orderByComparator, false);
2332    
2333                            return array;
2334                    }
2335                    catch (Exception e) {
2336                            throw processException(e);
2337                    }
2338                    finally {
2339                            closeSession(session);
2340                    }
2341            }
2342    
2343            protected UserGroup getByCompanyId_PrevAndNext(Session session,
2344                    UserGroup userGroup, long companyId,
2345                    OrderByComparator orderByComparator, boolean previous) {
2346                    StringBundler query = null;
2347    
2348                    if (orderByComparator != null) {
2349                            query = new StringBundler(6 +
2350                                            (orderByComparator.getOrderByFields().length * 6));
2351                    }
2352                    else {
2353                            query = new StringBundler(3);
2354                    }
2355    
2356                    query.append(_SQL_SELECT_USERGROUP_WHERE);
2357    
2358                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2359    
2360                    if (orderByComparator != null) {
2361                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2362    
2363                            if (orderByConditionFields.length > 0) {
2364                                    query.append(WHERE_AND);
2365                            }
2366    
2367                            for (int i = 0; i < orderByConditionFields.length; i++) {
2368                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2369                                    query.append(orderByConditionFields[i]);
2370    
2371                                    if ((i + 1) < orderByConditionFields.length) {
2372                                            if (orderByComparator.isAscending() ^ previous) {
2373                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2374                                            }
2375                                            else {
2376                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2377                                            }
2378                                    }
2379                                    else {
2380                                            if (orderByComparator.isAscending() ^ previous) {
2381                                                    query.append(WHERE_GREATER_THAN);
2382                                            }
2383                                            else {
2384                                                    query.append(WHERE_LESSER_THAN);
2385                                            }
2386                                    }
2387                            }
2388    
2389                            query.append(ORDER_BY_CLAUSE);
2390    
2391                            String[] orderByFields = orderByComparator.getOrderByFields();
2392    
2393                            for (int i = 0; i < orderByFields.length; i++) {
2394                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2395                                    query.append(orderByFields[i]);
2396    
2397                                    if ((i + 1) < orderByFields.length) {
2398                                            if (orderByComparator.isAscending() ^ previous) {
2399                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2400                                            }
2401                                            else {
2402                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2403                                            }
2404                                    }
2405                                    else {
2406                                            if (orderByComparator.isAscending() ^ previous) {
2407                                                    query.append(ORDER_BY_ASC);
2408                                            }
2409                                            else {
2410                                                    query.append(ORDER_BY_DESC);
2411                                            }
2412                                    }
2413                            }
2414                    }
2415                    else {
2416                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
2417                    }
2418    
2419                    String sql = query.toString();
2420    
2421                    Query q = session.createQuery(sql);
2422    
2423                    q.setFirstResult(0);
2424                    q.setMaxResults(2);
2425    
2426                    QueryPos qPos = QueryPos.getInstance(q);
2427    
2428                    qPos.add(companyId);
2429    
2430                    if (orderByComparator != null) {
2431                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
2432    
2433                            for (Object value : values) {
2434                                    qPos.add(value);
2435                            }
2436                    }
2437    
2438                    List<UserGroup> list = q.list();
2439    
2440                    if (list.size() == 2) {
2441                            return list.get(1);
2442                    }
2443                    else {
2444                            return null;
2445                    }
2446            }
2447    
2448            /**
2449             * Returns all the user groups that the user has permission to view where companyId = &#63;.
2450             *
2451             * @param companyId the company ID
2452             * @return the matching user groups that the user has permission to view
2453             * @throws SystemException if a system exception occurred
2454             */
2455            @Override
2456            public List<UserGroup> filterFindByCompanyId(long companyId)
2457                    throws SystemException {
2458                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2459                            QueryUtil.ALL_POS, null);
2460            }
2461    
2462            /**
2463             * Returns a range of all the user groups that the user has permission to view where companyId = &#63;.
2464             *
2465             * <p>
2466             * 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.
2467             * </p>
2468             *
2469             * @param companyId the company ID
2470             * @param start the lower bound of the range of user groups
2471             * @param end the upper bound of the range of user groups (not inclusive)
2472             * @return the range of matching user groups that the user has permission to view
2473             * @throws SystemException if a system exception occurred
2474             */
2475            @Override
2476            public List<UserGroup> filterFindByCompanyId(long companyId, int start,
2477                    int end) throws SystemException {
2478                    return filterFindByCompanyId(companyId, start, end, null);
2479            }
2480    
2481            /**
2482             * Returns an ordered range of all the user groups that the user has permissions to view where companyId = &#63;.
2483             *
2484             * <p>
2485             * 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.
2486             * </p>
2487             *
2488             * @param companyId the company ID
2489             * @param start the lower bound of the range of user groups
2490             * @param end the upper bound of the range of user groups (not inclusive)
2491             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2492             * @return the ordered range of matching user groups that the user has permission to view
2493             * @throws SystemException if a system exception occurred
2494             */
2495            @Override
2496            public List<UserGroup> filterFindByCompanyId(long companyId, int start,
2497                    int end, OrderByComparator orderByComparator) throws SystemException {
2498                    if (!InlineSQLHelperUtil.isEnabled()) {
2499                            return findByCompanyId(companyId, start, end, orderByComparator);
2500                    }
2501    
2502                    StringBundler query = null;
2503    
2504                    if (orderByComparator != null) {
2505                            query = new StringBundler(3 +
2506                                            (orderByComparator.getOrderByFields().length * 3));
2507                    }
2508                    else {
2509                            query = new StringBundler(3);
2510                    }
2511    
2512                    if (getDB().isSupportsInlineDistinct()) {
2513                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
2514                    }
2515                    else {
2516                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
2517                    }
2518    
2519                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2520    
2521                    if (!getDB().isSupportsInlineDistinct()) {
2522                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
2523                    }
2524    
2525                    if (orderByComparator != null) {
2526                            if (getDB().isSupportsInlineDistinct()) {
2527                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2528                                            orderByComparator, true);
2529                            }
2530                            else {
2531                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2532                                            orderByComparator, true);
2533                            }
2534                    }
2535                    else {
2536                            if (getDB().isSupportsInlineDistinct()) {
2537                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
2538                            }
2539                            else {
2540                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
2541                            }
2542                    }
2543    
2544                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2545                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2546    
2547                    Session session = null;
2548    
2549                    try {
2550                            session = openSession();
2551    
2552                            SQLQuery q = session.createSQLQuery(sql);
2553    
2554                            if (getDB().isSupportsInlineDistinct()) {
2555                                    q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
2556                            }
2557                            else {
2558                                    q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
2559                            }
2560    
2561                            QueryPos qPos = QueryPos.getInstance(q);
2562    
2563                            qPos.add(companyId);
2564    
2565                            return (List<UserGroup>)QueryUtil.list(q, getDialect(), start, end);
2566                    }
2567                    catch (Exception e) {
2568                            throw processException(e);
2569                    }
2570                    finally {
2571                            closeSession(session);
2572                    }
2573            }
2574    
2575            /**
2576             * 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;.
2577             *
2578             * @param userGroupId the primary key of the current user group
2579             * @param companyId the company ID
2580             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2581             * @return the previous, current, and next user group
2582             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
2583             * @throws SystemException if a system exception occurred
2584             */
2585            @Override
2586            public UserGroup[] filterFindByCompanyId_PrevAndNext(long userGroupId,
2587                    long companyId, OrderByComparator orderByComparator)
2588                    throws NoSuchUserGroupException, SystemException {
2589                    if (!InlineSQLHelperUtil.isEnabled()) {
2590                            return findByCompanyId_PrevAndNext(userGroupId, companyId,
2591                                    orderByComparator);
2592                    }
2593    
2594                    UserGroup userGroup = findByPrimaryKey(userGroupId);
2595    
2596                    Session session = null;
2597    
2598                    try {
2599                            session = openSession();
2600    
2601                            UserGroup[] array = new UserGroupImpl[3];
2602    
2603                            array[0] = filterGetByCompanyId_PrevAndNext(session, userGroup,
2604                                            companyId, orderByComparator, true);
2605    
2606                            array[1] = userGroup;
2607    
2608                            array[2] = filterGetByCompanyId_PrevAndNext(session, userGroup,
2609                                            companyId, orderByComparator, false);
2610    
2611                            return array;
2612                    }
2613                    catch (Exception e) {
2614                            throw processException(e);
2615                    }
2616                    finally {
2617                            closeSession(session);
2618                    }
2619            }
2620    
2621            protected UserGroup filterGetByCompanyId_PrevAndNext(Session session,
2622                    UserGroup userGroup, long companyId,
2623                    OrderByComparator orderByComparator, boolean previous) {
2624                    StringBundler query = null;
2625    
2626                    if (orderByComparator != null) {
2627                            query = new StringBundler(6 +
2628                                            (orderByComparator.getOrderByFields().length * 6));
2629                    }
2630                    else {
2631                            query = new StringBundler(3);
2632                    }
2633    
2634                    if (getDB().isSupportsInlineDistinct()) {
2635                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
2636                    }
2637                    else {
2638                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
2639                    }
2640    
2641                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2642    
2643                    if (!getDB().isSupportsInlineDistinct()) {
2644                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
2645                    }
2646    
2647                    if (orderByComparator != null) {
2648                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2649    
2650                            if (orderByConditionFields.length > 0) {
2651                                    query.append(WHERE_AND);
2652                            }
2653    
2654                            for (int i = 0; i < orderByConditionFields.length; i++) {
2655                                    if (getDB().isSupportsInlineDistinct()) {
2656                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2657                                    }
2658                                    else {
2659                                            query.append(_ORDER_BY_ENTITY_TABLE);
2660                                    }
2661    
2662                                    query.append(orderByConditionFields[i]);
2663    
2664                                    if ((i + 1) < orderByConditionFields.length) {
2665                                            if (orderByComparator.isAscending() ^ previous) {
2666                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2667                                            }
2668                                            else {
2669                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2670                                            }
2671                                    }
2672                                    else {
2673                                            if (orderByComparator.isAscending() ^ previous) {
2674                                                    query.append(WHERE_GREATER_THAN);
2675                                            }
2676                                            else {
2677                                                    query.append(WHERE_LESSER_THAN);
2678                                            }
2679                                    }
2680                            }
2681    
2682                            query.append(ORDER_BY_CLAUSE);
2683    
2684                            String[] orderByFields = orderByComparator.getOrderByFields();
2685    
2686                            for (int i = 0; i < orderByFields.length; i++) {
2687                                    if (getDB().isSupportsInlineDistinct()) {
2688                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2689                                    }
2690                                    else {
2691                                            query.append(_ORDER_BY_ENTITY_TABLE);
2692                                    }
2693    
2694                                    query.append(orderByFields[i]);
2695    
2696                                    if ((i + 1) < orderByFields.length) {
2697                                            if (orderByComparator.isAscending() ^ previous) {
2698                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2699                                            }
2700                                            else {
2701                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2702                                            }
2703                                    }
2704                                    else {
2705                                            if (orderByComparator.isAscending() ^ previous) {
2706                                                    query.append(ORDER_BY_ASC);
2707                                            }
2708                                            else {
2709                                                    query.append(ORDER_BY_DESC);
2710                                            }
2711                                    }
2712                            }
2713                    }
2714                    else {
2715                            if (getDB().isSupportsInlineDistinct()) {
2716                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
2717                            }
2718                            else {
2719                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
2720                            }
2721                    }
2722    
2723                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2724                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2725    
2726                    SQLQuery q = session.createSQLQuery(sql);
2727    
2728                    q.setFirstResult(0);
2729                    q.setMaxResults(2);
2730    
2731                    if (getDB().isSupportsInlineDistinct()) {
2732                            q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
2733                    }
2734                    else {
2735                            q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
2736                    }
2737    
2738                    QueryPos qPos = QueryPos.getInstance(q);
2739    
2740                    qPos.add(companyId);
2741    
2742                    if (orderByComparator != null) {
2743                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
2744    
2745                            for (Object value : values) {
2746                                    qPos.add(value);
2747                            }
2748                    }
2749    
2750                    List<UserGroup> list = q.list();
2751    
2752                    if (list.size() == 2) {
2753                            return list.get(1);
2754                    }
2755                    else {
2756                            return null;
2757                    }
2758            }
2759    
2760            /**
2761             * Removes all the user groups where companyId = &#63; from the database.
2762             *
2763             * @param companyId the company ID
2764             * @throws SystemException if a system exception occurred
2765             */
2766            @Override
2767            public void removeByCompanyId(long companyId) throws SystemException {
2768                    for (UserGroup userGroup : findByCompanyId(companyId,
2769                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2770                            remove(userGroup);
2771                    }
2772            }
2773    
2774            /**
2775             * Returns the number of user groups where companyId = &#63;.
2776             *
2777             * @param companyId the company ID
2778             * @return the number of matching user groups
2779             * @throws SystemException if a system exception occurred
2780             */
2781            @Override
2782            public int countByCompanyId(long companyId) throws SystemException {
2783                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2784    
2785                    Object[] finderArgs = new Object[] { companyId };
2786    
2787                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2788                                    this);
2789    
2790                    if (count == null) {
2791                            StringBundler query = new StringBundler(2);
2792    
2793                            query.append(_SQL_COUNT_USERGROUP_WHERE);
2794    
2795                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2796    
2797                            String sql = query.toString();
2798    
2799                            Session session = null;
2800    
2801                            try {
2802                                    session = openSession();
2803    
2804                                    Query q = session.createQuery(sql);
2805    
2806                                    QueryPos qPos = QueryPos.getInstance(q);
2807    
2808                                    qPos.add(companyId);
2809    
2810                                    count = (Long)q.uniqueResult();
2811    
2812                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2813                            }
2814                            catch (Exception e) {
2815                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2816    
2817                                    throw processException(e);
2818                            }
2819                            finally {
2820                                    closeSession(session);
2821                            }
2822                    }
2823    
2824                    return count.intValue();
2825            }
2826    
2827            /**
2828             * Returns the number of user groups that the user has permission to view where companyId = &#63;.
2829             *
2830             * @param companyId the company ID
2831             * @return the number of matching user groups that the user has permission to view
2832             * @throws SystemException if a system exception occurred
2833             */
2834            @Override
2835            public int filterCountByCompanyId(long companyId) throws SystemException {
2836                    if (!InlineSQLHelperUtil.isEnabled()) {
2837                            return countByCompanyId(companyId);
2838                    }
2839    
2840                    StringBundler query = new StringBundler(2);
2841    
2842                    query.append(_FILTER_SQL_COUNT_USERGROUP_WHERE);
2843    
2844                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2845    
2846                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2847                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2848    
2849                    Session session = null;
2850    
2851                    try {
2852                            session = openSession();
2853    
2854                            SQLQuery q = session.createSQLQuery(sql);
2855    
2856                            q.addScalar(COUNT_COLUMN_NAME,
2857                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2858    
2859                            QueryPos qPos = QueryPos.getInstance(q);
2860    
2861                            qPos.add(companyId);
2862    
2863                            Long count = (Long)q.uniqueResult();
2864    
2865                            return count.intValue();
2866                    }
2867                    catch (Exception e) {
2868                            throw processException(e);
2869                    }
2870                    finally {
2871                            closeSession(session);
2872                    }
2873            }
2874    
2875            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "userGroup.companyId = ?";
2876            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2877                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
2878                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
2879                            new String[] {
2880                                    Long.class.getName(), Long.class.getName(),
2881                                    
2882                            Integer.class.getName(), Integer.class.getName(),
2883                                    OrderByComparator.class.getName()
2884                            });
2885            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2886                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
2887                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
2888                            new String[] { Long.class.getName(), Long.class.getName() },
2889                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK |
2890                            UserGroupModelImpl.PARENTUSERGROUPID_COLUMN_BITMASK |
2891                            UserGroupModelImpl.NAME_COLUMN_BITMASK);
2892            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
2893                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
2894                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
2895                            new String[] { Long.class.getName(), Long.class.getName() });
2896    
2897            /**
2898             * Returns all the user groups where companyId = &#63; and parentUserGroupId = &#63;.
2899             *
2900             * @param companyId the company ID
2901             * @param parentUserGroupId the parent user group ID
2902             * @return the matching user groups
2903             * @throws SystemException if a system exception occurred
2904             */
2905            @Override
2906            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId)
2907                    throws SystemException {
2908                    return findByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
2909                            QueryUtil.ALL_POS, null);
2910            }
2911    
2912            /**
2913             * Returns a range of all the user groups where companyId = &#63; and parentUserGroupId = &#63;.
2914             *
2915             * <p>
2916             * 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.
2917             * </p>
2918             *
2919             * @param companyId the company ID
2920             * @param parentUserGroupId the parent user group ID
2921             * @param start the lower bound of the range of user groups
2922             * @param end the upper bound of the range of user groups (not inclusive)
2923             * @return the range of matching user groups
2924             * @throws SystemException if a system exception occurred
2925             */
2926            @Override
2927            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
2928                    int start, int end) throws SystemException {
2929                    return findByC_P(companyId, parentUserGroupId, start, end, null);
2930            }
2931    
2932            /**
2933             * Returns an ordered range of all the user groups where companyId = &#63; and parentUserGroupId = &#63;.
2934             *
2935             * <p>
2936             * 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.
2937             * </p>
2938             *
2939             * @param companyId the company ID
2940             * @param parentUserGroupId the parent user group ID
2941             * @param start the lower bound of the range of user groups
2942             * @param end the upper bound of the range of user groups (not inclusive)
2943             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2944             * @return the ordered range of matching user groups
2945             * @throws SystemException if a system exception occurred
2946             */
2947            @Override
2948            public List<UserGroup> findByC_P(long companyId, long parentUserGroupId,
2949                    int start, int end, OrderByComparator orderByComparator)
2950                    throws SystemException {
2951                    boolean pagination = true;
2952                    FinderPath finderPath = null;
2953                    Object[] finderArgs = null;
2954    
2955                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2956                                    (orderByComparator == null)) {
2957                            pagination = false;
2958                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
2959                            finderArgs = new Object[] { companyId, parentUserGroupId };
2960                    }
2961                    else {
2962                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
2963                            finderArgs = new Object[] {
2964                                            companyId, parentUserGroupId,
2965                                            
2966                                            start, end, orderByComparator
2967                                    };
2968                    }
2969    
2970                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
2971                                    finderArgs, this);
2972    
2973                    if ((list != null) && !list.isEmpty()) {
2974                            for (UserGroup userGroup : list) {
2975                                    if ((companyId != userGroup.getCompanyId()) ||
2976                                                    (parentUserGroupId != userGroup.getParentUserGroupId())) {
2977                                            list = null;
2978    
2979                                            break;
2980                                    }
2981                            }
2982                    }
2983    
2984                    if (list == null) {
2985                            StringBundler query = null;
2986    
2987                            if (orderByComparator != null) {
2988                                    query = new StringBundler(4 +
2989                                                    (orderByComparator.getOrderByFields().length * 3));
2990                            }
2991                            else {
2992                                    query = new StringBundler(4);
2993                            }
2994    
2995                            query.append(_SQL_SELECT_USERGROUP_WHERE);
2996    
2997                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2998    
2999                            query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
3000    
3001                            if (orderByComparator != null) {
3002                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3003                                            orderByComparator);
3004                            }
3005                            else
3006                             if (pagination) {
3007                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
3008                            }
3009    
3010                            String sql = query.toString();
3011    
3012                            Session session = null;
3013    
3014                            try {
3015                                    session = openSession();
3016    
3017                                    Query q = session.createQuery(sql);
3018    
3019                                    QueryPos qPos = QueryPos.getInstance(q);
3020    
3021                                    qPos.add(companyId);
3022    
3023                                    qPos.add(parentUserGroupId);
3024    
3025                                    if (!pagination) {
3026                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
3027                                                            start, end, false);
3028    
3029                                            Collections.sort(list);
3030    
3031                                            list = new UnmodifiableList<UserGroup>(list);
3032                                    }
3033                                    else {
3034                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
3035                                                            start, end);
3036                                    }
3037    
3038                                    cacheResult(list);
3039    
3040                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3041                            }
3042                            catch (Exception e) {
3043                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3044    
3045                                    throw processException(e);
3046                            }
3047                            finally {
3048                                    closeSession(session);
3049                            }
3050                    }
3051    
3052                    return list;
3053            }
3054    
3055            /**
3056             * Returns the first user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
3057             *
3058             * @param companyId the company ID
3059             * @param parentUserGroupId the parent user group ID
3060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3061             * @return the first matching user group
3062             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
3063             * @throws SystemException if a system exception occurred
3064             */
3065            @Override
3066            public UserGroup findByC_P_First(long companyId, long parentUserGroupId,
3067                    OrderByComparator orderByComparator)
3068                    throws NoSuchUserGroupException, SystemException {
3069                    UserGroup userGroup = fetchByC_P_First(companyId, parentUserGroupId,
3070                                    orderByComparator);
3071    
3072                    if (userGroup != null) {
3073                            return userGroup;
3074                    }
3075    
3076                    StringBundler msg = new StringBundler(6);
3077    
3078                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3079    
3080                    msg.append("companyId=");
3081                    msg.append(companyId);
3082    
3083                    msg.append(", parentUserGroupId=");
3084                    msg.append(parentUserGroupId);
3085    
3086                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3087    
3088                    throw new NoSuchUserGroupException(msg.toString());
3089            }
3090    
3091            /**
3092             * Returns the first user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
3093             *
3094             * @param companyId the company ID
3095             * @param parentUserGroupId the parent user group ID
3096             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3097             * @return the first matching user group, or <code>null</code> if a matching user group could not be found
3098             * @throws SystemException if a system exception occurred
3099             */
3100            @Override
3101            public UserGroup fetchByC_P_First(long companyId, long parentUserGroupId,
3102                    OrderByComparator orderByComparator) throws SystemException {
3103                    List<UserGroup> list = findByC_P(companyId, parentUserGroupId, 0, 1,
3104                                    orderByComparator);
3105    
3106                    if (!list.isEmpty()) {
3107                            return list.get(0);
3108                    }
3109    
3110                    return null;
3111            }
3112    
3113            /**
3114             * Returns the last user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
3115             *
3116             * @param companyId the company ID
3117             * @param parentUserGroupId the parent user group ID
3118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3119             * @return the last matching user group
3120             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
3121             * @throws SystemException if a system exception occurred
3122             */
3123            @Override
3124            public UserGroup findByC_P_Last(long companyId, long parentUserGroupId,
3125                    OrderByComparator orderByComparator)
3126                    throws NoSuchUserGroupException, SystemException {
3127                    UserGroup userGroup = fetchByC_P_Last(companyId, parentUserGroupId,
3128                                    orderByComparator);
3129    
3130                    if (userGroup != null) {
3131                            return userGroup;
3132                    }
3133    
3134                    StringBundler msg = new StringBundler(6);
3135    
3136                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3137    
3138                    msg.append("companyId=");
3139                    msg.append(companyId);
3140    
3141                    msg.append(", parentUserGroupId=");
3142                    msg.append(parentUserGroupId);
3143    
3144                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3145    
3146                    throw new NoSuchUserGroupException(msg.toString());
3147            }
3148    
3149            /**
3150             * Returns the last user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
3151             *
3152             * @param companyId the company ID
3153             * @param parentUserGroupId the parent user group ID
3154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3155             * @return the last matching user group, or <code>null</code> if a matching user group could not be found
3156             * @throws SystemException if a system exception occurred
3157             */
3158            @Override
3159            public UserGroup fetchByC_P_Last(long companyId, long parentUserGroupId,
3160                    OrderByComparator orderByComparator) throws SystemException {
3161                    int count = countByC_P(companyId, parentUserGroupId);
3162    
3163                    if (count == 0) {
3164                            return null;
3165                    }
3166    
3167                    List<UserGroup> list = findByC_P(companyId, parentUserGroupId,
3168                                    count - 1, count, orderByComparator);
3169    
3170                    if (!list.isEmpty()) {
3171                            return list.get(0);
3172                    }
3173    
3174                    return null;
3175            }
3176    
3177            /**
3178             * Returns the user groups before and after the current user group in the ordered set where companyId = &#63; and parentUserGroupId = &#63;.
3179             *
3180             * @param userGroupId the primary key of the current user group
3181             * @param companyId the company ID
3182             * @param parentUserGroupId the parent user group ID
3183             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3184             * @return the previous, current, and next user group
3185             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
3186             * @throws SystemException if a system exception occurred
3187             */
3188            @Override
3189            public UserGroup[] findByC_P_PrevAndNext(long userGroupId, long companyId,
3190                    long parentUserGroupId, OrderByComparator orderByComparator)
3191                    throws NoSuchUserGroupException, SystemException {
3192                    UserGroup userGroup = findByPrimaryKey(userGroupId);
3193    
3194                    Session session = null;
3195    
3196                    try {
3197                            session = openSession();
3198    
3199                            UserGroup[] array = new UserGroupImpl[3];
3200    
3201                            array[0] = getByC_P_PrevAndNext(session, userGroup, companyId,
3202                                            parentUserGroupId, orderByComparator, true);
3203    
3204                            array[1] = userGroup;
3205    
3206                            array[2] = getByC_P_PrevAndNext(session, userGroup, companyId,
3207                                            parentUserGroupId, orderByComparator, false);
3208    
3209                            return array;
3210                    }
3211                    catch (Exception e) {
3212                            throw processException(e);
3213                    }
3214                    finally {
3215                            closeSession(session);
3216                    }
3217            }
3218    
3219            protected UserGroup getByC_P_PrevAndNext(Session session,
3220                    UserGroup userGroup, long companyId, long parentUserGroupId,
3221                    OrderByComparator orderByComparator, boolean previous) {
3222                    StringBundler query = null;
3223    
3224                    if (orderByComparator != null) {
3225                            query = new StringBundler(6 +
3226                                            (orderByComparator.getOrderByFields().length * 6));
3227                    }
3228                    else {
3229                            query = new StringBundler(3);
3230                    }
3231    
3232                    query.append(_SQL_SELECT_USERGROUP_WHERE);
3233    
3234                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3235    
3236                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
3237    
3238                    if (orderByComparator != null) {
3239                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3240    
3241                            if (orderByConditionFields.length > 0) {
3242                                    query.append(WHERE_AND);
3243                            }
3244    
3245                            for (int i = 0; i < orderByConditionFields.length; i++) {
3246                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3247                                    query.append(orderByConditionFields[i]);
3248    
3249                                    if ((i + 1) < orderByConditionFields.length) {
3250                                            if (orderByComparator.isAscending() ^ previous) {
3251                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3252                                            }
3253                                            else {
3254                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3255                                            }
3256                                    }
3257                                    else {
3258                                            if (orderByComparator.isAscending() ^ previous) {
3259                                                    query.append(WHERE_GREATER_THAN);
3260                                            }
3261                                            else {
3262                                                    query.append(WHERE_LESSER_THAN);
3263                                            }
3264                                    }
3265                            }
3266    
3267                            query.append(ORDER_BY_CLAUSE);
3268    
3269                            String[] orderByFields = orderByComparator.getOrderByFields();
3270    
3271                            for (int i = 0; i < orderByFields.length; i++) {
3272                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3273                                    query.append(orderByFields[i]);
3274    
3275                                    if ((i + 1) < orderByFields.length) {
3276                                            if (orderByComparator.isAscending() ^ previous) {
3277                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3278                                            }
3279                                            else {
3280                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3281                                            }
3282                                    }
3283                                    else {
3284                                            if (orderByComparator.isAscending() ^ previous) {
3285                                                    query.append(ORDER_BY_ASC);
3286                                            }
3287                                            else {
3288                                                    query.append(ORDER_BY_DESC);
3289                                            }
3290                                    }
3291                            }
3292                    }
3293                    else {
3294                            query.append(UserGroupModelImpl.ORDER_BY_JPQL);
3295                    }
3296    
3297                    String sql = query.toString();
3298    
3299                    Query q = session.createQuery(sql);
3300    
3301                    q.setFirstResult(0);
3302                    q.setMaxResults(2);
3303    
3304                    QueryPos qPos = QueryPos.getInstance(q);
3305    
3306                    qPos.add(companyId);
3307    
3308                    qPos.add(parentUserGroupId);
3309    
3310                    if (orderByComparator != null) {
3311                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
3312    
3313                            for (Object value : values) {
3314                                    qPos.add(value);
3315                            }
3316                    }
3317    
3318                    List<UserGroup> list = q.list();
3319    
3320                    if (list.size() == 2) {
3321                            return list.get(1);
3322                    }
3323                    else {
3324                            return null;
3325                    }
3326            }
3327    
3328            /**
3329             * Returns all the user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
3330             *
3331             * @param companyId the company ID
3332             * @param parentUserGroupId the parent user group ID
3333             * @return the matching user groups that the user has permission to view
3334             * @throws SystemException if a system exception occurred
3335             */
3336            @Override
3337            public List<UserGroup> filterFindByC_P(long companyId,
3338                    long parentUserGroupId) throws SystemException {
3339                    return filterFindByC_P(companyId, parentUserGroupId, QueryUtil.ALL_POS,
3340                            QueryUtil.ALL_POS, null);
3341            }
3342    
3343            /**
3344             * Returns a range of all the user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
3345             *
3346             * <p>
3347             * 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.
3348             * </p>
3349             *
3350             * @param companyId the company ID
3351             * @param parentUserGroupId the parent user group ID
3352             * @param start the lower bound of the range of user groups
3353             * @param end the upper bound of the range of user groups (not inclusive)
3354             * @return the range of matching user groups that the user has permission to view
3355             * @throws SystemException if a system exception occurred
3356             */
3357            @Override
3358            public List<UserGroup> filterFindByC_P(long companyId,
3359                    long parentUserGroupId, int start, int end) throws SystemException {
3360                    return filterFindByC_P(companyId, parentUserGroupId, start, end, null);
3361            }
3362    
3363            /**
3364             * Returns an ordered range of all the user groups that the user has permissions to view where companyId = &#63; and parentUserGroupId = &#63;.
3365             *
3366             * <p>
3367             * 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.
3368             * </p>
3369             *
3370             * @param companyId the company ID
3371             * @param parentUserGroupId the parent user group ID
3372             * @param start the lower bound of the range of user groups
3373             * @param end the upper bound of the range of user groups (not inclusive)
3374             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3375             * @return the ordered range of matching user groups that the user has permission to view
3376             * @throws SystemException if a system exception occurred
3377             */
3378            @Override
3379            public List<UserGroup> filterFindByC_P(long companyId,
3380                    long parentUserGroupId, int start, int end,
3381                    OrderByComparator orderByComparator) throws SystemException {
3382                    if (!InlineSQLHelperUtil.isEnabled()) {
3383                            return findByC_P(companyId, parentUserGroupId, start, end,
3384                                    orderByComparator);
3385                    }
3386    
3387                    StringBundler query = null;
3388    
3389                    if (orderByComparator != null) {
3390                            query = new StringBundler(4 +
3391                                            (orderByComparator.getOrderByFields().length * 3));
3392                    }
3393                    else {
3394                            query = new StringBundler(4);
3395                    }
3396    
3397                    if (getDB().isSupportsInlineDistinct()) {
3398                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
3399                    }
3400                    else {
3401                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
3402                    }
3403    
3404                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3405    
3406                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
3407    
3408                    if (!getDB().isSupportsInlineDistinct()) {
3409                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
3410                    }
3411    
3412                    if (orderByComparator != null) {
3413                            if (getDB().isSupportsInlineDistinct()) {
3414                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3415                                            orderByComparator, true);
3416                            }
3417                            else {
3418                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3419                                            orderByComparator, true);
3420                            }
3421                    }
3422                    else {
3423                            if (getDB().isSupportsInlineDistinct()) {
3424                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
3425                            }
3426                            else {
3427                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
3428                            }
3429                    }
3430    
3431                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3432                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3433    
3434                    Session session = null;
3435    
3436                    try {
3437                            session = openSession();
3438    
3439                            SQLQuery q = session.createSQLQuery(sql);
3440    
3441                            if (getDB().isSupportsInlineDistinct()) {
3442                                    q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
3443                            }
3444                            else {
3445                                    q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
3446                            }
3447    
3448                            QueryPos qPos = QueryPos.getInstance(q);
3449    
3450                            qPos.add(companyId);
3451    
3452                            qPos.add(parentUserGroupId);
3453    
3454                            return (List<UserGroup>)QueryUtil.list(q, getDialect(), start, end);
3455                    }
3456                    catch (Exception e) {
3457                            throw processException(e);
3458                    }
3459                    finally {
3460                            closeSession(session);
3461                    }
3462            }
3463    
3464            /**
3465             * 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;.
3466             *
3467             * @param userGroupId the primary key of the current user group
3468             * @param companyId the company ID
3469             * @param parentUserGroupId the parent user group ID
3470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3471             * @return the previous, current, and next user group
3472             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
3473             * @throws SystemException if a system exception occurred
3474             */
3475            @Override
3476            public UserGroup[] filterFindByC_P_PrevAndNext(long userGroupId,
3477                    long companyId, long parentUserGroupId,
3478                    OrderByComparator orderByComparator)
3479                    throws NoSuchUserGroupException, SystemException {
3480                    if (!InlineSQLHelperUtil.isEnabled()) {
3481                            return findByC_P_PrevAndNext(userGroupId, companyId,
3482                                    parentUserGroupId, orderByComparator);
3483                    }
3484    
3485                    UserGroup userGroup = findByPrimaryKey(userGroupId);
3486    
3487                    Session session = null;
3488    
3489                    try {
3490                            session = openSession();
3491    
3492                            UserGroup[] array = new UserGroupImpl[3];
3493    
3494                            array[0] = filterGetByC_P_PrevAndNext(session, userGroup,
3495                                            companyId, parentUserGroupId, orderByComparator, true);
3496    
3497                            array[1] = userGroup;
3498    
3499                            array[2] = filterGetByC_P_PrevAndNext(session, userGroup,
3500                                            companyId, parentUserGroupId, orderByComparator, false);
3501    
3502                            return array;
3503                    }
3504                    catch (Exception e) {
3505                            throw processException(e);
3506                    }
3507                    finally {
3508                            closeSession(session);
3509                    }
3510            }
3511    
3512            protected UserGroup filterGetByC_P_PrevAndNext(Session session,
3513                    UserGroup userGroup, long companyId, long parentUserGroupId,
3514                    OrderByComparator orderByComparator, boolean previous) {
3515                    StringBundler query = null;
3516    
3517                    if (orderByComparator != null) {
3518                            query = new StringBundler(6 +
3519                                            (orderByComparator.getOrderByFields().length * 6));
3520                    }
3521                    else {
3522                            query = new StringBundler(3);
3523                    }
3524    
3525                    if (getDB().isSupportsInlineDistinct()) {
3526                            query.append(_FILTER_SQL_SELECT_USERGROUP_WHERE);
3527                    }
3528                    else {
3529                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1);
3530                    }
3531    
3532                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3533    
3534                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
3535    
3536                    if (!getDB().isSupportsInlineDistinct()) {
3537                            query.append(_FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2);
3538                    }
3539    
3540                    if (orderByComparator != null) {
3541                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3542    
3543                            if (orderByConditionFields.length > 0) {
3544                                    query.append(WHERE_AND);
3545                            }
3546    
3547                            for (int i = 0; i < orderByConditionFields.length; i++) {
3548                                    if (getDB().isSupportsInlineDistinct()) {
3549                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3550                                    }
3551                                    else {
3552                                            query.append(_ORDER_BY_ENTITY_TABLE);
3553                                    }
3554    
3555                                    query.append(orderByConditionFields[i]);
3556    
3557                                    if ((i + 1) < orderByConditionFields.length) {
3558                                            if (orderByComparator.isAscending() ^ previous) {
3559                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3560                                            }
3561                                            else {
3562                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3563                                            }
3564                                    }
3565                                    else {
3566                                            if (orderByComparator.isAscending() ^ previous) {
3567                                                    query.append(WHERE_GREATER_THAN);
3568                                            }
3569                                            else {
3570                                                    query.append(WHERE_LESSER_THAN);
3571                                            }
3572                                    }
3573                            }
3574    
3575                            query.append(ORDER_BY_CLAUSE);
3576    
3577                            String[] orderByFields = orderByComparator.getOrderByFields();
3578    
3579                            for (int i = 0; i < orderByFields.length; i++) {
3580                                    if (getDB().isSupportsInlineDistinct()) {
3581                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3582                                    }
3583                                    else {
3584                                            query.append(_ORDER_BY_ENTITY_TABLE);
3585                                    }
3586    
3587                                    query.append(orderByFields[i]);
3588    
3589                                    if ((i + 1) < orderByFields.length) {
3590                                            if (orderByComparator.isAscending() ^ previous) {
3591                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3592                                            }
3593                                            else {
3594                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3595                                            }
3596                                    }
3597                                    else {
3598                                            if (orderByComparator.isAscending() ^ previous) {
3599                                                    query.append(ORDER_BY_ASC);
3600                                            }
3601                                            else {
3602                                                    query.append(ORDER_BY_DESC);
3603                                            }
3604                                    }
3605                            }
3606                    }
3607                    else {
3608                            if (getDB().isSupportsInlineDistinct()) {
3609                                    query.append(UserGroupModelImpl.ORDER_BY_JPQL);
3610                            }
3611                            else {
3612                                    query.append(UserGroupModelImpl.ORDER_BY_SQL);
3613                            }
3614                    }
3615    
3616                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3617                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3618    
3619                    SQLQuery q = session.createSQLQuery(sql);
3620    
3621                    q.setFirstResult(0);
3622                    q.setMaxResults(2);
3623    
3624                    if (getDB().isSupportsInlineDistinct()) {
3625                            q.addEntity(_FILTER_ENTITY_ALIAS, UserGroupImpl.class);
3626                    }
3627                    else {
3628                            q.addEntity(_FILTER_ENTITY_TABLE, UserGroupImpl.class);
3629                    }
3630    
3631                    QueryPos qPos = QueryPos.getInstance(q);
3632    
3633                    qPos.add(companyId);
3634    
3635                    qPos.add(parentUserGroupId);
3636    
3637                    if (orderByComparator != null) {
3638                            Object[] values = orderByComparator.getOrderByConditionValues(userGroup);
3639    
3640                            for (Object value : values) {
3641                                    qPos.add(value);
3642                            }
3643                    }
3644    
3645                    List<UserGroup> list = q.list();
3646    
3647                    if (list.size() == 2) {
3648                            return list.get(1);
3649                    }
3650                    else {
3651                            return null;
3652                    }
3653            }
3654    
3655            /**
3656             * Removes all the user groups where companyId = &#63; and parentUserGroupId = &#63; from the database.
3657             *
3658             * @param companyId the company ID
3659             * @param parentUserGroupId the parent user group ID
3660             * @throws SystemException if a system exception occurred
3661             */
3662            @Override
3663            public void removeByC_P(long companyId, long parentUserGroupId)
3664                    throws SystemException {
3665                    for (UserGroup userGroup : findByC_P(companyId, parentUserGroupId,
3666                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3667                            remove(userGroup);
3668                    }
3669            }
3670    
3671            /**
3672             * Returns the number of user groups where companyId = &#63; and parentUserGroupId = &#63;.
3673             *
3674             * @param companyId the company ID
3675             * @param parentUserGroupId the parent user group ID
3676             * @return the number of matching user groups
3677             * @throws SystemException if a system exception occurred
3678             */
3679            @Override
3680            public int countByC_P(long companyId, long parentUserGroupId)
3681                    throws SystemException {
3682                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
3683    
3684                    Object[] finderArgs = new Object[] { companyId, parentUserGroupId };
3685    
3686                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3687                                    this);
3688    
3689                    if (count == null) {
3690                            StringBundler query = new StringBundler(3);
3691    
3692                            query.append(_SQL_COUNT_USERGROUP_WHERE);
3693    
3694                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3695    
3696                            query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
3697    
3698                            String sql = query.toString();
3699    
3700                            Session session = null;
3701    
3702                            try {
3703                                    session = openSession();
3704    
3705                                    Query q = session.createQuery(sql);
3706    
3707                                    QueryPos qPos = QueryPos.getInstance(q);
3708    
3709                                    qPos.add(companyId);
3710    
3711                                    qPos.add(parentUserGroupId);
3712    
3713                                    count = (Long)q.uniqueResult();
3714    
3715                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3716                            }
3717                            catch (Exception e) {
3718                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3719    
3720                                    throw processException(e);
3721                            }
3722                            finally {
3723                                    closeSession(session);
3724                            }
3725                    }
3726    
3727                    return count.intValue();
3728            }
3729    
3730            /**
3731             * Returns the number of user groups that the user has permission to view where companyId = &#63; and parentUserGroupId = &#63;.
3732             *
3733             * @param companyId the company ID
3734             * @param parentUserGroupId the parent user group ID
3735             * @return the number of matching user groups that the user has permission to view
3736             * @throws SystemException if a system exception occurred
3737             */
3738            @Override
3739            public int filterCountByC_P(long companyId, long parentUserGroupId)
3740                    throws SystemException {
3741                    if (!InlineSQLHelperUtil.isEnabled()) {
3742                            return countByC_P(companyId, parentUserGroupId);
3743                    }
3744    
3745                    StringBundler query = new StringBundler(3);
3746    
3747                    query.append(_FILTER_SQL_COUNT_USERGROUP_WHERE);
3748    
3749                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
3750    
3751                    query.append(_FINDER_COLUMN_C_P_PARENTUSERGROUPID_2);
3752    
3753                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3754                                    UserGroup.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3755    
3756                    Session session = null;
3757    
3758                    try {
3759                            session = openSession();
3760    
3761                            SQLQuery q = session.createSQLQuery(sql);
3762    
3763                            q.addScalar(COUNT_COLUMN_NAME,
3764                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3765    
3766                            QueryPos qPos = QueryPos.getInstance(q);
3767    
3768                            qPos.add(companyId);
3769    
3770                            qPos.add(parentUserGroupId);
3771    
3772                            Long count = (Long)q.uniqueResult();
3773    
3774                            return count.intValue();
3775                    }
3776                    catch (Exception e) {
3777                            throw processException(e);
3778                    }
3779                    finally {
3780                            closeSession(session);
3781                    }
3782            }
3783    
3784            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "userGroup.companyId = ? AND ";
3785            private static final String _FINDER_COLUMN_C_P_PARENTUSERGROUPID_2 = "userGroup.parentUserGroupId = ?";
3786            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
3787                            UserGroupModelImpl.FINDER_CACHE_ENABLED, UserGroupImpl.class,
3788                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
3789                            new String[] { Long.class.getName(), String.class.getName() },
3790                            UserGroupModelImpl.COMPANYID_COLUMN_BITMASK |
3791                            UserGroupModelImpl.NAME_COLUMN_BITMASK);
3792            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
3793                            UserGroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
3794                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
3795                            new String[] { Long.class.getName(), String.class.getName() });
3796    
3797            /**
3798             * Returns the user group where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchUserGroupException} if it could not be found.
3799             *
3800             * @param companyId the company ID
3801             * @param name the name
3802             * @return the matching user group
3803             * @throws com.liferay.portal.NoSuchUserGroupException if a matching user group could not be found
3804             * @throws SystemException if a system exception occurred
3805             */
3806            @Override
3807            public UserGroup findByC_N(long companyId, String name)
3808                    throws NoSuchUserGroupException, SystemException {
3809                    UserGroup userGroup = fetchByC_N(companyId, name);
3810    
3811                    if (userGroup == null) {
3812                            StringBundler msg = new StringBundler(6);
3813    
3814                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3815    
3816                            msg.append("companyId=");
3817                            msg.append(companyId);
3818    
3819                            msg.append(", name=");
3820                            msg.append(name);
3821    
3822                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3823    
3824                            if (_log.isWarnEnabled()) {
3825                                    _log.warn(msg.toString());
3826                            }
3827    
3828                            throw new NoSuchUserGroupException(msg.toString());
3829                    }
3830    
3831                    return userGroup;
3832            }
3833    
3834            /**
3835             * 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.
3836             *
3837             * @param companyId the company ID
3838             * @param name the name
3839             * @return the matching user group, or <code>null</code> if a matching user group could not be found
3840             * @throws SystemException if a system exception occurred
3841             */
3842            @Override
3843            public UserGroup fetchByC_N(long companyId, String name)
3844                    throws SystemException {
3845                    return fetchByC_N(companyId, name, true);
3846            }
3847    
3848            /**
3849             * 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.
3850             *
3851             * @param companyId the company ID
3852             * @param name the name
3853             * @param retrieveFromCache whether to use the finder cache
3854             * @return the matching user group, or <code>null</code> if a matching user group could not be found
3855             * @throws SystemException if a system exception occurred
3856             */
3857            @Override
3858            public UserGroup fetchByC_N(long companyId, String name,
3859                    boolean retrieveFromCache) throws SystemException {
3860                    Object[] finderArgs = new Object[] { companyId, name };
3861    
3862                    Object result = null;
3863    
3864                    if (retrieveFromCache) {
3865                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
3866                                            finderArgs, this);
3867                    }
3868    
3869                    if (result instanceof UserGroup) {
3870                            UserGroup userGroup = (UserGroup)result;
3871    
3872                            if ((companyId != userGroup.getCompanyId()) ||
3873                                            !Validator.equals(name, userGroup.getName())) {
3874                                    result = null;
3875                            }
3876                    }
3877    
3878                    if (result == null) {
3879                            StringBundler query = new StringBundler(4);
3880    
3881                            query.append(_SQL_SELECT_USERGROUP_WHERE);
3882    
3883                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
3884    
3885                            boolean bindName = false;
3886    
3887                            if (name == null) {
3888                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
3889                            }
3890                            else if (name.equals(StringPool.BLANK)) {
3891                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
3892                            }
3893                            else {
3894                                    bindName = true;
3895    
3896                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
3897                            }
3898    
3899                            String sql = query.toString();
3900    
3901                            Session session = null;
3902    
3903                            try {
3904                                    session = openSession();
3905    
3906                                    Query q = session.createQuery(sql);
3907    
3908                                    QueryPos qPos = QueryPos.getInstance(q);
3909    
3910                                    qPos.add(companyId);
3911    
3912                                    if (bindName) {
3913                                            qPos.add(name);
3914                                    }
3915    
3916                                    List<UserGroup> list = q.list();
3917    
3918                                    if (list.isEmpty()) {
3919                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
3920                                                    finderArgs, list);
3921                                    }
3922                                    else {
3923                                            UserGroup userGroup = list.get(0);
3924    
3925                                            result = userGroup;
3926    
3927                                            cacheResult(userGroup);
3928    
3929                                            if ((userGroup.getCompanyId() != companyId) ||
3930                                                            (userGroup.getName() == null) ||
3931                                                            !userGroup.getName().equals(name)) {
3932                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
3933                                                            finderArgs, userGroup);
3934                                            }
3935                                    }
3936                            }
3937                            catch (Exception e) {
3938                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
3939                                            finderArgs);
3940    
3941                                    throw processException(e);
3942                            }
3943                            finally {
3944                                    closeSession(session);
3945                            }
3946                    }
3947    
3948                    if (result instanceof List<?>) {
3949                            return null;
3950                    }
3951                    else {
3952                            return (UserGroup)result;
3953                    }
3954            }
3955    
3956            /**
3957             * Removes the user group where companyId = &#63; and name = &#63; from the database.
3958             *
3959             * @param companyId the company ID
3960             * @param name the name
3961             * @return the user group that was removed
3962             * @throws SystemException if a system exception occurred
3963             */
3964            @Override
3965            public UserGroup removeByC_N(long companyId, String name)
3966                    throws NoSuchUserGroupException, SystemException {
3967                    UserGroup userGroup = findByC_N(companyId, name);
3968    
3969                    return remove(userGroup);
3970            }
3971    
3972            /**
3973             * Returns the number of user groups where companyId = &#63; and name = &#63;.
3974             *
3975             * @param companyId the company ID
3976             * @param name the name
3977             * @return the number of matching user groups
3978             * @throws SystemException if a system exception occurred
3979             */
3980            @Override
3981            public int countByC_N(long companyId, String name)
3982                    throws SystemException {
3983                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
3984    
3985                    Object[] finderArgs = new Object[] { companyId, name };
3986    
3987                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3988                                    this);
3989    
3990                    if (count == null) {
3991                            StringBundler query = new StringBundler(3);
3992    
3993                            query.append(_SQL_COUNT_USERGROUP_WHERE);
3994    
3995                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
3996    
3997                            boolean bindName = false;
3998    
3999                            if (name == null) {
4000                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
4001                            }
4002                            else if (name.equals(StringPool.BLANK)) {
4003                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
4004                            }
4005                            else {
4006                                    bindName = true;
4007    
4008                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
4009                            }
4010    
4011                            String sql = query.toString();
4012    
4013                            Session session = null;
4014    
4015                            try {
4016                                    session = openSession();
4017    
4018                                    Query q = session.createQuery(sql);
4019    
4020                                    QueryPos qPos = QueryPos.getInstance(q);
4021    
4022                                    qPos.add(companyId);
4023    
4024                                    if (bindName) {
4025                                            qPos.add(name);
4026                                    }
4027    
4028                                    count = (Long)q.uniqueResult();
4029    
4030                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4031                            }
4032                            catch (Exception e) {
4033                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4034    
4035                                    throw processException(e);
4036                            }
4037                            finally {
4038                                    closeSession(session);
4039                            }
4040                    }
4041    
4042                    return count.intValue();
4043            }
4044    
4045            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "userGroup.companyId = ? AND ";
4046            private static final String _FINDER_COLUMN_C_N_NAME_1 = "userGroup.name IS NULL";
4047            private static final String _FINDER_COLUMN_C_N_NAME_2 = "userGroup.name = ?";
4048            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(userGroup.name IS NULL OR userGroup.name = '')";
4049    
4050            /**
4051             * Caches the user group in the entity cache if it is enabled.
4052             *
4053             * @param userGroup the user group
4054             */
4055            @Override
4056            public void cacheResult(UserGroup userGroup) {
4057                    EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4058                            UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
4059    
4060                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
4061                            new Object[] { userGroup.getCompanyId(), userGroup.getName() },
4062                            userGroup);
4063    
4064                    userGroup.resetOriginalValues();
4065            }
4066    
4067            /**
4068             * Caches the user groups in the entity cache if it is enabled.
4069             *
4070             * @param userGroups the user groups
4071             */
4072            @Override
4073            public void cacheResult(List<UserGroup> userGroups) {
4074                    for (UserGroup userGroup : userGroups) {
4075                            if (EntityCacheUtil.getResult(
4076                                                    UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4077                                                    UserGroupImpl.class, userGroup.getPrimaryKey()) == null) {
4078                                    cacheResult(userGroup);
4079                            }
4080                            else {
4081                                    userGroup.resetOriginalValues();
4082                            }
4083                    }
4084            }
4085    
4086            /**
4087             * Clears the cache for all user groups.
4088             *
4089             * <p>
4090             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4091             * </p>
4092             */
4093            @Override
4094            public void clearCache() {
4095                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4096                            CacheRegistryUtil.clear(UserGroupImpl.class.getName());
4097                    }
4098    
4099                    EntityCacheUtil.clearCache(UserGroupImpl.class.getName());
4100    
4101                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4102                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4103                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4104            }
4105    
4106            /**
4107             * Clears the cache for the user group.
4108             *
4109             * <p>
4110             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
4111             * </p>
4112             */
4113            @Override
4114            public void clearCache(UserGroup userGroup) {
4115                    EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4116                            UserGroupImpl.class, userGroup.getPrimaryKey());
4117    
4118                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4119                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4120    
4121                    clearUniqueFindersCache(userGroup);
4122            }
4123    
4124            @Override
4125            public void clearCache(List<UserGroup> userGroups) {
4126                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4127                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4128    
4129                    for (UserGroup userGroup : userGroups) {
4130                            EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4131                                    UserGroupImpl.class, userGroup.getPrimaryKey());
4132    
4133                            clearUniqueFindersCache(userGroup);
4134                    }
4135            }
4136    
4137            protected void cacheUniqueFindersCache(UserGroup userGroup) {
4138                    if (userGroup.isNew()) {
4139                            Object[] args = new Object[] {
4140                                            userGroup.getCompanyId(), userGroup.getName()
4141                                    };
4142    
4143                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
4144                                    Long.valueOf(1));
4145                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, userGroup);
4146                    }
4147                    else {
4148                            UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
4149    
4150                            if ((userGroupModelImpl.getColumnBitmask() &
4151                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
4152                                    Object[] args = new Object[] {
4153                                                    userGroup.getCompanyId(), userGroup.getName()
4154                                            };
4155    
4156                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
4157                                            Long.valueOf(1));
4158                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args,
4159                                            userGroup);
4160                            }
4161                    }
4162            }
4163    
4164            protected void clearUniqueFindersCache(UserGroup userGroup) {
4165                    UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
4166    
4167                    Object[] args = new Object[] {
4168                                    userGroup.getCompanyId(), userGroup.getName()
4169                            };
4170    
4171                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
4172                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
4173    
4174                    if ((userGroupModelImpl.getColumnBitmask() &
4175                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
4176                            args = new Object[] {
4177                                            userGroupModelImpl.getOriginalCompanyId(),
4178                                            userGroupModelImpl.getOriginalName()
4179                                    };
4180    
4181                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
4182                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
4183                    }
4184            }
4185    
4186            /**
4187             * Creates a new user group with the primary key. Does not add the user group to the database.
4188             *
4189             * @param userGroupId the primary key for the new user group
4190             * @return the new user group
4191             */
4192            @Override
4193            public UserGroup create(long userGroupId) {
4194                    UserGroup userGroup = new UserGroupImpl();
4195    
4196                    userGroup.setNew(true);
4197                    userGroup.setPrimaryKey(userGroupId);
4198    
4199                    String uuid = PortalUUIDUtil.generate();
4200    
4201                    userGroup.setUuid(uuid);
4202    
4203                    return userGroup;
4204            }
4205    
4206            /**
4207             * Removes the user group with the primary key from the database. Also notifies the appropriate model listeners.
4208             *
4209             * @param userGroupId the primary key of the user group
4210             * @return the user group that was removed
4211             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
4212             * @throws SystemException if a system exception occurred
4213             */
4214            @Override
4215            public UserGroup remove(long userGroupId)
4216                    throws NoSuchUserGroupException, SystemException {
4217                    return remove((Serializable)userGroupId);
4218            }
4219    
4220            /**
4221             * Removes the user group with the primary key from the database. Also notifies the appropriate model listeners.
4222             *
4223             * @param primaryKey the primary key of the user group
4224             * @return the user group that was removed
4225             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
4226             * @throws SystemException if a system exception occurred
4227             */
4228            @Override
4229            public UserGroup remove(Serializable primaryKey)
4230                    throws NoSuchUserGroupException, SystemException {
4231                    Session session = null;
4232    
4233                    try {
4234                            session = openSession();
4235    
4236                            UserGroup userGroup = (UserGroup)session.get(UserGroupImpl.class,
4237                                            primaryKey);
4238    
4239                            if (userGroup == null) {
4240                                    if (_log.isWarnEnabled()) {
4241                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4242                                    }
4243    
4244                                    throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4245                                            primaryKey);
4246                            }
4247    
4248                            return remove(userGroup);
4249                    }
4250                    catch (NoSuchUserGroupException nsee) {
4251                            throw nsee;
4252                    }
4253                    catch (Exception e) {
4254                            throw processException(e);
4255                    }
4256                    finally {
4257                            closeSession(session);
4258                    }
4259            }
4260    
4261            @Override
4262            protected UserGroup removeImpl(UserGroup userGroup)
4263                    throws SystemException {
4264                    userGroup = toUnwrappedModel(userGroup);
4265    
4266                    try {
4267                            clearGroups.clear(userGroup.getPrimaryKey());
4268                    }
4269                    catch (Exception e) {
4270                            throw processException(e);
4271                    }
4272                    finally {
4273                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
4274                    }
4275    
4276                    try {
4277                            clearTeams.clear(userGroup.getPrimaryKey());
4278                    }
4279                    catch (Exception e) {
4280                            throw processException(e);
4281                    }
4282                    finally {
4283                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
4284                    }
4285    
4286                    try {
4287                            clearUsers.clear(userGroup.getPrimaryKey());
4288                    }
4289                    catch (Exception e) {
4290                            throw processException(e);
4291                    }
4292                    finally {
4293                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
4294                    }
4295    
4296                    Session session = null;
4297    
4298                    try {
4299                            session = openSession();
4300    
4301                            if (!session.contains(userGroup)) {
4302                                    userGroup = (UserGroup)session.get(UserGroupImpl.class,
4303                                                    userGroup.getPrimaryKeyObj());
4304                            }
4305    
4306                            if (userGroup != null) {
4307                                    session.delete(userGroup);
4308                            }
4309                    }
4310                    catch (Exception e) {
4311                            throw processException(e);
4312                    }
4313                    finally {
4314                            closeSession(session);
4315                    }
4316    
4317                    if (userGroup != null) {
4318                            clearCache(userGroup);
4319                    }
4320    
4321                    return userGroup;
4322            }
4323    
4324            @Override
4325            public UserGroup updateImpl(com.liferay.portal.model.UserGroup userGroup)
4326                    throws SystemException {
4327                    userGroup = toUnwrappedModel(userGroup);
4328    
4329                    boolean isNew = userGroup.isNew();
4330    
4331                    UserGroupModelImpl userGroupModelImpl = (UserGroupModelImpl)userGroup;
4332    
4333                    if (Validator.isNull(userGroup.getUuid())) {
4334                            String uuid = PortalUUIDUtil.generate();
4335    
4336                            userGroup.setUuid(uuid);
4337                    }
4338    
4339                    Session session = null;
4340    
4341                    try {
4342                            session = openSession();
4343    
4344                            if (userGroup.isNew()) {
4345                                    session.save(userGroup);
4346    
4347                                    userGroup.setNew(false);
4348                            }
4349                            else {
4350                                    session.merge(userGroup);
4351                            }
4352                    }
4353                    catch (Exception e) {
4354                            throw processException(e);
4355                    }
4356                    finally {
4357                            closeSession(session);
4358                    }
4359    
4360                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4361    
4362                    if (isNew || !UserGroupModelImpl.COLUMN_BITMASK_ENABLED) {
4363                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4364                    }
4365    
4366                    else {
4367                            if ((userGroupModelImpl.getColumnBitmask() &
4368                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
4369                                    Object[] args = new Object[] {
4370                                                    userGroupModelImpl.getOriginalUuid()
4371                                            };
4372    
4373                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4374                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4375                                            args);
4376    
4377                                    args = new Object[] { userGroupModelImpl.getUuid() };
4378    
4379                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
4380                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
4381                                            args);
4382                            }
4383    
4384                            if ((userGroupModelImpl.getColumnBitmask() &
4385                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
4386                                    Object[] args = new Object[] {
4387                                                    userGroupModelImpl.getOriginalUuid(),
4388                                                    userGroupModelImpl.getOriginalCompanyId()
4389                                            };
4390    
4391                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4392                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4393                                            args);
4394    
4395                                    args = new Object[] {
4396                                                    userGroupModelImpl.getUuid(),
4397                                                    userGroupModelImpl.getCompanyId()
4398                                            };
4399    
4400                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
4401                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
4402                                            args);
4403                            }
4404    
4405                            if ((userGroupModelImpl.getColumnBitmask() &
4406                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4407                                    Object[] args = new Object[] {
4408                                                    userGroupModelImpl.getOriginalCompanyId()
4409                                            };
4410    
4411                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4412                                            args);
4413                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4414                                            args);
4415    
4416                                    args = new Object[] { userGroupModelImpl.getCompanyId() };
4417    
4418                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4419                                            args);
4420                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4421                                            args);
4422                            }
4423    
4424                            if ((userGroupModelImpl.getColumnBitmask() &
4425                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
4426                                    Object[] args = new Object[] {
4427                                                    userGroupModelImpl.getOriginalCompanyId(),
4428                                                    userGroupModelImpl.getOriginalParentUserGroupId()
4429                                            };
4430    
4431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
4432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
4433                                            args);
4434    
4435                                    args = new Object[] {
4436                                                    userGroupModelImpl.getCompanyId(),
4437                                                    userGroupModelImpl.getParentUserGroupId()
4438                                            };
4439    
4440                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
4441                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
4442                                            args);
4443                            }
4444                    }
4445    
4446                    EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4447                            UserGroupImpl.class, userGroup.getPrimaryKey(), userGroup);
4448    
4449                    clearUniqueFindersCache(userGroup);
4450                    cacheUniqueFindersCache(userGroup);
4451    
4452                    return userGroup;
4453            }
4454    
4455            protected UserGroup toUnwrappedModel(UserGroup userGroup) {
4456                    if (userGroup instanceof UserGroupImpl) {
4457                            return userGroup;
4458                    }
4459    
4460                    UserGroupImpl userGroupImpl = new UserGroupImpl();
4461    
4462                    userGroupImpl.setNew(userGroup.isNew());
4463                    userGroupImpl.setPrimaryKey(userGroup.getPrimaryKey());
4464    
4465                    userGroupImpl.setUuid(userGroup.getUuid());
4466                    userGroupImpl.setUserGroupId(userGroup.getUserGroupId());
4467                    userGroupImpl.setCompanyId(userGroup.getCompanyId());
4468                    userGroupImpl.setUserId(userGroup.getUserId());
4469                    userGroupImpl.setUserName(userGroup.getUserName());
4470                    userGroupImpl.setCreateDate(userGroup.getCreateDate());
4471                    userGroupImpl.setModifiedDate(userGroup.getModifiedDate());
4472                    userGroupImpl.setParentUserGroupId(userGroup.getParentUserGroupId());
4473                    userGroupImpl.setName(userGroup.getName());
4474                    userGroupImpl.setDescription(userGroup.getDescription());
4475                    userGroupImpl.setAddedByLDAPImport(userGroup.isAddedByLDAPImport());
4476    
4477                    return userGroupImpl;
4478            }
4479    
4480            /**
4481             * Returns the user group with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4482             *
4483             * @param primaryKey the primary key of the user group
4484             * @return the user group
4485             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
4486             * @throws SystemException if a system exception occurred
4487             */
4488            @Override
4489            public UserGroup findByPrimaryKey(Serializable primaryKey)
4490                    throws NoSuchUserGroupException, SystemException {
4491                    UserGroup userGroup = fetchByPrimaryKey(primaryKey);
4492    
4493                    if (userGroup == null) {
4494                            if (_log.isWarnEnabled()) {
4495                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4496                            }
4497    
4498                            throw new NoSuchUserGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4499                                    primaryKey);
4500                    }
4501    
4502                    return userGroup;
4503            }
4504    
4505            /**
4506             * Returns the user group with the primary key or throws a {@link com.liferay.portal.NoSuchUserGroupException} if it could not be found.
4507             *
4508             * @param userGroupId the primary key of the user group
4509             * @return the user group
4510             * @throws com.liferay.portal.NoSuchUserGroupException if a user group with the primary key could not be found
4511             * @throws SystemException if a system exception occurred
4512             */
4513            @Override
4514            public UserGroup findByPrimaryKey(long userGroupId)
4515                    throws NoSuchUserGroupException, SystemException {
4516                    return findByPrimaryKey((Serializable)userGroupId);
4517            }
4518    
4519            /**
4520             * Returns the user group with the primary key or returns <code>null</code> if it could not be found.
4521             *
4522             * @param primaryKey the primary key of the user group
4523             * @return the user group, or <code>null</code> if a user group with the primary key could not be found
4524             * @throws SystemException if a system exception occurred
4525             */
4526            @Override
4527            public UserGroup fetchByPrimaryKey(Serializable primaryKey)
4528                    throws SystemException {
4529                    UserGroup userGroup = (UserGroup)EntityCacheUtil.getResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4530                                    UserGroupImpl.class, primaryKey);
4531    
4532                    if (userGroup == _nullUserGroup) {
4533                            return null;
4534                    }
4535    
4536                    if (userGroup == null) {
4537                            Session session = null;
4538    
4539                            try {
4540                                    session = openSession();
4541    
4542                                    userGroup = (UserGroup)session.get(UserGroupImpl.class,
4543                                                    primaryKey);
4544    
4545                                    if (userGroup != null) {
4546                                            cacheResult(userGroup);
4547                                    }
4548                                    else {
4549                                            EntityCacheUtil.putResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4550                                                    UserGroupImpl.class, primaryKey, _nullUserGroup);
4551                                    }
4552                            }
4553                            catch (Exception e) {
4554                                    EntityCacheUtil.removeResult(UserGroupModelImpl.ENTITY_CACHE_ENABLED,
4555                                            UserGroupImpl.class, primaryKey);
4556    
4557                                    throw processException(e);
4558                            }
4559                            finally {
4560                                    closeSession(session);
4561                            }
4562                    }
4563    
4564                    return userGroup;
4565            }
4566    
4567            /**
4568             * Returns the user group with the primary key or returns <code>null</code> if it could not be found.
4569             *
4570             * @param userGroupId the primary key of the user group
4571             * @return the user group, or <code>null</code> if a user group with the primary key could not be found
4572             * @throws SystemException if a system exception occurred
4573             */
4574            @Override
4575            public UserGroup fetchByPrimaryKey(long userGroupId)
4576                    throws SystemException {
4577                    return fetchByPrimaryKey((Serializable)userGroupId);
4578            }
4579    
4580            /**
4581             * Returns all the user groups.
4582             *
4583             * @return the user groups
4584             * @throws SystemException if a system exception occurred
4585             */
4586            @Override
4587            public List<UserGroup> findAll() throws SystemException {
4588                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4589            }
4590    
4591            /**
4592             * Returns a range of all the user groups.
4593             *
4594             * <p>
4595             * 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.
4596             * </p>
4597             *
4598             * @param start the lower bound of the range of user groups
4599             * @param end the upper bound of the range of user groups (not inclusive)
4600             * @return the range of user groups
4601             * @throws SystemException if a system exception occurred
4602             */
4603            @Override
4604            public List<UserGroup> findAll(int start, int end)
4605                    throws SystemException {
4606                    return findAll(start, end, null);
4607            }
4608    
4609            /**
4610             * Returns an ordered range of all the user groups.
4611             *
4612             * <p>
4613             * 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.
4614             * </p>
4615             *
4616             * @param start the lower bound of the range of user groups
4617             * @param end the upper bound of the range of user groups (not inclusive)
4618             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4619             * @return the ordered range of user groups
4620             * @throws SystemException if a system exception occurred
4621             */
4622            @Override
4623            public List<UserGroup> findAll(int start, int end,
4624                    OrderByComparator orderByComparator) throws SystemException {
4625                    boolean pagination = true;
4626                    FinderPath finderPath = null;
4627                    Object[] finderArgs = null;
4628    
4629                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4630                                    (orderByComparator == null)) {
4631                            pagination = false;
4632                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4633                            finderArgs = FINDER_ARGS_EMPTY;
4634                    }
4635                    else {
4636                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4637                            finderArgs = new Object[] { start, end, orderByComparator };
4638                    }
4639    
4640                    List<UserGroup> list = (List<UserGroup>)FinderCacheUtil.getResult(finderPath,
4641                                    finderArgs, this);
4642    
4643                    if (list == null) {
4644                            StringBundler query = null;
4645                            String sql = null;
4646    
4647                            if (orderByComparator != null) {
4648                                    query = new StringBundler(2 +
4649                                                    (orderByComparator.getOrderByFields().length * 3));
4650    
4651                                    query.append(_SQL_SELECT_USERGROUP);
4652    
4653                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4654                                            orderByComparator);
4655    
4656                                    sql = query.toString();
4657                            }
4658                            else {
4659                                    sql = _SQL_SELECT_USERGROUP;
4660    
4661                                    if (pagination) {
4662                                            sql = sql.concat(UserGroupModelImpl.ORDER_BY_JPQL);
4663                                    }
4664                            }
4665    
4666                            Session session = null;
4667    
4668                            try {
4669                                    session = openSession();
4670    
4671                                    Query q = session.createQuery(sql);
4672    
4673                                    if (!pagination) {
4674                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
4675                                                            start, end, false);
4676    
4677                                            Collections.sort(list);
4678    
4679                                            list = new UnmodifiableList<UserGroup>(list);
4680                                    }
4681                                    else {
4682                                            list = (List<UserGroup>)QueryUtil.list(q, getDialect(),
4683                                                            start, end);
4684                                    }
4685    
4686                                    cacheResult(list);
4687    
4688                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4689                            }
4690                            catch (Exception e) {
4691                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4692    
4693                                    throw processException(e);
4694                            }
4695                            finally {
4696                                    closeSession(session);
4697                            }
4698                    }
4699    
4700                    return list;
4701            }
4702    
4703            /**
4704             * Removes all the user groups from the database.
4705             *
4706             * @throws SystemException if a system exception occurred
4707             */
4708            @Override
4709            public void removeAll() throws SystemException {
4710                    for (UserGroup userGroup : findAll()) {
4711                            remove(userGroup);
4712                    }
4713            }
4714    
4715            /**
4716             * Returns the number of user groups.
4717             *
4718             * @return the number of user groups
4719             * @throws SystemException if a system exception occurred
4720             */
4721            @Override
4722            public int countAll() throws SystemException {
4723                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4724                                    FINDER_ARGS_EMPTY, this);
4725    
4726                    if (count == null) {
4727                            Session session = null;
4728    
4729                            try {
4730                                    session = openSession();
4731    
4732                                    Query q = session.createQuery(_SQL_COUNT_USERGROUP);
4733    
4734                                    count = (Long)q.uniqueResult();
4735    
4736                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4737                                            FINDER_ARGS_EMPTY, count);
4738                            }
4739                            catch (Exception e) {
4740                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4741                                            FINDER_ARGS_EMPTY);
4742    
4743                                    throw processException(e);
4744                            }
4745                            finally {
4746                                    closeSession(session);
4747                            }
4748                    }
4749    
4750                    return count.intValue();
4751            }
4752    
4753            /**
4754             * Returns all the groups associated with the user group.
4755             *
4756             * @param pk the primary key of the user group
4757             * @return the groups associated with the user group
4758             * @throws SystemException if a system exception occurred
4759             */
4760            @Override
4761            public List<com.liferay.portal.model.Group> getGroups(long pk)
4762                    throws SystemException {
4763                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4764            }
4765    
4766            /**
4767             * Returns a range of all the groups associated with the user group.
4768             *
4769             * <p>
4770             * 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.
4771             * </p>
4772             *
4773             * @param pk the primary key of the user group
4774             * @param start the lower bound of the range of user groups
4775             * @param end the upper bound of the range of user groups (not inclusive)
4776             * @return the range of groups associated with the user group
4777             * @throws SystemException if a system exception occurred
4778             */
4779            @Override
4780            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
4781                    int end) throws SystemException {
4782                    return getGroups(pk, start, end, null);
4783            }
4784    
4785            public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4786                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
4787                            com.liferay.portal.model.impl.GroupImpl.class,
4788                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
4789                            "getGroups",
4790                            new String[] {
4791                                    Long.class.getName(), Integer.class.getName(),
4792                                    Integer.class.getName(), OrderByComparator.class.getName()
4793                            });
4794    
4795            static {
4796                    FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
4797            }
4798    
4799            /**
4800             * Returns an ordered range of all the groups associated with the user group.
4801             *
4802             * <p>
4803             * 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.
4804             * </p>
4805             *
4806             * @param pk the primary key of the user group
4807             * @param start the lower bound of the range of user groups
4808             * @param end the upper bound of the range of user groups (not inclusive)
4809             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4810             * @return the ordered range of groups associated with the user group
4811             * @throws SystemException if a system exception occurred
4812             */
4813            @Override
4814            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
4815                    int end, OrderByComparator orderByComparator) throws SystemException {
4816                    boolean pagination = true;
4817                    Object[] finderArgs = null;
4818    
4819                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4820                                    (orderByComparator == null)) {
4821                            pagination = false;
4822                            finderArgs = new Object[] { pk };
4823                    }
4824                    else {
4825                            finderArgs = new Object[] { pk, start, end, orderByComparator };
4826                    }
4827    
4828                    List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
4829                                    finderArgs, this);
4830    
4831                    if (list == null) {
4832                            Session session = null;
4833    
4834                            try {
4835                                    session = openSession();
4836    
4837                                    String sql = null;
4838    
4839                                    if (orderByComparator != null) {
4840                                            sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
4841                                                                                    .concat(orderByComparator.getOrderBy());
4842                                    }
4843                                    else {
4844                                            sql = _SQL_GETGROUPS;
4845    
4846                                            if (pagination) {
4847                                                    sql = sql.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
4848                                            }
4849                                    }
4850    
4851                                    SQLQuery q = session.createSQLQuery(sql);
4852    
4853                                    q.addEntity("Group_",
4854                                            com.liferay.portal.model.impl.GroupImpl.class);
4855    
4856                                    QueryPos qPos = QueryPos.getInstance(q);
4857    
4858                                    qPos.add(pk);
4859    
4860                                    if (!pagination) {
4861                                            list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
4862                                                            getDialect(), start, end, false);
4863    
4864                                            Collections.sort(list);
4865    
4866                                            list = new UnmodifiableList<com.liferay.portal.model.Group>(list);
4867                                    }
4868                                    else {
4869                                            list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
4870                                                            getDialect(), start, end);
4871                                    }
4872    
4873                                    groupPersistence.cacheResult(list);
4874    
4875                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
4876                                            list);
4877                            }
4878                            catch (Exception e) {
4879                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS, finderArgs);
4880    
4881                                    throw processException(e);
4882                            }
4883                            finally {
4884                                    closeSession(session);
4885                            }
4886                    }
4887    
4888                    return list;
4889            }
4890    
4891            public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4892                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
4893                            Long.class,
4894                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
4895                            "getGroupsSize", new String[] { Long.class.getName() });
4896    
4897            static {
4898                    FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
4899            }
4900    
4901            /**
4902             * Returns the number of groups associated with the user group.
4903             *
4904             * @param pk the primary key of the user group
4905             * @return the number of groups associated with the user group
4906             * @throws SystemException if a system exception occurred
4907             */
4908            @Override
4909            public int getGroupsSize(long pk) throws SystemException {
4910                    Object[] finderArgs = new Object[] { pk };
4911    
4912                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
4913                                    finderArgs, this);
4914    
4915                    if (count == null) {
4916                            Session session = null;
4917    
4918                            try {
4919                                    session = openSession();
4920    
4921                                    SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
4922    
4923                                    q.addScalar(COUNT_COLUMN_NAME,
4924                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
4925    
4926                                    QueryPos qPos = QueryPos.getInstance(q);
4927    
4928                                    qPos.add(pk);
4929    
4930                                    count = (Long)q.uniqueResult();
4931    
4932                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
4933                                            finderArgs, count);
4934                            }
4935                            catch (Exception e) {
4936                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS_SIZE,
4937                                            finderArgs);
4938    
4939                                    throw processException(e);
4940                            }
4941                            finally {
4942                                    closeSession(session);
4943                            }
4944                    }
4945    
4946                    return count.intValue();
4947            }
4948    
4949            public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4950                            UserGroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
4951                            Boolean.class,
4952                            UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
4953                            "containsGroup",
4954                            new String[] { Long.class.getName(), Long.class.getName() });
4955    
4956            /**
4957             * Returns <code>true</code> if the group is associated with the user group.
4958             *
4959             * @param pk the primary key of the user group
4960             * @param groupPK the primary key of the group
4961             * @return <code>true</code> if the group is associated with the user group; <code>false</code> otherwise
4962             * @throws SystemException if a system exception occurred
4963             */
4964            @Override
4965            public boolean containsGroup(long pk, long groupPK)
4966                    throws SystemException {
4967                    Object[] finderArgs = new Object[] { pk, groupPK };
4968    
4969                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
4970                                    finderArgs, this);
4971    
4972                    if (value == null) {
4973                            try {
4974                                    value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
4975    
4976                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
4977                                            finderArgs, value);
4978                            }
4979                            catch (Exception e) {
4980                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_GROUP,
4981                                            finderArgs);
4982    
4983                                    throw processException(e);
4984                            }
4985                    }
4986    
4987                    return value.booleanValue();
4988            }
4989    
4990            /**
4991             * Returns <code>true</code> if the user group has any groups associated with it.
4992             *
4993             * @param pk the primary key of the user group to check for associations with groups
4994             * @return <code>true</code> if the user group has any groups associated with it; <code>false</code> otherwise
4995             * @throws SystemException if a system exception occurred
4996             */
4997            @Override
4998            public boolean containsGroups(long pk) throws SystemException {
4999                    if (getGroupsSize(pk) > 0) {
5000                            return true;
5001                    }
5002                    else {
5003                            return false;
5004                    }
5005            }
5006    
5007            /**
5008             * Adds an association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5009             *
5010             * @param pk the primary key of the user group
5011             * @param groupPK the primary key of the group
5012             * @throws SystemException if a system exception occurred
5013             */
5014            @Override
5015            public void addGroup(long pk, long groupPK) throws SystemException {
5016                    try {
5017                            addGroup.add(pk, groupPK);
5018                    }
5019                    catch (Exception e) {
5020                            throw processException(e);
5021                    }
5022                    finally {
5023                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5024                    }
5025            }
5026    
5027            /**
5028             * Adds an association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5029             *
5030             * @param pk the primary key of the user group
5031             * @param group the group
5032             * @throws SystemException if a system exception occurred
5033             */
5034            @Override
5035            public void addGroup(long pk, com.liferay.portal.model.Group group)
5036                    throws SystemException {
5037                    try {
5038                            addGroup.add(pk, group.getPrimaryKey());
5039                    }
5040                    catch (Exception e) {
5041                            throw processException(e);
5042                    }
5043                    finally {
5044                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5045                    }
5046            }
5047    
5048            /**
5049             * Adds an association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5050             *
5051             * @param pk the primary key of the user group
5052             * @param groupPKs the primary keys of the groups
5053             * @throws SystemException if a system exception occurred
5054             */
5055            @Override
5056            public void addGroups(long pk, long[] groupPKs) throws SystemException {
5057                    try {
5058                            for (long groupPK : groupPKs) {
5059                                    addGroup.add(pk, groupPK);
5060                            }
5061                    }
5062                    catch (Exception e) {
5063                            throw processException(e);
5064                    }
5065                    finally {
5066                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5067                    }
5068            }
5069    
5070            /**
5071             * Adds an association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5072             *
5073             * @param pk the primary key of the user group
5074             * @param groups the groups
5075             * @throws SystemException if a system exception occurred
5076             */
5077            @Override
5078            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
5079                    throws SystemException {
5080                    try {
5081                            for (com.liferay.portal.model.Group group : groups) {
5082                                    addGroup.add(pk, group.getPrimaryKey());
5083                            }
5084                    }
5085                    catch (Exception e) {
5086                            throw processException(e);
5087                    }
5088                    finally {
5089                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5090                    }
5091            }
5092    
5093            /**
5094             * Clears all associations between the user group and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5095             *
5096             * @param pk the primary key of the user group to clear the associated groups from
5097             * @throws SystemException if a system exception occurred
5098             */
5099            @Override
5100            public void clearGroups(long pk) throws SystemException {
5101                    try {
5102                            clearGroups.clear(pk);
5103                    }
5104                    catch (Exception e) {
5105                            throw processException(e);
5106                    }
5107                    finally {
5108                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5109                    }
5110            }
5111    
5112            /**
5113             * Removes the association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5114             *
5115             * @param pk the primary key of the user group
5116             * @param groupPK the primary key of the group
5117             * @throws SystemException if a system exception occurred
5118             */
5119            @Override
5120            public void removeGroup(long pk, long groupPK) throws SystemException {
5121                    try {
5122                            removeGroup.remove(pk, groupPK);
5123                    }
5124                    catch (Exception e) {
5125                            throw processException(e);
5126                    }
5127                    finally {
5128                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5129                    }
5130            }
5131    
5132            /**
5133             * Removes the association between the user group and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5134             *
5135             * @param pk the primary key of the user group
5136             * @param group the group
5137             * @throws SystemException if a system exception occurred
5138             */
5139            @Override
5140            public void removeGroup(long pk, com.liferay.portal.model.Group group)
5141                    throws SystemException {
5142                    try {
5143                            removeGroup.remove(pk, group.getPrimaryKey());
5144                    }
5145                    catch (Exception e) {
5146                            throw processException(e);
5147                    }
5148                    finally {
5149                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5150                    }
5151            }
5152    
5153            /**
5154             * Removes the association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5155             *
5156             * @param pk the primary key of the user group
5157             * @param groupPKs the primary keys of the groups
5158             * @throws SystemException if a system exception occurred
5159             */
5160            @Override
5161            public void removeGroups(long pk, long[] groupPKs)
5162                    throws SystemException {
5163                    try {
5164                            for (long groupPK : groupPKs) {
5165                                    removeGroup.remove(pk, groupPK);
5166                            }
5167                    }
5168                    catch (Exception e) {
5169                            throw processException(e);
5170                    }
5171                    finally {
5172                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5173                    }
5174            }
5175    
5176            /**
5177             * Removes the association between the user group and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5178             *
5179             * @param pk the primary key of the user group
5180             * @param groups the groups
5181             * @throws SystemException if a system exception occurred
5182             */
5183            @Override
5184            public void removeGroups(long pk,
5185                    List<com.liferay.portal.model.Group> groups) throws SystemException {
5186                    try {
5187                            for (com.liferay.portal.model.Group group : groups) {
5188                                    removeGroup.remove(pk, group.getPrimaryKey());
5189                            }
5190                    }
5191                    catch (Exception e) {
5192                            throw processException(e);
5193                    }
5194                    finally {
5195                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5196                    }
5197            }
5198    
5199            /**
5200             * 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.
5201             *
5202             * @param pk the primary key of the user group
5203             * @param groupPKs the primary keys of the groups to be associated with the user group
5204             * @throws SystemException if a system exception occurred
5205             */
5206            @Override
5207            public void setGroups(long pk, long[] groupPKs) throws SystemException {
5208                    try {
5209                            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
5210    
5211                            List<com.liferay.portal.model.Group> groups = getGroups(pk);
5212    
5213                            for (com.liferay.portal.model.Group group : groups) {
5214                                    if (!groupPKSet.remove(group.getPrimaryKey())) {
5215                                            removeGroup.remove(pk, group.getPrimaryKey());
5216                                    }
5217                            }
5218    
5219                            for (Long groupPK : groupPKSet) {
5220                                    addGroup.add(pk, groupPK);
5221                            }
5222                    }
5223                    catch (Exception e) {
5224                            throw processException(e);
5225                    }
5226                    finally {
5227                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5228                    }
5229            }
5230    
5231            /**
5232             * 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.
5233             *
5234             * @param pk the primary key of the user group
5235             * @param groups the groups to be associated with the user group
5236             * @throws SystemException if a system exception occurred
5237             */
5238            @Override
5239            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
5240                    throws SystemException {
5241                    try {
5242                            long[] groupPKs = new long[groups.size()];
5243    
5244                            for (int i = 0; i < groups.size(); i++) {
5245                                    com.liferay.portal.model.Group group = groups.get(i);
5246    
5247                                    groupPKs[i] = group.getPrimaryKey();
5248                            }
5249    
5250                            setGroups(pk, groupPKs);
5251                    }
5252                    catch (Exception e) {
5253                            throw processException(e);
5254                    }
5255                    finally {
5256                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
5257                    }
5258            }
5259    
5260            /**
5261             * Returns all the teams associated with the user group.
5262             *
5263             * @param pk the primary key of the user group
5264             * @return the teams associated with the user group
5265             * @throws SystemException if a system exception occurred
5266             */
5267            @Override
5268            public List<com.liferay.portal.model.Team> getTeams(long pk)
5269                    throws SystemException {
5270                    return getTeams(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
5271            }
5272    
5273            /**
5274             * Returns a range of all the teams associated with the user group.
5275             *
5276             * <p>
5277             * 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.
5278             * </p>
5279             *
5280             * @param pk the primary key of the user group
5281             * @param start the lower bound of the range of user groups
5282             * @param end the upper bound of the range of user groups (not inclusive)
5283             * @return the range of teams associated with the user group
5284             * @throws SystemException if a system exception occurred
5285             */
5286            @Override
5287            public List<com.liferay.portal.model.Team> getTeams(long pk, int start,
5288                    int end) throws SystemException {
5289                    return getTeams(pk, start, end, null);
5290            }
5291    
5292            public static final FinderPath FINDER_PATH_GET_TEAMS = new FinderPath(com.liferay.portal.model.impl.TeamModelImpl.ENTITY_CACHE_ENABLED,
5293                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
5294                            com.liferay.portal.model.impl.TeamImpl.class,
5295                            UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME, "getTeams",
5296                            new String[] {
5297                                    Long.class.getName(), Integer.class.getName(),
5298                                    Integer.class.getName(), OrderByComparator.class.getName()
5299                            });
5300    
5301            static {
5302                    FINDER_PATH_GET_TEAMS.setCacheKeyGeneratorCacheName(null);
5303            }
5304    
5305            /**
5306             * Returns an ordered range of all the teams associated with the user group.
5307             *
5308             * <p>
5309             * 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.
5310             * </p>
5311             *
5312             * @param pk the primary key of the user group
5313             * @param start the lower bound of the range of user groups
5314             * @param end the upper bound of the range of user groups (not inclusive)
5315             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5316             * @return the ordered range of teams associated with the user group
5317             * @throws SystemException if a system exception occurred
5318             */
5319            @Override
5320            public List<com.liferay.portal.model.Team> getTeams(long pk, int start,
5321                    int end, OrderByComparator orderByComparator) throws SystemException {
5322                    boolean pagination = true;
5323                    Object[] finderArgs = null;
5324    
5325                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5326                                    (orderByComparator == null)) {
5327                            pagination = false;
5328                            finderArgs = new Object[] { pk };
5329                    }
5330                    else {
5331                            finderArgs = new Object[] { pk, start, end, orderByComparator };
5332                    }
5333    
5334                    List<com.liferay.portal.model.Team> list = (List<com.liferay.portal.model.Team>)FinderCacheUtil.getResult(FINDER_PATH_GET_TEAMS,
5335                                    finderArgs, this);
5336    
5337                    if (list == null) {
5338                            Session session = null;
5339    
5340                            try {
5341                                    session = openSession();
5342    
5343                                    String sql = null;
5344    
5345                                    if (orderByComparator != null) {
5346                                            sql = _SQL_GETTEAMS.concat(ORDER_BY_CLAUSE)
5347                                                                               .concat(orderByComparator.getOrderBy());
5348                                    }
5349                                    else {
5350                                            sql = _SQL_GETTEAMS;
5351    
5352                                            if (pagination) {
5353                                                    sql = sql.concat(com.liferay.portal.model.impl.TeamModelImpl.ORDER_BY_SQL);
5354                                            }
5355                                    }
5356    
5357                                    SQLQuery q = session.createSQLQuery(sql);
5358    
5359                                    q.addEntity("Team", com.liferay.portal.model.impl.TeamImpl.class);
5360    
5361                                    QueryPos qPos = QueryPos.getInstance(q);
5362    
5363                                    qPos.add(pk);
5364    
5365                                    if (!pagination) {
5366                                            list = (List<com.liferay.portal.model.Team>)QueryUtil.list(q,
5367                                                            getDialect(), start, end, false);
5368    
5369                                            Collections.sort(list);
5370    
5371                                            list = new UnmodifiableList<com.liferay.portal.model.Team>(list);
5372                                    }
5373                                    else {
5374                                            list = (List<com.liferay.portal.model.Team>)QueryUtil.list(q,
5375                                                            getDialect(), start, end);
5376                                    }
5377    
5378                                    teamPersistence.cacheResult(list);
5379    
5380                                    FinderCacheUtil.putResult(FINDER_PATH_GET_TEAMS, finderArgs,
5381                                            list);
5382                            }
5383                            catch (Exception e) {
5384                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_TEAMS, finderArgs);
5385    
5386                                    throw processException(e);
5387                            }
5388                            finally {
5389                                    closeSession(session);
5390                            }
5391                    }
5392    
5393                    return list;
5394            }
5395    
5396            public static final FinderPath FINDER_PATH_GET_TEAMS_SIZE = new FinderPath(com.liferay.portal.model.impl.TeamModelImpl.ENTITY_CACHE_ENABLED,
5397                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
5398                            Long.class, UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
5399                            "getTeamsSize", new String[] { Long.class.getName() });
5400    
5401            static {
5402                    FINDER_PATH_GET_TEAMS_SIZE.setCacheKeyGeneratorCacheName(null);
5403            }
5404    
5405            /**
5406             * Returns the number of teams associated with the user group.
5407             *
5408             * @param pk the primary key of the user group
5409             * @return the number of teams associated with the user group
5410             * @throws SystemException if a system exception occurred
5411             */
5412            @Override
5413            public int getTeamsSize(long pk) throws SystemException {
5414                    Object[] finderArgs = new Object[] { pk };
5415    
5416                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_TEAMS_SIZE,
5417                                    finderArgs, this);
5418    
5419                    if (count == null) {
5420                            Session session = null;
5421    
5422                            try {
5423                                    session = openSession();
5424    
5425                                    SQLQuery q = session.createSQLQuery(_SQL_GETTEAMSSIZE);
5426    
5427                                    q.addScalar(COUNT_COLUMN_NAME,
5428                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
5429    
5430                                    QueryPos qPos = QueryPos.getInstance(q);
5431    
5432                                    qPos.add(pk);
5433    
5434                                    count = (Long)q.uniqueResult();
5435    
5436                                    FinderCacheUtil.putResult(FINDER_PATH_GET_TEAMS_SIZE,
5437                                            finderArgs, count);
5438                            }
5439                            catch (Exception e) {
5440                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_TEAMS_SIZE,
5441                                            finderArgs);
5442    
5443                                    throw processException(e);
5444                            }
5445                            finally {
5446                                    closeSession(session);
5447                            }
5448                    }
5449    
5450                    return count.intValue();
5451            }
5452    
5453            public static final FinderPath FINDER_PATH_CONTAINS_TEAM = new FinderPath(com.liferay.portal.model.impl.TeamModelImpl.ENTITY_CACHE_ENABLED,
5454                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERGROUPS_TEAMS,
5455                            Boolean.class,
5456                            UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME,
5457                            "containsTeam",
5458                            new String[] { Long.class.getName(), Long.class.getName() });
5459    
5460            /**
5461             * Returns <code>true</code> if the team is associated with the user group.
5462             *
5463             * @param pk the primary key of the user group
5464             * @param teamPK the primary key of the team
5465             * @return <code>true</code> if the team is associated with the user group; <code>false</code> otherwise
5466             * @throws SystemException if a system exception occurred
5467             */
5468            @Override
5469            public boolean containsTeam(long pk, long teamPK) throws SystemException {
5470                    Object[] finderArgs = new Object[] { pk, teamPK };
5471    
5472                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_TEAM,
5473                                    finderArgs, this);
5474    
5475                    if (value == null) {
5476                            try {
5477                                    value = Boolean.valueOf(containsTeam.contains(pk, teamPK));
5478    
5479                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_TEAM,
5480                                            finderArgs, value);
5481                            }
5482                            catch (Exception e) {
5483                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_TEAM,
5484                                            finderArgs);
5485    
5486                                    throw processException(e);
5487                            }
5488                    }
5489    
5490                    return value.booleanValue();
5491            }
5492    
5493            /**
5494             * Returns <code>true</code> if the user group has any teams associated with it.
5495             *
5496             * @param pk the primary key of the user group to check for associations with teams
5497             * @return <code>true</code> if the user group has any teams associated with it; <code>false</code> otherwise
5498             * @throws SystemException if a system exception occurred
5499             */
5500            @Override
5501            public boolean containsTeams(long pk) throws SystemException {
5502                    if (getTeamsSize(pk) > 0) {
5503                            return true;
5504                    }
5505                    else {
5506                            return false;
5507                    }
5508            }
5509    
5510            /**
5511             * Adds an association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5512             *
5513             * @param pk the primary key of the user group
5514             * @param teamPK the primary key of the team
5515             * @throws SystemException if a system exception occurred
5516             */
5517            @Override
5518            public void addTeam(long pk, long teamPK) throws SystemException {
5519                    try {
5520                            addTeam.add(pk, teamPK);
5521                    }
5522                    catch (Exception e) {
5523                            throw processException(e);
5524                    }
5525                    finally {
5526                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5527                    }
5528            }
5529    
5530            /**
5531             * Adds an association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5532             *
5533             * @param pk the primary key of the user group
5534             * @param team the team
5535             * @throws SystemException if a system exception occurred
5536             */
5537            @Override
5538            public void addTeam(long pk, com.liferay.portal.model.Team team)
5539                    throws SystemException {
5540                    try {
5541                            addTeam.add(pk, team.getPrimaryKey());
5542                    }
5543                    catch (Exception e) {
5544                            throw processException(e);
5545                    }
5546                    finally {
5547                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5548                    }
5549            }
5550    
5551            /**
5552             * Adds an association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5553             *
5554             * @param pk the primary key of the user group
5555             * @param teamPKs the primary keys of the teams
5556             * @throws SystemException if a system exception occurred
5557             */
5558            @Override
5559            public void addTeams(long pk, long[] teamPKs) throws SystemException {
5560                    try {
5561                            for (long teamPK : teamPKs) {
5562                                    addTeam.add(pk, teamPK);
5563                            }
5564                    }
5565                    catch (Exception e) {
5566                            throw processException(e);
5567                    }
5568                    finally {
5569                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5570                    }
5571            }
5572    
5573            /**
5574             * Adds an association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5575             *
5576             * @param pk the primary key of the user group
5577             * @param teams the teams
5578             * @throws SystemException if a system exception occurred
5579             */
5580            @Override
5581            public void addTeams(long pk, List<com.liferay.portal.model.Team> teams)
5582                    throws SystemException {
5583                    try {
5584                            for (com.liferay.portal.model.Team team : teams) {
5585                                    addTeam.add(pk, team.getPrimaryKey());
5586                            }
5587                    }
5588                    catch (Exception e) {
5589                            throw processException(e);
5590                    }
5591                    finally {
5592                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5593                    }
5594            }
5595    
5596            /**
5597             * Clears all associations between the user group and its teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5598             *
5599             * @param pk the primary key of the user group to clear the associated teams from
5600             * @throws SystemException if a system exception occurred
5601             */
5602            @Override
5603            public void clearTeams(long pk) throws SystemException {
5604                    try {
5605                            clearTeams.clear(pk);
5606                    }
5607                    catch (Exception e) {
5608                            throw processException(e);
5609                    }
5610                    finally {
5611                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5612                    }
5613            }
5614    
5615            /**
5616             * Removes the association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5617             *
5618             * @param pk the primary key of the user group
5619             * @param teamPK the primary key of the team
5620             * @throws SystemException if a system exception occurred
5621             */
5622            @Override
5623            public void removeTeam(long pk, long teamPK) throws SystemException {
5624                    try {
5625                            removeTeam.remove(pk, teamPK);
5626                    }
5627                    catch (Exception e) {
5628                            throw processException(e);
5629                    }
5630                    finally {
5631                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5632                    }
5633            }
5634    
5635            /**
5636             * Removes the association between the user group and the team. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5637             *
5638             * @param pk the primary key of the user group
5639             * @param team the team
5640             * @throws SystemException if a system exception occurred
5641             */
5642            @Override
5643            public void removeTeam(long pk, com.liferay.portal.model.Team team)
5644                    throws SystemException {
5645                    try {
5646                            removeTeam.remove(pk, team.getPrimaryKey());
5647                    }
5648                    catch (Exception e) {
5649                            throw processException(e);
5650                    }
5651                    finally {
5652                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5653                    }
5654            }
5655    
5656            /**
5657             * Removes the association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5658             *
5659             * @param pk the primary key of the user group
5660             * @param teamPKs the primary keys of the teams
5661             * @throws SystemException if a system exception occurred
5662             */
5663            @Override
5664            public void removeTeams(long pk, long[] teamPKs) throws SystemException {
5665                    try {
5666                            for (long teamPK : teamPKs) {
5667                                    removeTeam.remove(pk, teamPK);
5668                            }
5669                    }
5670                    catch (Exception e) {
5671                            throw processException(e);
5672                    }
5673                    finally {
5674                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5675                    }
5676            }
5677    
5678            /**
5679             * Removes the association between the user group and the teams. Also notifies the appropriate model listeners and clears the mapping table finder cache.
5680             *
5681             * @param pk the primary key of the user group
5682             * @param teams the teams
5683             * @throws SystemException if a system exception occurred
5684             */
5685            @Override
5686            public void removeTeams(long pk, List<com.liferay.portal.model.Team> teams)
5687                    throws SystemException {
5688                    try {
5689                            for (com.liferay.portal.model.Team team : teams) {
5690                                    removeTeam.remove(pk, team.getPrimaryKey());
5691                            }
5692                    }
5693                    catch (Exception e) {
5694                            throw processException(e);
5695                    }
5696                    finally {
5697                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5698                    }
5699            }
5700    
5701            /**
5702             * 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.
5703             *
5704             * @param pk the primary key of the user group
5705             * @param teamPKs the primary keys of the teams to be associated with the user group
5706             * @throws SystemException if a system exception occurred
5707             */
5708            @Override
5709            public void setTeams(long pk, long[] teamPKs) throws SystemException {
5710                    try {
5711                            Set<Long> teamPKSet = SetUtil.fromArray(teamPKs);
5712    
5713                            List<com.liferay.portal.model.Team> teams = getTeams(pk);
5714    
5715                            for (com.liferay.portal.model.Team team : teams) {
5716                                    if (!teamPKSet.remove(team.getPrimaryKey())) {
5717                                            removeTeam.remove(pk, team.getPrimaryKey());
5718                                    }
5719                            }
5720    
5721                            for (Long teamPK : teamPKSet) {
5722                                    addTeam.add(pk, teamPK);
5723                            }
5724                    }
5725                    catch (Exception e) {
5726                            throw processException(e);
5727                    }
5728                    finally {
5729                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5730                    }
5731            }
5732    
5733            /**
5734             * 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.
5735             *
5736             * @param pk the primary key of the user group
5737             * @param teams the teams to be associated with the user group
5738             * @throws SystemException if a system exception occurred
5739             */
5740            @Override
5741            public void setTeams(long pk, List<com.liferay.portal.model.Team> teams)
5742                    throws SystemException {
5743                    try {
5744                            long[] teamPKs = new long[teams.size()];
5745    
5746                            for (int i = 0; i < teams.size(); i++) {
5747                                    com.liferay.portal.model.Team team = teams.get(i);
5748    
5749                                    teamPKs[i] = team.getPrimaryKey();
5750                            }
5751    
5752                            setTeams(pk, teamPKs);
5753                    }
5754                    catch (Exception e) {
5755                            throw processException(e);
5756                    }
5757                    finally {
5758                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERGROUPS_TEAMS_NAME);
5759                    }
5760            }
5761    
5762            /**
5763             * Returns all the users associated with the user group.
5764             *
5765             * @param pk the primary key of the user group
5766             * @return the users associated with the user group
5767             * @throws SystemException if a system exception occurred
5768             */
5769            @Override
5770            public List<com.liferay.portal.model.User> getUsers(long pk)
5771                    throws SystemException {
5772                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
5773            }
5774    
5775            /**
5776             * Returns a range of all the users associated with the user group.
5777             *
5778             * <p>
5779             * 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.
5780             * </p>
5781             *
5782             * @param pk the primary key of the user group
5783             * @param start the lower bound of the range of user groups
5784             * @param end the upper bound of the range of user groups (not inclusive)
5785             * @return the range of users associated with the user group
5786             * @throws SystemException if a system exception occurred
5787             */
5788            @Override
5789            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
5790                    int end) throws SystemException {
5791                    return getUsers(pk, start, end, null);
5792            }
5793    
5794            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5795                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
5796                            com.liferay.portal.model.impl.UserImpl.class,
5797                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME, "getUsers",
5798                            new String[] {
5799                                    Long.class.getName(), Integer.class.getName(),
5800                                    Integer.class.getName(), OrderByComparator.class.getName()
5801                            });
5802    
5803            static {
5804                    FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
5805            }
5806    
5807            /**
5808             * Returns an ordered range of all the users associated with the user group.
5809             *
5810             * <p>
5811             * 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.
5812             * </p>
5813             *
5814             * @param pk the primary key of the user group
5815             * @param start the lower bound of the range of user groups
5816             * @param end the upper bound of the range of user groups (not inclusive)
5817             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5818             * @return the ordered range of users associated with the user group
5819             * @throws SystemException if a system exception occurred
5820             */
5821            @Override
5822            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
5823                    int end, OrderByComparator orderByComparator) throws SystemException {
5824                    boolean pagination = true;
5825                    Object[] finderArgs = null;
5826    
5827                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5828                                    (orderByComparator == null)) {
5829                            pagination = false;
5830                            finderArgs = new Object[] { pk };
5831                    }
5832                    else {
5833                            finderArgs = new Object[] { pk, start, end, orderByComparator };
5834                    }
5835    
5836                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
5837                                    finderArgs, this);
5838    
5839                    if (list == null) {
5840                            Session session = null;
5841    
5842                            try {
5843                                    session = openSession();
5844    
5845                                    String sql = null;
5846    
5847                                    if (orderByComparator != null) {
5848                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
5849                                                                               .concat(orderByComparator.getOrderBy());
5850                                    }
5851                                    else {
5852                                            sql = _SQL_GETUSERS;
5853    
5854                                            if (pagination) {
5855                                                    sql = sql.concat(com.liferay.portal.model.impl.UserModelImpl.ORDER_BY_SQL);
5856                                            }
5857                                    }
5858    
5859                                    SQLQuery q = session.createSQLQuery(sql);
5860    
5861                                    q.addEntity("User_",
5862                                            com.liferay.portal.model.impl.UserImpl.class);
5863    
5864                                    QueryPos qPos = QueryPos.getInstance(q);
5865    
5866                                    qPos.add(pk);
5867    
5868                                    if (!pagination) {
5869                                            list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
5870                                                            getDialect(), start, end, false);
5871    
5872                                            Collections.sort(list);
5873    
5874                                            list = new UnmodifiableList<com.liferay.portal.model.User>(list);
5875                                    }
5876                                    else {
5877                                            list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
5878                                                            getDialect(), start, end);
5879                                    }
5880    
5881                                    userPersistence.cacheResult(list);
5882    
5883                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
5884                                            list);
5885                            }
5886                            catch (Exception e) {
5887                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS, finderArgs);
5888    
5889                                    throw processException(e);
5890                            }
5891                            finally {
5892                                    closeSession(session);
5893                            }
5894                    }
5895    
5896                    return list;
5897            }
5898    
5899            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5900                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
5901                            Long.class, UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
5902                            "getUsersSize", new String[] { Long.class.getName() });
5903    
5904            static {
5905                    FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
5906            }
5907    
5908            /**
5909             * Returns the number of users associated with the user group.
5910             *
5911             * @param pk the primary key of the user group
5912             * @return the number of users associated with the user group
5913             * @throws SystemException if a system exception occurred
5914             */
5915            @Override
5916            public int getUsersSize(long pk) throws SystemException {
5917                    Object[] finderArgs = new Object[] { pk };
5918    
5919                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
5920                                    finderArgs, this);
5921    
5922                    if (count == null) {
5923                            Session session = null;
5924    
5925                            try {
5926                                    session = openSession();
5927    
5928                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
5929    
5930                                    q.addScalar(COUNT_COLUMN_NAME,
5931                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
5932    
5933                                    QueryPos qPos = QueryPos.getInstance(q);
5934    
5935                                    qPos.add(pk);
5936    
5937                                    count = (Long)q.uniqueResult();
5938    
5939                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
5940                                            finderArgs, count);
5941                            }
5942                            catch (Exception e) {
5943                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS_SIZE,
5944                                            finderArgs);
5945    
5946                                    throw processException(e);
5947                            }
5948                            finally {
5949                                    closeSession(session);
5950                            }
5951                    }
5952    
5953                    return count.intValue();
5954            }
5955    
5956            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5957                            UserGroupModelImpl.FINDER_CACHE_ENABLED_USERS_USERGROUPS,
5958                            Boolean.class,
5959                            UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME,
5960                            "containsUser",
5961                            new String[] { Long.class.getName(), Long.class.getName() });
5962    
5963            /**
5964             * Returns <code>true</code> if the user is associated with the user group.
5965             *
5966             * @param pk the primary key of the user group
5967             * @param userPK the primary key of the user
5968             * @return <code>true</code> if the user is associated with the user group; <code>false</code> otherwise
5969             * @throws SystemException if a system exception occurred
5970             */
5971            @Override
5972            public boolean containsUser(long pk, long userPK) throws SystemException {
5973                    Object[] finderArgs = new Object[] { pk, userPK };
5974    
5975                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
5976                                    finderArgs, this);
5977    
5978                    if (value == null) {
5979                            try {
5980                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
5981    
5982                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
5983                                            finderArgs, value);
5984                            }
5985                            catch (Exception e) {
5986                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USER,
5987                                            finderArgs);
5988    
5989                                    throw processException(e);
5990                            }
5991                    }
5992    
5993                    return value.booleanValue();
5994            }
5995    
5996            /**
5997             * Returns <code>true</code> if the user group has any users associated with it.
5998             *
5999             * @param pk the primary key of the user group to check for associations with users
6000             * @return <code>true</code> if the user group has any users associated with it; <code>false</code> otherwise
6001             * @throws SystemException if a system exception occurred
6002             */
6003            @Override
6004            public boolean containsUsers(long pk) throws SystemException {
6005                    if (getUsersSize(pk) > 0) {
6006                            return true;
6007                    }
6008                    else {
6009                            return false;
6010                    }
6011            }
6012    
6013            /**
6014             * Adds an association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6015             *
6016             * @param pk the primary key of the user group
6017             * @param userPK the primary key of the user
6018             * @throws SystemException if a system exception occurred
6019             */
6020            @Override
6021            public void addUser(long pk, long userPK) throws SystemException {
6022                    try {
6023                            addUser.add(pk, userPK);
6024                    }
6025                    catch (Exception e) {
6026                            throw processException(e);
6027                    }
6028                    finally {
6029                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6030                    }
6031            }
6032    
6033            /**
6034             * Adds an association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6035             *
6036             * @param pk the primary key of the user group
6037             * @param user the user
6038             * @throws SystemException if a system exception occurred
6039             */
6040            @Override
6041            public void addUser(long pk, com.liferay.portal.model.User user)
6042                    throws SystemException {
6043                    try {
6044                            addUser.add(pk, user.getPrimaryKey());
6045                    }
6046                    catch (Exception e) {
6047                            throw processException(e);
6048                    }
6049                    finally {
6050                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6051                    }
6052            }
6053    
6054            /**
6055             * Adds an association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6056             *
6057             * @param pk the primary key of the user group
6058             * @param userPKs the primary keys of the users
6059             * @throws SystemException if a system exception occurred
6060             */
6061            @Override
6062            public void addUsers(long pk, long[] userPKs) throws SystemException {
6063                    try {
6064                            for (long userPK : userPKs) {
6065                                    addUser.add(pk, userPK);
6066                            }
6067                    }
6068                    catch (Exception e) {
6069                            throw processException(e);
6070                    }
6071                    finally {
6072                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6073                    }
6074            }
6075    
6076            /**
6077             * Adds an association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6078             *
6079             * @param pk the primary key of the user group
6080             * @param users the users
6081             * @throws SystemException if a system exception occurred
6082             */
6083            @Override
6084            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
6085                    throws SystemException {
6086                    try {
6087                            for (com.liferay.portal.model.User user : users) {
6088                                    addUser.add(pk, user.getPrimaryKey());
6089                            }
6090                    }
6091                    catch (Exception e) {
6092                            throw processException(e);
6093                    }
6094                    finally {
6095                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6096                    }
6097            }
6098    
6099            /**
6100             * Clears all associations between the user group and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6101             *
6102             * @param pk the primary key of the user group to clear the associated users from
6103             * @throws SystemException if a system exception occurred
6104             */
6105            @Override
6106            public void clearUsers(long pk) throws SystemException {
6107                    try {
6108                            clearUsers.clear(pk);
6109                    }
6110                    catch (Exception e) {
6111                            throw processException(e);
6112                    }
6113                    finally {
6114                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6115                    }
6116            }
6117    
6118            /**
6119             * Removes the association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6120             *
6121             * @param pk the primary key of the user group
6122             * @param userPK the primary key of the user
6123             * @throws SystemException if a system exception occurred
6124             */
6125            @Override
6126            public void removeUser(long pk, long userPK) throws SystemException {
6127                    try {
6128                            removeUser.remove(pk, userPK);
6129                    }
6130                    catch (Exception e) {
6131                            throw processException(e);
6132                    }
6133                    finally {
6134                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6135                    }
6136            }
6137    
6138            /**
6139             * Removes the association between the user group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6140             *
6141             * @param pk the primary key of the user group
6142             * @param user the user
6143             * @throws SystemException if a system exception occurred
6144             */
6145            @Override
6146            public void removeUser(long pk, com.liferay.portal.model.User user)
6147                    throws SystemException {
6148                    try {
6149                            removeUser.remove(pk, user.getPrimaryKey());
6150                    }
6151                    catch (Exception e) {
6152                            throw processException(e);
6153                    }
6154                    finally {
6155                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6156                    }
6157            }
6158    
6159            /**
6160             * Removes the association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6161             *
6162             * @param pk the primary key of the user group
6163             * @param userPKs the primary keys of the users
6164             * @throws SystemException if a system exception occurred
6165             */
6166            @Override
6167            public void removeUsers(long pk, long[] userPKs) throws SystemException {
6168                    try {
6169                            for (long userPK : userPKs) {
6170                                    removeUser.remove(pk, userPK);
6171                            }
6172                    }
6173                    catch (Exception e) {
6174                            throw processException(e);
6175                    }
6176                    finally {
6177                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6178                    }
6179            }
6180    
6181            /**
6182             * Removes the association between the user group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
6183             *
6184             * @param pk the primary key of the user group
6185             * @param users the users
6186             * @throws SystemException if a system exception occurred
6187             */
6188            @Override
6189            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
6190                    throws SystemException {
6191                    try {
6192                            for (com.liferay.portal.model.User user : users) {
6193                                    removeUser.remove(pk, user.getPrimaryKey());
6194                            }
6195                    }
6196                    catch (Exception e) {
6197                            throw processException(e);
6198                    }
6199                    finally {
6200                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6201                    }
6202            }
6203    
6204            /**
6205             * 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.
6206             *
6207             * @param pk the primary key of the user group
6208             * @param userPKs the primary keys of the users to be associated with the user group
6209             * @throws SystemException if a system exception occurred
6210             */
6211            @Override
6212            public void setUsers(long pk, long[] userPKs) throws SystemException {
6213                    try {
6214                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
6215    
6216                            List<com.liferay.portal.model.User> users = getUsers(pk);
6217    
6218                            for (com.liferay.portal.model.User user : users) {
6219                                    if (!userPKSet.remove(user.getPrimaryKey())) {
6220                                            removeUser.remove(pk, user.getPrimaryKey());
6221                                    }
6222                            }
6223    
6224                            for (Long userPK : userPKSet) {
6225                                    addUser.add(pk, userPK);
6226                            }
6227                    }
6228                    catch (Exception e) {
6229                            throw processException(e);
6230                    }
6231                    finally {
6232                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6233                    }
6234            }
6235    
6236            /**
6237             * 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.
6238             *
6239             * @param pk the primary key of the user group
6240             * @param users the users to be associated with the user group
6241             * @throws SystemException if a system exception occurred
6242             */
6243            @Override
6244            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
6245                    throws SystemException {
6246                    try {
6247                            long[] userPKs = new long[users.size()];
6248    
6249                            for (int i = 0; i < users.size(); i++) {
6250                                    com.liferay.portal.model.User user = users.get(i);
6251    
6252                                    userPKs[i] = user.getPrimaryKey();
6253                            }
6254    
6255                            setUsers(pk, userPKs);
6256                    }
6257                    catch (Exception e) {
6258                            throw processException(e);
6259                    }
6260                    finally {
6261                            FinderCacheUtil.clearCache(UserGroupModelImpl.MAPPING_TABLE_USERS_USERGROUPS_NAME);
6262                    }
6263            }
6264    
6265            @Override
6266            protected Set<String> getBadColumnNames() {
6267                    return _badColumnNames;
6268            }
6269    
6270            /**
6271             * Initializes the user group persistence.
6272             */
6273            public void afterPropertiesSet() {
6274                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6275                                            com.liferay.portal.util.PropsUtil.get(
6276                                                    "value.object.listener.com.liferay.portal.model.UserGroup")));
6277    
6278                    if (listenerClassNames.length > 0) {
6279                            try {
6280                                    List<ModelListener<UserGroup>> listenersList = new ArrayList<ModelListener<UserGroup>>();
6281    
6282                                    for (String listenerClassName : listenerClassNames) {
6283                                            listenersList.add((ModelListener<UserGroup>)InstanceFactory.newInstance(
6284                                                            getClassLoader(), listenerClassName));
6285                                    }
6286    
6287                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6288                            }
6289                            catch (Exception e) {
6290                                    _log.error(e);
6291                            }
6292                    }
6293    
6294                    containsGroup = new ContainsGroup();
6295    
6296                    addGroup = new AddGroup();
6297                    clearGroups = new ClearGroups();
6298                    removeGroup = new RemoveGroup();
6299    
6300                    containsTeam = new ContainsTeam();
6301    
6302                    addTeam = new AddTeam();
6303                    clearTeams = new ClearTeams();
6304                    removeTeam = new RemoveTeam();
6305    
6306                    containsUser = new ContainsUser();
6307    
6308                    addUser = new AddUser();
6309                    clearUsers = new ClearUsers();
6310                    removeUser = new RemoveUser();
6311            }
6312    
6313            public void destroy() {
6314                    EntityCacheUtil.removeCache(UserGroupImpl.class.getName());
6315                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6316                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6317                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6318            }
6319    
6320            @BeanReference(type = GroupPersistence.class)
6321            protected GroupPersistence groupPersistence;
6322            protected ContainsGroup containsGroup;
6323            protected AddGroup addGroup;
6324            protected ClearGroups clearGroups;
6325            protected RemoveGroup removeGroup;
6326            @BeanReference(type = TeamPersistence.class)
6327            protected TeamPersistence teamPersistence;
6328            protected ContainsTeam containsTeam;
6329            protected AddTeam addTeam;
6330            protected ClearTeams clearTeams;
6331            protected RemoveTeam removeTeam;
6332            @BeanReference(type = UserPersistence.class)
6333            protected UserPersistence userPersistence;
6334            protected ContainsUser containsUser;
6335            protected AddUser addUser;
6336            protected ClearUsers clearUsers;
6337            protected RemoveUser removeUser;
6338    
6339            protected class ContainsGroup {
6340                    protected ContainsGroup() {
6341                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
6342                                            "SELECT 1 FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?",
6343                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
6344                                            RowMapper.COUNT);
6345                    }
6346    
6347                    protected boolean contains(long userGroupId, long groupId) {
6348                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
6349                                                    new Long(userGroupId), new Long(groupId)
6350                                            });
6351    
6352                            if (results.isEmpty()) {
6353                                    return false;
6354                            }
6355    
6356                            return true;
6357                    }
6358    
6359                    private MappingSqlQuery<Integer> _mappingSqlQuery;
6360            }
6361    
6362            protected class AddGroup {
6363                    protected AddGroup() {
6364                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6365                                            "INSERT INTO Groups_UserGroups (userGroupId, groupId) VALUES (?, ?)",
6366                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6367                    }
6368    
6369                    protected void add(long userGroupId, long groupId)
6370                            throws SystemException {
6371                            if (!containsGroup.contains(userGroupId, groupId)) {
6372                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
6373    
6374                                    for (ModelListener<UserGroup> listener : listeners) {
6375                                            listener.onBeforeAddAssociation(userGroupId,
6376                                                    com.liferay.portal.model.Group.class.getName(), groupId);
6377                                    }
6378    
6379                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6380                                            listener.onBeforeAddAssociation(groupId,
6381                                                    UserGroup.class.getName(), userGroupId);
6382                                    }
6383    
6384                                    _sqlUpdate.update(new Object[] {
6385                                                    new Long(userGroupId), new Long(groupId)
6386                                            });
6387    
6388                                    for (ModelListener<UserGroup> listener : listeners) {
6389                                            listener.onAfterAddAssociation(userGroupId,
6390                                                    com.liferay.portal.model.Group.class.getName(), groupId);
6391                                    }
6392    
6393                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6394                                            listener.onAfterAddAssociation(groupId,
6395                                                    UserGroup.class.getName(), userGroupId);
6396                                    }
6397                            }
6398                    }
6399    
6400                    private SqlUpdate _sqlUpdate;
6401            }
6402    
6403            protected class ClearGroups {
6404                    protected ClearGroups() {
6405                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6406                                            "DELETE FROM Groups_UserGroups WHERE userGroupId = ?",
6407                                            new int[] { java.sql.Types.BIGINT });
6408                    }
6409    
6410                    protected void clear(long userGroupId) throws SystemException {
6411                            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
6412    
6413                            List<com.liferay.portal.model.Group> groups = null;
6414    
6415                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
6416                                    groups = getGroups(userGroupId);
6417    
6418                                    for (com.liferay.portal.model.Group group : groups) {
6419                                            for (ModelListener<UserGroup> listener : listeners) {
6420                                                    listener.onBeforeRemoveAssociation(userGroupId,
6421                                                            com.liferay.portal.model.Group.class.getName(),
6422                                                            group.getPrimaryKey());
6423                                            }
6424    
6425                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6426                                                    listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
6427                                                            UserGroup.class.getName(), userGroupId);
6428                                            }
6429                                    }
6430                            }
6431    
6432                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
6433    
6434                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
6435                                    for (com.liferay.portal.model.Group group : groups) {
6436                                            for (ModelListener<UserGroup> listener : listeners) {
6437                                                    listener.onAfterRemoveAssociation(userGroupId,
6438                                                            com.liferay.portal.model.Group.class.getName(),
6439                                                            group.getPrimaryKey());
6440                                            }
6441    
6442                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6443                                                    listener.onAfterRemoveAssociation(group.getPrimaryKey(),
6444                                                            UserGroup.class.getName(), userGroupId);
6445                                            }
6446                                    }
6447                            }
6448                    }
6449    
6450                    private SqlUpdate _sqlUpdate;
6451            }
6452    
6453            protected class RemoveGroup {
6454                    protected RemoveGroup() {
6455                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6456                                            "DELETE FROM Groups_UserGroups WHERE userGroupId = ? AND groupId = ?",
6457                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6458                    }
6459    
6460                    protected void remove(long userGroupId, long groupId)
6461                            throws SystemException {
6462                            if (containsGroup.contains(userGroupId, groupId)) {
6463                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
6464    
6465                                    for (ModelListener<UserGroup> listener : listeners) {
6466                                            listener.onBeforeRemoveAssociation(userGroupId,
6467                                                    com.liferay.portal.model.Group.class.getName(), groupId);
6468                                    }
6469    
6470                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6471                                            listener.onBeforeRemoveAssociation(groupId,
6472                                                    UserGroup.class.getName(), userGroupId);
6473                                    }
6474    
6475                                    _sqlUpdate.update(new Object[] {
6476                                                    new Long(userGroupId), new Long(groupId)
6477                                            });
6478    
6479                                    for (ModelListener<UserGroup> listener : listeners) {
6480                                            listener.onAfterRemoveAssociation(userGroupId,
6481                                                    com.liferay.portal.model.Group.class.getName(), groupId);
6482                                    }
6483    
6484                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6485                                            listener.onAfterRemoveAssociation(groupId,
6486                                                    UserGroup.class.getName(), userGroupId);
6487                                    }
6488                            }
6489                    }
6490    
6491                    private SqlUpdate _sqlUpdate;
6492            }
6493    
6494            protected class ContainsTeam {
6495                    protected ContainsTeam() {
6496                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
6497                                            "SELECT 1 FROM UserGroups_Teams WHERE userGroupId = ? AND teamId = ?",
6498                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
6499                                            RowMapper.COUNT);
6500                    }
6501    
6502                    protected boolean contains(long userGroupId, long teamId) {
6503                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
6504                                                    new Long(userGroupId), new Long(teamId)
6505                                            });
6506    
6507                            if (results.isEmpty()) {
6508                                    return false;
6509                            }
6510    
6511                            return true;
6512                    }
6513    
6514                    private MappingSqlQuery<Integer> _mappingSqlQuery;
6515            }
6516    
6517            protected class AddTeam {
6518                    protected AddTeam() {
6519                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6520                                            "INSERT INTO UserGroups_Teams (userGroupId, teamId) VALUES (?, ?)",
6521                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6522                    }
6523    
6524                    protected void add(long userGroupId, long teamId)
6525                            throws SystemException {
6526                            if (!containsTeam.contains(userGroupId, teamId)) {
6527                                    ModelListener<com.liferay.portal.model.Team>[] teamListeners = teamPersistence.getListeners();
6528    
6529                                    for (ModelListener<UserGroup> listener : listeners) {
6530                                            listener.onBeforeAddAssociation(userGroupId,
6531                                                    com.liferay.portal.model.Team.class.getName(), teamId);
6532                                    }
6533    
6534                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
6535                                            listener.onBeforeAddAssociation(teamId,
6536                                                    UserGroup.class.getName(), userGroupId);
6537                                    }
6538    
6539                                    _sqlUpdate.update(new Object[] {
6540                                                    new Long(userGroupId), new Long(teamId)
6541                                            });
6542    
6543                                    for (ModelListener<UserGroup> listener : listeners) {
6544                                            listener.onAfterAddAssociation(userGroupId,
6545                                                    com.liferay.portal.model.Team.class.getName(), teamId);
6546                                    }
6547    
6548                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
6549                                            listener.onAfterAddAssociation(teamId,
6550                                                    UserGroup.class.getName(), userGroupId);
6551                                    }
6552                            }
6553                    }
6554    
6555                    private SqlUpdate _sqlUpdate;
6556            }
6557    
6558            protected class ClearTeams {
6559                    protected ClearTeams() {
6560                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6561                                            "DELETE FROM UserGroups_Teams WHERE userGroupId = ?",
6562                                            new int[] { java.sql.Types.BIGINT });
6563                    }
6564    
6565                    protected void clear(long userGroupId) throws SystemException {
6566                            ModelListener<com.liferay.portal.model.Team>[] teamListeners = teamPersistence.getListeners();
6567    
6568                            List<com.liferay.portal.model.Team> teams = null;
6569    
6570                            if ((listeners.length > 0) || (teamListeners.length > 0)) {
6571                                    teams = getTeams(userGroupId);
6572    
6573                                    for (com.liferay.portal.model.Team team : teams) {
6574                                            for (ModelListener<UserGroup> listener : listeners) {
6575                                                    listener.onBeforeRemoveAssociation(userGroupId,
6576                                                            com.liferay.portal.model.Team.class.getName(),
6577                                                            team.getPrimaryKey());
6578                                            }
6579    
6580                                            for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
6581                                                    listener.onBeforeRemoveAssociation(team.getPrimaryKey(),
6582                                                            UserGroup.class.getName(), userGroupId);
6583                                            }
6584                                    }
6585                            }
6586    
6587                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
6588    
6589                            if ((listeners.length > 0) || (teamListeners.length > 0)) {
6590                                    for (com.liferay.portal.model.Team team : teams) {
6591                                            for (ModelListener<UserGroup> listener : listeners) {
6592                                                    listener.onAfterRemoveAssociation(userGroupId,
6593                                                            com.liferay.portal.model.Team.class.getName(),
6594                                                            team.getPrimaryKey());
6595                                            }
6596    
6597                                            for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
6598                                                    listener.onAfterRemoveAssociation(team.getPrimaryKey(),
6599                                                            UserGroup.class.getName(), userGroupId);
6600                                            }
6601                                    }
6602                            }
6603                    }
6604    
6605                    private SqlUpdate _sqlUpdate;
6606            }
6607    
6608            protected class RemoveTeam {
6609                    protected RemoveTeam() {
6610                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6611                                            "DELETE FROM UserGroups_Teams WHERE userGroupId = ? AND teamId = ?",
6612                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6613                    }
6614    
6615                    protected void remove(long userGroupId, long teamId)
6616                            throws SystemException {
6617                            if (containsTeam.contains(userGroupId, teamId)) {
6618                                    ModelListener<com.liferay.portal.model.Team>[] teamListeners = teamPersistence.getListeners();
6619    
6620                                    for (ModelListener<UserGroup> listener : listeners) {
6621                                            listener.onBeforeRemoveAssociation(userGroupId,
6622                                                    com.liferay.portal.model.Team.class.getName(), teamId);
6623                                    }
6624    
6625                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
6626                                            listener.onBeforeRemoveAssociation(teamId,
6627                                                    UserGroup.class.getName(), userGroupId);
6628                                    }
6629    
6630                                    _sqlUpdate.update(new Object[] {
6631                                                    new Long(userGroupId), new Long(teamId)
6632                                            });
6633    
6634                                    for (ModelListener<UserGroup> listener : listeners) {
6635                                            listener.onAfterRemoveAssociation(userGroupId,
6636                                                    com.liferay.portal.model.Team.class.getName(), teamId);
6637                                    }
6638    
6639                                    for (ModelListener<com.liferay.portal.model.Team> listener : teamListeners) {
6640                                            listener.onAfterRemoveAssociation(teamId,
6641                                                    UserGroup.class.getName(), userGroupId);
6642                                    }
6643                            }
6644                    }
6645    
6646                    private SqlUpdate _sqlUpdate;
6647            }
6648    
6649            protected class ContainsUser {
6650                    protected ContainsUser() {
6651                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
6652                                            "SELECT 1 FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
6653                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
6654                                            RowMapper.COUNT);
6655                    }
6656    
6657                    protected boolean contains(long userGroupId, long userId) {
6658                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
6659                                                    new Long(userGroupId), new Long(userId)
6660                                            });
6661    
6662                            if (results.isEmpty()) {
6663                                    return false;
6664                            }
6665    
6666                            return true;
6667                    }
6668    
6669                    private MappingSqlQuery<Integer> _mappingSqlQuery;
6670            }
6671    
6672            protected class AddUser {
6673                    protected AddUser() {
6674                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6675                                            "INSERT INTO Users_UserGroups (userGroupId, userId) VALUES (?, ?)",
6676                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6677                    }
6678    
6679                    protected void add(long userGroupId, long userId)
6680                            throws SystemException {
6681                            if (!containsUser.contains(userGroupId, userId)) {
6682                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6683    
6684                                    for (ModelListener<UserGroup> listener : listeners) {
6685                                            listener.onBeforeAddAssociation(userGroupId,
6686                                                    com.liferay.portal.model.User.class.getName(), userId);
6687                                    }
6688    
6689                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6690                                            listener.onBeforeAddAssociation(userId,
6691                                                    UserGroup.class.getName(), userGroupId);
6692                                    }
6693    
6694                                    _sqlUpdate.update(new Object[] {
6695                                                    new Long(userGroupId), new Long(userId)
6696                                            });
6697    
6698                                    for (ModelListener<UserGroup> listener : listeners) {
6699                                            listener.onAfterAddAssociation(userGroupId,
6700                                                    com.liferay.portal.model.User.class.getName(), userId);
6701                                    }
6702    
6703                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6704                                            listener.onAfterAddAssociation(userId,
6705                                                    UserGroup.class.getName(), userGroupId);
6706                                    }
6707                            }
6708                    }
6709    
6710                    private SqlUpdate _sqlUpdate;
6711            }
6712    
6713            protected class ClearUsers {
6714                    protected ClearUsers() {
6715                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6716                                            "DELETE FROM Users_UserGroups WHERE userGroupId = ?",
6717                                            new int[] { java.sql.Types.BIGINT });
6718                    }
6719    
6720                    protected void clear(long userGroupId) throws SystemException {
6721                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6722    
6723                            List<com.liferay.portal.model.User> users = null;
6724    
6725                            if ((listeners.length > 0) || (userListeners.length > 0)) {
6726                                    users = getUsers(userGroupId);
6727    
6728                                    for (com.liferay.portal.model.User user : users) {
6729                                            for (ModelListener<UserGroup> listener : listeners) {
6730                                                    listener.onBeforeRemoveAssociation(userGroupId,
6731                                                            com.liferay.portal.model.User.class.getName(),
6732                                                            user.getPrimaryKey());
6733                                            }
6734    
6735                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6736                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
6737                                                            UserGroup.class.getName(), userGroupId);
6738                                            }
6739                                    }
6740                            }
6741    
6742                            _sqlUpdate.update(new Object[] { new Long(userGroupId) });
6743    
6744                            if ((listeners.length > 0) || (userListeners.length > 0)) {
6745                                    for (com.liferay.portal.model.User user : users) {
6746                                            for (ModelListener<UserGroup> listener : listeners) {
6747                                                    listener.onAfterRemoveAssociation(userGroupId,
6748                                                            com.liferay.portal.model.User.class.getName(),
6749                                                            user.getPrimaryKey());
6750                                            }
6751    
6752                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6753                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
6754                                                            UserGroup.class.getName(), userGroupId);
6755                                            }
6756                                    }
6757                            }
6758                    }
6759    
6760                    private SqlUpdate _sqlUpdate;
6761            }
6762    
6763            protected class RemoveUser {
6764                    protected RemoveUser() {
6765                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6766                                            "DELETE FROM Users_UserGroups WHERE userGroupId = ? AND userId = ?",
6767                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6768                    }
6769    
6770                    protected void remove(long userGroupId, long userId)
6771                            throws SystemException {
6772                            if (containsUser.contains(userGroupId, userId)) {
6773                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6774    
6775                                    for (ModelListener<UserGroup> listener : listeners) {
6776                                            listener.onBeforeRemoveAssociation(userGroupId,
6777                                                    com.liferay.portal.model.User.class.getName(), userId);
6778                                    }
6779    
6780                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6781                                            listener.onBeforeRemoveAssociation(userId,
6782                                                    UserGroup.class.getName(), userGroupId);
6783                                    }
6784    
6785                                    _sqlUpdate.update(new Object[] {
6786                                                    new Long(userGroupId), new Long(userId)
6787                                            });
6788    
6789                                    for (ModelListener<UserGroup> listener : listeners) {
6790                                            listener.onAfterRemoveAssociation(userGroupId,
6791                                                    com.liferay.portal.model.User.class.getName(), userId);
6792                                    }
6793    
6794                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6795                                            listener.onAfterRemoveAssociation(userId,
6796                                                    UserGroup.class.getName(), userGroupId);
6797                                    }
6798                            }
6799                    }
6800    
6801                    private SqlUpdate _sqlUpdate;
6802            }
6803    
6804            private static final String _SQL_SELECT_USERGROUP = "SELECT userGroup FROM UserGroup userGroup";
6805            private static final String _SQL_SELECT_USERGROUP_WHERE = "SELECT userGroup FROM UserGroup userGroup WHERE ";
6806            private static final String _SQL_COUNT_USERGROUP = "SELECT COUNT(userGroup) FROM UserGroup userGroup";
6807            private static final String _SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(userGroup) FROM UserGroup userGroup WHERE ";
6808            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_UserGroups ON (Groups_UserGroups.groupId = Group_.groupId) WHERE (Groups_UserGroups.userGroupId = ?)";
6809            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE userGroupId = ?";
6810            private static final String _SQL_GETTEAMS = "SELECT {Team.*} FROM Team INNER JOIN UserGroups_Teams ON (UserGroups_Teams.teamId = Team.teamId) WHERE (UserGroups_Teams.userGroupId = ?)";
6811            private static final String _SQL_GETTEAMSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM UserGroups_Teams WHERE userGroupId = ?";
6812            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_UserGroups ON (Users_UserGroups.userId = User_.userId) WHERE (Users_UserGroups.userGroupId = ?)";
6813            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_UserGroups WHERE userGroupId = ?";
6814            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "userGroup.userGroupId";
6815            private static final String _FILTER_SQL_SELECT_USERGROUP_WHERE = "SELECT DISTINCT {userGroup.*} FROM UserGroup userGroup WHERE ";
6816            private static final String _FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_1 =
6817                    "SELECT {UserGroup.*} FROM (SELECT DISTINCT userGroup.userGroupId FROM UserGroup userGroup WHERE ";
6818            private static final String _FILTER_SQL_SELECT_USERGROUP_NO_INLINE_DISTINCT_WHERE_2 =
6819                    ") TEMP_TABLE INNER JOIN UserGroup ON TEMP_TABLE.userGroupId = UserGroup.userGroupId";
6820            private static final String _FILTER_SQL_COUNT_USERGROUP_WHERE = "SELECT COUNT(DISTINCT userGroup.userGroupId) AS COUNT_VALUE FROM UserGroup userGroup WHERE ";
6821            private static final String _FILTER_ENTITY_ALIAS = "userGroup";
6822            private static final String _FILTER_ENTITY_TABLE = "UserGroup";
6823            private static final String _ORDER_BY_ENTITY_ALIAS = "userGroup.";
6824            private static final String _ORDER_BY_ENTITY_TABLE = "UserGroup.";
6825            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroup exists with the primary key ";
6826            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroup exists with the key {";
6827            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6828            private static Log _log = LogFactoryUtil.getLog(UserGroupPersistenceImpl.class);
6829            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
6830                                    "uuid"
6831                            });
6832            private static UserGroup _nullUserGroup = new UserGroupImpl() {
6833                            @Override
6834                            public Object clone() {
6835                                    return this;
6836                            }
6837    
6838                            @Override
6839                            public CacheModel<UserGroup> toCacheModel() {
6840                                    return _nullUserGroupCacheModel;
6841                            }
6842                    };
6843    
6844            private static CacheModel<UserGroup> _nullUserGroupCacheModel = new CacheModel<UserGroup>() {
6845                            @Override
6846                            public UserGroup toEntityModel() {
6847                                    return _nullUserGroup;
6848                            }
6849                    };
6850    }