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