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