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