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