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