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