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