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