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