1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchGroupException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
30  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
31  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
32  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
33  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
34  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
35  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
36  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
37  import com.liferay.portal.kernel.dao.orm.FinderPath;
38  import com.liferay.portal.kernel.dao.orm.Query;
39  import com.liferay.portal.kernel.dao.orm.QueryPos;
40  import com.liferay.portal.kernel.dao.orm.QueryUtil;
41  import com.liferay.portal.kernel.dao.orm.SQLQuery;
42  import com.liferay.portal.kernel.dao.orm.Session;
43  import com.liferay.portal.kernel.dao.orm.Type;
44  import com.liferay.portal.kernel.log.Log;
45  import com.liferay.portal.kernel.log.LogFactoryUtil;
46  import com.liferay.portal.kernel.util.GetterUtil;
47  import com.liferay.portal.kernel.util.OrderByComparator;
48  import com.liferay.portal.kernel.util.StringPool;
49  import com.liferay.portal.kernel.util.StringUtil;
50  import com.liferay.portal.kernel.util.Validator;
51  import com.liferay.portal.model.Group;
52  import com.liferay.portal.model.ModelListener;
53  import com.liferay.portal.model.impl.GroupImpl;
54  import com.liferay.portal.model.impl.GroupModelImpl;
55  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
56  
57  import java.sql.Types;
58  
59  import java.util.ArrayList;
60  import java.util.Collections;
61  import java.util.List;
62  
63  /**
64   * <a href="GroupPersistenceImpl.java.html"><b><i>View Source</i></b></a>
65   *
66   * @author Brian Wing Shun Chan
67   *
68   */
69  public class GroupPersistenceImpl extends BasePersistenceImpl
70      implements GroupPersistence {
71      public static final String FINDER_CLASS_NAME_ENTITY = GroupImpl.class.getName();
72      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
73          ".List";
74      public static final FinderPath FINDER_PATH_FETCH_BY_LIVEGROUPID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
75              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
76              "fetchByLiveGroupId", new String[] { Long.class.getName() });
77      public static final FinderPath FINDER_PATH_COUNT_BY_LIVEGROUPID = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
78              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
79              "countByLiveGroupId", new String[] { Long.class.getName() });
80      public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
81              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
82              "fetchByC_N",
83              new String[] { Long.class.getName(), String.class.getName() });
84      public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
85              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
86              "countByC_N",
87              new String[] { Long.class.getName(), String.class.getName() });
88      public static final FinderPath FINDER_PATH_FETCH_BY_C_F = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
89              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
90              "fetchByC_F",
91              new String[] { Long.class.getName(), String.class.getName() });
92      public static final FinderPath FINDER_PATH_COUNT_BY_C_F = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
93              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94              "countByC_F",
95              new String[] { Long.class.getName(), String.class.getName() });
96      public static final FinderPath FINDER_PATH_FIND_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
97              GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
98              "findByT_A",
99              new String[] { Integer.class.getName(), Boolean.class.getName() });
100     public static final FinderPath FINDER_PATH_FIND_BY_OBC_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
101             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102             "findByT_A",
103             new String[] {
104                 Integer.class.getName(), Boolean.class.getName(),
105                 
106             "java.lang.Integer", "java.lang.Integer",
107                 "com.liferay.portal.kernel.util.OrderByComparator"
108             });
109     public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
110             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111             "countByT_A",
112             new String[] { Integer.class.getName(), Boolean.class.getName() });
113     public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
114             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
115             "fetchByC_C_C",
116             new String[] {
117                 Long.class.getName(), Long.class.getName(), Long.class.getName()
118             });
119     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
120             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121             "countByC_C_C",
122             new String[] {
123                 Long.class.getName(), Long.class.getName(), Long.class.getName()
124             });
125     public static final FinderPath FINDER_PATH_FETCH_BY_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
126             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
127             "fetchByC_L_N",
128             new String[] {
129                 Long.class.getName(), Long.class.getName(),
130                 String.class.getName()
131             });
132     public static final FinderPath FINDER_PATH_COUNT_BY_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
133             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134             "countByC_L_N",
135             new String[] {
136                 Long.class.getName(), Long.class.getName(),
137                 String.class.getName()
138             });
139     public static final FinderPath FINDER_PATH_FETCH_BY_C_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
140             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
141             "fetchByC_C_L_N",
142             new String[] {
143                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
144                 String.class.getName()
145             });
146     public static final FinderPath FINDER_PATH_COUNT_BY_C_C_L_N = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
147             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
148             "countByC_C_L_N",
149             new String[] {
150                 Long.class.getName(), Long.class.getName(), Long.class.getName(),
151                 String.class.getName()
152             });
153     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
154             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
155             "findAll", new String[0]);
156     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(GroupModelImpl.ENTITY_CACHE_ENABLED,
157             GroupModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
158             "countAll", new String[0]);
159 
160     public void cacheResult(Group group) {
161         EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
162             GroupImpl.class, group.getPrimaryKey(), group);
163 
164         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
165             new Object[] { new Long(group.getLiveGroupId()) }, group);
166 
167         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
168             new Object[] { new Long(group.getCompanyId()), group.getName() },
169             group);
170 
171         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
172             new Object[] { new Long(group.getCompanyId()), group.getFriendlyURL() },
173             group);
174 
175         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
176             new Object[] {
177                 new Long(group.getCompanyId()), new Long(group.getClassNameId()),
178                 new Long(group.getClassPK())
179             }, group);
180 
181         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
182             new Object[] {
183                 new Long(group.getCompanyId()), new Long(group.getLiveGroupId()),
184                 
185             group.getName()
186             }, group);
187 
188         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
189             new Object[] {
190                 new Long(group.getCompanyId()), new Long(group.getClassNameId()),
191                 new Long(group.getLiveGroupId()),
192                 
193             group.getName()
194             }, group);
195     }
196 
197     public void cacheResult(List<Group> groups) {
198         for (Group group : groups) {
199             if (EntityCacheUtil.getResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
200                         GroupImpl.class, group.getPrimaryKey(), this) == null) {
201                 cacheResult(group);
202             }
203         }
204     }
205 
206     public void clearCache() {
207         CacheRegistry.clear(GroupImpl.class.getName());
208         EntityCacheUtil.clearCache(GroupImpl.class.getName());
209         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
210         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
211     }
212 
213     public Group create(long groupId) {
214         Group group = new GroupImpl();
215 
216         group.setNew(true);
217         group.setPrimaryKey(groupId);
218 
219         return group;
220     }
221 
222     public Group remove(long groupId)
223         throws NoSuchGroupException, SystemException {
224         Session session = null;
225 
226         try {
227             session = openSession();
228 
229             Group group = (Group)session.get(GroupImpl.class, new Long(groupId));
230 
231             if (group == null) {
232                 if (_log.isWarnEnabled()) {
233                     _log.warn("No Group exists with the primary key " +
234                         groupId);
235                 }
236 
237                 throw new NoSuchGroupException(
238                     "No Group exists with the primary key " + groupId);
239             }
240 
241             return remove(group);
242         }
243         catch (NoSuchGroupException nsee) {
244             throw nsee;
245         }
246         catch (Exception e) {
247             throw processException(e);
248         }
249         finally {
250             closeSession(session);
251         }
252     }
253 
254     public Group remove(Group group) throws SystemException {
255         for (ModelListener<Group> listener : listeners) {
256             listener.onBeforeRemove(group);
257         }
258 
259         group = removeImpl(group);
260 
261         for (ModelListener<Group> listener : listeners) {
262             listener.onAfterRemove(group);
263         }
264 
265         return group;
266     }
267 
268     protected Group removeImpl(Group group) throws SystemException {
269         try {
270             clearOrganizations.clear(group.getPrimaryKey());
271         }
272         catch (Exception e) {
273             throw processException(e);
274         }
275         finally {
276             FinderCacheUtil.clearCache("Groups_Orgs");
277         }
278 
279         try {
280             clearPermissions.clear(group.getPrimaryKey());
281         }
282         catch (Exception e) {
283             throw processException(e);
284         }
285         finally {
286             FinderCacheUtil.clearCache("Groups_Permissions");
287         }
288 
289         try {
290             clearRoles.clear(group.getPrimaryKey());
291         }
292         catch (Exception e) {
293             throw processException(e);
294         }
295         finally {
296             FinderCacheUtil.clearCache("Groups_Roles");
297         }
298 
299         try {
300             clearUserGroups.clear(group.getPrimaryKey());
301         }
302         catch (Exception e) {
303             throw processException(e);
304         }
305         finally {
306             FinderCacheUtil.clearCache("Groups_UserGroups");
307         }
308 
309         try {
310             clearUsers.clear(group.getPrimaryKey());
311         }
312         catch (Exception e) {
313             throw processException(e);
314         }
315         finally {
316             FinderCacheUtil.clearCache("Users_Groups");
317         }
318 
319         Session session = null;
320 
321         try {
322             session = openSession();
323 
324             if (group.isCachedModel() || BatchSessionUtil.isEnabled()) {
325                 Object staleObject = session.get(GroupImpl.class,
326                         group.getPrimaryKeyObj());
327 
328                 if (staleObject != null) {
329                     session.evict(staleObject);
330                 }
331             }
332 
333             session.delete(group);
334 
335             session.flush();
336         }
337         catch (Exception e) {
338             throw processException(e);
339         }
340         finally {
341             closeSession(session);
342         }
343 
344         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
345 
346         GroupModelImpl groupModelImpl = (GroupModelImpl)group;
347 
348         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
349             new Object[] { new Long(groupModelImpl.getOriginalLiveGroupId()) });
350 
351         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
352             new Object[] {
353                 new Long(groupModelImpl.getOriginalCompanyId()),
354                 
355             groupModelImpl.getOriginalName()
356             });
357 
358         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F,
359             new Object[] {
360                 new Long(groupModelImpl.getOriginalCompanyId()),
361                 
362             groupModelImpl.getOriginalFriendlyURL()
363             });
364 
365         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
366             new Object[] {
367                 new Long(groupModelImpl.getOriginalCompanyId()),
368                 new Long(groupModelImpl.getOriginalClassNameId()),
369                 new Long(groupModelImpl.getOriginalClassPK())
370             });
371 
372         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N,
373             new Object[] {
374                 new Long(groupModelImpl.getOriginalCompanyId()),
375                 new Long(groupModelImpl.getOriginalLiveGroupId()),
376                 
377             groupModelImpl.getOriginalName()
378             });
379 
380         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N,
381             new Object[] {
382                 new Long(groupModelImpl.getOriginalCompanyId()),
383                 new Long(groupModelImpl.getOriginalClassNameId()),
384                 new Long(groupModelImpl.getOriginalLiveGroupId()),
385                 
386             groupModelImpl.getOriginalName()
387             });
388 
389         EntityCacheUtil.removeResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
390             GroupImpl.class, group.getPrimaryKey());
391 
392         return group;
393     }
394 
395     /**
396      * @deprecated Use <code>update(Group group, boolean merge)</code>.
397      */
398     public Group update(Group group) throws SystemException {
399         if (_log.isWarnEnabled()) {
400             _log.warn(
401                 "Using the deprecated update(Group group) method. Use update(Group group, boolean merge) instead.");
402         }
403 
404         return update(group, false);
405     }
406 
407     /**
408      * Add, update, or merge, the entity. This method also calls the model
409      * listeners to trigger the proper events associated with adding, deleting,
410      * or updating an entity.
411      *
412      * @param        group the entity to add, update, or merge
413      * @param        merge boolean value for whether to merge the entity. The
414      *                default value is false. Setting merge to true is more
415      *                expensive and should only be true when group is
416      *                transient. See LEP-5473 for a detailed discussion of this
417      *                method.
418      * @return        true if the portlet can be displayed via Ajax
419      */
420     public Group update(Group group, boolean merge) throws SystemException {
421         boolean isNew = group.isNew();
422 
423         for (ModelListener<Group> listener : listeners) {
424             if (isNew) {
425                 listener.onBeforeCreate(group);
426             }
427             else {
428                 listener.onBeforeUpdate(group);
429             }
430         }
431 
432         group = updateImpl(group, merge);
433 
434         for (ModelListener<Group> listener : listeners) {
435             if (isNew) {
436                 listener.onAfterCreate(group);
437             }
438             else {
439                 listener.onAfterUpdate(group);
440             }
441         }
442 
443         return group;
444     }
445 
446     public Group updateImpl(com.liferay.portal.model.Group group, boolean merge)
447         throws SystemException {
448         boolean isNew = group.isNew();
449 
450         GroupModelImpl groupModelImpl = (GroupModelImpl)group;
451 
452         Session session = null;
453 
454         try {
455             session = openSession();
456 
457             BatchSessionUtil.update(session, group, merge);
458 
459             group.setNew(false);
460         }
461         catch (Exception e) {
462             throw processException(e);
463         }
464         finally {
465             closeSession(session);
466         }
467 
468         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
469 
470         EntityCacheUtil.putResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
471             GroupImpl.class, group.getPrimaryKey(), group);
472 
473         if (!isNew &&
474                 (group.getLiveGroupId() != groupModelImpl.getOriginalLiveGroupId())) {
475             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
476                 new Object[] { new Long(groupModelImpl.getOriginalLiveGroupId()) });
477         }
478 
479         if (isNew ||
480                 (group.getLiveGroupId() != groupModelImpl.getOriginalLiveGroupId())) {
481             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
482                 new Object[] { new Long(group.getLiveGroupId()) }, group);
483         }
484 
485         if (!isNew &&
486                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
487                 !Validator.equals(group.getName(),
488                     groupModelImpl.getOriginalName()))) {
489             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
490                 new Object[] {
491                     new Long(groupModelImpl.getOriginalCompanyId()),
492                     
493                 groupModelImpl.getOriginalName()
494                 });
495         }
496 
497         if (isNew ||
498                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
499                 !Validator.equals(group.getName(),
500                     groupModelImpl.getOriginalName()))) {
501             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
502                 new Object[] { new Long(group.getCompanyId()), group.getName() },
503                 group);
504         }
505 
506         if (!isNew &&
507                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
508                 !Validator.equals(group.getFriendlyURL(),
509                     groupModelImpl.getOriginalFriendlyURL()))) {
510             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_F,
511                 new Object[] {
512                     new Long(groupModelImpl.getOriginalCompanyId()),
513                     
514                 groupModelImpl.getOriginalFriendlyURL()
515                 });
516         }
517 
518         if (isNew ||
519                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
520                 !Validator.equals(group.getFriendlyURL(),
521                     groupModelImpl.getOriginalFriendlyURL()))) {
522             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
523                 new Object[] {
524                     new Long(group.getCompanyId()),
525                     
526                 group.getFriendlyURL()
527                 }, group);
528         }
529 
530         if (!isNew &&
531                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
532                 (group.getClassNameId() != groupModelImpl.getOriginalClassNameId()) ||
533                 (group.getClassPK() != groupModelImpl.getOriginalClassPK()))) {
534             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
535                 new Object[] {
536                     new Long(groupModelImpl.getOriginalCompanyId()),
537                     new Long(groupModelImpl.getOriginalClassNameId()),
538                     new Long(groupModelImpl.getOriginalClassPK())
539                 });
540         }
541 
542         if (isNew ||
543                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
544                 (group.getClassNameId() != groupModelImpl.getOriginalClassNameId()) ||
545                 (group.getClassPK() != groupModelImpl.getOriginalClassPK()))) {
546             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
547                 new Object[] {
548                     new Long(group.getCompanyId()),
549                     new Long(group.getClassNameId()),
550                     new Long(group.getClassPK())
551                 }, group);
552         }
553 
554         if (!isNew &&
555                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
556                 (group.getLiveGroupId() != groupModelImpl.getOriginalLiveGroupId()) ||
557                 !Validator.equals(group.getName(),
558                     groupModelImpl.getOriginalName()))) {
559             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L_N,
560                 new Object[] {
561                     new Long(groupModelImpl.getOriginalCompanyId()),
562                     new Long(groupModelImpl.getOriginalLiveGroupId()),
563                     
564                 groupModelImpl.getOriginalName()
565                 });
566         }
567 
568         if (isNew ||
569                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
570                 (group.getLiveGroupId() != groupModelImpl.getOriginalLiveGroupId()) ||
571                 !Validator.equals(group.getName(),
572                     groupModelImpl.getOriginalName()))) {
573             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
574                 new Object[] {
575                     new Long(group.getCompanyId()),
576                     new Long(group.getLiveGroupId()),
577                     
578                 group.getName()
579                 }, group);
580         }
581 
582         if (!isNew &&
583                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
584                 (group.getClassNameId() != groupModelImpl.getOriginalClassNameId()) ||
585                 (group.getLiveGroupId() != groupModelImpl.getOriginalLiveGroupId()) ||
586                 !Validator.equals(group.getName(),
587                     groupModelImpl.getOriginalName()))) {
588             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_L_N,
589                 new Object[] {
590                     new Long(groupModelImpl.getOriginalCompanyId()),
591                     new Long(groupModelImpl.getOriginalClassNameId()),
592                     new Long(groupModelImpl.getOriginalLiveGroupId()),
593                     
594                 groupModelImpl.getOriginalName()
595                 });
596         }
597 
598         if (isNew ||
599                 ((group.getCompanyId() != groupModelImpl.getOriginalCompanyId()) ||
600                 (group.getClassNameId() != groupModelImpl.getOriginalClassNameId()) ||
601                 (group.getLiveGroupId() != groupModelImpl.getOriginalLiveGroupId()) ||
602                 !Validator.equals(group.getName(),
603                     groupModelImpl.getOriginalName()))) {
604             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
605                 new Object[] {
606                     new Long(group.getCompanyId()),
607                     new Long(group.getClassNameId()),
608                     new Long(group.getLiveGroupId()),
609                     
610                 group.getName()
611                 }, group);
612         }
613 
614         return group;
615     }
616 
617     public Group findByPrimaryKey(long groupId)
618         throws NoSuchGroupException, SystemException {
619         Group group = fetchByPrimaryKey(groupId);
620 
621         if (group == null) {
622             if (_log.isWarnEnabled()) {
623                 _log.warn("No Group exists with the primary key " + groupId);
624             }
625 
626             throw new NoSuchGroupException(
627                 "No Group exists with the primary key " + groupId);
628         }
629 
630         return group;
631     }
632 
633     public Group fetchByPrimaryKey(long groupId) throws SystemException {
634         Group group = (Group)EntityCacheUtil.getResult(GroupModelImpl.ENTITY_CACHE_ENABLED,
635                 GroupImpl.class, groupId, this);
636 
637         if (group == null) {
638             Session session = null;
639 
640             try {
641                 session = openSession();
642 
643                 group = (Group)session.get(GroupImpl.class, new Long(groupId));
644             }
645             catch (Exception e) {
646                 throw processException(e);
647             }
648             finally {
649                 if (group != null) {
650                     cacheResult(group);
651                 }
652 
653                 closeSession(session);
654             }
655         }
656 
657         return group;
658     }
659 
660     public Group findByLiveGroupId(long liveGroupId)
661         throws NoSuchGroupException, SystemException {
662         Group group = fetchByLiveGroupId(liveGroupId);
663 
664         if (group == null) {
665             StringBuilder msg = new StringBuilder();
666 
667             msg.append("No Group exists with the key {");
668 
669             msg.append("liveGroupId=" + liveGroupId);
670 
671             msg.append(StringPool.CLOSE_CURLY_BRACE);
672 
673             if (_log.isWarnEnabled()) {
674                 _log.warn(msg.toString());
675             }
676 
677             throw new NoSuchGroupException(msg.toString());
678         }
679 
680         return group;
681     }
682 
683     public Group fetchByLiveGroupId(long liveGroupId) throws SystemException {
684         return fetchByLiveGroupId(liveGroupId, true);
685     }
686 
687     public Group fetchByLiveGroupId(long liveGroupId, boolean retrieveFromCache)
688         throws SystemException {
689         Object[] finderArgs = new Object[] { new Long(liveGroupId) };
690 
691         Object result = null;
692 
693         if (retrieveFromCache) {
694             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
695                     finderArgs, this);
696         }
697 
698         if (result == null) {
699             Session session = null;
700 
701             try {
702                 session = openSession();
703 
704                 StringBuilder query = new StringBuilder();
705 
706                 query.append("FROM com.liferay.portal.model.Group WHERE ");
707 
708                 query.append("liveGroupId = ?");
709 
710                 query.append(" ");
711 
712                 query.append("ORDER BY ");
713 
714                 query.append("name ASC");
715 
716                 Query q = session.createQuery(query.toString());
717 
718                 QueryPos qPos = QueryPos.getInstance(q);
719 
720                 qPos.add(liveGroupId);
721 
722                 List<Group> list = q.list();
723 
724                 result = list;
725 
726                 Group group = null;
727 
728                 if (list.isEmpty()) {
729                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
730                         finderArgs, list);
731                 }
732                 else {
733                     group = list.get(0);
734 
735                     cacheResult(group);
736 
737                     if ((group.getLiveGroupId() != liveGroupId)) {
738                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
739                             finderArgs, group);
740                     }
741                 }
742 
743                 return group;
744             }
745             catch (Exception e) {
746                 throw processException(e);
747             }
748             finally {
749                 if (result == null) {
750                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_LIVEGROUPID,
751                         finderArgs, new ArrayList<Group>());
752                 }
753 
754                 closeSession(session);
755             }
756         }
757         else {
758             if (result instanceof List) {
759                 return null;
760             }
761             else {
762                 return (Group)result;
763             }
764         }
765     }
766 
767     public Group findByC_N(long companyId, String name)
768         throws NoSuchGroupException, SystemException {
769         Group group = fetchByC_N(companyId, name);
770 
771         if (group == null) {
772             StringBuilder msg = new StringBuilder();
773 
774             msg.append("No Group exists with the key {");
775 
776             msg.append("companyId=" + companyId);
777 
778             msg.append(", ");
779             msg.append("name=" + name);
780 
781             msg.append(StringPool.CLOSE_CURLY_BRACE);
782 
783             if (_log.isWarnEnabled()) {
784                 _log.warn(msg.toString());
785             }
786 
787             throw new NoSuchGroupException(msg.toString());
788         }
789 
790         return group;
791     }
792 
793     public Group fetchByC_N(long companyId, String name)
794         throws SystemException {
795         return fetchByC_N(companyId, name, true);
796     }
797 
798     public Group fetchByC_N(long companyId, String name,
799         boolean retrieveFromCache) throws SystemException {
800         Object[] finderArgs = new Object[] { new Long(companyId), name };
801 
802         Object result = null;
803 
804         if (retrieveFromCache) {
805             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
806                     finderArgs, this);
807         }
808 
809         if (result == null) {
810             Session session = null;
811 
812             try {
813                 session = openSession();
814 
815                 StringBuilder query = new StringBuilder();
816 
817                 query.append("FROM com.liferay.portal.model.Group WHERE ");
818 
819                 query.append("companyId = ?");
820 
821                 query.append(" AND ");
822 
823                 if (name == null) {
824                     query.append("name IS NULL");
825                 }
826                 else {
827                     query.append("name = ?");
828                 }
829 
830                 query.append(" ");
831 
832                 query.append("ORDER BY ");
833 
834                 query.append("name ASC");
835 
836                 Query q = session.createQuery(query.toString());
837 
838                 QueryPos qPos = QueryPos.getInstance(q);
839 
840                 qPos.add(companyId);
841 
842                 if (name != null) {
843                     qPos.add(name);
844                 }
845 
846                 List<Group> list = q.list();
847 
848                 result = list;
849 
850                 Group group = null;
851 
852                 if (list.isEmpty()) {
853                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
854                         finderArgs, list);
855                 }
856                 else {
857                     group = list.get(0);
858 
859                     cacheResult(group);
860 
861                     if ((group.getCompanyId() != companyId) ||
862                             (group.getName() == null) ||
863                             !group.getName().equals(name)) {
864                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
865                             finderArgs, group);
866                     }
867                 }
868 
869                 return group;
870             }
871             catch (Exception e) {
872                 throw processException(e);
873             }
874             finally {
875                 if (result == null) {
876                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
877                         finderArgs, new ArrayList<Group>());
878                 }
879 
880                 closeSession(session);
881             }
882         }
883         else {
884             if (result instanceof List) {
885                 return null;
886             }
887             else {
888                 return (Group)result;
889             }
890         }
891     }
892 
893     public Group findByC_F(long companyId, String friendlyURL)
894         throws NoSuchGroupException, SystemException {
895         Group group = fetchByC_F(companyId, friendlyURL);
896 
897         if (group == null) {
898             StringBuilder msg = new StringBuilder();
899 
900             msg.append("No Group exists with the key {");
901 
902             msg.append("companyId=" + companyId);
903 
904             msg.append(", ");
905             msg.append("friendlyURL=" + friendlyURL);
906 
907             msg.append(StringPool.CLOSE_CURLY_BRACE);
908 
909             if (_log.isWarnEnabled()) {
910                 _log.warn(msg.toString());
911             }
912 
913             throw new NoSuchGroupException(msg.toString());
914         }
915 
916         return group;
917     }
918 
919     public Group fetchByC_F(long companyId, String friendlyURL)
920         throws SystemException {
921         return fetchByC_F(companyId, friendlyURL, true);
922     }
923 
924     public Group fetchByC_F(long companyId, String friendlyURL,
925         boolean retrieveFromCache) throws SystemException {
926         Object[] finderArgs = new Object[] { new Long(companyId), friendlyURL };
927 
928         Object result = null;
929 
930         if (retrieveFromCache) {
931             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_F,
932                     finderArgs, this);
933         }
934 
935         if (result == null) {
936             Session session = null;
937 
938             try {
939                 session = openSession();
940 
941                 StringBuilder query = new StringBuilder();
942 
943                 query.append("FROM com.liferay.portal.model.Group WHERE ");
944 
945                 query.append("companyId = ?");
946 
947                 query.append(" AND ");
948 
949                 if (friendlyURL == null) {
950                     query.append("friendlyURL IS NULL");
951                 }
952                 else {
953                     query.append("friendlyURL = ?");
954                 }
955 
956                 query.append(" ");
957 
958                 query.append("ORDER BY ");
959 
960                 query.append("name ASC");
961 
962                 Query q = session.createQuery(query.toString());
963 
964                 QueryPos qPos = QueryPos.getInstance(q);
965 
966                 qPos.add(companyId);
967 
968                 if (friendlyURL != null) {
969                     qPos.add(friendlyURL);
970                 }
971 
972                 List<Group> list = q.list();
973 
974                 result = list;
975 
976                 Group group = null;
977 
978                 if (list.isEmpty()) {
979                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
980                         finderArgs, list);
981                 }
982                 else {
983                     group = list.get(0);
984 
985                     cacheResult(group);
986 
987                     if ((group.getCompanyId() != companyId) ||
988                             (group.getFriendlyURL() == null) ||
989                             !group.getFriendlyURL().equals(friendlyURL)) {
990                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
991                             finderArgs, group);
992                     }
993                 }
994 
995                 return group;
996             }
997             catch (Exception e) {
998                 throw processException(e);
999             }
1000            finally {
1001                if (result == null) {
1002                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_F,
1003                        finderArgs, new ArrayList<Group>());
1004                }
1005
1006                closeSession(session);
1007            }
1008        }
1009        else {
1010            if (result instanceof List) {
1011                return null;
1012            }
1013            else {
1014                return (Group)result;
1015            }
1016        }
1017    }
1018
1019    public List<Group> findByT_A(int type, boolean active)
1020        throws SystemException {
1021        Object[] finderArgs = new Object[] {
1022                new Integer(type), Boolean.valueOf(active)
1023            };
1024
1025        List<Group> list = (List<Group>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_A,
1026                finderArgs, this);
1027
1028        if (list == null) {
1029            Session session = null;
1030
1031            try {
1032                session = openSession();
1033
1034                StringBuilder query = new StringBuilder();
1035
1036                query.append("FROM com.liferay.portal.model.Group WHERE ");
1037
1038                query.append("type_ = ?");
1039
1040                query.append(" AND ");
1041
1042                query.append("active_ = ?");
1043
1044                query.append(" ");
1045
1046                query.append("ORDER BY ");
1047
1048                query.append("name ASC");
1049
1050                Query q = session.createQuery(query.toString());
1051
1052                QueryPos qPos = QueryPos.getInstance(q);
1053
1054                qPos.add(type);
1055
1056                qPos.add(active);
1057
1058                list = q.list();
1059            }
1060            catch (Exception e) {
1061                throw processException(e);
1062            }
1063            finally {
1064                if (list == null) {
1065                    list = new ArrayList<Group>();
1066                }
1067
1068                cacheResult(list);
1069
1070                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_A, finderArgs,
1071                    list);
1072
1073                closeSession(session);
1074            }
1075        }
1076
1077        return list;
1078    }
1079
1080    public List<Group> findByT_A(int type, boolean active, int start, int end)
1081        throws SystemException {
1082        return findByT_A(type, active, start, end, null);
1083    }
1084
1085    public List<Group> findByT_A(int type, boolean active, int start, int end,
1086        OrderByComparator obc) throws SystemException {
1087        Object[] finderArgs = new Object[] {
1088                new Integer(type), Boolean.valueOf(active),
1089                
1090                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1091            };
1092
1093        List<Group> list = (List<Group>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_T_A,
1094                finderArgs, this);
1095
1096        if (list == null) {
1097            Session session = null;
1098
1099            try {
1100                session = openSession();
1101
1102                StringBuilder query = new StringBuilder();
1103
1104                query.append("FROM com.liferay.portal.model.Group WHERE ");
1105
1106                query.append("type_ = ?");
1107
1108                query.append(" AND ");
1109
1110                query.append("active_ = ?");
1111
1112                query.append(" ");
1113
1114                if (obc != null) {
1115                    query.append("ORDER BY ");
1116                    query.append(obc.getOrderBy());
1117                }
1118
1119                else {
1120                    query.append("ORDER BY ");
1121
1122                    query.append("name ASC");
1123                }
1124
1125                Query q = session.createQuery(query.toString());
1126
1127                QueryPos qPos = QueryPos.getInstance(q);
1128
1129                qPos.add(type);
1130
1131                qPos.add(active);
1132
1133                list = (List<Group>)QueryUtil.list(q, getDialect(), start, end);
1134            }
1135            catch (Exception e) {
1136                throw processException(e);
1137            }
1138            finally {
1139                if (list == null) {
1140                    list = new ArrayList<Group>();
1141                }
1142
1143                cacheResult(list);
1144
1145                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_T_A,
1146                    finderArgs, list);
1147
1148                closeSession(session);
1149            }
1150        }
1151
1152        return list;
1153    }
1154
1155    public Group findByT_A_First(int type, boolean active, OrderByComparator obc)
1156        throws NoSuchGroupException, SystemException {
1157        List<Group> list = findByT_A(type, active, 0, 1, obc);
1158
1159        if (list.isEmpty()) {
1160            StringBuilder msg = new StringBuilder();
1161
1162            msg.append("No Group exists with the key {");
1163
1164            msg.append("type=" + type);
1165
1166            msg.append(", ");
1167            msg.append("active=" + active);
1168
1169            msg.append(StringPool.CLOSE_CURLY_BRACE);
1170
1171            throw new NoSuchGroupException(msg.toString());
1172        }
1173        else {
1174            return list.get(0);
1175        }
1176    }
1177
1178    public Group findByT_A_Last(int type, boolean active, OrderByComparator obc)
1179        throws NoSuchGroupException, SystemException {
1180        int count = countByT_A(type, active);
1181
1182        List<Group> list = findByT_A(type, active, count - 1, count, obc);
1183
1184        if (list.isEmpty()) {
1185            StringBuilder msg = new StringBuilder();
1186
1187            msg.append("No Group exists with the key {");
1188
1189            msg.append("type=" + type);
1190
1191            msg.append(", ");
1192            msg.append("active=" + active);
1193
1194            msg.append(StringPool.CLOSE_CURLY_BRACE);
1195
1196            throw new NoSuchGroupException(msg.toString());
1197        }
1198        else {
1199            return list.get(0);
1200        }
1201    }
1202
1203    public Group[] findByT_A_PrevAndNext(long groupId, int type,
1204        boolean active, OrderByComparator obc)
1205        throws NoSuchGroupException, SystemException {
1206        Group group = findByPrimaryKey(groupId);
1207
1208        int count = countByT_A(type, active);
1209
1210        Session session = null;
1211
1212        try {
1213            session = openSession();
1214
1215            StringBuilder query = new StringBuilder();
1216
1217            query.append("FROM com.liferay.portal.model.Group WHERE ");
1218
1219            query.append("type_ = ?");
1220
1221            query.append(" AND ");
1222
1223            query.append("active_ = ?");
1224
1225            query.append(" ");
1226
1227            if (obc != null) {
1228                query.append("ORDER BY ");
1229                query.append(obc.getOrderBy());
1230            }
1231
1232            else {
1233                query.append("ORDER BY ");
1234
1235                query.append("name ASC");
1236            }
1237
1238            Query q = session.createQuery(query.toString());
1239
1240            QueryPos qPos = QueryPos.getInstance(q);
1241
1242            qPos.add(type);
1243
1244            qPos.add(active);
1245
1246            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, group);
1247
1248            Group[] array = new GroupImpl[3];
1249
1250            array[0] = (Group)objArray[0];
1251            array[1] = (Group)objArray[1];
1252            array[2] = (Group)objArray[2];
1253
1254            return array;
1255        }
1256        catch (Exception e) {
1257            throw processException(e);
1258        }
1259        finally {
1260            closeSession(session);
1261        }
1262    }
1263
1264    public Group findByC_C_C(long companyId, long classNameId, long classPK)
1265        throws NoSuchGroupException, SystemException {
1266        Group group = fetchByC_C_C(companyId, classNameId, classPK);
1267
1268        if (group == null) {
1269            StringBuilder msg = new StringBuilder();
1270
1271            msg.append("No Group exists with the key {");
1272
1273            msg.append("companyId=" + companyId);
1274
1275            msg.append(", ");
1276            msg.append("classNameId=" + classNameId);
1277
1278            msg.append(", ");
1279            msg.append("classPK=" + classPK);
1280
1281            msg.append(StringPool.CLOSE_CURLY_BRACE);
1282
1283            if (_log.isWarnEnabled()) {
1284                _log.warn(msg.toString());
1285            }
1286
1287            throw new NoSuchGroupException(msg.toString());
1288        }
1289
1290        return group;
1291    }
1292
1293    public Group fetchByC_C_C(long companyId, long classNameId, long classPK)
1294        throws SystemException {
1295        return fetchByC_C_C(companyId, classNameId, classPK, true);
1296    }
1297
1298    public Group fetchByC_C_C(long companyId, long classNameId, long classPK,
1299        boolean retrieveFromCache) throws SystemException {
1300        Object[] finderArgs = new Object[] {
1301                new Long(companyId), new Long(classNameId), new Long(classPK)
1302            };
1303
1304        Object result = null;
1305
1306        if (retrieveFromCache) {
1307            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
1308                    finderArgs, this);
1309        }
1310
1311        if (result == null) {
1312            Session session = null;
1313
1314            try {
1315                session = openSession();
1316
1317                StringBuilder query = new StringBuilder();
1318
1319                query.append("FROM com.liferay.portal.model.Group WHERE ");
1320
1321                query.append("companyId = ?");
1322
1323                query.append(" AND ");
1324
1325                query.append("classNameId = ?");
1326
1327                query.append(" AND ");
1328
1329                query.append("classPK = ?");
1330
1331                query.append(" ");
1332
1333                query.append("ORDER BY ");
1334
1335                query.append("name ASC");
1336
1337                Query q = session.createQuery(query.toString());
1338
1339                QueryPos qPos = QueryPos.getInstance(q);
1340
1341                qPos.add(companyId);
1342
1343                qPos.add(classNameId);
1344
1345                qPos.add(classPK);
1346
1347                List<Group> list = q.list();
1348
1349                result = list;
1350
1351                Group group = null;
1352
1353                if (list.isEmpty()) {
1354                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1355                        finderArgs, list);
1356                }
1357                else {
1358                    group = list.get(0);
1359
1360                    cacheResult(group);
1361
1362                    if ((group.getCompanyId() != companyId) ||
1363                            (group.getClassNameId() != classNameId) ||
1364                            (group.getClassPK() != classPK)) {
1365                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1366                            finderArgs, group);
1367                    }
1368                }
1369
1370                return group;
1371            }
1372            catch (Exception e) {
1373                throw processException(e);
1374            }
1375            finally {
1376                if (result == null) {
1377                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1378                        finderArgs, new ArrayList<Group>());
1379                }
1380
1381                closeSession(session);
1382            }
1383        }
1384        else {
1385            if (result instanceof List) {
1386                return null;
1387            }
1388            else {
1389                return (Group)result;
1390            }
1391        }
1392    }
1393
1394    public Group findByC_L_N(long companyId, long liveGroupId, String name)
1395        throws NoSuchGroupException, SystemException {
1396        Group group = fetchByC_L_N(companyId, liveGroupId, name);
1397
1398        if (group == null) {
1399            StringBuilder msg = new StringBuilder();
1400
1401            msg.append("No Group exists with the key {");
1402
1403            msg.append("companyId=" + companyId);
1404
1405            msg.append(", ");
1406            msg.append("liveGroupId=" + liveGroupId);
1407
1408            msg.append(", ");
1409            msg.append("name=" + name);
1410
1411            msg.append(StringPool.CLOSE_CURLY_BRACE);
1412
1413            if (_log.isWarnEnabled()) {
1414                _log.warn(msg.toString());
1415            }
1416
1417            throw new NoSuchGroupException(msg.toString());
1418        }
1419
1420        return group;
1421    }
1422
1423    public Group fetchByC_L_N(long companyId, long liveGroupId, String name)
1424        throws SystemException {
1425        return fetchByC_L_N(companyId, liveGroupId, name, true);
1426    }
1427
1428    public Group fetchByC_L_N(long companyId, long liveGroupId, String name,
1429        boolean retrieveFromCache) throws SystemException {
1430        Object[] finderArgs = new Object[] {
1431                new Long(companyId), new Long(liveGroupId),
1432                
1433                name
1434            };
1435
1436        Object result = null;
1437
1438        if (retrieveFromCache) {
1439            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_L_N,
1440                    finderArgs, this);
1441        }
1442
1443        if (result == null) {
1444            Session session = null;
1445
1446            try {
1447                session = openSession();
1448
1449                StringBuilder query = new StringBuilder();
1450
1451                query.append("FROM com.liferay.portal.model.Group WHERE ");
1452
1453                query.append("companyId = ?");
1454
1455                query.append(" AND ");
1456
1457                query.append("liveGroupId = ?");
1458
1459                query.append(" AND ");
1460
1461                if (name == null) {
1462                    query.append("name IS NULL");
1463                }
1464                else {
1465                    query.append("name = ?");
1466                }
1467
1468                query.append(" ");
1469
1470                query.append("ORDER BY ");
1471
1472                query.append("name ASC");
1473
1474                Query q = session.createQuery(query.toString());
1475
1476                QueryPos qPos = QueryPos.getInstance(q);
1477
1478                qPos.add(companyId);
1479
1480                qPos.add(liveGroupId);
1481
1482                if (name != null) {
1483                    qPos.add(name);
1484                }
1485
1486                List<Group> list = q.list();
1487
1488                result = list;
1489
1490                Group group = null;
1491
1492                if (list.isEmpty()) {
1493                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
1494                        finderArgs, list);
1495                }
1496                else {
1497                    group = list.get(0);
1498
1499                    cacheResult(group);
1500
1501                    if ((group.getCompanyId() != companyId) ||
1502                            (group.getLiveGroupId() != liveGroupId) ||
1503                            (group.getName() == null) ||
1504                            !group.getName().equals(name)) {
1505                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
1506                            finderArgs, group);
1507                    }
1508                }
1509
1510                return group;
1511            }
1512            catch (Exception e) {
1513                throw processException(e);
1514            }
1515            finally {
1516                if (result == null) {
1517                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L_N,
1518                        finderArgs, new ArrayList<Group>());
1519                }
1520
1521                closeSession(session);
1522            }
1523        }
1524        else {
1525            if (result instanceof List) {
1526                return null;
1527            }
1528            else {
1529                return (Group)result;
1530            }
1531        }
1532    }
1533
1534    public Group findByC_C_L_N(long companyId, long classNameId,
1535        long liveGroupId, String name)
1536        throws NoSuchGroupException, SystemException {
1537        Group group = fetchByC_C_L_N(companyId, classNameId, liveGroupId, name);
1538
1539        if (group == null) {
1540            StringBuilder msg = new StringBuilder();
1541
1542            msg.append("No Group exists with the key {");
1543
1544            msg.append("companyId=" + companyId);
1545
1546            msg.append(", ");
1547            msg.append("classNameId=" + classNameId);
1548
1549            msg.append(", ");
1550            msg.append("liveGroupId=" + liveGroupId);
1551
1552            msg.append(", ");
1553            msg.append("name=" + name);
1554
1555            msg.append(StringPool.CLOSE_CURLY_BRACE);
1556
1557            if (_log.isWarnEnabled()) {
1558                _log.warn(msg.toString());
1559            }
1560
1561            throw new NoSuchGroupException(msg.toString());
1562        }
1563
1564        return group;
1565    }
1566
1567    public Group fetchByC_C_L_N(long companyId, long classNameId,
1568        long liveGroupId, String name) throws SystemException {
1569        return fetchByC_C_L_N(companyId, classNameId, liveGroupId, name, true);
1570    }
1571
1572    public Group fetchByC_C_L_N(long companyId, long classNameId,
1573        long liveGroupId, String name, boolean retrieveFromCache)
1574        throws SystemException {
1575        Object[] finderArgs = new Object[] {
1576                new Long(companyId), new Long(classNameId),
1577                new Long(liveGroupId),
1578                
1579                name
1580            };
1581
1582        Object result = null;
1583
1584        if (retrieveFromCache) {
1585            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_L_N,
1586                    finderArgs, this);
1587        }
1588
1589        if (result == null) {
1590            Session session = null;
1591
1592            try {
1593                session = openSession();
1594
1595                StringBuilder query = new StringBuilder();
1596
1597                query.append("FROM com.liferay.portal.model.Group WHERE ");
1598
1599                query.append("companyId = ?");
1600
1601                query.append(" AND ");
1602
1603                query.append("classNameId = ?");
1604
1605                query.append(" AND ");
1606
1607                query.append("liveGroupId = ?");
1608
1609                query.append(" AND ");
1610
1611                if (name == null) {
1612                    query.append("name IS NULL");
1613                }
1614                else {
1615                    query.append("name = ?");
1616                }
1617
1618                query.append(" ");
1619
1620                query.append("ORDER BY ");
1621
1622                query.append("name ASC");
1623
1624                Query q = session.createQuery(query.toString());
1625
1626                QueryPos qPos = QueryPos.getInstance(q);
1627
1628                qPos.add(companyId);
1629
1630                qPos.add(classNameId);
1631
1632                qPos.add(liveGroupId);
1633
1634                if (name != null) {
1635                    qPos.add(name);
1636                }
1637
1638                List<Group> list = q.list();
1639
1640                result = list;
1641
1642                Group group = null;
1643
1644                if (list.isEmpty()) {
1645                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
1646                        finderArgs, list);
1647                }
1648                else {
1649                    group = list.get(0);
1650
1651                    cacheResult(group);
1652
1653                    if ((group.getCompanyId() != companyId) ||
1654                            (group.getClassNameId() != classNameId) ||
1655                            (group.getLiveGroupId() != liveGroupId) ||
1656                            (group.getName() == null) ||
1657                            !group.getName().equals(name)) {
1658                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
1659                            finderArgs, group);
1660                    }
1661                }
1662
1663                return group;
1664            }
1665            catch (Exception e) {
1666                throw processException(e);
1667            }
1668            finally {
1669                if (result == null) {
1670                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_L_N,
1671                        finderArgs, new ArrayList<Group>());
1672                }
1673
1674                closeSession(session);
1675            }
1676        }
1677        else {
1678            if (result instanceof List) {
1679                return null;
1680            }
1681            else {
1682                return (Group)result;
1683            }
1684        }
1685    }
1686
1687    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1688        throws SystemException {
1689        Session session = null;
1690
1691        try {
1692            session = openSession();
1693
1694            dynamicQuery.compile(session);
1695
1696            return dynamicQuery.list();
1697        }
1698        catch (Exception e) {
1699            throw processException(e);
1700        }
1701        finally {
1702            closeSession(session);
1703        }
1704    }
1705
1706    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1707        int start, int end) throws SystemException {
1708        Session session = null;
1709
1710        try {
1711            session = openSession();
1712
1713            dynamicQuery.setLimit(start, end);
1714
1715            dynamicQuery.compile(session);
1716
1717            return dynamicQuery.list();
1718        }
1719        catch (Exception e) {
1720            throw processException(e);
1721        }
1722        finally {
1723            closeSession(session);
1724        }
1725    }
1726
1727    public List<Group> findAll() throws SystemException {
1728        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1729    }
1730
1731    public List<Group> findAll(int start, int end) throws SystemException {
1732        return findAll(start, end, null);
1733    }
1734
1735    public List<Group> findAll(int start, int end, OrderByComparator obc)
1736        throws SystemException {
1737        Object[] finderArgs = new Object[] {
1738                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1739            };
1740
1741        List<Group> list = (List<Group>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1742                finderArgs, this);
1743
1744        if (list == null) {
1745            Session session = null;
1746
1747            try {
1748                session = openSession();
1749
1750                StringBuilder query = new StringBuilder();
1751
1752                query.append("FROM com.liferay.portal.model.Group ");
1753
1754                if (obc != null) {
1755                    query.append("ORDER BY ");
1756                    query.append(obc.getOrderBy());
1757                }
1758
1759                else {
1760                    query.append("ORDER BY ");
1761
1762                    query.append("name ASC");
1763                }
1764
1765                Query q = session.createQuery(query.toString());
1766
1767                if (obc == null) {
1768                    list = (List<Group>)QueryUtil.list(q, getDialect(), start,
1769                            end, false);
1770
1771                    Collections.sort(list);
1772                }
1773                else {
1774                    list = (List<Group>)QueryUtil.list(q, getDialect(), start,
1775                            end);
1776                }
1777            }
1778            catch (Exception e) {
1779                throw processException(e);
1780            }
1781            finally {
1782                if (list == null) {
1783                    list = new ArrayList<Group>();
1784                }
1785
1786                cacheResult(list);
1787
1788                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1789
1790                closeSession(session);
1791            }
1792        }
1793
1794        return list;
1795    }
1796
1797    public void removeByLiveGroupId(long liveGroupId)
1798        throws NoSuchGroupException, SystemException {
1799        Group group = findByLiveGroupId(liveGroupId);
1800
1801        remove(group);
1802    }
1803
1804    public void removeByC_N(long companyId, String name)
1805        throws NoSuchGroupException, SystemException {
1806        Group group = findByC_N(companyId, name);
1807
1808        remove(group);
1809    }
1810
1811    public void removeByC_F(long companyId, String friendlyURL)
1812        throws NoSuchGroupException, SystemException {
1813        Group group = findByC_F(companyId, friendlyURL);
1814
1815        remove(group);
1816    }
1817
1818    public void removeByT_A(int type, boolean active) throws SystemException {
1819        for (Group group : findByT_A(type, active)) {
1820            remove(group);
1821        }
1822    }
1823
1824    public void removeByC_C_C(long companyId, long classNameId, long classPK)
1825        throws NoSuchGroupException, SystemException {
1826        Group group = findByC_C_C(companyId, classNameId, classPK);
1827
1828        remove(group);
1829    }
1830
1831    public void removeByC_L_N(long companyId, long liveGroupId, String name)
1832        throws NoSuchGroupException, SystemException {
1833        Group group = findByC_L_N(companyId, liveGroupId, name);
1834
1835        remove(group);
1836    }
1837
1838    public void removeByC_C_L_N(long companyId, long classNameId,
1839        long liveGroupId, String name)
1840        throws NoSuchGroupException, SystemException {
1841        Group group = findByC_C_L_N(companyId, classNameId, liveGroupId, name);
1842
1843        remove(group);
1844    }
1845
1846    public void removeAll() throws SystemException {
1847        for (Group group : findAll()) {
1848            remove(group);
1849        }
1850    }
1851
1852    public int countByLiveGroupId(long liveGroupId) throws SystemException {
1853        Object[] finderArgs = new Object[] { new Long(liveGroupId) };
1854
1855        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_LIVEGROUPID,
1856                finderArgs, this);
1857
1858        if (count == null) {
1859            Session session = null;
1860
1861            try {
1862                session = openSession();
1863
1864                StringBuilder query = new StringBuilder();
1865
1866                query.append("SELECT COUNT(*) ");
1867                query.append("FROM com.liferay.portal.model.Group WHERE ");
1868
1869                query.append("liveGroupId = ?");
1870
1871                query.append(" ");
1872
1873                Query q = session.createQuery(query.toString());
1874
1875                QueryPos qPos = QueryPos.getInstance(q);
1876
1877                qPos.add(liveGroupId);
1878
1879                count = (Long)q.uniqueResult();
1880            }
1881            catch (Exception e) {
1882                throw processException(e);
1883            }
1884            finally {
1885                if (count == null) {
1886                    count = Long.valueOf(0);
1887                }
1888
1889                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_LIVEGROUPID,
1890                    finderArgs, count);
1891
1892                closeSession(session);
1893            }
1894        }
1895
1896        return count.intValue();
1897    }
1898
1899    public int countByC_N(long companyId, String name)
1900        throws SystemException {
1901        Object[] finderArgs = new Object[] { new Long(companyId), name };
1902
1903        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
1904                finderArgs, this);
1905
1906        if (count == null) {
1907            Session session = null;
1908
1909            try {
1910                session = openSession();
1911
1912                StringBuilder query = new StringBuilder();
1913
1914                query.append("SELECT COUNT(*) ");
1915                query.append("FROM com.liferay.portal.model.Group WHERE ");
1916
1917                query.append("companyId = ?");
1918
1919                query.append(" AND ");
1920
1921                if (name == null) {
1922                    query.append("name IS NULL");
1923                }
1924                else {
1925                    query.append("name = ?");
1926                }
1927
1928                query.append(" ");
1929
1930                Query q = session.createQuery(query.toString());
1931
1932                QueryPos qPos = QueryPos.getInstance(q);
1933
1934                qPos.add(companyId);
1935
1936                if (name != null) {
1937                    qPos.add(name);
1938                }
1939
1940                count = (Long)q.uniqueResult();
1941            }
1942            catch (Exception e) {
1943                throw processException(e);
1944            }
1945            finally {
1946                if (count == null) {
1947                    count = Long.valueOf(0);
1948                }
1949
1950                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
1951                    count);
1952
1953                closeSession(session);
1954            }
1955        }
1956
1957        return count.intValue();
1958    }
1959
1960    public int countByC_F(long companyId, String friendlyURL)
1961        throws SystemException {
1962        Object[] finderArgs = new Object[] { new Long(companyId), friendlyURL };
1963
1964        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_F,
1965                finderArgs, this);
1966
1967        if (count == null) {
1968            Session session = null;
1969
1970            try {
1971                session = openSession();
1972
1973                StringBuilder query = new StringBuilder();
1974
1975                query.append("SELECT COUNT(*) ");
1976                query.append("FROM com.liferay.portal.model.Group WHERE ");
1977
1978                query.append("companyId = ?");
1979
1980                query.append(" AND ");
1981
1982                if (friendlyURL == null) {
1983                    query.append("friendlyURL IS NULL");
1984                }
1985                else {
1986                    query.append("friendlyURL = ?");
1987                }
1988
1989                query.append(" ");
1990
1991                Query q = session.createQuery(query.toString());
1992
1993                QueryPos qPos = QueryPos.getInstance(q);
1994
1995                qPos.add(companyId);
1996
1997                if (friendlyURL != null) {
1998                    qPos.add(friendlyURL);
1999                }
2000
2001                count = (Long)q.uniqueResult();
2002            }
2003            catch (Exception e) {
2004                throw processException(e);
2005            }
2006            finally {
2007                if (count == null) {
2008                    count = Long.valueOf(0);
2009                }
2010
2011                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_F, finderArgs,
2012                    count);
2013
2014                closeSession(session);
2015            }
2016        }
2017
2018        return count.intValue();
2019    }
2020
2021    public int countByT_A(int type, boolean active) throws SystemException {
2022        Object[] finderArgs = new Object[] {
2023                new Integer(type), Boolean.valueOf(active)
2024            };
2025
2026        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_A,
2027                finderArgs, this);
2028
2029        if (count == null) {
2030            Session session = null;
2031
2032            try {
2033                session = openSession();
2034
2035                StringBuilder query = new StringBuilder();
2036
2037                query.append("SELECT COUNT(*) ");
2038                query.append("FROM com.liferay.portal.model.Group WHERE ");
2039
2040                query.append("type_ = ?");
2041
2042                query.append(" AND ");
2043
2044                query.append("active_ = ?");
2045
2046                query.append(" ");
2047
2048                Query q = session.createQuery(query.toString());
2049
2050                QueryPos qPos = QueryPos.getInstance(q);
2051
2052                qPos.add(type);
2053
2054                qPos.add(active);
2055
2056                count = (Long)q.uniqueResult();
2057            }
2058            catch (Exception e) {
2059                throw processException(e);
2060            }
2061            finally {
2062                if (count == null) {
2063                    count = Long.valueOf(0);
2064                }
2065
2066                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_A, finderArgs,
2067                    count);
2068
2069                closeSession(session);
2070            }
2071        }
2072
2073        return count.intValue();
2074    }
2075
2076    public int countByC_C_C(long companyId, long classNameId, long classPK)
2077        throws SystemException {
2078        Object[] finderArgs = new Object[] {
2079                new Long(companyId), new Long(classNameId), new Long(classPK)
2080            };
2081
2082        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2083                finderArgs, this);
2084
2085        if (count == null) {
2086            Session session = null;
2087
2088            try {
2089                session = openSession();
2090
2091                StringBuilder query = new StringBuilder();
2092
2093                query.append("SELECT COUNT(*) ");
2094                query.append("FROM com.liferay.portal.model.Group WHERE ");
2095
2096                query.append("companyId = ?");
2097
2098                query.append(" AND ");
2099
2100                query.append("classNameId = ?");
2101
2102                query.append(" AND ");
2103
2104                query.append("classPK = ?");
2105
2106                query.append(" ");
2107
2108                Query q = session.createQuery(query.toString());
2109
2110                QueryPos qPos = QueryPos.getInstance(q);
2111
2112                qPos.add(companyId);
2113
2114                qPos.add(classNameId);
2115
2116                qPos.add(classPK);
2117
2118                count = (Long)q.uniqueResult();
2119            }
2120            catch (Exception e) {
2121                throw processException(e);
2122            }
2123            finally {
2124                if (count == null) {
2125                    count = Long.valueOf(0);
2126                }
2127
2128                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2129                    finderArgs, count);
2130
2131                closeSession(session);
2132            }
2133        }
2134
2135        return count.intValue();
2136    }
2137
2138    public int countByC_L_N(long companyId, long liveGroupId, String name)
2139        throws SystemException {
2140        Object[] finderArgs = new Object[] {
2141                new Long(companyId), new Long(liveGroupId),
2142                
2143                name
2144            };
2145
2146        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_L_N,
2147                finderArgs, this);
2148
2149        if (count == null) {
2150            Session session = null;
2151
2152            try {
2153                session = openSession();
2154
2155                StringBuilder query = new StringBuilder();
2156
2157                query.append("SELECT COUNT(*) ");
2158                query.append("FROM com.liferay.portal.model.Group WHERE ");
2159
2160                query.append("companyId = ?");
2161
2162                query.append(" AND ");
2163
2164                query.append("liveGroupId = ?");
2165
2166                query.append(" AND ");
2167
2168                if (name == null) {
2169                    query.append("name IS NULL");
2170                }
2171                else {
2172                    query.append("name = ?");
2173                }
2174
2175                query.append(" ");
2176
2177                Query q = session.createQuery(query.toString());
2178
2179                QueryPos qPos = QueryPos.getInstance(q);
2180
2181                qPos.add(companyId);
2182
2183                qPos.add(liveGroupId);
2184
2185                if (name != null) {
2186                    qPos.add(name);
2187                }
2188
2189                count = (Long)q.uniqueResult();
2190            }
2191            catch (Exception e) {
2192                throw processException(e);
2193            }
2194            finally {
2195                if (count == null) {
2196                    count = Long.valueOf(0);
2197                }
2198
2199                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L_N,
2200                    finderArgs, count);
2201
2202                closeSession(session);
2203            }
2204        }
2205
2206        return count.intValue();
2207    }
2208
2209    public int countByC_C_L_N(long companyId, long classNameId,
2210        long liveGroupId, String name) throws SystemException {
2211        Object[] finderArgs = new Object[] {
2212                new Long(companyId), new Long(classNameId),
2213                new Long(liveGroupId),
2214                
2215                name
2216            };
2217
2218        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_L_N,
2219                finderArgs, this);
2220
2221        if (count == null) {
2222            Session session = null;
2223
2224            try {
2225                session = openSession();
2226
2227                StringBuilder query = new StringBuilder();
2228
2229                query.append("SELECT COUNT(*) ");
2230                query.append("FROM com.liferay.portal.model.Group WHERE ");
2231
2232                query.append("companyId = ?");
2233
2234                query.append(" AND ");
2235
2236                query.append("classNameId = ?");
2237
2238                query.append(" AND ");
2239
2240                query.append("liveGroupId = ?");
2241
2242                query.append(" AND ");
2243
2244                if (name == null) {
2245                    query.append("name IS NULL");
2246                }
2247                else {
2248                    query.append("name = ?");
2249                }
2250
2251                query.append(" ");
2252
2253                Query q = session.createQuery(query.toString());
2254
2255                QueryPos qPos = QueryPos.getInstance(q);
2256
2257                qPos.add(companyId);
2258
2259                qPos.add(classNameId);
2260
2261                qPos.add(liveGroupId);
2262
2263                if (name != null) {
2264                    qPos.add(name);
2265                }
2266
2267                count = (Long)q.uniqueResult();
2268            }
2269            catch (Exception e) {
2270                throw processException(e);
2271            }
2272            finally {
2273                if (count == null) {
2274                    count = Long.valueOf(0);
2275                }
2276
2277                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_L_N,
2278                    finderArgs, count);
2279
2280                closeSession(session);
2281            }
2282        }
2283
2284        return count.intValue();
2285    }
2286
2287    public int countAll() throws SystemException {
2288        Object[] finderArgs = new Object[0];
2289
2290        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2291                finderArgs, this);
2292
2293        if (count == null) {
2294            Session session = null;
2295
2296            try {
2297                session = openSession();
2298
2299                Query q = session.createQuery(
2300                        "SELECT COUNT(*) FROM com.liferay.portal.model.Group");
2301
2302                count = (Long)q.uniqueResult();
2303            }
2304            catch (Exception e) {
2305                throw processException(e);
2306            }
2307            finally {
2308                if (count == null) {
2309                    count = Long.valueOf(0);
2310                }
2311
2312                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2313                    count);
2314
2315                closeSession(session);
2316            }
2317        }
2318
2319        return count.intValue();
2320    }
2321
2322    public List<com.liferay.portal.model.Organization> getOrganizations(long pk)
2323        throws SystemException {
2324        return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2325    }
2326
2327    public List<com.liferay.portal.model.Organization> getOrganizations(
2328        long pk, int start, int end) throws SystemException {
2329        return getOrganizations(pk, start, end, null);
2330    }
2331
2332    public static final FinderPath FINDER_PATH_GET_ORGANIZATIONS = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2333            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, "Groups_Orgs",
2334            "getOrganizations",
2335            new String[] {
2336                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2337                "com.liferay.portal.kernel.util.OrderByComparator"
2338            });
2339
2340    public List<com.liferay.portal.model.Organization> getOrganizations(
2341        long pk, int start, int end, OrderByComparator obc)
2342        throws SystemException {
2343        Object[] finderArgs = new Object[] {
2344                new Long(pk), String.valueOf(start), String.valueOf(end),
2345                String.valueOf(obc)
2346            };
2347
2348        List<com.liferay.portal.model.Organization> list = (List<com.liferay.portal.model.Organization>)FinderCacheUtil.getResult(FINDER_PATH_GET_ORGANIZATIONS,
2349                finderArgs, this);
2350
2351        if (list == null) {
2352            Session session = null;
2353
2354            try {
2355                session = openSession();
2356
2357                StringBuilder sb = new StringBuilder();
2358
2359                sb.append(_SQL_GETORGANIZATIONS);
2360
2361                if (obc != null) {
2362                    sb.append("ORDER BY ");
2363                    sb.append(obc.getOrderBy());
2364                }
2365
2366                else {
2367                    sb.append("ORDER BY ");
2368
2369                    sb.append("Organization_.name ASC");
2370                }
2371
2372                String sql = sb.toString();
2373
2374                SQLQuery q = session.createSQLQuery(sql);
2375
2376                q.addEntity("Organization_",
2377                    com.liferay.portal.model.impl.OrganizationImpl.class);
2378
2379                QueryPos qPos = QueryPos.getInstance(q);
2380
2381                qPos.add(pk);
2382
2383                list = (List<com.liferay.portal.model.Organization>)QueryUtil.list(q,
2384                        getDialect(), start, end);
2385            }
2386            catch (Exception e) {
2387                throw processException(e);
2388            }
2389            finally {
2390                if (list == null) {
2391                    list = new ArrayList<com.liferay.portal.model.Organization>();
2392                }
2393
2394                organizationPersistence.cacheResult(list);
2395
2396                FinderCacheUtil.putResult(FINDER_PATH_GET_ORGANIZATIONS,
2397                    finderArgs, list);
2398
2399                closeSession(session);
2400            }
2401        }
2402
2403        return list;
2404    }
2405
2406    public static final FinderPath FINDER_PATH_GET_ORGANIZATIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2407            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, "Groups_Orgs",
2408            "getOrganizationsSize", new String[] { Long.class.getName() });
2409
2410    public int getOrganizationsSize(long pk) throws SystemException {
2411        Object[] finderArgs = new Object[] { new Long(pk) };
2412
2413        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
2414                finderArgs, this);
2415
2416        if (count == null) {
2417            Session session = null;
2418
2419            try {
2420                session = openSession();
2421
2422                SQLQuery q = session.createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
2423
2424                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2425
2426                QueryPos qPos = QueryPos.getInstance(q);
2427
2428                qPos.add(pk);
2429
2430                count = (Long)q.uniqueResult();
2431            }
2432            catch (Exception e) {
2433                throw processException(e);
2434            }
2435            finally {
2436                if (count == null) {
2437                    count = Long.valueOf(0);
2438                }
2439
2440                FinderCacheUtil.putResult(FINDER_PATH_GET_ORGANIZATIONS_SIZE,
2441                    finderArgs, count);
2442
2443                closeSession(session);
2444            }
2445        }
2446
2447        return count.intValue();
2448    }
2449
2450    public static final FinderPath FINDER_PATH_CONTAINS_ORGANIZATION = new FinderPath(com.liferay.portal.model.impl.OrganizationModelImpl.ENTITY_CACHE_ENABLED,
2451            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ORGS, "Groups_Orgs",
2452            "containsOrganization",
2453            new String[] { Long.class.getName(), Long.class.getName() });
2454
2455    public boolean containsOrganization(long pk, long organizationPK)
2456        throws SystemException {
2457        Object[] finderArgs = new Object[] {
2458                new Long(pk),
2459                
2460                new Long(organizationPK)
2461            };
2462
2463        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ORGANIZATION,
2464                finderArgs, this);
2465
2466        if (value == null) {
2467            try {
2468                value = Boolean.valueOf(containsOrganization.contains(pk,
2469                            organizationPK));
2470            }
2471            catch (Exception e) {
2472                throw processException(e);
2473            }
2474            finally {
2475                if (value == null) {
2476                    value = Boolean.FALSE;
2477                }
2478
2479                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ORGANIZATION,
2480                    finderArgs, value);
2481            }
2482        }
2483
2484        return value.booleanValue();
2485    }
2486
2487    public boolean containsOrganizations(long pk) throws SystemException {
2488        if (getOrganizationsSize(pk) > 0) {
2489            return true;
2490        }
2491        else {
2492            return false;
2493        }
2494    }
2495
2496    public void addOrganization(long pk, long organizationPK)
2497        throws SystemException {
2498        try {
2499            addOrganization.add(pk, organizationPK);
2500        }
2501        catch (Exception e) {
2502            throw processException(e);
2503        }
2504        finally {
2505            FinderCacheUtil.clearCache("Groups_Orgs");
2506        }
2507    }
2508
2509    public void addOrganization(long pk,
2510        com.liferay.portal.model.Organization organization)
2511        throws SystemException {
2512        try {
2513            addOrganization.add(pk, organization.getPrimaryKey());
2514        }
2515        catch (Exception e) {
2516            throw processException(e);
2517        }
2518        finally {
2519            FinderCacheUtil.clearCache("Groups_Orgs");
2520        }
2521    }
2522
2523    public void addOrganizations(long pk, long[] organizationPKs)
2524        throws SystemException {
2525        try {
2526            for (long organizationPK : organizationPKs) {
2527                addOrganization.add(pk, organizationPK);
2528            }
2529        }
2530        catch (Exception e) {
2531            throw processException(e);
2532        }
2533        finally {
2534            FinderCacheUtil.clearCache("Groups_Orgs");
2535        }
2536    }
2537
2538    public void addOrganizations(long pk,
2539        List<com.liferay.portal.model.Organization> organizations)
2540        throws SystemException {
2541        try {
2542            for (com.liferay.portal.model.Organization organization : organizations) {
2543                addOrganization.add(pk, organization.getPrimaryKey());
2544            }
2545        }
2546        catch (Exception e) {
2547            throw processException(e);
2548        }
2549        finally {
2550            FinderCacheUtil.clearCache("Groups_Orgs");
2551        }
2552    }
2553
2554    public void clearOrganizations(long pk) throws SystemException {
2555        try {
2556            clearOrganizations.clear(pk);
2557        }
2558        catch (Exception e) {
2559            throw processException(e);
2560        }
2561        finally {
2562            FinderCacheUtil.clearCache("Groups_Orgs");
2563        }
2564    }
2565
2566    public void removeOrganization(long pk, long organizationPK)
2567        throws SystemException {
2568        try {
2569            removeOrganization.remove(pk, organizationPK);
2570        }
2571        catch (Exception e) {
2572            throw processException(e);
2573        }
2574        finally {
2575            FinderCacheUtil.clearCache("Groups_Orgs");
2576        }
2577    }
2578
2579    public void removeOrganization(long pk,
2580        com.liferay.portal.model.Organization organization)
2581        throws SystemException {
2582        try {
2583            removeOrganization.remove(pk, organization.getPrimaryKey());
2584        }
2585        catch (Exception e) {
2586            throw processException(e);
2587        }
2588        finally {
2589            FinderCacheUtil.clearCache("Groups_Orgs");
2590        }
2591    }
2592
2593    public void removeOrganizations(long pk, long[] organizationPKs)
2594        throws SystemException {
2595        try {
2596            for (long organizationPK : organizationPKs) {
2597                removeOrganization.remove(pk, organizationPK);
2598            }
2599        }
2600        catch (Exception e) {
2601            throw processException(e);
2602        }
2603        finally {
2604            FinderCacheUtil.clearCache("Groups_Orgs");
2605        }
2606    }
2607
2608    public void removeOrganizations(long pk,
2609        List<com.liferay.portal.model.Organization> organizations)
2610        throws SystemException {
2611        try {
2612            for (com.liferay.portal.model.Organization organization : organizations) {
2613                removeOrganization.remove(pk, organization.getPrimaryKey());
2614            }
2615        }
2616        catch (Exception e) {
2617            throw processException(e);
2618        }
2619        finally {
2620            FinderCacheUtil.clearCache("Groups_Orgs");
2621        }
2622    }
2623
2624    public void setOrganizations(long pk, long[] organizationPKs)
2625        throws SystemException {
2626        try {
2627            clearOrganizations.clear(pk);
2628
2629            for (long organizationPK : organizationPKs) {
2630                addOrganization.add(pk, organizationPK);
2631            }
2632        }
2633        catch (Exception e) {
2634            throw processException(e);
2635        }
2636        finally {
2637            FinderCacheUtil.clearCache("Groups_Orgs");
2638        }
2639    }
2640
2641    public void setOrganizations(long pk,
2642        List<com.liferay.portal.model.Organization> organizations)
2643        throws SystemException {
2644        try {
2645            clearOrganizations.clear(pk);
2646
2647            for (com.liferay.portal.model.Organization organization : organizations) {
2648                addOrganization.add(pk, organization.getPrimaryKey());
2649            }
2650        }
2651        catch (Exception e) {
2652            throw processException(e);
2653        }
2654        finally {
2655            FinderCacheUtil.clearCache("Groups_Orgs");
2656        }
2657    }
2658
2659    public List<com.liferay.portal.model.Permission> getPermissions(long pk)
2660        throws SystemException {
2661        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2662    }
2663
2664    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
2665        int start, int end) throws SystemException {
2666        return getPermissions(pk, start, end, null);
2667    }
2668
2669    public static final FinderPath FINDER_PATH_GET_PERMISSIONS = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2670            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
2671            "Groups_Permissions", "getPermissions",
2672            new String[] {
2673                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2674                "com.liferay.portal.kernel.util.OrderByComparator"
2675            });
2676
2677    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
2678        int start, int end, OrderByComparator obc) throws SystemException {
2679        Object[] finderArgs = new Object[] {
2680                new Long(pk), String.valueOf(start), String.valueOf(end),
2681                String.valueOf(obc)
2682            };
2683
2684        List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS,
2685                finderArgs, this);
2686
2687        if (list == null) {
2688            Session session = null;
2689
2690            try {
2691                session = openSession();
2692
2693                StringBuilder sb = new StringBuilder();
2694
2695                sb.append(_SQL_GETPERMISSIONS);
2696
2697                if (obc != null) {
2698                    sb.append("ORDER BY ");
2699                    sb.append(obc.getOrderBy());
2700                }
2701
2702                String sql = sb.toString();
2703
2704                SQLQuery q = session.createSQLQuery(sql);
2705
2706                q.addEntity("Permission_",
2707                    com.liferay.portal.model.impl.PermissionImpl.class);
2708
2709                QueryPos qPos = QueryPos.getInstance(q);
2710
2711                qPos.add(pk);
2712
2713                list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
2714                        getDialect(), start, end);
2715            }
2716            catch (Exception e) {
2717                throw processException(e);
2718            }
2719            finally {
2720                if (list == null) {
2721                    list = new ArrayList<com.liferay.portal.model.Permission>();
2722                }
2723
2724                permissionPersistence.cacheResult(list);
2725
2726                FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS,
2727                    finderArgs, list);
2728
2729                closeSession(session);
2730            }
2731        }
2732
2733        return list;
2734    }
2735
2736    public static final FinderPath FINDER_PATH_GET_PERMISSIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2737            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
2738            "Groups_Permissions", "getPermissionsSize",
2739            new String[] { Long.class.getName() });
2740
2741    public int getPermissionsSize(long pk) throws SystemException {
2742        Object[] finderArgs = new Object[] { new Long(pk) };
2743
2744        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
2745                finderArgs, this);
2746
2747        if (count == null) {
2748            Session session = null;
2749
2750            try {
2751                session = openSession();
2752
2753                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
2754
2755                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2756
2757                QueryPos qPos = QueryPos.getInstance(q);
2758
2759                qPos.add(pk);
2760
2761                count = (Long)q.uniqueResult();
2762            }
2763            catch (Exception e) {
2764                throw processException(e);
2765            }
2766            finally {
2767                if (count == null) {
2768                    count = Long.valueOf(0);
2769                }
2770
2771                FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
2772                    finderArgs, count);
2773
2774                closeSession(session);
2775            }
2776        }
2777
2778        return count.intValue();
2779    }
2780
2781    public static final FinderPath FINDER_PATH_CONTAINS_PERMISSION = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2782            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
2783            "Groups_Permissions", "containsPermission",
2784            new String[] { Long.class.getName(), Long.class.getName() });
2785
2786    public boolean containsPermission(long pk, long permissionPK)
2787        throws SystemException {
2788        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
2789
2790        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_PERMISSION,
2791                finderArgs, this);
2792
2793        if (value == null) {
2794            try {
2795                value = Boolean.valueOf(containsPermission.contains(pk,
2796                            permissionPK));
2797            }
2798            catch (Exception e) {
2799                throw processException(e);
2800            }
2801            finally {
2802                if (value == null) {
2803                    value = Boolean.FALSE;
2804                }
2805
2806                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_PERMISSION,
2807                    finderArgs, value);
2808            }
2809        }
2810
2811        return value.booleanValue();
2812    }
2813
2814    public boolean containsPermissions(long pk) throws SystemException {
2815        if (getPermissionsSize(pk) > 0) {
2816            return true;
2817        }
2818        else {
2819            return false;
2820        }
2821    }
2822
2823    public void addPermission(long pk, long permissionPK)
2824        throws SystemException {
2825        try {
2826            addPermission.add(pk, permissionPK);
2827        }
2828        catch (Exception e) {
2829            throw processException(e);
2830        }
2831        finally {
2832            FinderCacheUtil.clearCache("Groups_Permissions");
2833        }
2834    }
2835
2836    public void addPermission(long pk,
2837        com.liferay.portal.model.Permission permission)
2838        throws SystemException {
2839        try {
2840            addPermission.add(pk, permission.getPrimaryKey());
2841        }
2842        catch (Exception e) {
2843            throw processException(e);
2844        }
2845        finally {
2846            FinderCacheUtil.clearCache("Groups_Permissions");
2847        }
2848    }
2849
2850    public void addPermissions(long pk, long[] permissionPKs)
2851        throws SystemException {
2852        try {
2853            for (long permissionPK : permissionPKs) {
2854                addPermission.add(pk, permissionPK);
2855            }
2856        }
2857        catch (Exception e) {
2858            throw processException(e);
2859        }
2860        finally {
2861            FinderCacheUtil.clearCache("Groups_Permissions");
2862        }
2863    }
2864
2865    public void addPermissions(long pk,
2866        List<com.liferay.portal.model.Permission> permissions)
2867        throws SystemException {
2868        try {
2869            for (com.liferay.portal.model.Permission permission : permissions) {
2870                addPermission.add(pk, permission.getPrimaryKey());
2871            }
2872        }
2873        catch (Exception e) {
2874            throw processException(e);
2875        }
2876        finally {
2877            FinderCacheUtil.clearCache("Groups_Permissions");
2878        }
2879    }
2880
2881    public void clearPermissions(long pk) throws SystemException {
2882        try {
2883            clearPermissions.clear(pk);
2884        }
2885        catch (Exception e) {
2886            throw processException(e);
2887        }
2888        finally {
2889            FinderCacheUtil.clearCache("Groups_Permissions");
2890        }
2891    }
2892
2893    public void removePermission(long pk, long permissionPK)
2894        throws SystemException {
2895        try {
2896            removePermission.remove(pk, permissionPK);
2897        }
2898        catch (Exception e) {
2899            throw processException(e);
2900        }
2901        finally {
2902            FinderCacheUtil.clearCache("Groups_Permissions");
2903        }
2904    }
2905
2906    public void removePermission(long pk,
2907        com.liferay.portal.model.Permission permission)
2908        throws SystemException {
2909        try {
2910            removePermission.remove(pk, permission.getPrimaryKey());
2911        }
2912        catch (Exception e) {
2913            throw processException(e);
2914        }
2915        finally {
2916            FinderCacheUtil.clearCache("Groups_Permissions");
2917        }
2918    }
2919
2920    public void removePermissions(long pk, long[] permissionPKs)
2921        throws SystemException {
2922        try {
2923            for (long permissionPK : permissionPKs) {
2924                removePermission.remove(pk, permissionPK);
2925            }
2926        }
2927        catch (Exception e) {
2928            throw processException(e);
2929        }
2930        finally {
2931            FinderCacheUtil.clearCache("Groups_Permissions");
2932        }
2933    }
2934
2935    public void removePermissions(long pk,
2936        List<com.liferay.portal.model.Permission> permissions)
2937        throws SystemException {
2938        try {
2939            for (com.liferay.portal.model.Permission permission : permissions) {
2940                removePermission.remove(pk, permission.getPrimaryKey());
2941            }
2942        }
2943        catch (Exception e) {
2944            throw processException(e);
2945        }
2946        finally {
2947            FinderCacheUtil.clearCache("Groups_Permissions");
2948        }
2949    }
2950
2951    public void setPermissions(long pk, long[] permissionPKs)
2952        throws SystemException {
2953        try {
2954            clearPermissions.clear(pk);
2955
2956            for (long permissionPK : permissionPKs) {
2957                addPermission.add(pk, permissionPK);
2958            }
2959        }
2960        catch (Exception e) {
2961            throw processException(e);
2962        }
2963        finally {
2964            FinderCacheUtil.clearCache("Groups_Permissions");
2965        }
2966    }
2967
2968    public void setPermissions(long pk,
2969        List<com.liferay.portal.model.Permission> permissions)
2970        throws SystemException {
2971        try {
2972            clearPermissions.clear(pk);
2973
2974            for (com.liferay.portal.model.Permission permission : permissions) {
2975                addPermission.add(pk, permission.getPrimaryKey());
2976            }
2977        }
2978        catch (Exception e) {
2979            throw processException(e);
2980        }
2981        finally {
2982            FinderCacheUtil.clearCache("Groups_Permissions");
2983        }
2984    }
2985
2986    public List<com.liferay.portal.model.Role> getRoles(long pk)
2987        throws SystemException {
2988        return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2989    }
2990
2991    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
2992        int end) throws SystemException {
2993        return getRoles(pk, start, end, null);
2994    }
2995
2996    public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
2997            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
2998            "getRoles",
2999            new String[] {
3000                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3001                "com.liferay.portal.kernel.util.OrderByComparator"
3002            });
3003
3004    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
3005        int end, OrderByComparator obc) throws SystemException {
3006        Object[] finderArgs = new Object[] {
3007                new Long(pk), String.valueOf(start), String.valueOf(end),
3008                String.valueOf(obc)
3009            };
3010
3011        List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
3012                finderArgs, this);
3013
3014        if (list == null) {
3015            Session session = null;
3016
3017            try {
3018                session = openSession();
3019
3020                StringBuilder sb = new StringBuilder();
3021
3022                sb.append(_SQL_GETROLES);
3023
3024                if (obc != null) {
3025                    sb.append("ORDER BY ");
3026                    sb.append(obc.getOrderBy());
3027                }
3028
3029                else {
3030                    sb.append("ORDER BY ");
3031
3032                    sb.append("Role_.name ASC");
3033                }
3034
3035                String sql = sb.toString();
3036
3037                SQLQuery q = session.createSQLQuery(sql);
3038
3039                q.addEntity("Role_",
3040                    com.liferay.portal.model.impl.RoleImpl.class);
3041
3042                QueryPos qPos = QueryPos.getInstance(q);
3043
3044                qPos.add(pk);
3045
3046                list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
3047                        getDialect(), start, end);
3048            }
3049            catch (Exception e) {
3050                throw processException(e);
3051            }
3052            finally {
3053                if (list == null) {
3054                    list = new ArrayList<com.liferay.portal.model.Role>();
3055                }
3056
3057                rolePersistence.cacheResult(list);
3058
3059                FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES, finderArgs,
3060                    list);
3061
3062                closeSession(session);
3063            }
3064        }
3065
3066        return list;
3067    }
3068
3069    public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
3070            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
3071            "getRolesSize", new String[] { Long.class.getName() });
3072
3073    public int getRolesSize(long pk) throws SystemException {
3074        Object[] finderArgs = new Object[] { new Long(pk) };
3075
3076        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
3077                finderArgs, this);
3078
3079        if (count == null) {
3080            Session session = null;
3081
3082            try {
3083                session = openSession();
3084
3085                SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
3086
3087                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3088
3089                QueryPos qPos = QueryPos.getInstance(q);
3090
3091                qPos.add(pk);
3092
3093                count = (Long)q.uniqueResult();
3094            }
3095            catch (Exception e) {
3096                throw processException(e);
3097            }
3098            finally {
3099                if (count == null) {
3100                    count = Long.valueOf(0);
3101                }
3102
3103                FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
3104                    finderArgs, count);
3105
3106                closeSession(session);
3107            }
3108        }
3109
3110        return count.intValue();
3111    }
3112
3113    public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
3114            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, "Groups_Roles",
3115            "containsRole",
3116            new String[] { Long.class.getName(), Long.class.getName() });
3117
3118    public boolean containsRole(long pk, long rolePK) throws SystemException {
3119        Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
3120
3121        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
3122                finderArgs, this);
3123
3124        if (value == null) {
3125            try {
3126                value = Boolean.valueOf(containsRole.contains(pk, rolePK));
3127            }
3128            catch (Exception e) {
3129                throw processException(e);
3130            }
3131            finally {
3132                if (value == null) {
3133                    value = Boolean.FALSE;
3134                }
3135
3136                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
3137                    finderArgs, value);
3138            }
3139        }
3140
3141        return value.booleanValue();
3142    }
3143
3144    public boolean containsRoles(long pk) throws SystemException {
3145        if (getRolesSize(pk) > 0) {
3146            return true;
3147        }
3148        else {
3149            return false;
3150        }
3151    }
3152
3153    public void addRole(long pk, long rolePK) throws SystemException {
3154        try {
3155            addRole.add(pk, rolePK);
3156        }
3157        catch (Exception e) {
3158            throw processException(e);
3159        }
3160        finally {
3161            FinderCacheUtil.clearCache("Groups_Roles");
3162        }
3163    }
3164
3165    public void addRole(long pk, com.liferay.portal.model.Role role)
3166        throws SystemException {
3167        try {
3168            addRole.add(pk, role.getPrimaryKey());
3169        }
3170        catch (Exception e) {
3171            throw processException(e);
3172        }
3173        finally {
3174            FinderCacheUtil.clearCache("Groups_Roles");
3175        }
3176    }
3177
3178    public void addRoles(long pk, long[] rolePKs) throws SystemException {
3179        try {
3180            for (long rolePK : rolePKs) {
3181                addRole.add(pk, rolePK);
3182            }
3183        }
3184        catch (Exception e) {
3185            throw processException(e);
3186        }
3187        finally {
3188            FinderCacheUtil.clearCache("Groups_Roles");
3189        }
3190    }
3191
3192    public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
3193        throws SystemException {
3194        try {
3195            for (com.liferay.portal.model.Role role : roles) {
3196                addRole.add(pk, role.getPrimaryKey());
3197            }
3198        }
3199        catch (Exception e) {
3200            throw processException(e);
3201        }
3202        finally {
3203            FinderCacheUtil.clearCache("Groups_Roles");
3204        }
3205    }
3206
3207    public void clearRoles(long pk) throws SystemException {
3208        try {
3209            clearRoles.clear(pk);
3210        }
3211        catch (Exception e) {
3212            throw processException(e);
3213        }
3214        finally {
3215            FinderCacheUtil.clearCache("Groups_Roles");
3216        }
3217    }
3218
3219    public void removeRole(long pk, long rolePK) throws SystemException {
3220        try {
3221            removeRole.remove(pk, rolePK);
3222        }
3223        catch (Exception e) {
3224            throw processException(e);
3225        }
3226        finally {
3227            FinderCacheUtil.clearCache("Groups_Roles");
3228        }
3229    }
3230
3231    public void removeRole(long pk, com.liferay.portal.model.Role role)
3232        throws SystemException {
3233        try {
3234            removeRole.remove(pk, role.getPrimaryKey());
3235        }
3236        catch (Exception e) {
3237            throw processException(e);
3238        }
3239        finally {
3240            FinderCacheUtil.clearCache("Groups_Roles");
3241        }
3242    }
3243
3244    public void removeRoles(long pk, long[] rolePKs) throws SystemException {
3245        try {
3246            for (long rolePK : rolePKs) {
3247                removeRole.remove(pk, rolePK);
3248            }
3249        }
3250        catch (Exception e) {
3251            throw processException(e);
3252        }
3253        finally {
3254            FinderCacheUtil.clearCache("Groups_Roles");
3255        }
3256    }
3257
3258    public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
3259        throws SystemException {
3260        try {
3261            for (com.liferay.portal.model.Role role : roles) {
3262                removeRole.remove(pk, role.getPrimaryKey());
3263            }
3264        }
3265        catch (Exception e) {
3266            throw processException(e);
3267        }
3268        finally {
3269            FinderCacheUtil.clearCache("Groups_Roles");
3270        }
3271    }
3272
3273    public void setRoles(long pk, long[] rolePKs) throws SystemException {
3274        try {
3275            clearRoles.clear(pk);
3276
3277            for (long rolePK : rolePKs) {
3278                addRole.add(pk, rolePK);
3279            }
3280        }
3281        catch (Exception e) {
3282            throw processException(e);
3283        }
3284        finally {
3285            FinderCacheUtil.clearCache("Groups_Roles");
3286        }
3287    }
3288
3289    public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
3290        throws SystemException {
3291        try {
3292            clearRoles.clear(pk);
3293
3294            for (com.liferay.portal.model.Role role : roles) {
3295                addRole.add(pk, role.getPrimaryKey());
3296            }
3297        }
3298        catch (Exception e) {
3299            throw processException(e);
3300        }
3301        finally {
3302            FinderCacheUtil.clearCache("Groups_Roles");
3303        }
3304    }
3305
3306    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
3307        throws SystemException {
3308        return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3309    }
3310
3311    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
3312        int start, int end) throws SystemException {
3313        return getUserGroups(pk, start, end, null);
3314    }
3315
3316    public static final FinderPath FINDER_PATH_GET_USERGROUPS = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
3317            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
3318            "Groups_UserGroups", "getUserGroups",
3319            new String[] {
3320                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3321                "com.liferay.portal.kernel.util.OrderByComparator"
3322            });
3323
3324    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
3325        int start, int end, OrderByComparator obc) throws SystemException {
3326        Object[] finderArgs = new Object[] {
3327                new Long(pk), String.valueOf(start), String.valueOf(end),
3328                String.valueOf(obc)
3329            };
3330
3331        List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS,
3332                finderArgs, this);
3333
3334        if (list == null) {
3335            Session session = null;
3336
3337            try {
3338                session = openSession();
3339
3340                StringBuilder sb = new StringBuilder();
3341
3342                sb.append(_SQL_GETUSERGROUPS);
3343
3344                if (obc != null) {
3345                    sb.append("ORDER BY ");
3346                    sb.append(obc.getOrderBy());
3347                }
3348
3349                else {
3350                    sb.append("ORDER BY ");
3351
3352                    sb.append("UserGroup.name ASC");
3353                }
3354
3355                String sql = sb.toString();
3356
3357                SQLQuery q = session.createSQLQuery(sql);
3358
3359                q.addEntity("UserGroup",
3360                    com.liferay.portal.model.impl.UserGroupImpl.class);
3361
3362                QueryPos qPos = QueryPos.getInstance(q);
3363
3364                qPos.add(pk);
3365
3366                list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
3367                        getDialect(), start, end);
3368            }
3369            catch (Exception e) {
3370                throw processException(e);
3371            }
3372            finally {
3373                if (list == null) {
3374                    list = new ArrayList<com.liferay.portal.model.UserGroup>();
3375                }
3376
3377                userGroupPersistence.cacheResult(list);
3378
3379                FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS,
3380                    finderArgs, list);
3381
3382                closeSession(session);
3383            }
3384        }
3385
3386        return list;
3387    }
3388
3389    public static final FinderPath FINDER_PATH_GET_USERGROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
3390            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
3391            "Groups_UserGroups", "getUserGroupsSize",
3392            new String[] { Long.class.getName() });
3393
3394    public int getUserGroupsSize(long pk) throws SystemException {
3395        Object[] finderArgs = new Object[] { new Long(pk) };
3396
3397        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERGROUPS_SIZE,
3398                finderArgs, this);
3399
3400        if (count == null) {
3401            Session session = null;
3402
3403            try {
3404                session = openSession();
3405
3406                SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
3407
3408                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3409
3410                QueryPos qPos = QueryPos.getInstance(q);
3411
3412                qPos.add(pk);
3413
3414                count = (Long)q.uniqueResult();
3415            }
3416            catch (Exception e) {
3417                throw processException(e);
3418            }
3419            finally {
3420                if (count == null) {
3421                    count = Long.valueOf(0);
3422                }
3423
3424                FinderCacheUtil.putResult(FINDER_PATH_GET_USERGROUPS_SIZE,
3425                    finderArgs, count);
3426
3427                closeSession(session);
3428            }
3429        }
3430
3431        return count.intValue();
3432    }
3433
3434    public static final FinderPath FINDER_PATH_CONTAINS_USERGROUP = new FinderPath(com.liferay.portal.model.impl.UserGroupModelImpl.ENTITY_CACHE_ENABLED,
3435            GroupModelImpl.FINDER_CACHE_ENABLED_GROUPS_USERGROUPS,
3436            "Groups_UserGroups", "containsUserGroup",
3437            new String[] { Long.class.getName(), Long.class.getName() });
3438
3439    public boolean containsUserGroup(long pk, long userGroupPK)
3440        throws SystemException {
3441        Object[] finderArgs = new Object[] { new Long(pk), new Long(userGroupPK) };
3442
3443        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USERGROUP,
3444                finderArgs, this);
3445
3446        if (value == null) {
3447            try {
3448                value = Boolean.valueOf(containsUserGroup.contains(pk,
3449                            userGroupPK));
3450            }
3451            catch (Exception e) {
3452                throw processException(e);
3453            }
3454            finally {
3455                if (value == null) {
3456                    value = Boolean.FALSE;
3457                }
3458
3459                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USERGROUP,
3460                    finderArgs, value);
3461            }
3462        }
3463
3464        return value.booleanValue();
3465    }
3466
3467    public boolean containsUserGroups(long pk) throws SystemException {
3468        if (getUserGroupsSize(pk) > 0) {
3469            return true;
3470        }
3471        else {
3472            return false;
3473        }
3474    }
3475
3476    public void addUserGroup(long pk, long userGroupPK)
3477        throws SystemException {
3478        try {
3479            addUserGroup.add(pk, userGroupPK);
3480        }
3481        catch (Exception e) {
3482            throw processException(e);
3483        }
3484        finally {
3485            FinderCacheUtil.clearCache("Groups_UserGroups");
3486        }
3487    }
3488
3489    public void addUserGroup(long pk,
3490        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
3491        try {
3492            addUserGroup.add(pk, userGroup.getPrimaryKey());
3493        }
3494        catch (Exception e) {
3495            throw processException(e);
3496        }
3497        finally {
3498            FinderCacheUtil.clearCache("Groups_UserGroups");
3499        }
3500    }
3501
3502    public void addUserGroups(long pk, long[] userGroupPKs)
3503        throws SystemException {
3504        try {
3505            for (long userGroupPK : userGroupPKs) {
3506                addUserGroup.add(pk, userGroupPK);
3507            }
3508        }
3509        catch (Exception e) {
3510            throw processException(e);
3511        }
3512        finally {
3513            FinderCacheUtil.clearCache("Groups_UserGroups");
3514        }
3515    }
3516
3517    public void addUserGroups(long pk,
3518        List<com.liferay.portal.model.UserGroup> userGroups)
3519        throws SystemException {
3520        try {
3521            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3522                addUserGroup.add(pk, userGroup.getPrimaryKey());
3523            }
3524        }
3525        catch (Exception e) {
3526            throw processException(e);
3527        }
3528        finally {
3529            FinderCacheUtil.clearCache("Groups_UserGroups");
3530        }
3531    }
3532
3533    public void clearUserGroups(long pk) throws SystemException {
3534        try {
3535            clearUserGroups.clear(pk);
3536        }
3537        catch (Exception e) {
3538            throw processException(e);
3539        }
3540        finally {
3541            FinderCacheUtil.clearCache("Groups_UserGroups");
3542        }
3543    }
3544
3545    public void removeUserGroup(long pk, long userGroupPK)
3546        throws SystemException {
3547        try {
3548            removeUserGroup.remove(pk, userGroupPK);
3549        }
3550        catch (Exception e) {
3551            throw processException(e);
3552        }
3553        finally {
3554            FinderCacheUtil.clearCache("Groups_UserGroups");
3555        }
3556    }
3557
3558    public void removeUserGroup(long pk,
3559        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
3560        try {
3561            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
3562        }
3563        catch (Exception e) {
3564            throw processException(e);
3565        }
3566        finally {
3567            FinderCacheUtil.clearCache("Groups_UserGroups");
3568        }
3569    }
3570
3571    public void removeUserGroups(long pk, long[] userGroupPKs)
3572        throws SystemException {
3573        try {
3574            for (long userGroupPK : userGroupPKs) {
3575                removeUserGroup.remove(pk, userGroupPK);
3576            }
3577        }
3578        catch (Exception e) {
3579            throw processException(e);
3580        }
3581        finally {
3582            FinderCacheUtil.clearCache("Groups_UserGroups");
3583        }
3584    }
3585
3586    public void removeUserGroups(long pk,
3587        List<com.liferay.portal.model.UserGroup> userGroups)
3588        throws SystemException {
3589        try {
3590            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3591                removeUserGroup.remove(pk, userGroup.getPrimaryKey());
3592            }
3593        }
3594        catch (Exception e) {
3595            throw processException(e);
3596        }
3597        finally {
3598            FinderCacheUtil.clearCache("Groups_UserGroups");
3599        }
3600    }
3601
3602    public void setUserGroups(long pk, long[] userGroupPKs)
3603        throws SystemException {
3604        try {
3605            clearUserGroups.clear(pk);
3606
3607            for (long userGroupPK : userGroupPKs) {
3608                addUserGroup.add(pk, userGroupPK);
3609            }
3610        }
3611        catch (Exception e) {
3612            throw processException(e);
3613        }
3614        finally {
3615            FinderCacheUtil.clearCache("Groups_UserGroups");
3616        }
3617    }
3618
3619    public void setUserGroups(long pk,
3620        List<com.liferay.portal.model.UserGroup> userGroups)
3621        throws SystemException {
3622        try {
3623            clearUserGroups.clear(pk);
3624
3625            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
3626                addUserGroup.add(pk, userGroup.getPrimaryKey());
3627            }
3628        }
3629        catch (Exception e) {
3630            throw processException(e);
3631        }
3632        finally {
3633            FinderCacheUtil.clearCache("Groups_UserGroups");
3634        }
3635    }
3636
3637    public List<com.liferay.portal.model.User> getUsers(long pk)
3638        throws SystemException {
3639        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3640    }
3641
3642    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3643        int end) throws SystemException {
3644        return getUsers(pk, start, end, null);
3645    }
3646
3647    public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3648            GroupModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS, "Users_Groups",
3649            "getUsers",
3650            new String[] {
3651                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3652                "com.liferay.portal.kernel.util.OrderByComparator"
3653            });
3654
3655    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3656        int end, OrderByComparator obc) throws SystemException {
3657        Object[] finderArgs = new Object[] {
3658                new Long(pk), String.valueOf(start), String.valueOf(end),
3659                String.valueOf(obc)
3660            };
3661
3662        List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
3663                finderArgs, this);
3664
3665        if (list == null) {
3666            Session session = null;
3667
3668            try {
3669                session = openSession();
3670
3671                StringBuilder sb = new StringBuilder();
3672
3673                sb.append(_SQL_GETUSERS);
3674
3675                if (obc != null) {
3676                    sb.append("ORDER BY ");
3677                    sb.append(obc.getOrderBy());
3678                }
3679
3680                String sql = sb.toString();
3681
3682                SQLQuery q = session.createSQLQuery(sql);
3683
3684                q.addEntity("User_",
3685                    com.liferay.portal.model.impl.UserImpl.class);
3686
3687                QueryPos qPos = QueryPos.getInstance(q);
3688
3689                qPos.add(pk);
3690
3691                list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
3692                        getDialect(), start, end);
3693            }
3694            catch (Exception e) {
3695                throw processException(e);
3696            }
3697            finally {
3698                if (list == null) {
3699                    list = new ArrayList<com.liferay.portal.model.User>();
3700                }
3701
3702                userPersistence.cacheResult(list);
3703
3704                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
3705                    list);
3706
3707                closeSession(session);
3708            }
3709        }
3710
3711        return list;
3712    }
3713
3714    public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3715            GroupModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS, "Users_Groups",
3716            "getUsersSize", new String[] { Long.class.getName() });
3717
3718    public int getUsersSize(long pk) throws SystemException {
3719        Object[] finderArgs = new Object[] { new Long(pk) };
3720
3721        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
3722                finderArgs, this);
3723
3724        if (count == null) {
3725            Session session = null;
3726
3727            try {
3728                session = openSession();
3729
3730                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
3731
3732                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
3733
3734                QueryPos qPos = QueryPos.getInstance(q);
3735
3736                qPos.add(pk);
3737
3738                count = (Long)q.uniqueResult();
3739            }
3740            catch (Exception e) {
3741                throw processException(e);
3742            }
3743            finally {
3744                if (count == null) {
3745                    count = Long.valueOf(0);
3746                }
3747
3748                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
3749                    finderArgs, count);
3750
3751                closeSession(session);
3752            }
3753        }
3754
3755        return count.intValue();
3756    }
3757
3758    public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3759            GroupModelImpl.FINDER_CACHE_ENABLED_USERS_GROUPS, "Users_Groups",
3760            "containsUser",
3761            new String[] { Long.class.getName(), Long.class.getName() });
3762
3763    public boolean containsUser(long pk, long userPK) throws SystemException {
3764        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
3765
3766        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
3767                finderArgs, this);
3768
3769        if (value == null) {
3770            try {
3771                value = Boolean.valueOf(containsUser.contains(pk, userPK));
3772            }
3773            catch (Exception e) {
3774                throw processException(e);
3775            }
3776            finally {
3777                if (value == null) {
3778                    value = Boolean.FALSE;
3779                }
3780
3781                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
3782                    finderArgs, value);
3783            }
3784        }
3785
3786        return value.booleanValue();
3787    }
3788
3789    public boolean containsUsers(long pk) throws SystemException {
3790        if (getUsersSize(pk) > 0) {
3791            return true;
3792        }
3793        else {
3794            return false;
3795        }
3796    }
3797
3798    public void addUser(long pk, long userPK) throws SystemException {
3799        try {
3800            addUser.add(pk, userPK);
3801        }
3802        catch (Exception e) {
3803            throw processException(e);
3804        }
3805        finally {
3806            FinderCacheUtil.clearCache("Users_Groups");
3807        }
3808    }
3809
3810    public void addUser(long pk, com.liferay.portal.model.User user)
3811        throws SystemException {
3812        try {
3813            addUser.add(pk, user.getPrimaryKey());
3814        }
3815        catch (Exception e) {
3816            throw processException(e);
3817        }
3818        finally {
3819            FinderCacheUtil.clearCache("Users_Groups");
3820        }
3821    }
3822
3823    public void addUsers(long pk, long[] userPKs) throws SystemException {
3824        try {
3825            for (long userPK : userPKs) {
3826                addUser.add(pk, userPK);
3827            }
3828        }
3829        catch (Exception e) {
3830            throw processException(e);
3831        }
3832        finally {
3833            FinderCacheUtil.clearCache("Users_Groups");
3834        }
3835    }
3836
3837    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
3838        throws SystemException {
3839        try {
3840            for (com.liferay.portal.model.User user : users) {
3841                addUser.add(pk, user.getPrimaryKey());
3842            }
3843        }
3844        catch (Exception e) {
3845            throw processException(e);
3846        }
3847        finally {
3848            FinderCacheUtil.clearCache("Users_Groups");
3849        }
3850    }
3851
3852    public void clearUsers(long pk) throws SystemException {
3853        try {
3854            clearUsers.clear(pk);
3855        }
3856        catch (Exception e) {
3857            throw processException(e);
3858        }
3859        finally {
3860            FinderCacheUtil.clearCache("Users_Groups");
3861        }
3862    }
3863
3864    public void removeUser(long pk, long userPK) throws SystemException {
3865        try {
3866            removeUser.remove(pk, userPK);
3867        }
3868        catch (Exception e) {
3869            throw processException(e);
3870        }
3871        finally {
3872            FinderCacheUtil.clearCache("Users_Groups");
3873        }
3874    }
3875
3876    public void removeUser(long pk, com.liferay.portal.model.User user)
3877        throws SystemException {
3878        try {
3879            removeUser.remove(pk, user.getPrimaryKey());
3880        }
3881        catch (Exception e) {
3882            throw processException(e);
3883        }
3884        finally {
3885            FinderCacheUtil.clearCache("Users_Groups");
3886        }
3887    }
3888
3889    public void removeUsers(long pk, long[] userPKs) throws SystemException {
3890        try {
3891            for (long userPK : userPKs) {
3892                removeUser.remove(pk, userPK);
3893            }
3894        }
3895        catch (Exception e) {
3896            throw processException(e);
3897        }
3898        finally {
3899            FinderCacheUtil.clearCache("Users_Groups");
3900        }
3901    }
3902
3903    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
3904        throws SystemException {
3905        try {
3906            for (com.liferay.portal.model.User user : users) {
3907                removeUser.remove(pk, user.getPrimaryKey());
3908            }
3909        }
3910        catch (Exception e) {
3911            throw processException(e);
3912        }
3913        finally {
3914            FinderCacheUtil.clearCache("Users_Groups");
3915        }
3916    }
3917
3918    public void setUsers(long pk, long[] userPKs) throws SystemException {
3919        try {
3920            clearUsers.clear(pk);
3921
3922            for (long userPK : userPKs) {
3923                addUser.add(pk, userPK);
3924            }
3925        }
3926        catch (Exception e) {
3927            throw processException(e);
3928        }
3929        finally {
3930            FinderCacheUtil.clearCache("Users_Groups");
3931        }
3932    }
3933
3934    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
3935        throws SystemException {
3936        try {
3937            clearUsers.clear(pk);
3938
3939            for (com.liferay.portal.model.User user : users) {
3940                addUser.add(pk, user.getPrimaryKey());
3941            }
3942        }
3943        catch (Exception e) {
3944            throw processException(e);
3945        }
3946        finally {
3947            FinderCacheUtil.clearCache("Users_Groups");
3948        }
3949    }
3950
3951    public void afterPropertiesSet() {
3952        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3953                    com.liferay.portal.util.PropsUtil.get(
3954                        "value.object.listener.com.liferay.portal.model.Group")));
3955
3956        if (listenerClassNames.length > 0) {
3957            try {
3958                List<ModelListener<Group>> listenersList = new ArrayList<ModelListener<Group>>();
3959
3960                for (String listenerClassName : listenerClassNames) {
3961                    listenersList.add((ModelListener<Group>)Class.forName(
3962                            listenerClassName).newInstance());
3963                }
3964
3965                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3966            }
3967            catch (Exception e) {
3968                _log.error(e);
3969            }
3970        }
3971
3972        containsOrganization = new ContainsOrganization(this);
3973
3974        addOrganization = new AddOrganization(this);
3975        clearOrganizations = new ClearOrganizations(this);
3976        removeOrganization = new RemoveOrganization(this);
3977
3978        containsPermission = new ContainsPermission(this);
3979
3980        addPermission = new AddPermission(this);
3981        clearPermissions = new ClearPermissions(this);
3982        removePermission = new RemovePermission(this);
3983
3984        containsRole = new ContainsRole(this);
3985
3986        addRole = new AddRole(this);
3987        clearRoles = new ClearRoles(this);
3988        removeRole = new RemoveRole(this);
3989
3990        containsUserGroup = new ContainsUserGroup(this);
3991
3992        addUserGroup = new AddUserGroup(this);
3993        clearUserGroups = new ClearUserGroups(this);
3994        removeUserGroup = new RemoveUserGroup(this);
3995
3996        containsUser = new ContainsUser(this);
3997
3998        addUser = new AddUser(this);
3999        clearUsers = new ClearUsers(this);
4000        removeUser = new RemoveUser(this);
4001    }
4002
4003    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
4004    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
4005    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
4006    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
4007    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
4008    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
4009    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
4010    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
4011    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
4012    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
4013    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
4014    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
4015    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
4016    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
4017    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
4018    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
4019    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
4020    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
4021    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
4022    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
4023    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
4024    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
4025    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
4026    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
4027    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
4028    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
4029    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
4030    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
4031    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
4032    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
4033    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
4034    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4035    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
4036    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
4037    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
4038    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
4039    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
4040    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
4041    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
4042    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4043    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
4044    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
4045    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
4046    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
4047    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
4048    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
4049    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
4050    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
4051    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
4052    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
4053    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
4054    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
4055    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
4056    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
4057    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
4058    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
4059    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
4060    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
4061    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
4062    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
4063    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
4064    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
4065    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
4066    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
4067    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
4068    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
4069    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
4070    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
4071    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
4072    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
4073    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
4074    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
4075    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
4076    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
4077    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
4078    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
4079    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
4080    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
4081    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
4082    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
4083    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
4084    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
4085    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
4086    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
4087    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
4088    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
4089    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
4090    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
4091    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
4092    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
4093    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
4094    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
4095    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence.impl")
4096    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
4097    @BeanReference(name = "com.liferay.portlet.bookmarks.service.persistence.BookmarksFolderPersistence.impl")
4098    protected com.liferay.portlet.bookmarks.service.persistence.BookmarksFolderPersistence bookmarksFolderPersistence;
4099    @BeanReference(name = "com.liferay.portlet.calendar.service.persistence.CalEventPersistence.impl")
4100    protected com.liferay.portlet.calendar.service.persistence.CalEventPersistence calEventPersistence;
4101    @BeanReference(name = "com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence.impl")
4102    protected com.liferay.portlet.documentlibrary.service.persistence.DLFolderPersistence dlFolderPersistence;
4103    @BeanReference(name = "com.liferay.portlet.imagegallery.service.persistence.IGFolderPersistence.impl")
4104    protected com.liferay.portlet.imagegallery.service.persistence.IGFolderPersistence igFolderPersistence;
4105    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticlePersistence.impl")
4106    protected com.liferay.portlet.journal.service.persistence.JournalArticlePersistence journalArticlePersistence;
4107    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalStructurePersistence.impl")
4108    protected com.liferay.portlet.journal.service.persistence.JournalStructurePersistence journalStructurePersistence;
4109    @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence.impl")
4110    protected com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence journalTemplatePersistence;
4111    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence.impl")
4112    protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
4113    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence.impl")
4114    protected com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence mbCategoryPersistence;
4115    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence.impl")
4116    protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
4117    @BeanReference(name = "com.liferay.portlet.polls.service.persistence.PollsQuestionPersistence.impl")
4118    protected com.liferay.portlet.polls.service.persistence.PollsQuestionPersistence pollsQuestionPersistence;
4119    @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence.impl")
4120    protected com.liferay.portlet.shopping.service.persistence.ShoppingCartPersistence shoppingCartPersistence;
4121    @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence.impl")
4122    protected com.liferay.portlet.shopping.service.persistence.ShoppingCategoryPersistence shoppingCategoryPersistence;
4123    @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence.impl")
4124    protected com.liferay.portlet.shopping.service.persistence.ShoppingCouponPersistence shoppingCouponPersistence;
4125    @BeanReference(name = "com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence.impl")
4126    protected com.liferay.portlet.shopping.service.persistence.ShoppingOrderPersistence shoppingOrderPersistence;
4127    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence.impl")
4128    protected com.liferay.portlet.softwarecatalog.service.persistence.SCFrameworkVersionPersistence scFrameworkVersionPersistence;
4129    @BeanReference(name = "com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence.impl")
4130    protected com.liferay.portlet.softwarecatalog.service.persistence.SCProductEntryPersistence scProductEntryPersistence;
4131    @BeanReference(name = "com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence.impl")
4132    protected com.liferay.portlet.tasks.service.persistence.TasksProposalPersistence tasksProposalPersistence;
4133    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence.impl")
4134    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
4135    @BeanReference(name = "com.liferay.portlet.wiki.service.persistence.WikiNodePersistence.impl")
4136    protected com.liferay.portlet.wiki.service.persistence.WikiNodePersistence wikiNodePersistence;
4137    protected ContainsOrganization containsOrganization;
4138    protected AddOrganization addOrganization;
4139    protected ClearOrganizations clearOrganizations;
4140    protected RemoveOrganization removeOrganization;
4141    protected ContainsPermission containsPermission;
4142    protected AddPermission addPermission;
4143    protected ClearPermissions clearPermissions;
4144    protected RemovePermission removePermission;
4145    protected ContainsRole containsRole;
4146    protected AddRole addRole;
4147    protected ClearRoles clearRoles;
4148    protected RemoveRole removeRole;
4149    protected ContainsUserGroup containsUserGroup;
4150    protected AddUserGroup addUserGroup;
4151    protected ClearUserGroups clearUserGroups;
4152    protected RemoveUserGroup removeUserGroup;
4153    protected ContainsUser containsUser;
4154    protected AddUser addUser;
4155    protected ClearUsers clearUsers;
4156    protected RemoveUser removeUser;
4157
4158    protected class ContainsOrganization {
4159        protected ContainsOrganization(GroupPersistenceImpl persistenceImpl) {
4160            super();
4161
4162            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4163                    _SQL_CONTAINSORGANIZATION,
4164                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4165        }
4166
4167        protected boolean contains(long groupId, long organizationId) {
4168            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4169                        new Long(groupId), new Long(organizationId)
4170                    });
4171
4172            if (results.size() > 0) {
4173                Integer count = results.get(0);
4174
4175                if (count.intValue() > 0) {
4176                    return true;
4177                }
4178            }
4179
4180            return false;
4181        }
4182
4183        private MappingSqlQuery _mappingSqlQuery;
4184    }
4185
4186    protected class AddOrganization {
4187        protected AddOrganization(GroupPersistenceImpl persistenceImpl) {
4188            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4189                    "INSERT INTO Groups_Orgs (groupId, organizationId) VALUES (?, ?)",
4190                    new int[] { Types.BIGINT, Types.BIGINT });
4191            _persistenceImpl = persistenceImpl;
4192        }
4193
4194        protected void add(long groupId, long organizationId)
4195            throws SystemException {
4196            if (!_persistenceImpl.containsOrganization.contains(groupId,
4197                        organizationId)) {
4198                ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
4199                    organizationPersistence.getListeners();
4200
4201                for (ModelListener<Group> listener : listeners) {
4202                    listener.onBeforeAddAssociation(groupId,
4203                        com.liferay.portal.model.Organization.class.getName(),
4204                        organizationId);
4205                }
4206
4207                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
4208                    listener.onBeforeAddAssociation(organizationId,
4209                        Group.class.getName(), groupId);
4210                }
4211
4212                _sqlUpdate.update(new Object[] {
4213                        new Long(groupId), new Long(organizationId)
4214                    });
4215
4216                for (ModelListener<Group> listener : listeners) {
4217                    listener.onAfterAddAssociation(groupId,
4218                        com.liferay.portal.model.Organization.class.getName(),
4219                        organizationId);
4220                }
4221
4222                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
4223                    listener.onAfterAddAssociation(organizationId,
4224                        Group.class.getName(), groupId);
4225                }
4226            }
4227        }
4228
4229        private SqlUpdate _sqlUpdate;
4230        private GroupPersistenceImpl _persistenceImpl;
4231    }
4232
4233    protected class ClearOrganizations {
4234        protected ClearOrganizations(GroupPersistenceImpl persistenceImpl) {
4235            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4236                    "DELETE FROM Groups_Orgs WHERE groupId = ?",
4237                    new int[] { Types.BIGINT });
4238        }
4239
4240        protected void clear(long groupId) throws SystemException {
4241            ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
4242                organizationPersistence.getListeners();
4243
4244            List<com.liferay.portal.model.Organization> organizations = null;
4245
4246            if ((listeners.length > 0) || (organizationListeners.length > 0)) {
4247                organizations = getOrganizations(groupId);
4248
4249                for (com.liferay.portal.model.Organization organization : organizations) {
4250                    for (ModelListener<Group> listener : listeners) {
4251                        listener.onBeforeRemoveAssociation(groupId,
4252                            com.liferay.portal.model.Organization.class.getName(),
4253                            organization.getPrimaryKey());
4254                    }
4255
4256                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
4257                        listener.onBeforeRemoveAssociation(organization.getPrimaryKey(),
4258                            Group.class.getName(), groupId);
4259                    }
4260                }
4261            }
4262
4263            _sqlUpdate.update(new Object[] { new Long(groupId) });
4264
4265            if ((listeners.length > 0) || (organizationListeners.length > 0)) {
4266                for (com.liferay.portal.model.Organization organization : organizations) {
4267                    for (ModelListener<Group> listener : listeners) {
4268                        listener.onAfterRemoveAssociation(groupId,
4269                            com.liferay.portal.model.Organization.class.getName(),
4270                            organization.getPrimaryKey());
4271                    }
4272
4273                    for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
4274                        listener.onBeforeRemoveAssociation(organization.getPrimaryKey(),
4275                            Group.class.getName(), groupId);
4276                    }
4277                }
4278            }
4279        }
4280
4281        private SqlUpdate _sqlUpdate;
4282    }
4283
4284    protected class RemoveOrganization {
4285        protected RemoveOrganization(GroupPersistenceImpl persistenceImpl) {
4286            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4287                    "DELETE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?",
4288                    new int[] { Types.BIGINT, Types.BIGINT });
4289            _persistenceImpl = persistenceImpl;
4290        }
4291
4292        protected void remove(long groupId, long organizationId)
4293            throws SystemException {
4294            if (_persistenceImpl.containsOrganization.contains(groupId,
4295                        organizationId)) {
4296                ModelListener<com.liferay.portal.model.Organization>[] organizationListeners =
4297                    organizationPersistence.getListeners();
4298
4299                for (ModelListener<Group> listener : listeners) {
4300                    listener.onBeforeRemoveAssociation(groupId,
4301                        com.liferay.portal.model.Organization.class.getName(),
4302                        organizationId);
4303                }
4304
4305                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
4306                    listener.onBeforeRemoveAssociation(organizationId,
4307                        Group.class.getName(), groupId);
4308                }
4309
4310                _sqlUpdate.update(new Object[] {
4311                        new Long(groupId), new Long(organizationId)
4312                    });
4313
4314                for (ModelListener<Group> listener : listeners) {
4315                    listener.onAfterRemoveAssociation(groupId,
4316                        com.liferay.portal.model.Organization.class.getName(),
4317                        organizationId);
4318                }
4319
4320                for (ModelListener<com.liferay.portal.model.Organization> listener : organizationListeners) {
4321                    listener.onAfterRemoveAssociation(organizationId,
4322                        Group.class.getName(), groupId);
4323                }
4324            }
4325        }
4326
4327        private SqlUpdate _sqlUpdate;
4328        private GroupPersistenceImpl _persistenceImpl;
4329    }
4330
4331    protected class ContainsPermission {
4332        protected ContainsPermission(GroupPersistenceImpl persistenceImpl) {
4333            super();
4334
4335            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4336                    _SQL_CONTAINSPERMISSION,
4337                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4338        }
4339
4340        protected boolean contains(long groupId, long permissionId) {
4341            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4342                        new Long(groupId), new Long(permissionId)
4343                    });
4344
4345            if (results.size() > 0) {
4346                Integer count = results.get(0);
4347
4348                if (count.intValue() > 0) {
4349                    return true;
4350                }
4351            }
4352
4353            return false;
4354        }
4355
4356        private MappingSqlQuery _mappingSqlQuery;
4357    }
4358
4359    protected class AddPermission {
4360        protected AddPermission(GroupPersistenceImpl persistenceImpl) {
4361            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4362                    "INSERT INTO Groups_Permissions (groupId, permissionId) VALUES (?, ?)",
4363                    new int[] { Types.BIGINT, Types.BIGINT });
4364            _persistenceImpl = persistenceImpl;
4365        }
4366
4367        protected void add(long groupId, long permissionId)
4368            throws SystemException {
4369            if (!_persistenceImpl.containsPermission.contains(groupId,
4370                        permissionId)) {
4371                ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4372                    permissionPersistence.getListeners();
4373
4374                for (ModelListener<Group> listener : listeners) {
4375                    listener.onBeforeAddAssociation(groupId,
4376                        com.liferay.portal.model.Permission.class.getName(),
4377                        permissionId);
4378                }
4379
4380                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4381                    listener.onBeforeAddAssociation(permissionId,
4382                        Group.class.getName(), groupId);
4383                }
4384
4385                _sqlUpdate.update(new Object[] {
4386                        new Long(groupId), new Long(permissionId)
4387                    });
4388
4389                for (ModelListener<Group> listener : listeners) {
4390                    listener.onAfterAddAssociation(groupId,
4391                        com.liferay.portal.model.Permission.class.getName(),
4392                        permissionId);
4393                }
4394
4395                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4396                    listener.onAfterAddAssociation(permissionId,
4397                        Group.class.getName(), groupId);
4398                }
4399            }
4400        }
4401
4402        private SqlUpdate _sqlUpdate;
4403        private GroupPersistenceImpl _persistenceImpl;
4404    }
4405
4406    protected class ClearPermissions {
4407        protected ClearPermissions(GroupPersistenceImpl persistenceImpl) {
4408            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4409                    "DELETE FROM Groups_Permissions WHERE groupId = ?",
4410                    new int[] { Types.BIGINT });
4411        }
4412
4413        protected void clear(long groupId) throws SystemException {
4414            ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4415                permissionPersistence.getListeners();
4416
4417            List<com.liferay.portal.model.Permission> permissions = null;
4418
4419            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
4420                permissions = getPermissions(groupId);
4421
4422                for (com.liferay.portal.model.Permission permission : permissions) {
4423                    for (ModelListener<Group> listener : listeners) {
4424                        listener.onBeforeRemoveAssociation(groupId,
4425                            com.liferay.portal.model.Permission.class.getName(),
4426                            permission.getPrimaryKey());
4427                    }
4428
4429                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4430                        listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
4431                            Group.class.getName(), groupId);
4432                    }
4433                }
4434            }
4435
4436            _sqlUpdate.update(new Object[] { new Long(groupId) });
4437
4438            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
4439                for (com.liferay.portal.model.Permission permission : permissions) {
4440                    for (ModelListener<Group> listener : listeners) {
4441                        listener.onAfterRemoveAssociation(groupId,
4442                            com.liferay.portal.model.Permission.class.getName(),
4443                            permission.getPrimaryKey());
4444                    }
4445
4446                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4447                        listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
4448                            Group.class.getName(), groupId);
4449                    }
4450                }
4451            }
4452        }
4453
4454        private SqlUpdate _sqlUpdate;
4455    }
4456
4457    protected class RemovePermission {
4458        protected RemovePermission(GroupPersistenceImpl persistenceImpl) {
4459            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4460                    "DELETE FROM Groups_Permissions WHERE groupId = ? AND permissionId = ?",
4461                    new int[] { Types.BIGINT, Types.BIGINT });
4462            _persistenceImpl = persistenceImpl;
4463        }
4464
4465        protected void remove(long groupId, long permissionId)
4466            throws SystemException {
4467            if (_persistenceImpl.containsPermission.contains(groupId,
4468                        permissionId)) {
4469                ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4470                    permissionPersistence.getListeners();
4471
4472                for (ModelListener<Group> listener : listeners) {
4473                    listener.onBeforeRemoveAssociation(groupId,
4474                        com.liferay.portal.model.Permission.class.getName(),
4475                        permissionId);
4476                }
4477
4478                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4479                    listener.onBeforeRemoveAssociation(permissionId,
4480                        Group.class.getName(), groupId);
4481                }
4482
4483                _sqlUpdate.update(new Object[] {
4484                        new Long(groupId), new Long(permissionId)
4485                    });
4486
4487                for (ModelListener<Group> listener : listeners) {
4488                    listener.onAfterRemoveAssociation(groupId,
4489                        com.liferay.portal.model.Permission.class.getName(),
4490                        permissionId);
4491                }
4492
4493                for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4494                    listener.onAfterRemoveAssociation(permissionId,
4495                        Group.class.getName(), groupId);
4496                }
4497            }
4498        }
4499
4500        private SqlUpdate _sqlUpdate;
4501        private GroupPersistenceImpl _persistenceImpl;
4502    }
4503
4504    protected class ContainsRole {
4505        protected ContainsRole(GroupPersistenceImpl persistenceImpl) {
4506            super();
4507
4508            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4509                    _SQL_CONTAINSROLE,
4510                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4511        }
4512
4513        protected boolean contains(long groupId, long roleId) {
4514            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4515                        new Long(groupId), new Long(roleId)
4516                    });
4517
4518            if (results.size() > 0) {
4519                Integer count = results.get(0);
4520
4521                if (count.intValue() > 0) {
4522                    return true;
4523                }
4524            }
4525
4526            return false;
4527        }
4528
4529        private MappingSqlQuery _mappingSqlQuery;
4530    }
4531
4532    protected class AddRole {
4533        protected AddRole(GroupPersistenceImpl persistenceImpl) {
4534            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4535                    "INSERT INTO Groups_Roles (groupId, roleId) VALUES (?, ?)",
4536                    new int[] { Types.BIGINT, Types.BIGINT });
4537            _persistenceImpl = persistenceImpl;
4538        }
4539
4540        protected void add(long groupId, long roleId) throws SystemException {
4541            if (!_persistenceImpl.containsRole.contains(groupId, roleId)) {
4542                ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
4543
4544                for (ModelListener<Group> listener : listeners) {
4545                    listener.onBeforeAddAssociation(groupId,
4546                        com.liferay.portal.model.Role.class.getName(), roleId);
4547                }
4548
4549                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
4550                    listener.onBeforeAddAssociation(roleId,
4551                        Group.class.getName(), groupId);
4552                }
4553
4554                _sqlUpdate.update(new Object[] {
4555                        new Long(groupId), new Long(roleId)
4556                    });
4557
4558                for (ModelListener<Group> listener : listeners) {
4559                    listener.onAfterAddAssociation(groupId,
4560                        com.liferay.portal.model.Role.class.getName(), roleId);
4561                }
4562
4563                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
4564                    listener.onAfterAddAssociation(roleId,
4565                        Group.class.getName(), groupId);
4566                }
4567            }
4568        }
4569
4570        private SqlUpdate _sqlUpdate;
4571        private GroupPersistenceImpl _persistenceImpl;
4572    }
4573
4574    protected class ClearRoles {
4575        protected ClearRoles(GroupPersistenceImpl persistenceImpl) {
4576            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4577                    "DELETE FROM Groups_Roles WHERE groupId = ?",
4578                    new int[] { Types.BIGINT });
4579        }
4580
4581        protected void clear(long groupId) throws SystemException {
4582            ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
4583
4584            List<com.liferay.portal.model.Role> roles = null;
4585
4586            if ((listeners.length > 0) || (roleListeners.length > 0)) {
4587                roles = getRoles(groupId);
4588
4589                for (com.liferay.portal.model.Role role : roles) {
4590                    for (ModelListener<Group> listener : listeners) {
4591                        listener.onBeforeRemoveAssociation(groupId,
4592                            com.liferay.portal.model.Role.class.getName(),
4593                            role.getPrimaryKey());
4594                    }
4595
4596                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
4597                        listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
4598                            Group.class.getName(), groupId);
4599                    }
4600                }
4601            }
4602
4603            _sqlUpdate.update(new Object[] { new Long(groupId) });
4604
4605            if ((listeners.length > 0) || (roleListeners.length > 0)) {
4606                for (com.liferay.portal.model.Role role : roles) {
4607                    for (ModelListener<Group> listener : listeners) {
4608                        listener.onAfterRemoveAssociation(groupId,
4609                            com.liferay.portal.model.Role.class.getName(),
4610                            role.getPrimaryKey());
4611                    }
4612
4613                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
4614                        listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
4615                            Group.class.getName(), groupId);
4616                    }
4617                }
4618            }
4619        }
4620
4621        private SqlUpdate _sqlUpdate;
4622    }
4623
4624    protected class RemoveRole {
4625        protected RemoveRole(GroupPersistenceImpl persistenceImpl) {
4626            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4627                    "DELETE FROM Groups_Roles WHERE groupId = ? AND roleId = ?",
4628                    new int[] { Types.BIGINT, Types.BIGINT });
4629            _persistenceImpl = persistenceImpl;
4630        }
4631
4632        protected void remove(long groupId, long roleId)
4633            throws SystemException {
4634            if (_persistenceImpl.containsRole.contains(groupId, roleId)) {
4635                ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
4636
4637                for (ModelListener<Group> listener : listeners) {
4638                    listener.onBeforeRemoveAssociation(groupId,
4639                        com.liferay.portal.model.Role.class.getName(), roleId);
4640                }
4641
4642                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
4643                    listener.onBeforeRemoveAssociation(roleId,
4644                        Group.class.getName(), groupId);
4645                }
4646
4647                _sqlUpdate.update(new Object[] {
4648                        new Long(groupId), new Long(roleId)
4649                    });
4650
4651                for (ModelListener<Group> listener : listeners) {
4652                    listener.onAfterRemoveAssociation(groupId,
4653                        com.liferay.portal.model.Role.class.getName(), roleId);
4654                }
4655
4656                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
4657                    listener.onAfterRemoveAssociation(roleId,
4658                        Group.class.getName(), groupId);
4659                }
4660            }
4661        }
4662
4663        private SqlUpdate _sqlUpdate;
4664        private GroupPersistenceImpl _persistenceImpl;
4665    }
4666
4667    protected class ContainsUserGroup {
4668        protected ContainsUserGroup(GroupPersistenceImpl persistenceImpl) {
4669            super();
4670
4671            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4672                    _SQL_CONTAINSUSERGROUP,
4673                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4674        }
4675
4676        protected boolean contains(long groupId, long userGroupId) {
4677            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4678                        new Long(groupId), new Long(userGroupId)
4679                    });
4680
4681            if (results.size() > 0) {
4682                Integer count = results.get(0);
4683
4684                if (count.intValue() > 0) {
4685                    return true;
4686                }
4687            }
4688
4689            return false;
4690        }
4691
4692        private MappingSqlQuery _mappingSqlQuery;
4693    }
4694
4695    protected class AddUserGroup {
4696        protected AddUserGroup(GroupPersistenceImpl persistenceImpl) {
4697            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4698                    "INSERT INTO Groups_UserGroups (groupId, userGroupId) VALUES (?, ?)",
4699                    new int[] { Types.BIGINT, Types.BIGINT });
4700            _persistenceImpl = persistenceImpl;
4701        }
4702
4703        protected void add(long groupId, long userGroupId)
4704            throws SystemException {
4705            if (!_persistenceImpl.containsUserGroup.contains(groupId,
4706                        userGroupId)) {
4707                ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
4708                    userGroupPersistence.getListeners();
4709
4710                for (ModelListener<Group> listener : listeners) {
4711                    listener.onBeforeAddAssociation(groupId,
4712                        com.liferay.portal.model.UserGroup.class.getName(),
4713                        userGroupId);
4714                }
4715
4716                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
4717                    listener.onBeforeAddAssociation(userGroupId,
4718                        Group.class.getName(), groupId);
4719                }
4720
4721                _sqlUpdate.update(new Object[] {
4722                        new Long(groupId), new Long(userGroupId)
4723                    });
4724
4725                for (ModelListener<Group> listener : listeners) {
4726                    listener.onAfterAddAssociation(groupId,
4727                        com.liferay.portal.model.UserGroup.class.getName(),
4728                        userGroupId);
4729                }
4730
4731                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
4732                    listener.onAfterAddAssociation(userGroupId,
4733                        Group.class.getName(), groupId);
4734                }
4735            }
4736        }
4737
4738        private SqlUpdate _sqlUpdate;
4739        private GroupPersistenceImpl _persistenceImpl;
4740    }
4741
4742    protected class ClearUserGroups {
4743        protected ClearUserGroups(GroupPersistenceImpl persistenceImpl) {
4744            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4745                    "DELETE FROM Groups_UserGroups WHERE groupId = ?",
4746                    new int[] { Types.BIGINT });
4747        }
4748
4749        protected void clear(long groupId) throws SystemException {
4750            ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
4751                userGroupPersistence.getListeners();
4752
4753            List<com.liferay.portal.model.UserGroup> userGroups = null;
4754
4755            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
4756                userGroups = getUserGroups(groupId);
4757
4758                for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4759                    for (ModelListener<Group> listener : listeners) {
4760                        listener.onBeforeRemoveAssociation(groupId,
4761                            com.liferay.portal.model.UserGroup.class.getName(),
4762                            userGroup.getPrimaryKey());
4763                    }
4764
4765                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
4766                        listener.onBeforeRemoveAssociation(userGroup.getPrimaryKey(),
4767                            Group.class.getName(), groupId);
4768                    }
4769                }
4770            }
4771
4772            _sqlUpdate.update(new Object[] { new Long(groupId) });
4773
4774            if ((listeners.length > 0) || (userGroupListeners.length > 0)) {
4775                for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
4776                    for (ModelListener<Group> listener : listeners) {
4777                        listener.onAfterRemoveAssociation(groupId,
4778                            com.liferay.portal.model.UserGroup.class.getName(),
4779                            userGroup.getPrimaryKey());
4780                    }
4781
4782                    for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
4783                        listener.onBeforeRemoveAssociation(userGroup.getPrimaryKey(),
4784                            Group.class.getName(), groupId);
4785                    }
4786                }
4787            }
4788        }
4789
4790        private SqlUpdate _sqlUpdate;
4791    }
4792
4793    protected class RemoveUserGroup {
4794        protected RemoveUserGroup(GroupPersistenceImpl persistenceImpl) {
4795            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4796                    "DELETE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?",
4797                    new int[] { Types.BIGINT, Types.BIGINT });
4798            _persistenceImpl = persistenceImpl;
4799        }
4800
4801        protected void remove(long groupId, long userGroupId)
4802            throws SystemException {
4803            if (_persistenceImpl.containsUserGroup.contains(groupId, userGroupId)) {
4804                ModelListener<com.liferay.portal.model.UserGroup>[] userGroupListeners =
4805                    userGroupPersistence.getListeners();
4806
4807                for (ModelListener<Group> listener : listeners) {
4808                    listener.onBeforeRemoveAssociation(groupId,
4809                        com.liferay.portal.model.UserGroup.class.getName(),
4810                        userGroupId);
4811                }
4812
4813                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
4814                    listener.onBeforeRemoveAssociation(userGroupId,
4815                        Group.class.getName(), groupId);
4816                }
4817
4818                _sqlUpdate.update(new Object[] {
4819                        new Long(groupId), new Long(userGroupId)
4820                    });
4821
4822                for (ModelListener<Group> listener : listeners) {
4823                    listener.onAfterRemoveAssociation(groupId,
4824                        com.liferay.portal.model.UserGroup.class.getName(),
4825                        userGroupId);
4826                }
4827
4828                for (ModelListener<com.liferay.portal.model.UserGroup> listener : userGroupListeners) {
4829                    listener.onAfterRemoveAssociation(userGroupId,
4830                        Group.class.getName(), groupId);
4831                }
4832            }
4833        }
4834
4835        private SqlUpdate _sqlUpdate;
4836        private GroupPersistenceImpl _persistenceImpl;
4837    }
4838
4839    protected class ContainsUser {
4840        protected ContainsUser(GroupPersistenceImpl persistenceImpl) {
4841            super();
4842
4843            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4844                    _SQL_CONTAINSUSER,
4845                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
4846        }
4847
4848        protected boolean contains(long groupId, long userId) {
4849            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4850                        new Long(groupId), new Long(userId)
4851                    });
4852
4853            if (results.size() > 0) {
4854                Integer count = results.get(0);
4855
4856                if (count.intValue() > 0) {
4857                    return true;
4858                }
4859            }
4860
4861            return false;
4862        }
4863
4864        private MappingSqlQuery _mappingSqlQuery;
4865    }
4866
4867    protected class AddUser {
4868        protected AddUser(GroupPersistenceImpl persistenceImpl) {
4869            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4870                    "INSERT INTO Users_Groups (groupId, userId) VALUES (?, ?)",
4871                    new int[] { Types.BIGINT, Types.BIGINT });
4872            _persistenceImpl = persistenceImpl;
4873        }
4874
4875        protected void add(long groupId, long userId) throws SystemException {
4876            if (!_persistenceImpl.containsUser.contains(groupId, userId)) {
4877                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4878
4879                for (ModelListener<Group> listener : listeners) {
4880                    listener.onBeforeAddAssociation(groupId,
4881                        com.liferay.portal.model.User.class.getName(), userId);
4882                }
4883
4884                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4885                    listener.onBeforeAddAssociation(userId,
4886                        Group.class.getName(), groupId);
4887                }
4888
4889                _sqlUpdate.update(new Object[] {
4890                        new Long(groupId), new Long(userId)
4891                    });
4892
4893                for (ModelListener<Group> listener : listeners) {
4894                    listener.onAfterAddAssociation(groupId,
4895                        com.liferay.portal.model.User.class.getName(), userId);
4896                }
4897
4898                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4899                    listener.onAfterAddAssociation(userId,
4900                        Group.class.getName(), groupId);
4901                }
4902            }
4903        }
4904
4905        private SqlUpdate _sqlUpdate;
4906        private GroupPersistenceImpl _persistenceImpl;
4907    }
4908
4909    protected class ClearUsers {
4910        protected ClearUsers(GroupPersistenceImpl persistenceImpl) {
4911            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4912                    "DELETE FROM Users_Groups WHERE groupId = ?",
4913                    new int[] { Types.BIGINT });
4914        }
4915
4916        protected void clear(long groupId) throws SystemException {
4917            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4918
4919            List<com.liferay.portal.model.User> users = null;
4920
4921            if ((listeners.length > 0) || (userListeners.length > 0)) {
4922                users = getUsers(groupId);
4923
4924                for (com.liferay.portal.model.User user : users) {
4925                    for (ModelListener<Group> listener : listeners) {
4926                        listener.onBeforeRemoveAssociation(groupId,
4927                            com.liferay.portal.model.User.class.getName(),
4928                            user.getPrimaryKey());
4929                    }
4930
4931                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4932                        listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4933                            Group.class.getName(), groupId);
4934                    }
4935                }
4936            }
4937
4938            _sqlUpdate.update(new Object[] { new Long(groupId) });
4939
4940            if ((listeners.length > 0) || (userListeners.length > 0)) {
4941                for (com.liferay.portal.model.User user : users) {
4942                    for (ModelListener<Group> listener : listeners) {
4943                        listener.onAfterRemoveAssociation(groupId,
4944                            com.liferay.portal.model.User.class.getName(),
4945                            user.getPrimaryKey());
4946                    }
4947
4948                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4949                        listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4950                            Group.class.getName(), groupId);
4951                    }
4952                }
4953            }
4954        }
4955
4956        private SqlUpdate _sqlUpdate;
4957    }
4958
4959    protected class RemoveUser {
4960        protected RemoveUser(GroupPersistenceImpl persistenceImpl) {
4961            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4962                    "DELETE FROM Users_Groups WHERE groupId = ? AND userId = ?",
4963                    new int[] { Types.BIGINT, Types.BIGINT });
4964            _persistenceImpl = persistenceImpl;
4965        }
4966
4967        protected void remove(long groupId, long userId)
4968            throws SystemException {
4969            if (_persistenceImpl.containsUser.contains(groupId, userId)) {
4970                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4971
4972                for (ModelListener<Group> listener : listeners) {
4973                    listener.onBeforeRemoveAssociation(groupId,
4974                        com.liferay.portal.model.User.class.getName(), userId);
4975                }
4976
4977                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4978                    listener.onBeforeRemoveAssociation(userId,
4979                        Group.class.getName(), groupId);
4980                }
4981
4982                _sqlUpdate.update(new Object[] {
4983                        new Long(groupId), new Long(userId)
4984                    });
4985
4986                for (ModelListener<Group> listener : listeners) {
4987                    listener.onAfterRemoveAssociation(groupId,
4988                        com.liferay.portal.model.User.class.getName(), userId);
4989                }
4990
4991                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4992                    listener.onAfterRemoveAssociation(userId,
4993                        Group.class.getName(), groupId);
4994                }
4995            }
4996        }
4997
4998        private SqlUpdate _sqlUpdate;
4999        private GroupPersistenceImpl _persistenceImpl;
5000    }
5001
5002    private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Groups_Orgs ON (Groups_Orgs.organizationId = Organization_.organizationId) WHERE (Groups_Orgs.groupId = ?)";
5003    private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ?";
5004    private static final String _SQL_CONTAINSORGANIZATION = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?";
5005    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Groups_Permissions ON (Groups_Permissions.permissionId = Permission_.permissionId) WHERE (Groups_Permissions.groupId = ?)";
5006    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE groupId = ?";
5007    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE groupId = ? AND permissionId = ?";
5008    private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Groups_Roles ON (Groups_Roles.roleId = Role_.roleId) WHERE (Groups_Roles.groupId = ?)";
5009    private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ?";
5010    private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ? AND roleId = ?";
5011    private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Groups_UserGroups ON (Groups_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Groups_UserGroups.groupId = ?)";
5012    private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ?";
5013    private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?";
5014    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Groups ON (Users_Groups.userId = User_.userId) WHERE (Users_Groups.groupId = ?)";
5015    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ?";
5016    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ? AND userId = ?";
5017    private static Log _log = LogFactoryUtil.getLog(GroupPersistenceImpl.class);
5018}