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