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