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