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