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