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