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