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