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