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