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