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