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