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