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