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.NoSuchGroupException;
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.Group;
048    import com.liferay.portal.model.ModelListener;
049    import com.liferay.portal.model.impl.GroupImpl;
050    import com.liferay.portal.model.impl.GroupModelImpl;
051    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
052    
053    import java.io.Serializable;
054    
055    import java.util.ArrayList;
056    import java.util.Collections;
057    import java.util.List;
058    import java.util.Set;
059    
060    /**
061     * The persistence implementation for the group service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see GroupPersistence
069     * @see GroupUtil
070     * @generated
071     */
072    public class GroupPersistenceImpl extends BasePersistenceImpl<Group>
073            implements GroupPersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * Never modify or reference this class directly. Always use {@link GroupUtil} to access the group persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = GroupImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
085                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
088                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
091                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
094                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
103                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105                            new String[] { String.class.getName() },
106                            GroupModelImpl.UUID_COLUMN_BITMASK |
107                            GroupModelImpl.NAME_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
109                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the groups where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching groups
118             * @throws SystemException if a system exception occurred
119             */
120            public List<Group> findByUuid(String uuid) throws SystemException {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the groups where uuid = &#63;.
126             *
127             * <p>
128             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.GroupModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of groups
133             * @param end the upper bound of the range of groups (not inclusive)
134             * @return the range of matching groups
135             * @throws SystemException if a system exception occurred
136             */
137            public List<Group> findByUuid(String uuid, int start, int end)
138                    throws SystemException {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the groups where uuid = &#63;.
144             *
145             * <p>
146             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.GroupModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of groups
151             * @param end the upper bound of the range of groups (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching groups
154             * @throws SystemException if a system exception occurred
155             */
156            public List<Group> findByUuid(String uuid, int start, int end,
157                    OrderByComparator orderByComparator) throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
171                    }
172    
173                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (Group group : list) {
178                                    if (!Validator.equals(uuid, group.getUuid())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_GROUP__WHERE);
198    
199                            boolean bindUuid = false;
200    
201                            if (uuid == null) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
203                            }
204                            else if (uuid.equals(StringPool.BLANK)) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
206                            }
207                            else {
208                                    bindUuid = true;
209    
210                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
211                            }
212    
213                            if (orderByComparator != null) {
214                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215                                            orderByComparator);
216                            }
217                            else
218                             if (pagination) {
219                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
220                            }
221    
222                            String sql = query.toString();
223    
224                            Session session = null;
225    
226                            try {
227                                    session = openSession();
228    
229                                    Query q = session.createQuery(sql);
230    
231                                    QueryPos qPos = QueryPos.getInstance(q);
232    
233                                    if (bindUuid) {
234                                            qPos.add(uuid);
235                                    }
236    
237                                    if (!pagination) {
238                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
239                                                            end, false);
240    
241                                            Collections.sort(list);
242    
243                                            list = new UnmodifiableList<Group>(list);
244                                    }
245                                    else {
246                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
247                                                            end);
248                                    }
249    
250                                    cacheResult(list);
251    
252                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
253                            }
254                            catch (Exception e) {
255                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
256    
257                                    throw processException(e);
258                            }
259                            finally {
260                                    closeSession(session);
261                            }
262                    }
263    
264                    return list;
265            }
266    
267            /**
268             * Returns the first group in the ordered set where uuid = &#63;.
269             *
270             * @param uuid the uuid
271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
272             * @return the first matching group
273             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
274             * @throws SystemException if a system exception occurred
275             */
276            public Group findByUuid_First(String uuid,
277                    OrderByComparator orderByComparator)
278                    throws NoSuchGroupException, SystemException {
279                    Group group = fetchByUuid_First(uuid, orderByComparator);
280    
281                    if (group != null) {
282                            return group;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchGroupException(msg.toString());
295            }
296    
297            /**
298             * Returns the first group in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching group, or <code>null</code> if a matching group could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            public Group fetchByUuid_First(String uuid,
306                    OrderByComparator orderByComparator) throws SystemException {
307                    List<Group> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last group in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching group
322             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public Group findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchGroupException, SystemException {
328                    Group group = fetchByUuid_Last(uuid, orderByComparator);
329    
330                    if (group != null) {
331                            return group;
332                    }
333    
334                    StringBundler msg = new StringBundler(4);
335    
336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337    
338                    msg.append("uuid=");
339                    msg.append(uuid);
340    
341                    msg.append(StringPool.CLOSE_CURLY_BRACE);
342    
343                    throw new NoSuchGroupException(msg.toString());
344            }
345    
346            /**
347             * Returns the last group in the ordered set where uuid = &#63;.
348             *
349             * @param uuid the uuid
350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
351             * @return the last matching group, or <code>null</code> if a matching group could not be found
352             * @throws SystemException if a system exception occurred
353             */
354            public Group fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    List<Group> list = findByUuid(uuid, count - 1, count, orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the groups before and after the current group in the ordered set where uuid = &#63;.
369             *
370             * @param groupId the primary key of the current group
371             * @param uuid the uuid
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next group
374             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
375             * @throws SystemException if a system exception occurred
376             */
377            public Group[] findByUuid_PrevAndNext(long groupId, String uuid,
378                    OrderByComparator orderByComparator)
379                    throws NoSuchGroupException, SystemException {
380                    Group group = findByPrimaryKey(groupId);
381    
382                    Session session = null;
383    
384                    try {
385                            session = openSession();
386    
387                            Group[] array = new GroupImpl[3];
388    
389                            array[0] = getByUuid_PrevAndNext(session, group, uuid,
390                                            orderByComparator, true);
391    
392                            array[1] = group;
393    
394                            array[2] = getByUuid_PrevAndNext(session, group, uuid,
395                                            orderByComparator, false);
396    
397                            return array;
398                    }
399                    catch (Exception e) {
400                            throw processException(e);
401                    }
402                    finally {
403                            closeSession(session);
404                    }
405            }
406    
407            protected Group getByUuid_PrevAndNext(Session session, Group group,
408                    String uuid, OrderByComparator orderByComparator, boolean previous) {
409                    StringBundler query = null;
410    
411                    if (orderByComparator != null) {
412                            query = new StringBundler(6 +
413                                            (orderByComparator.getOrderByFields().length * 6));
414                    }
415                    else {
416                            query = new StringBundler(3);
417                    }
418    
419                    query.append(_SQL_SELECT_GROUP__WHERE);
420    
421                    boolean bindUuid = false;
422    
423                    if (uuid == null) {
424                            query.append(_FINDER_COLUMN_UUID_UUID_1);
425                    }
426                    else if (uuid.equals(StringPool.BLANK)) {
427                            query.append(_FINDER_COLUMN_UUID_UUID_3);
428                    }
429                    else {
430                            bindUuid = true;
431    
432                            query.append(_FINDER_COLUMN_UUID_UUID_2);
433                    }
434    
435                    if (orderByComparator != null) {
436                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
437    
438                            if (orderByConditionFields.length > 0) {
439                                    query.append(WHERE_AND);
440                            }
441    
442                            for (int i = 0; i < orderByConditionFields.length; i++) {
443                                    query.append(_ORDER_BY_ENTITY_ALIAS);
444                                    query.append(orderByConditionFields[i]);
445    
446                                    if ((i + 1) < orderByConditionFields.length) {
447                                            if (orderByComparator.isAscending() ^ previous) {
448                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
449                                            }
450                                            else {
451                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
452                                            }
453                                    }
454                                    else {
455                                            if (orderByComparator.isAscending() ^ previous) {
456                                                    query.append(WHERE_GREATER_THAN);
457                                            }
458                                            else {
459                                                    query.append(WHERE_LESSER_THAN);
460                                            }
461                                    }
462                            }
463    
464                            query.append(ORDER_BY_CLAUSE);
465    
466                            String[] orderByFields = orderByComparator.getOrderByFields();
467    
468                            for (int i = 0; i < orderByFields.length; i++) {
469                                    query.append(_ORDER_BY_ENTITY_ALIAS);
470                                    query.append(orderByFields[i]);
471    
472                                    if ((i + 1) < orderByFields.length) {
473                                            if (orderByComparator.isAscending() ^ previous) {
474                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
475                                            }
476                                            else {
477                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
478                                            }
479                                    }
480                                    else {
481                                            if (orderByComparator.isAscending() ^ previous) {
482                                                    query.append(ORDER_BY_ASC);
483                                            }
484                                            else {
485                                                    query.append(ORDER_BY_DESC);
486                                            }
487                                    }
488                            }
489                    }
490                    else {
491                            query.append(GroupModelImpl.ORDER_BY_JPQL);
492                    }
493    
494                    String sql = query.toString();
495    
496                    Query q = session.createQuery(sql);
497    
498                    q.setFirstResult(0);
499                    q.setMaxResults(2);
500    
501                    QueryPos qPos = QueryPos.getInstance(q);
502    
503                    if (bindUuid) {
504                            qPos.add(uuid);
505                    }
506    
507                    if (orderByComparator != null) {
508                            Object[] values = orderByComparator.getOrderByConditionValues(group);
509    
510                            for (Object value : values) {
511                                    qPos.add(value);
512                            }
513                    }
514    
515                    List<Group> list = q.list();
516    
517                    if (list.size() == 2) {
518                            return list.get(1);
519                    }
520                    else {
521                            return null;
522                    }
523            }
524    
525            /**
526             * Removes all the groups where uuid = &#63; from the database.
527             *
528             * @param uuid the uuid
529             * @throws SystemException if a system exception occurred
530             */
531            public void removeByUuid(String uuid) throws SystemException {
532                    for (Group group : findByUuid(uuid, QueryUtil.ALL_POS,
533                                    QueryUtil.ALL_POS, null)) {
534                            remove(group);
535                    }
536            }
537    
538            /**
539             * Returns the number of groups where uuid = &#63;.
540             *
541             * @param uuid the uuid
542             * @return the number of matching groups
543             * @throws SystemException if a system exception occurred
544             */
545            public int countByUuid(String uuid) throws SystemException {
546                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
547    
548                    Object[] finderArgs = new Object[] { uuid };
549    
550                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
551                                    this);
552    
553                    if (count == null) {
554                            StringBundler query = new StringBundler(2);
555    
556                            query.append(_SQL_COUNT_GROUP__WHERE);
557    
558                            boolean bindUuid = false;
559    
560                            if (uuid == null) {
561                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
562                            }
563                            else if (uuid.equals(StringPool.BLANK)) {
564                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
565                            }
566                            else {
567                                    bindUuid = true;
568    
569                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
570                            }
571    
572                            String sql = query.toString();
573    
574                            Session session = null;
575    
576                            try {
577                                    session = openSession();
578    
579                                    Query q = session.createQuery(sql);
580    
581                                    QueryPos qPos = QueryPos.getInstance(q);
582    
583                                    if (bindUuid) {
584                                            qPos.add(uuid);
585                                    }
586    
587                                    count = (Long)q.uniqueResult();
588    
589                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
590                            }
591                            catch (Exception e) {
592                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
593    
594                                    throw processException(e);
595                            }
596                            finally {
597                                    closeSession(session);
598                            }
599                    }
600    
601                    return count.intValue();
602            }
603    
604            private static final String _FINDER_COLUMN_UUID_UUID_1 = "group_.uuid IS NULL";
605            private static final String _FINDER_COLUMN_UUID_UUID_2 = "group_.uuid = ?";
606            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(group_.uuid IS NULL OR group_.uuid = '')";
607            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
608                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
609                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
610                            new String[] { String.class.getName(), Long.class.getName() },
611                            GroupModelImpl.UUID_COLUMN_BITMASK |
612                            GroupModelImpl.GROUPID_COLUMN_BITMASK);
613            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
614                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
615                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
616                            new String[] { String.class.getName(), Long.class.getName() });
617    
618            /**
619             * Returns the group where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
620             *
621             * @param uuid the uuid
622             * @param groupId the group ID
623             * @return the matching group
624             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
625             * @throws SystemException if a system exception occurred
626             */
627            public Group findByUUID_G(String uuid, long groupId)
628                    throws NoSuchGroupException, SystemException {
629                    Group group = fetchByUUID_G(uuid, groupId);
630    
631                    if (group == null) {
632                            StringBundler msg = new StringBundler(6);
633    
634                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
635    
636                            msg.append("uuid=");
637                            msg.append(uuid);
638    
639                            msg.append(", groupId=");
640                            msg.append(groupId);
641    
642                            msg.append(StringPool.CLOSE_CURLY_BRACE);
643    
644                            if (_log.isWarnEnabled()) {
645                                    _log.warn(msg.toString());
646                            }
647    
648                            throw new NoSuchGroupException(msg.toString());
649                    }
650    
651                    return group;
652            }
653    
654            /**
655             * Returns the group where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
656             *
657             * @param uuid the uuid
658             * @param groupId the group ID
659             * @return the matching group, or <code>null</code> if a matching group could not be found
660             * @throws SystemException if a system exception occurred
661             */
662            public Group fetchByUUID_G(String uuid, long groupId)
663                    throws SystemException {
664                    return fetchByUUID_G(uuid, groupId, true);
665            }
666    
667            /**
668             * Returns the group where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
669             *
670             * @param uuid the uuid
671             * @param groupId the group ID
672             * @param retrieveFromCache whether to use the finder cache
673             * @return the matching group, or <code>null</code> if a matching group could not be found
674             * @throws SystemException if a system exception occurred
675             */
676            public Group fetchByUUID_G(String uuid, long groupId,
677                    boolean retrieveFromCache) throws SystemException {
678                    Object[] finderArgs = new Object[] { uuid, groupId };
679    
680                    Object result = null;
681    
682                    if (retrieveFromCache) {
683                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
684                                            finderArgs, this);
685                    }
686    
687                    if (result instanceof Group) {
688                            Group group = (Group)result;
689    
690                            if (!Validator.equals(uuid, group.getUuid()) ||
691                                            (groupId != group.getGroupId())) {
692                                    result = null;
693                            }
694                    }
695    
696                    if (result == null) {
697                            StringBundler query = new StringBundler(4);
698    
699                            query.append(_SQL_SELECT_GROUP__WHERE);
700    
701                            boolean bindUuid = false;
702    
703                            if (uuid == null) {
704                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
705                            }
706                            else if (uuid.equals(StringPool.BLANK)) {
707                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
708                            }
709                            else {
710                                    bindUuid = true;
711    
712                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
713                            }
714    
715                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
716    
717                            String sql = query.toString();
718    
719                            Session session = null;
720    
721                            try {
722                                    session = openSession();
723    
724                                    Query q = session.createQuery(sql);
725    
726                                    QueryPos qPos = QueryPos.getInstance(q);
727    
728                                    if (bindUuid) {
729                                            qPos.add(uuid);
730                                    }
731    
732                                    qPos.add(groupId);
733    
734                                    List<Group> list = q.list();
735    
736                                    if (list.isEmpty()) {
737                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
738                                                    finderArgs, list);
739                                    }
740                                    else {
741                                            Group group = list.get(0);
742    
743                                            result = group;
744    
745                                            cacheResult(group);
746    
747                                            if ((group.getUuid() == null) ||
748                                                            !group.getUuid().equals(uuid) ||
749                                                            (group.getGroupId() != groupId)) {
750                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
751                                                            finderArgs, group);
752                                            }
753                                    }
754                            }
755                            catch (Exception e) {
756                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
757                                            finderArgs);
758    
759                                    throw processException(e);
760                            }
761                            finally {
762                                    closeSession(session);
763                            }
764                    }
765    
766                    if (result instanceof List<?>) {
767                            return null;
768                    }
769                    else {
770                            return (Group)result;
771                    }
772            }
773    
774            /**
775             * Removes the group where uuid = &#63; and groupId = &#63; from the database.
776             *
777             * @param uuid the uuid
778             * @param groupId the group ID
779             * @return the group that was removed
780             * @throws SystemException if a system exception occurred
781             */
782            public Group removeByUUID_G(String uuid, long groupId)
783                    throws NoSuchGroupException, SystemException {
784                    Group group = findByUUID_G(uuid, groupId);
785    
786                    return remove(group);
787            }
788    
789            /**
790             * Returns the number of groups where uuid = &#63; and groupId = &#63;.
791             *
792             * @param uuid the uuid
793             * @param groupId the group ID
794             * @return the number of matching groups
795             * @throws SystemException if a system exception occurred
796             */
797            public int countByUUID_G(String uuid, long groupId)
798                    throws SystemException {
799                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
800    
801                    Object[] finderArgs = new Object[] { uuid, groupId };
802    
803                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
804                                    this);
805    
806                    if (count == null) {
807                            StringBundler query = new StringBundler(3);
808    
809                            query.append(_SQL_COUNT_GROUP__WHERE);
810    
811                            boolean bindUuid = false;
812    
813                            if (uuid == null) {
814                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
815                            }
816                            else if (uuid.equals(StringPool.BLANK)) {
817                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
818                            }
819                            else {
820                                    bindUuid = true;
821    
822                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
823                            }
824    
825                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
826    
827                            String sql = query.toString();
828    
829                            Session session = null;
830    
831                            try {
832                                    session = openSession();
833    
834                                    Query q = session.createQuery(sql);
835    
836                                    QueryPos qPos = QueryPos.getInstance(q);
837    
838                                    if (bindUuid) {
839                                            qPos.add(uuid);
840                                    }
841    
842                                    qPos.add(groupId);
843    
844                                    count = (Long)q.uniqueResult();
845    
846                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
847                            }
848                            catch (Exception e) {
849                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
850    
851                                    throw processException(e);
852                            }
853                            finally {
854                                    closeSession(session);
855                            }
856                    }
857    
858                    return count.intValue();
859            }
860    
861            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "group_.uuid IS NULL AND ";
862            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "group_.uuid = ? AND ";
863            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(group_.uuid IS NULL OR group_.uuid = '') AND ";
864            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "group_.groupId = ?";
865            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
866                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
867                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
868                            new String[] {
869                                    String.class.getName(), Long.class.getName(),
870                                    
871                            Integer.class.getName(), Integer.class.getName(),
872                                    OrderByComparator.class.getName()
873                            });
874            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
875                    new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
876                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
877                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
878                            new String[] { String.class.getName(), Long.class.getName() },
879                            GroupModelImpl.UUID_COLUMN_BITMASK |
880                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
881                            GroupModelImpl.NAME_COLUMN_BITMASK);
882            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
883                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
884                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
885                            new String[] { String.class.getName(), Long.class.getName() });
886    
887            /**
888             * Returns all the groups where uuid = &#63; and companyId = &#63;.
889             *
890             * @param uuid the uuid
891             * @param companyId the company ID
892             * @return the matching groups
893             * @throws SystemException if a system exception occurred
894             */
895            public List<Group> findByUuid_C(String uuid, long companyId)
896                    throws SystemException {
897                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
898                            QueryUtil.ALL_POS, null);
899            }
900    
901            /**
902             * Returns a range of all the groups where uuid = &#63; and companyId = &#63;.
903             *
904             * <p>
905             * 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.GroupModelImpl}. 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.
906             * </p>
907             *
908             * @param uuid the uuid
909             * @param companyId the company ID
910             * @param start the lower bound of the range of groups
911             * @param end the upper bound of the range of groups (not inclusive)
912             * @return the range of matching groups
913             * @throws SystemException if a system exception occurred
914             */
915            public List<Group> findByUuid_C(String uuid, long companyId, int start,
916                    int end) throws SystemException {
917                    return findByUuid_C(uuid, companyId, start, end, null);
918            }
919    
920            /**
921             * Returns an ordered range of all the groups where uuid = &#63; and companyId = &#63;.
922             *
923             * <p>
924             * 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.GroupModelImpl}. 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.
925             * </p>
926             *
927             * @param uuid the uuid
928             * @param companyId the company ID
929             * @param start the lower bound of the range of groups
930             * @param end the upper bound of the range of groups (not inclusive)
931             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
932             * @return the ordered range of matching groups
933             * @throws SystemException if a system exception occurred
934             */
935            public List<Group> findByUuid_C(String uuid, long companyId, int start,
936                    int end, OrderByComparator orderByComparator) throws SystemException {
937                    boolean pagination = true;
938                    FinderPath finderPath = null;
939                    Object[] finderArgs = null;
940    
941                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
942                                    (orderByComparator == null)) {
943                            pagination = false;
944                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
945                            finderArgs = new Object[] { uuid, companyId };
946                    }
947                    else {
948                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
949                            finderArgs = new Object[] {
950                                            uuid, companyId,
951                                            
952                                            start, end, orderByComparator
953                                    };
954                    }
955    
956                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
957                                    finderArgs, this);
958    
959                    if ((list != null) && !list.isEmpty()) {
960                            for (Group group : list) {
961                                    if (!Validator.equals(uuid, group.getUuid()) ||
962                                                    (companyId != group.getCompanyId())) {
963                                            list = null;
964    
965                                            break;
966                                    }
967                            }
968                    }
969    
970                    if (list == null) {
971                            StringBundler query = null;
972    
973                            if (orderByComparator != null) {
974                                    query = new StringBundler(4 +
975                                                    (orderByComparator.getOrderByFields().length * 3));
976                            }
977                            else {
978                                    query = new StringBundler(4);
979                            }
980    
981                            query.append(_SQL_SELECT_GROUP__WHERE);
982    
983                            boolean bindUuid = false;
984    
985                            if (uuid == null) {
986                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
987                            }
988                            else if (uuid.equals(StringPool.BLANK)) {
989                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
990                            }
991                            else {
992                                    bindUuid = true;
993    
994                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
995                            }
996    
997                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
998    
999                            if (orderByComparator != null) {
1000                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1001                                            orderByComparator);
1002                            }
1003                            else
1004                             if (pagination) {
1005                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
1006                            }
1007    
1008                            String sql = query.toString();
1009    
1010                            Session session = null;
1011    
1012                            try {
1013                                    session = openSession();
1014    
1015                                    Query q = session.createQuery(sql);
1016    
1017                                    QueryPos qPos = QueryPos.getInstance(q);
1018    
1019                                    if (bindUuid) {
1020                                            qPos.add(uuid);
1021                                    }
1022    
1023                                    qPos.add(companyId);
1024    
1025                                    if (!pagination) {
1026                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
1027                                                            end, false);
1028    
1029                                            Collections.sort(list);
1030    
1031                                            list = new UnmodifiableList<Group>(list);
1032                                    }
1033                                    else {
1034                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
1035                                                            end);
1036                                    }
1037    
1038                                    cacheResult(list);
1039    
1040                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1041                            }
1042                            catch (Exception e) {
1043                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1044    
1045                                    throw processException(e);
1046                            }
1047                            finally {
1048                                    closeSession(session);
1049                            }
1050                    }
1051    
1052                    return list;
1053            }
1054    
1055            /**
1056             * Returns the first group in the ordered set where uuid = &#63; and companyId = &#63;.
1057             *
1058             * @param uuid the uuid
1059             * @param companyId the company ID
1060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1061             * @return the first matching group
1062             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
1063             * @throws SystemException if a system exception occurred
1064             */
1065            public Group findByUuid_C_First(String uuid, long companyId,
1066                    OrderByComparator orderByComparator)
1067                    throws NoSuchGroupException, SystemException {
1068                    Group group = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1069    
1070                    if (group != null) {
1071                            return group;
1072                    }
1073    
1074                    StringBundler msg = new StringBundler(6);
1075    
1076                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1077    
1078                    msg.append("uuid=");
1079                    msg.append(uuid);
1080    
1081                    msg.append(", companyId=");
1082                    msg.append(companyId);
1083    
1084                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1085    
1086                    throw new NoSuchGroupException(msg.toString());
1087            }
1088    
1089            /**
1090             * Returns the first group in the ordered set where uuid = &#63; and companyId = &#63;.
1091             *
1092             * @param uuid the uuid
1093             * @param companyId the company ID
1094             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1095             * @return the first matching group, or <code>null</code> if a matching group could not be found
1096             * @throws SystemException if a system exception occurred
1097             */
1098            public Group fetchByUuid_C_First(String uuid, long companyId,
1099                    OrderByComparator orderByComparator) throws SystemException {
1100                    List<Group> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1101    
1102                    if (!list.isEmpty()) {
1103                            return list.get(0);
1104                    }
1105    
1106                    return null;
1107            }
1108    
1109            /**
1110             * Returns the last group in the ordered set where uuid = &#63; and companyId = &#63;.
1111             *
1112             * @param uuid the uuid
1113             * @param companyId the company ID
1114             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1115             * @return the last matching group
1116             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
1117             * @throws SystemException if a system exception occurred
1118             */
1119            public Group findByUuid_C_Last(String uuid, long companyId,
1120                    OrderByComparator orderByComparator)
1121                    throws NoSuchGroupException, SystemException {
1122                    Group group = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1123    
1124                    if (group != null) {
1125                            return group;
1126                    }
1127    
1128                    StringBundler msg = new StringBundler(6);
1129    
1130                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1131    
1132                    msg.append("uuid=");
1133                    msg.append(uuid);
1134    
1135                    msg.append(", companyId=");
1136                    msg.append(companyId);
1137    
1138                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1139    
1140                    throw new NoSuchGroupException(msg.toString());
1141            }
1142    
1143            /**
1144             * Returns the last group in the ordered set where uuid = &#63; and companyId = &#63;.
1145             *
1146             * @param uuid the uuid
1147             * @param companyId the company ID
1148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1149             * @return the last matching group, or <code>null</code> if a matching group could not be found
1150             * @throws SystemException if a system exception occurred
1151             */
1152            public Group fetchByUuid_C_Last(String uuid, long companyId,
1153                    OrderByComparator orderByComparator) throws SystemException {
1154                    int count = countByUuid_C(uuid, companyId);
1155    
1156                    List<Group> list = findByUuid_C(uuid, companyId, count - 1, count,
1157                                    orderByComparator);
1158    
1159                    if (!list.isEmpty()) {
1160                            return list.get(0);
1161                    }
1162    
1163                    return null;
1164            }
1165    
1166            /**
1167             * Returns the groups before and after the current group in the ordered set where uuid = &#63; and companyId = &#63;.
1168             *
1169             * @param groupId the primary key of the current group
1170             * @param uuid the uuid
1171             * @param companyId the company ID
1172             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1173             * @return the previous, current, and next group
1174             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
1175             * @throws SystemException if a system exception occurred
1176             */
1177            public Group[] findByUuid_C_PrevAndNext(long groupId, String uuid,
1178                    long companyId, OrderByComparator orderByComparator)
1179                    throws NoSuchGroupException, SystemException {
1180                    Group group = findByPrimaryKey(groupId);
1181    
1182                    Session session = null;
1183    
1184                    try {
1185                            session = openSession();
1186    
1187                            Group[] array = new GroupImpl[3];
1188    
1189                            array[0] = getByUuid_C_PrevAndNext(session, group, uuid, companyId,
1190                                            orderByComparator, true);
1191    
1192                            array[1] = group;
1193    
1194                            array[2] = getByUuid_C_PrevAndNext(session, group, uuid, companyId,
1195                                            orderByComparator, false);
1196    
1197                            return array;
1198                    }
1199                    catch (Exception e) {
1200                            throw processException(e);
1201                    }
1202                    finally {
1203                            closeSession(session);
1204                    }
1205            }
1206    
1207            protected Group getByUuid_C_PrevAndNext(Session session, Group group,
1208                    String uuid, long companyId, OrderByComparator orderByComparator,
1209                    boolean previous) {
1210                    StringBundler query = null;
1211    
1212                    if (orderByComparator != null) {
1213                            query = new StringBundler(6 +
1214                                            (orderByComparator.getOrderByFields().length * 6));
1215                    }
1216                    else {
1217                            query = new StringBundler(3);
1218                    }
1219    
1220                    query.append(_SQL_SELECT_GROUP__WHERE);
1221    
1222                    boolean bindUuid = false;
1223    
1224                    if (uuid == null) {
1225                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1226                    }
1227                    else if (uuid.equals(StringPool.BLANK)) {
1228                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1229                    }
1230                    else {
1231                            bindUuid = true;
1232    
1233                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1234                    }
1235    
1236                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1237    
1238                    if (orderByComparator != null) {
1239                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1240    
1241                            if (orderByConditionFields.length > 0) {
1242                                    query.append(WHERE_AND);
1243                            }
1244    
1245                            for (int i = 0; i < orderByConditionFields.length; i++) {
1246                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1247                                    query.append(orderByConditionFields[i]);
1248    
1249                                    if ((i + 1) < orderByConditionFields.length) {
1250                                            if (orderByComparator.isAscending() ^ previous) {
1251                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1252                                            }
1253                                            else {
1254                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1255                                            }
1256                                    }
1257                                    else {
1258                                            if (orderByComparator.isAscending() ^ previous) {
1259                                                    query.append(WHERE_GREATER_THAN);
1260                                            }
1261                                            else {
1262                                                    query.append(WHERE_LESSER_THAN);
1263                                            }
1264                                    }
1265                            }
1266    
1267                            query.append(ORDER_BY_CLAUSE);
1268    
1269                            String[] orderByFields = orderByComparator.getOrderByFields();
1270    
1271                            for (int i = 0; i < orderByFields.length; i++) {
1272                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1273                                    query.append(orderByFields[i]);
1274    
1275                                    if ((i + 1) < orderByFields.length) {
1276                                            if (orderByComparator.isAscending() ^ previous) {
1277                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1278                                            }
1279                                            else {
1280                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1281                                            }
1282                                    }
1283                                    else {
1284                                            if (orderByComparator.isAscending() ^ previous) {
1285                                                    query.append(ORDER_BY_ASC);
1286                                            }
1287                                            else {
1288                                                    query.append(ORDER_BY_DESC);
1289                                            }
1290                                    }
1291                            }
1292                    }
1293                    else {
1294                            query.append(GroupModelImpl.ORDER_BY_JPQL);
1295                    }
1296    
1297                    String sql = query.toString();
1298    
1299                    Query q = session.createQuery(sql);
1300    
1301                    q.setFirstResult(0);
1302                    q.setMaxResults(2);
1303    
1304                    QueryPos qPos = QueryPos.getInstance(q);
1305    
1306                    if (bindUuid) {
1307                            qPos.add(uuid);
1308                    }
1309    
1310                    qPos.add(companyId);
1311    
1312                    if (orderByComparator != null) {
1313                            Object[] values = orderByComparator.getOrderByConditionValues(group);
1314    
1315                            for (Object value : values) {
1316                                    qPos.add(value);
1317                            }
1318                    }
1319    
1320                    List<Group> list = q.list();
1321    
1322                    if (list.size() == 2) {
1323                            return list.get(1);
1324                    }
1325                    else {
1326                            return null;
1327                    }
1328            }
1329    
1330            /**
1331             * Removes all the groups where uuid = &#63; and companyId = &#63; from the database.
1332             *
1333             * @param uuid the uuid
1334             * @param companyId the company ID
1335             * @throws SystemException if a system exception occurred
1336             */
1337            public void removeByUuid_C(String uuid, long companyId)
1338                    throws SystemException {
1339                    for (Group group : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1340                                    QueryUtil.ALL_POS, null)) {
1341                            remove(group);
1342                    }
1343            }
1344    
1345            /**
1346             * Returns the number of groups where uuid = &#63; and companyId = &#63;.
1347             *
1348             * @param uuid the uuid
1349             * @param companyId the company ID
1350             * @return the number of matching groups
1351             * @throws SystemException if a system exception occurred
1352             */
1353            public int countByUuid_C(String uuid, long companyId)
1354                    throws SystemException {
1355                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1356    
1357                    Object[] finderArgs = new Object[] { uuid, companyId };
1358    
1359                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1360                                    this);
1361    
1362                    if (count == null) {
1363                            StringBundler query = new StringBundler(3);
1364    
1365                            query.append(_SQL_COUNT_GROUP__WHERE);
1366    
1367                            boolean bindUuid = false;
1368    
1369                            if (uuid == null) {
1370                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1371                            }
1372                            else if (uuid.equals(StringPool.BLANK)) {
1373                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1374                            }
1375                            else {
1376                                    bindUuid = true;
1377    
1378                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1379                            }
1380    
1381                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1382    
1383                            String sql = query.toString();
1384    
1385                            Session session = null;
1386    
1387                            try {
1388                                    session = openSession();
1389    
1390                                    Query q = session.createQuery(sql);
1391    
1392                                    QueryPos qPos = QueryPos.getInstance(q);
1393    
1394                                    if (bindUuid) {
1395                                            qPos.add(uuid);
1396                                    }
1397    
1398                                    qPos.add(companyId);
1399    
1400                                    count = (Long)q.uniqueResult();
1401    
1402                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1403                            }
1404                            catch (Exception e) {
1405                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1406    
1407                                    throw processException(e);
1408                            }
1409                            finally {
1410                                    closeSession(session);
1411                            }
1412                    }
1413    
1414                    return count.intValue();
1415            }
1416    
1417            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "group_.uuid IS NULL AND ";
1418            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "group_.uuid = ? AND ";
1419            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(group_.uuid IS NULL OR group_.uuid = '') AND ";
1420            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "group_.companyId = ?";
1421            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1422                    new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
1423                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
1424                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1425                            new String[] {
1426                                    Long.class.getName(),
1427                                    
1428                            Integer.class.getName(), Integer.class.getName(),
1429                                    OrderByComparator.class.getName()
1430                            });
1431            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1432                    new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
1433                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
1434                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1435                            new String[] { Long.class.getName() },
1436                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
1437                            GroupModelImpl.NAME_COLUMN_BITMASK);
1438            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
1439                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
1440                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1441                            new String[] { Long.class.getName() });
1442    
1443            /**
1444             * Returns all the groups where companyId = &#63;.
1445             *
1446             * @param companyId the company ID
1447             * @return the matching groups
1448             * @throws SystemException if a system exception occurred
1449             */
1450            public List<Group> findByCompanyId(long companyId)
1451                    throws SystemException {
1452                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1453                            null);
1454            }
1455    
1456            /**
1457             * Returns a range of all the groups where companyId = &#63;.
1458             *
1459             * <p>
1460             * 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.GroupModelImpl}. 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.
1461             * </p>
1462             *
1463             * @param companyId the company ID
1464             * @param start the lower bound of the range of groups
1465             * @param end the upper bound of the range of groups (not inclusive)
1466             * @return the range of matching groups
1467             * @throws SystemException if a system exception occurred
1468             */
1469            public List<Group> findByCompanyId(long companyId, int start, int end)
1470                    throws SystemException {
1471                    return findByCompanyId(companyId, start, end, null);
1472            }
1473    
1474            /**
1475             * Returns an ordered range of all the groups where companyId = &#63;.
1476             *
1477             * <p>
1478             * 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.GroupModelImpl}. 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.
1479             * </p>
1480             *
1481             * @param companyId the company ID
1482             * @param start the lower bound of the range of groups
1483             * @param end the upper bound of the range of groups (not inclusive)
1484             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1485             * @return the ordered range of matching groups
1486             * @throws SystemException if a system exception occurred
1487             */
1488            public List<Group> findByCompanyId(long companyId, int start, int end,
1489                    OrderByComparator orderByComparator) throws SystemException {
1490                    boolean pagination = true;
1491                    FinderPath finderPath = null;
1492                    Object[] finderArgs = null;
1493    
1494                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1495                                    (orderByComparator == null)) {
1496                            pagination = false;
1497                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1498                            finderArgs = new Object[] { companyId };
1499                    }
1500                    else {
1501                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1502                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
1503                    }
1504    
1505                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
1506                                    finderArgs, this);
1507    
1508                    if ((list != null) && !list.isEmpty()) {
1509                            for (Group group : list) {
1510                                    if ((companyId != group.getCompanyId())) {
1511                                            list = null;
1512    
1513                                            break;
1514                                    }
1515                            }
1516                    }
1517    
1518                    if (list == null) {
1519                            StringBundler query = null;
1520    
1521                            if (orderByComparator != null) {
1522                                    query = new StringBundler(3 +
1523                                                    (orderByComparator.getOrderByFields().length * 3));
1524                            }
1525                            else {
1526                                    query = new StringBundler(3);
1527                            }
1528    
1529                            query.append(_SQL_SELECT_GROUP__WHERE);
1530    
1531                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1532    
1533                            if (orderByComparator != null) {
1534                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1535                                            orderByComparator);
1536                            }
1537                            else
1538                             if (pagination) {
1539                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
1540                            }
1541    
1542                            String sql = query.toString();
1543    
1544                            Session session = null;
1545    
1546                            try {
1547                                    session = openSession();
1548    
1549                                    Query q = session.createQuery(sql);
1550    
1551                                    QueryPos qPos = QueryPos.getInstance(q);
1552    
1553                                    qPos.add(companyId);
1554    
1555                                    if (!pagination) {
1556                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
1557                                                            end, false);
1558    
1559                                            Collections.sort(list);
1560    
1561                                            list = new UnmodifiableList<Group>(list);
1562                                    }
1563                                    else {
1564                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
1565                                                            end);
1566                                    }
1567    
1568                                    cacheResult(list);
1569    
1570                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1571                            }
1572                            catch (Exception e) {
1573                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1574    
1575                                    throw processException(e);
1576                            }
1577                            finally {
1578                                    closeSession(session);
1579                            }
1580                    }
1581    
1582                    return list;
1583            }
1584    
1585            /**
1586             * Returns the first group in the ordered set where companyId = &#63;.
1587             *
1588             * @param companyId the company ID
1589             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1590             * @return the first matching group
1591             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
1592             * @throws SystemException if a system exception occurred
1593             */
1594            public Group findByCompanyId_First(long companyId,
1595                    OrderByComparator orderByComparator)
1596                    throws NoSuchGroupException, SystemException {
1597                    Group group = fetchByCompanyId_First(companyId, orderByComparator);
1598    
1599                    if (group != null) {
1600                            return group;
1601                    }
1602    
1603                    StringBundler msg = new StringBundler(4);
1604    
1605                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1606    
1607                    msg.append("companyId=");
1608                    msg.append(companyId);
1609    
1610                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1611    
1612                    throw new NoSuchGroupException(msg.toString());
1613            }
1614    
1615            /**
1616             * Returns the first group in the ordered set where companyId = &#63;.
1617             *
1618             * @param companyId the company ID
1619             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1620             * @return the first matching group, or <code>null</code> if a matching group could not be found
1621             * @throws SystemException if a system exception occurred
1622             */
1623            public Group fetchByCompanyId_First(long companyId,
1624                    OrderByComparator orderByComparator) throws SystemException {
1625                    List<Group> list = findByCompanyId(companyId, 0, 1, orderByComparator);
1626    
1627                    if (!list.isEmpty()) {
1628                            return list.get(0);
1629                    }
1630    
1631                    return null;
1632            }
1633    
1634            /**
1635             * Returns the last group in the ordered set where companyId = &#63;.
1636             *
1637             * @param companyId the company ID
1638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1639             * @return the last matching group
1640             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
1641             * @throws SystemException if a system exception occurred
1642             */
1643            public Group findByCompanyId_Last(long companyId,
1644                    OrderByComparator orderByComparator)
1645                    throws NoSuchGroupException, SystemException {
1646                    Group group = fetchByCompanyId_Last(companyId, orderByComparator);
1647    
1648                    if (group != null) {
1649                            return group;
1650                    }
1651    
1652                    StringBundler msg = new StringBundler(4);
1653    
1654                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1655    
1656                    msg.append("companyId=");
1657                    msg.append(companyId);
1658    
1659                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1660    
1661                    throw new NoSuchGroupException(msg.toString());
1662            }
1663    
1664            /**
1665             * Returns the last group in the ordered set where companyId = &#63;.
1666             *
1667             * @param companyId the company ID
1668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1669             * @return the last matching group, or <code>null</code> if a matching group could not be found
1670             * @throws SystemException if a system exception occurred
1671             */
1672            public Group fetchByCompanyId_Last(long companyId,
1673                    OrderByComparator orderByComparator) throws SystemException {
1674                    int count = countByCompanyId(companyId);
1675    
1676                    List<Group> list = findByCompanyId(companyId, count - 1, count,
1677                                    orderByComparator);
1678    
1679                    if (!list.isEmpty()) {
1680                            return list.get(0);
1681                    }
1682    
1683                    return null;
1684            }
1685    
1686            /**
1687             * Returns the groups before and after the current group in the ordered set where companyId = &#63;.
1688             *
1689             * @param groupId the primary key of the current group
1690             * @param companyId the company ID
1691             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1692             * @return the previous, current, and next group
1693             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
1694             * @throws SystemException if a system exception occurred
1695             */
1696            public Group[] findByCompanyId_PrevAndNext(long groupId, long companyId,
1697                    OrderByComparator orderByComparator)
1698                    throws NoSuchGroupException, SystemException {
1699                    Group group = findByPrimaryKey(groupId);
1700    
1701                    Session session = null;
1702    
1703                    try {
1704                            session = openSession();
1705    
1706                            Group[] array = new GroupImpl[3];
1707    
1708                            array[0] = getByCompanyId_PrevAndNext(session, group, companyId,
1709                                            orderByComparator, true);
1710    
1711                            array[1] = group;
1712    
1713                            array[2] = getByCompanyId_PrevAndNext(session, group, companyId,
1714                                            orderByComparator, false);
1715    
1716                            return array;
1717                    }
1718                    catch (Exception e) {
1719                            throw processException(e);
1720                    }
1721                    finally {
1722                            closeSession(session);
1723                    }
1724            }
1725    
1726            protected Group getByCompanyId_PrevAndNext(Session session, Group group,
1727                    long companyId, OrderByComparator orderByComparator, boolean previous) {
1728                    StringBundler query = null;
1729    
1730                    if (orderByComparator != null) {
1731                            query = new StringBundler(6 +
1732                                            (orderByComparator.getOrderByFields().length * 6));
1733                    }
1734                    else {
1735                            query = new StringBundler(3);
1736                    }
1737    
1738                    query.append(_SQL_SELECT_GROUP__WHERE);
1739    
1740                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1741    
1742                    if (orderByComparator != null) {
1743                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1744    
1745                            if (orderByConditionFields.length > 0) {
1746                                    query.append(WHERE_AND);
1747                            }
1748    
1749                            for (int i = 0; i < orderByConditionFields.length; i++) {
1750                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1751                                    query.append(orderByConditionFields[i]);
1752    
1753                                    if ((i + 1) < orderByConditionFields.length) {
1754                                            if (orderByComparator.isAscending() ^ previous) {
1755                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1756                                            }
1757                                            else {
1758                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1759                                            }
1760                                    }
1761                                    else {
1762                                            if (orderByComparator.isAscending() ^ previous) {
1763                                                    query.append(WHERE_GREATER_THAN);
1764                                            }
1765                                            else {
1766                                                    query.append(WHERE_LESSER_THAN);
1767                                            }
1768                                    }
1769                            }
1770    
1771                            query.append(ORDER_BY_CLAUSE);
1772    
1773                            String[] orderByFields = orderByComparator.getOrderByFields();
1774    
1775                            for (int i = 0; i < orderByFields.length; i++) {
1776                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1777                                    query.append(orderByFields[i]);
1778    
1779                                    if ((i + 1) < orderByFields.length) {
1780                                            if (orderByComparator.isAscending() ^ previous) {
1781                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1782                                            }
1783                                            else {
1784                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1785                                            }
1786                                    }
1787                                    else {
1788                                            if (orderByComparator.isAscending() ^ previous) {
1789                                                    query.append(ORDER_BY_ASC);
1790                                            }
1791                                            else {
1792                                                    query.append(ORDER_BY_DESC);
1793                                            }
1794                                    }
1795                            }
1796                    }
1797                    else {
1798                            query.append(GroupModelImpl.ORDER_BY_JPQL);
1799                    }
1800    
1801                    String sql = query.toString();
1802    
1803                    Query q = session.createQuery(sql);
1804    
1805                    q.setFirstResult(0);
1806                    q.setMaxResults(2);
1807    
1808                    QueryPos qPos = QueryPos.getInstance(q);
1809    
1810                    qPos.add(companyId);
1811    
1812                    if (orderByComparator != null) {
1813                            Object[] values = orderByComparator.getOrderByConditionValues(group);
1814    
1815                            for (Object value : values) {
1816                                    qPos.add(value);
1817                            }
1818                    }
1819    
1820                    List<Group> list = q.list();
1821    
1822                    if (list.size() == 2) {
1823                            return list.get(1);
1824                    }
1825                    else {
1826                            return null;
1827                    }
1828            }
1829    
1830            /**
1831             * Removes all the groups where companyId = &#63; from the database.
1832             *
1833             * @param companyId the company ID
1834             * @throws SystemException if a system exception occurred
1835             */
1836            public void removeByCompanyId(long companyId) throws SystemException {
1837                    for (Group group : findByCompanyId(companyId, QueryUtil.ALL_POS,
1838                                    QueryUtil.ALL_POS, null)) {
1839                            remove(group);
1840                    }
1841            }
1842    
1843            /**
1844             * Returns the number of groups where companyId = &#63;.
1845             *
1846             * @param companyId the company ID
1847             * @return the number of matching groups
1848             * @throws SystemException if a system exception occurred
1849             */
1850            public int countByCompanyId(long companyId) throws SystemException {
1851                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
1852    
1853                    Object[] finderArgs = new Object[] { companyId };
1854    
1855                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1856                                    this);
1857    
1858                    if (count == null) {
1859                            StringBundler query = new StringBundler(2);
1860    
1861                            query.append(_SQL_COUNT_GROUP__WHERE);
1862    
1863                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1864    
1865                            String sql = query.toString();
1866    
1867                            Session session = null;
1868    
1869                            try {
1870                                    session = openSession();
1871    
1872                                    Query q = session.createQuery(sql);
1873    
1874                                    QueryPos qPos = QueryPos.getInstance(q);
1875    
1876                                    qPos.add(companyId);
1877    
1878                                    count = (Long)q.uniqueResult();
1879    
1880                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1881                            }
1882                            catch (Exception e) {
1883                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1884    
1885                                    throw processException(e);
1886                            }
1887                            finally {
1888                                    closeSession(session);
1889                            }
1890                    }
1891    
1892                    return count.intValue();
1893            }
1894    
1895            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "group_.companyId = ?";
1896            public static final FinderPath FINDER_PATH_FETCH_BY_LIVEGROUPID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
1897                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
1898                            FINDER_CLASS_NAME_ENTITY, "fetchByLiveGroupId",
1899                            new String[] { Long.class.getName() },
1900                            GroupModelImpl.LIVEGROUPID_COLUMN_BITMASK);
1901            public static final FinderPath FINDER_PATH_COUNT_BY_LIVEGROUPID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
1902                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
1903                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByLiveGroupId",
1904                            new String[] { Long.class.getName() });
1905    
1906            /**
1907             * Returns the group where liveGroupId = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
1908             *
1909             * @param liveGroupId the live group ID
1910             * @return the matching group
1911             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
1912             * @throws SystemException if a system exception occurred
1913             */
1914            public Group findByLiveGroupId(long liveGroupId)
1915                    throws NoSuchGroupException, SystemException {
1916                    Group group = fetchByLiveGroupId(liveGroupId);
1917    
1918                    if (group == null) {
1919                            StringBundler msg = new StringBundler(4);
1920    
1921                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1922    
1923                            msg.append("liveGroupId=");
1924                            msg.append(liveGroupId);
1925    
1926                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1927    
1928                            if (_log.isWarnEnabled()) {
1929                                    _log.warn(msg.toString());
1930                            }
1931    
1932                            throw new NoSuchGroupException(msg.toString());
1933                    }
1934    
1935                    return group;
1936            }
1937    
1938            /**
1939             * Returns the group where liveGroupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1940             *
1941             * @param liveGroupId the live group ID
1942             * @return the matching group, or <code>null</code> if a matching group could not be found
1943             * @throws SystemException if a system exception occurred
1944             */
1945            public Group fetchByLiveGroupId(long liveGroupId) throws SystemException {
1946                    return fetchByLiveGroupId(liveGroupId, true);
1947            }
1948    
1949            /**
1950             * Returns the group where liveGroupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1951             *
1952             * @param liveGroupId the live group ID
1953             * @param retrieveFromCache whether to use the finder cache
1954             * @return the matching group, or <code>null</code> if a matching group could not be found
1955             * @throws SystemException if a system exception occurred
1956             */
1957            public Group fetchByLiveGroupId(long liveGroupId, boolean retrieveFromCache)
1958                    throws SystemException {
1959                    Object[] finderArgs = new Object[] { liveGroupId };
1960    
1961                    Object result = null;
1962    
1963                    if (retrieveFromCache) {
1964                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
1965                                            finderArgs, this);
1966                    }
1967    
1968                    if (result instanceof Group) {
1969                            Group group = (Group)result;
1970    
1971                            if ((liveGroupId != group.getLiveGroupId())) {
1972                                    result = null;
1973                            }
1974                    }
1975    
1976                    if (result == null) {
1977                            StringBundler query = new StringBundler(3);
1978    
1979                            query.append(_SQL_SELECT_GROUP__WHERE);
1980    
1981                            query.append(_FINDER_COLUMN_LIVEGROUPID_LIVEGROUPID_2);
1982    
1983                            String sql = query.toString();
1984    
1985                            Session session = null;
1986    
1987                            try {
1988                                    session = openSession();
1989    
1990                                    Query q = session.createQuery(sql);
1991    
1992                                    QueryPos qPos = QueryPos.getInstance(q);
1993    
1994                                    qPos.add(liveGroupId);
1995    
1996                                    List<Group> list = q.list();
1997    
1998                                    if (list.isEmpty()) {
1999                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
2000                                                    finderArgs, list);
2001                                    }
2002                                    else {
2003                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
2004                                                    _log.warn(
2005                                                            "GroupPersistenceImpl.fetchByLiveGroupId(long, boolean) with parameters (" +
2006                                                            StringUtil.merge(finderArgs) +
2007                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
2008                                            }
2009    
2010                                            Group group = list.get(0);
2011    
2012                                            result = group;
2013    
2014                                            cacheResult(group);
2015    
2016                                            if ((group.getLiveGroupId() != liveGroupId)) {
2017                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
2018                                                            finderArgs, group);
2019                                            }
2020                                    }
2021                            }
2022                            catch (Exception e) {
2023                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
2024                                            finderArgs);
2025    
2026                                    throw processException(e);
2027                            }
2028                            finally {
2029                                    closeSession(session);
2030                            }
2031                    }
2032    
2033                    if (result instanceof List<?>) {
2034                            return null;
2035                    }
2036                    else {
2037                            return (Group)result;
2038                    }
2039            }
2040    
2041            /**
2042             * Removes the group where liveGroupId = &#63; from the database.
2043             *
2044             * @param liveGroupId the live group ID
2045             * @return the group that was removed
2046             * @throws SystemException if a system exception occurred
2047             */
2048            public Group removeByLiveGroupId(long liveGroupId)
2049                    throws NoSuchGroupException, SystemException {
2050                    Group group = findByLiveGroupId(liveGroupId);
2051    
2052                    return remove(group);
2053            }
2054    
2055            /**
2056             * Returns the number of groups where liveGroupId = &#63;.
2057             *
2058             * @param liveGroupId the live group ID
2059             * @return the number of matching groups
2060             * @throws SystemException if a system exception occurred
2061             */
2062            public int countByLiveGroupId(long liveGroupId) throws SystemException {
2063                    FinderPath finderPath = FINDER_PATH_COUNT_BY_LIVEGROUPID;
2064    
2065                    Object[] finderArgs = new Object[] { liveGroupId };
2066    
2067                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2068                                    this);
2069    
2070                    if (count == null) {
2071                            StringBundler query = new StringBundler(2);
2072    
2073                            query.append(_SQL_COUNT_GROUP__WHERE);
2074    
2075                            query.append(_FINDER_COLUMN_LIVEGROUPID_LIVEGROUPID_2);
2076    
2077                            String sql = query.toString();
2078    
2079                            Session session = null;
2080    
2081                            try {
2082                                    session = openSession();
2083    
2084                                    Query q = session.createQuery(sql);
2085    
2086                                    QueryPos qPos = QueryPos.getInstance(q);
2087    
2088                                    qPos.add(liveGroupId);
2089    
2090                                    count = (Long)q.uniqueResult();
2091    
2092                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2093                            }
2094                            catch (Exception e) {
2095                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2096    
2097                                    throw processException(e);
2098                            }
2099                            finally {
2100                                    closeSession(session);
2101                            }
2102                    }
2103    
2104                    return count.intValue();
2105            }
2106    
2107            private static final String _FINDER_COLUMN_LIVEGROUPID_LIVEGROUPID_2 = "group_.liveGroupId = ?";
2108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2109                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
2110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
2111                            new String[] {
2112                                    Long.class.getName(), Long.class.getName(),
2113                                    
2114                            Integer.class.getName(), Integer.class.getName(),
2115                                    OrderByComparator.class.getName()
2116                            });
2117            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2118                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
2119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
2120                            new String[] { Long.class.getName(), Long.class.getName() },
2121                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
2122                            GroupModelImpl.PARENTGROUPID_COLUMN_BITMASK |
2123                            GroupModelImpl.NAME_COLUMN_BITMASK);
2124            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2125                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
2126                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
2127                            new String[] { Long.class.getName(), Long.class.getName() });
2128    
2129            /**
2130             * Returns all the groups where companyId = &#63; and parentGroupId = &#63;.
2131             *
2132             * @param companyId the company ID
2133             * @param parentGroupId the parent group ID
2134             * @return the matching groups
2135             * @throws SystemException if a system exception occurred
2136             */
2137            public List<Group> findByC_P(long companyId, long parentGroupId)
2138                    throws SystemException {
2139                    return findByC_P(companyId, parentGroupId, QueryUtil.ALL_POS,
2140                            QueryUtil.ALL_POS, null);
2141            }
2142    
2143            /**
2144             * Returns a range of all the groups where companyId = &#63; and parentGroupId = &#63;.
2145             *
2146             * <p>
2147             * 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.GroupModelImpl}. 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.
2148             * </p>
2149             *
2150             * @param companyId the company ID
2151             * @param parentGroupId the parent group ID
2152             * @param start the lower bound of the range of groups
2153             * @param end the upper bound of the range of groups (not inclusive)
2154             * @return the range of matching groups
2155             * @throws SystemException if a system exception occurred
2156             */
2157            public List<Group> findByC_P(long companyId, long parentGroupId, int start,
2158                    int end) throws SystemException {
2159                    return findByC_P(companyId, parentGroupId, start, end, null);
2160            }
2161    
2162            /**
2163             * Returns an ordered range of all the groups where companyId = &#63; and parentGroupId = &#63;.
2164             *
2165             * <p>
2166             * 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.GroupModelImpl}. 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.
2167             * </p>
2168             *
2169             * @param companyId the company ID
2170             * @param parentGroupId the parent group ID
2171             * @param start the lower bound of the range of groups
2172             * @param end the upper bound of the range of groups (not inclusive)
2173             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2174             * @return the ordered range of matching groups
2175             * @throws SystemException if a system exception occurred
2176             */
2177            public List<Group> findByC_P(long companyId, long parentGroupId, int start,
2178                    int end, OrderByComparator orderByComparator) throws SystemException {
2179                    boolean pagination = true;
2180                    FinderPath finderPath = null;
2181                    Object[] finderArgs = null;
2182    
2183                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2184                                    (orderByComparator == null)) {
2185                            pagination = false;
2186                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
2187                            finderArgs = new Object[] { companyId, parentGroupId };
2188                    }
2189                    else {
2190                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
2191                            finderArgs = new Object[] {
2192                                            companyId, parentGroupId,
2193                                            
2194                                            start, end, orderByComparator
2195                                    };
2196                    }
2197    
2198                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
2199                                    finderArgs, this);
2200    
2201                    if ((list != null) && !list.isEmpty()) {
2202                            for (Group group : list) {
2203                                    if ((companyId != group.getCompanyId()) ||
2204                                                    (parentGroupId != group.getParentGroupId())) {
2205                                            list = null;
2206    
2207                                            break;
2208                                    }
2209                            }
2210                    }
2211    
2212                    if (list == null) {
2213                            StringBundler query = null;
2214    
2215                            if (orderByComparator != null) {
2216                                    query = new StringBundler(4 +
2217                                                    (orderByComparator.getOrderByFields().length * 3));
2218                            }
2219                            else {
2220                                    query = new StringBundler(4);
2221                            }
2222    
2223                            query.append(_SQL_SELECT_GROUP__WHERE);
2224    
2225                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2226    
2227                            query.append(_FINDER_COLUMN_C_P_PARENTGROUPID_2);
2228    
2229                            if (orderByComparator != null) {
2230                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2231                                            orderByComparator);
2232                            }
2233                            else
2234                             if (pagination) {
2235                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
2236                            }
2237    
2238                            String sql = query.toString();
2239    
2240                            Session session = null;
2241    
2242                            try {
2243                                    session = openSession();
2244    
2245                                    Query q = session.createQuery(sql);
2246    
2247                                    QueryPos qPos = QueryPos.getInstance(q);
2248    
2249                                    qPos.add(companyId);
2250    
2251                                    qPos.add(parentGroupId);
2252    
2253                                    if (!pagination) {
2254                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
2255                                                            end, false);
2256    
2257                                            Collections.sort(list);
2258    
2259                                            list = new UnmodifiableList<Group>(list);
2260                                    }
2261                                    else {
2262                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
2263                                                            end);
2264                                    }
2265    
2266                                    cacheResult(list);
2267    
2268                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2269                            }
2270                            catch (Exception e) {
2271                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2272    
2273                                    throw processException(e);
2274                            }
2275                            finally {
2276                                    closeSession(session);
2277                            }
2278                    }
2279    
2280                    return list;
2281            }
2282    
2283            /**
2284             * Returns the first group in the ordered set where companyId = &#63; and parentGroupId = &#63;.
2285             *
2286             * @param companyId the company ID
2287             * @param parentGroupId the parent group ID
2288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2289             * @return the first matching group
2290             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
2291             * @throws SystemException if a system exception occurred
2292             */
2293            public Group findByC_P_First(long companyId, long parentGroupId,
2294                    OrderByComparator orderByComparator)
2295                    throws NoSuchGroupException, SystemException {
2296                    Group group = fetchByC_P_First(companyId, parentGroupId,
2297                                    orderByComparator);
2298    
2299                    if (group != null) {
2300                            return group;
2301                    }
2302    
2303                    StringBundler msg = new StringBundler(6);
2304    
2305                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2306    
2307                    msg.append("companyId=");
2308                    msg.append(companyId);
2309    
2310                    msg.append(", parentGroupId=");
2311                    msg.append(parentGroupId);
2312    
2313                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2314    
2315                    throw new NoSuchGroupException(msg.toString());
2316            }
2317    
2318            /**
2319             * Returns the first group in the ordered set where companyId = &#63; and parentGroupId = &#63;.
2320             *
2321             * @param companyId the company ID
2322             * @param parentGroupId the parent group ID
2323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2324             * @return the first matching group, or <code>null</code> if a matching group could not be found
2325             * @throws SystemException if a system exception occurred
2326             */
2327            public Group fetchByC_P_First(long companyId, long parentGroupId,
2328                    OrderByComparator orderByComparator) throws SystemException {
2329                    List<Group> list = findByC_P(companyId, parentGroupId, 0, 1,
2330                                    orderByComparator);
2331    
2332                    if (!list.isEmpty()) {
2333                            return list.get(0);
2334                    }
2335    
2336                    return null;
2337            }
2338    
2339            /**
2340             * Returns the last group in the ordered set where companyId = &#63; and parentGroupId = &#63;.
2341             *
2342             * @param companyId the company ID
2343             * @param parentGroupId the parent group ID
2344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2345             * @return the last matching group
2346             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
2347             * @throws SystemException if a system exception occurred
2348             */
2349            public Group findByC_P_Last(long companyId, long parentGroupId,
2350                    OrderByComparator orderByComparator)
2351                    throws NoSuchGroupException, SystemException {
2352                    Group group = fetchByC_P_Last(companyId, parentGroupId,
2353                                    orderByComparator);
2354    
2355                    if (group != null) {
2356                            return group;
2357                    }
2358    
2359                    StringBundler msg = new StringBundler(6);
2360    
2361                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2362    
2363                    msg.append("companyId=");
2364                    msg.append(companyId);
2365    
2366                    msg.append(", parentGroupId=");
2367                    msg.append(parentGroupId);
2368    
2369                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2370    
2371                    throw new NoSuchGroupException(msg.toString());
2372            }
2373    
2374            /**
2375             * Returns the last group in the ordered set where companyId = &#63; and parentGroupId = &#63;.
2376             *
2377             * @param companyId the company ID
2378             * @param parentGroupId the parent group ID
2379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2380             * @return the last matching group, or <code>null</code> if a matching group could not be found
2381             * @throws SystemException if a system exception occurred
2382             */
2383            public Group fetchByC_P_Last(long companyId, long parentGroupId,
2384                    OrderByComparator orderByComparator) throws SystemException {
2385                    int count = countByC_P(companyId, parentGroupId);
2386    
2387                    List<Group> list = findByC_P(companyId, parentGroupId, count - 1,
2388                                    count, orderByComparator);
2389    
2390                    if (!list.isEmpty()) {
2391                            return list.get(0);
2392                    }
2393    
2394                    return null;
2395            }
2396    
2397            /**
2398             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and parentGroupId = &#63;.
2399             *
2400             * @param groupId the primary key of the current group
2401             * @param companyId the company ID
2402             * @param parentGroupId the parent group ID
2403             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2404             * @return the previous, current, and next group
2405             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
2406             * @throws SystemException if a system exception occurred
2407             */
2408            public Group[] findByC_P_PrevAndNext(long groupId, long companyId,
2409                    long parentGroupId, OrderByComparator orderByComparator)
2410                    throws NoSuchGroupException, SystemException {
2411                    Group group = findByPrimaryKey(groupId);
2412    
2413                    Session session = null;
2414    
2415                    try {
2416                            session = openSession();
2417    
2418                            Group[] array = new GroupImpl[3];
2419    
2420                            array[0] = getByC_P_PrevAndNext(session, group, companyId,
2421                                            parentGroupId, orderByComparator, true);
2422    
2423                            array[1] = group;
2424    
2425                            array[2] = getByC_P_PrevAndNext(session, group, companyId,
2426                                            parentGroupId, orderByComparator, false);
2427    
2428                            return array;
2429                    }
2430                    catch (Exception e) {
2431                            throw processException(e);
2432                    }
2433                    finally {
2434                            closeSession(session);
2435                    }
2436            }
2437    
2438            protected Group getByC_P_PrevAndNext(Session session, Group group,
2439                    long companyId, long parentGroupId,
2440                    OrderByComparator orderByComparator, boolean previous) {
2441                    StringBundler query = null;
2442    
2443                    if (orderByComparator != null) {
2444                            query = new StringBundler(6 +
2445                                            (orderByComparator.getOrderByFields().length * 6));
2446                    }
2447                    else {
2448                            query = new StringBundler(3);
2449                    }
2450    
2451                    query.append(_SQL_SELECT_GROUP__WHERE);
2452    
2453                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2454    
2455                    query.append(_FINDER_COLUMN_C_P_PARENTGROUPID_2);
2456    
2457                    if (orderByComparator != null) {
2458                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2459    
2460                            if (orderByConditionFields.length > 0) {
2461                                    query.append(WHERE_AND);
2462                            }
2463    
2464                            for (int i = 0; i < orderByConditionFields.length; i++) {
2465                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2466                                    query.append(orderByConditionFields[i]);
2467    
2468                                    if ((i + 1) < orderByConditionFields.length) {
2469                                            if (orderByComparator.isAscending() ^ previous) {
2470                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2471                                            }
2472                                            else {
2473                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2474                                            }
2475                                    }
2476                                    else {
2477                                            if (orderByComparator.isAscending() ^ previous) {
2478                                                    query.append(WHERE_GREATER_THAN);
2479                                            }
2480                                            else {
2481                                                    query.append(WHERE_LESSER_THAN);
2482                                            }
2483                                    }
2484                            }
2485    
2486                            query.append(ORDER_BY_CLAUSE);
2487    
2488                            String[] orderByFields = orderByComparator.getOrderByFields();
2489    
2490                            for (int i = 0; i < orderByFields.length; i++) {
2491                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2492                                    query.append(orderByFields[i]);
2493    
2494                                    if ((i + 1) < orderByFields.length) {
2495                                            if (orderByComparator.isAscending() ^ previous) {
2496                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2497                                            }
2498                                            else {
2499                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2500                                            }
2501                                    }
2502                                    else {
2503                                            if (orderByComparator.isAscending() ^ previous) {
2504                                                    query.append(ORDER_BY_ASC);
2505                                            }
2506                                            else {
2507                                                    query.append(ORDER_BY_DESC);
2508                                            }
2509                                    }
2510                            }
2511                    }
2512                    else {
2513                            query.append(GroupModelImpl.ORDER_BY_JPQL);
2514                    }
2515    
2516                    String sql = query.toString();
2517    
2518                    Query q = session.createQuery(sql);
2519    
2520                    q.setFirstResult(0);
2521                    q.setMaxResults(2);
2522    
2523                    QueryPos qPos = QueryPos.getInstance(q);
2524    
2525                    qPos.add(companyId);
2526    
2527                    qPos.add(parentGroupId);
2528    
2529                    if (orderByComparator != null) {
2530                            Object[] values = orderByComparator.getOrderByConditionValues(group);
2531    
2532                            for (Object value : values) {
2533                                    qPos.add(value);
2534                            }
2535                    }
2536    
2537                    List<Group> list = q.list();
2538    
2539                    if (list.size() == 2) {
2540                            return list.get(1);
2541                    }
2542                    else {
2543                            return null;
2544                    }
2545            }
2546    
2547            /**
2548             * Removes all the groups where companyId = &#63; and parentGroupId = &#63; from the database.
2549             *
2550             * @param companyId the company ID
2551             * @param parentGroupId the parent group ID
2552             * @throws SystemException if a system exception occurred
2553             */
2554            public void removeByC_P(long companyId, long parentGroupId)
2555                    throws SystemException {
2556                    for (Group group : findByC_P(companyId, parentGroupId,
2557                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2558                            remove(group);
2559                    }
2560            }
2561    
2562            /**
2563             * Returns the number of groups where companyId = &#63; and parentGroupId = &#63;.
2564             *
2565             * @param companyId the company ID
2566             * @param parentGroupId the parent group ID
2567             * @return the number of matching groups
2568             * @throws SystemException if a system exception occurred
2569             */
2570            public int countByC_P(long companyId, long parentGroupId)
2571                    throws SystemException {
2572                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
2573    
2574                    Object[] finderArgs = new Object[] { companyId, parentGroupId };
2575    
2576                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2577                                    this);
2578    
2579                    if (count == null) {
2580                            StringBundler query = new StringBundler(3);
2581    
2582                            query.append(_SQL_COUNT_GROUP__WHERE);
2583    
2584                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
2585    
2586                            query.append(_FINDER_COLUMN_C_P_PARENTGROUPID_2);
2587    
2588                            String sql = query.toString();
2589    
2590                            Session session = null;
2591    
2592                            try {
2593                                    session = openSession();
2594    
2595                                    Query q = session.createQuery(sql);
2596    
2597                                    QueryPos qPos = QueryPos.getInstance(q);
2598    
2599                                    qPos.add(companyId);
2600    
2601                                    qPos.add(parentGroupId);
2602    
2603                                    count = (Long)q.uniqueResult();
2604    
2605                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2606                            }
2607                            catch (Exception e) {
2608                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2609    
2610                                    throw processException(e);
2611                            }
2612                            finally {
2613                                    closeSession(session);
2614                            }
2615                    }
2616    
2617                    return count.intValue();
2618            }
2619    
2620            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "group_.companyId = ? AND ";
2621            private static final String _FINDER_COLUMN_C_P_PARENTGROUPID_2 = "group_.parentGroupId = ?";
2622            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2623                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
2624                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
2625                            new String[] { Long.class.getName(), String.class.getName() },
2626                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
2627                            GroupModelImpl.NAME_COLUMN_BITMASK);
2628            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2629                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
2630                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
2631                            new String[] { Long.class.getName(), String.class.getName() });
2632    
2633            /**
2634             * Returns the group where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
2635             *
2636             * @param companyId the company ID
2637             * @param name the name
2638             * @return the matching group
2639             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
2640             * @throws SystemException if a system exception occurred
2641             */
2642            public Group findByC_N(long companyId, String name)
2643                    throws NoSuchGroupException, SystemException {
2644                    Group group = fetchByC_N(companyId, name);
2645    
2646                    if (group == null) {
2647                            StringBundler msg = new StringBundler(6);
2648    
2649                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2650    
2651                            msg.append("companyId=");
2652                            msg.append(companyId);
2653    
2654                            msg.append(", name=");
2655                            msg.append(name);
2656    
2657                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2658    
2659                            if (_log.isWarnEnabled()) {
2660                                    _log.warn(msg.toString());
2661                            }
2662    
2663                            throw new NoSuchGroupException(msg.toString());
2664                    }
2665    
2666                    return group;
2667            }
2668    
2669            /**
2670             * Returns the group where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2671             *
2672             * @param companyId the company ID
2673             * @param name the name
2674             * @return the matching group, or <code>null</code> if a matching group could not be found
2675             * @throws SystemException if a system exception occurred
2676             */
2677            public Group fetchByC_N(long companyId, String name)
2678                    throws SystemException {
2679                    return fetchByC_N(companyId, name, true);
2680            }
2681    
2682            /**
2683             * Returns the group where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2684             *
2685             * @param companyId the company ID
2686             * @param name the name
2687             * @param retrieveFromCache whether to use the finder cache
2688             * @return the matching group, or <code>null</code> if a matching group could not be found
2689             * @throws SystemException if a system exception occurred
2690             */
2691            public Group fetchByC_N(long companyId, String name,
2692                    boolean retrieveFromCache) throws SystemException {
2693                    Object[] finderArgs = new Object[] { companyId, name };
2694    
2695                    Object result = null;
2696    
2697                    if (retrieveFromCache) {
2698                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2699                                            finderArgs, this);
2700                    }
2701    
2702                    if (result instanceof Group) {
2703                            Group group = (Group)result;
2704    
2705                            if ((companyId != group.getCompanyId()) ||
2706                                            !Validator.equals(name, group.getName())) {
2707                                    result = null;
2708                            }
2709                    }
2710    
2711                    if (result == null) {
2712                            StringBundler query = new StringBundler(4);
2713    
2714                            query.append(_SQL_SELECT_GROUP__WHERE);
2715    
2716                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2717    
2718                            boolean bindName = false;
2719    
2720                            if (name == null) {
2721                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2722                            }
2723                            else if (name.equals(StringPool.BLANK)) {
2724                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
2725                            }
2726                            else {
2727                                    bindName = true;
2728    
2729                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
2730                            }
2731    
2732                            String sql = query.toString();
2733    
2734                            Session session = null;
2735    
2736                            try {
2737                                    session = openSession();
2738    
2739                                    Query q = session.createQuery(sql);
2740    
2741                                    QueryPos qPos = QueryPos.getInstance(q);
2742    
2743                                    qPos.add(companyId);
2744    
2745                                    if (bindName) {
2746                                            qPos.add(name);
2747                                    }
2748    
2749                                    List<Group> list = q.list();
2750    
2751                                    if (list.isEmpty()) {
2752                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2753                                                    finderArgs, list);
2754                                    }
2755                                    else {
2756                                            Group group = list.get(0);
2757    
2758                                            result = group;
2759    
2760                                            cacheResult(group);
2761    
2762                                            if ((group.getCompanyId() != companyId) ||
2763                                                            (group.getName() == null) ||
2764                                                            !group.getName().equals(name)) {
2765                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2766                                                            finderArgs, group);
2767                                            }
2768                                    }
2769                            }
2770                            catch (Exception e) {
2771                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2772                                            finderArgs);
2773    
2774                                    throw processException(e);
2775                            }
2776                            finally {
2777                                    closeSession(session);
2778                            }
2779                    }
2780    
2781                    if (result instanceof List<?>) {
2782                            return null;
2783                    }
2784                    else {
2785                            return (Group)result;
2786                    }
2787            }
2788    
2789            /**
2790             * Removes the group where companyId = &#63; and name = &#63; from the database.
2791             *
2792             * @param companyId the company ID
2793             * @param name the name
2794             * @return the group that was removed
2795             * @throws SystemException if a system exception occurred
2796             */
2797            public Group removeByC_N(long companyId, String name)
2798                    throws NoSuchGroupException, SystemException {
2799                    Group group = findByC_N(companyId, name);
2800    
2801                    return remove(group);
2802            }
2803    
2804            /**
2805             * Returns the number of groups where companyId = &#63; and name = &#63;.
2806             *
2807             * @param companyId the company ID
2808             * @param name the name
2809             * @return the number of matching groups
2810             * @throws SystemException if a system exception occurred
2811             */
2812            public int countByC_N(long companyId, String name)
2813                    throws SystemException {
2814                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
2815    
2816                    Object[] finderArgs = new Object[] { companyId, name };
2817    
2818                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2819                                    this);
2820    
2821                    if (count == null) {
2822                            StringBundler query = new StringBundler(3);
2823    
2824                            query.append(_SQL_COUNT_GROUP__WHERE);
2825    
2826                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2827    
2828                            boolean bindName = false;
2829    
2830                            if (name == null) {
2831                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
2832                            }
2833                            else if (name.equals(StringPool.BLANK)) {
2834                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
2835                            }
2836                            else {
2837                                    bindName = true;
2838    
2839                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
2840                            }
2841    
2842                            String sql = query.toString();
2843    
2844                            Session session = null;
2845    
2846                            try {
2847                                    session = openSession();
2848    
2849                                    Query q = session.createQuery(sql);
2850    
2851                                    QueryPos qPos = QueryPos.getInstance(q);
2852    
2853                                    qPos.add(companyId);
2854    
2855                                    if (bindName) {
2856                                            qPos.add(name);
2857                                    }
2858    
2859                                    count = (Long)q.uniqueResult();
2860    
2861                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2862                            }
2863                            catch (Exception e) {
2864                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2865    
2866                                    throw processException(e);
2867                            }
2868                            finally {
2869                                    closeSession(session);
2870                            }
2871                    }
2872    
2873                    return count.intValue();
2874            }
2875    
2876            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "group_.companyId = ? AND ";
2877            private static final String _FINDER_COLUMN_C_N_NAME_1 = "group_.name IS NULL";
2878            private static final String _FINDER_COLUMN_C_N_NAME_2 = "group_.name = ?";
2879            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(group_.name IS NULL OR group_.name = '')";
2880            public static final FinderPath FINDER_PATH_FETCH_BY_C_F = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2881                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
2882                            FINDER_CLASS_NAME_ENTITY, "fetchByC_F",
2883                            new String[] { Long.class.getName(), String.class.getName() },
2884                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
2885                            GroupModelImpl.FRIENDLYURL_COLUMN_BITMASK);
2886            public static final FinderPath FINDER_PATH_COUNT_BY_C_F = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
2887                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
2888                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_F",
2889                            new String[] { Long.class.getName(), String.class.getName() });
2890    
2891            /**
2892             * Returns the group where companyId = &#63; and friendlyURL = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
2893             *
2894             * @param companyId the company ID
2895             * @param friendlyURL the friendly u r l
2896             * @return the matching group
2897             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
2898             * @throws SystemException if a system exception occurred
2899             */
2900            public Group findByC_F(long companyId, String friendlyURL)
2901                    throws NoSuchGroupException, SystemException {
2902                    Group group = fetchByC_F(companyId, friendlyURL);
2903    
2904                    if (group == null) {
2905                            StringBundler msg = new StringBundler(6);
2906    
2907                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2908    
2909                            msg.append("companyId=");
2910                            msg.append(companyId);
2911    
2912                            msg.append(", friendlyURL=");
2913                            msg.append(friendlyURL);
2914    
2915                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2916    
2917                            if (_log.isWarnEnabled()) {
2918                                    _log.warn(msg.toString());
2919                            }
2920    
2921                            throw new NoSuchGroupException(msg.toString());
2922                    }
2923    
2924                    return group;
2925            }
2926    
2927            /**
2928             * Returns the group where companyId = &#63; and friendlyURL = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2929             *
2930             * @param companyId the company ID
2931             * @param friendlyURL the friendly u r l
2932             * @return the matching group, or <code>null</code> if a matching group could not be found
2933             * @throws SystemException if a system exception occurred
2934             */
2935            public Group fetchByC_F(long companyId, String friendlyURL)
2936                    throws SystemException {
2937                    return fetchByC_F(companyId, friendlyURL, true);
2938            }
2939    
2940            /**
2941             * Returns the group where companyId = &#63; and friendlyURL = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2942             *
2943             * @param companyId the company ID
2944             * @param friendlyURL the friendly u r l
2945             * @param retrieveFromCache whether to use the finder cache
2946             * @return the matching group, or <code>null</code> if a matching group could not be found
2947             * @throws SystemException if a system exception occurred
2948             */
2949            public Group fetchByC_F(long companyId, String friendlyURL,
2950                    boolean retrieveFromCache) throws SystemException {
2951                    Object[] finderArgs = new Object[] { companyId, friendlyURL };
2952    
2953                    Object result = null;
2954    
2955                    if (retrieveFromCache) {
2956                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_F,
2957                                            finderArgs, this);
2958                    }
2959    
2960                    if (result instanceof Group) {
2961                            Group group = (Group)result;
2962    
2963                            if ((companyId != group.getCompanyId()) ||
2964                                            !Validator.equals(friendlyURL, group.getFriendlyURL())) {
2965                                    result = null;
2966                            }
2967                    }
2968    
2969                    if (result == null) {
2970                            StringBundler query = new StringBundler(4);
2971    
2972                            query.append(_SQL_SELECT_GROUP__WHERE);
2973    
2974                            query.append(_FINDER_COLUMN_C_F_COMPANYID_2);
2975    
2976                            boolean bindFriendlyURL = false;
2977    
2978                            if (friendlyURL == null) {
2979                                    query.append(_FINDER_COLUMN_C_F_FRIENDLYURL_1);
2980                            }
2981                            else if (friendlyURL.equals(StringPool.BLANK)) {
2982                                    query.append(_FINDER_COLUMN_C_F_FRIENDLYURL_3);
2983                            }
2984                            else {
2985                                    bindFriendlyURL = true;
2986    
2987                                    query.append(_FINDER_COLUMN_C_F_FRIENDLYURL_2);
2988                            }
2989    
2990                            String sql = query.toString();
2991    
2992                            Session session = null;
2993    
2994                            try {
2995                                    session = openSession();
2996    
2997                                    Query q = session.createQuery(sql);
2998    
2999                                    QueryPos qPos = QueryPos.getInstance(q);
3000    
3001                                    qPos.add(companyId);
3002    
3003                                    if (bindFriendlyURL) {
3004                                            qPos.add(friendlyURL);
3005                                    }
3006    
3007                                    List<Group> list = q.list();
3008    
3009                                    if (list.isEmpty()) {
3010                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
3011                                                    finderArgs, list);
3012                                    }
3013                                    else {
3014                                            Group group = list.get(0);
3015    
3016                                            result = group;
3017    
3018                                            cacheResult(group);
3019    
3020                                            if ((group.getCompanyId() != companyId) ||
3021                                                            (group.getFriendlyURL() == null) ||
3022                                                            !group.getFriendlyURL().equals(friendlyURL)) {
3023                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
3024                                                            finderArgs, group);
3025                                            }
3026                                    }
3027                            }
3028                            catch (Exception e) {
3029                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F,
3030                                            finderArgs);
3031    
3032                                    throw processException(e);
3033                            }
3034                            finally {
3035                                    closeSession(session);
3036                            }
3037                    }
3038    
3039                    if (result instanceof List<?>) {
3040                            return null;
3041                    }
3042                    else {
3043                            return (Group)result;
3044                    }
3045            }
3046    
3047            /**
3048             * Removes the group where companyId = &#63; and friendlyURL = &#63; from the database.
3049             *
3050             * @param companyId the company ID
3051             * @param friendlyURL the friendly u r l
3052             * @return the group that was removed
3053             * @throws SystemException if a system exception occurred
3054             */
3055            public Group removeByC_F(long companyId, String friendlyURL)
3056                    throws NoSuchGroupException, SystemException {
3057                    Group group = findByC_F(companyId, friendlyURL);
3058    
3059                    return remove(group);
3060            }
3061    
3062            /**
3063             * Returns the number of groups where companyId = &#63; and friendlyURL = &#63;.
3064             *
3065             * @param companyId the company ID
3066             * @param friendlyURL the friendly u r l
3067             * @return the number of matching groups
3068             * @throws SystemException if a system exception occurred
3069             */
3070            public int countByC_F(long companyId, String friendlyURL)
3071                    throws SystemException {
3072                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_F;
3073    
3074                    Object[] finderArgs = new Object[] { companyId, friendlyURL };
3075    
3076                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3077                                    this);
3078    
3079                    if (count == null) {
3080                            StringBundler query = new StringBundler(3);
3081    
3082                            query.append(_SQL_COUNT_GROUP__WHERE);
3083    
3084                            query.append(_FINDER_COLUMN_C_F_COMPANYID_2);
3085    
3086                            boolean bindFriendlyURL = false;
3087    
3088                            if (friendlyURL == null) {
3089                                    query.append(_FINDER_COLUMN_C_F_FRIENDLYURL_1);
3090                            }
3091                            else if (friendlyURL.equals(StringPool.BLANK)) {
3092                                    query.append(_FINDER_COLUMN_C_F_FRIENDLYURL_3);
3093                            }
3094                            else {
3095                                    bindFriendlyURL = true;
3096    
3097                                    query.append(_FINDER_COLUMN_C_F_FRIENDLYURL_2);
3098                            }
3099    
3100                            String sql = query.toString();
3101    
3102                            Session session = null;
3103    
3104                            try {
3105                                    session = openSession();
3106    
3107                                    Query q = session.createQuery(sql);
3108    
3109                                    QueryPos qPos = QueryPos.getInstance(q);
3110    
3111                                    qPos.add(companyId);
3112    
3113                                    if (bindFriendlyURL) {
3114                                            qPos.add(friendlyURL);
3115                                    }
3116    
3117                                    count = (Long)q.uniqueResult();
3118    
3119                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3120                            }
3121                            catch (Exception e) {
3122                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3123    
3124                                    throw processException(e);
3125                            }
3126                            finally {
3127                                    closeSession(session);
3128                            }
3129                    }
3130    
3131                    return count.intValue();
3132            }
3133    
3134            private static final String _FINDER_COLUMN_C_F_COMPANYID_2 = "group_.companyId = ? AND ";
3135            private static final String _FINDER_COLUMN_C_F_FRIENDLYURL_1 = "group_.friendlyURL IS NULL";
3136            private static final String _FINDER_COLUMN_C_F_FRIENDLYURL_2 = "group_.friendlyURL = ?";
3137            private static final String _FINDER_COLUMN_C_F_FRIENDLYURL_3 = "(group_.friendlyURL IS NULL OR group_.friendlyURL = '')";
3138            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
3139                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
3140                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
3141                            new String[] {
3142                                    Long.class.getName(), Boolean.class.getName(),
3143                                    
3144                            Integer.class.getName(), Integer.class.getName(),
3145                                    OrderByComparator.class.getName()
3146                            });
3147            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
3148                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
3149                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
3150                            new String[] { Long.class.getName(), Boolean.class.getName() },
3151                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
3152                            GroupModelImpl.SITE_COLUMN_BITMASK |
3153                            GroupModelImpl.NAME_COLUMN_BITMASK);
3154            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
3155                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
3156                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
3157                            new String[] { Long.class.getName(), Boolean.class.getName() });
3158    
3159            /**
3160             * Returns all the groups where companyId = &#63; and site = &#63;.
3161             *
3162             * @param companyId the company ID
3163             * @param site the site
3164             * @return the matching groups
3165             * @throws SystemException if a system exception occurred
3166             */
3167            public List<Group> findByC_S(long companyId, boolean site)
3168                    throws SystemException {
3169                    return findByC_S(companyId, site, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3170                            null);
3171            }
3172    
3173            /**
3174             * Returns a range of all the groups where companyId = &#63; and site = &#63;.
3175             *
3176             * <p>
3177             * 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.GroupModelImpl}. 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.
3178             * </p>
3179             *
3180             * @param companyId the company ID
3181             * @param site the site
3182             * @param start the lower bound of the range of groups
3183             * @param end the upper bound of the range of groups (not inclusive)
3184             * @return the range of matching groups
3185             * @throws SystemException if a system exception occurred
3186             */
3187            public List<Group> findByC_S(long companyId, boolean site, int start,
3188                    int end) throws SystemException {
3189                    return findByC_S(companyId, site, start, end, null);
3190            }
3191    
3192            /**
3193             * Returns an ordered range of all the groups where companyId = &#63; and site = &#63;.
3194             *
3195             * <p>
3196             * 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.GroupModelImpl}. 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.
3197             * </p>
3198             *
3199             * @param companyId the company ID
3200             * @param site the site
3201             * @param start the lower bound of the range of groups
3202             * @param end the upper bound of the range of groups (not inclusive)
3203             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3204             * @return the ordered range of matching groups
3205             * @throws SystemException if a system exception occurred
3206             */
3207            public List<Group> findByC_S(long companyId, boolean site, int start,
3208                    int end, OrderByComparator orderByComparator) throws SystemException {
3209                    boolean pagination = true;
3210                    FinderPath finderPath = null;
3211                    Object[] finderArgs = null;
3212    
3213                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3214                                    (orderByComparator == null)) {
3215                            pagination = false;
3216                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
3217                            finderArgs = new Object[] { companyId, site };
3218                    }
3219                    else {
3220                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
3221                            finderArgs = new Object[] {
3222                                            companyId, site,
3223                                            
3224                                            start, end, orderByComparator
3225                                    };
3226                    }
3227    
3228                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
3229                                    finderArgs, this);
3230    
3231                    if ((list != null) && !list.isEmpty()) {
3232                            for (Group group : list) {
3233                                    if ((companyId != group.getCompanyId()) ||
3234                                                    (site != group.getSite())) {
3235                                            list = null;
3236    
3237                                            break;
3238                                    }
3239                            }
3240                    }
3241    
3242                    if (list == null) {
3243                            StringBundler query = null;
3244    
3245                            if (orderByComparator != null) {
3246                                    query = new StringBundler(4 +
3247                                                    (orderByComparator.getOrderByFields().length * 3));
3248                            }
3249                            else {
3250                                    query = new StringBundler(4);
3251                            }
3252    
3253                            query.append(_SQL_SELECT_GROUP__WHERE);
3254    
3255                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
3256    
3257                            query.append(_FINDER_COLUMN_C_S_SITE_2);
3258    
3259                            if (orderByComparator != null) {
3260                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3261                                            orderByComparator);
3262                            }
3263                            else
3264                             if (pagination) {
3265                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
3266                            }
3267    
3268                            String sql = query.toString();
3269    
3270                            Session session = null;
3271    
3272                            try {
3273                                    session = openSession();
3274    
3275                                    Query q = session.createQuery(sql);
3276    
3277                                    QueryPos qPos = QueryPos.getInstance(q);
3278    
3279                                    qPos.add(companyId);
3280    
3281                                    qPos.add(site);
3282    
3283                                    if (!pagination) {
3284                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
3285                                                            end, false);
3286    
3287                                            Collections.sort(list);
3288    
3289                                            list = new UnmodifiableList<Group>(list);
3290                                    }
3291                                    else {
3292                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
3293                                                            end);
3294                                    }
3295    
3296                                    cacheResult(list);
3297    
3298                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3299                            }
3300                            catch (Exception e) {
3301                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3302    
3303                                    throw processException(e);
3304                            }
3305                            finally {
3306                                    closeSession(session);
3307                            }
3308                    }
3309    
3310                    return list;
3311            }
3312    
3313            /**
3314             * Returns the first group in the ordered set where companyId = &#63; and site = &#63;.
3315             *
3316             * @param companyId the company ID
3317             * @param site the site
3318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3319             * @return the first matching group
3320             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
3321             * @throws SystemException if a system exception occurred
3322             */
3323            public Group findByC_S_First(long companyId, boolean site,
3324                    OrderByComparator orderByComparator)
3325                    throws NoSuchGroupException, SystemException {
3326                    Group group = fetchByC_S_First(companyId, site, orderByComparator);
3327    
3328                    if (group != null) {
3329                            return group;
3330                    }
3331    
3332                    StringBundler msg = new StringBundler(6);
3333    
3334                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3335    
3336                    msg.append("companyId=");
3337                    msg.append(companyId);
3338    
3339                    msg.append(", site=");
3340                    msg.append(site);
3341    
3342                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3343    
3344                    throw new NoSuchGroupException(msg.toString());
3345            }
3346    
3347            /**
3348             * Returns the first group in the ordered set where companyId = &#63; and site = &#63;.
3349             *
3350             * @param companyId the company ID
3351             * @param site the site
3352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3353             * @return the first matching group, or <code>null</code> if a matching group could not be found
3354             * @throws SystemException if a system exception occurred
3355             */
3356            public Group fetchByC_S_First(long companyId, boolean site,
3357                    OrderByComparator orderByComparator) throws SystemException {
3358                    List<Group> list = findByC_S(companyId, site, 0, 1, orderByComparator);
3359    
3360                    if (!list.isEmpty()) {
3361                            return list.get(0);
3362                    }
3363    
3364                    return null;
3365            }
3366    
3367            /**
3368             * Returns the last group in the ordered set where companyId = &#63; and site = &#63;.
3369             *
3370             * @param companyId the company ID
3371             * @param site the site
3372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3373             * @return the last matching group
3374             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
3375             * @throws SystemException if a system exception occurred
3376             */
3377            public Group findByC_S_Last(long companyId, boolean site,
3378                    OrderByComparator orderByComparator)
3379                    throws NoSuchGroupException, SystemException {
3380                    Group group = fetchByC_S_Last(companyId, site, orderByComparator);
3381    
3382                    if (group != null) {
3383                            return group;
3384                    }
3385    
3386                    StringBundler msg = new StringBundler(6);
3387    
3388                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3389    
3390                    msg.append("companyId=");
3391                    msg.append(companyId);
3392    
3393                    msg.append(", site=");
3394                    msg.append(site);
3395    
3396                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3397    
3398                    throw new NoSuchGroupException(msg.toString());
3399            }
3400    
3401            /**
3402             * Returns the last group in the ordered set where companyId = &#63; and site = &#63;.
3403             *
3404             * @param companyId the company ID
3405             * @param site the site
3406             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3407             * @return the last matching group, or <code>null</code> if a matching group could not be found
3408             * @throws SystemException if a system exception occurred
3409             */
3410            public Group fetchByC_S_Last(long companyId, boolean site,
3411                    OrderByComparator orderByComparator) throws SystemException {
3412                    int count = countByC_S(companyId, site);
3413    
3414                    List<Group> list = findByC_S(companyId, site, count - 1, count,
3415                                    orderByComparator);
3416    
3417                    if (!list.isEmpty()) {
3418                            return list.get(0);
3419                    }
3420    
3421                    return null;
3422            }
3423    
3424            /**
3425             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and site = &#63;.
3426             *
3427             * @param groupId the primary key of the current group
3428             * @param companyId the company ID
3429             * @param site the site
3430             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3431             * @return the previous, current, and next group
3432             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
3433             * @throws SystemException if a system exception occurred
3434             */
3435            public Group[] findByC_S_PrevAndNext(long groupId, long companyId,
3436                    boolean site, OrderByComparator orderByComparator)
3437                    throws NoSuchGroupException, SystemException {
3438                    Group group = findByPrimaryKey(groupId);
3439    
3440                    Session session = null;
3441    
3442                    try {
3443                            session = openSession();
3444    
3445                            Group[] array = new GroupImpl[3];
3446    
3447                            array[0] = getByC_S_PrevAndNext(session, group, companyId, site,
3448                                            orderByComparator, true);
3449    
3450                            array[1] = group;
3451    
3452                            array[2] = getByC_S_PrevAndNext(session, group, companyId, site,
3453                                            orderByComparator, false);
3454    
3455                            return array;
3456                    }
3457                    catch (Exception e) {
3458                            throw processException(e);
3459                    }
3460                    finally {
3461                            closeSession(session);
3462                    }
3463            }
3464    
3465            protected Group getByC_S_PrevAndNext(Session session, Group group,
3466                    long companyId, boolean site, OrderByComparator orderByComparator,
3467                    boolean previous) {
3468                    StringBundler query = null;
3469    
3470                    if (orderByComparator != null) {
3471                            query = new StringBundler(6 +
3472                                            (orderByComparator.getOrderByFields().length * 6));
3473                    }
3474                    else {
3475                            query = new StringBundler(3);
3476                    }
3477    
3478                    query.append(_SQL_SELECT_GROUP__WHERE);
3479    
3480                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
3481    
3482                    query.append(_FINDER_COLUMN_C_S_SITE_2);
3483    
3484                    if (orderByComparator != null) {
3485                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3486    
3487                            if (orderByConditionFields.length > 0) {
3488                                    query.append(WHERE_AND);
3489                            }
3490    
3491                            for (int i = 0; i < orderByConditionFields.length; i++) {
3492                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3493                                    query.append(orderByConditionFields[i]);
3494    
3495                                    if ((i + 1) < orderByConditionFields.length) {
3496                                            if (orderByComparator.isAscending() ^ previous) {
3497                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3498                                            }
3499                                            else {
3500                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3501                                            }
3502                                    }
3503                                    else {
3504                                            if (orderByComparator.isAscending() ^ previous) {
3505                                                    query.append(WHERE_GREATER_THAN);
3506                                            }
3507                                            else {
3508                                                    query.append(WHERE_LESSER_THAN);
3509                                            }
3510                                    }
3511                            }
3512    
3513                            query.append(ORDER_BY_CLAUSE);
3514    
3515                            String[] orderByFields = orderByComparator.getOrderByFields();
3516    
3517                            for (int i = 0; i < orderByFields.length; i++) {
3518                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3519                                    query.append(orderByFields[i]);
3520    
3521                                    if ((i + 1) < orderByFields.length) {
3522                                            if (orderByComparator.isAscending() ^ previous) {
3523                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3524                                            }
3525                                            else {
3526                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3527                                            }
3528                                    }
3529                                    else {
3530                                            if (orderByComparator.isAscending() ^ previous) {
3531                                                    query.append(ORDER_BY_ASC);
3532                                            }
3533                                            else {
3534                                                    query.append(ORDER_BY_DESC);
3535                                            }
3536                                    }
3537                            }
3538                    }
3539                    else {
3540                            query.append(GroupModelImpl.ORDER_BY_JPQL);
3541                    }
3542    
3543                    String sql = query.toString();
3544    
3545                    Query q = session.createQuery(sql);
3546    
3547                    q.setFirstResult(0);
3548                    q.setMaxResults(2);
3549    
3550                    QueryPos qPos = QueryPos.getInstance(q);
3551    
3552                    qPos.add(companyId);
3553    
3554                    qPos.add(site);
3555    
3556                    if (orderByComparator != null) {
3557                            Object[] values = orderByComparator.getOrderByConditionValues(group);
3558    
3559                            for (Object value : values) {
3560                                    qPos.add(value);
3561                            }
3562                    }
3563    
3564                    List<Group> list = q.list();
3565    
3566                    if (list.size() == 2) {
3567                            return list.get(1);
3568                    }
3569                    else {
3570                            return null;
3571                    }
3572            }
3573    
3574            /**
3575             * Removes all the groups where companyId = &#63; and site = &#63; from the database.
3576             *
3577             * @param companyId the company ID
3578             * @param site the site
3579             * @throws SystemException if a system exception occurred
3580             */
3581            public void removeByC_S(long companyId, boolean site)
3582                    throws SystemException {
3583                    for (Group group : findByC_S(companyId, site, QueryUtil.ALL_POS,
3584                                    QueryUtil.ALL_POS, null)) {
3585                            remove(group);
3586                    }
3587            }
3588    
3589            /**
3590             * Returns the number of groups where companyId = &#63; and site = &#63;.
3591             *
3592             * @param companyId the company ID
3593             * @param site the site
3594             * @return the number of matching groups
3595             * @throws SystemException if a system exception occurred
3596             */
3597            public int countByC_S(long companyId, boolean site)
3598                    throws SystemException {
3599                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
3600    
3601                    Object[] finderArgs = new Object[] { companyId, site };
3602    
3603                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3604                                    this);
3605    
3606                    if (count == null) {
3607                            StringBundler query = new StringBundler(3);
3608    
3609                            query.append(_SQL_COUNT_GROUP__WHERE);
3610    
3611                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
3612    
3613                            query.append(_FINDER_COLUMN_C_S_SITE_2);
3614    
3615                            String sql = query.toString();
3616    
3617                            Session session = null;
3618    
3619                            try {
3620                                    session = openSession();
3621    
3622                                    Query q = session.createQuery(sql);
3623    
3624                                    QueryPos qPos = QueryPos.getInstance(q);
3625    
3626                                    qPos.add(companyId);
3627    
3628                                    qPos.add(site);
3629    
3630                                    count = (Long)q.uniqueResult();
3631    
3632                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3633                            }
3634                            catch (Exception e) {
3635                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3636    
3637                                    throw processException(e);
3638                            }
3639                            finally {
3640                                    closeSession(session);
3641                            }
3642                    }
3643    
3644                    return count.intValue();
3645            }
3646    
3647            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "group_.companyId = ? AND ";
3648            private static final String _FINDER_COLUMN_C_S_SITE_2 = "group_.site = ?";
3649            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
3650                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
3651                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
3652                            new String[] {
3653                                    Integer.class.getName(), Boolean.class.getName(),
3654                                    
3655                            Integer.class.getName(), Integer.class.getName(),
3656                                    OrderByComparator.class.getName()
3657                            });
3658            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
3659                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
3660                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
3661                            new String[] { Integer.class.getName(), Boolean.class.getName() },
3662                            GroupModelImpl.TYPE_COLUMN_BITMASK |
3663                            GroupModelImpl.ACTIVE_COLUMN_BITMASK |
3664                            GroupModelImpl.NAME_COLUMN_BITMASK);
3665            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
3666                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
3667                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
3668                            new String[] { Integer.class.getName(), Boolean.class.getName() });
3669    
3670            /**
3671             * Returns all the groups where type = &#63; and active = &#63;.
3672             *
3673             * @param type the type
3674             * @param active the active
3675             * @return the matching groups
3676             * @throws SystemException if a system exception occurred
3677             */
3678            public List<Group> findByT_A(int type, boolean active)
3679                    throws SystemException {
3680                    return findByT_A(type, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3681                            null);
3682            }
3683    
3684            /**
3685             * Returns a range of all the groups where type = &#63; and active = &#63;.
3686             *
3687             * <p>
3688             * 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.GroupModelImpl}. 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.
3689             * </p>
3690             *
3691             * @param type the type
3692             * @param active the active
3693             * @param start the lower bound of the range of groups
3694             * @param end the upper bound of the range of groups (not inclusive)
3695             * @return the range of matching groups
3696             * @throws SystemException if a system exception occurred
3697             */
3698            public List<Group> findByT_A(int type, boolean active, int start, int end)
3699                    throws SystemException {
3700                    return findByT_A(type, active, start, end, null);
3701            }
3702    
3703            /**
3704             * Returns an ordered range of all the groups where type = &#63; and active = &#63;.
3705             *
3706             * <p>
3707             * 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.GroupModelImpl}. 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.
3708             * </p>
3709             *
3710             * @param type the type
3711             * @param active the active
3712             * @param start the lower bound of the range of groups
3713             * @param end the upper bound of the range of groups (not inclusive)
3714             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3715             * @return the ordered range of matching groups
3716             * @throws SystemException if a system exception occurred
3717             */
3718            public List<Group> findByT_A(int type, boolean active, int start, int end,
3719                    OrderByComparator orderByComparator) throws SystemException {
3720                    boolean pagination = true;
3721                    FinderPath finderPath = null;
3722                    Object[] finderArgs = null;
3723    
3724                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3725                                    (orderByComparator == null)) {
3726                            pagination = false;
3727                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
3728                            finderArgs = new Object[] { type, active };
3729                    }
3730                    else {
3731                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
3732                            finderArgs = new Object[] {
3733                                            type, active,
3734                                            
3735                                            start, end, orderByComparator
3736                                    };
3737                    }
3738    
3739                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
3740                                    finderArgs, this);
3741    
3742                    if ((list != null) && !list.isEmpty()) {
3743                            for (Group group : list) {
3744                                    if ((type != group.getType()) || (active != group.getActive())) {
3745                                            list = null;
3746    
3747                                            break;
3748                                    }
3749                            }
3750                    }
3751    
3752                    if (list == null) {
3753                            StringBundler query = null;
3754    
3755                            if (orderByComparator != null) {
3756                                    query = new StringBundler(4 +
3757                                                    (orderByComparator.getOrderByFields().length * 3));
3758                            }
3759                            else {
3760                                    query = new StringBundler(4);
3761                            }
3762    
3763                            query.append(_SQL_SELECT_GROUP__WHERE);
3764    
3765                            query.append(_FINDER_COLUMN_T_A_TYPE_2);
3766    
3767                            query.append(_FINDER_COLUMN_T_A_ACTIVE_2);
3768    
3769                            if (orderByComparator != null) {
3770                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3771                                            orderByComparator);
3772                            }
3773                            else
3774                             if (pagination) {
3775                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
3776                            }
3777    
3778                            String sql = query.toString();
3779    
3780                            Session session = null;
3781    
3782                            try {
3783                                    session = openSession();
3784    
3785                                    Query q = session.createQuery(sql);
3786    
3787                                    QueryPos qPos = QueryPos.getInstance(q);
3788    
3789                                    qPos.add(type);
3790    
3791                                    qPos.add(active);
3792    
3793                                    if (!pagination) {
3794                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
3795                                                            end, false);
3796    
3797                                            Collections.sort(list);
3798    
3799                                            list = new UnmodifiableList<Group>(list);
3800                                    }
3801                                    else {
3802                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
3803                                                            end);
3804                                    }
3805    
3806                                    cacheResult(list);
3807    
3808                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3809                            }
3810                            catch (Exception e) {
3811                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3812    
3813                                    throw processException(e);
3814                            }
3815                            finally {
3816                                    closeSession(session);
3817                            }
3818                    }
3819    
3820                    return list;
3821            }
3822    
3823            /**
3824             * Returns the first group in the ordered set where type = &#63; and active = &#63;.
3825             *
3826             * @param type the type
3827             * @param active the active
3828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3829             * @return the first matching group
3830             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
3831             * @throws SystemException if a system exception occurred
3832             */
3833            public Group findByT_A_First(int type, boolean active,
3834                    OrderByComparator orderByComparator)
3835                    throws NoSuchGroupException, SystemException {
3836                    Group group = fetchByT_A_First(type, active, orderByComparator);
3837    
3838                    if (group != null) {
3839                            return group;
3840                    }
3841    
3842                    StringBundler msg = new StringBundler(6);
3843    
3844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3845    
3846                    msg.append("type=");
3847                    msg.append(type);
3848    
3849                    msg.append(", active=");
3850                    msg.append(active);
3851    
3852                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3853    
3854                    throw new NoSuchGroupException(msg.toString());
3855            }
3856    
3857            /**
3858             * Returns the first group in the ordered set where type = &#63; and active = &#63;.
3859             *
3860             * @param type the type
3861             * @param active the active
3862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3863             * @return the first matching group, or <code>null</code> if a matching group could not be found
3864             * @throws SystemException if a system exception occurred
3865             */
3866            public Group fetchByT_A_First(int type, boolean active,
3867                    OrderByComparator orderByComparator) throws SystemException {
3868                    List<Group> list = findByT_A(type, active, 0, 1, orderByComparator);
3869    
3870                    if (!list.isEmpty()) {
3871                            return list.get(0);
3872                    }
3873    
3874                    return null;
3875            }
3876    
3877            /**
3878             * Returns the last group in the ordered set where type = &#63; and active = &#63;.
3879             *
3880             * @param type the type
3881             * @param active the active
3882             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3883             * @return the last matching group
3884             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
3885             * @throws SystemException if a system exception occurred
3886             */
3887            public Group findByT_A_Last(int type, boolean active,
3888                    OrderByComparator orderByComparator)
3889                    throws NoSuchGroupException, SystemException {
3890                    Group group = fetchByT_A_Last(type, active, orderByComparator);
3891    
3892                    if (group != null) {
3893                            return group;
3894                    }
3895    
3896                    StringBundler msg = new StringBundler(6);
3897    
3898                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3899    
3900                    msg.append("type=");
3901                    msg.append(type);
3902    
3903                    msg.append(", active=");
3904                    msg.append(active);
3905    
3906                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3907    
3908                    throw new NoSuchGroupException(msg.toString());
3909            }
3910    
3911            /**
3912             * Returns the last group in the ordered set where type = &#63; and active = &#63;.
3913             *
3914             * @param type the type
3915             * @param active the active
3916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3917             * @return the last matching group, or <code>null</code> if a matching group could not be found
3918             * @throws SystemException if a system exception occurred
3919             */
3920            public Group fetchByT_A_Last(int type, boolean active,
3921                    OrderByComparator orderByComparator) throws SystemException {
3922                    int count = countByT_A(type, active);
3923    
3924                    List<Group> list = findByT_A(type, active, count - 1, count,
3925                                    orderByComparator);
3926    
3927                    if (!list.isEmpty()) {
3928                            return list.get(0);
3929                    }
3930    
3931                    return null;
3932            }
3933    
3934            /**
3935             * Returns the groups before and after the current group in the ordered set where type = &#63; and active = &#63;.
3936             *
3937             * @param groupId the primary key of the current group
3938             * @param type the type
3939             * @param active the active
3940             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3941             * @return the previous, current, and next group
3942             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
3943             * @throws SystemException if a system exception occurred
3944             */
3945            public Group[] findByT_A_PrevAndNext(long groupId, int type,
3946                    boolean active, OrderByComparator orderByComparator)
3947                    throws NoSuchGroupException, SystemException {
3948                    Group group = findByPrimaryKey(groupId);
3949    
3950                    Session session = null;
3951    
3952                    try {
3953                            session = openSession();
3954    
3955                            Group[] array = new GroupImpl[3];
3956    
3957                            array[0] = getByT_A_PrevAndNext(session, group, type, active,
3958                                            orderByComparator, true);
3959    
3960                            array[1] = group;
3961    
3962                            array[2] = getByT_A_PrevAndNext(session, group, type, active,
3963                                            orderByComparator, false);
3964    
3965                            return array;
3966                    }
3967                    catch (Exception e) {
3968                            throw processException(e);
3969                    }
3970                    finally {
3971                            closeSession(session);
3972                    }
3973            }
3974    
3975            protected Group getByT_A_PrevAndNext(Session session, Group group,
3976                    int type, boolean active, OrderByComparator orderByComparator,
3977                    boolean previous) {
3978                    StringBundler query = null;
3979    
3980                    if (orderByComparator != null) {
3981                            query = new StringBundler(6 +
3982                                            (orderByComparator.getOrderByFields().length * 6));
3983                    }
3984                    else {
3985                            query = new StringBundler(3);
3986                    }
3987    
3988                    query.append(_SQL_SELECT_GROUP__WHERE);
3989    
3990                    query.append(_FINDER_COLUMN_T_A_TYPE_2);
3991    
3992                    query.append(_FINDER_COLUMN_T_A_ACTIVE_2);
3993    
3994                    if (orderByComparator != null) {
3995                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3996    
3997                            if (orderByConditionFields.length > 0) {
3998                                    query.append(WHERE_AND);
3999                            }
4000    
4001                            for (int i = 0; i < orderByConditionFields.length; i++) {
4002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4003                                    query.append(orderByConditionFields[i]);
4004    
4005                                    if ((i + 1) < orderByConditionFields.length) {
4006                                            if (orderByComparator.isAscending() ^ previous) {
4007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4008                                            }
4009                                            else {
4010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4011                                            }
4012                                    }
4013                                    else {
4014                                            if (orderByComparator.isAscending() ^ previous) {
4015                                                    query.append(WHERE_GREATER_THAN);
4016                                            }
4017                                            else {
4018                                                    query.append(WHERE_LESSER_THAN);
4019                                            }
4020                                    }
4021                            }
4022    
4023                            query.append(ORDER_BY_CLAUSE);
4024    
4025                            String[] orderByFields = orderByComparator.getOrderByFields();
4026    
4027                            for (int i = 0; i < orderByFields.length; i++) {
4028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4029                                    query.append(orderByFields[i]);
4030    
4031                                    if ((i + 1) < orderByFields.length) {
4032                                            if (orderByComparator.isAscending() ^ previous) {
4033                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4034                                            }
4035                                            else {
4036                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4037                                            }
4038                                    }
4039                                    else {
4040                                            if (orderByComparator.isAscending() ^ previous) {
4041                                                    query.append(ORDER_BY_ASC);
4042                                            }
4043                                            else {
4044                                                    query.append(ORDER_BY_DESC);
4045                                            }
4046                                    }
4047                            }
4048                    }
4049                    else {
4050                            query.append(GroupModelImpl.ORDER_BY_JPQL);
4051                    }
4052    
4053                    String sql = query.toString();
4054    
4055                    Query q = session.createQuery(sql);
4056    
4057                    q.setFirstResult(0);
4058                    q.setMaxResults(2);
4059    
4060                    QueryPos qPos = QueryPos.getInstance(q);
4061    
4062                    qPos.add(type);
4063    
4064                    qPos.add(active);
4065    
4066                    if (orderByComparator != null) {
4067                            Object[] values = orderByComparator.getOrderByConditionValues(group);
4068    
4069                            for (Object value : values) {
4070                                    qPos.add(value);
4071                            }
4072                    }
4073    
4074                    List<Group> list = q.list();
4075    
4076                    if (list.size() == 2) {
4077                            return list.get(1);
4078                    }
4079                    else {
4080                            return null;
4081                    }
4082            }
4083    
4084            /**
4085             * Removes all the groups where type = &#63; and active = &#63; from the database.
4086             *
4087             * @param type the type
4088             * @param active the active
4089             * @throws SystemException if a system exception occurred
4090             */
4091            public void removeByT_A(int type, boolean active) throws SystemException {
4092                    for (Group group : findByT_A(type, active, QueryUtil.ALL_POS,
4093                                    QueryUtil.ALL_POS, null)) {
4094                            remove(group);
4095                    }
4096            }
4097    
4098            /**
4099             * Returns the number of groups where type = &#63; and active = &#63;.
4100             *
4101             * @param type the type
4102             * @param active the active
4103             * @return the number of matching groups
4104             * @throws SystemException if a system exception occurred
4105             */
4106            public int countByT_A(int type, boolean active) throws SystemException {
4107                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
4108    
4109                    Object[] finderArgs = new Object[] { type, active };
4110    
4111                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4112                                    this);
4113    
4114                    if (count == null) {
4115                            StringBundler query = new StringBundler(3);
4116    
4117                            query.append(_SQL_COUNT_GROUP__WHERE);
4118    
4119                            query.append(_FINDER_COLUMN_T_A_TYPE_2);
4120    
4121                            query.append(_FINDER_COLUMN_T_A_ACTIVE_2);
4122    
4123                            String sql = query.toString();
4124    
4125                            Session session = null;
4126    
4127                            try {
4128                                    session = openSession();
4129    
4130                                    Query q = session.createQuery(sql);
4131    
4132                                    QueryPos qPos = QueryPos.getInstance(q);
4133    
4134                                    qPos.add(type);
4135    
4136                                    qPos.add(active);
4137    
4138                                    count = (Long)q.uniqueResult();
4139    
4140                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4141                            }
4142                            catch (Exception e) {
4143                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4144    
4145                                    throw processException(e);
4146                            }
4147                            finally {
4148                                    closeSession(session);
4149                            }
4150                    }
4151    
4152                    return count.intValue();
4153            }
4154    
4155            private static final String _FINDER_COLUMN_T_A_TYPE_2 = "group_.type = ? AND ";
4156            private static final String _FINDER_COLUMN_T_A_ACTIVE_2 = "group_.active = ?";
4157            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4158                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4159                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
4160                            new String[] {
4161                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4162                            },
4163                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
4164                            GroupModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4165                            GroupModelImpl.CLASSPK_COLUMN_BITMASK);
4166            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4167                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
4168                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
4169                            new String[] {
4170                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4171                            });
4172    
4173            /**
4174             * Returns the group where companyId = &#63; and classNameId = &#63; and classPK = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
4175             *
4176             * @param companyId the company ID
4177             * @param classNameId the class name ID
4178             * @param classPK the class p k
4179             * @return the matching group
4180             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
4181             * @throws SystemException if a system exception occurred
4182             */
4183            public Group findByC_C_C(long companyId, long classNameId, long classPK)
4184                    throws NoSuchGroupException, SystemException {
4185                    Group group = fetchByC_C_C(companyId, classNameId, classPK);
4186    
4187                    if (group == null) {
4188                            StringBundler msg = new StringBundler(8);
4189    
4190                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4191    
4192                            msg.append("companyId=");
4193                            msg.append(companyId);
4194    
4195                            msg.append(", classNameId=");
4196                            msg.append(classNameId);
4197    
4198                            msg.append(", classPK=");
4199                            msg.append(classPK);
4200    
4201                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4202    
4203                            if (_log.isWarnEnabled()) {
4204                                    _log.warn(msg.toString());
4205                            }
4206    
4207                            throw new NoSuchGroupException(msg.toString());
4208                    }
4209    
4210                    return group;
4211            }
4212    
4213            /**
4214             * Returns the group where companyId = &#63; and classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
4215             *
4216             * @param companyId the company ID
4217             * @param classNameId the class name ID
4218             * @param classPK the class p k
4219             * @return the matching group, or <code>null</code> if a matching group could not be found
4220             * @throws SystemException if a system exception occurred
4221             */
4222            public Group fetchByC_C_C(long companyId, long classNameId, long classPK)
4223                    throws SystemException {
4224                    return fetchByC_C_C(companyId, classNameId, classPK, true);
4225            }
4226    
4227            /**
4228             * Returns the group where companyId = &#63; and classNameId = &#63; and classPK = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
4229             *
4230             * @param companyId the company ID
4231             * @param classNameId the class name ID
4232             * @param classPK the class p k
4233             * @param retrieveFromCache whether to use the finder cache
4234             * @return the matching group, or <code>null</code> if a matching group could not be found
4235             * @throws SystemException if a system exception occurred
4236             */
4237            public Group fetchByC_C_C(long companyId, long classNameId, long classPK,
4238                    boolean retrieveFromCache) throws SystemException {
4239                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
4240    
4241                    Object result = null;
4242    
4243                    if (retrieveFromCache) {
4244                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
4245                                            finderArgs, this);
4246                    }
4247    
4248                    if (result instanceof Group) {
4249                            Group group = (Group)result;
4250    
4251                            if ((companyId != group.getCompanyId()) ||
4252                                            (classNameId != group.getClassNameId()) ||
4253                                            (classPK != group.getClassPK())) {
4254                                    result = null;
4255                            }
4256                    }
4257    
4258                    if (result == null) {
4259                            StringBundler query = new StringBundler(5);
4260    
4261                            query.append(_SQL_SELECT_GROUP__WHERE);
4262    
4263                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
4264    
4265                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
4266    
4267                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
4268    
4269                            String sql = query.toString();
4270    
4271                            Session session = null;
4272    
4273                            try {
4274                                    session = openSession();
4275    
4276                                    Query q = session.createQuery(sql);
4277    
4278                                    QueryPos qPos = QueryPos.getInstance(q);
4279    
4280                                    qPos.add(companyId);
4281    
4282                                    qPos.add(classNameId);
4283    
4284                                    qPos.add(classPK);
4285    
4286                                    List<Group> list = q.list();
4287    
4288                                    if (list.isEmpty()) {
4289                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
4290                                                    finderArgs, list);
4291                                    }
4292                                    else {
4293                                            Group group = list.get(0);
4294    
4295                                            result = group;
4296    
4297                                            cacheResult(group);
4298    
4299                                            if ((group.getCompanyId() != companyId) ||
4300                                                            (group.getClassNameId() != classNameId) ||
4301                                                            (group.getClassPK() != classPK)) {
4302                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
4303                                                            finderArgs, group);
4304                                            }
4305                                    }
4306                            }
4307                            catch (Exception e) {
4308                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
4309                                            finderArgs);
4310    
4311                                    throw processException(e);
4312                            }
4313                            finally {
4314                                    closeSession(session);
4315                            }
4316                    }
4317    
4318                    if (result instanceof List<?>) {
4319                            return null;
4320                    }
4321                    else {
4322                            return (Group)result;
4323                    }
4324            }
4325    
4326            /**
4327             * Removes the group where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
4328             *
4329             * @param companyId the company ID
4330             * @param classNameId the class name ID
4331             * @param classPK the class p k
4332             * @return the group that was removed
4333             * @throws SystemException if a system exception occurred
4334             */
4335            public Group removeByC_C_C(long companyId, long classNameId, long classPK)
4336                    throws NoSuchGroupException, SystemException {
4337                    Group group = findByC_C_C(companyId, classNameId, classPK);
4338    
4339                    return remove(group);
4340            }
4341    
4342            /**
4343             * Returns the number of groups where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
4344             *
4345             * @param companyId the company ID
4346             * @param classNameId the class name ID
4347             * @param classPK the class p k
4348             * @return the number of matching groups
4349             * @throws SystemException if a system exception occurred
4350             */
4351            public int countByC_C_C(long companyId, long classNameId, long classPK)
4352                    throws SystemException {
4353                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
4354    
4355                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
4356    
4357                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4358                                    this);
4359    
4360                    if (count == null) {
4361                            StringBundler query = new StringBundler(4);
4362    
4363                            query.append(_SQL_COUNT_GROUP__WHERE);
4364    
4365                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
4366    
4367                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
4368    
4369                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
4370    
4371                            String sql = query.toString();
4372    
4373                            Session session = null;
4374    
4375                            try {
4376                                    session = openSession();
4377    
4378                                    Query q = session.createQuery(sql);
4379    
4380                                    QueryPos qPos = QueryPos.getInstance(q);
4381    
4382                                    qPos.add(companyId);
4383    
4384                                    qPos.add(classNameId);
4385    
4386                                    qPos.add(classPK);
4387    
4388                                    count = (Long)q.uniqueResult();
4389    
4390                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4391                            }
4392                            catch (Exception e) {
4393                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4394    
4395                                    throw processException(e);
4396                            }
4397                            finally {
4398                                    closeSession(session);
4399                            }
4400                    }
4401    
4402                    return count.intValue();
4403            }
4404    
4405            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "group_.companyId = ? AND ";
4406            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "group_.classNameId = ? AND ";
4407            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "group_.classPK = ?";
4408            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4409                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4410                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_P",
4411                            new String[] {
4412                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
4413                                    
4414                            Integer.class.getName(), Integer.class.getName(),
4415                                    OrderByComparator.class.getName()
4416                            });
4417            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4418                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4419                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_P",
4420                            new String[] {
4421                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4422                            },
4423                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
4424                            GroupModelImpl.CLASSNAMEID_COLUMN_BITMASK |
4425                            GroupModelImpl.PARENTGROUPID_COLUMN_BITMASK |
4426                            GroupModelImpl.NAME_COLUMN_BITMASK);
4427            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4428                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
4429                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_P",
4430                            new String[] {
4431                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
4432                            });
4433    
4434            /**
4435             * Returns all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4436             *
4437             * @param companyId the company ID
4438             * @param classNameId the class name ID
4439             * @param parentGroupId the parent group ID
4440             * @return the matching groups
4441             * @throws SystemException if a system exception occurred
4442             */
4443            public List<Group> findByC_C_P(long companyId, long classNameId,
4444                    long parentGroupId) throws SystemException {
4445                    return findByC_C_P(companyId, classNameId, parentGroupId,
4446                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4447            }
4448    
4449            /**
4450             * Returns a range of all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4451             *
4452             * <p>
4453             * 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.GroupModelImpl}. 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.
4454             * </p>
4455             *
4456             * @param companyId the company ID
4457             * @param classNameId the class name ID
4458             * @param parentGroupId the parent group ID
4459             * @param start the lower bound of the range of groups
4460             * @param end the upper bound of the range of groups (not inclusive)
4461             * @return the range of matching groups
4462             * @throws SystemException if a system exception occurred
4463             */
4464            public List<Group> findByC_C_P(long companyId, long classNameId,
4465                    long parentGroupId, int start, int end) throws SystemException {
4466                    return findByC_C_P(companyId, classNameId, parentGroupId, start, end,
4467                            null);
4468            }
4469    
4470            /**
4471             * Returns an ordered range of all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4472             *
4473             * <p>
4474             * 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.GroupModelImpl}. 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.
4475             * </p>
4476             *
4477             * @param companyId the company ID
4478             * @param classNameId the class name ID
4479             * @param parentGroupId the parent group ID
4480             * @param start the lower bound of the range of groups
4481             * @param end the upper bound of the range of groups (not inclusive)
4482             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4483             * @return the ordered range of matching groups
4484             * @throws SystemException if a system exception occurred
4485             */
4486            public List<Group> findByC_C_P(long companyId, long classNameId,
4487                    long parentGroupId, int start, int end,
4488                    OrderByComparator orderByComparator) throws SystemException {
4489                    boolean pagination = true;
4490                    FinderPath finderPath = null;
4491                    Object[] finderArgs = null;
4492    
4493                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4494                                    (orderByComparator == null)) {
4495                            pagination = false;
4496                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P;
4497                            finderArgs = new Object[] { companyId, classNameId, parentGroupId };
4498                    }
4499                    else {
4500                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_P;
4501                            finderArgs = new Object[] {
4502                                            companyId, classNameId, parentGroupId,
4503                                            
4504                                            start, end, orderByComparator
4505                                    };
4506                    }
4507    
4508                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
4509                                    finderArgs, this);
4510    
4511                    if ((list != null) && !list.isEmpty()) {
4512                            for (Group group : list) {
4513                                    if ((companyId != group.getCompanyId()) ||
4514                                                    (classNameId != group.getClassNameId()) ||
4515                                                    (parentGroupId != group.getParentGroupId())) {
4516                                            list = null;
4517    
4518                                            break;
4519                                    }
4520                            }
4521                    }
4522    
4523                    if (list == null) {
4524                            StringBundler query = null;
4525    
4526                            if (orderByComparator != null) {
4527                                    query = new StringBundler(5 +
4528                                                    (orderByComparator.getOrderByFields().length * 3));
4529                            }
4530                            else {
4531                                    query = new StringBundler(5);
4532                            }
4533    
4534                            query.append(_SQL_SELECT_GROUP__WHERE);
4535    
4536                            query.append(_FINDER_COLUMN_C_C_P_COMPANYID_2);
4537    
4538                            query.append(_FINDER_COLUMN_C_C_P_CLASSNAMEID_2);
4539    
4540                            query.append(_FINDER_COLUMN_C_C_P_PARENTGROUPID_2);
4541    
4542                            if (orderByComparator != null) {
4543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4544                                            orderByComparator);
4545                            }
4546                            else
4547                             if (pagination) {
4548                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
4549                            }
4550    
4551                            String sql = query.toString();
4552    
4553                            Session session = null;
4554    
4555                            try {
4556                                    session = openSession();
4557    
4558                                    Query q = session.createQuery(sql);
4559    
4560                                    QueryPos qPos = QueryPos.getInstance(q);
4561    
4562                                    qPos.add(companyId);
4563    
4564                                    qPos.add(classNameId);
4565    
4566                                    qPos.add(parentGroupId);
4567    
4568                                    if (!pagination) {
4569                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
4570                                                            end, false);
4571    
4572                                            Collections.sort(list);
4573    
4574                                            list = new UnmodifiableList<Group>(list);
4575                                    }
4576                                    else {
4577                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
4578                                                            end);
4579                                    }
4580    
4581                                    cacheResult(list);
4582    
4583                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4584                            }
4585                            catch (Exception e) {
4586                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4587    
4588                                    throw processException(e);
4589                            }
4590                            finally {
4591                                    closeSession(session);
4592                            }
4593                    }
4594    
4595                    return list;
4596            }
4597    
4598            /**
4599             * Returns the first group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4600             *
4601             * @param companyId the company ID
4602             * @param classNameId the class name ID
4603             * @param parentGroupId the parent group ID
4604             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4605             * @return the first matching group
4606             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
4607             * @throws SystemException if a system exception occurred
4608             */
4609            public Group findByC_C_P_First(long companyId, long classNameId,
4610                    long parentGroupId, OrderByComparator orderByComparator)
4611                    throws NoSuchGroupException, SystemException {
4612                    Group group = fetchByC_C_P_First(companyId, classNameId, parentGroupId,
4613                                    orderByComparator);
4614    
4615                    if (group != null) {
4616                            return group;
4617                    }
4618    
4619                    StringBundler msg = new StringBundler(8);
4620    
4621                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4622    
4623                    msg.append("companyId=");
4624                    msg.append(companyId);
4625    
4626                    msg.append(", classNameId=");
4627                    msg.append(classNameId);
4628    
4629                    msg.append(", parentGroupId=");
4630                    msg.append(parentGroupId);
4631    
4632                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4633    
4634                    throw new NoSuchGroupException(msg.toString());
4635            }
4636    
4637            /**
4638             * Returns the first group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4639             *
4640             * @param companyId the company ID
4641             * @param classNameId the class name ID
4642             * @param parentGroupId the parent group ID
4643             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4644             * @return the first matching group, or <code>null</code> if a matching group could not be found
4645             * @throws SystemException if a system exception occurred
4646             */
4647            public Group fetchByC_C_P_First(long companyId, long classNameId,
4648                    long parentGroupId, OrderByComparator orderByComparator)
4649                    throws SystemException {
4650                    List<Group> list = findByC_C_P(companyId, classNameId, parentGroupId,
4651                                    0, 1, orderByComparator);
4652    
4653                    if (!list.isEmpty()) {
4654                            return list.get(0);
4655                    }
4656    
4657                    return null;
4658            }
4659    
4660            /**
4661             * Returns the last group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4662             *
4663             * @param companyId the company ID
4664             * @param classNameId the class name ID
4665             * @param parentGroupId the parent group ID
4666             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4667             * @return the last matching group
4668             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
4669             * @throws SystemException if a system exception occurred
4670             */
4671            public Group findByC_C_P_Last(long companyId, long classNameId,
4672                    long parentGroupId, OrderByComparator orderByComparator)
4673                    throws NoSuchGroupException, SystemException {
4674                    Group group = fetchByC_C_P_Last(companyId, classNameId, parentGroupId,
4675                                    orderByComparator);
4676    
4677                    if (group != null) {
4678                            return group;
4679                    }
4680    
4681                    StringBundler msg = new StringBundler(8);
4682    
4683                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4684    
4685                    msg.append("companyId=");
4686                    msg.append(companyId);
4687    
4688                    msg.append(", classNameId=");
4689                    msg.append(classNameId);
4690    
4691                    msg.append(", parentGroupId=");
4692                    msg.append(parentGroupId);
4693    
4694                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4695    
4696                    throw new NoSuchGroupException(msg.toString());
4697            }
4698    
4699            /**
4700             * Returns the last group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4701             *
4702             * @param companyId the company ID
4703             * @param classNameId the class name ID
4704             * @param parentGroupId the parent group ID
4705             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4706             * @return the last matching group, or <code>null</code> if a matching group could not be found
4707             * @throws SystemException if a system exception occurred
4708             */
4709            public Group fetchByC_C_P_Last(long companyId, long classNameId,
4710                    long parentGroupId, OrderByComparator orderByComparator)
4711                    throws SystemException {
4712                    int count = countByC_C_P(companyId, classNameId, parentGroupId);
4713    
4714                    List<Group> list = findByC_C_P(companyId, classNameId, parentGroupId,
4715                                    count - 1, count, orderByComparator);
4716    
4717                    if (!list.isEmpty()) {
4718                            return list.get(0);
4719                    }
4720    
4721                    return null;
4722            }
4723    
4724            /**
4725             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4726             *
4727             * @param groupId the primary key of the current group
4728             * @param companyId the company ID
4729             * @param classNameId the class name ID
4730             * @param parentGroupId the parent group ID
4731             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4732             * @return the previous, current, and next group
4733             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
4734             * @throws SystemException if a system exception occurred
4735             */
4736            public Group[] findByC_C_P_PrevAndNext(long groupId, long companyId,
4737                    long classNameId, long parentGroupId,
4738                    OrderByComparator orderByComparator)
4739                    throws NoSuchGroupException, SystemException {
4740                    Group group = findByPrimaryKey(groupId);
4741    
4742                    Session session = null;
4743    
4744                    try {
4745                            session = openSession();
4746    
4747                            Group[] array = new GroupImpl[3];
4748    
4749                            array[0] = getByC_C_P_PrevAndNext(session, group, companyId,
4750                                            classNameId, parentGroupId, orderByComparator, true);
4751    
4752                            array[1] = group;
4753    
4754                            array[2] = getByC_C_P_PrevAndNext(session, group, companyId,
4755                                            classNameId, parentGroupId, orderByComparator, false);
4756    
4757                            return array;
4758                    }
4759                    catch (Exception e) {
4760                            throw processException(e);
4761                    }
4762                    finally {
4763                            closeSession(session);
4764                    }
4765            }
4766    
4767            protected Group getByC_C_P_PrevAndNext(Session session, Group group,
4768                    long companyId, long classNameId, long parentGroupId,
4769                    OrderByComparator orderByComparator, boolean previous) {
4770                    StringBundler query = null;
4771    
4772                    if (orderByComparator != null) {
4773                            query = new StringBundler(6 +
4774                                            (orderByComparator.getOrderByFields().length * 6));
4775                    }
4776                    else {
4777                            query = new StringBundler(3);
4778                    }
4779    
4780                    query.append(_SQL_SELECT_GROUP__WHERE);
4781    
4782                    query.append(_FINDER_COLUMN_C_C_P_COMPANYID_2);
4783    
4784                    query.append(_FINDER_COLUMN_C_C_P_CLASSNAMEID_2);
4785    
4786                    query.append(_FINDER_COLUMN_C_C_P_PARENTGROUPID_2);
4787    
4788                    if (orderByComparator != null) {
4789                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4790    
4791                            if (orderByConditionFields.length > 0) {
4792                                    query.append(WHERE_AND);
4793                            }
4794    
4795                            for (int i = 0; i < orderByConditionFields.length; i++) {
4796                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4797                                    query.append(orderByConditionFields[i]);
4798    
4799                                    if ((i + 1) < orderByConditionFields.length) {
4800                                            if (orderByComparator.isAscending() ^ previous) {
4801                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4802                                            }
4803                                            else {
4804                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4805                                            }
4806                                    }
4807                                    else {
4808                                            if (orderByComparator.isAscending() ^ previous) {
4809                                                    query.append(WHERE_GREATER_THAN);
4810                                            }
4811                                            else {
4812                                                    query.append(WHERE_LESSER_THAN);
4813                                            }
4814                                    }
4815                            }
4816    
4817                            query.append(ORDER_BY_CLAUSE);
4818    
4819                            String[] orderByFields = orderByComparator.getOrderByFields();
4820    
4821                            for (int i = 0; i < orderByFields.length; i++) {
4822                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4823                                    query.append(orderByFields[i]);
4824    
4825                                    if ((i + 1) < orderByFields.length) {
4826                                            if (orderByComparator.isAscending() ^ previous) {
4827                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4828                                            }
4829                                            else {
4830                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4831                                            }
4832                                    }
4833                                    else {
4834                                            if (orderByComparator.isAscending() ^ previous) {
4835                                                    query.append(ORDER_BY_ASC);
4836                                            }
4837                                            else {
4838                                                    query.append(ORDER_BY_DESC);
4839                                            }
4840                                    }
4841                            }
4842                    }
4843                    else {
4844                            query.append(GroupModelImpl.ORDER_BY_JPQL);
4845                    }
4846    
4847                    String sql = query.toString();
4848    
4849                    Query q = session.createQuery(sql);
4850    
4851                    q.setFirstResult(0);
4852                    q.setMaxResults(2);
4853    
4854                    QueryPos qPos = QueryPos.getInstance(q);
4855    
4856                    qPos.add(companyId);
4857    
4858                    qPos.add(classNameId);
4859    
4860                    qPos.add(parentGroupId);
4861    
4862                    if (orderByComparator != null) {
4863                            Object[] values = orderByComparator.getOrderByConditionValues(group);
4864    
4865                            for (Object value : values) {
4866                                    qPos.add(value);
4867                            }
4868                    }
4869    
4870                    List<Group> list = q.list();
4871    
4872                    if (list.size() == 2) {
4873                            return list.get(1);
4874                    }
4875                    else {
4876                            return null;
4877                    }
4878            }
4879    
4880            /**
4881             * Removes all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63; from the database.
4882             *
4883             * @param companyId the company ID
4884             * @param classNameId the class name ID
4885             * @param parentGroupId the parent group ID
4886             * @throws SystemException if a system exception occurred
4887             */
4888            public void removeByC_C_P(long companyId, long classNameId,
4889                    long parentGroupId) throws SystemException {
4890                    for (Group group : findByC_C_P(companyId, classNameId, parentGroupId,
4891                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4892                            remove(group);
4893                    }
4894            }
4895    
4896            /**
4897             * Returns the number of groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
4898             *
4899             * @param companyId the company ID
4900             * @param classNameId the class name ID
4901             * @param parentGroupId the parent group ID
4902             * @return the number of matching groups
4903             * @throws SystemException if a system exception occurred
4904             */
4905            public int countByC_C_P(long companyId, long classNameId, long parentGroupId)
4906                    throws SystemException {
4907                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_P;
4908    
4909                    Object[] finderArgs = new Object[] { companyId, classNameId, parentGroupId };
4910    
4911                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4912                                    this);
4913    
4914                    if (count == null) {
4915                            StringBundler query = new StringBundler(4);
4916    
4917                            query.append(_SQL_COUNT_GROUP__WHERE);
4918    
4919                            query.append(_FINDER_COLUMN_C_C_P_COMPANYID_2);
4920    
4921                            query.append(_FINDER_COLUMN_C_C_P_CLASSNAMEID_2);
4922    
4923                            query.append(_FINDER_COLUMN_C_C_P_PARENTGROUPID_2);
4924    
4925                            String sql = query.toString();
4926    
4927                            Session session = null;
4928    
4929                            try {
4930                                    session = openSession();
4931    
4932                                    Query q = session.createQuery(sql);
4933    
4934                                    QueryPos qPos = QueryPos.getInstance(q);
4935    
4936                                    qPos.add(companyId);
4937    
4938                                    qPos.add(classNameId);
4939    
4940                                    qPos.add(parentGroupId);
4941    
4942                                    count = (Long)q.uniqueResult();
4943    
4944                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4945                            }
4946                            catch (Exception e) {
4947                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4948    
4949                                    throw processException(e);
4950                            }
4951                            finally {
4952                                    closeSession(session);
4953                            }
4954                    }
4955    
4956                    return count.intValue();
4957            }
4958    
4959            private static final String _FINDER_COLUMN_C_C_P_COMPANYID_2 = "group_.companyId = ? AND ";
4960            private static final String _FINDER_COLUMN_C_C_P_CLASSNAMEID_2 = "group_.classNameId = ? AND ";
4961            private static final String _FINDER_COLUMN_C_C_P_PARENTGROUPID_2 = "group_.parentGroupId = ?";
4962            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4963                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4964                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P_S",
4965                            new String[] {
4966                                    Long.class.getName(), Long.class.getName(),
4967                                    Boolean.class.getName(),
4968                                    
4969                            Integer.class.getName(), Integer.class.getName(),
4970                                    OrderByComparator.class.getName()
4971                            });
4972            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4973                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4974                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P_S",
4975                            new String[] {
4976                                    Long.class.getName(), Long.class.getName(),
4977                                    Boolean.class.getName()
4978                            },
4979                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
4980                            GroupModelImpl.PARENTGROUPID_COLUMN_BITMASK |
4981                            GroupModelImpl.SITE_COLUMN_BITMASK |
4982                            GroupModelImpl.NAME_COLUMN_BITMASK);
4983            public static final FinderPath FINDER_PATH_COUNT_BY_C_P_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4984                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
4985                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P_S",
4986                            new String[] {
4987                                    Long.class.getName(), Long.class.getName(),
4988                                    Boolean.class.getName()
4989                            });
4990    
4991            /**
4992             * Returns all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
4993             *
4994             * @param companyId the company ID
4995             * @param parentGroupId the parent group ID
4996             * @param site the site
4997             * @return the matching groups
4998             * @throws SystemException if a system exception occurred
4999             */
5000            public List<Group> findByC_P_S(long companyId, long parentGroupId,
5001                    boolean site) throws SystemException {
5002                    return findByC_P_S(companyId, parentGroupId, site, QueryUtil.ALL_POS,
5003                            QueryUtil.ALL_POS, null);
5004            }
5005    
5006            /**
5007             * Returns a range of all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5008             *
5009             * <p>
5010             * 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.GroupModelImpl}. 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.
5011             * </p>
5012             *
5013             * @param companyId the company ID
5014             * @param parentGroupId the parent group ID
5015             * @param site the site
5016             * @param start the lower bound of the range of groups
5017             * @param end the upper bound of the range of groups (not inclusive)
5018             * @return the range of matching groups
5019             * @throws SystemException if a system exception occurred
5020             */
5021            public List<Group> findByC_P_S(long companyId, long parentGroupId,
5022                    boolean site, int start, int end) throws SystemException {
5023                    return findByC_P_S(companyId, parentGroupId, site, start, end, null);
5024            }
5025    
5026            /**
5027             * Returns an ordered range of all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5028             *
5029             * <p>
5030             * 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.GroupModelImpl}. 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.
5031             * </p>
5032             *
5033             * @param companyId the company ID
5034             * @param parentGroupId the parent group ID
5035             * @param site the site
5036             * @param start the lower bound of the range of groups
5037             * @param end the upper bound of the range of groups (not inclusive)
5038             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5039             * @return the ordered range of matching groups
5040             * @throws SystemException if a system exception occurred
5041             */
5042            public List<Group> findByC_P_S(long companyId, long parentGroupId,
5043                    boolean site, int start, int end, OrderByComparator orderByComparator)
5044                    throws SystemException {
5045                    boolean pagination = true;
5046                    FinderPath finderPath = null;
5047                    Object[] finderArgs = null;
5048    
5049                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5050                                    (orderByComparator == null)) {
5051                            pagination = false;
5052                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S;
5053                            finderArgs = new Object[] { companyId, parentGroupId, site };
5054                    }
5055                    else {
5056                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P_S;
5057                            finderArgs = new Object[] {
5058                                            companyId, parentGroupId, site,
5059                                            
5060                                            start, end, orderByComparator
5061                                    };
5062                    }
5063    
5064                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
5065                                    finderArgs, this);
5066    
5067                    if ((list != null) && !list.isEmpty()) {
5068                            for (Group group : list) {
5069                                    if ((companyId != group.getCompanyId()) ||
5070                                                    (parentGroupId != group.getParentGroupId()) ||
5071                                                    (site != group.getSite())) {
5072                                            list = null;
5073    
5074                                            break;
5075                                    }
5076                            }
5077                    }
5078    
5079                    if (list == null) {
5080                            StringBundler query = null;
5081    
5082                            if (orderByComparator != null) {
5083                                    query = new StringBundler(5 +
5084                                                    (orderByComparator.getOrderByFields().length * 3));
5085                            }
5086                            else {
5087                                    query = new StringBundler(5);
5088                            }
5089    
5090                            query.append(_SQL_SELECT_GROUP__WHERE);
5091    
5092                            query.append(_FINDER_COLUMN_C_P_S_COMPANYID_2);
5093    
5094                            query.append(_FINDER_COLUMN_C_P_S_PARENTGROUPID_2);
5095    
5096                            query.append(_FINDER_COLUMN_C_P_S_SITE_2);
5097    
5098                            if (orderByComparator != null) {
5099                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5100                                            orderByComparator);
5101                            }
5102                            else
5103                             if (pagination) {
5104                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
5105                            }
5106    
5107                            String sql = query.toString();
5108    
5109                            Session session = null;
5110    
5111                            try {
5112                                    session = openSession();
5113    
5114                                    Query q = session.createQuery(sql);
5115    
5116                                    QueryPos qPos = QueryPos.getInstance(q);
5117    
5118                                    qPos.add(companyId);
5119    
5120                                    qPos.add(parentGroupId);
5121    
5122                                    qPos.add(site);
5123    
5124                                    if (!pagination) {
5125                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
5126                                                            end, false);
5127    
5128                                            Collections.sort(list);
5129    
5130                                            list = new UnmodifiableList<Group>(list);
5131                                    }
5132                                    else {
5133                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
5134                                                            end);
5135                                    }
5136    
5137                                    cacheResult(list);
5138    
5139                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5140                            }
5141                            catch (Exception e) {
5142                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5143    
5144                                    throw processException(e);
5145                            }
5146                            finally {
5147                                    closeSession(session);
5148                            }
5149                    }
5150    
5151                    return list;
5152            }
5153    
5154            /**
5155             * Returns the first group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5156             *
5157             * @param companyId the company ID
5158             * @param parentGroupId the parent group ID
5159             * @param site the site
5160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5161             * @return the first matching group
5162             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5163             * @throws SystemException if a system exception occurred
5164             */
5165            public Group findByC_P_S_First(long companyId, long parentGroupId,
5166                    boolean site, OrderByComparator orderByComparator)
5167                    throws NoSuchGroupException, SystemException {
5168                    Group group = fetchByC_P_S_First(companyId, parentGroupId, site,
5169                                    orderByComparator);
5170    
5171                    if (group != null) {
5172                            return group;
5173                    }
5174    
5175                    StringBundler msg = new StringBundler(8);
5176    
5177                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5178    
5179                    msg.append("companyId=");
5180                    msg.append(companyId);
5181    
5182                    msg.append(", parentGroupId=");
5183                    msg.append(parentGroupId);
5184    
5185                    msg.append(", site=");
5186                    msg.append(site);
5187    
5188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5189    
5190                    throw new NoSuchGroupException(msg.toString());
5191            }
5192    
5193            /**
5194             * Returns the first group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5195             *
5196             * @param companyId the company ID
5197             * @param parentGroupId the parent group ID
5198             * @param site the site
5199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5200             * @return the first matching group, or <code>null</code> if a matching group could not be found
5201             * @throws SystemException if a system exception occurred
5202             */
5203            public Group fetchByC_P_S_First(long companyId, long parentGroupId,
5204                    boolean site, OrderByComparator orderByComparator)
5205                    throws SystemException {
5206                    List<Group> list = findByC_P_S(companyId, parentGroupId, site, 0, 1,
5207                                    orderByComparator);
5208    
5209                    if (!list.isEmpty()) {
5210                            return list.get(0);
5211                    }
5212    
5213                    return null;
5214            }
5215    
5216            /**
5217             * Returns the last group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5218             *
5219             * @param companyId the company ID
5220             * @param parentGroupId the parent group ID
5221             * @param site the site
5222             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5223             * @return the last matching group
5224             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5225             * @throws SystemException if a system exception occurred
5226             */
5227            public Group findByC_P_S_Last(long companyId, long parentGroupId,
5228                    boolean site, OrderByComparator orderByComparator)
5229                    throws NoSuchGroupException, SystemException {
5230                    Group group = fetchByC_P_S_Last(companyId, parentGroupId, site,
5231                                    orderByComparator);
5232    
5233                    if (group != null) {
5234                            return group;
5235                    }
5236    
5237                    StringBundler msg = new StringBundler(8);
5238    
5239                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5240    
5241                    msg.append("companyId=");
5242                    msg.append(companyId);
5243    
5244                    msg.append(", parentGroupId=");
5245                    msg.append(parentGroupId);
5246    
5247                    msg.append(", site=");
5248                    msg.append(site);
5249    
5250                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5251    
5252                    throw new NoSuchGroupException(msg.toString());
5253            }
5254    
5255            /**
5256             * Returns the last group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5257             *
5258             * @param companyId the company ID
5259             * @param parentGroupId the parent group ID
5260             * @param site the site
5261             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5262             * @return the last matching group, or <code>null</code> if a matching group could not be found
5263             * @throws SystemException if a system exception occurred
5264             */
5265            public Group fetchByC_P_S_Last(long companyId, long parentGroupId,
5266                    boolean site, OrderByComparator orderByComparator)
5267                    throws SystemException {
5268                    int count = countByC_P_S(companyId, parentGroupId, site);
5269    
5270                    List<Group> list = findByC_P_S(companyId, parentGroupId, site,
5271                                    count - 1, count, orderByComparator);
5272    
5273                    if (!list.isEmpty()) {
5274                            return list.get(0);
5275                    }
5276    
5277                    return null;
5278            }
5279    
5280            /**
5281             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5282             *
5283             * @param groupId the primary key of the current group
5284             * @param companyId the company ID
5285             * @param parentGroupId the parent group ID
5286             * @param site the site
5287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5288             * @return the previous, current, and next group
5289             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
5290             * @throws SystemException if a system exception occurred
5291             */
5292            public Group[] findByC_P_S_PrevAndNext(long groupId, long companyId,
5293                    long parentGroupId, boolean site, OrderByComparator orderByComparator)
5294                    throws NoSuchGroupException, SystemException {
5295                    Group group = findByPrimaryKey(groupId);
5296    
5297                    Session session = null;
5298    
5299                    try {
5300                            session = openSession();
5301    
5302                            Group[] array = new GroupImpl[3];
5303    
5304                            array[0] = getByC_P_S_PrevAndNext(session, group, companyId,
5305                                            parentGroupId, site, orderByComparator, true);
5306    
5307                            array[1] = group;
5308    
5309                            array[2] = getByC_P_S_PrevAndNext(session, group, companyId,
5310                                            parentGroupId, site, orderByComparator, false);
5311    
5312                            return array;
5313                    }
5314                    catch (Exception e) {
5315                            throw processException(e);
5316                    }
5317                    finally {
5318                            closeSession(session);
5319                    }
5320            }
5321    
5322            protected Group getByC_P_S_PrevAndNext(Session session, Group group,
5323                    long companyId, long parentGroupId, boolean site,
5324                    OrderByComparator orderByComparator, boolean previous) {
5325                    StringBundler query = null;
5326    
5327                    if (orderByComparator != null) {
5328                            query = new StringBundler(6 +
5329                                            (orderByComparator.getOrderByFields().length * 6));
5330                    }
5331                    else {
5332                            query = new StringBundler(3);
5333                    }
5334    
5335                    query.append(_SQL_SELECT_GROUP__WHERE);
5336    
5337                    query.append(_FINDER_COLUMN_C_P_S_COMPANYID_2);
5338    
5339                    query.append(_FINDER_COLUMN_C_P_S_PARENTGROUPID_2);
5340    
5341                    query.append(_FINDER_COLUMN_C_P_S_SITE_2);
5342    
5343                    if (orderByComparator != null) {
5344                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5345    
5346                            if (orderByConditionFields.length > 0) {
5347                                    query.append(WHERE_AND);
5348                            }
5349    
5350                            for (int i = 0; i < orderByConditionFields.length; i++) {
5351                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5352                                    query.append(orderByConditionFields[i]);
5353    
5354                                    if ((i + 1) < orderByConditionFields.length) {
5355                                            if (orderByComparator.isAscending() ^ previous) {
5356                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5357                                            }
5358                                            else {
5359                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5360                                            }
5361                                    }
5362                                    else {
5363                                            if (orderByComparator.isAscending() ^ previous) {
5364                                                    query.append(WHERE_GREATER_THAN);
5365                                            }
5366                                            else {
5367                                                    query.append(WHERE_LESSER_THAN);
5368                                            }
5369                                    }
5370                            }
5371    
5372                            query.append(ORDER_BY_CLAUSE);
5373    
5374                            String[] orderByFields = orderByComparator.getOrderByFields();
5375    
5376                            for (int i = 0; i < orderByFields.length; i++) {
5377                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5378                                    query.append(orderByFields[i]);
5379    
5380                                    if ((i + 1) < orderByFields.length) {
5381                                            if (orderByComparator.isAscending() ^ previous) {
5382                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5383                                            }
5384                                            else {
5385                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5386                                            }
5387                                    }
5388                                    else {
5389                                            if (orderByComparator.isAscending() ^ previous) {
5390                                                    query.append(ORDER_BY_ASC);
5391                                            }
5392                                            else {
5393                                                    query.append(ORDER_BY_DESC);
5394                                            }
5395                                    }
5396                            }
5397                    }
5398                    else {
5399                            query.append(GroupModelImpl.ORDER_BY_JPQL);
5400                    }
5401    
5402                    String sql = query.toString();
5403    
5404                    Query q = session.createQuery(sql);
5405    
5406                    q.setFirstResult(0);
5407                    q.setMaxResults(2);
5408    
5409                    QueryPos qPos = QueryPos.getInstance(q);
5410    
5411                    qPos.add(companyId);
5412    
5413                    qPos.add(parentGroupId);
5414    
5415                    qPos.add(site);
5416    
5417                    if (orderByComparator != null) {
5418                            Object[] values = orderByComparator.getOrderByConditionValues(group);
5419    
5420                            for (Object value : values) {
5421                                    qPos.add(value);
5422                            }
5423                    }
5424    
5425                    List<Group> list = q.list();
5426    
5427                    if (list.size() == 2) {
5428                            return list.get(1);
5429                    }
5430                    else {
5431                            return null;
5432                    }
5433            }
5434    
5435            /**
5436             * Removes all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63; from the database.
5437             *
5438             * @param companyId the company ID
5439             * @param parentGroupId the parent group ID
5440             * @param site the site
5441             * @throws SystemException if a system exception occurred
5442             */
5443            public void removeByC_P_S(long companyId, long parentGroupId, boolean site)
5444                    throws SystemException {
5445                    for (Group group : findByC_P_S(companyId, parentGroupId, site,
5446                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5447                            remove(group);
5448                    }
5449            }
5450    
5451            /**
5452             * Returns the number of groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
5453             *
5454             * @param companyId the company ID
5455             * @param parentGroupId the parent group ID
5456             * @param site the site
5457             * @return the number of matching groups
5458             * @throws SystemException if a system exception occurred
5459             */
5460            public int countByC_P_S(long companyId, long parentGroupId, boolean site)
5461                    throws SystemException {
5462                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P_S;
5463    
5464                    Object[] finderArgs = new Object[] { companyId, parentGroupId, site };
5465    
5466                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5467                                    this);
5468    
5469                    if (count == null) {
5470                            StringBundler query = new StringBundler(4);
5471    
5472                            query.append(_SQL_COUNT_GROUP__WHERE);
5473    
5474                            query.append(_FINDER_COLUMN_C_P_S_COMPANYID_2);
5475    
5476                            query.append(_FINDER_COLUMN_C_P_S_PARENTGROUPID_2);
5477    
5478                            query.append(_FINDER_COLUMN_C_P_S_SITE_2);
5479    
5480                            String sql = query.toString();
5481    
5482                            Session session = null;
5483    
5484                            try {
5485                                    session = openSession();
5486    
5487                                    Query q = session.createQuery(sql);
5488    
5489                                    QueryPos qPos = QueryPos.getInstance(q);
5490    
5491                                    qPos.add(companyId);
5492    
5493                                    qPos.add(parentGroupId);
5494    
5495                                    qPos.add(site);
5496    
5497                                    count = (Long)q.uniqueResult();
5498    
5499                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5500                            }
5501                            catch (Exception e) {
5502                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5503    
5504                                    throw processException(e);
5505                            }
5506                            finally {
5507                                    closeSession(session);
5508                            }
5509                    }
5510    
5511                    return count.intValue();
5512            }
5513    
5514            private static final String _FINDER_COLUMN_C_P_S_COMPANYID_2 = "group_.companyId = ? AND ";
5515            private static final String _FINDER_COLUMN_C_P_S_PARENTGROUPID_2 = "group_.parentGroupId = ? AND ";
5516            private static final String _FINDER_COLUMN_C_P_S_SITE_2 = "group_.site = ?";
5517            public static final FinderPath FINDER_PATH_FETCH_BY_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5518                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
5519                            FINDER_CLASS_NAME_ENTITY, "fetchByC_L_N",
5520                            new String[] {
5521                                    Long.class.getName(), Long.class.getName(),
5522                                    String.class.getName()
5523                            },
5524                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
5525                            GroupModelImpl.LIVEGROUPID_COLUMN_BITMASK |
5526                            GroupModelImpl.NAME_COLUMN_BITMASK);
5527            public static final FinderPath FINDER_PATH_COUNT_BY_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5528                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
5529                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_L_N",
5530                            new String[] {
5531                                    Long.class.getName(), Long.class.getName(),
5532                                    String.class.getName()
5533                            });
5534    
5535            /**
5536             * Returns the group where companyId = &#63; and liveGroupId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
5537             *
5538             * @param companyId the company ID
5539             * @param liveGroupId the live group ID
5540             * @param name the name
5541             * @return the matching group
5542             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5543             * @throws SystemException if a system exception occurred
5544             */
5545            public Group findByC_L_N(long companyId, long liveGroupId, String name)
5546                    throws NoSuchGroupException, SystemException {
5547                    Group group = fetchByC_L_N(companyId, liveGroupId, name);
5548    
5549                    if (group == null) {
5550                            StringBundler msg = new StringBundler(8);
5551    
5552                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5553    
5554                            msg.append("companyId=");
5555                            msg.append(companyId);
5556    
5557                            msg.append(", liveGroupId=");
5558                            msg.append(liveGroupId);
5559    
5560                            msg.append(", name=");
5561                            msg.append(name);
5562    
5563                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5564    
5565                            if (_log.isWarnEnabled()) {
5566                                    _log.warn(msg.toString());
5567                            }
5568    
5569                            throw new NoSuchGroupException(msg.toString());
5570                    }
5571    
5572                    return group;
5573            }
5574    
5575            /**
5576             * Returns the group where companyId = &#63; and liveGroupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5577             *
5578             * @param companyId the company ID
5579             * @param liveGroupId the live group ID
5580             * @param name the name
5581             * @return the matching group, or <code>null</code> if a matching group could not be found
5582             * @throws SystemException if a system exception occurred
5583             */
5584            public Group fetchByC_L_N(long companyId, long liveGroupId, String name)
5585                    throws SystemException {
5586                    return fetchByC_L_N(companyId, liveGroupId, name, true);
5587            }
5588    
5589            /**
5590             * Returns the group where companyId = &#63; and liveGroupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5591             *
5592             * @param companyId the company ID
5593             * @param liveGroupId the live group ID
5594             * @param name the name
5595             * @param retrieveFromCache whether to use the finder cache
5596             * @return the matching group, or <code>null</code> if a matching group could not be found
5597             * @throws SystemException if a system exception occurred
5598             */
5599            public Group fetchByC_L_N(long companyId, long liveGroupId, String name,
5600                    boolean retrieveFromCache) throws SystemException {
5601                    Object[] finderArgs = new Object[] { companyId, liveGroupId, name };
5602    
5603                    Object result = null;
5604    
5605                    if (retrieveFromCache) {
5606                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_L_N,
5607                                            finderArgs, this);
5608                    }
5609    
5610                    if (result instanceof Group) {
5611                            Group group = (Group)result;
5612    
5613                            if ((companyId != group.getCompanyId()) ||
5614                                            (liveGroupId != group.getLiveGroupId()) ||
5615                                            !Validator.equals(name, group.getName())) {
5616                                    result = null;
5617                            }
5618                    }
5619    
5620                    if (result == null) {
5621                            StringBundler query = new StringBundler(5);
5622    
5623                            query.append(_SQL_SELECT_GROUP__WHERE);
5624    
5625                            query.append(_FINDER_COLUMN_C_L_N_COMPANYID_2);
5626    
5627                            query.append(_FINDER_COLUMN_C_L_N_LIVEGROUPID_2);
5628    
5629                            boolean bindName = false;
5630    
5631                            if (name == null) {
5632                                    query.append(_FINDER_COLUMN_C_L_N_NAME_1);
5633                            }
5634                            else if (name.equals(StringPool.BLANK)) {
5635                                    query.append(_FINDER_COLUMN_C_L_N_NAME_3);
5636                            }
5637                            else {
5638                                    bindName = true;
5639    
5640                                    query.append(_FINDER_COLUMN_C_L_N_NAME_2);
5641                            }
5642    
5643                            String sql = query.toString();
5644    
5645                            Session session = null;
5646    
5647                            try {
5648                                    session = openSession();
5649    
5650                                    Query q = session.createQuery(sql);
5651    
5652                                    QueryPos qPos = QueryPos.getInstance(q);
5653    
5654                                    qPos.add(companyId);
5655    
5656                                    qPos.add(liveGroupId);
5657    
5658                                    if (bindName) {
5659                                            qPos.add(name);
5660                                    }
5661    
5662                                    List<Group> list = q.list();
5663    
5664                                    if (list.isEmpty()) {
5665                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
5666                                                    finderArgs, list);
5667                                    }
5668                                    else {
5669                                            Group group = list.get(0);
5670    
5671                                            result = group;
5672    
5673                                            cacheResult(group);
5674    
5675                                            if ((group.getCompanyId() != companyId) ||
5676                                                            (group.getLiveGroupId() != liveGroupId) ||
5677                                                            (group.getName() == null) ||
5678                                                            !group.getName().equals(name)) {
5679                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
5680                                                            finderArgs, group);
5681                                            }
5682                                    }
5683                            }
5684                            catch (Exception e) {
5685                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N,
5686                                            finderArgs);
5687    
5688                                    throw processException(e);
5689                            }
5690                            finally {
5691                                    closeSession(session);
5692                            }
5693                    }
5694    
5695                    if (result instanceof List<?>) {
5696                            return null;
5697                    }
5698                    else {
5699                            return (Group)result;
5700                    }
5701            }
5702    
5703            /**
5704             * Removes the group where companyId = &#63; and liveGroupId = &#63; and name = &#63; from the database.
5705             *
5706             * @param companyId the company ID
5707             * @param liveGroupId the live group ID
5708             * @param name the name
5709             * @return the group that was removed
5710             * @throws SystemException if a system exception occurred
5711             */
5712            public Group removeByC_L_N(long companyId, long liveGroupId, String name)
5713                    throws NoSuchGroupException, SystemException {
5714                    Group group = findByC_L_N(companyId, liveGroupId, name);
5715    
5716                    return remove(group);
5717            }
5718    
5719            /**
5720             * Returns the number of groups where companyId = &#63; and liveGroupId = &#63; and name = &#63;.
5721             *
5722             * @param companyId the company ID
5723             * @param liveGroupId the live group ID
5724             * @param name the name
5725             * @return the number of matching groups
5726             * @throws SystemException if a system exception occurred
5727             */
5728            public int countByC_L_N(long companyId, long liveGroupId, String name)
5729                    throws SystemException {
5730                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_L_N;
5731    
5732                    Object[] finderArgs = new Object[] { companyId, liveGroupId, name };
5733    
5734                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5735                                    this);
5736    
5737                    if (count == null) {
5738                            StringBundler query = new StringBundler(4);
5739    
5740                            query.append(_SQL_COUNT_GROUP__WHERE);
5741    
5742                            query.append(_FINDER_COLUMN_C_L_N_COMPANYID_2);
5743    
5744                            query.append(_FINDER_COLUMN_C_L_N_LIVEGROUPID_2);
5745    
5746                            boolean bindName = false;
5747    
5748                            if (name == null) {
5749                                    query.append(_FINDER_COLUMN_C_L_N_NAME_1);
5750                            }
5751                            else if (name.equals(StringPool.BLANK)) {
5752                                    query.append(_FINDER_COLUMN_C_L_N_NAME_3);
5753                            }
5754                            else {
5755                                    bindName = true;
5756    
5757                                    query.append(_FINDER_COLUMN_C_L_N_NAME_2);
5758                            }
5759    
5760                            String sql = query.toString();
5761    
5762                            Session session = null;
5763    
5764                            try {
5765                                    session = openSession();
5766    
5767                                    Query q = session.createQuery(sql);
5768    
5769                                    QueryPos qPos = QueryPos.getInstance(q);
5770    
5771                                    qPos.add(companyId);
5772    
5773                                    qPos.add(liveGroupId);
5774    
5775                                    if (bindName) {
5776                                            qPos.add(name);
5777                                    }
5778    
5779                                    count = (Long)q.uniqueResult();
5780    
5781                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5782                            }
5783                            catch (Exception e) {
5784                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5785    
5786                                    throw processException(e);
5787                            }
5788                            finally {
5789                                    closeSession(session);
5790                            }
5791                    }
5792    
5793                    return count.intValue();
5794            }
5795    
5796            private static final String _FINDER_COLUMN_C_L_N_COMPANYID_2 = "group_.companyId = ? AND ";
5797            private static final String _FINDER_COLUMN_C_L_N_LIVEGROUPID_2 = "group_.liveGroupId = ? AND ";
5798            private static final String _FINDER_COLUMN_C_L_N_NAME_1 = "group_.name IS NULL";
5799            private static final String _FINDER_COLUMN_C_L_N_NAME_2 = "group_.name = ?";
5800            private static final String _FINDER_COLUMN_C_L_N_NAME_3 = "(group_.name IS NULL OR group_.name = '')";
5801            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5802                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
5803                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C_L_N",
5804                            new String[] {
5805                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5806                                    String.class.getName()
5807                            },
5808                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
5809                            GroupModelImpl.CLASSNAMEID_COLUMN_BITMASK |
5810                            GroupModelImpl.LIVEGROUPID_COLUMN_BITMASK |
5811                            GroupModelImpl.NAME_COLUMN_BITMASK);
5812            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5813                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
5814                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_L_N",
5815                            new String[] {
5816                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5817                                    String.class.getName()
5818                            });
5819    
5820            /**
5821             * Returns the group where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
5822             *
5823             * @param companyId the company ID
5824             * @param classNameId the class name ID
5825             * @param liveGroupId the live group ID
5826             * @param name the name
5827             * @return the matching group
5828             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5829             * @throws SystemException if a system exception occurred
5830             */
5831            public Group findByC_C_L_N(long companyId, long classNameId,
5832                    long liveGroupId, String name)
5833                    throws NoSuchGroupException, SystemException {
5834                    Group group = fetchByC_C_L_N(companyId, classNameId, liveGroupId, name);
5835    
5836                    if (group == null) {
5837                            StringBundler msg = new StringBundler(10);
5838    
5839                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5840    
5841                            msg.append("companyId=");
5842                            msg.append(companyId);
5843    
5844                            msg.append(", classNameId=");
5845                            msg.append(classNameId);
5846    
5847                            msg.append(", liveGroupId=");
5848                            msg.append(liveGroupId);
5849    
5850                            msg.append(", name=");
5851                            msg.append(name);
5852    
5853                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5854    
5855                            if (_log.isWarnEnabled()) {
5856                                    _log.warn(msg.toString());
5857                            }
5858    
5859                            throw new NoSuchGroupException(msg.toString());
5860                    }
5861    
5862                    return group;
5863            }
5864    
5865            /**
5866             * Returns the group where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5867             *
5868             * @param companyId the company ID
5869             * @param classNameId the class name ID
5870             * @param liveGroupId the live group ID
5871             * @param name the name
5872             * @return the matching group, or <code>null</code> if a matching group could not be found
5873             * @throws SystemException if a system exception occurred
5874             */
5875            public Group fetchByC_C_L_N(long companyId, long classNameId,
5876                    long liveGroupId, String name) throws SystemException {
5877                    return fetchByC_C_L_N(companyId, classNameId, liveGroupId, name, true);
5878            }
5879    
5880            /**
5881             * Returns the group where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5882             *
5883             * @param companyId the company ID
5884             * @param classNameId the class name ID
5885             * @param liveGroupId the live group ID
5886             * @param name the name
5887             * @param retrieveFromCache whether to use the finder cache
5888             * @return the matching group, or <code>null</code> if a matching group could not be found
5889             * @throws SystemException if a system exception occurred
5890             */
5891            public Group fetchByC_C_L_N(long companyId, long classNameId,
5892                    long liveGroupId, String name, boolean retrieveFromCache)
5893                    throws SystemException {
5894                    Object[] finderArgs = new Object[] {
5895                                    companyId, classNameId, liveGroupId, name
5896                            };
5897    
5898                    Object result = null;
5899    
5900                    if (retrieveFromCache) {
5901                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_L_N,
5902                                            finderArgs, this);
5903                    }
5904    
5905                    if (result instanceof Group) {
5906                            Group group = (Group)result;
5907    
5908                            if ((companyId != group.getCompanyId()) ||
5909                                            (classNameId != group.getClassNameId()) ||
5910                                            (liveGroupId != group.getLiveGroupId()) ||
5911                                            !Validator.equals(name, group.getName())) {
5912                                    result = null;
5913                            }
5914                    }
5915    
5916                    if (result == null) {
5917                            StringBundler query = new StringBundler(6);
5918    
5919                            query.append(_SQL_SELECT_GROUP__WHERE);
5920    
5921                            query.append(_FINDER_COLUMN_C_C_L_N_COMPANYID_2);
5922    
5923                            query.append(_FINDER_COLUMN_C_C_L_N_CLASSNAMEID_2);
5924    
5925                            query.append(_FINDER_COLUMN_C_C_L_N_LIVEGROUPID_2);
5926    
5927                            boolean bindName = false;
5928    
5929                            if (name == null) {
5930                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_1);
5931                            }
5932                            else if (name.equals(StringPool.BLANK)) {
5933                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_3);
5934                            }
5935                            else {
5936                                    bindName = true;
5937    
5938                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_2);
5939                            }
5940    
5941                            String sql = query.toString();
5942    
5943                            Session session = null;
5944    
5945                            try {
5946                                    session = openSession();
5947    
5948                                    Query q = session.createQuery(sql);
5949    
5950                                    QueryPos qPos = QueryPos.getInstance(q);
5951    
5952                                    qPos.add(companyId);
5953    
5954                                    qPos.add(classNameId);
5955    
5956                                    qPos.add(liveGroupId);
5957    
5958                                    if (bindName) {
5959                                            qPos.add(name);
5960                                    }
5961    
5962                                    List<Group> list = q.list();
5963    
5964                                    if (list.isEmpty()) {
5965                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
5966                                                    finderArgs, list);
5967                                    }
5968                                    else {
5969                                            Group group = list.get(0);
5970    
5971                                            result = group;
5972    
5973                                            cacheResult(group);
5974    
5975                                            if ((group.getCompanyId() != companyId) ||
5976                                                            (group.getClassNameId() != classNameId) ||
5977                                                            (group.getLiveGroupId() != liveGroupId) ||
5978                                                            (group.getName() == null) ||
5979                                                            !group.getName().equals(name)) {
5980                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
5981                                                            finderArgs, group);
5982                                            }
5983                                    }
5984                            }
5985                            catch (Exception e) {
5986                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N,
5987                                            finderArgs);
5988    
5989                                    throw processException(e);
5990                            }
5991                            finally {
5992                                    closeSession(session);
5993                            }
5994                    }
5995    
5996                    if (result instanceof List<?>) {
5997                            return null;
5998                    }
5999                    else {
6000                            return (Group)result;
6001                    }
6002            }
6003    
6004            /**
6005             * Removes the group where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63; from the database.
6006             *
6007             * @param companyId the company ID
6008             * @param classNameId the class name ID
6009             * @param liveGroupId the live group ID
6010             * @param name the name
6011             * @return the group that was removed
6012             * @throws SystemException if a system exception occurred
6013             */
6014            public Group removeByC_C_L_N(long companyId, long classNameId,
6015                    long liveGroupId, String name)
6016                    throws NoSuchGroupException, SystemException {
6017                    Group group = findByC_C_L_N(companyId, classNameId, liveGroupId, name);
6018    
6019                    return remove(group);
6020            }
6021    
6022            /**
6023             * Returns the number of groups where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63;.
6024             *
6025             * @param companyId the company ID
6026             * @param classNameId the class name ID
6027             * @param liveGroupId the live group ID
6028             * @param name the name
6029             * @return the number of matching groups
6030             * @throws SystemException if a system exception occurred
6031             */
6032            public int countByC_C_L_N(long companyId, long classNameId,
6033                    long liveGroupId, String name) throws SystemException {
6034                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_L_N;
6035    
6036                    Object[] finderArgs = new Object[] {
6037                                    companyId, classNameId, liveGroupId, name
6038                            };
6039    
6040                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6041                                    this);
6042    
6043                    if (count == null) {
6044                            StringBundler query = new StringBundler(5);
6045    
6046                            query.append(_SQL_COUNT_GROUP__WHERE);
6047    
6048                            query.append(_FINDER_COLUMN_C_C_L_N_COMPANYID_2);
6049    
6050                            query.append(_FINDER_COLUMN_C_C_L_N_CLASSNAMEID_2);
6051    
6052                            query.append(_FINDER_COLUMN_C_C_L_N_LIVEGROUPID_2);
6053    
6054                            boolean bindName = false;
6055    
6056                            if (name == null) {
6057                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_1);
6058                            }
6059                            else if (name.equals(StringPool.BLANK)) {
6060                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_3);
6061                            }
6062                            else {
6063                                    bindName = true;
6064    
6065                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_2);
6066                            }
6067    
6068                            String sql = query.toString();
6069    
6070                            Session session = null;
6071    
6072                            try {
6073                                    session = openSession();
6074    
6075                                    Query q = session.createQuery(sql);
6076    
6077                                    QueryPos qPos = QueryPos.getInstance(q);
6078    
6079                                    qPos.add(companyId);
6080    
6081                                    qPos.add(classNameId);
6082    
6083                                    qPos.add(liveGroupId);
6084    
6085                                    if (bindName) {
6086                                            qPos.add(name);
6087                                    }
6088    
6089                                    count = (Long)q.uniqueResult();
6090    
6091                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6092                            }
6093                            catch (Exception e) {
6094                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6095    
6096                                    throw processException(e);
6097                            }
6098                            finally {
6099                                    closeSession(session);
6100                            }
6101                    }
6102    
6103                    return count.intValue();
6104            }
6105    
6106            private static final String _FINDER_COLUMN_C_C_L_N_COMPANYID_2 = "group_.companyId = ? AND ";
6107            private static final String _FINDER_COLUMN_C_C_L_N_CLASSNAMEID_2 = "group_.classNameId = ? AND ";
6108            private static final String _FINDER_COLUMN_C_C_L_N_LIVEGROUPID_2 = "group_.liveGroupId = ? AND ";
6109            private static final String _FINDER_COLUMN_C_C_L_N_NAME_1 = "group_.name IS NULL";
6110            private static final String _FINDER_COLUMN_C_C_L_N_NAME_2 = "group_.name = ?";
6111            private static final String _FINDER_COLUMN_C_C_L_N_NAME_3 = "(group_.name IS NULL OR group_.name = '')";
6112    
6113            /**
6114             * Caches the group in the entity cache if it is enabled.
6115             *
6116             * @param group the group
6117             */
6118            public void cacheResult(Group group) {
6119                    EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6120                            GroupImpl.class, group.getPrimaryKey(), group);
6121    
6122                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
6123                            new Object[] { group.getUuid(), group.getGroupId() }, group);
6124    
6125                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
6126                            new Object[] { group.getLiveGroupId() }, group);
6127    
6128                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
6129                            new Object[] { group.getCompanyId(), group.getName() }, group);
6130    
6131                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
6132                            new Object[] { group.getCompanyId(), group.getFriendlyURL() }, group);
6133    
6134                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
6135                            new Object[] {
6136                                    group.getCompanyId(), group.getClassNameId(), group.getClassPK()
6137                            }, group);
6138    
6139                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
6140                            new Object[] {
6141                                    group.getCompanyId(), group.getLiveGroupId(), group.getName()
6142                            }, group);
6143    
6144                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
6145                            new Object[] {
6146                                    group.getCompanyId(), group.getClassNameId(),
6147                                    group.getLiveGroupId(), group.getName()
6148                            }, group);
6149    
6150                    group.resetOriginalValues();
6151            }
6152    
6153            /**
6154             * Caches the groups in the entity cache if it is enabled.
6155             *
6156             * @param groups the groups
6157             */
6158            public void cacheResult(List<Group> groups) {
6159                    for (Group group : groups) {
6160                            if (EntityCacheUtil.getResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6161                                                    GroupImpl.class, group.getPrimaryKey()) == null) {
6162                                    cacheResult(group);
6163                            }
6164                            else {
6165                                    group.resetOriginalValues();
6166                            }
6167                    }
6168            }
6169    
6170            /**
6171             * Clears the cache for all groups.
6172             *
6173             * <p>
6174             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6175             * </p>
6176             */
6177            @Override
6178            public void clearCache() {
6179                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
6180                            CacheRegistryUtil.clear(GroupImpl.class.getName());
6181                    }
6182    
6183                    EntityCacheUtil.clearCache(GroupImpl.class.getName());
6184    
6185                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
6186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6188            }
6189    
6190            /**
6191             * Clears the cache for the group.
6192             *
6193             * <p>
6194             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
6195             * </p>
6196             */
6197            @Override
6198            public void clearCache(Group group) {
6199                    EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6200                            GroupImpl.class, group.getPrimaryKey());
6201    
6202                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6203                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6204    
6205                    clearUniqueFindersCache(group);
6206            }
6207    
6208            @Override
6209            public void clearCache(List<Group> groups) {
6210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6211                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6212    
6213                    for (Group group : groups) {
6214                            EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6215                                    GroupImpl.class, group.getPrimaryKey());
6216    
6217                            clearUniqueFindersCache(group);
6218                    }
6219            }
6220    
6221            protected void cacheUniqueFindersCache(Group group) {
6222                    if (group.isNew()) {
6223                            Object[] args = new Object[] { group.getUuid(), group.getGroupId() };
6224    
6225                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6226                                    Long.valueOf(1));
6227                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, group);
6228    
6229                            args = new Object[] { group.getLiveGroupId() };
6230    
6231                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LIVEGROUPID, args,
6232                                    Long.valueOf(1));
6233                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID, args,
6234                                    group);
6235    
6236                            args = new Object[] { group.getCompanyId(), group.getName() };
6237    
6238                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6239                                    Long.valueOf(1));
6240                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, group);
6241    
6242                            args = new Object[] { group.getCompanyId(), group.getFriendlyURL() };
6243    
6244                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, args,
6245                                    Long.valueOf(1));
6246                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F, args, group);
6247    
6248                            args = new Object[] {
6249                                            group.getCompanyId(), group.getClassNameId(),
6250                                            group.getClassPK()
6251                                    };
6252    
6253                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
6254                                    Long.valueOf(1));
6255                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, group);
6256    
6257                            args = new Object[] {
6258                                            group.getCompanyId(), group.getLiveGroupId(),
6259                                            group.getName()
6260                                    };
6261    
6262                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L_N, args,
6263                                    Long.valueOf(1));
6264                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N, args, group);
6265    
6266                            args = new Object[] {
6267                                            group.getCompanyId(), group.getClassNameId(),
6268                                            group.getLiveGroupId(), group.getName()
6269                                    };
6270    
6271                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_L_N, args,
6272                                    Long.valueOf(1));
6273                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N, args, group);
6274                    }
6275                    else {
6276                            GroupModelImpl groupModelImpl = (GroupModelImpl)group;
6277    
6278                            if ((groupModelImpl.getColumnBitmask() &
6279                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6280                                    Object[] args = new Object[] { group.getUuid(), group.getGroupId() };
6281    
6282                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
6283                                            Long.valueOf(1));
6284                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
6285                                            group);
6286                            }
6287    
6288                            if ((groupModelImpl.getColumnBitmask() &
6289                                            FINDER_PATH_FETCH_BY_LIVEGROUPID.getColumnBitmask()) != 0) {
6290                                    Object[] args = new Object[] { group.getLiveGroupId() };
6291    
6292                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LIVEGROUPID,
6293                                            args, Long.valueOf(1));
6294                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
6295                                            args, group);
6296                            }
6297    
6298                            if ((groupModelImpl.getColumnBitmask() &
6299                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6300                                    Object[] args = new Object[] {
6301                                                    group.getCompanyId(), group.getName()
6302                                            };
6303    
6304                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
6305                                            Long.valueOf(1));
6306                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, group);
6307                            }
6308    
6309                            if ((groupModelImpl.getColumnBitmask() &
6310                                            FINDER_PATH_FETCH_BY_C_F.getColumnBitmask()) != 0) {
6311                                    Object[] args = new Object[] {
6312                                                    group.getCompanyId(), group.getFriendlyURL()
6313                                            };
6314    
6315                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, args,
6316                                            Long.valueOf(1));
6317                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F, args, group);
6318                            }
6319    
6320                            if ((groupModelImpl.getColumnBitmask() &
6321                                            FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
6322                                    Object[] args = new Object[] {
6323                                                    group.getCompanyId(), group.getClassNameId(),
6324                                                    group.getClassPK()
6325                                            };
6326    
6327                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
6328                                            Long.valueOf(1));
6329                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args,
6330                                            group);
6331                            }
6332    
6333                            if ((groupModelImpl.getColumnBitmask() &
6334                                            FINDER_PATH_FETCH_BY_C_L_N.getColumnBitmask()) != 0) {
6335                                    Object[] args = new Object[] {
6336                                                    group.getCompanyId(), group.getLiveGroupId(),
6337                                                    group.getName()
6338                                            };
6339    
6340                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L_N, args,
6341                                            Long.valueOf(1));
6342                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N, args,
6343                                            group);
6344                            }
6345    
6346                            if ((groupModelImpl.getColumnBitmask() &
6347                                            FINDER_PATH_FETCH_BY_C_C_L_N.getColumnBitmask()) != 0) {
6348                                    Object[] args = new Object[] {
6349                                                    group.getCompanyId(), group.getClassNameId(),
6350                                                    group.getLiveGroupId(), group.getName()
6351                                            };
6352    
6353                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_L_N, args,
6354                                            Long.valueOf(1));
6355                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N, args,
6356                                            group);
6357                            }
6358                    }
6359            }
6360    
6361            protected void clearUniqueFindersCache(Group group) {
6362                    GroupModelImpl groupModelImpl = (GroupModelImpl)group;
6363    
6364                    Object[] args = new Object[] { group.getUuid(), group.getGroupId() };
6365    
6366                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6367                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6368    
6369                    if ((groupModelImpl.getColumnBitmask() &
6370                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
6371                            args = new Object[] {
6372                                            groupModelImpl.getOriginalUuid(),
6373                                            groupModelImpl.getOriginalGroupId()
6374                                    };
6375    
6376                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
6377                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
6378                    }
6379    
6380                    args = new Object[] { group.getLiveGroupId() };
6381    
6382                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LIVEGROUPID, args);
6383                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID, args);
6384    
6385                    if ((groupModelImpl.getColumnBitmask() &
6386                                    FINDER_PATH_FETCH_BY_LIVEGROUPID.getColumnBitmask()) != 0) {
6387                            args = new Object[] { groupModelImpl.getOriginalLiveGroupId() };
6388    
6389                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LIVEGROUPID, args);
6390                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID, args);
6391                    }
6392    
6393                    args = new Object[] { group.getCompanyId(), group.getName() };
6394    
6395                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6396                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6397    
6398                    if ((groupModelImpl.getColumnBitmask() &
6399                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
6400                            args = new Object[] {
6401                                            groupModelImpl.getOriginalCompanyId(),
6402                                            groupModelImpl.getOriginalName()
6403                                    };
6404    
6405                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
6406                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
6407                    }
6408    
6409                    args = new Object[] { group.getCompanyId(), group.getFriendlyURL() };
6410    
6411                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_F, args);
6412                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F, args);
6413    
6414                    if ((groupModelImpl.getColumnBitmask() &
6415                                    FINDER_PATH_FETCH_BY_C_F.getColumnBitmask()) != 0) {
6416                            args = new Object[] {
6417                                            groupModelImpl.getOriginalCompanyId(),
6418                                            groupModelImpl.getOriginalFriendlyURL()
6419                                    };
6420    
6421                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_F, args);
6422                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F, args);
6423                    }
6424    
6425                    args = new Object[] {
6426                                    group.getCompanyId(), group.getClassNameId(), group.getClassPK()
6427                            };
6428    
6429                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
6430                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
6431    
6432                    if ((groupModelImpl.getColumnBitmask() &
6433                                    FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
6434                            args = new Object[] {
6435                                            groupModelImpl.getOriginalCompanyId(),
6436                                            groupModelImpl.getOriginalClassNameId(),
6437                                            groupModelImpl.getOriginalClassPK()
6438                                    };
6439    
6440                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
6441                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
6442                    }
6443    
6444                    args = new Object[] {
6445                                    group.getCompanyId(), group.getLiveGroupId(), group.getName()
6446                            };
6447    
6448                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_L_N, args);
6449                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N, args);
6450    
6451                    if ((groupModelImpl.getColumnBitmask() &
6452                                    FINDER_PATH_FETCH_BY_C_L_N.getColumnBitmask()) != 0) {
6453                            args = new Object[] {
6454                                            groupModelImpl.getOriginalCompanyId(),
6455                                            groupModelImpl.getOriginalLiveGroupId(),
6456                                            groupModelImpl.getOriginalName()
6457                                    };
6458    
6459                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_L_N, args);
6460                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N, args);
6461                    }
6462    
6463                    args = new Object[] {
6464                                    group.getCompanyId(), group.getClassNameId(),
6465                                    group.getLiveGroupId(), group.getName()
6466                            };
6467    
6468                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_L_N, args);
6469                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N, args);
6470    
6471                    if ((groupModelImpl.getColumnBitmask() &
6472                                    FINDER_PATH_FETCH_BY_C_C_L_N.getColumnBitmask()) != 0) {
6473                            args = new Object[] {
6474                                            groupModelImpl.getOriginalCompanyId(),
6475                                            groupModelImpl.getOriginalClassNameId(),
6476                                            groupModelImpl.getOriginalLiveGroupId(),
6477                                            groupModelImpl.getOriginalName()
6478                                    };
6479    
6480                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_L_N, args);
6481                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N, args);
6482                    }
6483            }
6484    
6485            /**
6486             * Creates a new group with the primary key. Does not add the group to the database.
6487             *
6488             * @param groupId the primary key for the new group
6489             * @return the new group
6490             */
6491            public Group create(long groupId) {
6492                    Group group = new GroupImpl();
6493    
6494                    group.setNew(true);
6495                    group.setPrimaryKey(groupId);
6496    
6497                    String uuid = PortalUUIDUtil.generate();
6498    
6499                    group.setUuid(uuid);
6500    
6501                    return group;
6502            }
6503    
6504            /**
6505             * Removes the group with the primary key from the database. Also notifies the appropriate model listeners.
6506             *
6507             * @param groupId the primary key of the group
6508             * @return the group that was removed
6509             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
6510             * @throws SystemException if a system exception occurred
6511             */
6512            public Group remove(long groupId)
6513                    throws NoSuchGroupException, SystemException {
6514                    return remove((Serializable)groupId);
6515            }
6516    
6517            /**
6518             * Removes the group with the primary key from the database. Also notifies the appropriate model listeners.
6519             *
6520             * @param primaryKey the primary key of the group
6521             * @return the group that was removed
6522             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
6523             * @throws SystemException if a system exception occurred
6524             */
6525            @Override
6526            public Group remove(Serializable primaryKey)
6527                    throws NoSuchGroupException, SystemException {
6528                    Session session = null;
6529    
6530                    try {
6531                            session = openSession();
6532    
6533                            Group group = (Group)session.get(GroupImpl.class, primaryKey);
6534    
6535                            if (group == null) {
6536                                    if (_log.isWarnEnabled()) {
6537                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6538                                    }
6539    
6540                                    throw new NoSuchGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6541                                            primaryKey);
6542                            }
6543    
6544                            return remove(group);
6545                    }
6546                    catch (NoSuchGroupException nsee) {
6547                            throw nsee;
6548                    }
6549                    catch (Exception e) {
6550                            throw processException(e);
6551                    }
6552                    finally {
6553                            closeSession(session);
6554                    }
6555            }
6556    
6557            @Override
6558            protected Group removeImpl(Group group) throws SystemException {
6559                    group = toUnwrappedModel(group);
6560    
6561                    try {
6562                            clearOrganizations.clear(group.getPrimaryKey());
6563                    }
6564                    catch (Exception e) {
6565                            throw processException(e);
6566                    }
6567                    finally {
6568                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
6569                    }
6570    
6571                    try {
6572                            clearRoles.clear(group.getPrimaryKey());
6573                    }
6574                    catch (Exception e) {
6575                            throw processException(e);
6576                    }
6577                    finally {
6578                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
6579                    }
6580    
6581                    try {
6582                            clearUserGroups.clear(group.getPrimaryKey());
6583                    }
6584                    catch (Exception e) {
6585                            throw processException(e);
6586                    }
6587                    finally {
6588                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
6589                    }
6590    
6591                    try {
6592                            clearUsers.clear(group.getPrimaryKey());
6593                    }
6594                    catch (Exception e) {
6595                            throw processException(e);
6596                    }
6597                    finally {
6598                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
6599                    }
6600    
6601                    Session session = null;
6602    
6603                    try {
6604                            session = openSession();
6605    
6606                            if (!session.contains(group)) {
6607                                    group = (Group)session.get(GroupImpl.class,
6608                                                    group.getPrimaryKeyObj());
6609                            }
6610    
6611                            if (group != null) {
6612                                    session.delete(group);
6613                            }
6614                    }
6615                    catch (Exception e) {
6616                            throw processException(e);
6617                    }
6618                    finally {
6619                            closeSession(session);
6620                    }
6621    
6622                    if (group != null) {
6623                            clearCache(group);
6624                    }
6625    
6626                    return group;
6627            }
6628    
6629            @Override
6630            public Group updateImpl(com.liferay.portal.model.Group group)
6631                    throws SystemException {
6632                    group = toUnwrappedModel(group);
6633    
6634                    boolean isNew = group.isNew();
6635    
6636                    GroupModelImpl groupModelImpl = (GroupModelImpl)group;
6637    
6638                    if (Validator.isNull(group.getUuid())) {
6639                            String uuid = PortalUUIDUtil.generate();
6640    
6641                            group.setUuid(uuid);
6642                    }
6643    
6644                    Session session = null;
6645    
6646                    try {
6647                            session = openSession();
6648    
6649                            if (group.isNew()) {
6650                                    session.save(group);
6651    
6652                                    group.setNew(false);
6653                            }
6654                            else {
6655                                    session.merge(group);
6656                            }
6657                    }
6658                    catch (Exception e) {
6659                            throw processException(e);
6660                    }
6661                    finally {
6662                            closeSession(session);
6663                    }
6664    
6665                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
6666    
6667                    if (isNew || !GroupModelImpl.COLUMN_BITMASK_ENABLED) {
6668                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6669                    }
6670    
6671                    else {
6672                            if ((groupModelImpl.getColumnBitmask() &
6673                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
6674                                    Object[] args = new Object[] { groupModelImpl.getOriginalUuid() };
6675    
6676                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6677                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6678                                            args);
6679    
6680                                    args = new Object[] { groupModelImpl.getUuid() };
6681    
6682                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
6683                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
6684                                            args);
6685                            }
6686    
6687                            if ((groupModelImpl.getColumnBitmask() &
6688                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
6689                                    Object[] args = new Object[] {
6690                                                    groupModelImpl.getOriginalUuid(),
6691                                                    groupModelImpl.getOriginalCompanyId()
6692                                            };
6693    
6694                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6695                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6696                                            args);
6697    
6698                                    args = new Object[] {
6699                                                    groupModelImpl.getUuid(), groupModelImpl.getCompanyId()
6700                                            };
6701    
6702                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
6703                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
6704                                            args);
6705                            }
6706    
6707                            if ((groupModelImpl.getColumnBitmask() &
6708                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
6709                                    Object[] args = new Object[] {
6710                                                    groupModelImpl.getOriginalCompanyId()
6711                                            };
6712    
6713                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6714                                            args);
6715                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6716                                            args);
6717    
6718                                    args = new Object[] { groupModelImpl.getCompanyId() };
6719    
6720                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
6721                                            args);
6722                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
6723                                            args);
6724                            }
6725    
6726                            if ((groupModelImpl.getColumnBitmask() &
6727                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
6728                                    Object[] args = new Object[] {
6729                                                    groupModelImpl.getOriginalCompanyId(),
6730                                                    groupModelImpl.getOriginalParentGroupId()
6731                                            };
6732    
6733                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6734                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6735                                            args);
6736    
6737                                    args = new Object[] {
6738                                                    groupModelImpl.getCompanyId(),
6739                                                    groupModelImpl.getParentGroupId()
6740                                            };
6741    
6742                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
6743                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
6744                                            args);
6745                            }
6746    
6747                            if ((groupModelImpl.getColumnBitmask() &
6748                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
6749                                    Object[] args = new Object[] {
6750                                                    groupModelImpl.getOriginalCompanyId(),
6751                                                    groupModelImpl.getOriginalSite()
6752                                            };
6753    
6754                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
6755                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
6756                                            args);
6757    
6758                                    args = new Object[] {
6759                                                    groupModelImpl.getCompanyId(), groupModelImpl.getSite()
6760                                            };
6761    
6762                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
6763                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
6764                                            args);
6765                            }
6766    
6767                            if ((groupModelImpl.getColumnBitmask() &
6768                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
6769                                    Object[] args = new Object[] {
6770                                                    groupModelImpl.getOriginalType(),
6771                                                    groupModelImpl.getOriginalActive()
6772                                            };
6773    
6774                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
6775                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
6776                                            args);
6777    
6778                                    args = new Object[] {
6779                                                    groupModelImpl.getType(), groupModelImpl.getActive()
6780                                            };
6781    
6782                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
6783                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
6784                                            args);
6785                            }
6786    
6787                            if ((groupModelImpl.getColumnBitmask() &
6788                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P.getColumnBitmask()) != 0) {
6789                                    Object[] args = new Object[] {
6790                                                    groupModelImpl.getOriginalCompanyId(),
6791                                                    groupModelImpl.getOriginalClassNameId(),
6792                                                    groupModelImpl.getOriginalParentGroupId()
6793                                            };
6794    
6795                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_P, args);
6796                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P,
6797                                            args);
6798    
6799                                    args = new Object[] {
6800                                                    groupModelImpl.getCompanyId(),
6801                                                    groupModelImpl.getClassNameId(),
6802                                                    groupModelImpl.getParentGroupId()
6803                                            };
6804    
6805                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_P, args);
6806                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P,
6807                                            args);
6808                            }
6809    
6810                            if ((groupModelImpl.getColumnBitmask() &
6811                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S.getColumnBitmask()) != 0) {
6812                                    Object[] args = new Object[] {
6813                                                    groupModelImpl.getOriginalCompanyId(),
6814                                                    groupModelImpl.getOriginalParentGroupId(),
6815                                                    groupModelImpl.getOriginalSite()
6816                                            };
6817    
6818                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P_S, args);
6819                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S,
6820                                            args);
6821    
6822                                    args = new Object[] {
6823                                                    groupModelImpl.getCompanyId(),
6824                                                    groupModelImpl.getParentGroupId(),
6825                                                    groupModelImpl.getSite()
6826                                            };
6827    
6828                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P_S, args);
6829                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S,
6830                                            args);
6831                            }
6832                    }
6833    
6834                    EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6835                            GroupImpl.class, group.getPrimaryKey(), group);
6836    
6837                    clearUniqueFindersCache(group);
6838                    cacheUniqueFindersCache(group);
6839    
6840                    return group;
6841            }
6842    
6843            protected Group toUnwrappedModel(Group group) {
6844                    if (group instanceof GroupImpl) {
6845                            return group;
6846                    }
6847    
6848                    GroupImpl groupImpl = new GroupImpl();
6849    
6850                    groupImpl.setNew(group.isNew());
6851                    groupImpl.setPrimaryKey(group.getPrimaryKey());
6852    
6853                    groupImpl.setUuid(group.getUuid());
6854                    groupImpl.setGroupId(group.getGroupId());
6855                    groupImpl.setCompanyId(group.getCompanyId());
6856                    groupImpl.setCreatorUserId(group.getCreatorUserId());
6857                    groupImpl.setClassNameId(group.getClassNameId());
6858                    groupImpl.setClassPK(group.getClassPK());
6859                    groupImpl.setParentGroupId(group.getParentGroupId());
6860                    groupImpl.setLiveGroupId(group.getLiveGroupId());
6861                    groupImpl.setTreePath(group.getTreePath());
6862                    groupImpl.setName(group.getName());
6863                    groupImpl.setDescription(group.getDescription());
6864                    groupImpl.setType(group.getType());
6865                    groupImpl.setTypeSettings(group.getTypeSettings());
6866                    groupImpl.setFriendlyURL(group.getFriendlyURL());
6867                    groupImpl.setSite(group.isSite());
6868                    groupImpl.setActive(group.isActive());
6869    
6870                    return groupImpl;
6871            }
6872    
6873            /**
6874             * Returns the group with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
6875             *
6876             * @param primaryKey the primary key of the group
6877             * @return the group
6878             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
6879             * @throws SystemException if a system exception occurred
6880             */
6881            @Override
6882            public Group findByPrimaryKey(Serializable primaryKey)
6883                    throws NoSuchGroupException, SystemException {
6884                    Group group = fetchByPrimaryKey(primaryKey);
6885    
6886                    if (group == null) {
6887                            if (_log.isWarnEnabled()) {
6888                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
6889                            }
6890    
6891                            throw new NoSuchGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
6892                                    primaryKey);
6893                    }
6894    
6895                    return group;
6896            }
6897    
6898            /**
6899             * Returns the group with the primary key or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
6900             *
6901             * @param groupId the primary key of the group
6902             * @return the group
6903             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
6904             * @throws SystemException if a system exception occurred
6905             */
6906            public Group findByPrimaryKey(long groupId)
6907                    throws NoSuchGroupException, SystemException {
6908                    return findByPrimaryKey((Serializable)groupId);
6909            }
6910    
6911            /**
6912             * Returns the group with the primary key or returns <code>null</code> if it could not be found.
6913             *
6914             * @param primaryKey the primary key of the group
6915             * @return the group, or <code>null</code> if a group with the primary key could not be found
6916             * @throws SystemException if a system exception occurred
6917             */
6918            @Override
6919            public Group fetchByPrimaryKey(Serializable primaryKey)
6920                    throws SystemException {
6921                    Group group = (Group)EntityCacheUtil.getResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6922                                    GroupImpl.class, primaryKey);
6923    
6924                    if (group == _nullGroup) {
6925                            return null;
6926                    }
6927    
6928                    if (group == null) {
6929                            Session session = null;
6930    
6931                            try {
6932                                    session = openSession();
6933    
6934                                    group = (Group)session.get(GroupImpl.class, primaryKey);
6935    
6936                                    if (group != null) {
6937                                            cacheResult(group);
6938                                    }
6939                                    else {
6940                                            EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6941                                                    GroupImpl.class, primaryKey, _nullGroup);
6942                                    }
6943                            }
6944                            catch (Exception e) {
6945                                    EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
6946                                            GroupImpl.class, primaryKey);
6947    
6948                                    throw processException(e);
6949                            }
6950                            finally {
6951                                    closeSession(session);
6952                            }
6953                    }
6954    
6955                    return group;
6956            }
6957    
6958            /**
6959             * Returns the group with the primary key or returns <code>null</code> if it could not be found.
6960             *
6961             * @param groupId the primary key of the group
6962             * @return the group, or <code>null</code> if a group with the primary key could not be found
6963             * @throws SystemException if a system exception occurred
6964             */
6965            public Group fetchByPrimaryKey(long groupId) throws SystemException {
6966                    return fetchByPrimaryKey((Serializable)groupId);
6967            }
6968    
6969            /**
6970             * Returns all the groups.
6971             *
6972             * @return the groups
6973             * @throws SystemException if a system exception occurred
6974             */
6975            public List<Group> findAll() throws SystemException {
6976                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6977            }
6978    
6979            /**
6980             * Returns a range of all the groups.
6981             *
6982             * <p>
6983             * 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.GroupModelImpl}. 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.
6984             * </p>
6985             *
6986             * @param start the lower bound of the range of groups
6987             * @param end the upper bound of the range of groups (not inclusive)
6988             * @return the range of groups
6989             * @throws SystemException if a system exception occurred
6990             */
6991            public List<Group> findAll(int start, int end) throws SystemException {
6992                    return findAll(start, end, null);
6993            }
6994    
6995            /**
6996             * Returns an ordered range of all the groups.
6997             *
6998             * <p>
6999             * 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.GroupModelImpl}. 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.
7000             * </p>
7001             *
7002             * @param start the lower bound of the range of groups
7003             * @param end the upper bound of the range of groups (not inclusive)
7004             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7005             * @return the ordered range of groups
7006             * @throws SystemException if a system exception occurred
7007             */
7008            public List<Group> findAll(int start, int end,
7009                    OrderByComparator orderByComparator) throws SystemException {
7010                    boolean pagination = true;
7011                    FinderPath finderPath = null;
7012                    Object[] finderArgs = null;
7013    
7014                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7015                                    (orderByComparator == null)) {
7016                            pagination = false;
7017                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7018                            finderArgs = FINDER_ARGS_EMPTY;
7019                    }
7020                    else {
7021                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7022                            finderArgs = new Object[] { start, end, orderByComparator };
7023                    }
7024    
7025                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
7026                                    finderArgs, this);
7027    
7028                    if (list == null) {
7029                            StringBundler query = null;
7030                            String sql = null;
7031    
7032                            if (orderByComparator != null) {
7033                                    query = new StringBundler(2 +
7034                                                    (orderByComparator.getOrderByFields().length * 3));
7035    
7036                                    query.append(_SQL_SELECT_GROUP_);
7037    
7038                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7039                                            orderByComparator);
7040    
7041                                    sql = query.toString();
7042                            }
7043                            else {
7044                                    sql = _SQL_SELECT_GROUP_;
7045    
7046                                    if (pagination) {
7047                                            sql = sql.concat(GroupModelImpl.ORDER_BY_JPQL);
7048                                    }
7049                            }
7050    
7051                            Session session = null;
7052    
7053                            try {
7054                                    session = openSession();
7055    
7056                                    Query q = session.createQuery(sql);
7057    
7058                                    if (!pagination) {
7059                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
7060                                                            end, false);
7061    
7062                                            Collections.sort(list);
7063    
7064                                            list = new UnmodifiableList<Group>(list);
7065                                    }
7066                                    else {
7067                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
7068                                                            end);
7069                                    }
7070    
7071                                    cacheResult(list);
7072    
7073                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7074                            }
7075                            catch (Exception e) {
7076                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7077    
7078                                    throw processException(e);
7079                            }
7080                            finally {
7081                                    closeSession(session);
7082                            }
7083                    }
7084    
7085                    return list;
7086            }
7087    
7088            /**
7089             * Removes all the groups from the database.
7090             *
7091             * @throws SystemException if a system exception occurred
7092             */
7093            public void removeAll() throws SystemException {
7094                    for (Group group : findAll()) {
7095                            remove(group);
7096                    }
7097            }
7098    
7099            /**
7100             * Returns the number of groups.
7101             *
7102             * @return the number of groups
7103             * @throws SystemException if a system exception occurred
7104             */
7105            public int countAll() throws SystemException {
7106                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7107                                    FINDER_ARGS_EMPTY, this);
7108    
7109                    if (count == null) {
7110                            Session session = null;
7111    
7112                            try {
7113                                    session = openSession();
7114    
7115                                    Query q = session.createQuery(_SQL_COUNT_GROUP_);
7116    
7117                                    count = (Long)q.uniqueResult();
7118    
7119                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7120                                            FINDER_ARGS_EMPTY, count);
7121                            }
7122                            catch (Exception e) {
7123                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7124                                            FINDER_ARGS_EMPTY);
7125    
7126                                    throw processException(e);
7127                            }
7128                            finally {
7129                                    closeSession(session);
7130                            }
7131                    }
7132    
7133                    return count.intValue();
7134            }
7135    
7136            /**
7137             * Returns all the organizations associated with the group.
7138             *
7139             * @param pk the primary key of the group
7140             * @return the organizations associated with the group
7141             * @throws SystemException if a system exception occurred
7142             */
7143            public List<com.liferay.portal.model.Organization> getOrganizations(long pk)
7144                    throws SystemException {
7145                    return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7146            }
7147    
7148            /**
7149             * Returns a range of all the organizations associated with the group.
7150             *
7151             * <p>
7152             * 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.GroupModelImpl}. 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.
7153             * </p>
7154             *
7155             * @param pk the primary key of the group
7156             * @param start the lower bound of the range of groups
7157             * @param end the upper bound of the range of groups (not inclusive)
7158             * @return the range of organizations associated with the group
7159             * @throws SystemException if a system exception occurred
7160             */
7161            public List<com.liferay.portal.model.Organization> getOrganizations(
7162                    long pk, int start, int end) throws SystemException {
7163                    return getOrganizations(pk, start, end, null);
7164            }
7165    
7166            public static final FinderPath FINDER_PATH_GET_ORGANIZATIONS = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7167                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS,
7168                            com.liferay.portal.model.impl.OrganizationImpl.class,
7169                            GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME, "getOrganizations",
7170                            new String[] {
7171                                    Long.class.getName(), Integer.class.getName(),
7172                                    Integer.class.getName(), OrderByComparator.class.getName()
7173                            });
7174    
7175            static {
7176                    FINDER_PATH_GET_ORGANIZATIONS.setCacheKeyGeneratorCacheName(null);
7177            }
7178    
7179            /**
7180             * Returns an ordered range of all the organizations associated with the group.
7181             *
7182             * <p>
7183             * 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.GroupModelImpl}. 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.
7184             * </p>
7185             *
7186             * @param pk the primary key of the group
7187             * @param start the lower bound of the range of groups
7188             * @param end the upper bound of the range of groups (not inclusive)
7189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7190             * @return the ordered range of organizations associated with the group
7191             * @throws SystemException if a system exception occurred
7192             */
7193            public List<com.liferay.portal.model.Organization> getOrganizations(
7194                    long pk, int start, int end, OrderByComparator orderByComparator)
7195                    throws SystemException {
7196                    boolean pagination = true;
7197                    Object[] finderArgs = null;
7198    
7199                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7200                                    (orderByComparator == null)) {
7201                            pagination = false;
7202                            finderArgs = new Object[] { pk };
7203                    }
7204                    else {
7205                            finderArgs = new Object[] { pk, start, end, orderByComparator };
7206                    }
7207    
7208                    List<com.liferay.portal.model.Organization> list = (List<com.liferay.portal.model.Organization>)FinderCacheUtil.getResult(FINDER_PATH_GET_ORGANIZATIONS,
7209                                    finderArgs, this);
7210    
7211                    if (list == null) {
7212                            Session session = null;
7213    
7214                            try {
7215                                    session = openSession();
7216    
7217                                    String sql = null;
7218    
7219                                    if (orderByComparator != null) {
7220                                            sql = _SQL_GETORGANIZATIONS.concat(ORDER_BY_CLAUSE)
7221                                                                                               .concat(orderByComparator.getOrderBy());
7222                                    }
7223                                    else {
7224                                            sql = _SQL_GETORGANIZATIONS;
7225    
7226                                            if (pagination) {
7227                                                    sql = sql.concat(com.liferay.portal.model.impl.OrganizationModelImpl.ORDER_BY_SQL);
7228                                            }
7229                                    }
7230    
7231                                    SQLQuery q = session.createSQLQuery(sql);
7232    
7233                                    q.addEntity("Organization_",
7234                                            com.liferay.portal.model.impl.OrganizationImpl.class);
7235    
7236                                    QueryPos qPos = QueryPos.getInstance(q);
7237    
7238                                    qPos.add(pk);
7239    
7240                                    if (!pagination) {
7241                                            list = (List<com.liferay.portal.model.Organization>)QueryUtil.list(q,
7242                                                            getDialect(), start, end, false);
7243    
7244                                            Collections.sort(list);
7245    
7246                                            list = new UnmodifiableList<com.liferay.portal.model.Organization>(list);
7247                                    }
7248                                    else {
7249                                            list = (List<com.liferay.portal.model.Organization>)QueryUtil.list(q,
7250                                                            getDialect(), start, end);
7251                                    }
7252    
7253                                    organizationPersistence.cacheResult(list);
7254    
7255                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ORGANIZATIONS,
7256                                            finderArgs, list);
7257                            }
7258                            catch (Exception e) {
7259                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ORGANIZATIONS,
7260                                            finderArgs);
7261    
7262                                    throw processException(e);
7263                            }
7264                            finally {
7265                                    closeSession(session);
7266                            }
7267                    }
7268    
7269                    return list;
7270            }
7271    
7272            public static final FinderPath FINDER_PATH_GET_ORGANIZATIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7273                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, Long.class,
7274                            GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
7275                            "getOrganizationsSize", new String[] { Long.class.getName() });
7276    
7277            static {
7278                    FINDER_PATH_GET_ORGANIZATIONS_SIZE.setCacheKeyGeneratorCacheName(null);
7279            }
7280    
7281            /**
7282             * Returns the number of organizations associated with the group.
7283             *
7284             * @param pk the primary key of the group
7285             * @return the number of organizations associated with the group
7286             * @throws SystemException if a system exception occurred
7287             */
7288            public int getOrganizationsSize(long pk) throws SystemException {
7289                    Object[] finderArgs = new Object[] { pk };
7290    
7291                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
7292                                    finderArgs, this);
7293    
7294                    if (count == null) {
7295                            Session session = null;
7296    
7297                            try {
7298                                    session = openSession();
7299    
7300                                    SQLQuery q = session.createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
7301    
7302                                    q.addScalar(COUNT_COLUMN_NAME,
7303                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
7304    
7305                                    QueryPos qPos = QueryPos.getInstance(q);
7306    
7307                                    qPos.add(pk);
7308    
7309                                    count = (Long)q.uniqueResult();
7310    
7311                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
7312                                            finderArgs, count);
7313                            }
7314                            catch (Exception e) {
7315                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
7316                                            finderArgs);
7317    
7318                                    throw processException(e);
7319                            }
7320                            finally {
7321                                    closeSession(session);
7322                            }
7323                    }
7324    
7325                    return count.intValue();
7326            }
7327    
7328            public static final FinderPath FINDER_PATH_CONTAINS_ORGANIZATION = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
7329                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, Boolean.class,
7330                            GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME,
7331                            "containsOrganization",
7332                            new String[] { Long.class.getName(), Long.class.getName() });
7333    
7334            /**
7335             * Returns <code>true</code> if the organization is associated with the group.
7336             *
7337             * @param pk the primary key of the group
7338             * @param organizationPK the primary key of the organization
7339             * @return <code>true</code> if the organization is associated with the group; <code>false</code> otherwise
7340             * @throws SystemException if a system exception occurred
7341             */
7342            public boolean containsOrganization(long pk, long organizationPK)
7343                    throws SystemException {
7344                    Object[] finderArgs = new Object[] { pk, organizationPK };
7345    
7346                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ORGANIZATION,
7347                                    finderArgs, this);
7348    
7349                    if (value == null) {
7350                            try {
7351                                    value = Boolean.valueOf(containsOrganization.contains(pk,
7352                                                            organizationPK));
7353    
7354                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ORGANIZATION,
7355                                            finderArgs, value);
7356                            }
7357                            catch (Exception e) {
7358                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_ORGANIZATION,
7359                                            finderArgs);
7360    
7361                                    throw processException(e);
7362                            }
7363                    }
7364    
7365                    return value.booleanValue();
7366            }
7367    
7368            /**
7369             * Returns <code>true</code> if the group has any organizations associated with it.
7370             *
7371             * @param pk the primary key of the group to check for associations with organizations
7372             * @return <code>true</code> if the group has any organizations associated with it; <code>false</code> otherwise
7373             * @throws SystemException if a system exception occurred
7374             */
7375            public boolean containsOrganizations(long pk) throws SystemException {
7376                    if (getOrganizationsSize(pk) > 0) {
7377                            return true;
7378                    }
7379                    else {
7380                            return false;
7381                    }
7382            }
7383    
7384            /**
7385             * Adds an association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7386             *
7387             * @param pk the primary key of the group
7388             * @param organizationPK the primary key of the organization
7389             * @throws SystemException if a system exception occurred
7390             */
7391            public void addOrganization(long pk, long organizationPK)
7392                    throws SystemException {
7393                    try {
7394                            addOrganization.add(pk, organizationPK);
7395                    }
7396                    catch (Exception e) {
7397                            throw processException(e);
7398                    }
7399                    finally {
7400                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7401                    }
7402            }
7403    
7404            /**
7405             * Adds an association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7406             *
7407             * @param pk the primary key of the group
7408             * @param organization the organization
7409             * @throws SystemException if a system exception occurred
7410             */
7411            public void addOrganization(long pk,
7412                    com.liferay.portal.model.Organization organization)
7413                    throws SystemException {
7414                    try {
7415                            addOrganization.add(pk, organization.getPrimaryKey());
7416                    }
7417                    catch (Exception e) {
7418                            throw processException(e);
7419                    }
7420                    finally {
7421                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7422                    }
7423            }
7424    
7425            /**
7426             * Adds an association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7427             *
7428             * @param pk the primary key of the group
7429             * @param organizationPKs the primary keys of the organizations
7430             * @throws SystemException if a system exception occurred
7431             */
7432            public void addOrganizations(long pk, long[] organizationPKs)
7433                    throws SystemException {
7434                    try {
7435                            for (long organizationPK : organizationPKs) {
7436                                    addOrganization.add(pk, organizationPK);
7437                            }
7438                    }
7439                    catch (Exception e) {
7440                            throw processException(e);
7441                    }
7442                    finally {
7443                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7444                    }
7445            }
7446    
7447            /**
7448             * Adds an association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7449             *
7450             * @param pk the primary key of the group
7451             * @param organizations the organizations
7452             * @throws SystemException if a system exception occurred
7453             */
7454            public void addOrganizations(long pk,
7455                    List<com.liferay.portal.model.Organization> organizations)
7456                    throws SystemException {
7457                    try {
7458                            for (com.liferay.portal.model.Organization organization : organizations) {
7459                                    addOrganization.add(pk, organization.getPrimaryKey());
7460                            }
7461                    }
7462                    catch (Exception e) {
7463                            throw processException(e);
7464                    }
7465                    finally {
7466                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7467                    }
7468            }
7469    
7470            /**
7471             * Clears all associations between the group and its organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7472             *
7473             * @param pk the primary key of the group to clear the associated organizations from
7474             * @throws SystemException if a system exception occurred
7475             */
7476            public void clearOrganizations(long pk) throws SystemException {
7477                    try {
7478                            clearOrganizations.clear(pk);
7479                    }
7480                    catch (Exception e) {
7481                            throw processException(e);
7482                    }
7483                    finally {
7484                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7485                    }
7486            }
7487    
7488            /**
7489             * Removes the association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7490             *
7491             * @param pk the primary key of the group
7492             * @param organizationPK the primary key of the organization
7493             * @throws SystemException if a system exception occurred
7494             */
7495            public void removeOrganization(long pk, long organizationPK)
7496                    throws SystemException {
7497                    try {
7498                            removeOrganization.remove(pk, organizationPK);
7499                    }
7500                    catch (Exception e) {
7501                            throw processException(e);
7502                    }
7503                    finally {
7504                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7505                    }
7506            }
7507    
7508            /**
7509             * Removes the association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7510             *
7511             * @param pk the primary key of the group
7512             * @param organization the organization
7513             * @throws SystemException if a system exception occurred
7514             */
7515            public void removeOrganization(long pk,
7516                    com.liferay.portal.model.Organization organization)
7517                    throws SystemException {
7518                    try {
7519                            removeOrganization.remove(pk, organization.getPrimaryKey());
7520                    }
7521                    catch (Exception e) {
7522                            throw processException(e);
7523                    }
7524                    finally {
7525                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7526                    }
7527            }
7528    
7529            /**
7530             * Removes the association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7531             *
7532             * @param pk the primary key of the group
7533             * @param organizationPKs the primary keys of the organizations
7534             * @throws SystemException if a system exception occurred
7535             */
7536            public void removeOrganizations(long pk, long[] organizationPKs)
7537                    throws SystemException {
7538                    try {
7539                            for (long organizationPK : organizationPKs) {
7540                                    removeOrganization.remove(pk, organizationPK);
7541                            }
7542                    }
7543                    catch (Exception e) {
7544                            throw processException(e);
7545                    }
7546                    finally {
7547                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7548                    }
7549            }
7550    
7551            /**
7552             * Removes the association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7553             *
7554             * @param pk the primary key of the group
7555             * @param organizations the organizations
7556             * @throws SystemException if a system exception occurred
7557             */
7558            public void removeOrganizations(long pk,
7559                    List<com.liferay.portal.model.Organization> organizations)
7560                    throws SystemException {
7561                    try {
7562                            for (com.liferay.portal.model.Organization organization : organizations) {
7563                                    removeOrganization.remove(pk, organization.getPrimaryKey());
7564                            }
7565                    }
7566                    catch (Exception e) {
7567                            throw processException(e);
7568                    }
7569                    finally {
7570                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7571                    }
7572            }
7573    
7574            /**
7575             * Sets the organizations associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7576             *
7577             * @param pk the primary key of the group
7578             * @param organizationPKs the primary keys of the organizations to be associated with the group
7579             * @throws SystemException if a system exception occurred
7580             */
7581            public void setOrganizations(long pk, long[] organizationPKs)
7582                    throws SystemException {
7583                    try {
7584                            Set<Long> organizationPKSet = SetUtil.fromArray(organizationPKs);
7585    
7586                            List<com.liferay.portal.model.Organization> organizations = getOrganizations(pk);
7587    
7588                            for (com.liferay.portal.model.Organization organization : organizations) {
7589                                    if (!organizationPKSet.remove(organization.getPrimaryKey())) {
7590                                            removeOrganization.remove(pk, organization.getPrimaryKey());
7591                                    }
7592                            }
7593    
7594                            for (Long organizationPK : organizationPKSet) {
7595                                    addOrganization.add(pk, organizationPK);
7596                            }
7597                    }
7598                    catch (Exception e) {
7599                            throw processException(e);
7600                    }
7601                    finally {
7602                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7603                    }
7604            }
7605    
7606            /**
7607             * Sets the organizations associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7608             *
7609             * @param pk the primary key of the group
7610             * @param organizations the organizations to be associated with the group
7611             * @throws SystemException if a system exception occurred
7612             */
7613            public void setOrganizations(long pk,
7614                    List<com.liferay.portal.model.Organization> organizations)
7615                    throws SystemException {
7616                    try {
7617                            long[] organizationPKs = new long[organizations.size()];
7618    
7619                            for (int i = 0; i < organizations.size(); i++) {
7620                                    com.liferay.portal.model.Organization organization = organizations.get(i);
7621    
7622                                    organizationPKs[i] = organization.getPrimaryKey();
7623                            }
7624    
7625                            setOrganizations(pk, organizationPKs);
7626                    }
7627                    catch (Exception e) {
7628                            throw processException(e);
7629                    }
7630                    finally {
7631                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
7632                    }
7633            }
7634    
7635            /**
7636             * Returns all the roles associated with the group.
7637             *
7638             * @param pk the primary key of the group
7639             * @return the roles associated with the group
7640             * @throws SystemException if a system exception occurred
7641             */
7642            public List<com.liferay.portal.model.Role> getRoles(long pk)
7643                    throws SystemException {
7644                    return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7645            }
7646    
7647            /**
7648             * Returns a range of all the roles associated with the group.
7649             *
7650             * <p>
7651             * 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.GroupModelImpl}. 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.
7652             * </p>
7653             *
7654             * @param pk the primary key of the group
7655             * @param start the lower bound of the range of groups
7656             * @param end the upper bound of the range of groups (not inclusive)
7657             * @return the range of roles associated with the group
7658             * @throws SystemException if a system exception occurred
7659             */
7660            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
7661                    int end) throws SystemException {
7662                    return getRoles(pk, start, end, null);
7663            }
7664    
7665            public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
7666                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
7667                            com.liferay.portal.model.impl.RoleImpl.class,
7668                            GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getRoles",
7669                            new String[] {
7670                                    Long.class.getName(), Integer.class.getName(),
7671                                    Integer.class.getName(), OrderByComparator.class.getName()
7672                            });
7673    
7674            static {
7675                    FINDER_PATH_GET_ROLES.setCacheKeyGeneratorCacheName(null);
7676            }
7677    
7678            /**
7679             * Returns an ordered range of all the roles associated with the group.
7680             *
7681             * <p>
7682             * 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.GroupModelImpl}. 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.
7683             * </p>
7684             *
7685             * @param pk the primary key of the group
7686             * @param start the lower bound of the range of groups
7687             * @param end the upper bound of the range of groups (not inclusive)
7688             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7689             * @return the ordered range of roles associated with the group
7690             * @throws SystemException if a system exception occurred
7691             */
7692            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
7693                    int end, OrderByComparator orderByComparator) throws SystemException {
7694                    boolean pagination = true;
7695                    Object[] finderArgs = null;
7696    
7697                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7698                                    (orderByComparator == null)) {
7699                            pagination = false;
7700                            finderArgs = new Object[] { pk };
7701                    }
7702                    else {
7703                            finderArgs = new Object[] { pk, start, end, orderByComparator };
7704                    }
7705    
7706                    List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
7707                                    finderArgs, this);
7708    
7709                    if (list == null) {
7710                            Session session = null;
7711    
7712                            try {
7713                                    session = openSession();
7714    
7715                                    String sql = null;
7716    
7717                                    if (orderByComparator != null) {
7718                                            sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
7719                                                                               .concat(orderByComparator.getOrderBy());
7720                                    }
7721                                    else {
7722                                            sql = _SQL_GETROLES;
7723    
7724                                            if (pagination) {
7725                                                    sql = sql.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
7726                                            }
7727                                    }
7728    
7729                                    SQLQuery q = session.createSQLQuery(sql);
7730    
7731                                    q.addEntity("Role_",
7732                                            com.liferay.portal.model.impl.RoleImpl.class);
7733    
7734                                    QueryPos qPos = QueryPos.getInstance(q);
7735    
7736                                    qPos.add(pk);
7737    
7738                                    if (!pagination) {
7739                                            list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
7740                                                            getDialect(), start, end, false);
7741    
7742                                            Collections.sort(list);
7743    
7744                                            list = new UnmodifiableList<com.liferay.portal.model.Role>(list);
7745                                    }
7746                                    else {
7747                                            list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
7748                                                            getDialect(), start, end);
7749                                    }
7750    
7751                                    rolePersistence.cacheResult(list);
7752    
7753                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES, finderArgs,
7754                                            list);
7755                            }
7756                            catch (Exception e) {
7757                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ROLES, finderArgs);
7758    
7759                                    throw processException(e);
7760                            }
7761                            finally {
7762                                    closeSession(session);
7763                            }
7764                    }
7765    
7766                    return list;
7767            }
7768    
7769            public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
7770                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Long.class,
7771                            GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getRolesSize",
7772                            new String[] { Long.class.getName() });
7773    
7774            static {
7775                    FINDER_PATH_GET_ROLES_SIZE.setCacheKeyGeneratorCacheName(null);
7776            }
7777    
7778            /**
7779             * Returns the number of roles associated with the group.
7780             *
7781             * @param pk the primary key of the group
7782             * @return the number of roles associated with the group
7783             * @throws SystemException if a system exception occurred
7784             */
7785            public int getRolesSize(long pk) throws SystemException {
7786                    Object[] finderArgs = new Object[] { pk };
7787    
7788                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
7789                                    finderArgs, this);
7790    
7791                    if (count == null) {
7792                            Session session = null;
7793    
7794                            try {
7795                                    session = openSession();
7796    
7797                                    SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
7798    
7799                                    q.addScalar(COUNT_COLUMN_NAME,
7800                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
7801    
7802                                    QueryPos qPos = QueryPos.getInstance(q);
7803    
7804                                    qPos.add(pk);
7805    
7806                                    count = (Long)q.uniqueResult();
7807    
7808                                    FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
7809                                            finderArgs, count);
7810                            }
7811                            catch (Exception e) {
7812                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_ROLES_SIZE,
7813                                            finderArgs);
7814    
7815                                    throw processException(e);
7816                            }
7817                            finally {
7818                                    closeSession(session);
7819                            }
7820                    }
7821    
7822                    return count.intValue();
7823            }
7824    
7825            public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
7826                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Boolean.class,
7827                            GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "containsRole",
7828                            new String[] { Long.class.getName(), Long.class.getName() });
7829    
7830            /**
7831             * Returns <code>true</code> if the role is associated with the group.
7832             *
7833             * @param pk the primary key of the group
7834             * @param rolePK the primary key of the role
7835             * @return <code>true</code> if the role is associated with the group; <code>false</code> otherwise
7836             * @throws SystemException if a system exception occurred
7837             */
7838            public boolean containsRole(long pk, long rolePK) throws SystemException {
7839                    Object[] finderArgs = new Object[] { pk, rolePK };
7840    
7841                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
7842                                    finderArgs, this);
7843    
7844                    if (value == null) {
7845                            try {
7846                                    value = Boolean.valueOf(containsRole.contains(pk, rolePK));
7847    
7848                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
7849                                            finderArgs, value);
7850                            }
7851                            catch (Exception e) {
7852                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_ROLE,
7853                                            finderArgs);
7854    
7855                                    throw processException(e);
7856                            }
7857                    }
7858    
7859                    return value.booleanValue();
7860            }
7861    
7862            /**
7863             * Returns <code>true</code> if the group has any roles associated with it.
7864             *
7865             * @param pk the primary key of the group to check for associations with roles
7866             * @return <code>true</code> if the group has any roles associated with it; <code>false</code> otherwise
7867             * @throws SystemException if a system exception occurred
7868             */
7869            public boolean containsRoles(long pk) throws SystemException {
7870                    if (getRolesSize(pk) > 0) {
7871                            return true;
7872                    }
7873                    else {
7874                            return false;
7875                    }
7876            }
7877    
7878            /**
7879             * Adds an association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7880             *
7881             * @param pk the primary key of the group
7882             * @param rolePK the primary key of the role
7883             * @throws SystemException if a system exception occurred
7884             */
7885            public void addRole(long pk, long rolePK) throws SystemException {
7886                    try {
7887                            addRole.add(pk, rolePK);
7888                    }
7889                    catch (Exception e) {
7890                            throw processException(e);
7891                    }
7892                    finally {
7893                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7894                    }
7895            }
7896    
7897            /**
7898             * Adds an association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7899             *
7900             * @param pk the primary key of the group
7901             * @param role the role
7902             * @throws SystemException if a system exception occurred
7903             */
7904            public void addRole(long pk, com.liferay.portal.model.Role role)
7905                    throws SystemException {
7906                    try {
7907                            addRole.add(pk, role.getPrimaryKey());
7908                    }
7909                    catch (Exception e) {
7910                            throw processException(e);
7911                    }
7912                    finally {
7913                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7914                    }
7915            }
7916    
7917            /**
7918             * Adds an association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7919             *
7920             * @param pk the primary key of the group
7921             * @param rolePKs the primary keys of the roles
7922             * @throws SystemException if a system exception occurred
7923             */
7924            public void addRoles(long pk, long[] rolePKs) throws SystemException {
7925                    try {
7926                            for (long rolePK : rolePKs) {
7927                                    addRole.add(pk, rolePK);
7928                            }
7929                    }
7930                    catch (Exception e) {
7931                            throw processException(e);
7932                    }
7933                    finally {
7934                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7935                    }
7936            }
7937    
7938            /**
7939             * Adds an association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7940             *
7941             * @param pk the primary key of the group
7942             * @param roles the roles
7943             * @throws SystemException if a system exception occurred
7944             */
7945            public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
7946                    throws SystemException {
7947                    try {
7948                            for (com.liferay.portal.model.Role role : roles) {
7949                                    addRole.add(pk, role.getPrimaryKey());
7950                            }
7951                    }
7952                    catch (Exception e) {
7953                            throw processException(e);
7954                    }
7955                    finally {
7956                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7957                    }
7958            }
7959    
7960            /**
7961             * Clears all associations between the group and its roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7962             *
7963             * @param pk the primary key of the group to clear the associated roles from
7964             * @throws SystemException if a system exception occurred
7965             */
7966            public void clearRoles(long pk) throws SystemException {
7967                    try {
7968                            clearRoles.clear(pk);
7969                    }
7970                    catch (Exception e) {
7971                            throw processException(e);
7972                    }
7973                    finally {
7974                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7975                    }
7976            }
7977    
7978            /**
7979             * Removes the association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7980             *
7981             * @param pk the primary key of the group
7982             * @param rolePK the primary key of the role
7983             * @throws SystemException if a system exception occurred
7984             */
7985            public void removeRole(long pk, long rolePK) throws SystemException {
7986                    try {
7987                            removeRole.remove(pk, rolePK);
7988                    }
7989                    catch (Exception e) {
7990                            throw processException(e);
7991                    }
7992                    finally {
7993                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7994                    }
7995            }
7996    
7997            /**
7998             * Removes the association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
7999             *
8000             * @param pk the primary key of the group
8001             * @param role the role
8002             * @throws SystemException if a system exception occurred
8003             */
8004            public void removeRole(long pk, com.liferay.portal.model.Role role)
8005                    throws SystemException {
8006                    try {
8007                            removeRole.remove(pk, role.getPrimaryKey());
8008                    }
8009                    catch (Exception e) {
8010                            throw processException(e);
8011                    }
8012                    finally {
8013                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8014                    }
8015            }
8016    
8017            /**
8018             * Removes the association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8019             *
8020             * @param pk the primary key of the group
8021             * @param rolePKs the primary keys of the roles
8022             * @throws SystemException if a system exception occurred
8023             */
8024            public void removeRoles(long pk, long[] rolePKs) throws SystemException {
8025                    try {
8026                            for (long rolePK : rolePKs) {
8027                                    removeRole.remove(pk, rolePK);
8028                            }
8029                    }
8030                    catch (Exception e) {
8031                            throw processException(e);
8032                    }
8033                    finally {
8034                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8035                    }
8036            }
8037    
8038            /**
8039             * Removes the association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8040             *
8041             * @param pk the primary key of the group
8042             * @param roles the roles
8043             * @throws SystemException if a system exception occurred
8044             */
8045            public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
8046                    throws SystemException {
8047                    try {
8048                            for (com.liferay.portal.model.Role role : roles) {
8049                                    removeRole.remove(pk, role.getPrimaryKey());
8050                            }
8051                    }
8052                    catch (Exception e) {
8053                            throw processException(e);
8054                    }
8055                    finally {
8056                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8057                    }
8058            }
8059    
8060            /**
8061             * Sets the roles associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8062             *
8063             * @param pk the primary key of the group
8064             * @param rolePKs the primary keys of the roles to be associated with the group
8065             * @throws SystemException if a system exception occurred
8066             */
8067            public void setRoles(long pk, long[] rolePKs) throws SystemException {
8068                    try {
8069                            Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
8070    
8071                            List<com.liferay.portal.model.Role> roles = getRoles(pk);
8072    
8073                            for (com.liferay.portal.model.Role role : roles) {
8074                                    if (!rolePKSet.remove(role.getPrimaryKey())) {
8075                                            removeRole.remove(pk, role.getPrimaryKey());
8076                                    }
8077                            }
8078    
8079                            for (Long rolePK : rolePKSet) {
8080                                    addRole.add(pk, rolePK);
8081                            }
8082                    }
8083                    catch (Exception e) {
8084                            throw processException(e);
8085                    }
8086                    finally {
8087                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8088                    }
8089            }
8090    
8091            /**
8092             * Sets the roles associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8093             *
8094             * @param pk the primary key of the group
8095             * @param roles the roles to be associated with the group
8096             * @throws SystemException if a system exception occurred
8097             */
8098            public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
8099                    throws SystemException {
8100                    try {
8101                            long[] rolePKs = new long[roles.size()];
8102    
8103                            for (int i = 0; i < roles.size(); i++) {
8104                                    com.liferay.portal.model.Role role = roles.get(i);
8105    
8106                                    rolePKs[i] = role.getPrimaryKey();
8107                            }
8108    
8109                            setRoles(pk, rolePKs);
8110                    }
8111                    catch (Exception e) {
8112                            throw processException(e);
8113                    }
8114                    finally {
8115                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8116                    }
8117            }
8118    
8119            /**
8120             * Returns all the user groups associated with the group.
8121             *
8122             * @param pk the primary key of the group
8123             * @return the user groups associated with the group
8124             * @throws SystemException if a system exception occurred
8125             */
8126            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
8127                    throws SystemException {
8128                    return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8129            }
8130    
8131            /**
8132             * Returns a range of all the user groups associated with the group.
8133             *
8134             * <p>
8135             * 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.GroupModelImpl}. 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.
8136             * </p>
8137             *
8138             * @param pk the primary key of the group
8139             * @param start the lower bound of the range of groups
8140             * @param end the upper bound of the range of groups (not inclusive)
8141             * @return the range of user groups associated with the group
8142             * @throws SystemException if a system exception occurred
8143             */
8144            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
8145                    int start, int end) throws SystemException {
8146                    return getUserGroups(pk, start, end, null);
8147            }
8148    
8149            public static final FinderPath FINDER_PATH_GET_USERGROUPS = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
8150                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
8151                            com.liferay.portal.model.impl.UserGroupImpl.class,
8152                            GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
8153                            "getUserGroups",
8154                            new String[] {
8155                                    Long.class.getName(), Integer.class.getName(),
8156                                    Integer.class.getName(), OrderByComparator.class.getName()
8157                            });
8158    
8159            static {
8160                    FINDER_PATH_GET_USERGROUPS.setCacheKeyGeneratorCacheName(null);
8161            }
8162    
8163            /**
8164             * Returns an ordered range of all the user groups associated with the group.
8165             *
8166             * <p>
8167             * 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.GroupModelImpl}. 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.
8168             * </p>
8169             *
8170             * @param pk the primary key of the group
8171             * @param start the lower bound of the range of groups
8172             * @param end the upper bound of the range of groups (not inclusive)
8173             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8174             * @return the ordered range of user groups associated with the group
8175             * @throws SystemException if a system exception occurred
8176             */
8177            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
8178                    int start, int end, OrderByComparator orderByComparator)
8179                    throws SystemException {
8180                    boolean pagination = true;
8181                    Object[] finderArgs = null;
8182    
8183                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8184                                    (orderByComparator == null)) {
8185                            pagination = false;
8186                            finderArgs = new Object[] { pk };
8187                    }
8188                    else {
8189                            finderArgs = new Object[] { pk, start, end, orderByComparator };
8190                    }
8191    
8192                    List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS,
8193                                    finderArgs, this);
8194    
8195                    if (list == null) {
8196                            Session session = null;
8197    
8198                            try {
8199                                    session = openSession();
8200    
8201                                    String sql = null;
8202    
8203                                    if (orderByComparator != null) {
8204                                            sql = _SQL_GETUSERGROUPS.concat(ORDER_BY_CLAUSE)
8205                                                                                            .concat(orderByComparator.getOrderBy());
8206                                    }
8207                                    else {
8208                                            sql = _SQL_GETUSERGROUPS;
8209    
8210                                            if (pagination) {
8211                                                    sql = sql.concat(com.liferay.portal.model.impl.UserGroupModelImpl.ORDER_BY_SQL);
8212                                            }
8213                                    }
8214    
8215                                    SQLQuery q = session.createSQLQuery(sql);
8216    
8217                                    q.addEntity("UserGroup",
8218                                            com.liferay.portal.model.impl.UserGroupImpl.class);
8219    
8220                                    QueryPos qPos = QueryPos.getInstance(q);
8221    
8222                                    qPos.add(pk);
8223    
8224                                    if (!pagination) {
8225                                            list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
8226                                                            getDialect(), start, end, false);
8227    
8228                                            Collections.sort(list);
8229    
8230                                            list = new UnmodifiableList<com.liferay.portal.model.UserGroup>(list);
8231                                    }
8232                                    else {
8233                                            list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
8234                                                            getDialect(), start, end);
8235                                    }
8236    
8237                                    userGroupPersistence.cacheResult(list);
8238    
8239                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS,
8240                                            finderArgs, list);
8241                            }
8242                            catch (Exception e) {
8243                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_USERGROUPS,
8244                                            finderArgs);
8245    
8246                                    throw processException(e);
8247                            }
8248                            finally {
8249                                    closeSession(session);
8250                            }
8251                    }
8252    
8253                    return list;
8254            }
8255    
8256            public static final FinderPath FINDER_PATH_GET_USERGROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
8257                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS, Long.class,
8258                            GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
8259                            "getUserGroupsSize", new String[] { Long.class.getName() });
8260    
8261            static {
8262                    FINDER_PATH_GET_USERGROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
8263            }
8264    
8265            /**
8266             * Returns the number of user groups associated with the group.
8267             *
8268             * @param pk the primary key of the group
8269             * @return the number of user groups associated with the group
8270             * @throws SystemException if a system exception occurred
8271             */
8272            public int getUserGroupsSize(long pk) throws SystemException {
8273                    Object[] finderArgs = new Object[] { pk };
8274    
8275                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS_SIZE,
8276                                    finderArgs, this);
8277    
8278                    if (count == null) {
8279                            Session session = null;
8280    
8281                            try {
8282                                    session = openSession();
8283    
8284                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
8285    
8286                                    q.addScalar(COUNT_COLUMN_NAME,
8287                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
8288    
8289                                    QueryPos qPos = QueryPos.getInstance(q);
8290    
8291                                    qPos.add(pk);
8292    
8293                                    count = (Long)q.uniqueResult();
8294    
8295                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS_SIZE,
8296                                            finderArgs, count);
8297                            }
8298                            catch (Exception e) {
8299                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_USERGROUPS_SIZE,
8300                                            finderArgs);
8301    
8302                                    throw processException(e);
8303                            }
8304                            finally {
8305                                    closeSession(session);
8306                            }
8307                    }
8308    
8309                    return count.intValue();
8310            }
8311    
8312            public static final FinderPath FINDER_PATH_CONTAINS_USERGROUP = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
8313                            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
8314                            Boolean.class, GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME,
8315                            "containsUserGroup",
8316                            new String[] { Long.class.getName(), Long.class.getName() });
8317    
8318            /**
8319             * Returns <code>true</code> if the user group is associated with the group.
8320             *
8321             * @param pk the primary key of the group
8322             * @param userGroupPK the primary key of the user group
8323             * @return <code>true</code> if the user group is associated with the group; <code>false</code> otherwise
8324             * @throws SystemException if a system exception occurred
8325             */
8326            public boolean containsUserGroup(long pk, long userGroupPK)
8327                    throws SystemException {
8328                    Object[] finderArgs = new Object[] { pk, userGroupPK };
8329    
8330                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USERGROUP,
8331                                    finderArgs, this);
8332    
8333                    if (value == null) {
8334                            try {
8335                                    value = Boolean.valueOf(containsUserGroup.contains(pk,
8336                                                            userGroupPK));
8337    
8338                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USERGROUP,
8339                                            finderArgs, value);
8340                            }
8341                            catch (Exception e) {
8342                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USERGROUP,
8343                                            finderArgs);
8344    
8345                                    throw processException(e);
8346                            }
8347                    }
8348    
8349                    return value.booleanValue();
8350            }
8351    
8352            /**
8353             * Returns <code>true</code> if the group has any user groups associated with it.
8354             *
8355             * @param pk the primary key of the group to check for associations with user groups
8356             * @return <code>true</code> if the group has any user groups associated with it; <code>false</code> otherwise
8357             * @throws SystemException if a system exception occurred
8358             */
8359            public boolean containsUserGroups(long pk) throws SystemException {
8360                    if (getUserGroupsSize(pk) > 0) {
8361                            return true;
8362                    }
8363                    else {
8364                            return false;
8365                    }
8366            }
8367    
8368            /**
8369             * Adds an association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8370             *
8371             * @param pk the primary key of the group
8372             * @param userGroupPK the primary key of the user group
8373             * @throws SystemException if a system exception occurred
8374             */
8375            public void addUserGroup(long pk, long userGroupPK)
8376                    throws SystemException {
8377                    try {
8378                            addUserGroup.add(pk, userGroupPK);
8379                    }
8380                    catch (Exception e) {
8381                            throw processException(e);
8382                    }
8383                    finally {
8384                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8385                    }
8386            }
8387    
8388            /**
8389             * Adds an association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8390             *
8391             * @param pk the primary key of the group
8392             * @param userGroup the user group
8393             * @throws SystemException if a system exception occurred
8394             */
8395            public void addUserGroup(long pk,
8396                    com.liferay.portal.model.UserGroup userGroup) throws SystemException {
8397                    try {
8398                            addUserGroup.add(pk, userGroup.getPrimaryKey());
8399                    }
8400                    catch (Exception e) {
8401                            throw processException(e);
8402                    }
8403                    finally {
8404                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8405                    }
8406            }
8407    
8408            /**
8409             * Adds an association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8410             *
8411             * @param pk the primary key of the group
8412             * @param userGroupPKs the primary keys of the user groups
8413             * @throws SystemException if a system exception occurred
8414             */
8415            public void addUserGroups(long pk, long[] userGroupPKs)
8416                    throws SystemException {
8417                    try {
8418                            for (long userGroupPK : userGroupPKs) {
8419                                    addUserGroup.add(pk, userGroupPK);
8420                            }
8421                    }
8422                    catch (Exception e) {
8423                            throw processException(e);
8424                    }
8425                    finally {
8426                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8427                    }
8428            }
8429    
8430            /**
8431             * Adds an association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8432             *
8433             * @param pk the primary key of the group
8434             * @param userGroups the user groups
8435             * @throws SystemException if a system exception occurred
8436             */
8437            public void addUserGroups(long pk,
8438                    List<com.liferay.portal.model.UserGroup> userGroups)
8439                    throws SystemException {
8440                    try {
8441                            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
8442                                    addUserGroup.add(pk, userGroup.getPrimaryKey());
8443                            }
8444                    }
8445                    catch (Exception e) {
8446                            throw processException(e);
8447                    }
8448                    finally {
8449                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8450                    }
8451            }
8452    
8453            /**
8454             * Clears all associations between the group and its user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8455             *
8456             * @param pk the primary key of the group to clear the associated user groups from
8457             * @throws SystemException if a system exception occurred
8458             */
8459            public void clearUserGroups(long pk) throws SystemException {
8460                    try {
8461                            clearUserGroups.clear(pk);
8462                    }
8463                    catch (Exception e) {
8464                            throw processException(e);
8465                    }
8466                    finally {
8467                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8468                    }
8469            }
8470    
8471            /**
8472             * Removes the association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8473             *
8474             * @param pk the primary key of the group
8475             * @param userGroupPK the primary key of the user group
8476             * @throws SystemException if a system exception occurred
8477             */
8478            public void removeUserGroup(long pk, long userGroupPK)
8479                    throws SystemException {
8480                    try {
8481                            removeUserGroup.remove(pk, userGroupPK);
8482                    }
8483                    catch (Exception e) {
8484                            throw processException(e);
8485                    }
8486                    finally {
8487                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8488                    }
8489            }
8490    
8491            /**
8492             * Removes the association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8493             *
8494             * @param pk the primary key of the group
8495             * @param userGroup the user group
8496             * @throws SystemException if a system exception occurred
8497             */
8498            public void removeUserGroup(long pk,
8499                    com.liferay.portal.model.UserGroup userGroup) throws SystemException {
8500                    try {
8501                            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
8502                    }
8503                    catch (Exception e) {
8504                            throw processException(e);
8505                    }
8506                    finally {
8507                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8508                    }
8509            }
8510    
8511            /**
8512             * Removes the association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8513             *
8514             * @param pk the primary key of the group
8515             * @param userGroupPKs the primary keys of the user groups
8516             * @throws SystemException if a system exception occurred
8517             */
8518            public void removeUserGroups(long pk, long[] userGroupPKs)
8519                    throws SystemException {
8520                    try {
8521                            for (long userGroupPK : userGroupPKs) {
8522                                    removeUserGroup.remove(pk, userGroupPK);
8523                            }
8524                    }
8525                    catch (Exception e) {
8526                            throw processException(e);
8527                    }
8528                    finally {
8529                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8530                    }
8531            }
8532    
8533            /**
8534             * Removes the association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8535             *
8536             * @param pk the primary key of the group
8537             * @param userGroups the user groups
8538             * @throws SystemException if a system exception occurred
8539             */
8540            public void removeUserGroups(long pk,
8541                    List<com.liferay.portal.model.UserGroup> userGroups)
8542                    throws SystemException {
8543                    try {
8544                            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
8545                                    removeUserGroup.remove(pk, userGroup.getPrimaryKey());
8546                            }
8547                    }
8548                    catch (Exception e) {
8549                            throw processException(e);
8550                    }
8551                    finally {
8552                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8553                    }
8554            }
8555    
8556            /**
8557             * Sets the user groups associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8558             *
8559             * @param pk the primary key of the group
8560             * @param userGroupPKs the primary keys of the user groups to be associated with the group
8561             * @throws SystemException if a system exception occurred
8562             */
8563            public void setUserGroups(long pk, long[] userGroupPKs)
8564                    throws SystemException {
8565                    try {
8566                            Set<Long> userGroupPKSet = SetUtil.fromArray(userGroupPKs);
8567    
8568                            List<com.liferay.portal.model.UserGroup> userGroups = getUserGroups(pk);
8569    
8570                            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
8571                                    if (!userGroupPKSet.remove(userGroup.getPrimaryKey())) {
8572                                            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
8573                                    }
8574                            }
8575    
8576                            for (Long userGroupPK : userGroupPKSet) {
8577                                    addUserGroup.add(pk, userGroupPK);
8578                            }
8579                    }
8580                    catch (Exception e) {
8581                            throw processException(e);
8582                    }
8583                    finally {
8584                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8585                    }
8586            }
8587    
8588            /**
8589             * Sets the user groups associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8590             *
8591             * @param pk the primary key of the group
8592             * @param userGroups the user groups to be associated with the group
8593             * @throws SystemException if a system exception occurred
8594             */
8595            public void setUserGroups(long pk,
8596                    List<com.liferay.portal.model.UserGroup> userGroups)
8597                    throws SystemException {
8598                    try {
8599                            long[] userGroupPKs = new long[userGroups.size()];
8600    
8601                            for (int i = 0; i < userGroups.size(); i++) {
8602                                    com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
8603    
8604                                    userGroupPKs[i] = userGroup.getPrimaryKey();
8605                            }
8606    
8607                            setUserGroups(pk, userGroupPKs);
8608                    }
8609                    catch (Exception e) {
8610                            throw processException(e);
8611                    }
8612                    finally {
8613                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
8614                    }
8615            }
8616    
8617            /**
8618             * Returns all the users associated with the group.
8619             *
8620             * @param pk the primary key of the group
8621             * @return the users associated with the group
8622             * @throws SystemException if a system exception occurred
8623             */
8624            public List<com.liferay.portal.model.User> getUsers(long pk)
8625                    throws SystemException {
8626                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8627            }
8628    
8629            /**
8630             * Returns a range of all the users associated with the group.
8631             *
8632             * <p>
8633             * 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.GroupModelImpl}. 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.
8634             * </p>
8635             *
8636             * @param pk the primary key of the group
8637             * @param start the lower bound of the range of groups
8638             * @param end the upper bound of the range of groups (not inclusive)
8639             * @return the range of users associated with the group
8640             * @throws SystemException if a system exception occurred
8641             */
8642            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
8643                    int end) throws SystemException {
8644                    return getUsers(pk, start, end, null);
8645            }
8646    
8647            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
8648                            GroupModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS,
8649                            com.liferay.portal.model.impl.UserImpl.class,
8650                            GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME, "getUsers",
8651                            new String[] {
8652                                    Long.class.getName(), Integer.class.getName(),
8653                                    Integer.class.getName(), OrderByComparator.class.getName()
8654                            });
8655    
8656            static {
8657                    FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
8658            }
8659    
8660            /**
8661             * Returns an ordered range of all the users associated with the group.
8662             *
8663             * <p>
8664             * 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.GroupModelImpl}. 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.
8665             * </p>
8666             *
8667             * @param pk the primary key of the group
8668             * @param start the lower bound of the range of groups
8669             * @param end the upper bound of the range of groups (not inclusive)
8670             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8671             * @return the ordered range of users associated with the group
8672             * @throws SystemException if a system exception occurred
8673             */
8674            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
8675                    int end, OrderByComparator orderByComparator) throws SystemException {
8676                    boolean pagination = true;
8677                    Object[] finderArgs = null;
8678    
8679                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8680                                    (orderByComparator == null)) {
8681                            pagination = false;
8682                            finderArgs = new Object[] { pk };
8683                    }
8684                    else {
8685                            finderArgs = new Object[] { pk, start, end, orderByComparator };
8686                    }
8687    
8688                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
8689                                    finderArgs, this);
8690    
8691                    if (list == null) {
8692                            Session session = null;
8693    
8694                            try {
8695                                    session = openSession();
8696    
8697                                    String sql = null;
8698    
8699                                    if (orderByComparator != null) {
8700                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
8701                                                                               .concat(orderByComparator.getOrderBy());
8702                                    }
8703                                    else {
8704                                            sql = _SQL_GETUSERS;
8705    
8706                                            if (pagination) {
8707                                                    sql = sql.concat(com.liferay.portal.model.impl.UserModelImpl.ORDER_BY_SQL);
8708                                            }
8709                                    }
8710    
8711                                    SQLQuery q = session.createSQLQuery(sql);
8712    
8713                                    q.addEntity("User_",
8714                                            com.liferay.portal.model.impl.UserImpl.class);
8715    
8716                                    QueryPos qPos = QueryPos.getInstance(q);
8717    
8718                                    qPos.add(pk);
8719    
8720                                    if (!pagination) {
8721                                            list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
8722                                                            getDialect(), start, end, false);
8723    
8724                                            Collections.sort(list);
8725    
8726                                            list = new UnmodifiableList<com.liferay.portal.model.User>(list);
8727                                    }
8728                                    else {
8729                                            list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
8730                                                            getDialect(), start, end);
8731                                    }
8732    
8733                                    userPersistence.cacheResult(list);
8734    
8735                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
8736                                            list);
8737                            }
8738                            catch (Exception e) {
8739                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS, finderArgs);
8740    
8741                                    throw processException(e);
8742                            }
8743                            finally {
8744                                    closeSession(session);
8745                            }
8746                    }
8747    
8748                    return list;
8749            }
8750    
8751            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
8752                            GroupModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS, Long.class,
8753                            GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME, "getUsersSize",
8754                            new String[] { Long.class.getName() });
8755    
8756            static {
8757                    FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
8758            }
8759    
8760            /**
8761             * Returns the number of users associated with the group.
8762             *
8763             * @param pk the primary key of the group
8764             * @return the number of users associated with the group
8765             * @throws SystemException if a system exception occurred
8766             */
8767            public int getUsersSize(long pk) throws SystemException {
8768                    Object[] finderArgs = new Object[] { pk };
8769    
8770                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
8771                                    finderArgs, this);
8772    
8773                    if (count == null) {
8774                            Session session = null;
8775    
8776                            try {
8777                                    session = openSession();
8778    
8779                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
8780    
8781                                    q.addScalar(COUNT_COLUMN_NAME,
8782                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
8783    
8784                                    QueryPos qPos = QueryPos.getInstance(q);
8785    
8786                                    qPos.add(pk);
8787    
8788                                    count = (Long)q.uniqueResult();
8789    
8790                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
8791                                            finderArgs, count);
8792                            }
8793                            catch (Exception e) {
8794                                    FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS_SIZE,
8795                                            finderArgs);
8796    
8797                                    throw processException(e);
8798                            }
8799                            finally {
8800                                    closeSession(session);
8801                            }
8802                    }
8803    
8804                    return count.intValue();
8805            }
8806    
8807            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
8808                            GroupModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS, Boolean.class,
8809                            GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME, "containsUser",
8810                            new String[] { Long.class.getName(), Long.class.getName() });
8811    
8812            /**
8813             * Returns <code>true</code> if the user is associated with the group.
8814             *
8815             * @param pk the primary key of the group
8816             * @param userPK the primary key of the user
8817             * @return <code>true</code> if the user is associated with the group; <code>false</code> otherwise
8818             * @throws SystemException if a system exception occurred
8819             */
8820            public boolean containsUser(long pk, long userPK) throws SystemException {
8821                    Object[] finderArgs = new Object[] { pk, userPK };
8822    
8823                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
8824                                    finderArgs, this);
8825    
8826                    if (value == null) {
8827                            try {
8828                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
8829    
8830                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
8831                                            finderArgs, value);
8832                            }
8833                            catch (Exception e) {
8834                                    FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USER,
8835                                            finderArgs);
8836    
8837                                    throw processException(e);
8838                            }
8839                    }
8840    
8841                    return value.booleanValue();
8842            }
8843    
8844            /**
8845             * Returns <code>true</code> if the group has any users associated with it.
8846             *
8847             * @param pk the primary key of the group to check for associations with users
8848             * @return <code>true</code> if the group has any users associated with it; <code>false</code> otherwise
8849             * @throws SystemException if a system exception occurred
8850             */
8851            public boolean containsUsers(long pk) throws SystemException {
8852                    if (getUsersSize(pk) > 0) {
8853                            return true;
8854                    }
8855                    else {
8856                            return false;
8857                    }
8858            }
8859    
8860            /**
8861             * Adds an association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8862             *
8863             * @param pk the primary key of the group
8864             * @param userPK the primary key of the user
8865             * @throws SystemException if a system exception occurred
8866             */
8867            public void addUser(long pk, long userPK) throws SystemException {
8868                    try {
8869                            addUser.add(pk, userPK);
8870                    }
8871                    catch (Exception e) {
8872                            throw processException(e);
8873                    }
8874                    finally {
8875                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8876                    }
8877            }
8878    
8879            /**
8880             * Adds an association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8881             *
8882             * @param pk the primary key of the group
8883             * @param user the user
8884             * @throws SystemException if a system exception occurred
8885             */
8886            public void addUser(long pk, com.liferay.portal.model.User user)
8887                    throws SystemException {
8888                    try {
8889                            addUser.add(pk, user.getPrimaryKey());
8890                    }
8891                    catch (Exception e) {
8892                            throw processException(e);
8893                    }
8894                    finally {
8895                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8896                    }
8897            }
8898    
8899            /**
8900             * Adds an association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8901             *
8902             * @param pk the primary key of the group
8903             * @param userPKs the primary keys of the users
8904             * @throws SystemException if a system exception occurred
8905             */
8906            public void addUsers(long pk, long[] userPKs) throws SystemException {
8907                    try {
8908                            for (long userPK : userPKs) {
8909                                    addUser.add(pk, userPK);
8910                            }
8911                    }
8912                    catch (Exception e) {
8913                            throw processException(e);
8914                    }
8915                    finally {
8916                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8917                    }
8918            }
8919    
8920            /**
8921             * Adds an association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8922             *
8923             * @param pk the primary key of the group
8924             * @param users the users
8925             * @throws SystemException if a system exception occurred
8926             */
8927            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
8928                    throws SystemException {
8929                    try {
8930                            for (com.liferay.portal.model.User user : users) {
8931                                    addUser.add(pk, user.getPrimaryKey());
8932                            }
8933                    }
8934                    catch (Exception e) {
8935                            throw processException(e);
8936                    }
8937                    finally {
8938                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8939                    }
8940            }
8941    
8942            /**
8943             * Clears all associations between the group and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8944             *
8945             * @param pk the primary key of the group to clear the associated users from
8946             * @throws SystemException if a system exception occurred
8947             */
8948            public void clearUsers(long pk) throws SystemException {
8949                    try {
8950                            clearUsers.clear(pk);
8951                    }
8952                    catch (Exception e) {
8953                            throw processException(e);
8954                    }
8955                    finally {
8956                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8957                    }
8958            }
8959    
8960            /**
8961             * Removes the association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8962             *
8963             * @param pk the primary key of the group
8964             * @param userPK the primary key of the user
8965             * @throws SystemException if a system exception occurred
8966             */
8967            public void removeUser(long pk, long userPK) throws SystemException {
8968                    try {
8969                            removeUser.remove(pk, userPK);
8970                    }
8971                    catch (Exception e) {
8972                            throw processException(e);
8973                    }
8974                    finally {
8975                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8976                    }
8977            }
8978    
8979            /**
8980             * Removes the association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8981             *
8982             * @param pk the primary key of the group
8983             * @param user the user
8984             * @throws SystemException if a system exception occurred
8985             */
8986            public void removeUser(long pk, com.liferay.portal.model.User user)
8987                    throws SystemException {
8988                    try {
8989                            removeUser.remove(pk, user.getPrimaryKey());
8990                    }
8991                    catch (Exception e) {
8992                            throw processException(e);
8993                    }
8994                    finally {
8995                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
8996                    }
8997            }
8998    
8999            /**
9000             * Removes the association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9001             *
9002             * @param pk the primary key of the group
9003             * @param userPKs the primary keys of the users
9004             * @throws SystemException if a system exception occurred
9005             */
9006            public void removeUsers(long pk, long[] userPKs) throws SystemException {
9007                    try {
9008                            for (long userPK : userPKs) {
9009                                    removeUser.remove(pk, userPK);
9010                            }
9011                    }
9012                    catch (Exception e) {
9013                            throw processException(e);
9014                    }
9015                    finally {
9016                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
9017                    }
9018            }
9019    
9020            /**
9021             * Removes the association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9022             *
9023             * @param pk the primary key of the group
9024             * @param users the users
9025             * @throws SystemException if a system exception occurred
9026             */
9027            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
9028                    throws SystemException {
9029                    try {
9030                            for (com.liferay.portal.model.User user : users) {
9031                                    removeUser.remove(pk, user.getPrimaryKey());
9032                            }
9033                    }
9034                    catch (Exception e) {
9035                            throw processException(e);
9036                    }
9037                    finally {
9038                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
9039                    }
9040            }
9041    
9042            /**
9043             * Sets the users associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9044             *
9045             * @param pk the primary key of the group
9046             * @param userPKs the primary keys of the users to be associated with the group
9047             * @throws SystemException if a system exception occurred
9048             */
9049            public void setUsers(long pk, long[] userPKs) throws SystemException {
9050                    try {
9051                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
9052    
9053                            List<com.liferay.portal.model.User> users = getUsers(pk);
9054    
9055                            for (com.liferay.portal.model.User user : users) {
9056                                    if (!userPKSet.remove(user.getPrimaryKey())) {
9057                                            removeUser.remove(pk, user.getPrimaryKey());
9058                                    }
9059                            }
9060    
9061                            for (Long userPK : userPKSet) {
9062                                    addUser.add(pk, userPK);
9063                            }
9064                    }
9065                    catch (Exception e) {
9066                            throw processException(e);
9067                    }
9068                    finally {
9069                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
9070                    }
9071            }
9072    
9073            /**
9074             * Sets the users associated with the group, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9075             *
9076             * @param pk the primary key of the group
9077             * @param users the users to be associated with the group
9078             * @throws SystemException if a system exception occurred
9079             */
9080            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
9081                    throws SystemException {
9082                    try {
9083                            long[] userPKs = new long[users.size()];
9084    
9085                            for (int i = 0; i < users.size(); i++) {
9086                                    com.liferay.portal.model.User user = users.get(i);
9087    
9088                                    userPKs[i] = user.getPrimaryKey();
9089                            }
9090    
9091                            setUsers(pk, userPKs);
9092                    }
9093                    catch (Exception e) {
9094                            throw processException(e);
9095                    }
9096                    finally {
9097                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
9098                    }
9099            }
9100    
9101            @Override
9102            protected Set<String> getBadColumnNames() {
9103                    return _badColumnNames;
9104            }
9105    
9106            /**
9107             * Initializes the group persistence.
9108             */
9109            public void afterPropertiesSet() {
9110                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9111                                            com.liferay.portal.util.PropsUtil.get(
9112                                                    "value.object.listener.com.liferay.portal.model.Group")));
9113    
9114                    if (listenerClassNames.length > 0) {
9115                            try {
9116                                    List<ModelListener<Group>> listenersList = new ArrayList<ModelListener<Group>>();
9117    
9118                                    for (String listenerClassName : listenerClassNames) {
9119                                            listenersList.add((ModelListener<Group>)InstanceFactory.newInstance(
9120                                                            getClassLoader(), listenerClassName));
9121                                    }
9122    
9123                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9124                            }
9125                            catch (Exception e) {
9126                                    _log.error(e);
9127                            }
9128                    }
9129    
9130                    containsOrganization = new ContainsOrganization();
9131    
9132                    addOrganization = new AddOrganization();
9133                    clearOrganizations = new ClearOrganizations();
9134                    removeOrganization = new RemoveOrganization();
9135    
9136                    containsRole = new ContainsRole();
9137    
9138                    addRole = new AddRole();
9139                    clearRoles = new ClearRoles();
9140                    removeRole = new RemoveRole();
9141    
9142                    containsUserGroup = new ContainsUserGroup();
9143    
9144                    addUserGroup = new AddUserGroup();
9145                    clearUserGroups = new ClearUserGroups();
9146                    removeUserGroup = new RemoveUserGroup();
9147    
9148                    containsUser = new ContainsUser();
9149    
9150                    addUser = new AddUser();
9151                    clearUsers = new ClearUsers();
9152                    removeUser = new RemoveUser();
9153            }
9154    
9155            public void destroy() {
9156                    EntityCacheUtil.removeCache(GroupImpl.class.getName());
9157                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9158                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9159                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9160            }
9161    
9162            @BeanReference(type = OrganizationPersistence.class)
9163            protected OrganizationPersistence organizationPersistence;
9164            protected ContainsOrganization containsOrganization;
9165            protected AddOrganization addOrganization;
9166            protected ClearOrganizations clearOrganizations;
9167            protected RemoveOrganization removeOrganization;
9168            @BeanReference(type = RolePersistence.class)
9169            protected RolePersistence rolePersistence;
9170            protected ContainsRole containsRole;
9171            protected AddRole addRole;
9172            protected ClearRoles clearRoles;
9173            protected RemoveRole removeRole;
9174            @BeanReference(type = UserGroupPersistence.class)
9175            protected UserGroupPersistence userGroupPersistence;
9176            protected ContainsUserGroup containsUserGroup;
9177            protected AddUserGroup addUserGroup;
9178            protected ClearUserGroups clearUserGroups;
9179            protected RemoveUserGroup removeUserGroup;
9180            @BeanReference(type = UserPersistence.class)
9181            protected UserPersistence userPersistence;
9182            protected ContainsUser containsUser;
9183            protected AddUser addUser;
9184            protected ClearUsers clearUsers;
9185            protected RemoveUser removeUser;
9186    
9187            protected class ContainsOrganization {
9188                    protected ContainsOrganization() {
9189                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
9190                                            "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?",
9191                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
9192                                            RowMapper.COUNT);
9193                    }
9194    
9195                    protected boolean contains(long groupId, long organizationId) {
9196                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
9197                                                    new Long(groupId), new Long(organizationId)
9198                                            });
9199    
9200                            if (results.size() > 0) {
9201                                    Integer count = results.get(0);
9202    
9203                                    if (count.intValue() > 0) {
9204                                            return true;
9205                                    }
9206                            }
9207    
9208                            return false;
9209                    }
9210    
9211                    private MappingSqlQuery<Integer> _mappingSqlQuery;
9212            }
9213    
9214            protected class AddOrganization {
9215                    protected AddOrganization() {
9216                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9217                                            "INSERT INTO Groups_Orgs (groupId, organizationId) VALUES (?, ?)",
9218                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9219                    }
9220    
9221                    protected void add(long groupId, long organizationId)
9222                            throws SystemException {
9223                            if (!containsOrganization.contains(groupId, organizationId)) {
9224                                    ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
9225                                            organizationPersistence.getListeners();
9226    
9227                                    for (ModelListener<Group> listener : listeners) {
9228                                            listener.onBeforeAddAssociation(groupId,
9229                                                    com.liferay.portal.model.Organization.class.getName(),
9230                                                    organizationId);
9231                                    }
9232    
9233                                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
9234                                            listener.onBeforeAddAssociation(organizationId,
9235                                                    Group.class.getName(), groupId);
9236                                    }
9237    
9238                                    _sqlUpdate.update(new Object[] {
9239                                                    new Long(groupId), new Long(organizationId)
9240                                            });
9241    
9242                                    for (ModelListener<Group> listener : listeners) {
9243                                            listener.onAfterAddAssociation(groupId,
9244                                                    com.liferay.portal.model.Organization.class.getName(),
9245                                                    organizationId);
9246                                    }
9247    
9248                                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
9249                                            listener.onAfterAddAssociation(organizationId,
9250                                                    Group.class.getName(), groupId);
9251                                    }
9252                            }
9253                    }
9254    
9255                    private SqlUpdate _sqlUpdate;
9256            }
9257    
9258            protected class ClearOrganizations {
9259                    protected ClearOrganizations() {
9260                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9261                                            "DELETE FROM Groups_Orgs WHERE groupId = ?",
9262                                            new int[] { java.sql.Types.BIGINT });
9263                    }
9264    
9265                    protected void clear(long groupId) throws SystemException {
9266                            ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
9267                                    organizationPersistence.getListeners();
9268    
9269                            List<com.liferay.portal.model.Organization> organizations = null;
9270    
9271                            if ((listeners.length > 0) || (organizationListeners.length > 0)) {
9272                                    organizations = getOrganizations(groupId);
9273    
9274                                    for (com.liferay.portal.model.Organization organization : organizations) {
9275                                            for (ModelListener<Group> listener : listeners) {
9276                                                    listener.onBeforeRemoveAssociation(groupId,
9277                                                            com.liferay.portal.model.Organization.class.getName(),
9278                                                            organization.getPrimaryKey());
9279                                            }
9280    
9281                                            for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
9282                                                    listener.onBeforeRemoveAssociation(organization.getPrimaryKey(),
9283                                                            Group.class.getName(), groupId);
9284                                            }
9285                                    }
9286                            }
9287    
9288                            _sqlUpdate.update(new Object[] { new Long(groupId) });
9289    
9290                            if ((listeners.length > 0) || (organizationListeners.length > 0)) {
9291                                    for (com.liferay.portal.model.Organization organization : organizations) {
9292                                            for (ModelListener<Group> listener : listeners) {
9293                                                    listener.onAfterRemoveAssociation(groupId,
9294                                                            com.liferay.portal.model.Organization.class.getName(),
9295                                                            organization.getPrimaryKey());
9296                                            }
9297    
9298                                            for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
9299                                                    listener.onAfterRemoveAssociation(organization.getPrimaryKey(),
9300                                                            Group.class.getName(), groupId);
9301                                            }
9302                                    }
9303                            }
9304                    }
9305    
9306                    private SqlUpdate _sqlUpdate;
9307            }
9308    
9309            protected class RemoveOrganization {
9310                    protected RemoveOrganization() {
9311                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9312                                            "DELETE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?",
9313                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9314                    }
9315    
9316                    protected void remove(long groupId, long organizationId)
9317                            throws SystemException {
9318                            if (containsOrganization.contains(groupId, organizationId)) {
9319                                    ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
9320                                            organizationPersistence.getListeners();
9321    
9322                                    for (ModelListener<Group> listener : listeners) {
9323                                            listener.onBeforeRemoveAssociation(groupId,
9324                                                    com.liferay.portal.model.Organization.class.getName(),
9325                                                    organizationId);
9326                                    }
9327    
9328                                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
9329                                            listener.onBeforeRemoveAssociation(organizationId,
9330                                                    Group.class.getName(), groupId);
9331                                    }
9332    
9333                                    _sqlUpdate.update(new Object[] {
9334                                                    new Long(groupId), new Long(organizationId)
9335                                            });
9336    
9337                                    for (ModelListener<Group> listener : listeners) {
9338                                            listener.onAfterRemoveAssociation(groupId,
9339                                                    com.liferay.portal.model.Organization.class.getName(),
9340                                                    organizationId);
9341                                    }
9342    
9343                                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
9344                                            listener.onAfterRemoveAssociation(organizationId,
9345                                                    Group.class.getName(), groupId);
9346                                    }
9347                            }
9348                    }
9349    
9350                    private SqlUpdate _sqlUpdate;
9351            }
9352    
9353            protected class ContainsRole {
9354                    protected ContainsRole() {
9355                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
9356                                            "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ? AND roleId = ?",
9357                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
9358                                            RowMapper.COUNT);
9359                    }
9360    
9361                    protected boolean contains(long groupId, long roleId) {
9362                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
9363                                                    new Long(groupId), new Long(roleId)
9364                                            });
9365    
9366                            if (results.size() > 0) {
9367                                    Integer count = results.get(0);
9368    
9369                                    if (count.intValue() > 0) {
9370                                            return true;
9371                                    }
9372                            }
9373    
9374                            return false;
9375                    }
9376    
9377                    private MappingSqlQuery<Integer> _mappingSqlQuery;
9378            }
9379    
9380            protected class AddRole {
9381                    protected AddRole() {
9382                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9383                                            "INSERT INTO Groups_Roles (groupId, roleId) VALUES (?, ?)",
9384                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9385                    }
9386    
9387                    protected void add(long groupId, long roleId) throws SystemException {
9388                            if (!containsRole.contains(groupId, roleId)) {
9389                                    ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
9390    
9391                                    for (ModelListener<Group> listener : listeners) {
9392                                            listener.onBeforeAddAssociation(groupId,
9393                                                    com.liferay.portal.model.Role.class.getName(), roleId);
9394                                    }
9395    
9396                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
9397                                            listener.onBeforeAddAssociation(roleId,
9398                                                    Group.class.getName(), groupId);
9399                                    }
9400    
9401                                    _sqlUpdate.update(new Object[] {
9402                                                    new Long(groupId), new Long(roleId)
9403                                            });
9404    
9405                                    for (ModelListener<Group> listener : listeners) {
9406                                            listener.onAfterAddAssociation(groupId,
9407                                                    com.liferay.portal.model.Role.class.getName(), roleId);
9408                                    }
9409    
9410                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
9411                                            listener.onAfterAddAssociation(roleId,
9412                                                    Group.class.getName(), groupId);
9413                                    }
9414                            }
9415                    }
9416    
9417                    private SqlUpdate _sqlUpdate;
9418            }
9419    
9420            protected class ClearRoles {
9421                    protected ClearRoles() {
9422                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9423                                            "DELETE FROM Groups_Roles WHERE groupId = ?",
9424                                            new int[] { java.sql.Types.BIGINT });
9425                    }
9426    
9427                    protected void clear(long groupId) throws SystemException {
9428                            ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
9429    
9430                            List<com.liferay.portal.model.Role> roles = null;
9431    
9432                            if ((listeners.length > 0) || (roleListeners.length > 0)) {
9433                                    roles = getRoles(groupId);
9434    
9435                                    for (com.liferay.portal.model.Role role : roles) {
9436                                            for (ModelListener<Group> listener : listeners) {
9437                                                    listener.onBeforeRemoveAssociation(groupId,
9438                                                            com.liferay.portal.model.Role.class.getName(),
9439                                                            role.getPrimaryKey());
9440                                            }
9441    
9442                                            for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
9443                                                    listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
9444                                                            Group.class.getName(), groupId);
9445                                            }
9446                                    }
9447                            }
9448    
9449                            _sqlUpdate.update(new Object[] { new Long(groupId) });
9450    
9451                            if ((listeners.length > 0) || (roleListeners.length > 0)) {
9452                                    for (com.liferay.portal.model.Role role : roles) {
9453                                            for (ModelListener<Group> listener : listeners) {
9454                                                    listener.onAfterRemoveAssociation(groupId,
9455                                                            com.liferay.portal.model.Role.class.getName(),
9456                                                            role.getPrimaryKey());
9457                                            }
9458    
9459                                            for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
9460                                                    listener.onAfterRemoveAssociation(role.getPrimaryKey(),
9461                                                            Group.class.getName(), groupId);
9462                                            }
9463                                    }
9464                            }
9465                    }
9466    
9467                    private SqlUpdate _sqlUpdate;
9468            }
9469    
9470            protected class RemoveRole {
9471                    protected RemoveRole() {
9472                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9473                                            "DELETE FROM Groups_Roles WHERE groupId = ? AND roleId = ?",
9474                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9475                    }
9476    
9477                    protected void remove(long groupId, long roleId)
9478                            throws SystemException {
9479                            if (containsRole.contains(groupId, roleId)) {
9480                                    ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
9481    
9482                                    for (ModelListener<Group> listener : listeners) {
9483                                            listener.onBeforeRemoveAssociation(groupId,
9484                                                    com.liferay.portal.model.Role.class.getName(), roleId);
9485                                    }
9486    
9487                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
9488                                            listener.onBeforeRemoveAssociation(roleId,
9489                                                    Group.class.getName(), groupId);
9490                                    }
9491    
9492                                    _sqlUpdate.update(new Object[] {
9493                                                    new Long(groupId), new Long(roleId)
9494                                            });
9495    
9496                                    for (ModelListener<Group> listener : listeners) {
9497                                            listener.onAfterRemoveAssociation(groupId,
9498                                                    com.liferay.portal.model.Role.class.getName(), roleId);
9499                                    }
9500    
9501                                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
9502                                            listener.onAfterRemoveAssociation(roleId,
9503                                                    Group.class.getName(), groupId);
9504                                    }
9505                            }
9506                    }
9507    
9508                    private SqlUpdate _sqlUpdate;
9509            }
9510    
9511            protected class ContainsUserGroup {
9512                    protected ContainsUserGroup() {
9513                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
9514                                            "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?",
9515                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
9516                                            RowMapper.COUNT);
9517                    }
9518    
9519                    protected boolean contains(long groupId, long userGroupId) {
9520                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
9521                                                    new Long(groupId), new Long(userGroupId)
9522                                            });
9523    
9524                            if (results.size() > 0) {
9525                                    Integer count = results.get(0);
9526    
9527                                    if (count.intValue() > 0) {
9528                                            return true;
9529                                    }
9530                            }
9531    
9532                            return false;
9533                    }
9534    
9535                    private MappingSqlQuery<Integer> _mappingSqlQuery;
9536            }
9537    
9538            protected class AddUserGroup {
9539                    protected AddUserGroup() {
9540                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9541                                            "INSERT INTO Groups_UserGroups (groupId, userGroupId) VALUES (?, ?)",
9542                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9543                    }
9544    
9545                    protected void add(long groupId, long userGroupId)
9546                            throws SystemException {
9547                            if (!containsUserGroup.contains(groupId, userGroupId)) {
9548                                    ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
9549                                            userGroupPersistence.getListeners();
9550    
9551                                    for (ModelListener<Group> listener : listeners) {
9552                                            listener.onBeforeAddAssociation(groupId,
9553                                                    com.liferay.portal.model.UserGroup.class.getName(),
9554                                                    userGroupId);
9555                                    }
9556    
9557                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
9558                                            listener.onBeforeAddAssociation(userGroupId,
9559                                                    Group.class.getName(), groupId);
9560                                    }
9561    
9562                                    _sqlUpdate.update(new Object[] {
9563                                                    new Long(groupId), new Long(userGroupId)
9564                                            });
9565    
9566                                    for (ModelListener<Group> listener : listeners) {
9567                                            listener.onAfterAddAssociation(groupId,
9568                                                    com.liferay.portal.model.UserGroup.class.getName(),
9569                                                    userGroupId);
9570                                    }
9571    
9572                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
9573                                            listener.onAfterAddAssociation(userGroupId,
9574                                                    Group.class.getName(), groupId);
9575                                    }
9576                            }
9577                    }
9578    
9579                    private SqlUpdate _sqlUpdate;
9580            }
9581    
9582            protected class ClearUserGroups {
9583                    protected ClearUserGroups() {
9584                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9585                                            "DELETE FROM Groups_UserGroups WHERE groupId = ?",
9586                                            new int[] { java.sql.Types.BIGINT });
9587                    }
9588    
9589                    protected void clear(long groupId) throws SystemException {
9590                            ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
9591                                    userGroupPersistence.getListeners();
9592    
9593                            List<com.liferay.portal.model.UserGroup> userGroups = null;
9594    
9595                            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
9596                                    userGroups = getUserGroups(groupId);
9597    
9598                                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
9599                                            for (ModelListener<Group> listener : listeners) {
9600                                                    listener.onBeforeRemoveAssociation(groupId,
9601                                                            com.liferay.portal.model.UserGroup.class.getName(),
9602                                                            userGroup.getPrimaryKey());
9603                                            }
9604    
9605                                            for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
9606                                                    listener.onBeforeRemoveAssociation(userGroup.getPrimaryKey(),
9607                                                            Group.class.getName(), groupId);
9608                                            }
9609                                    }
9610                            }
9611    
9612                            _sqlUpdate.update(new Object[] { new Long(groupId) });
9613    
9614                            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
9615                                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
9616                                            for (ModelListener<Group> listener : listeners) {
9617                                                    listener.onAfterRemoveAssociation(groupId,
9618                                                            com.liferay.portal.model.UserGroup.class.getName(),
9619                                                            userGroup.getPrimaryKey());
9620                                            }
9621    
9622                                            for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
9623                                                    listener.onAfterRemoveAssociation(userGroup.getPrimaryKey(),
9624                                                            Group.class.getName(), groupId);
9625                                            }
9626                                    }
9627                            }
9628                    }
9629    
9630                    private SqlUpdate _sqlUpdate;
9631            }
9632    
9633            protected class RemoveUserGroup {
9634                    protected RemoveUserGroup() {
9635                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9636                                            "DELETE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?",
9637                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9638                    }
9639    
9640                    protected void remove(long groupId, long userGroupId)
9641                            throws SystemException {
9642                            if (containsUserGroup.contains(groupId, userGroupId)) {
9643                                    ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
9644                                            userGroupPersistence.getListeners();
9645    
9646                                    for (ModelListener<Group> listener : listeners) {
9647                                            listener.onBeforeRemoveAssociation(groupId,
9648                                                    com.liferay.portal.model.UserGroup.class.getName(),
9649                                                    userGroupId);
9650                                    }
9651    
9652                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
9653                                            listener.onBeforeRemoveAssociation(userGroupId,
9654                                                    Group.class.getName(), groupId);
9655                                    }
9656    
9657                                    _sqlUpdate.update(new Object[] {
9658                                                    new Long(groupId), new Long(userGroupId)
9659                                            });
9660    
9661                                    for (ModelListener<Group> listener : listeners) {
9662                                            listener.onAfterRemoveAssociation(groupId,
9663                                                    com.liferay.portal.model.UserGroup.class.getName(),
9664                                                    userGroupId);
9665                                    }
9666    
9667                                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
9668                                            listener.onAfterRemoveAssociation(userGroupId,
9669                                                    Group.class.getName(), groupId);
9670                                    }
9671                            }
9672                    }
9673    
9674                    private SqlUpdate _sqlUpdate;
9675            }
9676    
9677            protected class ContainsUser {
9678                    protected ContainsUser() {
9679                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
9680                                            "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ? AND userId = ?",
9681                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
9682                                            RowMapper.COUNT);
9683                    }
9684    
9685                    protected boolean contains(long groupId, long userId) {
9686                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
9687                                                    new Long(groupId), new Long(userId)
9688                                            });
9689    
9690                            if (results.size() > 0) {
9691                                    Integer count = results.get(0);
9692    
9693                                    if (count.intValue() > 0) {
9694                                            return true;
9695                                    }
9696                            }
9697    
9698                            return false;
9699                    }
9700    
9701                    private MappingSqlQuery<Integer> _mappingSqlQuery;
9702            }
9703    
9704            protected class AddUser {
9705                    protected AddUser() {
9706                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9707                                            "INSERT INTO Users_Groups (groupId, userId) VALUES (?, ?)",
9708                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9709                    }
9710    
9711                    protected void add(long groupId, long userId) throws SystemException {
9712                            if (!containsUser.contains(groupId, userId)) {
9713                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
9714    
9715                                    for (ModelListener<Group> listener : listeners) {
9716                                            listener.onBeforeAddAssociation(groupId,
9717                                                    com.liferay.portal.model.User.class.getName(), userId);
9718                                    }
9719    
9720                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9721                                            listener.onBeforeAddAssociation(userId,
9722                                                    Group.class.getName(), groupId);
9723                                    }
9724    
9725                                    _sqlUpdate.update(new Object[] {
9726                                                    new Long(groupId), new Long(userId)
9727                                            });
9728    
9729                                    for (ModelListener<Group> listener : listeners) {
9730                                            listener.onAfterAddAssociation(groupId,
9731                                                    com.liferay.portal.model.User.class.getName(), userId);
9732                                    }
9733    
9734                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9735                                            listener.onAfterAddAssociation(userId,
9736                                                    Group.class.getName(), groupId);
9737                                    }
9738                            }
9739                    }
9740    
9741                    private SqlUpdate _sqlUpdate;
9742            }
9743    
9744            protected class ClearUsers {
9745                    protected ClearUsers() {
9746                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9747                                            "DELETE FROM Users_Groups WHERE groupId = ?",
9748                                            new int[] { java.sql.Types.BIGINT });
9749                    }
9750    
9751                    protected void clear(long groupId) throws SystemException {
9752                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
9753    
9754                            List<com.liferay.portal.model.User> users = null;
9755    
9756                            if ((listeners.length > 0) || (userListeners.length > 0)) {
9757                                    users = getUsers(groupId);
9758    
9759                                    for (com.liferay.portal.model.User user : users) {
9760                                            for (ModelListener<Group> listener : listeners) {
9761                                                    listener.onBeforeRemoveAssociation(groupId,
9762                                                            com.liferay.portal.model.User.class.getName(),
9763                                                            user.getPrimaryKey());
9764                                            }
9765    
9766                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9767                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
9768                                                            Group.class.getName(), groupId);
9769                                            }
9770                                    }
9771                            }
9772    
9773                            _sqlUpdate.update(new Object[] { new Long(groupId) });
9774    
9775                            if ((listeners.length > 0) || (userListeners.length > 0)) {
9776                                    for (com.liferay.portal.model.User user : users) {
9777                                            for (ModelListener<Group> listener : listeners) {
9778                                                    listener.onAfterRemoveAssociation(groupId,
9779                                                            com.liferay.portal.model.User.class.getName(),
9780                                                            user.getPrimaryKey());
9781                                            }
9782    
9783                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9784                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
9785                                                            Group.class.getName(), groupId);
9786                                            }
9787                                    }
9788                            }
9789                    }
9790    
9791                    private SqlUpdate _sqlUpdate;
9792            }
9793    
9794            protected class RemoveUser {
9795                    protected RemoveUser() {
9796                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9797                                            "DELETE FROM Users_Groups WHERE groupId = ? AND userId = ?",
9798                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9799                    }
9800    
9801                    protected void remove(long groupId, long userId)
9802                            throws SystemException {
9803                            if (containsUser.contains(groupId, userId)) {
9804                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
9805    
9806                                    for (ModelListener<Group> listener : listeners) {
9807                                            listener.onBeforeRemoveAssociation(groupId,
9808                                                    com.liferay.portal.model.User.class.getName(), userId);
9809                                    }
9810    
9811                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9812                                            listener.onBeforeRemoveAssociation(userId,
9813                                                    Group.class.getName(), groupId);
9814                                    }
9815    
9816                                    _sqlUpdate.update(new Object[] {
9817                                                    new Long(groupId), new Long(userId)
9818                                            });
9819    
9820                                    for (ModelListener<Group> listener : listeners) {
9821                                            listener.onAfterRemoveAssociation(groupId,
9822                                                    com.liferay.portal.model.User.class.getName(), userId);
9823                                    }
9824    
9825                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9826                                            listener.onAfterRemoveAssociation(userId,
9827                                                    Group.class.getName(), groupId);
9828                                    }
9829                            }
9830                    }
9831    
9832                    private SqlUpdate _sqlUpdate;
9833            }
9834    
9835            private static final String _SQL_SELECT_GROUP_ = "SELECT group_ FROM Group group_";
9836            private static final String _SQL_SELECT_GROUP__WHERE = "SELECT group_ FROM Group group_ WHERE ";
9837            private static final String _SQL_COUNT_GROUP_ = "SELECT COUNT(group_) FROM Group group_";
9838            private static final String _SQL_COUNT_GROUP__WHERE = "SELECT COUNT(group_) FROM Group group_ WHERE ";
9839            private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Groups_Orgs ON (Groups_Orgs.organizationId = Organization_.organizationId) WHERE (Groups_Orgs.groupId = ?)";
9840            private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ?";
9841            private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Groups_Roles ON (Groups_Roles.roleId = Role_.roleId) WHERE (Groups_Roles.groupId = ?)";
9842            private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ?";
9843            private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Groups_UserGroups ON (Groups_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Groups_UserGroups.groupId = ?)";
9844            private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ?";
9845            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Groups ON (Users_Groups.userId = User_.userId) WHERE (Users_Groups.groupId = ?)";
9846            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ?";
9847            private static final String _ORDER_BY_ENTITY_ALIAS = "group_.";
9848            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Group exists with the primary key ";
9849            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Group exists with the key {";
9850            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9851            private static Log _log = LogFactoryUtil.getLog(GroupPersistenceImpl.class);
9852            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9853                                    "uuid", "type", "active"
9854                            });
9855            private static Group _nullGroup = new GroupImpl() {
9856                            @Override
9857                            public Object clone() {
9858                                    return this;
9859                            }
9860    
9861                            @Override
9862                            public CacheModel<Group> toCacheModel() {
9863                                    return _nullGroupCacheModel;
9864                            }
9865                    };
9866    
9867            private static CacheModel<Group> _nullGroupCacheModel = new CacheModel<Group>() {
9868                            public Group toEntityModel() {
9869                                    return _nullGroup;
9870                            }
9871                    };
9872    }