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