1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchGroupException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
28  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
29  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
30  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
31  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
32  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
33  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
34  import com.liferay.portal.kernel.dao.orm.Query;
35  import com.liferay.portal.kernel.dao.orm.QueryPos;
36  import com.liferay.portal.kernel.dao.orm.QueryUtil;
37  import com.liferay.portal.kernel.dao.orm.SQLQuery;
38  import com.liferay.portal.kernel.dao.orm.Session;
39  import com.liferay.portal.kernel.dao.orm.Type;
40  import com.liferay.portal.kernel.util.GetterUtil;
41  import com.liferay.portal.kernel.util.ListUtil;
42  import com.liferay.portal.kernel.util.OrderByComparator;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.model.Group;
46  import com.liferay.portal.model.ModelListener;
47  import com.liferay.portal.model.impl.GroupImpl;
48  import com.liferay.portal.model.impl.GroupModelImpl;
49  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
50  
51  import org.apache.commons.logging.Log;
52  import org.apache.commons.logging.LogFactory;
53  
54  import java.sql.Types;
55  
56  import java.util.ArrayList;
57  import java.util.Collections;
58  import java.util.Iterator;
59  import java.util.List;
60  
61  /**
62   * <a href="GroupPersistenceImpl.java.html"><b><i>View Source</i></b></a>
63   *
64   * @author Brian Wing Shun Chan
65   *
66   */
67  public class GroupPersistenceImpl extends BasePersistenceImpl
68      implements GroupPersistence {
69      public Group create(long groupId) {
70          Group group = new GroupImpl();
71  
72          group.setNew(true);
73          group.setPrimaryKey(groupId);
74  
75          return group;
76      }
77  
78      public Group remove(long groupId)
79          throws NoSuchGroupException, SystemException {
80          Session session = null;
81  
82          try {
83              session = openSession();
84  
85              Group group = (Group)session.get(GroupImpl.class, new Long(groupId));
86  
87              if (group == null) {
88                  if (_log.isWarnEnabled()) {
89                      _log.warn("No Group exists with the primary key " +
90                          groupId);
91                  }
92  
93                  throw new NoSuchGroupException(
94                      "No Group exists with the primary key " + groupId);
95              }
96  
97              return remove(group);
98          }
99          catch (NoSuchGroupException nsee) {
100             throw nsee;
101         }
102         catch (Exception e) {
103             throw processException(e);
104         }
105         finally {
106             closeSession(session);
107         }
108     }
109 
110     public Group remove(Group group) throws SystemException {
111         if (_listeners.length > 0) {
112             for (ModelListener listener : _listeners) {
113                 listener.onBeforeRemove(group);
114             }
115         }
116 
117         group = removeImpl(group);
118 
119         if (_listeners.length > 0) {
120             for (ModelListener listener : _listeners) {
121                 listener.onAfterRemove(group);
122             }
123         }
124 
125         return group;
126     }
127 
128     protected Group removeImpl(Group group) throws SystemException {
129         try {
130             clearOrganizations.clear(group.getPrimaryKey());
131         }
132         catch (Exception e) {
133             throw processException(e);
134         }
135         finally {
136             FinderCacheUtil.clearCache("Groups_Orgs");
137         }
138 
139         try {
140             clearPermissions.clear(group.getPrimaryKey());
141         }
142         catch (Exception e) {
143             throw processException(e);
144         }
145         finally {
146             FinderCacheUtil.clearCache("Groups_Permissions");
147         }
148 
149         try {
150             clearRoles.clear(group.getPrimaryKey());
151         }
152         catch (Exception e) {
153             throw processException(e);
154         }
155         finally {
156             FinderCacheUtil.clearCache("Groups_Roles");
157         }
158 
159         try {
160             clearUserGroups.clear(group.getPrimaryKey());
161         }
162         catch (Exception e) {
163             throw processException(e);
164         }
165         finally {
166             FinderCacheUtil.clearCache("Groups_UserGroups");
167         }
168 
169         try {
170             clearUsers.clear(group.getPrimaryKey());
171         }
172         catch (Exception e) {
173             throw processException(e);
174         }
175         finally {
176             FinderCacheUtil.clearCache("Users_Groups");
177         }
178 
179         Session session = null;
180 
181         try {
182             session = openSession();
183 
184             session.delete(group);
185 
186             session.flush();
187 
188             return group;
189         }
190         catch (Exception e) {
191             throw processException(e);
192         }
193         finally {
194             closeSession(session);
195 
196             FinderCacheUtil.clearCache(Group.class.getName());
197         }
198     }
199 
200     /**
201      * @deprecated Use <code>update(Group group, boolean merge)</code>.
202      */
203     public Group update(Group group) throws SystemException {
204         if (_log.isWarnEnabled()) {
205             _log.warn(
206                 "Using the deprecated update(Group group) method. Use update(Group group, boolean merge) instead.");
207         }
208 
209         return update(group, false);
210     }
211 
212     /**
213      * Add, update, or merge, the entity. This method also calls the model
214      * listeners to trigger the proper events associated with adding, deleting,
215      * or updating an entity.
216      *
217      * @param        group the entity to add, update, or merge
218      * @param        merge boolean value for whether to merge the entity. The
219      *                default value is false. Setting merge to true is more
220      *                expensive and should only be true when group is
221      *                transient. See LEP-5473 for a detailed discussion of this
222      *                method.
223      * @return        true if the portlet can be displayed via Ajax
224      */
225     public Group update(Group group, boolean merge) throws SystemException {
226         boolean isNew = group.isNew();
227 
228         if (_listeners.length > 0) {
229             for (ModelListener listener : _listeners) {
230                 if (isNew) {
231                     listener.onBeforeCreate(group);
232                 }
233                 else {
234                     listener.onBeforeUpdate(group);
235                 }
236             }
237         }
238 
239         group = updateImpl(group, merge);
240 
241         if (_listeners.length > 0) {
242             for (ModelListener listener : _listeners) {
243                 if (isNew) {
244                     listener.onAfterCreate(group);
245                 }
246                 else {
247                     listener.onAfterUpdate(group);
248                 }
249             }
250         }
251 
252         return group;
253     }
254 
255     public Group updateImpl(com.liferay.portal.model.Group group, boolean merge)
256         throws SystemException {
257         FinderCacheUtil.clearCache("Groups_Orgs");
258         FinderCacheUtil.clearCache("Groups_Permissions");
259         FinderCacheUtil.clearCache("Groups_Roles");
260         FinderCacheUtil.clearCache("Groups_UserGroups");
261         FinderCacheUtil.clearCache("Users_Groups");
262 
263         Session session = null;
264 
265         try {
266             session = openSession();
267 
268             if (merge) {
269                 session.merge(group);
270             }
271             else {
272                 if (group.isNew()) {
273                     session.save(group);
274                 }
275             }
276 
277             session.flush();
278 
279             group.setNew(false);
280 
281             return group;
282         }
283         catch (Exception e) {
284             throw processException(e);
285         }
286         finally {
287             closeSession(session);
288 
289             FinderCacheUtil.clearCache(Group.class.getName());
290         }
291     }
292 
293     public Group findByPrimaryKey(long groupId)
294         throws NoSuchGroupException, SystemException {
295         Group group = fetchByPrimaryKey(groupId);
296 
297         if (group == null) {
298             if (_log.isWarnEnabled()) {
299                 _log.warn("No Group exists with the primary key " + groupId);
300             }
301 
302             throw new NoSuchGroupException(
303                 "No Group exists with the primary key " + groupId);
304         }
305 
306         return group;
307     }
308 
309     public Group fetchByPrimaryKey(long groupId) throws SystemException {
310         Session session = null;
311 
312         try {
313             session = openSession();
314 
315             return (Group)session.get(GroupImpl.class, new Long(groupId));
316         }
317         catch (Exception e) {
318             throw processException(e);
319         }
320         finally {
321             closeSession(session);
322         }
323     }
324 
325     public Group findByLiveGroupId(long liveGroupId)
326         throws NoSuchGroupException, SystemException {
327         Group group = fetchByLiveGroupId(liveGroupId);
328 
329         if (group == null) {
330             StringBuilder msg = new StringBuilder();
331 
332             msg.append("No Group exists with the key {");
333 
334             msg.append("liveGroupId=" + liveGroupId);
335 
336             msg.append(StringPool.CLOSE_CURLY_BRACE);
337 
338             if (_log.isWarnEnabled()) {
339                 _log.warn(msg.toString());
340             }
341 
342             throw new NoSuchGroupException(msg.toString());
343         }
344 
345         return group;
346     }
347 
348     public Group fetchByLiveGroupId(long liveGroupId) throws SystemException {
349         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
350         String finderClassName = Group.class.getName();
351         String finderMethodName = "fetchByLiveGroupId";
352         String[] finderParams = new String[] { Long.class.getName() };
353         Object[] finderArgs = new Object[] { new Long(liveGroupId) };
354 
355         Object result = null;
356 
357         if (finderClassNameCacheEnabled) {
358             result = FinderCacheUtil.getResult(finderClassName,
359                     finderMethodName, finderParams, finderArgs, this);
360         }
361 
362         if (result == null) {
363             Session session = null;
364 
365             try {
366                 session = openSession();
367 
368                 StringBuilder query = new StringBuilder();
369 
370                 query.append("FROM com.liferay.portal.model.Group WHERE ");
371 
372                 query.append("liveGroupId = ?");
373 
374                 query.append(" ");
375 
376                 query.append("ORDER BY ");
377 
378                 query.append("name ASC");
379 
380                 Query q = session.createQuery(query.toString());
381 
382                 QueryPos qPos = QueryPos.getInstance(q);
383 
384                 qPos.add(liveGroupId);
385 
386                 List<Group> list = q.list();
387 
388                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
389                     finderClassName, finderMethodName, finderParams,
390                     finderArgs, list);
391 
392                 if (list.size() == 0) {
393                     return null;
394                 }
395                 else {
396                     return list.get(0);
397                 }
398             }
399             catch (Exception e) {
400                 throw processException(e);
401             }
402             finally {
403                 closeSession(session);
404             }
405         }
406         else {
407             List<Group> list = (List<Group>)result;
408 
409             if (list.size() == 0) {
410                 return null;
411             }
412             else {
413                 return list.get(0);
414             }
415         }
416     }
417 
418     public Group findByC_N(long companyId, String name)
419         throws NoSuchGroupException, SystemException {
420         Group group = fetchByC_N(companyId, name);
421 
422         if (group == null) {
423             StringBuilder msg = new StringBuilder();
424 
425             msg.append("No Group exists with the key {");
426 
427             msg.append("companyId=" + companyId);
428 
429             msg.append(", ");
430             msg.append("name=" + name);
431 
432             msg.append(StringPool.CLOSE_CURLY_BRACE);
433 
434             if (_log.isWarnEnabled()) {
435                 _log.warn(msg.toString());
436             }
437 
438             throw new NoSuchGroupException(msg.toString());
439         }
440 
441         return group;
442     }
443 
444     public Group fetchByC_N(long companyId, String name)
445         throws SystemException {
446         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
447         String finderClassName = Group.class.getName();
448         String finderMethodName = "fetchByC_N";
449         String[] finderParams = new String[] {
450                 Long.class.getName(), String.class.getName()
451             };
452         Object[] finderArgs = new Object[] { new Long(companyId), name };
453 
454         Object result = null;
455 
456         if (finderClassNameCacheEnabled) {
457             result = FinderCacheUtil.getResult(finderClassName,
458                     finderMethodName, finderParams, finderArgs, this);
459         }
460 
461         if (result == null) {
462             Session session = null;
463 
464             try {
465                 session = openSession();
466 
467                 StringBuilder query = new StringBuilder();
468 
469                 query.append("FROM com.liferay.portal.model.Group WHERE ");
470 
471                 query.append("companyId = ?");
472 
473                 query.append(" AND ");
474 
475                 if (name == null) {
476                     query.append("name IS NULL");
477                 }
478                 else {
479                     query.append("name = ?");
480                 }
481 
482                 query.append(" ");
483 
484                 query.append("ORDER BY ");
485 
486                 query.append("name ASC");
487 
488                 Query q = session.createQuery(query.toString());
489 
490                 QueryPos qPos = QueryPos.getInstance(q);
491 
492                 qPos.add(companyId);
493 
494                 if (name != null) {
495                     qPos.add(name);
496                 }
497 
498                 List<Group> list = q.list();
499 
500                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
501                     finderClassName, finderMethodName, finderParams,
502                     finderArgs, list);
503 
504                 if (list.size() == 0) {
505                     return null;
506                 }
507                 else {
508                     return list.get(0);
509                 }
510             }
511             catch (Exception e) {
512                 throw processException(e);
513             }
514             finally {
515                 closeSession(session);
516             }
517         }
518         else {
519             List<Group> list = (List<Group>)result;
520 
521             if (list.size() == 0) {
522                 return null;
523             }
524             else {
525                 return list.get(0);
526             }
527         }
528     }
529 
530     public Group findByC_F(long companyId, String friendlyURL)
531         throws NoSuchGroupException, SystemException {
532         Group group = fetchByC_F(companyId, friendlyURL);
533 
534         if (group == null) {
535             StringBuilder msg = new StringBuilder();
536 
537             msg.append("No Group exists with the key {");
538 
539             msg.append("companyId=" + companyId);
540 
541             msg.append(", ");
542             msg.append("friendlyURL=" + friendlyURL);
543 
544             msg.append(StringPool.CLOSE_CURLY_BRACE);
545 
546             if (_log.isWarnEnabled()) {
547                 _log.warn(msg.toString());
548             }
549 
550             throw new NoSuchGroupException(msg.toString());
551         }
552 
553         return group;
554     }
555 
556     public Group fetchByC_F(long companyId, String friendlyURL)
557         throws SystemException {
558         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
559         String finderClassName = Group.class.getName();
560         String finderMethodName = "fetchByC_F";
561         String[] finderParams = new String[] {
562                 Long.class.getName(), String.class.getName()
563             };
564         Object[] finderArgs = new Object[] { new Long(companyId), friendlyURL };
565 
566         Object result = null;
567 
568         if (finderClassNameCacheEnabled) {
569             result = FinderCacheUtil.getResult(finderClassName,
570                     finderMethodName, finderParams, finderArgs, this);
571         }
572 
573         if (result == null) {
574             Session session = null;
575 
576             try {
577                 session = openSession();
578 
579                 StringBuilder query = new StringBuilder();
580 
581                 query.append("FROM com.liferay.portal.model.Group WHERE ");
582 
583                 query.append("companyId = ?");
584 
585                 query.append(" AND ");
586 
587                 if (friendlyURL == null) {
588                     query.append("friendlyURL IS NULL");
589                 }
590                 else {
591                     query.append("lower(friendlyURL) = ?");
592                 }
593 
594                 query.append(" ");
595 
596                 query.append("ORDER BY ");
597 
598                 query.append("name ASC");
599 
600                 Query q = session.createQuery(query.toString());
601 
602                 QueryPos qPos = QueryPos.getInstance(q);
603 
604                 qPos.add(companyId);
605 
606                 if (friendlyURL != null) {
607                     qPos.add(friendlyURL);
608                 }
609 
610                 List<Group> list = q.list();
611 
612                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
613                     finderClassName, finderMethodName, finderParams,
614                     finderArgs, list);
615 
616                 if (list.size() == 0) {
617                     return null;
618                 }
619                 else {
620                     return list.get(0);
621                 }
622             }
623             catch (Exception e) {
624                 throw processException(e);
625             }
626             finally {
627                 closeSession(session);
628             }
629         }
630         else {
631             List<Group> list = (List<Group>)result;
632 
633             if (list.size() == 0) {
634                 return null;
635             }
636             else {
637                 return list.get(0);
638             }
639         }
640     }
641 
642     public Group findByC_C_C(long companyId, long classNameId, long classPK)
643         throws NoSuchGroupException, SystemException {
644         Group group = fetchByC_C_C(companyId, classNameId, classPK);
645 
646         if (group == null) {
647             StringBuilder msg = new StringBuilder();
648 
649             msg.append("No Group exists with the key {");
650 
651             msg.append("companyId=" + companyId);
652 
653             msg.append(", ");
654             msg.append("classNameId=" + classNameId);
655 
656             msg.append(", ");
657             msg.append("classPK=" + classPK);
658 
659             msg.append(StringPool.CLOSE_CURLY_BRACE);
660 
661             if (_log.isWarnEnabled()) {
662                 _log.warn(msg.toString());
663             }
664 
665             throw new NoSuchGroupException(msg.toString());
666         }
667 
668         return group;
669     }
670 
671     public Group fetchByC_C_C(long companyId, long classNameId, long classPK)
672         throws SystemException {
673         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
674         String finderClassName = Group.class.getName();
675         String finderMethodName = "fetchByC_C_C";
676         String[] finderParams = new String[] {
677                 Long.class.getName(), Long.class.getName(), Long.class.getName()
678             };
679         Object[] finderArgs = new Object[] {
680                 new Long(companyId), new Long(classNameId), new Long(classPK)
681             };
682 
683         Object result = null;
684 
685         if (finderClassNameCacheEnabled) {
686             result = FinderCacheUtil.getResult(finderClassName,
687                     finderMethodName, finderParams, finderArgs, this);
688         }
689 
690         if (result == null) {
691             Session session = null;
692 
693             try {
694                 session = openSession();
695 
696                 StringBuilder query = new StringBuilder();
697 
698                 query.append("FROM com.liferay.portal.model.Group WHERE ");
699 
700                 query.append("companyId = ?");
701 
702                 query.append(" AND ");
703 
704                 query.append("classNameId = ?");
705 
706                 query.append(" AND ");
707 
708                 query.append("classPK = ?");
709 
710                 query.append(" ");
711 
712                 query.append("ORDER BY ");
713 
714                 query.append("name ASC");
715 
716                 Query q = session.createQuery(query.toString());
717 
718                 QueryPos qPos = QueryPos.getInstance(q);
719 
720                 qPos.add(companyId);
721 
722                 qPos.add(classNameId);
723 
724                 qPos.add(classPK);
725 
726                 List<Group> list = q.list();
727 
728                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
729                     finderClassName, finderMethodName, finderParams,
730                     finderArgs, list);
731 
732                 if (list.size() == 0) {
733                     return null;
734                 }
735                 else {
736                     return list.get(0);
737                 }
738             }
739             catch (Exception e) {
740                 throw processException(e);
741             }
742             finally {
743                 closeSession(session);
744             }
745         }
746         else {
747             List<Group> list = (List<Group>)result;
748 
749             if (list.size() == 0) {
750                 return null;
751             }
752             else {
753                 return list.get(0);
754             }
755         }
756     }
757 
758     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
759         throws SystemException {
760         Session session = null;
761 
762         try {
763             session = openSession();
764 
765             dynamicQuery.compile(session);
766 
767             return dynamicQuery.list();
768         }
769         catch (Exception e) {
770             throw processException(e);
771         }
772         finally {
773             closeSession(session);
774         }
775     }
776 
777     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
778         int start, int end) throws SystemException {
779         Session session = null;
780 
781         try {
782             session = openSession();
783 
784             dynamicQuery.setLimit(start, end);
785 
786             dynamicQuery.compile(session);
787 
788             return dynamicQuery.list();
789         }
790         catch (Exception e) {
791             throw processException(e);
792         }
793         finally {
794             closeSession(session);
795         }
796     }
797 
798     public List<Group> findAll() throws SystemException {
799         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
800     }
801 
802     public List<Group> findAll(int start, int end) throws SystemException {
803         return findAll(start, end, null);
804     }
805 
806     public List<Group> findAll(int start, int end, OrderByComparator obc)
807         throws SystemException {
808         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
809         String finderClassName = Group.class.getName();
810         String finderMethodName = "findAll";
811         String[] finderParams = new String[] {
812                 "java.lang.Integer", "java.lang.Integer",
813                 "com.liferay.portal.kernel.util.OrderByComparator"
814             };
815         Object[] finderArgs = new Object[] {
816                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
817             };
818 
819         Object result = null;
820 
821         if (finderClassNameCacheEnabled) {
822             result = FinderCacheUtil.getResult(finderClassName,
823                     finderMethodName, finderParams, finderArgs, this);
824         }
825 
826         if (result == null) {
827             Session session = null;
828 
829             try {
830                 session = openSession();
831 
832                 StringBuilder query = new StringBuilder();
833 
834                 query.append("FROM com.liferay.portal.model.Group ");
835 
836                 if (obc != null) {
837                     query.append("ORDER BY ");
838                     query.append(obc.getOrderBy());
839                 }
840 
841                 else {
842                     query.append("ORDER BY ");
843 
844                     query.append("name ASC");
845                 }
846 
847                 Query q = session.createQuery(query.toString());
848 
849                 List<Group> list = (List<Group>)QueryUtil.list(q, getDialect(),
850                         start, end);
851 
852                 if (obc == null) {
853                     Collections.sort(list);
854                 }
855 
856                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
857                     finderClassName, finderMethodName, finderParams,
858                     finderArgs, list);
859 
860                 return list;
861             }
862             catch (Exception e) {
863                 throw processException(e);
864             }
865             finally {
866                 closeSession(session);
867             }
868         }
869         else {
870             return (List<Group>)result;
871         }
872     }
873 
874     public void removeByLiveGroupId(long liveGroupId)
875         throws NoSuchGroupException, SystemException {
876         Group group = findByLiveGroupId(liveGroupId);
877 
878         remove(group);
879     }
880 
881     public void removeByC_N(long companyId, String name)
882         throws NoSuchGroupException, SystemException {
883         Group group = findByC_N(companyId, name);
884 
885         remove(group);
886     }
887 
888     public void removeByC_F(long companyId, String friendlyURL)
889         throws NoSuchGroupException, SystemException {
890         Group group = findByC_F(companyId, friendlyURL);
891 
892         remove(group);
893     }
894 
895     public void removeByC_C_C(long companyId, long classNameId, long classPK)
896         throws NoSuchGroupException, SystemException {
897         Group group = findByC_C_C(companyId, classNameId, classPK);
898 
899         remove(group);
900     }
901 
902     public void removeAll() throws SystemException {
903         for (Group group : findAll()) {
904             remove(group);
905         }
906     }
907 
908     public int countByLiveGroupId(long liveGroupId) throws SystemException {
909         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
910         String finderClassName = Group.class.getName();
911         String finderMethodName = "countByLiveGroupId";
912         String[] finderParams = new String[] { Long.class.getName() };
913         Object[] finderArgs = new Object[] { new Long(liveGroupId) };
914 
915         Object result = null;
916 
917         if (finderClassNameCacheEnabled) {
918             result = FinderCacheUtil.getResult(finderClassName,
919                     finderMethodName, finderParams, finderArgs, this);
920         }
921 
922         if (result == null) {
923             Session session = null;
924 
925             try {
926                 session = openSession();
927 
928                 StringBuilder query = new StringBuilder();
929 
930                 query.append("SELECT COUNT(*) ");
931                 query.append("FROM com.liferay.portal.model.Group WHERE ");
932 
933                 query.append("liveGroupId = ?");
934 
935                 query.append(" ");
936 
937                 Query q = session.createQuery(query.toString());
938 
939                 QueryPos qPos = QueryPos.getInstance(q);
940 
941                 qPos.add(liveGroupId);
942 
943                 Long count = null;
944 
945                 Iterator<Long> itr = q.list().iterator();
946 
947                 if (itr.hasNext()) {
948                     count = itr.next();
949                 }
950 
951                 if (count == null) {
952                     count = new Long(0);
953                 }
954 
955                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
956                     finderClassName, finderMethodName, finderParams,
957                     finderArgs, count);
958 
959                 return count.intValue();
960             }
961             catch (Exception e) {
962                 throw processException(e);
963             }
964             finally {
965                 closeSession(session);
966             }
967         }
968         else {
969             return ((Long)result).intValue();
970         }
971     }
972 
973     public int countByC_N(long companyId, String name)
974         throws SystemException {
975         boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
976         String finderClassName = Group.class.getName();
977         String finderMethodName = "countByC_N";
978         String[] finderParams = new String[] {
979                 Long.class.getName(), String.class.getName()
980             };
981         Object[] finderArgs = new Object[] { new Long(companyId), name };
982 
983         Object result = null;
984 
985         if (finderClassNameCacheEnabled) {
986             result = FinderCacheUtil.getResult(finderClassName,
987                     finderMethodName, finderParams, finderArgs, this);
988         }
989 
990         if (result == null) {
991             Session session = null;
992 
993             try {
994                 session = openSession();
995 
996                 StringBuilder query = new StringBuilder();
997 
998                 query.append("SELECT COUNT(*) ");
999                 query.append("FROM com.liferay.portal.model.Group WHERE ");
1000
1001                query.append("companyId = ?");
1002
1003                query.append(" AND ");
1004
1005                if (name == null) {
1006                    query.append("name IS NULL");
1007                }
1008                else {
1009                    query.append("name = ?");
1010                }
1011
1012                query.append(" ");
1013
1014                Query q = session.createQuery(query.toString());
1015
1016                QueryPos qPos = QueryPos.getInstance(q);
1017
1018                qPos.add(companyId);
1019
1020                if (name != null) {
1021                    qPos.add(name);
1022                }
1023
1024                Long count = null;
1025
1026                Iterator<Long> itr = q.list().iterator();
1027
1028                if (itr.hasNext()) {
1029                    count = itr.next();
1030                }
1031
1032                if (count == null) {
1033                    count = new Long(0);
1034                }
1035
1036                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1037                    finderClassName, finderMethodName, finderParams,
1038                    finderArgs, count);
1039
1040                return count.intValue();
1041            }
1042            catch (Exception e) {
1043                throw processException(e);
1044            }
1045            finally {
1046                closeSession(session);
1047            }
1048        }
1049        else {
1050            return ((Long)result).intValue();
1051        }
1052    }
1053
1054    public int countByC_F(long companyId, String friendlyURL)
1055        throws SystemException {
1056        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
1057        String finderClassName = Group.class.getName();
1058        String finderMethodName = "countByC_F";
1059        String[] finderParams = new String[] {
1060                Long.class.getName(), String.class.getName()
1061            };
1062        Object[] finderArgs = new Object[] { new Long(companyId), friendlyURL };
1063
1064        Object result = null;
1065
1066        if (finderClassNameCacheEnabled) {
1067            result = FinderCacheUtil.getResult(finderClassName,
1068                    finderMethodName, finderParams, finderArgs, this);
1069        }
1070
1071        if (result == null) {
1072            Session session = null;
1073
1074            try {
1075                session = openSession();
1076
1077                StringBuilder query = new StringBuilder();
1078
1079                query.append("SELECT COUNT(*) ");
1080                query.append("FROM com.liferay.portal.model.Group WHERE ");
1081
1082                query.append("companyId = ?");
1083
1084                query.append(" AND ");
1085
1086                if (friendlyURL == null) {
1087                    query.append("friendlyURL IS NULL");
1088                }
1089                else {
1090                    query.append("lower(friendlyURL) = ?");
1091                }
1092
1093                query.append(" ");
1094
1095                Query q = session.createQuery(query.toString());
1096
1097                QueryPos qPos = QueryPos.getInstance(q);
1098
1099                qPos.add(companyId);
1100
1101                if (friendlyURL != null) {
1102                    qPos.add(friendlyURL);
1103                }
1104
1105                Long count = null;
1106
1107                Iterator<Long> itr = q.list().iterator();
1108
1109                if (itr.hasNext()) {
1110                    count = itr.next();
1111                }
1112
1113                if (count == null) {
1114                    count = new Long(0);
1115                }
1116
1117                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1118                    finderClassName, finderMethodName, finderParams,
1119                    finderArgs, count);
1120
1121                return count.intValue();
1122            }
1123            catch (Exception e) {
1124                throw processException(e);
1125            }
1126            finally {
1127                closeSession(session);
1128            }
1129        }
1130        else {
1131            return ((Long)result).intValue();
1132        }
1133    }
1134
1135    public int countByC_C_C(long companyId, long classNameId, long classPK)
1136        throws SystemException {
1137        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
1138        String finderClassName = Group.class.getName();
1139        String finderMethodName = "countByC_C_C";
1140        String[] finderParams = new String[] {
1141                Long.class.getName(), Long.class.getName(), Long.class.getName()
1142            };
1143        Object[] finderArgs = new Object[] {
1144                new Long(companyId), new Long(classNameId), new Long(classPK)
1145            };
1146
1147        Object result = null;
1148
1149        if (finderClassNameCacheEnabled) {
1150            result = FinderCacheUtil.getResult(finderClassName,
1151                    finderMethodName, finderParams, finderArgs, this);
1152        }
1153
1154        if (result == null) {
1155            Session session = null;
1156
1157            try {
1158                session = openSession();
1159
1160                StringBuilder query = new StringBuilder();
1161
1162                query.append("SELECT COUNT(*) ");
1163                query.append("FROM com.liferay.portal.model.Group WHERE ");
1164
1165                query.append("companyId = ?");
1166
1167                query.append(" AND ");
1168
1169                query.append("classNameId = ?");
1170
1171                query.append(" AND ");
1172
1173                query.append("classPK = ?");
1174
1175                query.append(" ");
1176
1177                Query q = session.createQuery(query.toString());
1178
1179                QueryPos qPos = QueryPos.getInstance(q);
1180
1181                qPos.add(companyId);
1182
1183                qPos.add(classNameId);
1184
1185                qPos.add(classPK);
1186
1187                Long count = null;
1188
1189                Iterator<Long> itr = q.list().iterator();
1190
1191                if (itr.hasNext()) {
1192                    count = itr.next();
1193                }
1194
1195                if (count == null) {
1196                    count = new Long(0);
1197                }
1198
1199                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1200                    finderClassName, finderMethodName, finderParams,
1201                    finderArgs, count);
1202
1203                return count.intValue();
1204            }
1205            catch (Exception e) {
1206                throw processException(e);
1207            }
1208            finally {
1209                closeSession(session);
1210            }
1211        }
1212        else {
1213            return ((Long)result).intValue();
1214        }
1215    }
1216
1217    public int countAll() throws SystemException {
1218        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED;
1219        String finderClassName = Group.class.getName();
1220        String finderMethodName = "countAll";
1221        String[] finderParams = new String[] {  };
1222        Object[] finderArgs = new Object[] {  };
1223
1224        Object result = null;
1225
1226        if (finderClassNameCacheEnabled) {
1227            result = FinderCacheUtil.getResult(finderClassName,
1228                    finderMethodName, finderParams, finderArgs, this);
1229        }
1230
1231        if (result == null) {
1232            Session session = null;
1233
1234            try {
1235                session = openSession();
1236
1237                Query q = session.createQuery(
1238                        "SELECT COUNT(*) FROM com.liferay.portal.model.Group");
1239
1240                Long count = null;
1241
1242                Iterator<Long> itr = q.list().iterator();
1243
1244                if (itr.hasNext()) {
1245                    count = itr.next();
1246                }
1247
1248                if (count == null) {
1249                    count = new Long(0);
1250                }
1251
1252                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1253                    finderClassName, finderMethodName, finderParams,
1254                    finderArgs, count);
1255
1256                return count.intValue();
1257            }
1258            catch (Exception e) {
1259                throw processException(e);
1260            }
1261            finally {
1262                closeSession(session);
1263            }
1264        }
1265        else {
1266            return ((Long)result).intValue();
1267        }
1268    }
1269
1270    public List<com.liferay.portal.model.Organization> getOrganizations(long pk)
1271        throws SystemException {
1272        return getOrganizations(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1273    }
1274
1275    public List<com.liferay.portal.model.Organization> getOrganizations(
1276        long pk, int start, int end) throws SystemException {
1277        return getOrganizations(pk, start, end, null);
1278    }
1279
1280    public List<com.liferay.portal.model.Organization> getOrganizations(
1281        long pk, int start, int end, OrderByComparator obc)
1282        throws SystemException {
1283        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1284
1285        String finderClassName = "Groups_Orgs";
1286
1287        String finderMethodName = "getOrganizations";
1288        String[] finderParams = new String[] {
1289                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1290                "com.liferay.portal.kernel.util.OrderByComparator"
1291            };
1292        Object[] finderArgs = new Object[] {
1293                new Long(pk), String.valueOf(start), String.valueOf(end),
1294                String.valueOf(obc)
1295            };
1296
1297        Object result = null;
1298
1299        if (finderClassNameCacheEnabled) {
1300            result = FinderCacheUtil.getResult(finderClassName,
1301                    finderMethodName, finderParams, finderArgs, this);
1302        }
1303
1304        if (result == null) {
1305            Session session = null;
1306
1307            try {
1308                session = openSession();
1309
1310                StringBuilder sb = new StringBuilder();
1311
1312                sb.append(_SQL_GETORGANIZATIONS);
1313
1314                if (obc != null) {
1315                    sb.append("ORDER BY ");
1316                    sb.append(obc.getOrderBy());
1317                }
1318
1319                else {
1320                    sb.append("ORDER BY ");
1321
1322                    sb.append("Organization_.name ASC");
1323                }
1324
1325                String sql = sb.toString();
1326
1327                SQLQuery q = session.createSQLQuery(sql);
1328
1329                q.addEntity("Organization_",
1330                    com.liferay.portal.model.impl.OrganizationImpl.class);
1331
1332                QueryPos qPos = QueryPos.getInstance(q);
1333
1334                qPos.add(pk);
1335
1336                List<com.liferay.portal.model.Organization> list = (List<com.liferay.portal.model.Organization>)QueryUtil.list(q,
1337                        getDialect(), start, end);
1338
1339                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1340                    finderClassName, finderMethodName, finderParams,
1341                    finderArgs, list);
1342
1343                return list;
1344            }
1345            catch (Exception e) {
1346                throw processException(e);
1347            }
1348            finally {
1349                closeSession(session);
1350            }
1351        }
1352        else {
1353            return (List<com.liferay.portal.model.Organization>)result;
1354        }
1355    }
1356
1357    public int getOrganizationsSize(long pk) throws SystemException {
1358        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1359
1360        String finderClassName = "Groups_Orgs";
1361
1362        String finderMethodName = "getOrganizationsSize";
1363        String[] finderParams = new String[] { Long.class.getName() };
1364        Object[] finderArgs = new Object[] { new Long(pk) };
1365
1366        Object result = null;
1367
1368        if (finderClassNameCacheEnabled) {
1369            result = FinderCacheUtil.getResult(finderClassName,
1370                    finderMethodName, finderParams, finderArgs, this);
1371        }
1372
1373        if (result == null) {
1374            Session session = null;
1375
1376            try {
1377                session = openSession();
1378
1379                SQLQuery q = session.createSQLQuery(_SQL_GETORGANIZATIONSSIZE);
1380
1381                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1382
1383                QueryPos qPos = QueryPos.getInstance(q);
1384
1385                qPos.add(pk);
1386
1387                Long count = null;
1388
1389                Iterator<Long> itr = q.list().iterator();
1390
1391                if (itr.hasNext()) {
1392                    count = itr.next();
1393                }
1394
1395                if (count == null) {
1396                    count = new Long(0);
1397                }
1398
1399                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1400                    finderClassName, finderMethodName, finderParams,
1401                    finderArgs, count);
1402
1403                return count.intValue();
1404            }
1405            catch (Exception e) {
1406                throw processException(e);
1407            }
1408            finally {
1409                closeSession(session);
1410            }
1411        }
1412        else {
1413            return ((Long)result).intValue();
1414        }
1415    }
1416
1417    public boolean containsOrganization(long pk, long organizationPK)
1418        throws SystemException {
1419        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ORGS;
1420
1421        String finderClassName = "Groups_Orgs";
1422
1423        String finderMethodName = "containsOrganizations";
1424        String[] finderParams = new String[] {
1425                Long.class.getName(),
1426                
1427                Long.class.getName()
1428            };
1429        Object[] finderArgs = new Object[] {
1430                new Long(pk),
1431                
1432                new Long(organizationPK)
1433            };
1434
1435        Object result = null;
1436
1437        if (finderClassNameCacheEnabled) {
1438            result = FinderCacheUtil.getResult(finderClassName,
1439                    finderMethodName, finderParams, finderArgs, this);
1440        }
1441
1442        if (result == null) {
1443            try {
1444                Boolean value = Boolean.valueOf(containsOrganization.contains(
1445                            pk, organizationPK));
1446
1447                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1448                    finderClassName, finderMethodName, finderParams,
1449                    finderArgs, value);
1450
1451                return value.booleanValue();
1452            }
1453            catch (Exception e) {
1454                throw processException(e);
1455            }
1456        }
1457        else {
1458            return ((Boolean)result).booleanValue();
1459        }
1460    }
1461
1462    public boolean containsOrganizations(long pk) throws SystemException {
1463        if (getOrganizationsSize(pk) > 0) {
1464            return true;
1465        }
1466        else {
1467            return false;
1468        }
1469    }
1470
1471    public void addOrganization(long pk, long organizationPK)
1472        throws SystemException {
1473        try {
1474            addOrganization.add(pk, organizationPK);
1475        }
1476        catch (Exception e) {
1477            throw processException(e);
1478        }
1479        finally {
1480            FinderCacheUtil.clearCache("Groups_Orgs");
1481        }
1482    }
1483
1484    public void addOrganization(long pk,
1485        com.liferay.portal.model.Organization organization)
1486        throws SystemException {
1487        try {
1488            addOrganization.add(pk, organization.getPrimaryKey());
1489        }
1490        catch (Exception e) {
1491            throw processException(e);
1492        }
1493        finally {
1494            FinderCacheUtil.clearCache("Groups_Orgs");
1495        }
1496    }
1497
1498    public void addOrganizations(long pk, long[] organizationPKs)
1499        throws SystemException {
1500        try {
1501            for (long organizationPK : organizationPKs) {
1502                addOrganization.add(pk, organizationPK);
1503            }
1504        }
1505        catch (Exception e) {
1506            throw processException(e);
1507        }
1508        finally {
1509            FinderCacheUtil.clearCache("Groups_Orgs");
1510        }
1511    }
1512
1513    public void addOrganizations(long pk,
1514        List<com.liferay.portal.model.Organization> organizations)
1515        throws SystemException {
1516        try {
1517            for (com.liferay.portal.model.Organization organization : organizations) {
1518                addOrganization.add(pk, organization.getPrimaryKey());
1519            }
1520        }
1521        catch (Exception e) {
1522            throw processException(e);
1523        }
1524        finally {
1525            FinderCacheUtil.clearCache("Groups_Orgs");
1526        }
1527    }
1528
1529    public void clearOrganizations(long pk) throws SystemException {
1530        try {
1531            clearOrganizations.clear(pk);
1532        }
1533        catch (Exception e) {
1534            throw processException(e);
1535        }
1536        finally {
1537            FinderCacheUtil.clearCache("Groups_Orgs");
1538        }
1539    }
1540
1541    public void removeOrganization(long pk, long organizationPK)
1542        throws SystemException {
1543        try {
1544            removeOrganization.remove(pk, organizationPK);
1545        }
1546        catch (Exception e) {
1547            throw processException(e);
1548        }
1549        finally {
1550            FinderCacheUtil.clearCache("Groups_Orgs");
1551        }
1552    }
1553
1554    public void removeOrganization(long pk,
1555        com.liferay.portal.model.Organization organization)
1556        throws SystemException {
1557        try {
1558            removeOrganization.remove(pk, organization.getPrimaryKey());
1559        }
1560        catch (Exception e) {
1561            throw processException(e);
1562        }
1563        finally {
1564            FinderCacheUtil.clearCache("Groups_Orgs");
1565        }
1566    }
1567
1568    public void removeOrganizations(long pk, long[] organizationPKs)
1569        throws SystemException {
1570        try {
1571            for (long organizationPK : organizationPKs) {
1572                removeOrganization.remove(pk, organizationPK);
1573            }
1574        }
1575        catch (Exception e) {
1576            throw processException(e);
1577        }
1578        finally {
1579            FinderCacheUtil.clearCache("Groups_Orgs");
1580        }
1581    }
1582
1583    public void removeOrganizations(long pk,
1584        List<com.liferay.portal.model.Organization> organizations)
1585        throws SystemException {
1586        try {
1587            for (com.liferay.portal.model.Organization organization : organizations) {
1588                removeOrganization.remove(pk, organization.getPrimaryKey());
1589            }
1590        }
1591        catch (Exception e) {
1592            throw processException(e);
1593        }
1594        finally {
1595            FinderCacheUtil.clearCache("Groups_Orgs");
1596        }
1597    }
1598
1599    public void setOrganizations(long pk, long[] organizationPKs)
1600        throws SystemException {
1601        try {
1602            clearOrganizations.clear(pk);
1603
1604            for (long organizationPK : organizationPKs) {
1605                addOrganization.add(pk, organizationPK);
1606            }
1607        }
1608        catch (Exception e) {
1609            throw processException(e);
1610        }
1611        finally {
1612            FinderCacheUtil.clearCache("Groups_Orgs");
1613        }
1614    }
1615
1616    public void setOrganizations(long pk,
1617        List<com.liferay.portal.model.Organization> organizations)
1618        throws SystemException {
1619        try {
1620            clearOrganizations.clear(pk);
1621
1622            for (com.liferay.portal.model.Organization organization : organizations) {
1623                addOrganization.add(pk, organization.getPrimaryKey());
1624            }
1625        }
1626        catch (Exception e) {
1627            throw processException(e);
1628        }
1629        finally {
1630            FinderCacheUtil.clearCache("Groups_Orgs");
1631        }
1632    }
1633
1634    public List<com.liferay.portal.model.Permission> getPermissions(long pk)
1635        throws SystemException {
1636        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1637    }
1638
1639    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
1640        int start, int end) throws SystemException {
1641        return getPermissions(pk, start, end, null);
1642    }
1643
1644    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
1645        int start, int end, OrderByComparator obc) throws SystemException {
1646        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
1647
1648        String finderClassName = "Groups_Permissions";
1649
1650        String finderMethodName = "getPermissions";
1651        String[] finderParams = new String[] {
1652                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1653                "com.liferay.portal.kernel.util.OrderByComparator"
1654            };
1655        Object[] finderArgs = new Object[] {
1656                new Long(pk), String.valueOf(start), String.valueOf(end),
1657                String.valueOf(obc)
1658            };
1659
1660        Object result = null;
1661
1662        if (finderClassNameCacheEnabled) {
1663            result = FinderCacheUtil.getResult(finderClassName,
1664                    finderMethodName, finderParams, finderArgs, this);
1665        }
1666
1667        if (result == null) {
1668            Session session = null;
1669
1670            try {
1671                session = openSession();
1672
1673                StringBuilder sb = new StringBuilder();
1674
1675                sb.append(_SQL_GETPERMISSIONS);
1676
1677                if (obc != null) {
1678                    sb.append("ORDER BY ");
1679                    sb.append(obc.getOrderBy());
1680                }
1681
1682                String sql = sb.toString();
1683
1684                SQLQuery q = session.createSQLQuery(sql);
1685
1686                q.addEntity("Permission_",
1687                    com.liferay.portal.model.impl.PermissionImpl.class);
1688
1689                QueryPos qPos = QueryPos.getInstance(q);
1690
1691                qPos.add(pk);
1692
1693                List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
1694                        getDialect(), start, end);
1695
1696                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1697                    finderClassName, finderMethodName, finderParams,
1698                    finderArgs, list);
1699
1700                return list;
1701            }
1702            catch (Exception e) {
1703                throw processException(e);
1704            }
1705            finally {
1706                closeSession(session);
1707            }
1708        }
1709        else {
1710            return (List<com.liferay.portal.model.Permission>)result;
1711        }
1712    }
1713
1714    public int getPermissionsSize(long pk) throws SystemException {
1715        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
1716
1717        String finderClassName = "Groups_Permissions";
1718
1719        String finderMethodName = "getPermissionsSize";
1720        String[] finderParams = new String[] { Long.class.getName() };
1721        Object[] finderArgs = new Object[] { new Long(pk) };
1722
1723        Object result = null;
1724
1725        if (finderClassNameCacheEnabled) {
1726            result = FinderCacheUtil.getResult(finderClassName,
1727                    finderMethodName, finderParams, finderArgs, this);
1728        }
1729
1730        if (result == null) {
1731            Session session = null;
1732
1733            try {
1734                session = openSession();
1735
1736                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
1737
1738                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1739
1740                QueryPos qPos = QueryPos.getInstance(q);
1741
1742                qPos.add(pk);
1743
1744                Long count = null;
1745
1746                Iterator<Long> itr = q.list().iterator();
1747
1748                if (itr.hasNext()) {
1749                    count = itr.next();
1750                }
1751
1752                if (count == null) {
1753                    count = new Long(0);
1754                }
1755
1756                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1757                    finderClassName, finderMethodName, finderParams,
1758                    finderArgs, count);
1759
1760                return count.intValue();
1761            }
1762            catch (Exception e) {
1763                throw processException(e);
1764            }
1765            finally {
1766                closeSession(session);
1767            }
1768        }
1769        else {
1770            return ((Long)result).intValue();
1771        }
1772    }
1773
1774    public boolean containsPermission(long pk, long permissionPK)
1775        throws SystemException {
1776        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_PERMISSIONS;
1777
1778        String finderClassName = "Groups_Permissions";
1779
1780        String finderMethodName = "containsPermissions";
1781        String[] finderParams = new String[] {
1782                Long.class.getName(),
1783                
1784                Long.class.getName()
1785            };
1786        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
1787
1788        Object result = null;
1789
1790        if (finderClassNameCacheEnabled) {
1791            result = FinderCacheUtil.getResult(finderClassName,
1792                    finderMethodName, finderParams, finderArgs, this);
1793        }
1794
1795        if (result == null) {
1796            try {
1797                Boolean value = Boolean.valueOf(containsPermission.contains(
1798                            pk, permissionPK));
1799
1800                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1801                    finderClassName, finderMethodName, finderParams,
1802                    finderArgs, value);
1803
1804                return value.booleanValue();
1805            }
1806            catch (Exception e) {
1807                throw processException(e);
1808            }
1809        }
1810        else {
1811            return ((Boolean)result).booleanValue();
1812        }
1813    }
1814
1815    public boolean containsPermissions(long pk) throws SystemException {
1816        if (getPermissionsSize(pk) > 0) {
1817            return true;
1818        }
1819        else {
1820            return false;
1821        }
1822    }
1823
1824    public void addPermission(long pk, long permissionPK)
1825        throws SystemException {
1826        try {
1827            addPermission.add(pk, permissionPK);
1828        }
1829        catch (Exception e) {
1830            throw processException(e);
1831        }
1832        finally {
1833            FinderCacheUtil.clearCache("Groups_Permissions");
1834        }
1835    }
1836
1837    public void addPermission(long pk,
1838        com.liferay.portal.model.Permission permission)
1839        throws SystemException {
1840        try {
1841            addPermission.add(pk, permission.getPrimaryKey());
1842        }
1843        catch (Exception e) {
1844            throw processException(e);
1845        }
1846        finally {
1847            FinderCacheUtil.clearCache("Groups_Permissions");
1848        }
1849    }
1850
1851    public void addPermissions(long pk, long[] permissionPKs)
1852        throws SystemException {
1853        try {
1854            for (long permissionPK : permissionPKs) {
1855                addPermission.add(pk, permissionPK);
1856            }
1857        }
1858        catch (Exception e) {
1859            throw processException(e);
1860        }
1861        finally {
1862            FinderCacheUtil.clearCache("Groups_Permissions");
1863        }
1864    }
1865
1866    public void addPermissions(long pk,
1867        List<com.liferay.portal.model.Permission> permissions)
1868        throws SystemException {
1869        try {
1870            for (com.liferay.portal.model.Permission permission : permissions) {
1871                addPermission.add(pk, permission.getPrimaryKey());
1872            }
1873        }
1874        catch (Exception e) {
1875            throw processException(e);
1876        }
1877        finally {
1878            FinderCacheUtil.clearCache("Groups_Permissions");
1879        }
1880    }
1881
1882    public void clearPermissions(long pk) throws SystemException {
1883        try {
1884            clearPermissions.clear(pk);
1885        }
1886        catch (Exception e) {
1887            throw processException(e);
1888        }
1889        finally {
1890            FinderCacheUtil.clearCache("Groups_Permissions");
1891        }
1892    }
1893
1894    public void removePermission(long pk, long permissionPK)
1895        throws SystemException {
1896        try {
1897            removePermission.remove(pk, permissionPK);
1898        }
1899        catch (Exception e) {
1900            throw processException(e);
1901        }
1902        finally {
1903            FinderCacheUtil.clearCache("Groups_Permissions");
1904        }
1905    }
1906
1907    public void removePermission(long pk,
1908        com.liferay.portal.model.Permission permission)
1909        throws SystemException {
1910        try {
1911            removePermission.remove(pk, permission.getPrimaryKey());
1912        }
1913        catch (Exception e) {
1914            throw processException(e);
1915        }
1916        finally {
1917            FinderCacheUtil.clearCache("Groups_Permissions");
1918        }
1919    }
1920
1921    public void removePermissions(long pk, long[] permissionPKs)
1922        throws SystemException {
1923        try {
1924            for (long permissionPK : permissionPKs) {
1925                removePermission.remove(pk, permissionPK);
1926            }
1927        }
1928        catch (Exception e) {
1929            throw processException(e);
1930        }
1931        finally {
1932            FinderCacheUtil.clearCache("Groups_Permissions");
1933        }
1934    }
1935
1936    public void removePermissions(long pk,
1937        List<com.liferay.portal.model.Permission> permissions)
1938        throws SystemException {
1939        try {
1940            for (com.liferay.portal.model.Permission permission : permissions) {
1941                removePermission.remove(pk, permission.getPrimaryKey());
1942            }
1943        }
1944        catch (Exception e) {
1945            throw processException(e);
1946        }
1947        finally {
1948            FinderCacheUtil.clearCache("Groups_Permissions");
1949        }
1950    }
1951
1952    public void setPermissions(long pk, long[] permissionPKs)
1953        throws SystemException {
1954        try {
1955            clearPermissions.clear(pk);
1956
1957            for (long permissionPK : permissionPKs) {
1958                addPermission.add(pk, permissionPK);
1959            }
1960        }
1961        catch (Exception e) {
1962            throw processException(e);
1963        }
1964        finally {
1965            FinderCacheUtil.clearCache("Groups_Permissions");
1966        }
1967    }
1968
1969    public void setPermissions(long pk,
1970        List<com.liferay.portal.model.Permission> permissions)
1971        throws SystemException {
1972        try {
1973            clearPermissions.clear(pk);
1974
1975            for (com.liferay.portal.model.Permission permission : permissions) {
1976                addPermission.add(pk, permission.getPrimaryKey());
1977            }
1978        }
1979        catch (Exception e) {
1980            throw processException(e);
1981        }
1982        finally {
1983            FinderCacheUtil.clearCache("Groups_Permissions");
1984        }
1985    }
1986
1987    public List<com.liferay.portal.model.Role> getRoles(long pk)
1988        throws SystemException {
1989        return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1990    }
1991
1992    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1993        int end) throws SystemException {
1994        return getRoles(pk, start, end, null);
1995    }
1996
1997    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1998        int end, OrderByComparator obc) throws SystemException {
1999        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
2000
2001        String finderClassName = "Groups_Roles";
2002
2003        String finderMethodName = "getRoles";
2004        String[] finderParams = new String[] {
2005                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2006                "com.liferay.portal.kernel.util.OrderByComparator"
2007            };
2008        Object[] finderArgs = new Object[] {
2009                new Long(pk), String.valueOf(start), String.valueOf(end),
2010                String.valueOf(obc)
2011            };
2012
2013        Object result = null;
2014
2015        if (finderClassNameCacheEnabled) {
2016            result = FinderCacheUtil.getResult(finderClassName,
2017                    finderMethodName, finderParams, finderArgs, this);
2018        }
2019
2020        if (result == null) {
2021            Session session = null;
2022
2023            try {
2024                session = openSession();
2025
2026                StringBuilder sb = new StringBuilder();
2027
2028                sb.append(_SQL_GETROLES);
2029
2030                if (obc != null) {
2031                    sb.append("ORDER BY ");
2032                    sb.append(obc.getOrderBy());
2033                }
2034
2035                else {
2036                    sb.append("ORDER BY ");
2037
2038                    sb.append("Role_.name ASC");
2039                }
2040
2041                String sql = sb.toString();
2042
2043                SQLQuery q = session.createSQLQuery(sql);
2044
2045                q.addEntity("Role_",
2046                    com.liferay.portal.model.impl.RoleImpl.class);
2047
2048                QueryPos qPos = QueryPos.getInstance(q);
2049
2050                qPos.add(pk);
2051
2052                List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
2053                        getDialect(), start, end);
2054
2055                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2056                    finderClassName, finderMethodName, finderParams,
2057                    finderArgs, list);
2058
2059                return list;
2060            }
2061            catch (Exception e) {
2062                throw processException(e);
2063            }
2064            finally {
2065                closeSession(session);
2066            }
2067        }
2068        else {
2069            return (List<com.liferay.portal.model.Role>)result;
2070        }
2071    }
2072
2073    public int getRolesSize(long pk) throws SystemException {
2074        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
2075
2076        String finderClassName = "Groups_Roles";
2077
2078        String finderMethodName = "getRolesSize";
2079        String[] finderParams = new String[] { Long.class.getName() };
2080        Object[] finderArgs = new Object[] { new Long(pk) };
2081
2082        Object result = null;
2083
2084        if (finderClassNameCacheEnabled) {
2085            result = FinderCacheUtil.getResult(finderClassName,
2086                    finderMethodName, finderParams, finderArgs, this);
2087        }
2088
2089        if (result == null) {
2090            Session session = null;
2091
2092            try {
2093                session = openSession();
2094
2095                SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
2096
2097                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2098
2099                QueryPos qPos = QueryPos.getInstance(q);
2100
2101                qPos.add(pk);
2102
2103                Long count = null;
2104
2105                Iterator<Long> itr = q.list().iterator();
2106
2107                if (itr.hasNext()) {
2108                    count = itr.next();
2109                }
2110
2111                if (count == null) {
2112                    count = new Long(0);
2113                }
2114
2115                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2116                    finderClassName, finderMethodName, finderParams,
2117                    finderArgs, count);
2118
2119                return count.intValue();
2120            }
2121            catch (Exception e) {
2122                throw processException(e);
2123            }
2124            finally {
2125                closeSession(session);
2126            }
2127        }
2128        else {
2129            return ((Long)result).intValue();
2130        }
2131    }
2132
2133    public boolean containsRole(long pk, long rolePK) throws SystemException {
2134        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_ROLES;
2135
2136        String finderClassName = "Groups_Roles";
2137
2138        String finderMethodName = "containsRoles";
2139        String[] finderParams = new String[] {
2140                Long.class.getName(),
2141                
2142                Long.class.getName()
2143            };
2144        Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
2145
2146        Object result = null;
2147
2148        if (finderClassNameCacheEnabled) {
2149            result = FinderCacheUtil.getResult(finderClassName,
2150                    finderMethodName, finderParams, finderArgs, this);
2151        }
2152
2153        if (result == null) {
2154            try {
2155                Boolean value = Boolean.valueOf(containsRole.contains(pk, rolePK));
2156
2157                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2158                    finderClassName, finderMethodName, finderParams,
2159                    finderArgs, value);
2160
2161                return value.booleanValue();
2162            }
2163            catch (Exception e) {
2164                throw processException(e);
2165            }
2166        }
2167        else {
2168            return ((Boolean)result).booleanValue();
2169        }
2170    }
2171
2172    public boolean containsRoles(long pk) throws SystemException {
2173        if (getRolesSize(pk) > 0) {
2174            return true;
2175        }
2176        else {
2177            return false;
2178        }
2179    }
2180
2181    public void addRole(long pk, long rolePK) throws SystemException {
2182        try {
2183            addRole.add(pk, rolePK);
2184        }
2185        catch (Exception e) {
2186            throw processException(e);
2187        }
2188        finally {
2189            FinderCacheUtil.clearCache("Groups_Roles");
2190        }
2191    }
2192
2193    public void addRole(long pk, com.liferay.portal.model.Role role)
2194        throws SystemException {
2195        try {
2196            addRole.add(pk, role.getPrimaryKey());
2197        }
2198        catch (Exception e) {
2199            throw processException(e);
2200        }
2201        finally {
2202            FinderCacheUtil.clearCache("Groups_Roles");
2203        }
2204    }
2205
2206    public void addRoles(long pk, long[] rolePKs) throws SystemException {
2207        try {
2208            for (long rolePK : rolePKs) {
2209                addRole.add(pk, rolePK);
2210            }
2211        }
2212        catch (Exception e) {
2213            throw processException(e);
2214        }
2215        finally {
2216            FinderCacheUtil.clearCache("Groups_Roles");
2217        }
2218    }
2219
2220    public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
2221        throws SystemException {
2222        try {
2223            for (com.liferay.portal.model.Role role : roles) {
2224                addRole.add(pk, role.getPrimaryKey());
2225            }
2226        }
2227        catch (Exception e) {
2228            throw processException(e);
2229        }
2230        finally {
2231            FinderCacheUtil.clearCache("Groups_Roles");
2232        }
2233    }
2234
2235    public void clearRoles(long pk) throws SystemException {
2236        try {
2237            clearRoles.clear(pk);
2238        }
2239        catch (Exception e) {
2240            throw processException(e);
2241        }
2242        finally {
2243            FinderCacheUtil.clearCache("Groups_Roles");
2244        }
2245    }
2246
2247    public void removeRole(long pk, long rolePK) throws SystemException {
2248        try {
2249            removeRole.remove(pk, rolePK);
2250        }
2251        catch (Exception e) {
2252            throw processException(e);
2253        }
2254        finally {
2255            FinderCacheUtil.clearCache("Groups_Roles");
2256        }
2257    }
2258
2259    public void removeRole(long pk, com.liferay.portal.model.Role role)
2260        throws SystemException {
2261        try {
2262            removeRole.remove(pk, role.getPrimaryKey());
2263        }
2264        catch (Exception e) {
2265            throw processException(e);
2266        }
2267        finally {
2268            FinderCacheUtil.clearCache("Groups_Roles");
2269        }
2270    }
2271
2272    public void removeRoles(long pk, long[] rolePKs) throws SystemException {
2273        try {
2274            for (long rolePK : rolePKs) {
2275                removeRole.remove(pk, rolePK);
2276            }
2277        }
2278        catch (Exception e) {
2279            throw processException(e);
2280        }
2281        finally {
2282            FinderCacheUtil.clearCache("Groups_Roles");
2283        }
2284    }
2285
2286    public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
2287        throws SystemException {
2288        try {
2289            for (com.liferay.portal.model.Role role : roles) {
2290                removeRole.remove(pk, role.getPrimaryKey());
2291            }
2292        }
2293        catch (Exception e) {
2294            throw processException(e);
2295        }
2296        finally {
2297            FinderCacheUtil.clearCache("Groups_Roles");
2298        }
2299    }
2300
2301    public void setRoles(long pk, long[] rolePKs) throws SystemException {
2302        try {
2303            clearRoles.clear(pk);
2304
2305            for (long rolePK : rolePKs) {
2306                addRole.add(pk, rolePK);
2307            }
2308        }
2309        catch (Exception e) {
2310            throw processException(e);
2311        }
2312        finally {
2313            FinderCacheUtil.clearCache("Groups_Roles");
2314        }
2315    }
2316
2317    public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
2318        throws SystemException {
2319        try {
2320            clearRoles.clear(pk);
2321
2322            for (com.liferay.portal.model.Role role : roles) {
2323                addRole.add(pk, role.getPrimaryKey());
2324            }
2325        }
2326        catch (Exception e) {
2327            throw processException(e);
2328        }
2329        finally {
2330            FinderCacheUtil.clearCache("Groups_Roles");
2331        }
2332    }
2333
2334    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk)
2335        throws SystemException {
2336        return getUserGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2337    }
2338
2339    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
2340        int start, int end) throws SystemException {
2341        return getUserGroups(pk, start, end, null);
2342    }
2343
2344    public List<com.liferay.portal.model.UserGroup> getUserGroups(long pk,
2345        int start, int end, OrderByComparator obc) throws SystemException {
2346        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS;
2347
2348        String finderClassName = "Groups_UserGroups";
2349
2350        String finderMethodName = "getUserGroups";
2351        String[] finderParams = new String[] {
2352                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2353                "com.liferay.portal.kernel.util.OrderByComparator"
2354            };
2355        Object[] finderArgs = new Object[] {
2356                new Long(pk), String.valueOf(start), String.valueOf(end),
2357                String.valueOf(obc)
2358            };
2359
2360        Object result = null;
2361
2362        if (finderClassNameCacheEnabled) {
2363            result = FinderCacheUtil.getResult(finderClassName,
2364                    finderMethodName, finderParams, finderArgs, this);
2365        }
2366
2367        if (result == null) {
2368            Session session = null;
2369
2370            try {
2371                session = openSession();
2372
2373                StringBuilder sb = new StringBuilder();
2374
2375                sb.append(_SQL_GETUSERGROUPS);
2376
2377                if (obc != null) {
2378                    sb.append("ORDER BY ");
2379                    sb.append(obc.getOrderBy());
2380                }
2381
2382                else {
2383                    sb.append("ORDER BY ");
2384
2385                    sb.append("UserGroup.name ASC");
2386                }
2387
2388                String sql = sb.toString();
2389
2390                SQLQuery q = session.createSQLQuery(sql);
2391
2392                q.addEntity("UserGroup",
2393                    com.liferay.portal.model.impl.UserGroupImpl.class);
2394
2395                QueryPos qPos = QueryPos.getInstance(q);
2396
2397                qPos.add(pk);
2398
2399                List<com.liferay.portal.model.UserGroup> list = (List<com.liferay.portal.model.UserGroup>)QueryUtil.list(q,
2400                        getDialect(), start, end);
2401
2402                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2403                    finderClassName, finderMethodName, finderParams,
2404                    finderArgs, list);
2405
2406                return list;
2407            }
2408            catch (Exception e) {
2409                throw processException(e);
2410            }
2411            finally {
2412                closeSession(session);
2413            }
2414        }
2415        else {
2416            return (List<com.liferay.portal.model.UserGroup>)result;
2417        }
2418    }
2419
2420    public int getUserGroupsSize(long pk) throws SystemException {
2421        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS;
2422
2423        String finderClassName = "Groups_UserGroups";
2424
2425        String finderMethodName = "getUserGroupsSize";
2426        String[] finderParams = new String[] { Long.class.getName() };
2427        Object[] finderArgs = new Object[] { new Long(pk) };
2428
2429        Object result = null;
2430
2431        if (finderClassNameCacheEnabled) {
2432            result = FinderCacheUtil.getResult(finderClassName,
2433                    finderMethodName, finderParams, finderArgs, this);
2434        }
2435
2436        if (result == null) {
2437            Session session = null;
2438
2439            try {
2440                session = openSession();
2441
2442                SQLQuery q = session.createSQLQuery(_SQL_GETUSERGROUPSSIZE);
2443
2444                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2445
2446                QueryPos qPos = QueryPos.getInstance(q);
2447
2448                qPos.add(pk);
2449
2450                Long count = null;
2451
2452                Iterator<Long> itr = q.list().iterator();
2453
2454                if (itr.hasNext()) {
2455                    count = itr.next();
2456                }
2457
2458                if (count == null) {
2459                    count = new Long(0);
2460                }
2461
2462                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2463                    finderClassName, finderMethodName, finderParams,
2464                    finderArgs, count);
2465
2466                return count.intValue();
2467            }
2468            catch (Exception e) {
2469                throw processException(e);
2470            }
2471            finally {
2472                closeSession(session);
2473            }
2474        }
2475        else {
2476            return ((Long)result).intValue();
2477        }
2478    }
2479
2480    public boolean containsUserGroup(long pk, long userGroupPK)
2481        throws SystemException {
2482        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_GROUPS_USERGROUPS;
2483
2484        String finderClassName = "Groups_UserGroups";
2485
2486        String finderMethodName = "containsUserGroups";
2487        String[] finderParams = new String[] {
2488                Long.class.getName(),
2489                
2490                Long.class.getName()
2491            };
2492        Object[] finderArgs = new Object[] { new Long(pk), new Long(userGroupPK) };
2493
2494        Object result = null;
2495
2496        if (finderClassNameCacheEnabled) {
2497            result = FinderCacheUtil.getResult(finderClassName,
2498                    finderMethodName, finderParams, finderArgs, this);
2499        }
2500
2501        if (result == null) {
2502            try {
2503                Boolean value = Boolean.valueOf(containsUserGroup.contains(pk,
2504                            userGroupPK));
2505
2506                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2507                    finderClassName, finderMethodName, finderParams,
2508                    finderArgs, value);
2509
2510                return value.booleanValue();
2511            }
2512            catch (Exception e) {
2513                throw processException(e);
2514            }
2515        }
2516        else {
2517            return ((Boolean)result).booleanValue();
2518        }
2519    }
2520
2521    public boolean containsUserGroups(long pk) throws SystemException {
2522        if (getUserGroupsSize(pk) > 0) {
2523            return true;
2524        }
2525        else {
2526            return false;
2527        }
2528    }
2529
2530    public void addUserGroup(long pk, long userGroupPK)
2531        throws SystemException {
2532        try {
2533            addUserGroup.add(pk, userGroupPK);
2534        }
2535        catch (Exception e) {
2536            throw processException(e);
2537        }
2538        finally {
2539            FinderCacheUtil.clearCache("Groups_UserGroups");
2540        }
2541    }
2542
2543    public void addUserGroup(long pk,
2544        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
2545        try {
2546            addUserGroup.add(pk, userGroup.getPrimaryKey());
2547        }
2548        catch (Exception e) {
2549            throw processException(e);
2550        }
2551        finally {
2552            FinderCacheUtil.clearCache("Groups_UserGroups");
2553        }
2554    }
2555
2556    public void addUserGroups(long pk, long[] userGroupPKs)
2557        throws SystemException {
2558        try {
2559            for (long userGroupPK : userGroupPKs) {
2560                addUserGroup.add(pk, userGroupPK);
2561            }
2562        }
2563        catch (Exception e) {
2564            throw processException(e);
2565        }
2566        finally {
2567            FinderCacheUtil.clearCache("Groups_UserGroups");
2568        }
2569    }
2570
2571    public void addUserGroups(long pk,
2572        List<com.liferay.portal.model.UserGroup> userGroups)
2573        throws SystemException {
2574        try {
2575            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2576                addUserGroup.add(pk, userGroup.getPrimaryKey());
2577            }
2578        }
2579        catch (Exception e) {
2580            throw processException(e);
2581        }
2582        finally {
2583            FinderCacheUtil.clearCache("Groups_UserGroups");
2584        }
2585    }
2586
2587    public void clearUserGroups(long pk) throws SystemException {
2588        try {
2589            clearUserGroups.clear(pk);
2590        }
2591        catch (Exception e) {
2592            throw processException(e);
2593        }
2594        finally {
2595            FinderCacheUtil.clearCache("Groups_UserGroups");
2596        }
2597    }
2598
2599    public void removeUserGroup(long pk, long userGroupPK)
2600        throws SystemException {
2601        try {
2602            removeUserGroup.remove(pk, userGroupPK);
2603        }
2604        catch (Exception e) {
2605            throw processException(e);
2606        }
2607        finally {
2608            FinderCacheUtil.clearCache("Groups_UserGroups");
2609        }
2610    }
2611
2612    public void removeUserGroup(long pk,
2613        com.liferay.portal.model.UserGroup userGroup) throws SystemException {
2614        try {
2615            removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2616        }
2617        catch (Exception e) {
2618            throw processException(e);
2619        }
2620        finally {
2621            FinderCacheUtil.clearCache("Groups_UserGroups");
2622        }
2623    }
2624
2625    public void removeUserGroups(long pk, long[] userGroupPKs)
2626        throws SystemException {
2627        try {
2628            for (long userGroupPK : userGroupPKs) {
2629                removeUserGroup.remove(pk, userGroupPK);
2630            }
2631        }
2632        catch (Exception e) {
2633            throw processException(e);
2634        }
2635        finally {
2636            FinderCacheUtil.clearCache("Groups_UserGroups");
2637        }
2638    }
2639
2640    public void removeUserGroups(long pk,
2641        List<com.liferay.portal.model.UserGroup> userGroups)
2642        throws SystemException {
2643        try {
2644            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2645                removeUserGroup.remove(pk, userGroup.getPrimaryKey());
2646            }
2647        }
2648        catch (Exception e) {
2649            throw processException(e);
2650        }
2651        finally {
2652            FinderCacheUtil.clearCache("Groups_UserGroups");
2653        }
2654    }
2655
2656    public void setUserGroups(long pk, long[] userGroupPKs)
2657        throws SystemException {
2658        try {
2659            clearUserGroups.clear(pk);
2660
2661            for (long userGroupPK : userGroupPKs) {
2662                addUserGroup.add(pk, userGroupPK);
2663            }
2664        }
2665        catch (Exception e) {
2666            throw processException(e);
2667        }
2668        finally {
2669            FinderCacheUtil.clearCache("Groups_UserGroups");
2670        }
2671    }
2672
2673    public void setUserGroups(long pk,
2674        List<com.liferay.portal.model.UserGroup> userGroups)
2675        throws SystemException {
2676        try {
2677            clearUserGroups.clear(pk);
2678
2679            for (com.liferay.portal.model.UserGroup userGroup : userGroups) {
2680                addUserGroup.add(pk, userGroup.getPrimaryKey());
2681            }
2682        }
2683        catch (Exception e) {
2684            throw processException(e);
2685        }
2686        finally {
2687            FinderCacheUtil.clearCache("Groups_UserGroups");
2688        }
2689    }
2690
2691    public List<com.liferay.portal.model.User> getUsers(long pk)
2692        throws SystemException {
2693        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2694    }
2695
2696    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2697        int end) throws SystemException {
2698        return getUsers(pk, start, end, null);
2699    }
2700
2701    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2702        int end, OrderByComparator obc) throws SystemException {
2703        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_USERS_GROUPS;
2704
2705        String finderClassName = "Users_Groups";
2706
2707        String finderMethodName = "getUsers";
2708        String[] finderParams = new String[] {
2709                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2710                "com.liferay.portal.kernel.util.OrderByComparator"
2711            };
2712        Object[] finderArgs = new Object[] {
2713                new Long(pk), String.valueOf(start), String.valueOf(end),
2714                String.valueOf(obc)
2715            };
2716
2717        Object result = null;
2718
2719        if (finderClassNameCacheEnabled) {
2720            result = FinderCacheUtil.getResult(finderClassName,
2721                    finderMethodName, finderParams, finderArgs, this);
2722        }
2723
2724        if (result == null) {
2725            Session session = null;
2726
2727            try {
2728                session = openSession();
2729
2730                StringBuilder sb = new StringBuilder();
2731
2732                sb.append(_SQL_GETUSERS);
2733
2734                if (obc != null) {
2735                    sb.append("ORDER BY ");
2736                    sb.append(obc.getOrderBy());
2737                }
2738
2739                String sql = sb.toString();
2740
2741                SQLQuery q = session.createSQLQuery(sql);
2742
2743                q.addEntity("User_",
2744                    com.liferay.portal.model.impl.UserImpl.class);
2745
2746                QueryPos qPos = QueryPos.getInstance(q);
2747
2748                qPos.add(pk);
2749
2750                List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2751                        getDialect(), start, end);
2752
2753                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2754                    finderClassName, finderMethodName, finderParams,
2755                    finderArgs, list);
2756
2757                return list;
2758            }
2759            catch (Exception e) {
2760                throw processException(e);
2761            }
2762            finally {
2763                closeSession(session);
2764            }
2765        }
2766        else {
2767            return (List<com.liferay.portal.model.User>)result;
2768        }
2769    }
2770
2771    public int getUsersSize(long pk) throws SystemException {
2772        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_USERS_GROUPS;
2773
2774        String finderClassName = "Users_Groups";
2775
2776        String finderMethodName = "getUsersSize";
2777        String[] finderParams = new String[] { Long.class.getName() };
2778        Object[] finderArgs = new Object[] { new Long(pk) };
2779
2780        Object result = null;
2781
2782        if (finderClassNameCacheEnabled) {
2783            result = FinderCacheUtil.getResult(finderClassName,
2784                    finderMethodName, finderParams, finderArgs, this);
2785        }
2786
2787        if (result == null) {
2788            Session session = null;
2789
2790            try {
2791                session = openSession();
2792
2793                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2794
2795                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
2796
2797                QueryPos qPos = QueryPos.getInstance(q);
2798
2799                qPos.add(pk);
2800
2801                Long count = null;
2802
2803                Iterator<Long> itr = q.list().iterator();
2804
2805                if (itr.hasNext()) {
2806                    count = itr.next();
2807                }
2808
2809                if (count == null) {
2810                    count = new Long(0);
2811                }
2812
2813                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2814                    finderClassName, finderMethodName, finderParams,
2815                    finderArgs, count);
2816
2817                return count.intValue();
2818            }
2819            catch (Exception e) {
2820                throw processException(e);
2821            }
2822            finally {
2823                closeSession(session);
2824            }
2825        }
2826        else {
2827            return ((Long)result).intValue();
2828        }
2829    }
2830
2831    public boolean containsUser(long pk, long userPK) throws SystemException {
2832        boolean finderClassNameCacheEnabled = GroupModelImpl.CACHE_ENABLED_USERS_GROUPS;
2833
2834        String finderClassName = "Users_Groups";
2835
2836        String finderMethodName = "containsUsers";
2837        String[] finderParams = new String[] {
2838                Long.class.getName(),
2839                
2840                Long.class.getName()
2841            };
2842        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2843
2844        Object result = null;
2845
2846        if (finderClassNameCacheEnabled) {
2847            result = FinderCacheUtil.getResult(finderClassName,
2848                    finderMethodName, finderParams, finderArgs, this);
2849        }
2850
2851        if (result == null) {
2852            try {
2853                Boolean value = Boolean.valueOf(containsUser.contains(pk, userPK));
2854
2855                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2856                    finderClassName, finderMethodName, finderParams,
2857                    finderArgs, value);
2858
2859                return value.booleanValue();
2860            }
2861            catch (Exception e) {
2862                throw processException(e);
2863            }
2864        }
2865        else {
2866            return ((Boolean)result).booleanValue();
2867        }
2868    }
2869
2870    public boolean containsUsers(long pk) throws SystemException {
2871        if (getUsersSize(pk) > 0) {
2872            return true;
2873        }
2874        else {
2875            return false;
2876        }
2877    }
2878
2879    public void addUser(long pk, long userPK) throws SystemException {
2880        try {
2881            addUser.add(pk, userPK);
2882        }
2883        catch (Exception e) {
2884            throw processException(e);
2885        }
2886        finally {
2887            FinderCacheUtil.clearCache("Users_Groups");
2888        }
2889    }
2890
2891    public void addUser(long pk, com.liferay.portal.model.User user)
2892        throws SystemException {
2893        try {
2894            addUser.add(pk, user.getPrimaryKey());
2895        }
2896        catch (Exception e) {
2897            throw processException(e);
2898        }
2899        finally {
2900            FinderCacheUtil.clearCache("Users_Groups");
2901        }
2902    }
2903
2904    public void addUsers(long pk, long[] userPKs) throws SystemException {
2905        try {
2906            for (long userPK : userPKs) {
2907                addUser.add(pk, userPK);
2908            }
2909        }
2910        catch (Exception e) {
2911            throw processException(e);
2912        }
2913        finally {
2914            FinderCacheUtil.clearCache("Users_Groups");
2915        }
2916    }
2917
2918    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2919        throws SystemException {
2920        try {
2921            for (com.liferay.portal.model.User user : users) {
2922                addUser.add(pk, user.getPrimaryKey());
2923            }
2924        }
2925        catch (Exception e) {
2926            throw processException(e);
2927        }
2928        finally {
2929            FinderCacheUtil.clearCache("Users_Groups");
2930        }
2931    }
2932
2933    public void clearUsers(long pk) throws SystemException {
2934        try {
2935            clearUsers.clear(pk);
2936        }
2937        catch (Exception e) {
2938            throw processException(e);
2939        }
2940        finally {
2941            FinderCacheUtil.clearCache("Users_Groups");
2942        }
2943    }
2944
2945    public void removeUser(long pk, long userPK) throws SystemException {
2946        try {
2947            removeUser.remove(pk, userPK);
2948        }
2949        catch (Exception e) {
2950            throw processException(e);
2951        }
2952        finally {
2953            FinderCacheUtil.clearCache("Users_Groups");
2954        }
2955    }
2956
2957    public void removeUser(long pk, com.liferay.portal.model.User user)
2958        throws SystemException {
2959        try {
2960            removeUser.remove(pk, user.getPrimaryKey());
2961        }
2962        catch (Exception e) {
2963            throw processException(e);
2964        }
2965        finally {
2966            FinderCacheUtil.clearCache("Users_Groups");
2967        }
2968    }
2969
2970    public void removeUsers(long pk, long[] userPKs) throws SystemException {
2971        try {
2972            for (long userPK : userPKs) {
2973                removeUser.remove(pk, userPK);
2974            }
2975        }
2976        catch (Exception e) {
2977            throw processException(e);
2978        }
2979        finally {
2980            FinderCacheUtil.clearCache("Users_Groups");
2981        }
2982    }
2983
2984    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2985        throws SystemException {
2986        try {
2987            for (com.liferay.portal.model.User user : users) {
2988                removeUser.remove(pk, user.getPrimaryKey());
2989            }
2990        }
2991        catch (Exception e) {
2992            throw processException(e);
2993        }
2994        finally {
2995            FinderCacheUtil.clearCache("Users_Groups");
2996        }
2997    }
2998
2999    public void setUsers(long pk, long[] userPKs) throws SystemException {
3000        try {
3001            clearUsers.clear(pk);
3002
3003            for (long userPK : userPKs) {
3004                addUser.add(pk, userPK);
3005            }
3006        }
3007        catch (Exception e) {
3008            throw processException(e);
3009        }
3010        finally {
3011            FinderCacheUtil.clearCache("Users_Groups");
3012        }
3013    }
3014
3015    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
3016        throws SystemException {
3017        try {
3018            clearUsers.clear(pk);
3019
3020            for (com.liferay.portal.model.User user : users) {
3021                addUser.add(pk, user.getPrimaryKey());
3022            }
3023        }
3024        catch (Exception e) {
3025            throw processException(e);
3026        }
3027        finally {
3028            FinderCacheUtil.clearCache("Users_Groups");
3029        }
3030    }
3031
3032    public void registerListener(ModelListener listener) {
3033        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3034
3035        listeners.add(listener);
3036
3037        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3038    }
3039
3040    public void unregisterListener(ModelListener listener) {
3041        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3042
3043        listeners.remove(listener);
3044
3045        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3046    }
3047
3048    public void afterPropertiesSet() {
3049        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3050                    com.liferay.portal.util.PropsUtil.get(
3051                        "value.object.listener.com.liferay.portal.model.Group")));
3052
3053        if (listenerClassNames.length > 0) {
3054            try {
3055                List<ModelListener> listeners = new ArrayList<ModelListener>();
3056
3057                for (String listenerClassName : listenerClassNames) {
3058                    listeners.add((ModelListener)Class.forName(
3059                            listenerClassName).newInstance());
3060                }
3061
3062                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3063            }
3064            catch (Exception e) {
3065                _log.error(e);
3066            }
3067        }
3068
3069        containsOrganization = new ContainsOrganization(this);
3070
3071        addOrganization = new AddOrganization(this);
3072        clearOrganizations = new ClearOrganizations(this);
3073        removeOrganization = new RemoveOrganization(this);
3074
3075        containsPermission = new ContainsPermission(this);
3076
3077        addPermission = new AddPermission(this);
3078        clearPermissions = new ClearPermissions(this);
3079        removePermission = new RemovePermission(this);
3080
3081        containsRole = new ContainsRole(this);
3082
3083        addRole = new AddRole(this);
3084        clearRoles = new ClearRoles(this);
3085        removeRole = new RemoveRole(this);
3086
3087        containsUserGroup = new ContainsUserGroup(this);
3088
3089        addUserGroup = new AddUserGroup(this);
3090        clearUserGroups = new ClearUserGroups(this);
3091        removeUserGroup = new RemoveUserGroup(this);
3092
3093        containsUser = new ContainsUser(this);
3094
3095        addUser = new AddUser(this);
3096        clearUsers = new ClearUsers(this);
3097        removeUser = new RemoveUser(this);
3098    }
3099
3100    protected ContainsOrganization containsOrganization;
3101    protected AddOrganization addOrganization;
3102    protected ClearOrganizations clearOrganizations;
3103    protected RemoveOrganization removeOrganization;
3104    protected ContainsPermission containsPermission;
3105    protected AddPermission addPermission;
3106    protected ClearPermissions clearPermissions;
3107    protected RemovePermission removePermission;
3108    protected ContainsRole containsRole;
3109    protected AddRole addRole;
3110    protected ClearRoles clearRoles;
3111    protected RemoveRole removeRole;
3112    protected ContainsUserGroup containsUserGroup;
3113    protected AddUserGroup addUserGroup;
3114    protected ClearUserGroups clearUserGroups;
3115    protected RemoveUserGroup removeUserGroup;
3116    protected ContainsUser containsUser;
3117    protected AddUser addUser;
3118    protected ClearUsers clearUsers;
3119    protected RemoveUser removeUser;
3120
3121    protected class ContainsOrganization {
3122        protected ContainsOrganization(GroupPersistenceImpl persistenceImpl) {
3123            super();
3124
3125            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3126                    _SQL_CONTAINSORGANIZATION,
3127                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3128        }
3129
3130        protected boolean contains(long groupId, long organizationId) {
3131            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3132                        new Long(groupId), new Long(organizationId)
3133                    });
3134
3135            if (results.size() > 0) {
3136                Integer count = results.get(0);
3137
3138                if (count.intValue() > 0) {
3139                    return true;
3140                }
3141            }
3142
3143            return false;
3144        }
3145
3146        private MappingSqlQuery _mappingSqlQuery;
3147    }
3148
3149    protected class AddOrganization {
3150        protected AddOrganization(GroupPersistenceImpl persistenceImpl) {
3151            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3152                    "INSERT INTO Groups_Orgs (groupId, organizationId) VALUES (?, ?)",
3153                    new int[] { Types.BIGINT, Types.BIGINT });
3154            _persistenceImpl = persistenceImpl;
3155        }
3156
3157        protected void add(long groupId, long organizationId) {
3158            if (!_persistenceImpl.containsOrganization.contains(groupId,
3159                        organizationId)) {
3160                _sqlUpdate.update(new Object[] {
3161                        new Long(groupId), new Long(organizationId)
3162                    });
3163            }
3164        }
3165
3166        private SqlUpdate _sqlUpdate;
3167        private GroupPersistenceImpl _persistenceImpl;
3168    }
3169
3170    protected class ClearOrganizations {
3171        protected ClearOrganizations(GroupPersistenceImpl persistenceImpl) {
3172            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3173                    "DELETE FROM Groups_Orgs WHERE groupId = ?",
3174                    new int[] { Types.BIGINT });
3175        }
3176
3177        protected void clear(long groupId) {
3178            _sqlUpdate.update(new Object[] { new Long(groupId) });
3179        }
3180
3181        private SqlUpdate _sqlUpdate;
3182    }
3183
3184    protected class RemoveOrganization {
3185        protected RemoveOrganization(GroupPersistenceImpl persistenceImpl) {
3186            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3187                    "DELETE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?",
3188                    new int[] { Types.BIGINT, Types.BIGINT });
3189        }
3190
3191        protected void remove(long groupId, long organizationId) {
3192            _sqlUpdate.update(new Object[] {
3193                    new Long(groupId), new Long(organizationId)
3194                });
3195        }
3196
3197        private SqlUpdate _sqlUpdate;
3198    }
3199
3200    protected class ContainsPermission {
3201        protected ContainsPermission(GroupPersistenceImpl persistenceImpl) {
3202            super();
3203
3204            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3205                    _SQL_CONTAINSPERMISSION,
3206                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3207        }
3208
3209        protected boolean contains(long groupId, long permissionId) {
3210            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3211                        new Long(groupId), new Long(permissionId)
3212                    });
3213
3214            if (results.size() > 0) {
3215                Integer count = results.get(0);
3216
3217                if (count.intValue() > 0) {
3218                    return true;
3219                }
3220            }
3221
3222            return false;
3223        }
3224
3225        private MappingSqlQuery _mappingSqlQuery;
3226    }
3227
3228    protected class AddPermission {
3229        protected AddPermission(GroupPersistenceImpl persistenceImpl) {
3230            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3231                    "INSERT INTO Groups_Permissions (groupId, permissionId) VALUES (?, ?)",
3232                    new int[] { Types.BIGINT, Types.BIGINT });
3233            _persistenceImpl = persistenceImpl;
3234        }
3235
3236        protected void add(long groupId, long permissionId) {
3237            if (!_persistenceImpl.containsPermission.contains(groupId,
3238                        permissionId)) {
3239                _sqlUpdate.update(new Object[] {
3240                        new Long(groupId), new Long(permissionId)
3241                    });
3242            }
3243        }
3244
3245        private SqlUpdate _sqlUpdate;
3246        private GroupPersistenceImpl _persistenceImpl;
3247    }
3248
3249    protected class ClearPermissions {
3250        protected ClearPermissions(GroupPersistenceImpl persistenceImpl) {
3251            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3252                    "DELETE FROM Groups_Permissions WHERE groupId = ?",
3253                    new int[] { Types.BIGINT });
3254        }
3255
3256        protected void clear(long groupId) {
3257            _sqlUpdate.update(new Object[] { new Long(groupId) });
3258        }
3259
3260        private SqlUpdate _sqlUpdate;
3261    }
3262
3263    protected class RemovePermission {
3264        protected RemovePermission(GroupPersistenceImpl persistenceImpl) {
3265            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3266                    "DELETE FROM Groups_Permissions WHERE groupId = ? AND permissionId = ?",
3267                    new int[] { Types.BIGINT, Types.BIGINT });
3268        }
3269
3270        protected void remove(long groupId, long permissionId) {
3271            _sqlUpdate.update(new Object[] {
3272                    new Long(groupId), new Long(permissionId)
3273                });
3274        }
3275
3276        private SqlUpdate _sqlUpdate;
3277    }
3278
3279    protected class ContainsRole {
3280        protected ContainsRole(GroupPersistenceImpl persistenceImpl) {
3281            super();
3282
3283            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3284                    _SQL_CONTAINSROLE,
3285                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3286        }
3287
3288        protected boolean contains(long groupId, long roleId) {
3289            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3290                        new Long(groupId), new Long(roleId)
3291                    });
3292
3293            if (results.size() > 0) {
3294                Integer count = results.get(0);
3295
3296                if (count.intValue() > 0) {
3297                    return true;
3298                }
3299            }
3300
3301            return false;
3302        }
3303
3304        private MappingSqlQuery _mappingSqlQuery;
3305    }
3306
3307    protected class AddRole {
3308        protected AddRole(GroupPersistenceImpl persistenceImpl) {
3309            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3310                    "INSERT INTO Groups_Roles (groupId, roleId) VALUES (?, ?)",
3311                    new int[] { Types.BIGINT, Types.BIGINT });
3312            _persistenceImpl = persistenceImpl;
3313        }
3314
3315        protected void add(long groupId, long roleId) {
3316            if (!_persistenceImpl.containsRole.contains(groupId, roleId)) {
3317                _sqlUpdate.update(new Object[] {
3318                        new Long(groupId), new Long(roleId)
3319                    });
3320            }
3321        }
3322
3323        private SqlUpdate _sqlUpdate;
3324        private GroupPersistenceImpl _persistenceImpl;
3325    }
3326
3327    protected class ClearRoles {
3328        protected ClearRoles(GroupPersistenceImpl persistenceImpl) {
3329            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3330                    "DELETE FROM Groups_Roles WHERE groupId = ?",
3331                    new int[] { Types.BIGINT });
3332        }
3333
3334        protected void clear(long groupId) {
3335            _sqlUpdate.update(new Object[] { new Long(groupId) });
3336        }
3337
3338        private SqlUpdate _sqlUpdate;
3339    }
3340
3341    protected class RemoveRole {
3342        protected RemoveRole(GroupPersistenceImpl persistenceImpl) {
3343            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3344                    "DELETE FROM Groups_Roles WHERE groupId = ? AND roleId = ?",
3345                    new int[] { Types.BIGINT, Types.BIGINT });
3346        }
3347
3348        protected void remove(long groupId, long roleId) {
3349            _sqlUpdate.update(new Object[] { new Long(groupId), new Long(roleId) });
3350        }
3351
3352        private SqlUpdate _sqlUpdate;
3353    }
3354
3355    protected class ContainsUserGroup {
3356        protected ContainsUserGroup(GroupPersistenceImpl persistenceImpl) {
3357            super();
3358
3359            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3360                    _SQL_CONTAINSUSERGROUP,
3361                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3362        }
3363
3364        protected boolean contains(long groupId, long userGroupId) {
3365            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3366                        new Long(groupId), new Long(userGroupId)
3367                    });
3368
3369            if (results.size() > 0) {
3370                Integer count = results.get(0);
3371
3372                if (count.intValue() > 0) {
3373                    return true;
3374                }
3375            }
3376
3377            return false;
3378        }
3379
3380        private MappingSqlQuery _mappingSqlQuery;
3381    }
3382
3383    protected class AddUserGroup {
3384        protected AddUserGroup(GroupPersistenceImpl persistenceImpl) {
3385            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3386                    "INSERT INTO Groups_UserGroups (groupId, userGroupId) VALUES (?, ?)",
3387                    new int[] { Types.BIGINT, Types.BIGINT });
3388            _persistenceImpl = persistenceImpl;
3389        }
3390
3391        protected void add(long groupId, long userGroupId) {
3392            if (!_persistenceImpl.containsUserGroup.contains(groupId,
3393                        userGroupId)) {
3394                _sqlUpdate.update(new Object[] {
3395                        new Long(groupId), new Long(userGroupId)
3396                    });
3397            }
3398        }
3399
3400        private SqlUpdate _sqlUpdate;
3401        private GroupPersistenceImpl _persistenceImpl;
3402    }
3403
3404    protected class ClearUserGroups {
3405        protected ClearUserGroups(GroupPersistenceImpl persistenceImpl) {
3406            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3407                    "DELETE FROM Groups_UserGroups WHERE groupId = ?",
3408                    new int[] { Types.BIGINT });
3409        }
3410
3411        protected void clear(long groupId) {
3412            _sqlUpdate.update(new Object[] { new Long(groupId) });
3413        }
3414
3415        private SqlUpdate _sqlUpdate;
3416    }
3417
3418    protected class RemoveUserGroup {
3419        protected RemoveUserGroup(GroupPersistenceImpl persistenceImpl) {
3420            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3421                    "DELETE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?",
3422                    new int[] { Types.BIGINT, Types.BIGINT });
3423        }
3424
3425        protected void remove(long groupId, long userGroupId) {
3426            _sqlUpdate.update(new Object[] {
3427                    new Long(groupId), new Long(userGroupId)
3428                });
3429        }
3430
3431        private SqlUpdate _sqlUpdate;
3432    }
3433
3434    protected class ContainsUser {
3435        protected ContainsUser(GroupPersistenceImpl persistenceImpl) {
3436            super();
3437
3438            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3439                    _SQL_CONTAINSUSER,
3440                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
3441        }
3442
3443        protected boolean contains(long groupId, long userId) {
3444            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3445                        new Long(groupId), new Long(userId)
3446                    });
3447
3448            if (results.size() > 0) {
3449                Integer count = results.get(0);
3450
3451                if (count.intValue() > 0) {
3452                    return true;
3453                }
3454            }
3455
3456            return false;
3457        }
3458
3459        private MappingSqlQuery _mappingSqlQuery;
3460    }
3461
3462    protected class AddUser {
3463        protected AddUser(GroupPersistenceImpl persistenceImpl) {
3464            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3465                    "INSERT INTO Users_Groups (groupId, userId) VALUES (?, ?)",
3466                    new int[] { Types.BIGINT, Types.BIGINT });
3467            _persistenceImpl = persistenceImpl;
3468        }
3469
3470        protected void add(long groupId, long userId) {
3471            if (!_persistenceImpl.containsUser.contains(groupId, userId)) {
3472                _sqlUpdate.update(new Object[] {
3473                        new Long(groupId), new Long(userId)
3474                    });
3475            }
3476        }
3477
3478        private SqlUpdate _sqlUpdate;
3479        private GroupPersistenceImpl _persistenceImpl;
3480    }
3481
3482    protected class ClearUsers {
3483        protected ClearUsers(GroupPersistenceImpl persistenceImpl) {
3484            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3485                    "DELETE FROM Users_Groups WHERE groupId = ?",
3486                    new int[] { Types.BIGINT });
3487        }
3488
3489        protected void clear(long groupId) {
3490            _sqlUpdate.update(new Object[] { new Long(groupId) });
3491        }
3492
3493        private SqlUpdate _sqlUpdate;
3494    }
3495
3496    protected class RemoveUser {
3497        protected RemoveUser(GroupPersistenceImpl persistenceImpl) {
3498            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3499                    "DELETE FROM Users_Groups WHERE groupId = ? AND userId = ?",
3500                    new int[] { Types.BIGINT, Types.BIGINT });
3501        }
3502
3503        protected void remove(long groupId, long userId) {
3504            _sqlUpdate.update(new Object[] { new Long(groupId), new Long(userId) });
3505        }
3506
3507        private SqlUpdate _sqlUpdate;
3508    }
3509
3510    private static final String _SQL_GETORGANIZATIONS = "SELECT {Organization_.*} FROM Organization_ INNER JOIN Groups_Orgs ON (Groups_Orgs.organizationId = Organization_.organizationId) WHERE (Groups_Orgs.groupId = ?)";
3511    private static final String _SQL_GETORGANIZATIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ?";
3512    private static final String _SQL_CONTAINSORGANIZATION = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Orgs WHERE groupId = ? AND organizationId = ?";
3513    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Groups_Permissions ON (Groups_Permissions.permissionId = Permission_.permissionId) WHERE (Groups_Permissions.groupId = ?)";
3514    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE groupId = ?";
3515    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE groupId = ? AND permissionId = ?";
3516    private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Groups_Roles ON (Groups_Roles.roleId = Role_.roleId) WHERE (Groups_Roles.groupId = ?)";
3517    private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ?";
3518    private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE groupId = ? AND roleId = ?";
3519    private static final String _SQL_GETUSERGROUPS = "SELECT {UserGroup.*} FROM UserGroup INNER JOIN Groups_UserGroups ON (Groups_UserGroups.userGroupId = UserGroup.userGroupId) WHERE (Groups_UserGroups.groupId = ?)";
3520    private static final String _SQL_GETUSERGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ?";
3521    private static final String _SQL_CONTAINSUSERGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_UserGroups WHERE groupId = ? AND userGroupId = ?";
3522    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Groups ON (Users_Groups.userId = User_.userId) WHERE (Users_Groups.groupId = ?)";
3523    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ?";
3524    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Groups WHERE groupId = ? AND userId = ?";
3525    private static Log _log = LogFactory.getLog(GroupPersistenceImpl.class);
3526    private ModelListener[] _listeners = new ModelListener[0];
3527}