001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchGroupException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.Group;
042    import com.liferay.portal.model.ModelListener;
043    import com.liferay.portal.model.impl.GroupImpl;
044    import com.liferay.portal.model.impl.GroupModelImpl;
045    import com.liferay.portal.service.persistence.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_C_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4263                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4264                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_A",
4265                            new String[] {
4266                                    Long.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_C_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4272                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4273                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_A",
4274                            new String[] { Long.class.getName(), Boolean.class.getName() },
4275                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
4276                            GroupModelImpl.ACTIVE_COLUMN_BITMASK |
4277                            GroupModelImpl.NAME_COLUMN_BITMASK);
4278            public static final FinderPath FINDER_PATH_COUNT_BY_C_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4279                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
4280                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_A",
4281                            new String[] { Long.class.getName(), Boolean.class.getName() });
4282    
4283            /**
4284             * Returns all the groups where companyId = &#63; and active = &#63;.
4285             *
4286             * @param companyId the company ID
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> findByC_A(long companyId, boolean active)
4293                    throws SystemException {
4294                    return findByC_A(companyId, active, QueryUtil.ALL_POS,
4295                            QueryUtil.ALL_POS, null);
4296            }
4297    
4298            /**
4299             * Returns a range of all the groups where companyId = &#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 companyId the company ID
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> findByC_A(long companyId, boolean active, int start,
4314                    int end) throws SystemException {
4315                    return findByC_A(companyId, active, start, end, null);
4316            }
4317    
4318            /**
4319             * Returns an ordered range of all the groups where companyId = &#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 companyId the company ID
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> findByC_A(long companyId, boolean active, int start,
4335                    int end, 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_C_A;
4344                            finderArgs = new Object[] { companyId, active };
4345                    }
4346                    else {
4347                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_A;
4348                            finderArgs = new Object[] {
4349                                            companyId, 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 ((companyId != group.getCompanyId()) ||
4361                                                    (active != group.getActive())) {
4362                                            list = null;
4363    
4364                                            break;
4365                                    }
4366                            }
4367                    }
4368    
4369                    if (list == null) {
4370                            StringBundler query = null;
4371    
4372                            if (orderByComparator != null) {
4373                                    query = new StringBundler(4 +
4374                                                    (orderByComparator.getOrderByFields().length * 3));
4375                            }
4376                            else {
4377                                    query = new StringBundler(4);
4378                            }
4379    
4380                            query.append(_SQL_SELECT_GROUP__WHERE);
4381    
4382                            query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
4383    
4384                            query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
4385    
4386                            if (orderByComparator != null) {
4387                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4388                                            orderByComparator);
4389                            }
4390                            else
4391                             if (pagination) {
4392                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
4393                            }
4394    
4395                            String sql = query.toString();
4396    
4397                            Session session = null;
4398    
4399                            try {
4400                                    session = openSession();
4401    
4402                                    Query q = session.createQuery(sql);
4403    
4404                                    QueryPos qPos = QueryPos.getInstance(q);
4405    
4406                                    qPos.add(companyId);
4407    
4408                                    qPos.add(active);
4409    
4410                                    if (!pagination) {
4411                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
4412                                                            end, false);
4413    
4414                                            Collections.sort(list);
4415    
4416                                            list = new UnmodifiableList<Group>(list);
4417                                    }
4418                                    else {
4419                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
4420                                                            end);
4421                                    }
4422    
4423                                    cacheResult(list);
4424    
4425                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4426                            }
4427                            catch (Exception e) {
4428                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4429    
4430                                    throw processException(e);
4431                            }
4432                            finally {
4433                                    closeSession(session);
4434                            }
4435                    }
4436    
4437                    return list;
4438            }
4439    
4440            /**
4441             * Returns the first group in the ordered set where companyId = &#63; and active = &#63;.
4442             *
4443             * @param companyId the company ID
4444             * @param active the active
4445             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4446             * @return the first matching group
4447             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
4448             * @throws SystemException if a system exception occurred
4449             */
4450            @Override
4451            public Group findByC_A_First(long companyId, boolean active,
4452                    OrderByComparator orderByComparator)
4453                    throws NoSuchGroupException, SystemException {
4454                    Group group = fetchByC_A_First(companyId, active, orderByComparator);
4455    
4456                    if (group != null) {
4457                            return group;
4458                    }
4459    
4460                    StringBundler msg = new StringBundler(6);
4461    
4462                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4463    
4464                    msg.append("companyId=");
4465                    msg.append(companyId);
4466    
4467                    msg.append(", active=");
4468                    msg.append(active);
4469    
4470                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4471    
4472                    throw new NoSuchGroupException(msg.toString());
4473            }
4474    
4475            /**
4476             * Returns the first group in the ordered set where companyId = &#63; and active = &#63;.
4477             *
4478             * @param companyId the company ID
4479             * @param active the active
4480             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4481             * @return the first matching group, or <code>null</code> if a matching group could not be found
4482             * @throws SystemException if a system exception occurred
4483             */
4484            @Override
4485            public Group fetchByC_A_First(long companyId, boolean active,
4486                    OrderByComparator orderByComparator) throws SystemException {
4487                    List<Group> list = findByC_A(companyId, active, 0, 1, orderByComparator);
4488    
4489                    if (!list.isEmpty()) {
4490                            return list.get(0);
4491                    }
4492    
4493                    return null;
4494            }
4495    
4496            /**
4497             * Returns the last group in the ordered set where companyId = &#63; and active = &#63;.
4498             *
4499             * @param companyId the company ID
4500             * @param active the active
4501             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4502             * @return the last matching group
4503             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
4504             * @throws SystemException if a system exception occurred
4505             */
4506            @Override
4507            public Group findByC_A_Last(long companyId, boolean active,
4508                    OrderByComparator orderByComparator)
4509                    throws NoSuchGroupException, SystemException {
4510                    Group group = fetchByC_A_Last(companyId, active, orderByComparator);
4511    
4512                    if (group != null) {
4513                            return group;
4514                    }
4515    
4516                    StringBundler msg = new StringBundler(6);
4517    
4518                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4519    
4520                    msg.append("companyId=");
4521                    msg.append(companyId);
4522    
4523                    msg.append(", active=");
4524                    msg.append(active);
4525    
4526                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4527    
4528                    throw new NoSuchGroupException(msg.toString());
4529            }
4530    
4531            /**
4532             * Returns the last group in the ordered set where companyId = &#63; and active = &#63;.
4533             *
4534             * @param companyId the company ID
4535             * @param active the active
4536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4537             * @return the last matching group, or <code>null</code> if a matching group could not be found
4538             * @throws SystemException if a system exception occurred
4539             */
4540            @Override
4541            public Group fetchByC_A_Last(long companyId, boolean active,
4542                    OrderByComparator orderByComparator) throws SystemException {
4543                    int count = countByC_A(companyId, active);
4544    
4545                    if (count == 0) {
4546                            return null;
4547                    }
4548    
4549                    List<Group> list = findByC_A(companyId, active, count - 1, count,
4550                                    orderByComparator);
4551    
4552                    if (!list.isEmpty()) {
4553                            return list.get(0);
4554                    }
4555    
4556                    return null;
4557            }
4558    
4559            /**
4560             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and active = &#63;.
4561             *
4562             * @param groupId the primary key of the current group
4563             * @param companyId the company ID
4564             * @param active the active
4565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4566             * @return the previous, current, and next group
4567             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
4568             * @throws SystemException if a system exception occurred
4569             */
4570            @Override
4571            public Group[] findByC_A_PrevAndNext(long groupId, long companyId,
4572                    boolean active, OrderByComparator orderByComparator)
4573                    throws NoSuchGroupException, SystemException {
4574                    Group group = findByPrimaryKey(groupId);
4575    
4576                    Session session = null;
4577    
4578                    try {
4579                            session = openSession();
4580    
4581                            Group[] array = new GroupImpl[3];
4582    
4583                            array[0] = getByC_A_PrevAndNext(session, group, companyId, active,
4584                                            orderByComparator, true);
4585    
4586                            array[1] = group;
4587    
4588                            array[2] = getByC_A_PrevAndNext(session, group, companyId, active,
4589                                            orderByComparator, false);
4590    
4591                            return array;
4592                    }
4593                    catch (Exception e) {
4594                            throw processException(e);
4595                    }
4596                    finally {
4597                            closeSession(session);
4598                    }
4599            }
4600    
4601            protected Group getByC_A_PrevAndNext(Session session, Group group,
4602                    long companyId, boolean active, OrderByComparator orderByComparator,
4603                    boolean previous) {
4604                    StringBundler query = null;
4605    
4606                    if (orderByComparator != null) {
4607                            query = new StringBundler(6 +
4608                                            (orderByComparator.getOrderByFields().length * 6));
4609                    }
4610                    else {
4611                            query = new StringBundler(3);
4612                    }
4613    
4614                    query.append(_SQL_SELECT_GROUP__WHERE);
4615    
4616                    query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
4617    
4618                    query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
4619    
4620                    if (orderByComparator != null) {
4621                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4622    
4623                            if (orderByConditionFields.length > 0) {
4624                                    query.append(WHERE_AND);
4625                            }
4626    
4627                            for (int i = 0; i < orderByConditionFields.length; i++) {
4628                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4629                                    query.append(orderByConditionFields[i]);
4630    
4631                                    if ((i + 1) < orderByConditionFields.length) {
4632                                            if (orderByComparator.isAscending() ^ previous) {
4633                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4634                                            }
4635                                            else {
4636                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4637                                            }
4638                                    }
4639                                    else {
4640                                            if (orderByComparator.isAscending() ^ previous) {
4641                                                    query.append(WHERE_GREATER_THAN);
4642                                            }
4643                                            else {
4644                                                    query.append(WHERE_LESSER_THAN);
4645                                            }
4646                                    }
4647                            }
4648    
4649                            query.append(ORDER_BY_CLAUSE);
4650    
4651                            String[] orderByFields = orderByComparator.getOrderByFields();
4652    
4653                            for (int i = 0; i < orderByFields.length; i++) {
4654                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4655                                    query.append(orderByFields[i]);
4656    
4657                                    if ((i + 1) < orderByFields.length) {
4658                                            if (orderByComparator.isAscending() ^ previous) {
4659                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4660                                            }
4661                                            else {
4662                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4663                                            }
4664                                    }
4665                                    else {
4666                                            if (orderByComparator.isAscending() ^ previous) {
4667                                                    query.append(ORDER_BY_ASC);
4668                                            }
4669                                            else {
4670                                                    query.append(ORDER_BY_DESC);
4671                                            }
4672                                    }
4673                            }
4674                    }
4675                    else {
4676                            query.append(GroupModelImpl.ORDER_BY_JPQL);
4677                    }
4678    
4679                    String sql = query.toString();
4680    
4681                    Query q = session.createQuery(sql);
4682    
4683                    q.setFirstResult(0);
4684                    q.setMaxResults(2);
4685    
4686                    QueryPos qPos = QueryPos.getInstance(q);
4687    
4688                    qPos.add(companyId);
4689    
4690                    qPos.add(active);
4691    
4692                    if (orderByComparator != null) {
4693                            Object[] values = orderByComparator.getOrderByConditionValues(group);
4694    
4695                            for (Object value : values) {
4696                                    qPos.add(value);
4697                            }
4698                    }
4699    
4700                    List<Group> list = q.list();
4701    
4702                    if (list.size() == 2) {
4703                            return list.get(1);
4704                    }
4705                    else {
4706                            return null;
4707                    }
4708            }
4709    
4710            /**
4711             * Removes all the groups where companyId = &#63; and active = &#63; from the database.
4712             *
4713             * @param companyId the company ID
4714             * @param active the active
4715             * @throws SystemException if a system exception occurred
4716             */
4717            @Override
4718            public void removeByC_A(long companyId, boolean active)
4719                    throws SystemException {
4720                    for (Group group : findByC_A(companyId, active, QueryUtil.ALL_POS,
4721                                    QueryUtil.ALL_POS, null)) {
4722                            remove(group);
4723                    }
4724            }
4725    
4726            /**
4727             * Returns the number of groups where companyId = &#63; and active = &#63;.
4728             *
4729             * @param companyId the company ID
4730             * @param active the active
4731             * @return the number of matching groups
4732             * @throws SystemException if a system exception occurred
4733             */
4734            @Override
4735            public int countByC_A(long companyId, boolean active)
4736                    throws SystemException {
4737                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_A;
4738    
4739                    Object[] finderArgs = new Object[] { companyId, active };
4740    
4741                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4742                                    this);
4743    
4744                    if (count == null) {
4745                            StringBundler query = new StringBundler(3);
4746    
4747                            query.append(_SQL_COUNT_GROUP__WHERE);
4748    
4749                            query.append(_FINDER_COLUMN_C_A_COMPANYID_2);
4750    
4751                            query.append(_FINDER_COLUMN_C_A_ACTIVE_2);
4752    
4753                            String sql = query.toString();
4754    
4755                            Session session = null;
4756    
4757                            try {
4758                                    session = openSession();
4759    
4760                                    Query q = session.createQuery(sql);
4761    
4762                                    QueryPos qPos = QueryPos.getInstance(q);
4763    
4764                                    qPos.add(companyId);
4765    
4766                                    qPos.add(active);
4767    
4768                                    count = (Long)q.uniqueResult();
4769    
4770                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4771                            }
4772                            catch (Exception e) {
4773                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4774    
4775                                    throw processException(e);
4776                            }
4777                            finally {
4778                                    closeSession(session);
4779                            }
4780                    }
4781    
4782                    return count.intValue();
4783            }
4784    
4785            private static final String _FINDER_COLUMN_C_A_COMPANYID_2 = "group_.companyId = ? AND ";
4786            private static final String _FINDER_COLUMN_C_A_ACTIVE_2 = "group_.active = ?";
4787            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4788                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4789                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
4790                            new String[] {
4791                                    Integer.class.getName(), Boolean.class.getName(),
4792                                    
4793                            Integer.class.getName(), Integer.class.getName(),
4794                                    OrderByComparator.class.getName()
4795                            });
4796            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4797                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
4798                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
4799                            new String[] { Integer.class.getName(), Boolean.class.getName() },
4800                            GroupModelImpl.TYPE_COLUMN_BITMASK |
4801                            GroupModelImpl.ACTIVE_COLUMN_BITMASK |
4802                            GroupModelImpl.NAME_COLUMN_BITMASK);
4803            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
4804                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
4805                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
4806                            new String[] { Integer.class.getName(), Boolean.class.getName() });
4807    
4808            /**
4809             * Returns all the groups where type = &#63; and active = &#63;.
4810             *
4811             * @param type the type
4812             * @param active the active
4813             * @return the matching groups
4814             * @throws SystemException if a system exception occurred
4815             */
4816            @Override
4817            public List<Group> findByT_A(int type, boolean active)
4818                    throws SystemException {
4819                    return findByT_A(type, active, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4820                            null);
4821            }
4822    
4823            /**
4824             * Returns a range of all the groups where type = &#63; and active = &#63;.
4825             *
4826             * <p>
4827             * 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.
4828             * </p>
4829             *
4830             * @param type the type
4831             * @param active the active
4832             * @param start the lower bound of the range of groups
4833             * @param end the upper bound of the range of groups (not inclusive)
4834             * @return the range of matching groups
4835             * @throws SystemException if a system exception occurred
4836             */
4837            @Override
4838            public List<Group> findByT_A(int type, boolean active, int start, int end)
4839                    throws SystemException {
4840                    return findByT_A(type, active, start, end, null);
4841            }
4842    
4843            /**
4844             * Returns an ordered range of all the groups where type = &#63; and active = &#63;.
4845             *
4846             * <p>
4847             * 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.
4848             * </p>
4849             *
4850             * @param type the type
4851             * @param active the active
4852             * @param start the lower bound of the range of groups
4853             * @param end the upper bound of the range of groups (not inclusive)
4854             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4855             * @return the ordered range of matching groups
4856             * @throws SystemException if a system exception occurred
4857             */
4858            @Override
4859            public List<Group> findByT_A(int type, boolean active, int start, int end,
4860                    OrderByComparator orderByComparator) throws SystemException {
4861                    boolean pagination = true;
4862                    FinderPath finderPath = null;
4863                    Object[] finderArgs = null;
4864    
4865                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4866                                    (orderByComparator == null)) {
4867                            pagination = false;
4868                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
4869                            finderArgs = new Object[] { type, active };
4870                    }
4871                    else {
4872                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
4873                            finderArgs = new Object[] {
4874                                            type, active,
4875                                            
4876                                            start, end, orderByComparator
4877                                    };
4878                    }
4879    
4880                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
4881                                    finderArgs, this);
4882    
4883                    if ((list != null) && !list.isEmpty()) {
4884                            for (Group group : list) {
4885                                    if ((type != group.getType()) || (active != group.getActive())) {
4886                                            list = null;
4887    
4888                                            break;
4889                                    }
4890                            }
4891                    }
4892    
4893                    if (list == null) {
4894                            StringBundler query = null;
4895    
4896                            if (orderByComparator != null) {
4897                                    query = new StringBundler(4 +
4898                                                    (orderByComparator.getOrderByFields().length * 3));
4899                            }
4900                            else {
4901                                    query = new StringBundler(4);
4902                            }
4903    
4904                            query.append(_SQL_SELECT_GROUP__WHERE);
4905    
4906                            query.append(_FINDER_COLUMN_T_A_TYPE_2);
4907    
4908                            query.append(_FINDER_COLUMN_T_A_ACTIVE_2);
4909    
4910                            if (orderByComparator != null) {
4911                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4912                                            orderByComparator);
4913                            }
4914                            else
4915                             if (pagination) {
4916                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
4917                            }
4918    
4919                            String sql = query.toString();
4920    
4921                            Session session = null;
4922    
4923                            try {
4924                                    session = openSession();
4925    
4926                                    Query q = session.createQuery(sql);
4927    
4928                                    QueryPos qPos = QueryPos.getInstance(q);
4929    
4930                                    qPos.add(type);
4931    
4932                                    qPos.add(active);
4933    
4934                                    if (!pagination) {
4935                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
4936                                                            end, false);
4937    
4938                                            Collections.sort(list);
4939    
4940                                            list = new UnmodifiableList<Group>(list);
4941                                    }
4942                                    else {
4943                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
4944                                                            end);
4945                                    }
4946    
4947                                    cacheResult(list);
4948    
4949                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4950                            }
4951                            catch (Exception e) {
4952                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4953    
4954                                    throw processException(e);
4955                            }
4956                            finally {
4957                                    closeSession(session);
4958                            }
4959                    }
4960    
4961                    return list;
4962            }
4963    
4964            /**
4965             * Returns the first group in the ordered set where type = &#63; and active = &#63;.
4966             *
4967             * @param type the type
4968             * @param active the active
4969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4970             * @return the first matching group
4971             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
4972             * @throws SystemException if a system exception occurred
4973             */
4974            @Override
4975            public Group findByT_A_First(int type, boolean active,
4976                    OrderByComparator orderByComparator)
4977                    throws NoSuchGroupException, SystemException {
4978                    Group group = fetchByT_A_First(type, active, orderByComparator);
4979    
4980                    if (group != null) {
4981                            return group;
4982                    }
4983    
4984                    StringBundler msg = new StringBundler(6);
4985    
4986                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4987    
4988                    msg.append("type=");
4989                    msg.append(type);
4990    
4991                    msg.append(", active=");
4992                    msg.append(active);
4993    
4994                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4995    
4996                    throw new NoSuchGroupException(msg.toString());
4997            }
4998    
4999            /**
5000             * Returns the first group in the ordered set where type = &#63; and active = &#63;.
5001             *
5002             * @param type the type
5003             * @param active the active
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 fetchByT_A_First(int type, boolean active,
5010                    OrderByComparator orderByComparator) throws SystemException {
5011                    List<Group> list = findByT_A(type, active, 0, 1, orderByComparator);
5012    
5013                    if (!list.isEmpty()) {
5014                            return list.get(0);
5015                    }
5016    
5017                    return null;
5018            }
5019    
5020            /**
5021             * Returns the last group in the ordered set where type = &#63; and active = &#63;.
5022             *
5023             * @param type the type
5024             * @param active the active
5025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5026             * @return the last matching group
5027             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5028             * @throws SystemException if a system exception occurred
5029             */
5030            @Override
5031            public Group findByT_A_Last(int type, boolean active,
5032                    OrderByComparator orderByComparator)
5033                    throws NoSuchGroupException, SystemException {
5034                    Group group = fetchByT_A_Last(type, active, orderByComparator);
5035    
5036                    if (group != null) {
5037                            return group;
5038                    }
5039    
5040                    StringBundler msg = new StringBundler(6);
5041    
5042                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5043    
5044                    msg.append("type=");
5045                    msg.append(type);
5046    
5047                    msg.append(", active=");
5048                    msg.append(active);
5049    
5050                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5051    
5052                    throw new NoSuchGroupException(msg.toString());
5053            }
5054    
5055            /**
5056             * Returns the last group in the ordered set where type = &#63; and active = &#63;.
5057             *
5058             * @param type the type
5059             * @param active the active
5060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5061             * @return the last matching group, or <code>null</code> if a matching group could not be found
5062             * @throws SystemException if a system exception occurred
5063             */
5064            @Override
5065            public Group fetchByT_A_Last(int type, boolean active,
5066                    OrderByComparator orderByComparator) throws SystemException {
5067                    int count = countByT_A(type, active);
5068    
5069                    if (count == 0) {
5070                            return null;
5071                    }
5072    
5073                    List<Group> list = findByT_A(type, active, count - 1, count,
5074                                    orderByComparator);
5075    
5076                    if (!list.isEmpty()) {
5077                            return list.get(0);
5078                    }
5079    
5080                    return null;
5081            }
5082    
5083            /**
5084             * Returns the groups before and after the current group in the ordered set where type = &#63; and active = &#63;.
5085             *
5086             * @param groupId the primary key of the current group
5087             * @param type the type
5088             * @param active the active
5089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5090             * @return the previous, current, and next group
5091             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
5092             * @throws SystemException if a system exception occurred
5093             */
5094            @Override
5095            public Group[] findByT_A_PrevAndNext(long groupId, int type,
5096                    boolean active, OrderByComparator orderByComparator)
5097                    throws NoSuchGroupException, SystemException {
5098                    Group group = findByPrimaryKey(groupId);
5099    
5100                    Session session = null;
5101    
5102                    try {
5103                            session = openSession();
5104    
5105                            Group[] array = new GroupImpl[3];
5106    
5107                            array[0] = getByT_A_PrevAndNext(session, group, type, active,
5108                                            orderByComparator, true);
5109    
5110                            array[1] = group;
5111    
5112                            array[2] = getByT_A_PrevAndNext(session, group, type, active,
5113                                            orderByComparator, false);
5114    
5115                            return array;
5116                    }
5117                    catch (Exception e) {
5118                            throw processException(e);
5119                    }
5120                    finally {
5121                            closeSession(session);
5122                    }
5123            }
5124    
5125            protected Group getByT_A_PrevAndNext(Session session, Group group,
5126                    int type, boolean active, OrderByComparator orderByComparator,
5127                    boolean previous) {
5128                    StringBundler query = null;
5129    
5130                    if (orderByComparator != null) {
5131                            query = new StringBundler(6 +
5132                                            (orderByComparator.getOrderByFields().length * 6));
5133                    }
5134                    else {
5135                            query = new StringBundler(3);
5136                    }
5137    
5138                    query.append(_SQL_SELECT_GROUP__WHERE);
5139    
5140                    query.append(_FINDER_COLUMN_T_A_TYPE_2);
5141    
5142                    query.append(_FINDER_COLUMN_T_A_ACTIVE_2);
5143    
5144                    if (orderByComparator != null) {
5145                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5146    
5147                            if (orderByConditionFields.length > 0) {
5148                                    query.append(WHERE_AND);
5149                            }
5150    
5151                            for (int i = 0; i < orderByConditionFields.length; i++) {
5152                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5153                                    query.append(orderByConditionFields[i]);
5154    
5155                                    if ((i + 1) < orderByConditionFields.length) {
5156                                            if (orderByComparator.isAscending() ^ previous) {
5157                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5158                                            }
5159                                            else {
5160                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5161                                            }
5162                                    }
5163                                    else {
5164                                            if (orderByComparator.isAscending() ^ previous) {
5165                                                    query.append(WHERE_GREATER_THAN);
5166                                            }
5167                                            else {
5168                                                    query.append(WHERE_LESSER_THAN);
5169                                            }
5170                                    }
5171                            }
5172    
5173                            query.append(ORDER_BY_CLAUSE);
5174    
5175                            String[] orderByFields = orderByComparator.getOrderByFields();
5176    
5177                            for (int i = 0; i < orderByFields.length; i++) {
5178                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5179                                    query.append(orderByFields[i]);
5180    
5181                                    if ((i + 1) < orderByFields.length) {
5182                                            if (orderByComparator.isAscending() ^ previous) {
5183                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5184                                            }
5185                                            else {
5186                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5187                                            }
5188                                    }
5189                                    else {
5190                                            if (orderByComparator.isAscending() ^ previous) {
5191                                                    query.append(ORDER_BY_ASC);
5192                                            }
5193                                            else {
5194                                                    query.append(ORDER_BY_DESC);
5195                                            }
5196                                    }
5197                            }
5198                    }
5199                    else {
5200                            query.append(GroupModelImpl.ORDER_BY_JPQL);
5201                    }
5202    
5203                    String sql = query.toString();
5204    
5205                    Query q = session.createQuery(sql);
5206    
5207                    q.setFirstResult(0);
5208                    q.setMaxResults(2);
5209    
5210                    QueryPos qPos = QueryPos.getInstance(q);
5211    
5212                    qPos.add(type);
5213    
5214                    qPos.add(active);
5215    
5216                    if (orderByComparator != null) {
5217                            Object[] values = orderByComparator.getOrderByConditionValues(group);
5218    
5219                            for (Object value : values) {
5220                                    qPos.add(value);
5221                            }
5222                    }
5223    
5224                    List<Group> list = q.list();
5225    
5226                    if (list.size() == 2) {
5227                            return list.get(1);
5228                    }
5229                    else {
5230                            return null;
5231                    }
5232            }
5233    
5234            /**
5235             * Removes all the groups where type = &#63; and active = &#63; from the database.
5236             *
5237             * @param type the type
5238             * @param active the active
5239             * @throws SystemException if a system exception occurred
5240             */
5241            @Override
5242            public void removeByT_A(int type, boolean active) throws SystemException {
5243                    for (Group group : findByT_A(type, active, QueryUtil.ALL_POS,
5244                                    QueryUtil.ALL_POS, null)) {
5245                            remove(group);
5246                    }
5247            }
5248    
5249            /**
5250             * Returns the number of groups where type = &#63; and active = &#63;.
5251             *
5252             * @param type the type
5253             * @param active the active
5254             * @return the number of matching groups
5255             * @throws SystemException if a system exception occurred
5256             */
5257            @Override
5258            public int countByT_A(int type, boolean active) throws SystemException {
5259                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
5260    
5261                    Object[] finderArgs = new Object[] { type, active };
5262    
5263                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5264                                    this);
5265    
5266                    if (count == null) {
5267                            StringBundler query = new StringBundler(3);
5268    
5269                            query.append(_SQL_COUNT_GROUP__WHERE);
5270    
5271                            query.append(_FINDER_COLUMN_T_A_TYPE_2);
5272    
5273                            query.append(_FINDER_COLUMN_T_A_ACTIVE_2);
5274    
5275                            String sql = query.toString();
5276    
5277                            Session session = null;
5278    
5279                            try {
5280                                    session = openSession();
5281    
5282                                    Query q = session.createQuery(sql);
5283    
5284                                    QueryPos qPos = QueryPos.getInstance(q);
5285    
5286                                    qPos.add(type);
5287    
5288                                    qPos.add(active);
5289    
5290                                    count = (Long)q.uniqueResult();
5291    
5292                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5293                            }
5294                            catch (Exception e) {
5295                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5296    
5297                                    throw processException(e);
5298                            }
5299                            finally {
5300                                    closeSession(session);
5301                            }
5302                    }
5303    
5304                    return count.intValue();
5305            }
5306    
5307            private static final String _FINDER_COLUMN_T_A_TYPE_2 = "group_.type = ? AND ";
5308            private static final String _FINDER_COLUMN_T_A_ACTIVE_2 = "group_.active = ?";
5309            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5310                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
5311                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_P",
5312                            new String[] {
5313                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5314                                    
5315                            Integer.class.getName(), Integer.class.getName(),
5316                                    OrderByComparator.class.getName()
5317                            });
5318            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5319                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
5320                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_P",
5321                            new String[] {
5322                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5323                            });
5324    
5325            /**
5326             * Returns all the groups where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5327             *
5328             * @param groupId the group ID
5329             * @param companyId the company ID
5330             * @param parentGroupId the parent group ID
5331             * @return the matching groups
5332             * @throws SystemException if a system exception occurred
5333             */
5334            @Override
5335            public List<Group> findByG_C_P(long groupId, long companyId,
5336                    long parentGroupId) throws SystemException {
5337                    return findByG_C_P(groupId, companyId, parentGroupId,
5338                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5339            }
5340    
5341            /**
5342             * Returns a range of all the groups where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5343             *
5344             * <p>
5345             * 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.
5346             * </p>
5347             *
5348             * @param groupId the group ID
5349             * @param companyId the company ID
5350             * @param parentGroupId the parent group ID
5351             * @param start the lower bound of the range of groups
5352             * @param end the upper bound of the range of groups (not inclusive)
5353             * @return the range of matching groups
5354             * @throws SystemException if a system exception occurred
5355             */
5356            @Override
5357            public List<Group> findByG_C_P(long groupId, long companyId,
5358                    long parentGroupId, int start, int end) throws SystemException {
5359                    return findByG_C_P(groupId, companyId, parentGroupId, start, end, null);
5360            }
5361    
5362            /**
5363             * Returns an ordered range of all the groups where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5364             *
5365             * <p>
5366             * 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.
5367             * </p>
5368             *
5369             * @param groupId the group ID
5370             * @param companyId the company ID
5371             * @param parentGroupId the parent group ID
5372             * @param start the lower bound of the range of groups
5373             * @param end the upper bound of the range of groups (not inclusive)
5374             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5375             * @return the ordered range of matching groups
5376             * @throws SystemException if a system exception occurred
5377             */
5378            @Override
5379            public List<Group> findByG_C_P(long groupId, long companyId,
5380                    long parentGroupId, int start, int end,
5381                    OrderByComparator orderByComparator) throws SystemException {
5382                    boolean pagination = true;
5383                    FinderPath finderPath = null;
5384                    Object[] finderArgs = null;
5385    
5386                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_P;
5387                    finderArgs = new Object[] {
5388                                    groupId, companyId, parentGroupId,
5389                                    
5390                                    start, end, orderByComparator
5391                            };
5392    
5393                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
5394                                    finderArgs, this);
5395    
5396                    if ((list != null) && !list.isEmpty()) {
5397                            for (Group group : list) {
5398                                    if ((groupId >= group.getGroupId()) ||
5399                                                    (companyId != group.getCompanyId()) ||
5400                                                    (parentGroupId != group.getParentGroupId())) {
5401                                            list = null;
5402    
5403                                            break;
5404                                    }
5405                            }
5406                    }
5407    
5408                    if (list == null) {
5409                            StringBundler query = null;
5410    
5411                            if (orderByComparator != null) {
5412                                    query = new StringBundler(5 +
5413                                                    (orderByComparator.getOrderByFields().length * 3));
5414                            }
5415                            else {
5416                                    query = new StringBundler(5);
5417                            }
5418    
5419                            query.append(_SQL_SELECT_GROUP__WHERE);
5420    
5421                            query.append(_FINDER_COLUMN_G_C_P_GROUPID_2);
5422    
5423                            query.append(_FINDER_COLUMN_G_C_P_COMPANYID_2);
5424    
5425                            query.append(_FINDER_COLUMN_G_C_P_PARENTGROUPID_2);
5426    
5427                            if (orderByComparator != null) {
5428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5429                                            orderByComparator);
5430                            }
5431                            else
5432                             if (pagination) {
5433                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
5434                            }
5435    
5436                            String sql = query.toString();
5437    
5438                            Session session = null;
5439    
5440                            try {
5441                                    session = openSession();
5442    
5443                                    Query q = session.createQuery(sql);
5444    
5445                                    QueryPos qPos = QueryPos.getInstance(q);
5446    
5447                                    qPos.add(groupId);
5448    
5449                                    qPos.add(companyId);
5450    
5451                                    qPos.add(parentGroupId);
5452    
5453                                    if (!pagination) {
5454                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
5455                                                            end, false);
5456    
5457                                            Collections.sort(list);
5458    
5459                                            list = new UnmodifiableList<Group>(list);
5460                                    }
5461                                    else {
5462                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
5463                                                            end);
5464                                    }
5465    
5466                                    cacheResult(list);
5467    
5468                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5469                            }
5470                            catch (Exception e) {
5471                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5472    
5473                                    throw processException(e);
5474                            }
5475                            finally {
5476                                    closeSession(session);
5477                            }
5478                    }
5479    
5480                    return list;
5481            }
5482    
5483            /**
5484             * Returns the first group in the ordered set where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5485             *
5486             * @param groupId the group ID
5487             * @param companyId the company ID
5488             * @param parentGroupId the parent group ID
5489             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5490             * @return the first matching group
5491             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5492             * @throws SystemException if a system exception occurred
5493             */
5494            @Override
5495            public Group findByG_C_P_First(long groupId, long companyId,
5496                    long parentGroupId, OrderByComparator orderByComparator)
5497                    throws NoSuchGroupException, SystemException {
5498                    Group group = fetchByG_C_P_First(groupId, companyId, parentGroupId,
5499                                    orderByComparator);
5500    
5501                    if (group != null) {
5502                            return group;
5503                    }
5504    
5505                    StringBundler msg = new StringBundler(8);
5506    
5507                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5508    
5509                    msg.append("groupId=");
5510                    msg.append(groupId);
5511    
5512                    msg.append(", companyId=");
5513                    msg.append(companyId);
5514    
5515                    msg.append(", parentGroupId=");
5516                    msg.append(parentGroupId);
5517    
5518                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5519    
5520                    throw new NoSuchGroupException(msg.toString());
5521            }
5522    
5523            /**
5524             * Returns the first group in the ordered set where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5525             *
5526             * @param groupId the group ID
5527             * @param companyId the company ID
5528             * @param parentGroupId the parent group ID
5529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5530             * @return the first matching group, or <code>null</code> if a matching group could not be found
5531             * @throws SystemException if a system exception occurred
5532             */
5533            @Override
5534            public Group fetchByG_C_P_First(long groupId, long companyId,
5535                    long parentGroupId, OrderByComparator orderByComparator)
5536                    throws SystemException {
5537                    List<Group> list = findByG_C_P(groupId, companyId, parentGroupId, 0, 1,
5538                                    orderByComparator);
5539    
5540                    if (!list.isEmpty()) {
5541                            return list.get(0);
5542                    }
5543    
5544                    return null;
5545            }
5546    
5547            /**
5548             * Returns the last group in the ordered set where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5549             *
5550             * @param groupId the group ID
5551             * @param companyId the company ID
5552             * @param parentGroupId the parent group ID
5553             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5554             * @return the last matching group
5555             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5556             * @throws SystemException if a system exception occurred
5557             */
5558            @Override
5559            public Group findByG_C_P_Last(long groupId, long companyId,
5560                    long parentGroupId, OrderByComparator orderByComparator)
5561                    throws NoSuchGroupException, SystemException {
5562                    Group group = fetchByG_C_P_Last(groupId, companyId, parentGroupId,
5563                                    orderByComparator);
5564    
5565                    if (group != null) {
5566                            return group;
5567                    }
5568    
5569                    StringBundler msg = new StringBundler(8);
5570    
5571                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5572    
5573                    msg.append("groupId=");
5574                    msg.append(groupId);
5575    
5576                    msg.append(", companyId=");
5577                    msg.append(companyId);
5578    
5579                    msg.append(", parentGroupId=");
5580                    msg.append(parentGroupId);
5581    
5582                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5583    
5584                    throw new NoSuchGroupException(msg.toString());
5585            }
5586    
5587            /**
5588             * Returns the last group in the ordered set where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5589             *
5590             * @param groupId the group ID
5591             * @param companyId the company ID
5592             * @param parentGroupId the parent group ID
5593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5594             * @return the last matching group, or <code>null</code> if a matching group could not be found
5595             * @throws SystemException if a system exception occurred
5596             */
5597            @Override
5598            public Group fetchByG_C_P_Last(long groupId, long companyId,
5599                    long parentGroupId, OrderByComparator orderByComparator)
5600                    throws SystemException {
5601                    int count = countByG_C_P(groupId, companyId, parentGroupId);
5602    
5603                    if (count == 0) {
5604                            return null;
5605                    }
5606    
5607                    List<Group> list = findByG_C_P(groupId, companyId, parentGroupId,
5608                                    count - 1, count, orderByComparator);
5609    
5610                    if (!list.isEmpty()) {
5611                            return list.get(0);
5612                    }
5613    
5614                    return null;
5615            }
5616    
5617            /**
5618             * Removes all the groups where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63; from the database.
5619             *
5620             * @param groupId the group ID
5621             * @param companyId the company ID
5622             * @param parentGroupId the parent group ID
5623             * @throws SystemException if a system exception occurred
5624             */
5625            @Override
5626            public void removeByG_C_P(long groupId, long companyId, long parentGroupId)
5627                    throws SystemException {
5628                    for (Group group : findByG_C_P(groupId, companyId, parentGroupId,
5629                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5630                            remove(group);
5631                    }
5632            }
5633    
5634            /**
5635             * Returns the number of groups where groupId &gt; &#63; and companyId = &#63; and parentGroupId = &#63;.
5636             *
5637             * @param groupId the group ID
5638             * @param companyId the company ID
5639             * @param parentGroupId the parent group ID
5640             * @return the number of matching groups
5641             * @throws SystemException if a system exception occurred
5642             */
5643            @Override
5644            public int countByG_C_P(long groupId, long companyId, long parentGroupId)
5645                    throws SystemException {
5646                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_P;
5647    
5648                    Object[] finderArgs = new Object[] { groupId, companyId, parentGroupId };
5649    
5650                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5651                                    this);
5652    
5653                    if (count == null) {
5654                            StringBundler query = new StringBundler(4);
5655    
5656                            query.append(_SQL_COUNT_GROUP__WHERE);
5657    
5658                            query.append(_FINDER_COLUMN_G_C_P_GROUPID_2);
5659    
5660                            query.append(_FINDER_COLUMN_G_C_P_COMPANYID_2);
5661    
5662                            query.append(_FINDER_COLUMN_G_C_P_PARENTGROUPID_2);
5663    
5664                            String sql = query.toString();
5665    
5666                            Session session = null;
5667    
5668                            try {
5669                                    session = openSession();
5670    
5671                                    Query q = session.createQuery(sql);
5672    
5673                                    QueryPos qPos = QueryPos.getInstance(q);
5674    
5675                                    qPos.add(groupId);
5676    
5677                                    qPos.add(companyId);
5678    
5679                                    qPos.add(parentGroupId);
5680    
5681                                    count = (Long)q.uniqueResult();
5682    
5683                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5684                            }
5685                            catch (Exception e) {
5686                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5687    
5688                                    throw processException(e);
5689                            }
5690                            finally {
5691                                    closeSession(session);
5692                            }
5693                    }
5694    
5695                    return count.intValue();
5696            }
5697    
5698            private static final String _FINDER_COLUMN_G_C_P_GROUPID_2 = "group_.groupId > ? AND ";
5699            private static final String _FINDER_COLUMN_G_C_P_COMPANYID_2 = "group_.companyId = ? AND ";
5700            private static final String _FINDER_COLUMN_G_C_P_PARENTGROUPID_2 = "group_.parentGroupId = ?";
5701            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5702                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
5703                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
5704                            new String[] {
5705                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5706                            },
5707                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
5708                            GroupModelImpl.CLASSNAMEID_COLUMN_BITMASK |
5709                            GroupModelImpl.CLASSPK_COLUMN_BITMASK);
5710            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5711                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
5712                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
5713                            new String[] {
5714                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5715                            });
5716    
5717            /**
5718             * 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.
5719             *
5720             * @param companyId the company ID
5721             * @param classNameId the class name ID
5722             * @param classPK the class p k
5723             * @return the matching group
5724             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
5725             * @throws SystemException if a system exception occurred
5726             */
5727            @Override
5728            public Group findByC_C_C(long companyId, long classNameId, long classPK)
5729                    throws NoSuchGroupException, SystemException {
5730                    Group group = fetchByC_C_C(companyId, classNameId, classPK);
5731    
5732                    if (group == null) {
5733                            StringBundler msg = new StringBundler(8);
5734    
5735                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5736    
5737                            msg.append("companyId=");
5738                            msg.append(companyId);
5739    
5740                            msg.append(", classNameId=");
5741                            msg.append(classNameId);
5742    
5743                            msg.append(", classPK=");
5744                            msg.append(classPK);
5745    
5746                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5747    
5748                            if (_log.isWarnEnabled()) {
5749                                    _log.warn(msg.toString());
5750                            }
5751    
5752                            throw new NoSuchGroupException(msg.toString());
5753                    }
5754    
5755                    return group;
5756            }
5757    
5758            /**
5759             * 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.
5760             *
5761             * @param companyId the company ID
5762             * @param classNameId the class name ID
5763             * @param classPK the class p k
5764             * @return the matching group, or <code>null</code> if a matching group could not be found
5765             * @throws SystemException if a system exception occurred
5766             */
5767            @Override
5768            public Group fetchByC_C_C(long companyId, long classNameId, long classPK)
5769                    throws SystemException {
5770                    return fetchByC_C_C(companyId, classNameId, classPK, true);
5771            }
5772    
5773            /**
5774             * 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.
5775             *
5776             * @param companyId the company ID
5777             * @param classNameId the class name ID
5778             * @param classPK the class p k
5779             * @param retrieveFromCache whether to use the finder cache
5780             * @return the matching group, or <code>null</code> if a matching group could not be found
5781             * @throws SystemException if a system exception occurred
5782             */
5783            @Override
5784            public Group fetchByC_C_C(long companyId, long classNameId, long classPK,
5785                    boolean retrieveFromCache) throws SystemException {
5786                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
5787    
5788                    Object result = null;
5789    
5790                    if (retrieveFromCache) {
5791                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
5792                                            finderArgs, this);
5793                    }
5794    
5795                    if (result instanceof Group) {
5796                            Group group = (Group)result;
5797    
5798                            if ((companyId != group.getCompanyId()) ||
5799                                            (classNameId != group.getClassNameId()) ||
5800                                            (classPK != group.getClassPK())) {
5801                                    result = null;
5802                            }
5803                    }
5804    
5805                    if (result == null) {
5806                            StringBundler query = new StringBundler(5);
5807    
5808                            query.append(_SQL_SELECT_GROUP__WHERE);
5809    
5810                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
5811    
5812                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
5813    
5814                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
5815    
5816                            String sql = query.toString();
5817    
5818                            Session session = null;
5819    
5820                            try {
5821                                    session = openSession();
5822    
5823                                    Query q = session.createQuery(sql);
5824    
5825                                    QueryPos qPos = QueryPos.getInstance(q);
5826    
5827                                    qPos.add(companyId);
5828    
5829                                    qPos.add(classNameId);
5830    
5831                                    qPos.add(classPK);
5832    
5833                                    List<Group> list = q.list();
5834    
5835                                    if (list.isEmpty()) {
5836                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
5837                                                    finderArgs, list);
5838                                    }
5839                                    else {
5840                                            Group group = list.get(0);
5841    
5842                                            result = group;
5843    
5844                                            cacheResult(group);
5845    
5846                                            if ((group.getCompanyId() != companyId) ||
5847                                                            (group.getClassNameId() != classNameId) ||
5848                                                            (group.getClassPK() != classPK)) {
5849                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
5850                                                            finderArgs, group);
5851                                            }
5852                                    }
5853                            }
5854                            catch (Exception e) {
5855                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
5856                                            finderArgs);
5857    
5858                                    throw processException(e);
5859                            }
5860                            finally {
5861                                    closeSession(session);
5862                            }
5863                    }
5864    
5865                    if (result instanceof List<?>) {
5866                            return null;
5867                    }
5868                    else {
5869                            return (Group)result;
5870                    }
5871            }
5872    
5873            /**
5874             * Removes the group where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
5875             *
5876             * @param companyId the company ID
5877             * @param classNameId the class name ID
5878             * @param classPK the class p k
5879             * @return the group that was removed
5880             * @throws SystemException if a system exception occurred
5881             */
5882            @Override
5883            public Group removeByC_C_C(long companyId, long classNameId, long classPK)
5884                    throws NoSuchGroupException, SystemException {
5885                    Group group = findByC_C_C(companyId, classNameId, classPK);
5886    
5887                    return remove(group);
5888            }
5889    
5890            /**
5891             * Returns the number of groups where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
5892             *
5893             * @param companyId the company ID
5894             * @param classNameId the class name ID
5895             * @param classPK the class p k
5896             * @return the number of matching groups
5897             * @throws SystemException if a system exception occurred
5898             */
5899            @Override
5900            public int countByC_C_C(long companyId, long classNameId, long classPK)
5901                    throws SystemException {
5902                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
5903    
5904                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
5905    
5906                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5907                                    this);
5908    
5909                    if (count == null) {
5910                            StringBundler query = new StringBundler(4);
5911    
5912                            query.append(_SQL_COUNT_GROUP__WHERE);
5913    
5914                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
5915    
5916                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
5917    
5918                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
5919    
5920                            String sql = query.toString();
5921    
5922                            Session session = null;
5923    
5924                            try {
5925                                    session = openSession();
5926    
5927                                    Query q = session.createQuery(sql);
5928    
5929                                    QueryPos qPos = QueryPos.getInstance(q);
5930    
5931                                    qPos.add(companyId);
5932    
5933                                    qPos.add(classNameId);
5934    
5935                                    qPos.add(classPK);
5936    
5937                                    count = (Long)q.uniqueResult();
5938    
5939                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5940                            }
5941                            catch (Exception e) {
5942                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5943    
5944                                    throw processException(e);
5945                            }
5946                            finally {
5947                                    closeSession(session);
5948                            }
5949                    }
5950    
5951                    return count.intValue();
5952            }
5953    
5954            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "group_.companyId = ? AND ";
5955            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "group_.classNameId = ? AND ";
5956            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "group_.classPK = ?";
5957            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5958                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
5959                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_P",
5960                            new String[] {
5961                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5962                                    
5963                            Integer.class.getName(), Integer.class.getName(),
5964                                    OrderByComparator.class.getName()
5965                            });
5966            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5967                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
5968                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_P",
5969                            new String[] {
5970                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5971                            },
5972                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
5973                            GroupModelImpl.CLASSNAMEID_COLUMN_BITMASK |
5974                            GroupModelImpl.PARENTGROUPID_COLUMN_BITMASK |
5975                            GroupModelImpl.NAME_COLUMN_BITMASK);
5976            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_P = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
5977                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
5978                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_P",
5979                            new String[] {
5980                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5981                            });
5982    
5983            /**
5984             * Returns all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
5985             *
5986             * @param companyId the company ID
5987             * @param classNameId the class name ID
5988             * @param parentGroupId the parent group ID
5989             * @return the matching groups
5990             * @throws SystemException if a system exception occurred
5991             */
5992            @Override
5993            public List<Group> findByC_C_P(long companyId, long classNameId,
5994                    long parentGroupId) throws SystemException {
5995                    return findByC_C_P(companyId, classNameId, parentGroupId,
5996                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5997            }
5998    
5999            /**
6000             * Returns a range of all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6001             *
6002             * <p>
6003             * 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.
6004             * </p>
6005             *
6006             * @param companyId the company ID
6007             * @param classNameId the class name ID
6008             * @param parentGroupId the parent group ID
6009             * @param start the lower bound of the range of groups
6010             * @param end the upper bound of the range of groups (not inclusive)
6011             * @return the range of matching groups
6012             * @throws SystemException if a system exception occurred
6013             */
6014            @Override
6015            public List<Group> findByC_C_P(long companyId, long classNameId,
6016                    long parentGroupId, int start, int end) throws SystemException {
6017                    return findByC_C_P(companyId, classNameId, parentGroupId, start, end,
6018                            null);
6019            }
6020    
6021            /**
6022             * Returns an ordered range of all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6023             *
6024             * <p>
6025             * 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.
6026             * </p>
6027             *
6028             * @param companyId the company ID
6029             * @param classNameId the class name ID
6030             * @param parentGroupId the parent group ID
6031             * @param start the lower bound of the range of groups
6032             * @param end the upper bound of the range of groups (not inclusive)
6033             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6034             * @return the ordered range of matching groups
6035             * @throws SystemException if a system exception occurred
6036             */
6037            @Override
6038            public List<Group> findByC_C_P(long companyId, long classNameId,
6039                    long parentGroupId, int start, int end,
6040                    OrderByComparator orderByComparator) throws SystemException {
6041                    boolean pagination = true;
6042                    FinderPath finderPath = null;
6043                    Object[] finderArgs = null;
6044    
6045                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6046                                    (orderByComparator == null)) {
6047                            pagination = false;
6048                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P;
6049                            finderArgs = new Object[] { companyId, classNameId, parentGroupId };
6050                    }
6051                    else {
6052                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_P;
6053                            finderArgs = new Object[] {
6054                                            companyId, classNameId, parentGroupId,
6055                                            
6056                                            start, end, orderByComparator
6057                                    };
6058                    }
6059    
6060                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
6061                                    finderArgs, this);
6062    
6063                    if ((list != null) && !list.isEmpty()) {
6064                            for (Group group : list) {
6065                                    if ((companyId != group.getCompanyId()) ||
6066                                                    (classNameId != group.getClassNameId()) ||
6067                                                    (parentGroupId != group.getParentGroupId())) {
6068                                            list = null;
6069    
6070                                            break;
6071                                    }
6072                            }
6073                    }
6074    
6075                    if (list == null) {
6076                            StringBundler query = null;
6077    
6078                            if (orderByComparator != null) {
6079                                    query = new StringBundler(5 +
6080                                                    (orderByComparator.getOrderByFields().length * 3));
6081                            }
6082                            else {
6083                                    query = new StringBundler(5);
6084                            }
6085    
6086                            query.append(_SQL_SELECT_GROUP__WHERE);
6087    
6088                            query.append(_FINDER_COLUMN_C_C_P_COMPANYID_2);
6089    
6090                            query.append(_FINDER_COLUMN_C_C_P_CLASSNAMEID_2);
6091    
6092                            query.append(_FINDER_COLUMN_C_C_P_PARENTGROUPID_2);
6093    
6094                            if (orderByComparator != null) {
6095                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6096                                            orderByComparator);
6097                            }
6098                            else
6099                             if (pagination) {
6100                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
6101                            }
6102    
6103                            String sql = query.toString();
6104    
6105                            Session session = null;
6106    
6107                            try {
6108                                    session = openSession();
6109    
6110                                    Query q = session.createQuery(sql);
6111    
6112                                    QueryPos qPos = QueryPos.getInstance(q);
6113    
6114                                    qPos.add(companyId);
6115    
6116                                    qPos.add(classNameId);
6117    
6118                                    qPos.add(parentGroupId);
6119    
6120                                    if (!pagination) {
6121                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
6122                                                            end, false);
6123    
6124                                            Collections.sort(list);
6125    
6126                                            list = new UnmodifiableList<Group>(list);
6127                                    }
6128                                    else {
6129                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
6130                                                            end);
6131                                    }
6132    
6133                                    cacheResult(list);
6134    
6135                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6136                            }
6137                            catch (Exception e) {
6138                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6139    
6140                                    throw processException(e);
6141                            }
6142                            finally {
6143                                    closeSession(session);
6144                            }
6145                    }
6146    
6147                    return list;
6148            }
6149    
6150            /**
6151             * Returns the first group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6152             *
6153             * @param companyId the company ID
6154             * @param classNameId the class name ID
6155             * @param parentGroupId the parent group ID
6156             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6157             * @return the first matching group
6158             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
6159             * @throws SystemException if a system exception occurred
6160             */
6161            @Override
6162            public Group findByC_C_P_First(long companyId, long classNameId,
6163                    long parentGroupId, OrderByComparator orderByComparator)
6164                    throws NoSuchGroupException, SystemException {
6165                    Group group = fetchByC_C_P_First(companyId, classNameId, parentGroupId,
6166                                    orderByComparator);
6167    
6168                    if (group != null) {
6169                            return group;
6170                    }
6171    
6172                    StringBundler msg = new StringBundler(8);
6173    
6174                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6175    
6176                    msg.append("companyId=");
6177                    msg.append(companyId);
6178    
6179                    msg.append(", classNameId=");
6180                    msg.append(classNameId);
6181    
6182                    msg.append(", parentGroupId=");
6183                    msg.append(parentGroupId);
6184    
6185                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6186    
6187                    throw new NoSuchGroupException(msg.toString());
6188            }
6189    
6190            /**
6191             * Returns the first group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6192             *
6193             * @param companyId the company ID
6194             * @param classNameId the class name ID
6195             * @param parentGroupId the parent group ID
6196             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6197             * @return the first matching group, or <code>null</code> if a matching group could not be found
6198             * @throws SystemException if a system exception occurred
6199             */
6200            @Override
6201            public Group fetchByC_C_P_First(long companyId, long classNameId,
6202                    long parentGroupId, OrderByComparator orderByComparator)
6203                    throws SystemException {
6204                    List<Group> list = findByC_C_P(companyId, classNameId, parentGroupId,
6205                                    0, 1, orderByComparator);
6206    
6207                    if (!list.isEmpty()) {
6208                            return list.get(0);
6209                    }
6210    
6211                    return null;
6212            }
6213    
6214            /**
6215             * Returns the last group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6216             *
6217             * @param companyId the company ID
6218             * @param classNameId the class name ID
6219             * @param parentGroupId the parent group ID
6220             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6221             * @return the last matching group
6222             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
6223             * @throws SystemException if a system exception occurred
6224             */
6225            @Override
6226            public Group findByC_C_P_Last(long companyId, long classNameId,
6227                    long parentGroupId, OrderByComparator orderByComparator)
6228                    throws NoSuchGroupException, SystemException {
6229                    Group group = fetchByC_C_P_Last(companyId, classNameId, parentGroupId,
6230                                    orderByComparator);
6231    
6232                    if (group != null) {
6233                            return group;
6234                    }
6235    
6236                    StringBundler msg = new StringBundler(8);
6237    
6238                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6239    
6240                    msg.append("companyId=");
6241                    msg.append(companyId);
6242    
6243                    msg.append(", classNameId=");
6244                    msg.append(classNameId);
6245    
6246                    msg.append(", parentGroupId=");
6247                    msg.append(parentGroupId);
6248    
6249                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6250    
6251                    throw new NoSuchGroupException(msg.toString());
6252            }
6253    
6254            /**
6255             * Returns the last group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6256             *
6257             * @param companyId the company ID
6258             * @param classNameId the class name ID
6259             * @param parentGroupId the parent group ID
6260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6261             * @return the last matching group, or <code>null</code> if a matching group could not be found
6262             * @throws SystemException if a system exception occurred
6263             */
6264            @Override
6265            public Group fetchByC_C_P_Last(long companyId, long classNameId,
6266                    long parentGroupId, OrderByComparator orderByComparator)
6267                    throws SystemException {
6268                    int count = countByC_C_P(companyId, classNameId, parentGroupId);
6269    
6270                    if (count == 0) {
6271                            return null;
6272                    }
6273    
6274                    List<Group> list = findByC_C_P(companyId, classNameId, parentGroupId,
6275                                    count - 1, count, orderByComparator);
6276    
6277                    if (!list.isEmpty()) {
6278                            return list.get(0);
6279                    }
6280    
6281                    return null;
6282            }
6283    
6284            /**
6285             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6286             *
6287             * @param groupId the primary key of the current group
6288             * @param companyId the company ID
6289             * @param classNameId the class name ID
6290             * @param parentGroupId the parent group ID
6291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6292             * @return the previous, current, and next group
6293             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
6294             * @throws SystemException if a system exception occurred
6295             */
6296            @Override
6297            public Group[] findByC_C_P_PrevAndNext(long groupId, long companyId,
6298                    long classNameId, long parentGroupId,
6299                    OrderByComparator orderByComparator)
6300                    throws NoSuchGroupException, SystemException {
6301                    Group group = findByPrimaryKey(groupId);
6302    
6303                    Session session = null;
6304    
6305                    try {
6306                            session = openSession();
6307    
6308                            Group[] array = new GroupImpl[3];
6309    
6310                            array[0] = getByC_C_P_PrevAndNext(session, group, companyId,
6311                                            classNameId, parentGroupId, orderByComparator, true);
6312    
6313                            array[1] = group;
6314    
6315                            array[2] = getByC_C_P_PrevAndNext(session, group, companyId,
6316                                            classNameId, parentGroupId, orderByComparator, false);
6317    
6318                            return array;
6319                    }
6320                    catch (Exception e) {
6321                            throw processException(e);
6322                    }
6323                    finally {
6324                            closeSession(session);
6325                    }
6326            }
6327    
6328            protected Group getByC_C_P_PrevAndNext(Session session, Group group,
6329                    long companyId, long classNameId, long parentGroupId,
6330                    OrderByComparator orderByComparator, boolean previous) {
6331                    StringBundler query = null;
6332    
6333                    if (orderByComparator != null) {
6334                            query = new StringBundler(6 +
6335                                            (orderByComparator.getOrderByFields().length * 6));
6336                    }
6337                    else {
6338                            query = new StringBundler(3);
6339                    }
6340    
6341                    query.append(_SQL_SELECT_GROUP__WHERE);
6342    
6343                    query.append(_FINDER_COLUMN_C_C_P_COMPANYID_2);
6344    
6345                    query.append(_FINDER_COLUMN_C_C_P_CLASSNAMEID_2);
6346    
6347                    query.append(_FINDER_COLUMN_C_C_P_PARENTGROUPID_2);
6348    
6349                    if (orderByComparator != null) {
6350                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6351    
6352                            if (orderByConditionFields.length > 0) {
6353                                    query.append(WHERE_AND);
6354                            }
6355    
6356                            for (int i = 0; i < orderByConditionFields.length; i++) {
6357                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6358                                    query.append(orderByConditionFields[i]);
6359    
6360                                    if ((i + 1) < orderByConditionFields.length) {
6361                                            if (orderByComparator.isAscending() ^ previous) {
6362                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6363                                            }
6364                                            else {
6365                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6366                                            }
6367                                    }
6368                                    else {
6369                                            if (orderByComparator.isAscending() ^ previous) {
6370                                                    query.append(WHERE_GREATER_THAN);
6371                                            }
6372                                            else {
6373                                                    query.append(WHERE_LESSER_THAN);
6374                                            }
6375                                    }
6376                            }
6377    
6378                            query.append(ORDER_BY_CLAUSE);
6379    
6380                            String[] orderByFields = orderByComparator.getOrderByFields();
6381    
6382                            for (int i = 0; i < orderByFields.length; i++) {
6383                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6384                                    query.append(orderByFields[i]);
6385    
6386                                    if ((i + 1) < orderByFields.length) {
6387                                            if (orderByComparator.isAscending() ^ previous) {
6388                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6389                                            }
6390                                            else {
6391                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6392                                            }
6393                                    }
6394                                    else {
6395                                            if (orderByComparator.isAscending() ^ previous) {
6396                                                    query.append(ORDER_BY_ASC);
6397                                            }
6398                                            else {
6399                                                    query.append(ORDER_BY_DESC);
6400                                            }
6401                                    }
6402                            }
6403                    }
6404                    else {
6405                            query.append(GroupModelImpl.ORDER_BY_JPQL);
6406                    }
6407    
6408                    String sql = query.toString();
6409    
6410                    Query q = session.createQuery(sql);
6411    
6412                    q.setFirstResult(0);
6413                    q.setMaxResults(2);
6414    
6415                    QueryPos qPos = QueryPos.getInstance(q);
6416    
6417                    qPos.add(companyId);
6418    
6419                    qPos.add(classNameId);
6420    
6421                    qPos.add(parentGroupId);
6422    
6423                    if (orderByComparator != null) {
6424                            Object[] values = orderByComparator.getOrderByConditionValues(group);
6425    
6426                            for (Object value : values) {
6427                                    qPos.add(value);
6428                            }
6429                    }
6430    
6431                    List<Group> list = q.list();
6432    
6433                    if (list.size() == 2) {
6434                            return list.get(1);
6435                    }
6436                    else {
6437                            return null;
6438                    }
6439            }
6440    
6441            /**
6442             * Removes all the groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63; from the database.
6443             *
6444             * @param companyId the company ID
6445             * @param classNameId the class name ID
6446             * @param parentGroupId the parent group ID
6447             * @throws SystemException if a system exception occurred
6448             */
6449            @Override
6450            public void removeByC_C_P(long companyId, long classNameId,
6451                    long parentGroupId) throws SystemException {
6452                    for (Group group : findByC_C_P(companyId, classNameId, parentGroupId,
6453                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6454                            remove(group);
6455                    }
6456            }
6457    
6458            /**
6459             * Returns the number of groups where companyId = &#63; and classNameId = &#63; and parentGroupId = &#63;.
6460             *
6461             * @param companyId the company ID
6462             * @param classNameId the class name ID
6463             * @param parentGroupId the parent group ID
6464             * @return the number of matching groups
6465             * @throws SystemException if a system exception occurred
6466             */
6467            @Override
6468            public int countByC_C_P(long companyId, long classNameId, long parentGroupId)
6469                    throws SystemException {
6470                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_P;
6471    
6472                    Object[] finderArgs = new Object[] { companyId, classNameId, parentGroupId };
6473    
6474                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6475                                    this);
6476    
6477                    if (count == null) {
6478                            StringBundler query = new StringBundler(4);
6479    
6480                            query.append(_SQL_COUNT_GROUP__WHERE);
6481    
6482                            query.append(_FINDER_COLUMN_C_C_P_COMPANYID_2);
6483    
6484                            query.append(_FINDER_COLUMN_C_C_P_CLASSNAMEID_2);
6485    
6486                            query.append(_FINDER_COLUMN_C_C_P_PARENTGROUPID_2);
6487    
6488                            String sql = query.toString();
6489    
6490                            Session session = null;
6491    
6492                            try {
6493                                    session = openSession();
6494    
6495                                    Query q = session.createQuery(sql);
6496    
6497                                    QueryPos qPos = QueryPos.getInstance(q);
6498    
6499                                    qPos.add(companyId);
6500    
6501                                    qPos.add(classNameId);
6502    
6503                                    qPos.add(parentGroupId);
6504    
6505                                    count = (Long)q.uniqueResult();
6506    
6507                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6508                            }
6509                            catch (Exception e) {
6510                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6511    
6512                                    throw processException(e);
6513                            }
6514                            finally {
6515                                    closeSession(session);
6516                            }
6517                    }
6518    
6519                    return count.intValue();
6520            }
6521    
6522            private static final String _FINDER_COLUMN_C_C_P_COMPANYID_2 = "group_.companyId = ? AND ";
6523            private static final String _FINDER_COLUMN_C_C_P_CLASSNAMEID_2 = "group_.classNameId = ? AND ";
6524            private static final String _FINDER_COLUMN_C_C_P_PARENTGROUPID_2 = "group_.parentGroupId = ?";
6525            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
6526                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
6527                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P_S",
6528                            new String[] {
6529                                    Long.class.getName(), Long.class.getName(),
6530                                    Boolean.class.getName(),
6531                                    
6532                            Integer.class.getName(), Integer.class.getName(),
6533                                    OrderByComparator.class.getName()
6534                            });
6535            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
6536                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
6537                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P_S",
6538                            new String[] {
6539                                    Long.class.getName(), Long.class.getName(),
6540                                    Boolean.class.getName()
6541                            },
6542                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
6543                            GroupModelImpl.PARENTGROUPID_COLUMN_BITMASK |
6544                            GroupModelImpl.SITE_COLUMN_BITMASK |
6545                            GroupModelImpl.NAME_COLUMN_BITMASK);
6546            public static final FinderPath FINDER_PATH_COUNT_BY_C_P_S = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
6547                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
6548                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P_S",
6549                            new String[] {
6550                                    Long.class.getName(), Long.class.getName(),
6551                                    Boolean.class.getName()
6552                            });
6553    
6554            /**
6555             * Returns all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6556             *
6557             * @param companyId the company ID
6558             * @param parentGroupId the parent group ID
6559             * @param site the site
6560             * @return the matching groups
6561             * @throws SystemException if a system exception occurred
6562             */
6563            @Override
6564            public List<Group> findByC_P_S(long companyId, long parentGroupId,
6565                    boolean site) throws SystemException {
6566                    return findByC_P_S(companyId, parentGroupId, site, QueryUtil.ALL_POS,
6567                            QueryUtil.ALL_POS, null);
6568            }
6569    
6570            /**
6571             * Returns a range of all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6572             *
6573             * <p>
6574             * 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.
6575             * </p>
6576             *
6577             * @param companyId the company ID
6578             * @param parentGroupId the parent group ID
6579             * @param site the site
6580             * @param start the lower bound of the range of groups
6581             * @param end the upper bound of the range of groups (not inclusive)
6582             * @return the range of matching groups
6583             * @throws SystemException if a system exception occurred
6584             */
6585            @Override
6586            public List<Group> findByC_P_S(long companyId, long parentGroupId,
6587                    boolean site, int start, int end) throws SystemException {
6588                    return findByC_P_S(companyId, parentGroupId, site, start, end, null);
6589            }
6590    
6591            /**
6592             * Returns an ordered range of all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6593             *
6594             * <p>
6595             * 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.
6596             * </p>
6597             *
6598             * @param companyId the company ID
6599             * @param parentGroupId the parent group ID
6600             * @param site the site
6601             * @param start the lower bound of the range of groups
6602             * @param end the upper bound of the range of groups (not inclusive)
6603             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6604             * @return the ordered range of matching groups
6605             * @throws SystemException if a system exception occurred
6606             */
6607            @Override
6608            public List<Group> findByC_P_S(long companyId, long parentGroupId,
6609                    boolean site, int start, int end, OrderByComparator orderByComparator)
6610                    throws SystemException {
6611                    boolean pagination = true;
6612                    FinderPath finderPath = null;
6613                    Object[] finderArgs = null;
6614    
6615                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6616                                    (orderByComparator == null)) {
6617                            pagination = false;
6618                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S;
6619                            finderArgs = new Object[] { companyId, parentGroupId, site };
6620                    }
6621                    else {
6622                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P_S;
6623                            finderArgs = new Object[] {
6624                                            companyId, parentGroupId, site,
6625                                            
6626                                            start, end, orderByComparator
6627                                    };
6628                    }
6629    
6630                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
6631                                    finderArgs, this);
6632    
6633                    if ((list != null) && !list.isEmpty()) {
6634                            for (Group group : list) {
6635                                    if ((companyId != group.getCompanyId()) ||
6636                                                    (parentGroupId != group.getParentGroupId()) ||
6637                                                    (site != group.getSite())) {
6638                                            list = null;
6639    
6640                                            break;
6641                                    }
6642                            }
6643                    }
6644    
6645                    if (list == null) {
6646                            StringBundler query = null;
6647    
6648                            if (orderByComparator != null) {
6649                                    query = new StringBundler(5 +
6650                                                    (orderByComparator.getOrderByFields().length * 3));
6651                            }
6652                            else {
6653                                    query = new StringBundler(5);
6654                            }
6655    
6656                            query.append(_SQL_SELECT_GROUP__WHERE);
6657    
6658                            query.append(_FINDER_COLUMN_C_P_S_COMPANYID_2);
6659    
6660                            query.append(_FINDER_COLUMN_C_P_S_PARENTGROUPID_2);
6661    
6662                            query.append(_FINDER_COLUMN_C_P_S_SITE_2);
6663    
6664                            if (orderByComparator != null) {
6665                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6666                                            orderByComparator);
6667                            }
6668                            else
6669                             if (pagination) {
6670                                    query.append(GroupModelImpl.ORDER_BY_JPQL);
6671                            }
6672    
6673                            String sql = query.toString();
6674    
6675                            Session session = null;
6676    
6677                            try {
6678                                    session = openSession();
6679    
6680                                    Query q = session.createQuery(sql);
6681    
6682                                    QueryPos qPos = QueryPos.getInstance(q);
6683    
6684                                    qPos.add(companyId);
6685    
6686                                    qPos.add(parentGroupId);
6687    
6688                                    qPos.add(site);
6689    
6690                                    if (!pagination) {
6691                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
6692                                                            end, false);
6693    
6694                                            Collections.sort(list);
6695    
6696                                            list = new UnmodifiableList<Group>(list);
6697                                    }
6698                                    else {
6699                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
6700                                                            end);
6701                                    }
6702    
6703                                    cacheResult(list);
6704    
6705                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6706                            }
6707                            catch (Exception e) {
6708                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6709    
6710                                    throw processException(e);
6711                            }
6712                            finally {
6713                                    closeSession(session);
6714                            }
6715                    }
6716    
6717                    return list;
6718            }
6719    
6720            /**
6721             * Returns the first group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6722             *
6723             * @param companyId the company ID
6724             * @param parentGroupId the parent group ID
6725             * @param site the site
6726             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6727             * @return the first matching group
6728             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
6729             * @throws SystemException if a system exception occurred
6730             */
6731            @Override
6732            public Group findByC_P_S_First(long companyId, long parentGroupId,
6733                    boolean site, OrderByComparator orderByComparator)
6734                    throws NoSuchGroupException, SystemException {
6735                    Group group = fetchByC_P_S_First(companyId, parentGroupId, site,
6736                                    orderByComparator);
6737    
6738                    if (group != null) {
6739                            return group;
6740                    }
6741    
6742                    StringBundler msg = new StringBundler(8);
6743    
6744                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6745    
6746                    msg.append("companyId=");
6747                    msg.append(companyId);
6748    
6749                    msg.append(", parentGroupId=");
6750                    msg.append(parentGroupId);
6751    
6752                    msg.append(", site=");
6753                    msg.append(site);
6754    
6755                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6756    
6757                    throw new NoSuchGroupException(msg.toString());
6758            }
6759    
6760            /**
6761             * Returns the first group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6762             *
6763             * @param companyId the company ID
6764             * @param parentGroupId the parent group ID
6765             * @param site the site
6766             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6767             * @return the first matching group, or <code>null</code> if a matching group could not be found
6768             * @throws SystemException if a system exception occurred
6769             */
6770            @Override
6771            public Group fetchByC_P_S_First(long companyId, long parentGroupId,
6772                    boolean site, OrderByComparator orderByComparator)
6773                    throws SystemException {
6774                    List<Group> list = findByC_P_S(companyId, parentGroupId, site, 0, 1,
6775                                    orderByComparator);
6776    
6777                    if (!list.isEmpty()) {
6778                            return list.get(0);
6779                    }
6780    
6781                    return null;
6782            }
6783    
6784            /**
6785             * Returns the last group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6786             *
6787             * @param companyId the company ID
6788             * @param parentGroupId the parent group ID
6789             * @param site the site
6790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6791             * @return the last matching group
6792             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
6793             * @throws SystemException if a system exception occurred
6794             */
6795            @Override
6796            public Group findByC_P_S_Last(long companyId, long parentGroupId,
6797                    boolean site, OrderByComparator orderByComparator)
6798                    throws NoSuchGroupException, SystemException {
6799                    Group group = fetchByC_P_S_Last(companyId, parentGroupId, site,
6800                                    orderByComparator);
6801    
6802                    if (group != null) {
6803                            return group;
6804                    }
6805    
6806                    StringBundler msg = new StringBundler(8);
6807    
6808                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6809    
6810                    msg.append("companyId=");
6811                    msg.append(companyId);
6812    
6813                    msg.append(", parentGroupId=");
6814                    msg.append(parentGroupId);
6815    
6816                    msg.append(", site=");
6817                    msg.append(site);
6818    
6819                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6820    
6821                    throw new NoSuchGroupException(msg.toString());
6822            }
6823    
6824            /**
6825             * Returns the last group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6826             *
6827             * @param companyId the company ID
6828             * @param parentGroupId the parent group ID
6829             * @param site the site
6830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6831             * @return the last matching group, or <code>null</code> if a matching group could not be found
6832             * @throws SystemException if a system exception occurred
6833             */
6834            @Override
6835            public Group fetchByC_P_S_Last(long companyId, long parentGroupId,
6836                    boolean site, OrderByComparator orderByComparator)
6837                    throws SystemException {
6838                    int count = countByC_P_S(companyId, parentGroupId, site);
6839    
6840                    if (count == 0) {
6841                            return null;
6842                    }
6843    
6844                    List<Group> list = findByC_P_S(companyId, parentGroupId, site,
6845                                    count - 1, count, orderByComparator);
6846    
6847                    if (!list.isEmpty()) {
6848                            return list.get(0);
6849                    }
6850    
6851                    return null;
6852            }
6853    
6854            /**
6855             * Returns the groups before and after the current group in the ordered set where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
6856             *
6857             * @param groupId the primary key of the current group
6858             * @param companyId the company ID
6859             * @param parentGroupId the parent group ID
6860             * @param site the site
6861             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6862             * @return the previous, current, and next group
6863             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
6864             * @throws SystemException if a system exception occurred
6865             */
6866            @Override
6867            public Group[] findByC_P_S_PrevAndNext(long groupId, long companyId,
6868                    long parentGroupId, boolean site, OrderByComparator orderByComparator)
6869                    throws NoSuchGroupException, SystemException {
6870                    Group group = findByPrimaryKey(groupId);
6871    
6872                    Session session = null;
6873    
6874                    try {
6875                            session = openSession();
6876    
6877                            Group[] array = new GroupImpl[3];
6878    
6879                            array[0] = getByC_P_S_PrevAndNext(session, group, companyId,
6880                                            parentGroupId, site, orderByComparator, true);
6881    
6882                            array[1] = group;
6883    
6884                            array[2] = getByC_P_S_PrevAndNext(session, group, companyId,
6885                                            parentGroupId, site, orderByComparator, false);
6886    
6887                            return array;
6888                    }
6889                    catch (Exception e) {
6890                            throw processException(e);
6891                    }
6892                    finally {
6893                            closeSession(session);
6894                    }
6895            }
6896    
6897            protected Group getByC_P_S_PrevAndNext(Session session, Group group,
6898                    long companyId, long parentGroupId, boolean site,
6899                    OrderByComparator orderByComparator, boolean previous) {
6900                    StringBundler query = null;
6901    
6902                    if (orderByComparator != null) {
6903                            query = new StringBundler(6 +
6904                                            (orderByComparator.getOrderByFields().length * 6));
6905                    }
6906                    else {
6907                            query = new StringBundler(3);
6908                    }
6909    
6910                    query.append(_SQL_SELECT_GROUP__WHERE);
6911    
6912                    query.append(_FINDER_COLUMN_C_P_S_COMPANYID_2);
6913    
6914                    query.append(_FINDER_COLUMN_C_P_S_PARENTGROUPID_2);
6915    
6916                    query.append(_FINDER_COLUMN_C_P_S_SITE_2);
6917    
6918                    if (orderByComparator != null) {
6919                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6920    
6921                            if (orderByConditionFields.length > 0) {
6922                                    query.append(WHERE_AND);
6923                            }
6924    
6925                            for (int i = 0; i < orderByConditionFields.length; i++) {
6926                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6927                                    query.append(orderByConditionFields[i]);
6928    
6929                                    if ((i + 1) < orderByConditionFields.length) {
6930                                            if (orderByComparator.isAscending() ^ previous) {
6931                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6932                                            }
6933                                            else {
6934                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6935                                            }
6936                                    }
6937                                    else {
6938                                            if (orderByComparator.isAscending() ^ previous) {
6939                                                    query.append(WHERE_GREATER_THAN);
6940                                            }
6941                                            else {
6942                                                    query.append(WHERE_LESSER_THAN);
6943                                            }
6944                                    }
6945                            }
6946    
6947                            query.append(ORDER_BY_CLAUSE);
6948    
6949                            String[] orderByFields = orderByComparator.getOrderByFields();
6950    
6951                            for (int i = 0; i < orderByFields.length; i++) {
6952                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6953                                    query.append(orderByFields[i]);
6954    
6955                                    if ((i + 1) < orderByFields.length) {
6956                                            if (orderByComparator.isAscending() ^ previous) {
6957                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6958                                            }
6959                                            else {
6960                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6961                                            }
6962                                    }
6963                                    else {
6964                                            if (orderByComparator.isAscending() ^ previous) {
6965                                                    query.append(ORDER_BY_ASC);
6966                                            }
6967                                            else {
6968                                                    query.append(ORDER_BY_DESC);
6969                                            }
6970                                    }
6971                            }
6972                    }
6973                    else {
6974                            query.append(GroupModelImpl.ORDER_BY_JPQL);
6975                    }
6976    
6977                    String sql = query.toString();
6978    
6979                    Query q = session.createQuery(sql);
6980    
6981                    q.setFirstResult(0);
6982                    q.setMaxResults(2);
6983    
6984                    QueryPos qPos = QueryPos.getInstance(q);
6985    
6986                    qPos.add(companyId);
6987    
6988                    qPos.add(parentGroupId);
6989    
6990                    qPos.add(site);
6991    
6992                    if (orderByComparator != null) {
6993                            Object[] values = orderByComparator.getOrderByConditionValues(group);
6994    
6995                            for (Object value : values) {
6996                                    qPos.add(value);
6997                            }
6998                    }
6999    
7000                    List<Group> list = q.list();
7001    
7002                    if (list.size() == 2) {
7003                            return list.get(1);
7004                    }
7005                    else {
7006                            return null;
7007                    }
7008            }
7009    
7010            /**
7011             * Removes all the groups where companyId = &#63; and parentGroupId = &#63; and site = &#63; from the database.
7012             *
7013             * @param companyId the company ID
7014             * @param parentGroupId the parent group ID
7015             * @param site the site
7016             * @throws SystemException if a system exception occurred
7017             */
7018            @Override
7019            public void removeByC_P_S(long companyId, long parentGroupId, boolean site)
7020                    throws SystemException {
7021                    for (Group group : findByC_P_S(companyId, parentGroupId, site,
7022                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7023                            remove(group);
7024                    }
7025            }
7026    
7027            /**
7028             * Returns the number of groups where companyId = &#63; and parentGroupId = &#63; and site = &#63;.
7029             *
7030             * @param companyId the company ID
7031             * @param parentGroupId the parent group ID
7032             * @param site the site
7033             * @return the number of matching groups
7034             * @throws SystemException if a system exception occurred
7035             */
7036            @Override
7037            public int countByC_P_S(long companyId, long parentGroupId, boolean site)
7038                    throws SystemException {
7039                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P_S;
7040    
7041                    Object[] finderArgs = new Object[] { companyId, parentGroupId, site };
7042    
7043                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7044                                    this);
7045    
7046                    if (count == null) {
7047                            StringBundler query = new StringBundler(4);
7048    
7049                            query.append(_SQL_COUNT_GROUP__WHERE);
7050    
7051                            query.append(_FINDER_COLUMN_C_P_S_COMPANYID_2);
7052    
7053                            query.append(_FINDER_COLUMN_C_P_S_PARENTGROUPID_2);
7054    
7055                            query.append(_FINDER_COLUMN_C_P_S_SITE_2);
7056    
7057                            String sql = query.toString();
7058    
7059                            Session session = null;
7060    
7061                            try {
7062                                    session = openSession();
7063    
7064                                    Query q = session.createQuery(sql);
7065    
7066                                    QueryPos qPos = QueryPos.getInstance(q);
7067    
7068                                    qPos.add(companyId);
7069    
7070                                    qPos.add(parentGroupId);
7071    
7072                                    qPos.add(site);
7073    
7074                                    count = (Long)q.uniqueResult();
7075    
7076                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7077                            }
7078                            catch (Exception e) {
7079                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7080    
7081                                    throw processException(e);
7082                            }
7083                            finally {
7084                                    closeSession(session);
7085                            }
7086                    }
7087    
7088                    return count.intValue();
7089            }
7090    
7091            private static final String _FINDER_COLUMN_C_P_S_COMPANYID_2 = "group_.companyId = ? AND ";
7092            private static final String _FINDER_COLUMN_C_P_S_PARENTGROUPID_2 = "group_.parentGroupId = ? AND ";
7093            private static final String _FINDER_COLUMN_C_P_S_SITE_2 = "group_.site = ?";
7094            public static final FinderPath FINDER_PATH_FETCH_BY_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
7095                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
7096                            FINDER_CLASS_NAME_ENTITY, "fetchByC_L_N",
7097                            new String[] {
7098                                    Long.class.getName(), Long.class.getName(),
7099                                    String.class.getName()
7100                            },
7101                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
7102                            GroupModelImpl.LIVEGROUPID_COLUMN_BITMASK |
7103                            GroupModelImpl.NAME_COLUMN_BITMASK);
7104            public static final FinderPath FINDER_PATH_COUNT_BY_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
7105                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
7106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_L_N",
7107                            new String[] {
7108                                    Long.class.getName(), Long.class.getName(),
7109                                    String.class.getName()
7110                            });
7111    
7112            /**
7113             * 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.
7114             *
7115             * @param companyId the company ID
7116             * @param liveGroupId the live group ID
7117             * @param name the name
7118             * @return the matching group
7119             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
7120             * @throws SystemException if a system exception occurred
7121             */
7122            @Override
7123            public Group findByC_L_N(long companyId, long liveGroupId, String name)
7124                    throws NoSuchGroupException, SystemException {
7125                    Group group = fetchByC_L_N(companyId, liveGroupId, name);
7126    
7127                    if (group == null) {
7128                            StringBundler msg = new StringBundler(8);
7129    
7130                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7131    
7132                            msg.append("companyId=");
7133                            msg.append(companyId);
7134    
7135                            msg.append(", liveGroupId=");
7136                            msg.append(liveGroupId);
7137    
7138                            msg.append(", name=");
7139                            msg.append(name);
7140    
7141                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7142    
7143                            if (_log.isWarnEnabled()) {
7144                                    _log.warn(msg.toString());
7145                            }
7146    
7147                            throw new NoSuchGroupException(msg.toString());
7148                    }
7149    
7150                    return group;
7151            }
7152    
7153            /**
7154             * 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.
7155             *
7156             * @param companyId the company ID
7157             * @param liveGroupId the live group ID
7158             * @param name the name
7159             * @return the matching group, or <code>null</code> if a matching group could not be found
7160             * @throws SystemException if a system exception occurred
7161             */
7162            @Override
7163            public Group fetchByC_L_N(long companyId, long liveGroupId, String name)
7164                    throws SystemException {
7165                    return fetchByC_L_N(companyId, liveGroupId, name, true);
7166            }
7167    
7168            /**
7169             * 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.
7170             *
7171             * @param companyId the company ID
7172             * @param liveGroupId the live group ID
7173             * @param name the name
7174             * @param retrieveFromCache whether to use the finder cache
7175             * @return the matching group, or <code>null</code> if a matching group could not be found
7176             * @throws SystemException if a system exception occurred
7177             */
7178            @Override
7179            public Group fetchByC_L_N(long companyId, long liveGroupId, String name,
7180                    boolean retrieveFromCache) throws SystemException {
7181                    Object[] finderArgs = new Object[] { companyId, liveGroupId, name };
7182    
7183                    Object result = null;
7184    
7185                    if (retrieveFromCache) {
7186                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_L_N,
7187                                            finderArgs, this);
7188                    }
7189    
7190                    if (result instanceof Group) {
7191                            Group group = (Group)result;
7192    
7193                            if ((companyId != group.getCompanyId()) ||
7194                                            (liveGroupId != group.getLiveGroupId()) ||
7195                                            !Validator.equals(name, group.getName())) {
7196                                    result = null;
7197                            }
7198                    }
7199    
7200                    if (result == null) {
7201                            StringBundler query = new StringBundler(5);
7202    
7203                            query.append(_SQL_SELECT_GROUP__WHERE);
7204    
7205                            query.append(_FINDER_COLUMN_C_L_N_COMPANYID_2);
7206    
7207                            query.append(_FINDER_COLUMN_C_L_N_LIVEGROUPID_2);
7208    
7209                            boolean bindName = false;
7210    
7211                            if (name == null) {
7212                                    query.append(_FINDER_COLUMN_C_L_N_NAME_1);
7213                            }
7214                            else if (name.equals(StringPool.BLANK)) {
7215                                    query.append(_FINDER_COLUMN_C_L_N_NAME_3);
7216                            }
7217                            else {
7218                                    bindName = true;
7219    
7220                                    query.append(_FINDER_COLUMN_C_L_N_NAME_2);
7221                            }
7222    
7223                            String sql = query.toString();
7224    
7225                            Session session = null;
7226    
7227                            try {
7228                                    session = openSession();
7229    
7230                                    Query q = session.createQuery(sql);
7231    
7232                                    QueryPos qPos = QueryPos.getInstance(q);
7233    
7234                                    qPos.add(companyId);
7235    
7236                                    qPos.add(liveGroupId);
7237    
7238                                    if (bindName) {
7239                                            qPos.add(name);
7240                                    }
7241    
7242                                    List<Group> list = q.list();
7243    
7244                                    if (list.isEmpty()) {
7245                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
7246                                                    finderArgs, list);
7247                                    }
7248                                    else {
7249                                            Group group = list.get(0);
7250    
7251                                            result = group;
7252    
7253                                            cacheResult(group);
7254    
7255                                            if ((group.getCompanyId() != companyId) ||
7256                                                            (group.getLiveGroupId() != liveGroupId) ||
7257                                                            (group.getName() == null) ||
7258                                                            !group.getName().equals(name)) {
7259                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
7260                                                            finderArgs, group);
7261                                            }
7262                                    }
7263                            }
7264                            catch (Exception e) {
7265                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N,
7266                                            finderArgs);
7267    
7268                                    throw processException(e);
7269                            }
7270                            finally {
7271                                    closeSession(session);
7272                            }
7273                    }
7274    
7275                    if (result instanceof List<?>) {
7276                            return null;
7277                    }
7278                    else {
7279                            return (Group)result;
7280                    }
7281            }
7282    
7283            /**
7284             * Removes the group where companyId = &#63; and liveGroupId = &#63; and name = &#63; from the database.
7285             *
7286             * @param companyId the company ID
7287             * @param liveGroupId the live group ID
7288             * @param name the name
7289             * @return the group that was removed
7290             * @throws SystemException if a system exception occurred
7291             */
7292            @Override
7293            public Group removeByC_L_N(long companyId, long liveGroupId, String name)
7294                    throws NoSuchGroupException, SystemException {
7295                    Group group = findByC_L_N(companyId, liveGroupId, name);
7296    
7297                    return remove(group);
7298            }
7299    
7300            /**
7301             * Returns the number of groups where companyId = &#63; and liveGroupId = &#63; and name = &#63;.
7302             *
7303             * @param companyId the company ID
7304             * @param liveGroupId the live group ID
7305             * @param name the name
7306             * @return the number of matching groups
7307             * @throws SystemException if a system exception occurred
7308             */
7309            @Override
7310            public int countByC_L_N(long companyId, long liveGroupId, String name)
7311                    throws SystemException {
7312                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_L_N;
7313    
7314                    Object[] finderArgs = new Object[] { companyId, liveGroupId, name };
7315    
7316                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7317                                    this);
7318    
7319                    if (count == null) {
7320                            StringBundler query = new StringBundler(4);
7321    
7322                            query.append(_SQL_COUNT_GROUP__WHERE);
7323    
7324                            query.append(_FINDER_COLUMN_C_L_N_COMPANYID_2);
7325    
7326                            query.append(_FINDER_COLUMN_C_L_N_LIVEGROUPID_2);
7327    
7328                            boolean bindName = false;
7329    
7330                            if (name == null) {
7331                                    query.append(_FINDER_COLUMN_C_L_N_NAME_1);
7332                            }
7333                            else if (name.equals(StringPool.BLANK)) {
7334                                    query.append(_FINDER_COLUMN_C_L_N_NAME_3);
7335                            }
7336                            else {
7337                                    bindName = true;
7338    
7339                                    query.append(_FINDER_COLUMN_C_L_N_NAME_2);
7340                            }
7341    
7342                            String sql = query.toString();
7343    
7344                            Session session = null;
7345    
7346                            try {
7347                                    session = openSession();
7348    
7349                                    Query q = session.createQuery(sql);
7350    
7351                                    QueryPos qPos = QueryPos.getInstance(q);
7352    
7353                                    qPos.add(companyId);
7354    
7355                                    qPos.add(liveGroupId);
7356    
7357                                    if (bindName) {
7358                                            qPos.add(name);
7359                                    }
7360    
7361                                    count = (Long)q.uniqueResult();
7362    
7363                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7364                            }
7365                            catch (Exception e) {
7366                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7367    
7368                                    throw processException(e);
7369                            }
7370                            finally {
7371                                    closeSession(session);
7372                            }
7373                    }
7374    
7375                    return count.intValue();
7376            }
7377    
7378            private static final String _FINDER_COLUMN_C_L_N_COMPANYID_2 = "group_.companyId = ? AND ";
7379            private static final String _FINDER_COLUMN_C_L_N_LIVEGROUPID_2 = "group_.liveGroupId = ? AND ";
7380            private static final String _FINDER_COLUMN_C_L_N_NAME_1 = "group_.name IS NULL";
7381            private static final String _FINDER_COLUMN_C_L_N_NAME_2 = "group_.name = ?";
7382            private static final String _FINDER_COLUMN_C_L_N_NAME_3 = "(group_.name IS NULL OR group_.name = '')";
7383            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
7384                            GroupModelImpl.FINDER_CACHE_ENABLED, GroupImpl.class,
7385                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C_L_N",
7386                            new String[] {
7387                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7388                                    String.class.getName()
7389                            },
7390                            GroupModelImpl.COMPANYID_COLUMN_BITMASK |
7391                            GroupModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7392                            GroupModelImpl.LIVEGROUPID_COLUMN_BITMASK |
7393                            GroupModelImpl.NAME_COLUMN_BITMASK);
7394            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
7395                            GroupModelImpl.FINDER_CACHE_ENABLED, Long.class,
7396                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_L_N",
7397                            new String[] {
7398                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
7399                                    String.class.getName()
7400                            });
7401    
7402            /**
7403             * 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.
7404             *
7405             * @param companyId the company ID
7406             * @param classNameId the class name ID
7407             * @param liveGroupId the live group ID
7408             * @param name the name
7409             * @return the matching group
7410             * @throws com.liferay.portal.NoSuchGroupException if a matching group could not be found
7411             * @throws SystemException if a system exception occurred
7412             */
7413            @Override
7414            public Group findByC_C_L_N(long companyId, long classNameId,
7415                    long liveGroupId, String name)
7416                    throws NoSuchGroupException, SystemException {
7417                    Group group = fetchByC_C_L_N(companyId, classNameId, liveGroupId, name);
7418    
7419                    if (group == null) {
7420                            StringBundler msg = new StringBundler(10);
7421    
7422                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7423    
7424                            msg.append("companyId=");
7425                            msg.append(companyId);
7426    
7427                            msg.append(", classNameId=");
7428                            msg.append(classNameId);
7429    
7430                            msg.append(", liveGroupId=");
7431                            msg.append(liveGroupId);
7432    
7433                            msg.append(", name=");
7434                            msg.append(name);
7435    
7436                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7437    
7438                            if (_log.isWarnEnabled()) {
7439                                    _log.warn(msg.toString());
7440                            }
7441    
7442                            throw new NoSuchGroupException(msg.toString());
7443                    }
7444    
7445                    return group;
7446            }
7447    
7448            /**
7449             * 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.
7450             *
7451             * @param companyId the company ID
7452             * @param classNameId the class name ID
7453             * @param liveGroupId the live group ID
7454             * @param name the name
7455             * @return the matching group, or <code>null</code> if a matching group could not be found
7456             * @throws SystemException if a system exception occurred
7457             */
7458            @Override
7459            public Group fetchByC_C_L_N(long companyId, long classNameId,
7460                    long liveGroupId, String name) throws SystemException {
7461                    return fetchByC_C_L_N(companyId, classNameId, liveGroupId, name, true);
7462            }
7463    
7464            /**
7465             * 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.
7466             *
7467             * @param companyId the company ID
7468             * @param classNameId the class name ID
7469             * @param liveGroupId the live group ID
7470             * @param name the name
7471             * @param retrieveFromCache whether to use the finder cache
7472             * @return the matching group, or <code>null</code> if a matching group could not be found
7473             * @throws SystemException if a system exception occurred
7474             */
7475            @Override
7476            public Group fetchByC_C_L_N(long companyId, long classNameId,
7477                    long liveGroupId, String name, boolean retrieveFromCache)
7478                    throws SystemException {
7479                    Object[] finderArgs = new Object[] {
7480                                    companyId, classNameId, liveGroupId, name
7481                            };
7482    
7483                    Object result = null;
7484    
7485                    if (retrieveFromCache) {
7486                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_L_N,
7487                                            finderArgs, this);
7488                    }
7489    
7490                    if (result instanceof Group) {
7491                            Group group = (Group)result;
7492    
7493                            if ((companyId != group.getCompanyId()) ||
7494                                            (classNameId != group.getClassNameId()) ||
7495                                            (liveGroupId != group.getLiveGroupId()) ||
7496                                            !Validator.equals(name, group.getName())) {
7497                                    result = null;
7498                            }
7499                    }
7500    
7501                    if (result == null) {
7502                            StringBundler query = new StringBundler(6);
7503    
7504                            query.append(_SQL_SELECT_GROUP__WHERE);
7505    
7506                            query.append(_FINDER_COLUMN_C_C_L_N_COMPANYID_2);
7507    
7508                            query.append(_FINDER_COLUMN_C_C_L_N_CLASSNAMEID_2);
7509    
7510                            query.append(_FINDER_COLUMN_C_C_L_N_LIVEGROUPID_2);
7511    
7512                            boolean bindName = false;
7513    
7514                            if (name == null) {
7515                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_1);
7516                            }
7517                            else if (name.equals(StringPool.BLANK)) {
7518                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_3);
7519                            }
7520                            else {
7521                                    bindName = true;
7522    
7523                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_2);
7524                            }
7525    
7526                            String sql = query.toString();
7527    
7528                            Session session = null;
7529    
7530                            try {
7531                                    session = openSession();
7532    
7533                                    Query q = session.createQuery(sql);
7534    
7535                                    QueryPos qPos = QueryPos.getInstance(q);
7536    
7537                                    qPos.add(companyId);
7538    
7539                                    qPos.add(classNameId);
7540    
7541                                    qPos.add(liveGroupId);
7542    
7543                                    if (bindName) {
7544                                            qPos.add(name);
7545                                    }
7546    
7547                                    List<Group> list = q.list();
7548    
7549                                    if (list.isEmpty()) {
7550                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
7551                                                    finderArgs, list);
7552                                    }
7553                                    else {
7554                                            Group group = list.get(0);
7555    
7556                                            result = group;
7557    
7558                                            cacheResult(group);
7559    
7560                                            if ((group.getCompanyId() != companyId) ||
7561                                                            (group.getClassNameId() != classNameId) ||
7562                                                            (group.getLiveGroupId() != liveGroupId) ||
7563                                                            (group.getName() == null) ||
7564                                                            !group.getName().equals(name)) {
7565                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
7566                                                            finderArgs, group);
7567                                            }
7568                                    }
7569                            }
7570                            catch (Exception e) {
7571                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N,
7572                                            finderArgs);
7573    
7574                                    throw processException(e);
7575                            }
7576                            finally {
7577                                    closeSession(session);
7578                            }
7579                    }
7580    
7581                    if (result instanceof List<?>) {
7582                            return null;
7583                    }
7584                    else {
7585                            return (Group)result;
7586                    }
7587            }
7588    
7589            /**
7590             * Removes the group where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63; from the database.
7591             *
7592             * @param companyId the company ID
7593             * @param classNameId the class name ID
7594             * @param liveGroupId the live group ID
7595             * @param name the name
7596             * @return the group that was removed
7597             * @throws SystemException if a system exception occurred
7598             */
7599            @Override
7600            public Group removeByC_C_L_N(long companyId, long classNameId,
7601                    long liveGroupId, String name)
7602                    throws NoSuchGroupException, SystemException {
7603                    Group group = findByC_C_L_N(companyId, classNameId, liveGroupId, name);
7604    
7605                    return remove(group);
7606            }
7607    
7608            /**
7609             * Returns the number of groups where companyId = &#63; and classNameId = &#63; and liveGroupId = &#63; and name = &#63;.
7610             *
7611             * @param companyId the company ID
7612             * @param classNameId the class name ID
7613             * @param liveGroupId the live group ID
7614             * @param name the name
7615             * @return the number of matching groups
7616             * @throws SystemException if a system exception occurred
7617             */
7618            @Override
7619            public int countByC_C_L_N(long companyId, long classNameId,
7620                    long liveGroupId, String name) throws SystemException {
7621                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_L_N;
7622    
7623                    Object[] finderArgs = new Object[] {
7624                                    companyId, classNameId, liveGroupId, name
7625                            };
7626    
7627                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7628                                    this);
7629    
7630                    if (count == null) {
7631                            StringBundler query = new StringBundler(5);
7632    
7633                            query.append(_SQL_COUNT_GROUP__WHERE);
7634    
7635                            query.append(_FINDER_COLUMN_C_C_L_N_COMPANYID_2);
7636    
7637                            query.append(_FINDER_COLUMN_C_C_L_N_CLASSNAMEID_2);
7638    
7639                            query.append(_FINDER_COLUMN_C_C_L_N_LIVEGROUPID_2);
7640    
7641                            boolean bindName = false;
7642    
7643                            if (name == null) {
7644                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_1);
7645                            }
7646                            else if (name.equals(StringPool.BLANK)) {
7647                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_3);
7648                            }
7649                            else {
7650                                    bindName = true;
7651    
7652                                    query.append(_FINDER_COLUMN_C_C_L_N_NAME_2);
7653                            }
7654    
7655                            String sql = query.toString();
7656    
7657                            Session session = null;
7658    
7659                            try {
7660                                    session = openSession();
7661    
7662                                    Query q = session.createQuery(sql);
7663    
7664                                    QueryPos qPos = QueryPos.getInstance(q);
7665    
7666                                    qPos.add(companyId);
7667    
7668                                    qPos.add(classNameId);
7669    
7670                                    qPos.add(liveGroupId);
7671    
7672                                    if (bindName) {
7673                                            qPos.add(name);
7674                                    }
7675    
7676                                    count = (Long)q.uniqueResult();
7677    
7678                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7679                            }
7680                            catch (Exception e) {
7681                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7682    
7683                                    throw processException(e);
7684                            }
7685                            finally {
7686                                    closeSession(session);
7687                            }
7688                    }
7689    
7690                    return count.intValue();
7691            }
7692    
7693            private static final String _FINDER_COLUMN_C_C_L_N_COMPANYID_2 = "group_.companyId = ? AND ";
7694            private static final String _FINDER_COLUMN_C_C_L_N_CLASSNAMEID_2 = "group_.classNameId = ? AND ";
7695            private static final String _FINDER_COLUMN_C_C_L_N_LIVEGROUPID_2 = "group_.liveGroupId = ? AND ";
7696            private static final String _FINDER_COLUMN_C_C_L_N_NAME_1 = "group_.name IS NULL";
7697            private static final String _FINDER_COLUMN_C_C_L_N_NAME_2 = "group_.name = ?";
7698            private static final String _FINDER_COLUMN_C_C_L_N_NAME_3 = "(group_.name IS NULL OR group_.name = '')";
7699    
7700            public GroupPersistenceImpl() {
7701                    setModelClass(Group.class);
7702            }
7703    
7704            /**
7705             * Caches the group in the entity cache if it is enabled.
7706             *
7707             * @param group the group
7708             */
7709            @Override
7710            public void cacheResult(Group group) {
7711                    EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
7712                            GroupImpl.class, group.getPrimaryKey(), group);
7713    
7714                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7715                            new Object[] { group.getUuid(), group.getGroupId() }, group);
7716    
7717                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
7718                            new Object[] { group.getLiveGroupId() }, group);
7719    
7720                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
7721                            new Object[] { group.getCompanyId(), group.getName() }, group);
7722    
7723                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
7724                            new Object[] { group.getCompanyId(), group.getFriendlyURL() }, group);
7725    
7726                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
7727                            new Object[] {
7728                                    group.getCompanyId(), group.getClassNameId(), group.getClassPK()
7729                            }, group);
7730    
7731                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
7732                            new Object[] {
7733                                    group.getCompanyId(), group.getLiveGroupId(), group.getName()
7734                            }, group);
7735    
7736                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
7737                            new Object[] {
7738                                    group.getCompanyId(), group.getClassNameId(),
7739                                    group.getLiveGroupId(), group.getName()
7740                            }, group);
7741    
7742                    group.resetOriginalValues();
7743            }
7744    
7745            /**
7746             * Caches the groups in the entity cache if it is enabled.
7747             *
7748             * @param groups the groups
7749             */
7750            @Override
7751            public void cacheResult(List<Group> groups) {
7752                    for (Group group : groups) {
7753                            if (EntityCacheUtil.getResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
7754                                                    GroupImpl.class, group.getPrimaryKey()) == null) {
7755                                    cacheResult(group);
7756                            }
7757                            else {
7758                                    group.resetOriginalValues();
7759                            }
7760                    }
7761            }
7762    
7763            /**
7764             * Clears the cache for all groups.
7765             *
7766             * <p>
7767             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7768             * </p>
7769             */
7770            @Override
7771            public void clearCache() {
7772                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7773                            CacheRegistryUtil.clear(GroupImpl.class.getName());
7774                    }
7775    
7776                    EntityCacheUtil.clearCache(GroupImpl.class.getName());
7777    
7778                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7779                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7780                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7781            }
7782    
7783            /**
7784             * Clears the cache for the group.
7785             *
7786             * <p>
7787             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7788             * </p>
7789             */
7790            @Override
7791            public void clearCache(Group group) {
7792                    EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
7793                            GroupImpl.class, group.getPrimaryKey());
7794    
7795                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7796                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7797    
7798                    clearUniqueFindersCache(group);
7799            }
7800    
7801            @Override
7802            public void clearCache(List<Group> groups) {
7803                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7804                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7805    
7806                    for (Group group : groups) {
7807                            EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
7808                                    GroupImpl.class, group.getPrimaryKey());
7809    
7810                            clearUniqueFindersCache(group);
7811                    }
7812            }
7813    
7814            protected void cacheUniqueFindersCache(Group group) {
7815                    if (group.isNew()) {
7816                            Object[] args = new Object[] { group.getUuid(), group.getGroupId() };
7817    
7818                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7819                                    Long.valueOf(1));
7820                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, group);
7821    
7822                            args = new Object[] { group.getLiveGroupId() };
7823    
7824                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LIVEGROUPID, args,
7825                                    Long.valueOf(1));
7826                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID, args,
7827                                    group);
7828    
7829                            args = new Object[] { group.getCompanyId(), group.getName() };
7830    
7831                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
7832                                    Long.valueOf(1));
7833                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, group);
7834    
7835                            args = new Object[] { group.getCompanyId(), group.getFriendlyURL() };
7836    
7837                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, args,
7838                                    Long.valueOf(1));
7839                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F, args, group);
7840    
7841                            args = new Object[] {
7842                                            group.getCompanyId(), group.getClassNameId(),
7843                                            group.getClassPK()
7844                                    };
7845    
7846                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
7847                                    Long.valueOf(1));
7848                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, group);
7849    
7850                            args = new Object[] {
7851                                            group.getCompanyId(), group.getLiveGroupId(),
7852                                            group.getName()
7853                                    };
7854    
7855                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L_N, args,
7856                                    Long.valueOf(1));
7857                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N, args, group);
7858    
7859                            args = new Object[] {
7860                                            group.getCompanyId(), group.getClassNameId(),
7861                                            group.getLiveGroupId(), group.getName()
7862                                    };
7863    
7864                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_L_N, args,
7865                                    Long.valueOf(1));
7866                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N, args, group);
7867                    }
7868                    else {
7869                            GroupModelImpl groupModelImpl = (GroupModelImpl)group;
7870    
7871                            if ((groupModelImpl.getColumnBitmask() &
7872                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7873                                    Object[] args = new Object[] { group.getUuid(), group.getGroupId() };
7874    
7875                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7876                                            Long.valueOf(1));
7877                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7878                                            group);
7879                            }
7880    
7881                            if ((groupModelImpl.getColumnBitmask() &
7882                                            FINDER_PATH_FETCH_BY_LIVEGROUPID.getColumnBitmask()) != 0) {
7883                                    Object[] args = new Object[] { group.getLiveGroupId() };
7884    
7885                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LIVEGROUPID,
7886                                            args, Long.valueOf(1));
7887                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
7888                                            args, group);
7889                            }
7890    
7891                            if ((groupModelImpl.getColumnBitmask() &
7892                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
7893                                    Object[] args = new Object[] {
7894                                                    group.getCompanyId(), group.getName()
7895                                            };
7896    
7897                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
7898                                            Long.valueOf(1));
7899                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, group);
7900                            }
7901    
7902                            if ((groupModelImpl.getColumnBitmask() &
7903                                            FINDER_PATH_FETCH_BY_C_F.getColumnBitmask()) != 0) {
7904                                    Object[] args = new Object[] {
7905                                                    group.getCompanyId(), group.getFriendlyURL()
7906                                            };
7907    
7908                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, args,
7909                                            Long.valueOf(1));
7910                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F, args, group);
7911                            }
7912    
7913                            if ((groupModelImpl.getColumnBitmask() &
7914                                            FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
7915                                    Object[] args = new Object[] {
7916                                                    group.getCompanyId(), group.getClassNameId(),
7917                                                    group.getClassPK()
7918                                            };
7919    
7920                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
7921                                            Long.valueOf(1));
7922                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args,
7923                                            group);
7924                            }
7925    
7926                            if ((groupModelImpl.getColumnBitmask() &
7927                                            FINDER_PATH_FETCH_BY_C_L_N.getColumnBitmask()) != 0) {
7928                                    Object[] args = new Object[] {
7929                                                    group.getCompanyId(), group.getLiveGroupId(),
7930                                                    group.getName()
7931                                            };
7932    
7933                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L_N, args,
7934                                            Long.valueOf(1));
7935                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N, args,
7936                                            group);
7937                            }
7938    
7939                            if ((groupModelImpl.getColumnBitmask() &
7940                                            FINDER_PATH_FETCH_BY_C_C_L_N.getColumnBitmask()) != 0) {
7941                                    Object[] args = new Object[] {
7942                                                    group.getCompanyId(), group.getClassNameId(),
7943                                                    group.getLiveGroupId(), group.getName()
7944                                            };
7945    
7946                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_L_N, args,
7947                                            Long.valueOf(1));
7948                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N, args,
7949                                            group);
7950                            }
7951                    }
7952            }
7953    
7954            protected void clearUniqueFindersCache(Group group) {
7955                    GroupModelImpl groupModelImpl = (GroupModelImpl)group;
7956    
7957                    Object[] args = new Object[] { group.getUuid(), group.getGroupId() };
7958    
7959                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7960                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7961    
7962                    if ((groupModelImpl.getColumnBitmask() &
7963                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7964                            args = new Object[] {
7965                                            groupModelImpl.getOriginalUuid(),
7966                                            groupModelImpl.getOriginalGroupId()
7967                                    };
7968    
7969                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7970                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7971                    }
7972    
7973                    args = new Object[] { group.getLiveGroupId() };
7974    
7975                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LIVEGROUPID, args);
7976                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID, args);
7977    
7978                    if ((groupModelImpl.getColumnBitmask() &
7979                                    FINDER_PATH_FETCH_BY_LIVEGROUPID.getColumnBitmask()) != 0) {
7980                            args = new Object[] { groupModelImpl.getOriginalLiveGroupId() };
7981    
7982                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_LIVEGROUPID, args);
7983                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID, args);
7984                    }
7985    
7986                    args = new Object[] { group.getCompanyId(), group.getName() };
7987    
7988                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
7989                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
7990    
7991                    if ((groupModelImpl.getColumnBitmask() &
7992                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
7993                            args = new Object[] {
7994                                            groupModelImpl.getOriginalCompanyId(),
7995                                            groupModelImpl.getOriginalName()
7996                                    };
7997    
7998                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
7999                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8000                    }
8001    
8002                    args = new Object[] { group.getCompanyId(), group.getFriendlyURL() };
8003    
8004                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_F, args);
8005                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F, args);
8006    
8007                    if ((groupModelImpl.getColumnBitmask() &
8008                                    FINDER_PATH_FETCH_BY_C_F.getColumnBitmask()) != 0) {
8009                            args = new Object[] {
8010                                            groupModelImpl.getOriginalCompanyId(),
8011                                            groupModelImpl.getOriginalFriendlyURL()
8012                                    };
8013    
8014                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_F, args);
8015                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F, args);
8016                    }
8017    
8018                    args = new Object[] {
8019                                    group.getCompanyId(), group.getClassNameId(), group.getClassPK()
8020                            };
8021    
8022                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8023                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8024    
8025                    if ((groupModelImpl.getColumnBitmask() &
8026                                    FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8027                            args = new Object[] {
8028                                            groupModelImpl.getOriginalCompanyId(),
8029                                            groupModelImpl.getOriginalClassNameId(),
8030                                            groupModelImpl.getOriginalClassPK()
8031                                    };
8032    
8033                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8034                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8035                    }
8036    
8037                    args = new Object[] {
8038                                    group.getCompanyId(), group.getLiveGroupId(), group.getName()
8039                            };
8040    
8041                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_L_N, args);
8042                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N, args);
8043    
8044                    if ((groupModelImpl.getColumnBitmask() &
8045                                    FINDER_PATH_FETCH_BY_C_L_N.getColumnBitmask()) != 0) {
8046                            args = new Object[] {
8047                                            groupModelImpl.getOriginalCompanyId(),
8048                                            groupModelImpl.getOriginalLiveGroupId(),
8049                                            groupModelImpl.getOriginalName()
8050                                    };
8051    
8052                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_L_N, args);
8053                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N, args);
8054                    }
8055    
8056                    args = new Object[] {
8057                                    group.getCompanyId(), group.getClassNameId(),
8058                                    group.getLiveGroupId(), group.getName()
8059                            };
8060    
8061                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_L_N, args);
8062                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N, args);
8063    
8064                    if ((groupModelImpl.getColumnBitmask() &
8065                                    FINDER_PATH_FETCH_BY_C_C_L_N.getColumnBitmask()) != 0) {
8066                            args = new Object[] {
8067                                            groupModelImpl.getOriginalCompanyId(),
8068                                            groupModelImpl.getOriginalClassNameId(),
8069                                            groupModelImpl.getOriginalLiveGroupId(),
8070                                            groupModelImpl.getOriginalName()
8071                                    };
8072    
8073                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_L_N, args);
8074                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N, args);
8075                    }
8076            }
8077    
8078            /**
8079             * Creates a new group with the primary key. Does not add the group to the database.
8080             *
8081             * @param groupId the primary key for the new group
8082             * @return the new group
8083             */
8084            @Override
8085            public Group create(long groupId) {
8086                    Group group = new GroupImpl();
8087    
8088                    group.setNew(true);
8089                    group.setPrimaryKey(groupId);
8090    
8091                    String uuid = PortalUUIDUtil.generate();
8092    
8093                    group.setUuid(uuid);
8094    
8095                    return group;
8096            }
8097    
8098            /**
8099             * Removes the group with the primary key from the database. Also notifies the appropriate model listeners.
8100             *
8101             * @param groupId the primary key of the group
8102             * @return the group that was removed
8103             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
8104             * @throws SystemException if a system exception occurred
8105             */
8106            @Override
8107            public Group remove(long groupId)
8108                    throws NoSuchGroupException, SystemException {
8109                    return remove((Serializable)groupId);
8110            }
8111    
8112            /**
8113             * Removes the group with the primary key from the database. Also notifies the appropriate model listeners.
8114             *
8115             * @param primaryKey the primary key of the group
8116             * @return the group that was removed
8117             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
8118             * @throws SystemException if a system exception occurred
8119             */
8120            @Override
8121            public Group remove(Serializable primaryKey)
8122                    throws NoSuchGroupException, SystemException {
8123                    Session session = null;
8124    
8125                    try {
8126                            session = openSession();
8127    
8128                            Group group = (Group)session.get(GroupImpl.class, primaryKey);
8129    
8130                            if (group == null) {
8131                                    if (_log.isWarnEnabled()) {
8132                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8133                                    }
8134    
8135                                    throw new NoSuchGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8136                                            primaryKey);
8137                            }
8138    
8139                            return remove(group);
8140                    }
8141                    catch (NoSuchGroupException nsee) {
8142                            throw nsee;
8143                    }
8144                    catch (Exception e) {
8145                            throw processException(e);
8146                    }
8147                    finally {
8148                            closeSession(session);
8149                    }
8150            }
8151    
8152            @Override
8153            protected Group removeImpl(Group group) throws SystemException {
8154                    group = toUnwrappedModel(group);
8155    
8156                    groupToOrganizationTableMapper.deleteLeftPrimaryKeyTableMappings(group.getPrimaryKey());
8157    
8158                    groupToRoleTableMapper.deleteLeftPrimaryKeyTableMappings(group.getPrimaryKey());
8159    
8160                    groupToUserGroupTableMapper.deleteLeftPrimaryKeyTableMappings(group.getPrimaryKey());
8161    
8162                    groupToUserTableMapper.deleteLeftPrimaryKeyTableMappings(group.getPrimaryKey());
8163    
8164                    Session session = null;
8165    
8166                    try {
8167                            session = openSession();
8168    
8169                            if (!session.contains(group)) {
8170                                    group = (Group)session.get(GroupImpl.class,
8171                                                    group.getPrimaryKeyObj());
8172                            }
8173    
8174                            if (group != null) {
8175                                    session.delete(group);
8176                            }
8177                    }
8178                    catch (Exception e) {
8179                            throw processException(e);
8180                    }
8181                    finally {
8182                            closeSession(session);
8183                    }
8184    
8185                    if (group != null) {
8186                            clearCache(group);
8187                    }
8188    
8189                    return group;
8190            }
8191    
8192            @Override
8193            public Group updateImpl(com.liferay.portal.model.Group group)
8194                    throws SystemException {
8195                    group = toUnwrappedModel(group);
8196    
8197                    boolean isNew = group.isNew();
8198    
8199                    GroupModelImpl groupModelImpl = (GroupModelImpl)group;
8200    
8201                    if (Validator.isNull(group.getUuid())) {
8202                            String uuid = PortalUUIDUtil.generate();
8203    
8204                            group.setUuid(uuid);
8205                    }
8206    
8207                    Session session = null;
8208    
8209                    try {
8210                            session = openSession();
8211    
8212                            if (group.isNew()) {
8213                                    session.save(group);
8214    
8215                                    group.setNew(false);
8216                            }
8217                            else {
8218                                    session.merge(group);
8219                            }
8220                    }
8221                    catch (Exception e) {
8222                            throw processException(e);
8223                    }
8224                    finally {
8225                            closeSession(session);
8226                    }
8227    
8228                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8229    
8230                    if (isNew || !GroupModelImpl.COLUMN_BITMASK_ENABLED) {
8231                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8232                    }
8233    
8234                    else {
8235                            if ((groupModelImpl.getColumnBitmask() &
8236                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8237                                    Object[] args = new Object[] { groupModelImpl.getOriginalUuid() };
8238    
8239                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8240                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8241                                            args);
8242    
8243                                    args = new Object[] { groupModelImpl.getUuid() };
8244    
8245                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8246                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8247                                            args);
8248                            }
8249    
8250                            if ((groupModelImpl.getColumnBitmask() &
8251                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8252                                    Object[] args = new Object[] {
8253                                                    groupModelImpl.getOriginalUuid(),
8254                                                    groupModelImpl.getOriginalCompanyId()
8255                                            };
8256    
8257                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8258                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8259                                            args);
8260    
8261                                    args = new Object[] {
8262                                                    groupModelImpl.getUuid(), groupModelImpl.getCompanyId()
8263                                            };
8264    
8265                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8266                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8267                                            args);
8268                            }
8269    
8270                            if ((groupModelImpl.getColumnBitmask() &
8271                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8272                                    Object[] args = new Object[] {
8273                                                    groupModelImpl.getOriginalCompanyId()
8274                                            };
8275    
8276                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8277                                            args);
8278                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8279                                            args);
8280    
8281                                    args = new Object[] { groupModelImpl.getCompanyId() };
8282    
8283                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8284                                            args);
8285                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8286                                            args);
8287                            }
8288    
8289                            if ((groupModelImpl.getColumnBitmask() &
8290                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
8291                                    Object[] args = new Object[] {
8292                                                    groupModelImpl.getOriginalCompanyId(),
8293                                                    groupModelImpl.getOriginalClassNameId()
8294                                            };
8295    
8296                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
8297                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
8298                                            args);
8299    
8300                                    args = new Object[] {
8301                                                    groupModelImpl.getCompanyId(),
8302                                                    groupModelImpl.getClassNameId()
8303                                            };
8304    
8305                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
8306                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
8307                                            args);
8308                            }
8309    
8310                            if ((groupModelImpl.getColumnBitmask() &
8311                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
8312                                    Object[] args = new Object[] {
8313                                                    groupModelImpl.getOriginalCompanyId(),
8314                                                    groupModelImpl.getOriginalParentGroupId()
8315                                            };
8316    
8317                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
8318                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
8319                                            args);
8320    
8321                                    args = new Object[] {
8322                                                    groupModelImpl.getCompanyId(),
8323                                                    groupModelImpl.getParentGroupId()
8324                                            };
8325    
8326                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
8327                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
8328                                            args);
8329                            }
8330    
8331                            if ((groupModelImpl.getColumnBitmask() &
8332                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
8333                                    Object[] args = new Object[] {
8334                                                    groupModelImpl.getOriginalCompanyId(),
8335                                                    groupModelImpl.getOriginalSite()
8336                                            };
8337    
8338                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
8339                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
8340                                            args);
8341    
8342                                    args = new Object[] {
8343                                                    groupModelImpl.getCompanyId(), groupModelImpl.getSite()
8344                                            };
8345    
8346                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
8347                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
8348                                            args);
8349                            }
8350    
8351                            if ((groupModelImpl.getColumnBitmask() &
8352                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A.getColumnBitmask()) != 0) {
8353                                    Object[] args = new Object[] {
8354                                                    groupModelImpl.getOriginalCompanyId(),
8355                                                    groupModelImpl.getOriginalActive()
8356                                            };
8357    
8358                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
8359                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
8360                                            args);
8361    
8362                                    args = new Object[] {
8363                                                    groupModelImpl.getCompanyId(),
8364                                                    groupModelImpl.getActive()
8365                                            };
8366    
8367                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_A, args);
8368                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_A,
8369                                            args);
8370                            }
8371    
8372                            if ((groupModelImpl.getColumnBitmask() &
8373                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
8374                                    Object[] args = new Object[] {
8375                                                    groupModelImpl.getOriginalType(),
8376                                                    groupModelImpl.getOriginalActive()
8377                                            };
8378    
8379                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
8380                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
8381                                            args);
8382    
8383                                    args = new Object[] {
8384                                                    groupModelImpl.getType(), groupModelImpl.getActive()
8385                                            };
8386    
8387                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
8388                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
8389                                            args);
8390                            }
8391    
8392                            if ((groupModelImpl.getColumnBitmask() &
8393                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P.getColumnBitmask()) != 0) {
8394                                    Object[] args = new Object[] {
8395                                                    groupModelImpl.getOriginalCompanyId(),
8396                                                    groupModelImpl.getOriginalClassNameId(),
8397                                                    groupModelImpl.getOriginalParentGroupId()
8398                                            };
8399    
8400                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_P, args);
8401                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P,
8402                                            args);
8403    
8404                                    args = new Object[] {
8405                                                    groupModelImpl.getCompanyId(),
8406                                                    groupModelImpl.getClassNameId(),
8407                                                    groupModelImpl.getParentGroupId()
8408                                            };
8409    
8410                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_P, args);
8411                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_P,
8412                                            args);
8413                            }
8414    
8415                            if ((groupModelImpl.getColumnBitmask() &
8416                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S.getColumnBitmask()) != 0) {
8417                                    Object[] args = new Object[] {
8418                                                    groupModelImpl.getOriginalCompanyId(),
8419                                                    groupModelImpl.getOriginalParentGroupId(),
8420                                                    groupModelImpl.getOriginalSite()
8421                                            };
8422    
8423                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P_S, args);
8424                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S,
8425                                            args);
8426    
8427                                    args = new Object[] {
8428                                                    groupModelImpl.getCompanyId(),
8429                                                    groupModelImpl.getParentGroupId(),
8430                                                    groupModelImpl.getSite()
8431                                            };
8432    
8433                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P_S, args);
8434                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_S,
8435                                            args);
8436                            }
8437                    }
8438    
8439                    EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
8440                            GroupImpl.class, group.getPrimaryKey(), group);
8441    
8442                    clearUniqueFindersCache(group);
8443                    cacheUniqueFindersCache(group);
8444    
8445                    return group;
8446            }
8447    
8448            protected Group toUnwrappedModel(Group group) {
8449                    if (group instanceof GroupImpl) {
8450                            return group;
8451                    }
8452    
8453                    GroupImpl groupImpl = new GroupImpl();
8454    
8455                    groupImpl.setNew(group.isNew());
8456                    groupImpl.setPrimaryKey(group.getPrimaryKey());
8457    
8458                    groupImpl.setUuid(group.getUuid());
8459                    groupImpl.setGroupId(group.getGroupId());
8460                    groupImpl.setCompanyId(group.getCompanyId());
8461                    groupImpl.setCreatorUserId(group.getCreatorUserId());
8462                    groupImpl.setClassNameId(group.getClassNameId());
8463                    groupImpl.setClassPK(group.getClassPK());
8464                    groupImpl.setParentGroupId(group.getParentGroupId());
8465                    groupImpl.setLiveGroupId(group.getLiveGroupId());
8466                    groupImpl.setTreePath(group.getTreePath());
8467                    groupImpl.setName(group.getName());
8468                    groupImpl.setDescription(group.getDescription());
8469                    groupImpl.setType(group.getType());
8470                    groupImpl.setTypeSettings(group.getTypeSettings());
8471                    groupImpl.setManualMembership(group.isManualMembership());
8472                    groupImpl.setMembershipRestriction(group.getMembershipRestriction());
8473                    groupImpl.setFriendlyURL(group.getFriendlyURL());
8474                    groupImpl.setSite(group.isSite());
8475                    groupImpl.setRemoteStagingGroupCount(group.getRemoteStagingGroupCount());
8476                    groupImpl.setActive(group.isActive());
8477    
8478                    return groupImpl;
8479            }
8480    
8481            /**
8482             * Returns the group with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8483             *
8484             * @param primaryKey the primary key of the group
8485             * @return the group
8486             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
8487             * @throws SystemException if a system exception occurred
8488             */
8489            @Override
8490            public Group findByPrimaryKey(Serializable primaryKey)
8491                    throws NoSuchGroupException, SystemException {
8492                    Group group = fetchByPrimaryKey(primaryKey);
8493    
8494                    if (group == null) {
8495                            if (_log.isWarnEnabled()) {
8496                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8497                            }
8498    
8499                            throw new NoSuchGroupException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8500                                    primaryKey);
8501                    }
8502    
8503                    return group;
8504            }
8505    
8506            /**
8507             * Returns the group with the primary key or throws a {@link com.liferay.portal.NoSuchGroupException} if it could not be found.
8508             *
8509             * @param groupId the primary key of the group
8510             * @return the group
8511             * @throws com.liferay.portal.NoSuchGroupException if a group with the primary key could not be found
8512             * @throws SystemException if a system exception occurred
8513             */
8514            @Override
8515            public Group findByPrimaryKey(long groupId)
8516                    throws NoSuchGroupException, SystemException {
8517                    return findByPrimaryKey((Serializable)groupId);
8518            }
8519    
8520            /**
8521             * Returns the group with the primary key or returns <code>null</code> if it could not be found.
8522             *
8523             * @param primaryKey the primary key of the group
8524             * @return the group, or <code>null</code> if a group with the primary key could not be found
8525             * @throws SystemException if a system exception occurred
8526             */
8527            @Override
8528            public Group fetchByPrimaryKey(Serializable primaryKey)
8529                    throws SystemException {
8530                    Group group = (Group)EntityCacheUtil.getResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
8531                                    GroupImpl.class, primaryKey);
8532    
8533                    if (group == _nullGroup) {
8534                            return null;
8535                    }
8536    
8537                    if (group == null) {
8538                            Session session = null;
8539    
8540                            try {
8541                                    session = openSession();
8542    
8543                                    group = (Group)session.get(GroupImpl.class, primaryKey);
8544    
8545                                    if (group != null) {
8546                                            cacheResult(group);
8547                                    }
8548                                    else {
8549                                            EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
8550                                                    GroupImpl.class, primaryKey, _nullGroup);
8551                                    }
8552                            }
8553                            catch (Exception e) {
8554                                    EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
8555                                            GroupImpl.class, primaryKey);
8556    
8557                                    throw processException(e);
8558                            }
8559                            finally {
8560                                    closeSession(session);
8561                            }
8562                    }
8563    
8564                    return group;
8565            }
8566    
8567            /**
8568             * Returns the group with the primary key or returns <code>null</code> if it could not be found.
8569             *
8570             * @param groupId the primary key of the group
8571             * @return the group, or <code>null</code> if a group with the primary key could not be found
8572             * @throws SystemException if a system exception occurred
8573             */
8574            @Override
8575            public Group fetchByPrimaryKey(long groupId) throws SystemException {
8576                    return fetchByPrimaryKey((Serializable)groupId);
8577            }
8578    
8579            /**
8580             * Returns all the groups.
8581             *
8582             * @return the groups
8583             * @throws SystemException if a system exception occurred
8584             */
8585            @Override
8586            public List<Group> findAll() throws SystemException {
8587                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8588            }
8589    
8590            /**
8591             * Returns a range of all the groups.
8592             *
8593             * <p>
8594             * 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.
8595             * </p>
8596             *
8597             * @param start the lower bound of the range of groups
8598             * @param end the upper bound of the range of groups (not inclusive)
8599             * @return the range of groups
8600             * @throws SystemException if a system exception occurred
8601             */
8602            @Override
8603            public List<Group> findAll(int start, int end) throws SystemException {
8604                    return findAll(start, end, null);
8605            }
8606    
8607            /**
8608             * Returns an ordered range of all the groups.
8609             *
8610             * <p>
8611             * 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.
8612             * </p>
8613             *
8614             * @param start the lower bound of the range of groups
8615             * @param end the upper bound of the range of groups (not inclusive)
8616             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8617             * @return the ordered range of groups
8618             * @throws SystemException if a system exception occurred
8619             */
8620            @Override
8621            public List<Group> findAll(int start, int end,
8622                    OrderByComparator orderByComparator) throws SystemException {
8623                    boolean pagination = true;
8624                    FinderPath finderPath = null;
8625                    Object[] finderArgs = null;
8626    
8627                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8628                                    (orderByComparator == null)) {
8629                            pagination = false;
8630                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
8631                            finderArgs = FINDER_ARGS_EMPTY;
8632                    }
8633                    else {
8634                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
8635                            finderArgs = new Object[] { start, end, orderByComparator };
8636                    }
8637    
8638                    List<Group> list = (List<Group>)FinderCacheUtil.getResult(finderPath,
8639                                    finderArgs, this);
8640    
8641                    if (list == null) {
8642                            StringBundler query = null;
8643                            String sql = null;
8644    
8645                            if (orderByComparator != null) {
8646                                    query = new StringBundler(2 +
8647                                                    (orderByComparator.getOrderByFields().length * 3));
8648    
8649                                    query.append(_SQL_SELECT_GROUP_);
8650    
8651                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8652                                            orderByComparator);
8653    
8654                                    sql = query.toString();
8655                            }
8656                            else {
8657                                    sql = _SQL_SELECT_GROUP_;
8658    
8659                                    if (pagination) {
8660                                            sql = sql.concat(GroupModelImpl.ORDER_BY_JPQL);
8661                                    }
8662                            }
8663    
8664                            Session session = null;
8665    
8666                            try {
8667                                    session = openSession();
8668    
8669                                    Query q = session.createQuery(sql);
8670    
8671                                    if (!pagination) {
8672                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
8673                                                            end, false);
8674    
8675                                            Collections.sort(list);
8676    
8677                                            list = new UnmodifiableList<Group>(list);
8678                                    }
8679                                    else {
8680                                            list = (List<Group>)QueryUtil.list(q, getDialect(), start,
8681                                                            end);
8682                                    }
8683    
8684                                    cacheResult(list);
8685    
8686                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8687                            }
8688                            catch (Exception e) {
8689                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8690    
8691                                    throw processException(e);
8692                            }
8693                            finally {
8694                                    closeSession(session);
8695                            }
8696                    }
8697    
8698                    return list;
8699            }
8700    
8701            /**
8702             * Removes all the groups from the database.
8703             *
8704             * @throws SystemException if a system exception occurred
8705             */
8706            @Override
8707            public void removeAll() throws SystemException {
8708                    for (Group group : findAll()) {
8709                            remove(group);
8710                    }
8711            }
8712    
8713            /**
8714             * Returns the number of groups.
8715             *
8716             * @return the number of groups
8717             * @throws SystemException if a system exception occurred
8718             */
8719            @Override
8720            public int countAll() throws SystemException {
8721                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
8722                                    FINDER_ARGS_EMPTY, this);
8723    
8724                    if (count == null) {
8725                            Session session = null;
8726    
8727                            try {
8728                                    session = openSession();
8729    
8730                                    Query q = session.createQuery(_SQL_COUNT_GROUP_);
8731    
8732                                    count = (Long)q.uniqueResult();
8733    
8734                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
8735                                            FINDER_ARGS_EMPTY, count);
8736                            }
8737                            catch (Exception e) {
8738                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
8739                                            FINDER_ARGS_EMPTY);
8740    
8741                                    throw processException(e);
8742                            }
8743                            finally {
8744                                    closeSession(session);
8745                            }
8746                    }
8747    
8748                    return count.intValue();
8749            }
8750    
8751            /**
8752             * Returns all the organizations associated with the group.
8753             *
8754             * @param pk the primary key of the group
8755             * @return the organizations associated with the group
8756             * @throws SystemException if a system exception occurred
8757             */
8758            @Override
8759            public List<com.liferay.portal.model.Organization> getOrganizations(long pk)
8760                    throws SystemException {
8761                    return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8762            }
8763    
8764            /**
8765             * Returns a range of all the organizations associated with the group.
8766             *
8767             * <p>
8768             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link 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.
8769             * </p>
8770             *
8771             * @param pk the primary key of the group
8772             * @param start the lower bound of the range of groups
8773             * @param end the upper bound of the range of groups (not inclusive)
8774             * @return the range of organizations associated with the group
8775             * @throws SystemException if a system exception occurred
8776             */
8777            @Override
8778            public List<com.liferay.portal.model.Organization> getOrganizations(
8779                    long pk, int start, int end) throws SystemException {
8780                    return getOrganizations(pk, start, end, null);
8781            }
8782    
8783            /**
8784             * Returns an ordered range of all the organizations associated with the group.
8785             *
8786             * <p>
8787             * 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.
8788             * </p>
8789             *
8790             * @param pk the primary key of the group
8791             * @param start the lower bound of the range of groups
8792             * @param end the upper bound of the range of groups (not inclusive)
8793             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8794             * @return the ordered range of organizations associated with the group
8795             * @throws SystemException if a system exception occurred
8796             */
8797            @Override
8798            public List<com.liferay.portal.model.Organization> getOrganizations(
8799                    long pk, int start, int end, OrderByComparator orderByComparator)
8800                    throws SystemException {
8801                    return groupToOrganizationTableMapper.getRightBaseModels(pk, start,
8802                            end, orderByComparator);
8803            }
8804    
8805            /**
8806             * Returns the number of organizations associated with the group.
8807             *
8808             * @param pk the primary key of the group
8809             * @return the number of organizations associated with the group
8810             * @throws SystemException if a system exception occurred
8811             */
8812            @Override
8813            public int getOrganizationsSize(long pk) throws SystemException {
8814                    long[] pks = groupToOrganizationTableMapper.getRightPrimaryKeys(pk);
8815    
8816                    return pks.length;
8817            }
8818    
8819            /**
8820             * Returns <code>true</code> if the organization is associated with the group.
8821             *
8822             * @param pk the primary key of the group
8823             * @param organizationPK the primary key of the organization
8824             * @return <code>true</code> if the organization is associated with the group; <code>false</code> otherwise
8825             * @throws SystemException if a system exception occurred
8826             */
8827            @Override
8828            public boolean containsOrganization(long pk, long organizationPK)
8829                    throws SystemException {
8830                    return groupToOrganizationTableMapper.containsTableMapping(pk,
8831                            organizationPK);
8832            }
8833    
8834            /**
8835             * Returns <code>true</code> if the group has any organizations associated with it.
8836             *
8837             * @param pk the primary key of the group to check for associations with organizations
8838             * @return <code>true</code> if the group has any organizations associated with it; <code>false</code> otherwise
8839             * @throws SystemException if a system exception occurred
8840             */
8841            @Override
8842            public boolean containsOrganizations(long pk) throws SystemException {
8843                    if (getOrganizationsSize(pk) > 0) {
8844                            return true;
8845                    }
8846                    else {
8847                            return false;
8848                    }
8849            }
8850    
8851            /**
8852             * Adds an association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8853             *
8854             * @param pk the primary key of the group
8855             * @param organizationPK the primary key of the organization
8856             * @throws SystemException if a system exception occurred
8857             */
8858            @Override
8859            public void addOrganization(long pk, long organizationPK)
8860                    throws SystemException {
8861                    groupToOrganizationTableMapper.addTableMapping(pk, organizationPK);
8862            }
8863    
8864            /**
8865             * Adds an association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8866             *
8867             * @param pk the primary key of the group
8868             * @param organization the organization
8869             * @throws SystemException if a system exception occurred
8870             */
8871            @Override
8872            public void addOrganization(long pk,
8873                    com.liferay.portal.model.Organization organization)
8874                    throws SystemException {
8875                    groupToOrganizationTableMapper.addTableMapping(pk,
8876                            organization.getPrimaryKey());
8877            }
8878    
8879            /**
8880             * Adds an association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8881             *
8882             * @param pk the primary key of the group
8883             * @param organizationPKs the primary keys of the organizations
8884             * @throws SystemException if a system exception occurred
8885             */
8886            @Override
8887            public void addOrganizations(long pk, long[] organizationPKs)
8888                    throws SystemException {
8889                    for (long organizationPK : organizationPKs) {
8890                            groupToOrganizationTableMapper.addTableMapping(pk, organizationPK);
8891                    }
8892            }
8893    
8894            /**
8895             * Adds an association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8896             *
8897             * @param pk the primary key of the group
8898             * @param organizations the organizations
8899             * @throws SystemException if a system exception occurred
8900             */
8901            @Override
8902            public void addOrganizations(long pk,
8903                    List<com.liferay.portal.model.Organization> organizations)
8904                    throws SystemException {
8905                    for (com.liferay.portal.model.Organization organization : organizations) {
8906                            groupToOrganizationTableMapper.addTableMapping(pk,
8907                                    organization.getPrimaryKey());
8908                    }
8909            }
8910    
8911            /**
8912             * Clears all associations between the group and its organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8913             *
8914             * @param pk the primary key of the group to clear the associated organizations from
8915             * @throws SystemException if a system exception occurred
8916             */
8917            @Override
8918            public void clearOrganizations(long pk) throws SystemException {
8919                    groupToOrganizationTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
8920            }
8921    
8922            /**
8923             * Removes the association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8924             *
8925             * @param pk the primary key of the group
8926             * @param organizationPK the primary key of the organization
8927             * @throws SystemException if a system exception occurred
8928             */
8929            @Override
8930            public void removeOrganization(long pk, long organizationPK)
8931                    throws SystemException {
8932                    groupToOrganizationTableMapper.deleteTableMapping(pk, organizationPK);
8933            }
8934    
8935            /**
8936             * Removes the association between the group and the organization. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8937             *
8938             * @param pk the primary key of the group
8939             * @param organization the organization
8940             * @throws SystemException if a system exception occurred
8941             */
8942            @Override
8943            public void removeOrganization(long pk,
8944                    com.liferay.portal.model.Organization organization)
8945                    throws SystemException {
8946                    groupToOrganizationTableMapper.deleteTableMapping(pk,
8947                            organization.getPrimaryKey());
8948            }
8949    
8950            /**
8951             * Removes the association between the group and the organizations. Also notifies the appropriate model listeners and clears the mapping table finder cache.
8952             *
8953             * @param pk the primary key of the group
8954             * @param organizationPKs the primary keys of the organizations
8955             * @throws SystemException if a system exception occurred
8956             */
8957            @Override
8958            public void removeOrganizations(long pk, long[] organizationPKs)
8959                    throws SystemException {
8960                    for (long organizationPK : organizationPKs) {
8961                            groupToOrganizationTableMapper.deleteTableMapping(pk, organizationPK);
8962                    }
8963            }
8964    
8965            /**
8966             * Removes the association between the group and the organizations. 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 organizations the organizations
8970             * @throws SystemException if a system exception occurred
8971             */
8972            @Override
8973            public void removeOrganizations(long pk,
8974                    List<com.liferay.portal.model.Organization> organizations)
8975                    throws SystemException {
8976                    for (com.liferay.portal.model.Organization organization : organizations) {
8977                            groupToOrganizationTableMapper.deleteTableMapping(pk,
8978                                    organization.getPrimaryKey());
8979                    }
8980            }
8981    
8982            /**
8983             * 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.
8984             *
8985             * @param pk the primary key of the group
8986             * @param organizationPKs the primary keys of the organizations to be associated with the group
8987             * @throws SystemException if a system exception occurred
8988             */
8989            @Override
8990            public void setOrganizations(long pk, long[] organizationPKs)
8991                    throws SystemException {
8992                    Set<Long> newOrganizationPKsSet = SetUtil.fromArray(organizationPKs);
8993                    Set<Long> oldOrganizationPKsSet = SetUtil.fromArray(groupToOrganizationTableMapper.getRightPrimaryKeys(
8994                                            pk));
8995    
8996                    Set<Long> removeOrganizationPKsSet = new HashSet<Long>(oldOrganizationPKsSet);
8997    
8998                    removeOrganizationPKsSet.removeAll(newOrganizationPKsSet);
8999    
9000                    for (long removeOrganizationPK : removeOrganizationPKsSet) {
9001                            groupToOrganizationTableMapper.deleteTableMapping(pk,
9002                                    removeOrganizationPK);
9003                    }
9004    
9005                    newOrganizationPKsSet.removeAll(oldOrganizationPKsSet);
9006    
9007                    for (long newOrganizationPK : newOrganizationPKsSet) {
9008                            groupToOrganizationTableMapper.addTableMapping(pk, newOrganizationPK);
9009                    }
9010            }
9011    
9012            /**
9013             * 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.
9014             *
9015             * @param pk the primary key of the group
9016             * @param organizations the organizations to be associated with the group
9017             * @throws SystemException if a system exception occurred
9018             */
9019            @Override
9020            public void setOrganizations(long pk,
9021                    List<com.liferay.portal.model.Organization> organizations)
9022                    throws SystemException {
9023                    try {
9024                            long[] organizationPKs = new long[organizations.size()];
9025    
9026                            for (int i = 0; i < organizations.size(); i++) {
9027                                    com.liferay.portal.model.Organization organization = organizations.get(i);
9028    
9029                                    organizationPKs[i] = organization.getPrimaryKey();
9030                            }
9031    
9032                            setOrganizations(pk, organizationPKs);
9033                    }
9034                    catch (Exception e) {
9035                            throw processException(e);
9036                    }
9037                    finally {
9038                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ORGS_NAME);
9039                    }
9040            }
9041    
9042            /**
9043             * Returns all the roles associated with the group.
9044             *
9045             * @param pk the primary key of the group
9046             * @return the roles associated with the group
9047             * @throws SystemException if a system exception occurred
9048             */
9049            @Override
9050            public List<com.liferay.portal.model.Role> getRoles(long pk)
9051                    throws SystemException {
9052                    return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9053            }
9054    
9055            /**
9056             * Returns a range of all the roles associated with the group.
9057             *
9058             * <p>
9059             * 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.
9060             * </p>
9061             *
9062             * @param pk the primary key of the group
9063             * @param start the lower bound of the range of groups
9064             * @param end the upper bound of the range of groups (not inclusive)
9065             * @return the range of roles associated with the group
9066             * @throws SystemException if a system exception occurred
9067             */
9068            @Override
9069            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
9070                    int end) throws SystemException {
9071                    return getRoles(pk, start, end, null);
9072            }
9073    
9074            /**
9075             * Returns an ordered range of all the roles associated with the group.
9076             *
9077             * <p>
9078             * 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.
9079             * </p>
9080             *
9081             * @param pk the primary key of the group
9082             * @param start the lower bound of the range of groups
9083             * @param end the upper bound of the range of groups (not inclusive)
9084             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9085             * @return the ordered range of roles associated with the group
9086             * @throws SystemException if a system exception occurred
9087             */
9088            @Override
9089            public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
9090                    int end, OrderByComparator orderByComparator) throws SystemException {
9091                    return groupToRoleTableMapper.getRightBaseModels(pk, start, end,
9092                            orderByComparator);
9093            }
9094    
9095            /**
9096             * Returns the number of roles associated with the group.
9097             *
9098             * @param pk the primary key of the group
9099             * @return the number of roles associated with the group
9100             * @throws SystemException if a system exception occurred
9101             */
9102            @Override
9103            public int getRolesSize(long pk) throws SystemException {
9104                    long[] pks = groupToRoleTableMapper.getRightPrimaryKeys(pk);
9105    
9106                    return pks.length;
9107            }
9108    
9109            /**
9110             * Returns <code>true</code> if the role is associated with the group.
9111             *
9112             * @param pk the primary key of the group
9113             * @param rolePK the primary key of the role
9114             * @return <code>true</code> if the role is associated with the group; <code>false</code> otherwise
9115             * @throws SystemException if a system exception occurred
9116             */
9117            @Override
9118            public boolean containsRole(long pk, long rolePK) throws SystemException {
9119                    return groupToRoleTableMapper.containsTableMapping(pk, rolePK);
9120            }
9121    
9122            /**
9123             * Returns <code>true</code> if the group has any roles associated with it.
9124             *
9125             * @param pk the primary key of the group to check for associations with roles
9126             * @return <code>true</code> if the group has any roles associated with it; <code>false</code> otherwise
9127             * @throws SystemException if a system exception occurred
9128             */
9129            @Override
9130            public boolean containsRoles(long pk) throws SystemException {
9131                    if (getRolesSize(pk) > 0) {
9132                            return true;
9133                    }
9134                    else {
9135                            return false;
9136                    }
9137            }
9138    
9139            /**
9140             * Adds an association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9141             *
9142             * @param pk the primary key of the group
9143             * @param rolePK the primary key of the role
9144             * @throws SystemException if a system exception occurred
9145             */
9146            @Override
9147            public void addRole(long pk, long rolePK) throws SystemException {
9148                    groupToRoleTableMapper.addTableMapping(pk, rolePK);
9149            }
9150    
9151            /**
9152             * Adds an association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9153             *
9154             * @param pk the primary key of the group
9155             * @param role the role
9156             * @throws SystemException if a system exception occurred
9157             */
9158            @Override
9159            public void addRole(long pk, com.liferay.portal.model.Role role)
9160                    throws SystemException {
9161                    groupToRoleTableMapper.addTableMapping(pk, role.getPrimaryKey());
9162            }
9163    
9164            /**
9165             * Adds an association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9166             *
9167             * @param pk the primary key of the group
9168             * @param rolePKs the primary keys of the roles
9169             * @throws SystemException if a system exception occurred
9170             */
9171            @Override
9172            public void addRoles(long pk, long[] rolePKs) throws SystemException {
9173                    for (long rolePK : rolePKs) {
9174                            groupToRoleTableMapper.addTableMapping(pk, rolePK);
9175                    }
9176            }
9177    
9178            /**
9179             * Adds an association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9180             *
9181             * @param pk the primary key of the group
9182             * @param roles the roles
9183             * @throws SystemException if a system exception occurred
9184             */
9185            @Override
9186            public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
9187                    throws SystemException {
9188                    for (com.liferay.portal.model.Role role : roles) {
9189                            groupToRoleTableMapper.addTableMapping(pk, role.getPrimaryKey());
9190                    }
9191            }
9192    
9193            /**
9194             * Clears all associations between the group and its roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9195             *
9196             * @param pk the primary key of the group to clear the associated roles from
9197             * @throws SystemException if a system exception occurred
9198             */
9199            @Override
9200            public void clearRoles(long pk) throws SystemException {
9201                    groupToRoleTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9202            }
9203    
9204            /**
9205             * Removes the association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9206             *
9207             * @param pk the primary key of the group
9208             * @param rolePK the primary key of the role
9209             * @throws SystemException if a system exception occurred
9210             */
9211            @Override
9212            public void removeRole(long pk, long rolePK) throws SystemException {
9213                    groupToRoleTableMapper.deleteTableMapping(pk, rolePK);
9214            }
9215    
9216            /**
9217             * Removes the association between the group and the role. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9218             *
9219             * @param pk the primary key of the group
9220             * @param role the role
9221             * @throws SystemException if a system exception occurred
9222             */
9223            @Override
9224            public void removeRole(long pk, com.liferay.portal.model.Role role)
9225                    throws SystemException {
9226                    groupToRoleTableMapper.deleteTableMapping(pk, role.getPrimaryKey());
9227            }
9228    
9229            /**
9230             * Removes the association between the group and the roles. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9231             *
9232             * @param pk the primary key of the group
9233             * @param rolePKs the primary keys of the roles
9234             * @throws SystemException if a system exception occurred
9235             */
9236            @Override
9237            public void removeRoles(long pk, long[] rolePKs) throws SystemException {
9238                    for (long rolePK : rolePKs) {
9239                            groupToRoleTableMapper.deleteTableMapping(pk, rolePK);
9240                    }
9241            }
9242    
9243            /**
9244             * Removes the association between the group and the roles. 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 roles the roles
9248             * @throws SystemException if a system exception occurred
9249             */
9250            @Override
9251            public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
9252                    throws SystemException {
9253                    for (com.liferay.portal.model.Role role : roles) {
9254                            groupToRoleTableMapper.deleteTableMapping(pk, role.getPrimaryKey());
9255                    }
9256            }
9257    
9258            /**
9259             * 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.
9260             *
9261             * @param pk the primary key of the group
9262             * @param rolePKs the primary keys of the roles to be associated with the group
9263             * @throws SystemException if a system exception occurred
9264             */
9265            @Override
9266            public void setRoles(long pk, long[] rolePKs) throws SystemException {
9267                    Set<Long> newRolePKsSet = SetUtil.fromArray(rolePKs);
9268                    Set<Long> oldRolePKsSet = SetUtil.fromArray(groupToRoleTableMapper.getRightPrimaryKeys(
9269                                            pk));
9270    
9271                    Set<Long> removeRolePKsSet = new HashSet<Long>(oldRolePKsSet);
9272    
9273                    removeRolePKsSet.removeAll(newRolePKsSet);
9274    
9275                    for (long removeRolePK : removeRolePKsSet) {
9276                            groupToRoleTableMapper.deleteTableMapping(pk, removeRolePK);
9277                    }
9278    
9279                    newRolePKsSet.removeAll(oldRolePKsSet);
9280    
9281                    for (long newRolePK : newRolePKsSet) {
9282                            groupToRoleTableMapper.addTableMapping(pk, newRolePK);
9283                    }
9284            }
9285    
9286            /**
9287             * 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.
9288             *
9289             * @param pk the primary key of the group
9290             * @param roles the roles to be associated with the group
9291             * @throws SystemException if a system exception occurred
9292             */
9293            @Override
9294            public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
9295                    throws SystemException {
9296                    try {
9297                            long[] rolePKs = new long[roles.size()];
9298    
9299                            for (int i = 0; i < roles.size(); i++) {
9300                                    com.liferay.portal.model.Role role = roles.get(i);
9301    
9302                                    rolePKs[i] = role.getPrimaryKey();
9303                            }
9304    
9305                            setRoles(pk, rolePKs);
9306                    }
9307                    catch (Exception e) {
9308                            throw processException(e);
9309                    }
9310                    finally {
9311                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
9312                    }
9313            }
9314    
9315            /**
9316             * Returns all the user groups associated with the group.
9317             *
9318             * @param pk the primary key of the group
9319             * @return the user groups associated with the group
9320             * @throws SystemException if a system exception occurred
9321             */
9322            @Override
9323            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
9324                    throws SystemException {
9325                    return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9326            }
9327    
9328            /**
9329             * Returns a range of all the user groups associated with the group.
9330             *
9331             * <p>
9332             * 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.
9333             * </p>
9334             *
9335             * @param pk the primary key of the group
9336             * @param start the lower bound of the range of groups
9337             * @param end the upper bound of the range of groups (not inclusive)
9338             * @return the range of user groups associated with the group
9339             * @throws SystemException if a system exception occurred
9340             */
9341            @Override
9342            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
9343                    int start, int end) throws SystemException {
9344                    return getUserGroups(pk, start, end, null);
9345            }
9346    
9347            /**
9348             * Returns an ordered range of all the user groups associated with the group.
9349             *
9350             * <p>
9351             * 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.
9352             * </p>
9353             *
9354             * @param pk the primary key of the group
9355             * @param start the lower bound of the range of groups
9356             * @param end the upper bound of the range of groups (not inclusive)
9357             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9358             * @return the ordered range of user groups associated with the group
9359             * @throws SystemException if a system exception occurred
9360             */
9361            @Override
9362            public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
9363                    int start, int end, OrderByComparator orderByComparator)
9364                    throws SystemException {
9365                    return groupToUserGroupTableMapper.getRightBaseModels(pk, start, end,
9366                            orderByComparator);
9367            }
9368    
9369            /**
9370             * Returns the number of user groups associated with the group.
9371             *
9372             * @param pk the primary key of the group
9373             * @return the number of user groups associated with the group
9374             * @throws SystemException if a system exception occurred
9375             */
9376            @Override
9377            public int getUserGroupsSize(long pk) throws SystemException {
9378                    long[] pks = groupToUserGroupTableMapper.getRightPrimaryKeys(pk);
9379    
9380                    return pks.length;
9381            }
9382    
9383            /**
9384             * Returns <code>true</code> if the user group is associated with the group.
9385             *
9386             * @param pk the primary key of the group
9387             * @param userGroupPK the primary key of the user group
9388             * @return <code>true</code> if the user group is associated with the group; <code>false</code> otherwise
9389             * @throws SystemException if a system exception occurred
9390             */
9391            @Override
9392            public boolean containsUserGroup(long pk, long userGroupPK)
9393                    throws SystemException {
9394                    return groupToUserGroupTableMapper.containsTableMapping(pk, userGroupPK);
9395            }
9396    
9397            /**
9398             * Returns <code>true</code> if the group has any user groups associated with it.
9399             *
9400             * @param pk the primary key of the group to check for associations with user groups
9401             * @return <code>true</code> if the group has any user groups associated with it; <code>false</code> otherwise
9402             * @throws SystemException if a system exception occurred
9403             */
9404            @Override
9405            public boolean containsUserGroups(long pk) throws SystemException {
9406                    if (getUserGroupsSize(pk) > 0) {
9407                            return true;
9408                    }
9409                    else {
9410                            return false;
9411                    }
9412            }
9413    
9414            /**
9415             * Adds an association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9416             *
9417             * @param pk the primary key of the group
9418             * @param userGroupPK the primary key of the user group
9419             * @throws SystemException if a system exception occurred
9420             */
9421            @Override
9422            public void addUserGroup(long pk, long userGroupPK)
9423                    throws SystemException {
9424                    groupToUserGroupTableMapper.addTableMapping(pk, userGroupPK);
9425            }
9426    
9427            /**
9428             * Adds an association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9429             *
9430             * @param pk the primary key of the group
9431             * @param userGroup the user group
9432             * @throws SystemException if a system exception occurred
9433             */
9434            @Override
9435            public void addUserGroup(long pk,
9436                    com.liferay.portal.model.UserGroup userGroup) throws SystemException {
9437                    groupToUserGroupTableMapper.addTableMapping(pk,
9438                            userGroup.getPrimaryKey());
9439            }
9440    
9441            /**
9442             * Adds an association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9443             *
9444             * @param pk the primary key of the group
9445             * @param userGroupPKs the primary keys of the user groups
9446             * @throws SystemException if a system exception occurred
9447             */
9448            @Override
9449            public void addUserGroups(long pk, long[] userGroupPKs)
9450                    throws SystemException {
9451                    for (long userGroupPK : userGroupPKs) {
9452                            groupToUserGroupTableMapper.addTableMapping(pk, userGroupPK);
9453                    }
9454            }
9455    
9456            /**
9457             * Adds an association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9458             *
9459             * @param pk the primary key of the group
9460             * @param userGroups the user groups
9461             * @throws SystemException if a system exception occurred
9462             */
9463            @Override
9464            public void addUserGroups(long pk,
9465                    List<com.liferay.portal.model.UserGroup> userGroups)
9466                    throws SystemException {
9467                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
9468                            groupToUserGroupTableMapper.addTableMapping(pk,
9469                                    userGroup.getPrimaryKey());
9470                    }
9471            }
9472    
9473            /**
9474             * Clears all associations between the group and its user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9475             *
9476             * @param pk the primary key of the group to clear the associated user groups from
9477             * @throws SystemException if a system exception occurred
9478             */
9479            @Override
9480            public void clearUserGroups(long pk) throws SystemException {
9481                    groupToUserGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9482            }
9483    
9484            /**
9485             * Removes the association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9486             *
9487             * @param pk the primary key of the group
9488             * @param userGroupPK the primary key of the user group
9489             * @throws SystemException if a system exception occurred
9490             */
9491            @Override
9492            public void removeUserGroup(long pk, long userGroupPK)
9493                    throws SystemException {
9494                    groupToUserGroupTableMapper.deleteTableMapping(pk, userGroupPK);
9495            }
9496    
9497            /**
9498             * Removes the association between the group and the user group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9499             *
9500             * @param pk the primary key of the group
9501             * @param userGroup the user group
9502             * @throws SystemException if a system exception occurred
9503             */
9504            @Override
9505            public void removeUserGroup(long pk,
9506                    com.liferay.portal.model.UserGroup userGroup) throws SystemException {
9507                    groupToUserGroupTableMapper.deleteTableMapping(pk,
9508                            userGroup.getPrimaryKey());
9509            }
9510    
9511            /**
9512             * Removes the association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9513             *
9514             * @param pk the primary key of the group
9515             * @param userGroupPKs the primary keys of the user groups
9516             * @throws SystemException if a system exception occurred
9517             */
9518            @Override
9519            public void removeUserGroups(long pk, long[] userGroupPKs)
9520                    throws SystemException {
9521                    for (long userGroupPK : userGroupPKs) {
9522                            groupToUserGroupTableMapper.deleteTableMapping(pk, userGroupPK);
9523                    }
9524            }
9525    
9526            /**
9527             * Removes the association between the group and the user groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9528             *
9529             * @param pk the primary key of the group
9530             * @param userGroups the user groups
9531             * @throws SystemException if a system exception occurred
9532             */
9533            @Override
9534            public void removeUserGroups(long pk,
9535                    List<com.liferay.portal.model.UserGroup> userGroups)
9536                    throws SystemException {
9537                    for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
9538                            groupToUserGroupTableMapper.deleteTableMapping(pk,
9539                                    userGroup.getPrimaryKey());
9540                    }
9541            }
9542    
9543            /**
9544             * 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.
9545             *
9546             * @param pk the primary key of the group
9547             * @param userGroupPKs the primary keys of the user groups to be associated with the group
9548             * @throws SystemException if a system exception occurred
9549             */
9550            @Override
9551            public void setUserGroups(long pk, long[] userGroupPKs)
9552                    throws SystemException {
9553                    Set<Long> newUserGroupPKsSet = SetUtil.fromArray(userGroupPKs);
9554                    Set<Long> oldUserGroupPKsSet = SetUtil.fromArray(groupToUserGroupTableMapper.getRightPrimaryKeys(
9555                                            pk));
9556    
9557                    Set<Long> removeUserGroupPKsSet = new HashSet<Long>(oldUserGroupPKsSet);
9558    
9559                    removeUserGroupPKsSet.removeAll(newUserGroupPKsSet);
9560    
9561                    for (long removeUserGroupPK : removeUserGroupPKsSet) {
9562                            groupToUserGroupTableMapper.deleteTableMapping(pk, removeUserGroupPK);
9563                    }
9564    
9565                    newUserGroupPKsSet.removeAll(oldUserGroupPKsSet);
9566    
9567                    for (long newUserGroupPK : newUserGroupPKsSet) {
9568                            groupToUserGroupTableMapper.addTableMapping(pk, newUserGroupPK);
9569                    }
9570            }
9571    
9572            /**
9573             * 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.
9574             *
9575             * @param pk the primary key of the group
9576             * @param userGroups the user groups to be associated with the group
9577             * @throws SystemException if a system exception occurred
9578             */
9579            @Override
9580            public void setUserGroups(long pk,
9581                    List<com.liferay.portal.model.UserGroup> userGroups)
9582                    throws SystemException {
9583                    try {
9584                            long[] userGroupPKs = new long[userGroups.size()];
9585    
9586                            for (int i = 0; i < userGroups.size(); i++) {
9587                                    com.liferay.portal.model.UserGroup userGroup = userGroups.get(i);
9588    
9589                                    userGroupPKs[i] = userGroup.getPrimaryKey();
9590                            }
9591    
9592                            setUserGroups(pk, userGroupPKs);
9593                    }
9594                    catch (Exception e) {
9595                            throw processException(e);
9596                    }
9597                    finally {
9598                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_GROUPS_USERGROUPS_NAME);
9599                    }
9600            }
9601    
9602            /**
9603             * Returns all the users associated with the group.
9604             *
9605             * @param pk the primary key of the group
9606             * @return the users associated with the group
9607             * @throws SystemException if a system exception occurred
9608             */
9609            @Override
9610            public List<com.liferay.portal.model.User> getUsers(long pk)
9611                    throws SystemException {
9612                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9613            }
9614    
9615            /**
9616             * Returns a range of all the users associated with the group.
9617             *
9618             * <p>
9619             * 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.
9620             * </p>
9621             *
9622             * @param pk the primary key of the group
9623             * @param start the lower bound of the range of groups
9624             * @param end the upper bound of the range of groups (not inclusive)
9625             * @return the range of users associated with the group
9626             * @throws SystemException if a system exception occurred
9627             */
9628            @Override
9629            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9630                    int end) throws SystemException {
9631                    return getUsers(pk, start, end, null);
9632            }
9633    
9634            /**
9635             * Returns an ordered range of all the users associated with the group.
9636             *
9637             * <p>
9638             * 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.
9639             * </p>
9640             *
9641             * @param pk the primary key of the group
9642             * @param start the lower bound of the range of groups
9643             * @param end the upper bound of the range of groups (not inclusive)
9644             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9645             * @return the ordered range of users associated with the group
9646             * @throws SystemException if a system exception occurred
9647             */
9648            @Override
9649            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9650                    int end, OrderByComparator orderByComparator) throws SystemException {
9651                    return groupToUserTableMapper.getRightBaseModels(pk, start, end,
9652                            orderByComparator);
9653            }
9654    
9655            /**
9656             * Returns the number of users associated with the group.
9657             *
9658             * @param pk the primary key of the group
9659             * @return the number of users associated with the group
9660             * @throws SystemException if a system exception occurred
9661             */
9662            @Override
9663            public int getUsersSize(long pk) throws SystemException {
9664                    long[] pks = groupToUserTableMapper.getRightPrimaryKeys(pk);
9665    
9666                    return pks.length;
9667            }
9668    
9669            /**
9670             * Returns <code>true</code> if the user is associated with the group.
9671             *
9672             * @param pk the primary key of the group
9673             * @param userPK the primary key of the user
9674             * @return <code>true</code> if the user is associated with the group; <code>false</code> otherwise
9675             * @throws SystemException if a system exception occurred
9676             */
9677            @Override
9678            public boolean containsUser(long pk, long userPK) throws SystemException {
9679                    return groupToUserTableMapper.containsTableMapping(pk, userPK);
9680            }
9681    
9682            /**
9683             * Returns <code>true</code> if the group has any users associated with it.
9684             *
9685             * @param pk the primary key of the group to check for associations with users
9686             * @return <code>true</code> if the group has any users associated with it; <code>false</code> otherwise
9687             * @throws SystemException if a system exception occurred
9688             */
9689            @Override
9690            public boolean containsUsers(long pk) throws SystemException {
9691                    if (getUsersSize(pk) > 0) {
9692                            return true;
9693                    }
9694                    else {
9695                            return false;
9696                    }
9697            }
9698    
9699            /**
9700             * Adds an association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9701             *
9702             * @param pk the primary key of the group
9703             * @param userPK the primary key of the user
9704             * @throws SystemException if a system exception occurred
9705             */
9706            @Override
9707            public void addUser(long pk, long userPK) throws SystemException {
9708                    groupToUserTableMapper.addTableMapping(pk, userPK);
9709            }
9710    
9711            /**
9712             * Adds an association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9713             *
9714             * @param pk the primary key of the group
9715             * @param user the user
9716             * @throws SystemException if a system exception occurred
9717             */
9718            @Override
9719            public void addUser(long pk, com.liferay.portal.model.User user)
9720                    throws SystemException {
9721                    groupToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
9722            }
9723    
9724            /**
9725             * Adds an association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9726             *
9727             * @param pk the primary key of the group
9728             * @param userPKs the primary keys of the users
9729             * @throws SystemException if a system exception occurred
9730             */
9731            @Override
9732            public void addUsers(long pk, long[] userPKs) throws SystemException {
9733                    for (long userPK : userPKs) {
9734                            groupToUserTableMapper.addTableMapping(pk, userPK);
9735                    }
9736            }
9737    
9738            /**
9739             * Adds an association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9740             *
9741             * @param pk the primary key of the group
9742             * @param users the users
9743             * @throws SystemException if a system exception occurred
9744             */
9745            @Override
9746            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
9747                    throws SystemException {
9748                    for (com.liferay.portal.model.User user : users) {
9749                            groupToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
9750                    }
9751            }
9752    
9753            /**
9754             * Clears all associations between the group and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9755             *
9756             * @param pk the primary key of the group to clear the associated users from
9757             * @throws SystemException if a system exception occurred
9758             */
9759            @Override
9760            public void clearUsers(long pk) throws SystemException {
9761                    groupToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9762            }
9763    
9764            /**
9765             * Removes the association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9766             *
9767             * @param pk the primary key of the group
9768             * @param userPK the primary key of the user
9769             * @throws SystemException if a system exception occurred
9770             */
9771            @Override
9772            public void removeUser(long pk, long userPK) throws SystemException {
9773                    groupToUserTableMapper.deleteTableMapping(pk, userPK);
9774            }
9775    
9776            /**
9777             * Removes the association between the group and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9778             *
9779             * @param pk the primary key of the group
9780             * @param user the user
9781             * @throws SystemException if a system exception occurred
9782             */
9783            @Override
9784            public void removeUser(long pk, com.liferay.portal.model.User user)
9785                    throws SystemException {
9786                    groupToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9787            }
9788    
9789            /**
9790             * Removes the association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9791             *
9792             * @param pk the primary key of the group
9793             * @param userPKs the primary keys of the users
9794             * @throws SystemException if a system exception occurred
9795             */
9796            @Override
9797            public void removeUsers(long pk, long[] userPKs) throws SystemException {
9798                    for (long userPK : userPKs) {
9799                            groupToUserTableMapper.deleteTableMapping(pk, userPK);
9800                    }
9801            }
9802    
9803            /**
9804             * Removes the association between the group and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9805             *
9806             * @param pk the primary key of the group
9807             * @param users the users
9808             * @throws SystemException if a system exception occurred
9809             */
9810            @Override
9811            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
9812                    throws SystemException {
9813                    for (com.liferay.portal.model.User user : users) {
9814                            groupToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9815                    }
9816            }
9817    
9818            /**
9819             * 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.
9820             *
9821             * @param pk the primary key of the group
9822             * @param userPKs the primary keys of the users to be associated with the group
9823             * @throws SystemException if a system exception occurred
9824             */
9825            @Override
9826            public void setUsers(long pk, long[] userPKs) throws SystemException {
9827                    Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
9828                    Set<Long> oldUserPKsSet = SetUtil.fromArray(groupToUserTableMapper.getRightPrimaryKeys(
9829                                            pk));
9830    
9831                    Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
9832    
9833                    removeUserPKsSet.removeAll(newUserPKsSet);
9834    
9835                    for (long removeUserPK : removeUserPKsSet) {
9836                            groupToUserTableMapper.deleteTableMapping(pk, removeUserPK);
9837                    }
9838    
9839                    newUserPKsSet.removeAll(oldUserPKsSet);
9840    
9841                    for (long newUserPK : newUserPKsSet) {
9842                            groupToUserTableMapper.addTableMapping(pk, newUserPK);
9843                    }
9844            }
9845    
9846            /**
9847             * 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.
9848             *
9849             * @param pk the primary key of the group
9850             * @param users the users to be associated with the group
9851             * @throws SystemException if a system exception occurred
9852             */
9853            @Override
9854            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
9855                    throws SystemException {
9856                    try {
9857                            long[] userPKs = new long[users.size()];
9858    
9859                            for (int i = 0; i < users.size(); i++) {
9860                                    com.liferay.portal.model.User user = users.get(i);
9861    
9862                                    userPKs[i] = user.getPrimaryKey();
9863                            }
9864    
9865                            setUsers(pk, userPKs);
9866                    }
9867                    catch (Exception e) {
9868                            throw processException(e);
9869                    }
9870                    finally {
9871                            FinderCacheUtil.clearCache(GroupModelImpl.MAPPING_TABLE_USERS_GROUPS_NAME);
9872                    }
9873            }
9874    
9875            @Override
9876            protected Set<String> getBadColumnNames() {
9877                    return _badColumnNames;
9878            }
9879    
9880            /**
9881             * Initializes the group persistence.
9882             */
9883            public void afterPropertiesSet() {
9884                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9885                                            com.liferay.portal.util.PropsUtil.get(
9886                                                    "value.object.listener.com.liferay.portal.model.Group")));
9887    
9888                    if (listenerClassNames.length > 0) {
9889                            try {
9890                                    List<ModelListener<Group>> listenersList = new ArrayList<ModelListener<Group>>();
9891    
9892                                    for (String listenerClassName : listenerClassNames) {
9893                                            listenersList.add((ModelListener<Group>)InstanceFactory.newInstance(
9894                                                            getClassLoader(), listenerClassName));
9895                                    }
9896    
9897                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9898                            }
9899                            catch (Exception e) {
9900                                    _log.error(e);
9901                            }
9902                    }
9903    
9904                    groupToOrganizationTableMapper = TableMapperFactory.getTableMapper("Groups_Orgs",
9905                                    "groupId", "organizationId", this, organizationPersistence);
9906    
9907                    groupToRoleTableMapper = TableMapperFactory.getTableMapper("Groups_Roles",
9908                                    "groupId", "roleId", this, rolePersistence);
9909    
9910                    groupToUserGroupTableMapper = TableMapperFactory.getTableMapper("Groups_UserGroups",
9911                                    "groupId", "userGroupId", this, userGroupPersistence);
9912    
9913                    groupToUserTableMapper = TableMapperFactory.getTableMapper("Users_Groups",
9914                                    "groupId", "userId", this, userPersistence);
9915            }
9916    
9917            public void destroy() {
9918                    EntityCacheUtil.removeCache(GroupImpl.class.getName());
9919                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9920                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9921                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9922    
9923                    TableMapperFactory.removeTableMapper("Groups_Orgs");
9924                    TableMapperFactory.removeTableMapper("Groups_Roles");
9925                    TableMapperFactory.removeTableMapper("Groups_UserGroups");
9926                    TableMapperFactory.removeTableMapper("Users_Groups");
9927            }
9928    
9929            @BeanReference(type = OrganizationPersistence.class)
9930            protected OrganizationPersistence organizationPersistence;
9931            protected TableMapper<Group, com.liferay.portal.model.Organization> groupToOrganizationTableMapper;
9932            @BeanReference(type = RolePersistence.class)
9933            protected RolePersistence rolePersistence;
9934            protected TableMapper<Group, com.liferay.portal.model.Role> groupToRoleTableMapper;
9935            @BeanReference(type = UserGroupPersistence.class)
9936            protected UserGroupPersistence userGroupPersistence;
9937            protected TableMapper<Group, com.liferay.portal.model.UserGroup> groupToUserGroupTableMapper;
9938            @BeanReference(type = UserPersistence.class)
9939            protected UserPersistence userPersistence;
9940            protected TableMapper<Group, com.liferay.portal.model.User> groupToUserTableMapper;
9941            private static final String _SQL_SELECT_GROUP_ = "SELECT group_ FROM Group group_";
9942            private static final String _SQL_SELECT_GROUP__WHERE = "SELECT group_ FROM Group group_ WHERE ";
9943            private static final String _SQL_COUNT_GROUP_ = "SELECT COUNT(group_) FROM Group group_";
9944            private static final String _SQL_COUNT_GROUP__WHERE = "SELECT COUNT(group_) FROM Group group_ WHERE ";
9945            private static final String _ORDER_BY_ENTITY_ALIAS = "group_.";
9946            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Group exists with the primary key ";
9947            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Group exists with the key {";
9948            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9949            private static Log _log = LogFactoryUtil.getLog(GroupPersistenceImpl.class);
9950            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9951                                    "uuid", "type", "active"
9952                            });
9953            private static Group _nullGroup = new GroupImpl() {
9954                            @Override
9955                            public Object clone() {
9956                                    return this;
9957                            }
9958    
9959                            @Override
9960                            public CacheModel<Group> toCacheModel() {
9961                                    return _nullGroupCacheModel;
9962                            }
9963                    };
9964    
9965            private static CacheModel<Group> _nullGroupCacheModel = new CacheModel<Group>() {
9966                            @Override
9967                            public Group toEntityModel() {
9968                                    return _nullGroup;
9969                            }
9970                    };
9971    }