1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchRoleException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
28  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
29  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
30  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
31  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
32  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
33  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
34  import com.liferay.portal.kernel.dao.orm.Query;
35  import com.liferay.portal.kernel.dao.orm.QueryPos;
36  import com.liferay.portal.kernel.dao.orm.QueryUtil;
37  import com.liferay.portal.kernel.dao.orm.SQLQuery;
38  import com.liferay.portal.kernel.dao.orm.Session;
39  import com.liferay.portal.kernel.dao.orm.Type;
40  import com.liferay.portal.kernel.util.GetterUtil;
41  import com.liferay.portal.kernel.util.ListUtil;
42  import com.liferay.portal.kernel.util.OrderByComparator;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.model.ModelListener;
46  import com.liferay.portal.model.Role;
47  import com.liferay.portal.model.impl.RoleImpl;
48  import com.liferay.portal.model.impl.RoleModelImpl;
49  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
50  
51  import org.apache.commons.logging.Log;
52  import org.apache.commons.logging.LogFactory;
53  
54  import java.sql.Types;
55  
56  import java.util.ArrayList;
57  import java.util.Collections;
58  import java.util.Iterator;
59  import java.util.List;
60  
61  /**
62   * <a href="RolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
63   *
64   * @author Brian Wing Shun Chan
65   *
66   */
67  public class RolePersistenceImpl extends BasePersistenceImpl
68      implements RolePersistence {
69      public Role create(long roleId) {
70          Role role = new RoleImpl();
71  
72          role.setNew(true);
73          role.setPrimaryKey(roleId);
74  
75          return role;
76      }
77  
78      public Role remove(long roleId) throws NoSuchRoleException, SystemException {
79          Session session = null;
80  
81          try {
82              session = openSession();
83  
84              Role role = (Role)session.get(RoleImpl.class, new Long(roleId));
85  
86              if (role == null) {
87                  if (_log.isWarnEnabled()) {
88                      _log.warn("No Role exists with the primary key " + roleId);
89                  }
90  
91                  throw new NoSuchRoleException(
92                      "No Role exists with the primary key " + roleId);
93              }
94  
95              return remove(role);
96          }
97          catch (NoSuchRoleException nsee) {
98              throw nsee;
99          }
100         catch (Exception e) {
101             throw processException(e);
102         }
103         finally {
104             closeSession(session);
105         }
106     }
107 
108     public Role remove(Role role) throws SystemException {
109         if (_listeners.length > 0) {
110             for (ModelListener listener : _listeners) {
111                 listener.onBeforeRemove(role);
112             }
113         }
114 
115         role = removeImpl(role);
116 
117         if (_listeners.length > 0) {
118             for (ModelListener listener : _listeners) {
119                 listener.onAfterRemove(role);
120             }
121         }
122 
123         return role;
124     }
125 
126     protected Role removeImpl(Role role) throws SystemException {
127         try {
128             clearGroups.clear(role.getPrimaryKey());
129         }
130         catch (Exception e) {
131             throw processException(e);
132         }
133         finally {
134             FinderCacheUtil.clearCache("Groups_Roles");
135         }
136 
137         try {
138             clearPermissions.clear(role.getPrimaryKey());
139         }
140         catch (Exception e) {
141             throw processException(e);
142         }
143         finally {
144             FinderCacheUtil.clearCache("Roles_Permissions");
145         }
146 
147         try {
148             clearUsers.clear(role.getPrimaryKey());
149         }
150         catch (Exception e) {
151             throw processException(e);
152         }
153         finally {
154             FinderCacheUtil.clearCache("Users_Roles");
155         }
156 
157         Session session = null;
158 
159         try {
160             session = openSession();
161 
162             session.delete(role);
163 
164             session.flush();
165 
166             return role;
167         }
168         catch (Exception e) {
169             throw processException(e);
170         }
171         finally {
172             closeSession(session);
173 
174             FinderCacheUtil.clearCache(Role.class.getName());
175         }
176     }
177 
178     /**
179      * @deprecated Use <code>update(Role role, boolean merge)</code>.
180      */
181     public Role update(Role role) throws SystemException {
182         if (_log.isWarnEnabled()) {
183             _log.warn(
184                 "Using the deprecated update(Role role) method. Use update(Role role, boolean merge) instead.");
185         }
186 
187         return update(role, false);
188     }
189 
190     /**
191      * Add, update, or merge, the entity. This method also calls the model
192      * listeners to trigger the proper events associated with adding, deleting,
193      * or updating an entity.
194      *
195      * @param        role the entity to add, update, or merge
196      * @param        merge boolean value for whether to merge the entity. The
197      *                default value is false. Setting merge to true is more
198      *                expensive and should only be true when role is
199      *                transient. See LEP-5473 for a detailed discussion of this
200      *                method.
201      * @return        true if the portlet can be displayed via Ajax
202      */
203     public Role update(Role role, boolean merge) throws SystemException {
204         boolean isNew = role.isNew();
205 
206         if (_listeners.length > 0) {
207             for (ModelListener listener : _listeners) {
208                 if (isNew) {
209                     listener.onBeforeCreate(role);
210                 }
211                 else {
212                     listener.onBeforeUpdate(role);
213                 }
214             }
215         }
216 
217         role = updateImpl(role, merge);
218 
219         if (_listeners.length > 0) {
220             for (ModelListener listener : _listeners) {
221                 if (isNew) {
222                     listener.onAfterCreate(role);
223                 }
224                 else {
225                     listener.onAfterUpdate(role);
226                 }
227             }
228         }
229 
230         return role;
231     }
232 
233     public Role updateImpl(com.liferay.portal.model.Role role, boolean merge)
234         throws SystemException {
235         FinderCacheUtil.clearCache("Groups_Roles");
236         FinderCacheUtil.clearCache("Roles_Permissions");
237         FinderCacheUtil.clearCache("Users_Roles");
238 
239         Session session = null;
240 
241         try {
242             session = openSession();
243 
244             if (merge) {
245                 session.merge(role);
246             }
247             else {
248                 if (role.isNew()) {
249                     session.save(role);
250                 }
251             }
252 
253             session.flush();
254 
255             role.setNew(false);
256 
257             return role;
258         }
259         catch (Exception e) {
260             throw processException(e);
261         }
262         finally {
263             closeSession(session);
264 
265             FinderCacheUtil.clearCache(Role.class.getName());
266         }
267     }
268 
269     public Role findByPrimaryKey(long roleId)
270         throws NoSuchRoleException, SystemException {
271         Role role = fetchByPrimaryKey(roleId);
272 
273         if (role == null) {
274             if (_log.isWarnEnabled()) {
275                 _log.warn("No Role exists with the primary key " + roleId);
276             }
277 
278             throw new NoSuchRoleException(
279                 "No Role exists with the primary key " + roleId);
280         }
281 
282         return role;
283     }
284 
285     public Role fetchByPrimaryKey(long roleId) throws SystemException {
286         Session session = null;
287 
288         try {
289             session = openSession();
290 
291             return (Role)session.get(RoleImpl.class, new Long(roleId));
292         }
293         catch (Exception e) {
294             throw processException(e);
295         }
296         finally {
297             closeSession(session);
298         }
299     }
300 
301     public List<Role> findByCompanyId(long companyId) throws SystemException {
302         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
303         String finderClassName = Role.class.getName();
304         String finderMethodName = "findByCompanyId";
305         String[] finderParams = new String[] { Long.class.getName() };
306         Object[] finderArgs = new Object[] { new Long(companyId) };
307 
308         Object result = null;
309 
310         if (finderClassNameCacheEnabled) {
311             result = FinderCacheUtil.getResult(finderClassName,
312                     finderMethodName, finderParams, finderArgs, this);
313         }
314 
315         if (result == null) {
316             Session session = null;
317 
318             try {
319                 session = openSession();
320 
321                 StringBuilder query = new StringBuilder();
322 
323                 query.append("FROM com.liferay.portal.model.Role WHERE ");
324 
325                 query.append("companyId = ?");
326 
327                 query.append(" ");
328 
329                 query.append("ORDER BY ");
330 
331                 query.append("name ASC");
332 
333                 Query q = session.createQuery(query.toString());
334 
335                 QueryPos qPos = QueryPos.getInstance(q);
336 
337                 qPos.add(companyId);
338 
339                 List<Role> list = q.list();
340 
341                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
342                     finderClassName, finderMethodName, finderParams,
343                     finderArgs, list);
344 
345                 return list;
346             }
347             catch (Exception e) {
348                 throw processException(e);
349             }
350             finally {
351                 closeSession(session);
352             }
353         }
354         else {
355             return (List<Role>)result;
356         }
357     }
358 
359     public List<Role> findByCompanyId(long companyId, int start, int end)
360         throws SystemException {
361         return findByCompanyId(companyId, start, end, null);
362     }
363 
364     public List<Role> findByCompanyId(long companyId, int start, int end,
365         OrderByComparator obc) throws SystemException {
366         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
367         String finderClassName = Role.class.getName();
368         String finderMethodName = "findByCompanyId";
369         String[] finderParams = new String[] {
370                 Long.class.getName(),
371                 
372                 "java.lang.Integer", "java.lang.Integer",
373                 "com.liferay.portal.kernel.util.OrderByComparator"
374             };
375         Object[] finderArgs = new Object[] {
376                 new Long(companyId),
377                 
378                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
379             };
380 
381         Object result = null;
382 
383         if (finderClassNameCacheEnabled) {
384             result = FinderCacheUtil.getResult(finderClassName,
385                     finderMethodName, finderParams, finderArgs, this);
386         }
387 
388         if (result == null) {
389             Session session = null;
390 
391             try {
392                 session = openSession();
393 
394                 StringBuilder query = new StringBuilder();
395 
396                 query.append("FROM com.liferay.portal.model.Role WHERE ");
397 
398                 query.append("companyId = ?");
399 
400                 query.append(" ");
401 
402                 if (obc != null) {
403                     query.append("ORDER BY ");
404                     query.append(obc.getOrderBy());
405                 }
406 
407                 else {
408                     query.append("ORDER BY ");
409 
410                     query.append("name ASC");
411                 }
412 
413                 Query q = session.createQuery(query.toString());
414 
415                 QueryPos qPos = QueryPos.getInstance(q);
416 
417                 qPos.add(companyId);
418 
419                 List<Role> list = (List<Role>)QueryUtil.list(q, getDialect(),
420                         start, end);
421 
422                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
423                     finderClassName, finderMethodName, finderParams,
424                     finderArgs, list);
425 
426                 return list;
427             }
428             catch (Exception e) {
429                 throw processException(e);
430             }
431             finally {
432                 closeSession(session);
433             }
434         }
435         else {
436             return (List<Role>)result;
437         }
438     }
439 
440     public Role findByCompanyId_First(long companyId, OrderByComparator obc)
441         throws NoSuchRoleException, SystemException {
442         List<Role> list = findByCompanyId(companyId, 0, 1, obc);
443 
444         if (list.size() == 0) {
445             StringBuilder msg = new StringBuilder();
446 
447             msg.append("No Role exists with the key {");
448 
449             msg.append("companyId=" + companyId);
450 
451             msg.append(StringPool.CLOSE_CURLY_BRACE);
452 
453             throw new NoSuchRoleException(msg.toString());
454         }
455         else {
456             return list.get(0);
457         }
458     }
459 
460     public Role findByCompanyId_Last(long companyId, OrderByComparator obc)
461         throws NoSuchRoleException, SystemException {
462         int count = countByCompanyId(companyId);
463 
464         List<Role> list = findByCompanyId(companyId, count - 1, count, obc);
465 
466         if (list.size() == 0) {
467             StringBuilder msg = new StringBuilder();
468 
469             msg.append("No Role exists with the key {");
470 
471             msg.append("companyId=" + companyId);
472 
473             msg.append(StringPool.CLOSE_CURLY_BRACE);
474 
475             throw new NoSuchRoleException(msg.toString());
476         }
477         else {
478             return list.get(0);
479         }
480     }
481 
482     public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
483         OrderByComparator obc) throws NoSuchRoleException, SystemException {
484         Role role = findByPrimaryKey(roleId);
485 
486         int count = countByCompanyId(companyId);
487 
488         Session session = null;
489 
490         try {
491             session = openSession();
492 
493             StringBuilder query = new StringBuilder();
494 
495             query.append("FROM com.liferay.portal.model.Role WHERE ");
496 
497             query.append("companyId = ?");
498 
499             query.append(" ");
500 
501             if (obc != null) {
502                 query.append("ORDER BY ");
503                 query.append(obc.getOrderBy());
504             }
505 
506             else {
507                 query.append("ORDER BY ");
508 
509                 query.append("name ASC");
510             }
511 
512             Query q = session.createQuery(query.toString());
513 
514             QueryPos qPos = QueryPos.getInstance(q);
515 
516             qPos.add(companyId);
517 
518             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, role);
519 
520             Role[] array = new RoleImpl[3];
521 
522             array[0] = (Role)objArray[0];
523             array[1] = (Role)objArray[1];
524             array[2] = (Role)objArray[2];
525 
526             return array;
527         }
528         catch (Exception e) {
529             throw processException(e);
530         }
531         finally {
532             closeSession(session);
533         }
534     }
535 
536     public Role findByC_N(long companyId, String name)
537         throws NoSuchRoleException, SystemException {
538         Role role = fetchByC_N(companyId, name);
539 
540         if (role == null) {
541             StringBuilder msg = new StringBuilder();
542 
543             msg.append("No Role exists with the key {");
544 
545             msg.append("companyId=" + companyId);
546 
547             msg.append(", ");
548             msg.append("name=" + name);
549 
550             msg.append(StringPool.CLOSE_CURLY_BRACE);
551 
552             if (_log.isWarnEnabled()) {
553                 _log.warn(msg.toString());
554             }
555 
556             throw new NoSuchRoleException(msg.toString());
557         }
558 
559         return role;
560     }
561 
562     public Role fetchByC_N(long companyId, String name)
563         throws SystemException {
564         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
565         String finderClassName = Role.class.getName();
566         String finderMethodName = "fetchByC_N";
567         String[] finderParams = new String[] {
568                 Long.class.getName(), String.class.getName()
569             };
570         Object[] finderArgs = new Object[] { new Long(companyId), name };
571 
572         Object result = null;
573 
574         if (finderClassNameCacheEnabled) {
575             result = FinderCacheUtil.getResult(finderClassName,
576                     finderMethodName, finderParams, finderArgs, this);
577         }
578 
579         if (result == null) {
580             Session session = null;
581 
582             try {
583                 session = openSession();
584 
585                 StringBuilder query = new StringBuilder();
586 
587                 query.append("FROM com.liferay.portal.model.Role WHERE ");
588 
589                 query.append("companyId = ?");
590 
591                 query.append(" AND ");
592 
593                 if (name == null) {
594                     query.append("name IS NULL");
595                 }
596                 else {
597                     query.append("name = ?");
598                 }
599 
600                 query.append(" ");
601 
602                 query.append("ORDER BY ");
603 
604                 query.append("name ASC");
605 
606                 Query q = session.createQuery(query.toString());
607 
608                 QueryPos qPos = QueryPos.getInstance(q);
609 
610                 qPos.add(companyId);
611 
612                 if (name != null) {
613                     qPos.add(name);
614                 }
615 
616                 List<Role> list = q.list();
617 
618                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
619                     finderClassName, finderMethodName, finderParams,
620                     finderArgs, list);
621 
622                 if (list.size() == 0) {
623                     return null;
624                 }
625                 else {
626                     return list.get(0);
627                 }
628             }
629             catch (Exception e) {
630                 throw processException(e);
631             }
632             finally {
633                 closeSession(session);
634             }
635         }
636         else {
637             List<Role> list = (List<Role>)result;
638 
639             if (list.size() == 0) {
640                 return null;
641             }
642             else {
643                 return list.get(0);
644             }
645         }
646     }
647 
648     public Role findByC_C_C(long companyId, long classNameId, long classPK)
649         throws NoSuchRoleException, SystemException {
650         Role role = fetchByC_C_C(companyId, classNameId, classPK);
651 
652         if (role == null) {
653             StringBuilder msg = new StringBuilder();
654 
655             msg.append("No Role exists with the key {");
656 
657             msg.append("companyId=" + companyId);
658 
659             msg.append(", ");
660             msg.append("classNameId=" + classNameId);
661 
662             msg.append(", ");
663             msg.append("classPK=" + classPK);
664 
665             msg.append(StringPool.CLOSE_CURLY_BRACE);
666 
667             if (_log.isWarnEnabled()) {
668                 _log.warn(msg.toString());
669             }
670 
671             throw new NoSuchRoleException(msg.toString());
672         }
673 
674         return role;
675     }
676 
677     public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
678         throws SystemException {
679         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
680         String finderClassName = Role.class.getName();
681         String finderMethodName = "fetchByC_C_C";
682         String[] finderParams = new String[] {
683                 Long.class.getName(), Long.class.getName(), Long.class.getName()
684             };
685         Object[] finderArgs = new Object[] {
686                 new Long(companyId), new Long(classNameId), new Long(classPK)
687             };
688 
689         Object result = null;
690 
691         if (finderClassNameCacheEnabled) {
692             result = FinderCacheUtil.getResult(finderClassName,
693                     finderMethodName, finderParams, finderArgs, this);
694         }
695 
696         if (result == null) {
697             Session session = null;
698 
699             try {
700                 session = openSession();
701 
702                 StringBuilder query = new StringBuilder();
703 
704                 query.append("FROM com.liferay.portal.model.Role WHERE ");
705 
706                 query.append("companyId = ?");
707 
708                 query.append(" AND ");
709 
710                 query.append("classNameId = ?");
711 
712                 query.append(" AND ");
713 
714                 query.append("classPK = ?");
715 
716                 query.append(" ");
717 
718                 query.append("ORDER BY ");
719 
720                 query.append("name ASC");
721 
722                 Query q = session.createQuery(query.toString());
723 
724                 QueryPos qPos = QueryPos.getInstance(q);
725 
726                 qPos.add(companyId);
727 
728                 qPos.add(classNameId);
729 
730                 qPos.add(classPK);
731 
732                 List<Role> list = q.list();
733 
734                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
735                     finderClassName, finderMethodName, finderParams,
736                     finderArgs, list);
737 
738                 if (list.size() == 0) {
739                     return null;
740                 }
741                 else {
742                     return list.get(0);
743                 }
744             }
745             catch (Exception e) {
746                 throw processException(e);
747             }
748             finally {
749                 closeSession(session);
750             }
751         }
752         else {
753             List<Role> list = (List<Role>)result;
754 
755             if (list.size() == 0) {
756                 return null;
757             }
758             else {
759                 return list.get(0);
760             }
761         }
762     }
763 
764     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
765         throws SystemException {
766         Session session = null;
767 
768         try {
769             session = openSession();
770 
771             dynamicQuery.compile(session);
772 
773             return dynamicQuery.list();
774         }
775         catch (Exception e) {
776             throw processException(e);
777         }
778         finally {
779             closeSession(session);
780         }
781     }
782 
783     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
784         int start, int end) throws SystemException {
785         Session session = null;
786 
787         try {
788             session = openSession();
789 
790             dynamicQuery.setLimit(start, end);
791 
792             dynamicQuery.compile(session);
793 
794             return dynamicQuery.list();
795         }
796         catch (Exception e) {
797             throw processException(e);
798         }
799         finally {
800             closeSession(session);
801         }
802     }
803 
804     public List<Role> findAll() throws SystemException {
805         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
806     }
807 
808     public List<Role> findAll(int start, int end) throws SystemException {
809         return findAll(start, end, null);
810     }
811 
812     public List<Role> findAll(int start, int end, OrderByComparator obc)
813         throws SystemException {
814         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
815         String finderClassName = Role.class.getName();
816         String finderMethodName = "findAll";
817         String[] finderParams = new String[] {
818                 "java.lang.Integer", "java.lang.Integer",
819                 "com.liferay.portal.kernel.util.OrderByComparator"
820             };
821         Object[] finderArgs = new Object[] {
822                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
823             };
824 
825         Object result = null;
826 
827         if (finderClassNameCacheEnabled) {
828             result = FinderCacheUtil.getResult(finderClassName,
829                     finderMethodName, finderParams, finderArgs, this);
830         }
831 
832         if (result == null) {
833             Session session = null;
834 
835             try {
836                 session = openSession();
837 
838                 StringBuilder query = new StringBuilder();
839 
840                 query.append("FROM com.liferay.portal.model.Role ");
841 
842                 if (obc != null) {
843                     query.append("ORDER BY ");
844                     query.append(obc.getOrderBy());
845                 }
846 
847                 else {
848                     query.append("ORDER BY ");
849 
850                     query.append("name ASC");
851                 }
852 
853                 Query q = session.createQuery(query.toString());
854 
855                 List<Role> list = (List<Role>)QueryUtil.list(q, getDialect(),
856                         start, end);
857 
858                 if (obc == null) {
859                     Collections.sort(list);
860                 }
861 
862                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
863                     finderClassName, finderMethodName, finderParams,
864                     finderArgs, list);
865 
866                 return list;
867             }
868             catch (Exception e) {
869                 throw processException(e);
870             }
871             finally {
872                 closeSession(session);
873             }
874         }
875         else {
876             return (List<Role>)result;
877         }
878     }
879 
880     public void removeByCompanyId(long companyId) throws SystemException {
881         for (Role role : findByCompanyId(companyId)) {
882             remove(role);
883         }
884     }
885 
886     public void removeByC_N(long companyId, String name)
887         throws NoSuchRoleException, SystemException {
888         Role role = findByC_N(companyId, name);
889 
890         remove(role);
891     }
892 
893     public void removeByC_C_C(long companyId, long classNameId, long classPK)
894         throws NoSuchRoleException, SystemException {
895         Role role = findByC_C_C(companyId, classNameId, classPK);
896 
897         remove(role);
898     }
899 
900     public void removeAll() throws SystemException {
901         for (Role role : findAll()) {
902             remove(role);
903         }
904     }
905 
906     public int countByCompanyId(long companyId) throws SystemException {
907         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
908         String finderClassName = Role.class.getName();
909         String finderMethodName = "countByCompanyId";
910         String[] finderParams = new String[] { Long.class.getName() };
911         Object[] finderArgs = new Object[] { new Long(companyId) };
912 
913         Object result = null;
914 
915         if (finderClassNameCacheEnabled) {
916             result = FinderCacheUtil.getResult(finderClassName,
917                     finderMethodName, finderParams, finderArgs, this);
918         }
919 
920         if (result == null) {
921             Session session = null;
922 
923             try {
924                 session = openSession();
925 
926                 StringBuilder query = new StringBuilder();
927 
928                 query.append("SELECT COUNT(*) ");
929                 query.append("FROM com.liferay.portal.model.Role WHERE ");
930 
931                 query.append("companyId = ?");
932 
933                 query.append(" ");
934 
935                 Query q = session.createQuery(query.toString());
936 
937                 QueryPos qPos = QueryPos.getInstance(q);
938 
939                 qPos.add(companyId);
940 
941                 Long count = null;
942 
943                 Iterator<Long> itr = q.list().iterator();
944 
945                 if (itr.hasNext()) {
946                     count = itr.next();
947                 }
948 
949                 if (count == null) {
950                     count = new Long(0);
951                 }
952 
953                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
954                     finderClassName, finderMethodName, finderParams,
955                     finderArgs, count);
956 
957                 return count.intValue();
958             }
959             catch (Exception e) {
960                 throw processException(e);
961             }
962             finally {
963                 closeSession(session);
964             }
965         }
966         else {
967             return ((Long)result).intValue();
968         }
969     }
970 
971     public int countByC_N(long companyId, String name)
972         throws SystemException {
973         boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
974         String finderClassName = Role.class.getName();
975         String finderMethodName = "countByC_N";
976         String[] finderParams = new String[] {
977                 Long.class.getName(), String.class.getName()
978             };
979         Object[] finderArgs = new Object[] { new Long(companyId), name };
980 
981         Object result = null;
982 
983         if (finderClassNameCacheEnabled) {
984             result = FinderCacheUtil.getResult(finderClassName,
985                     finderMethodName, finderParams, finderArgs, this);
986         }
987 
988         if (result == null) {
989             Session session = null;
990 
991             try {
992                 session = openSession();
993 
994                 StringBuilder query = new StringBuilder();
995 
996                 query.append("SELECT COUNT(*) ");
997                 query.append("FROM com.liferay.portal.model.Role WHERE ");
998 
999                 query.append("companyId = ?");
1000
1001                query.append(" AND ");
1002
1003                if (name == null) {
1004                    query.append("name IS NULL");
1005                }
1006                else {
1007                    query.append("name = ?");
1008                }
1009
1010                query.append(" ");
1011
1012                Query q = session.createQuery(query.toString());
1013
1014                QueryPos qPos = QueryPos.getInstance(q);
1015
1016                qPos.add(companyId);
1017
1018                if (name != null) {
1019                    qPos.add(name);
1020                }
1021
1022                Long count = null;
1023
1024                Iterator<Long> itr = q.list().iterator();
1025
1026                if (itr.hasNext()) {
1027                    count = itr.next();
1028                }
1029
1030                if (count == null) {
1031                    count = new Long(0);
1032                }
1033
1034                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1035                    finderClassName, finderMethodName, finderParams,
1036                    finderArgs, count);
1037
1038                return count.intValue();
1039            }
1040            catch (Exception e) {
1041                throw processException(e);
1042            }
1043            finally {
1044                closeSession(session);
1045            }
1046        }
1047        else {
1048            return ((Long)result).intValue();
1049        }
1050    }
1051
1052    public int countByC_C_C(long companyId, long classNameId, long classPK)
1053        throws SystemException {
1054        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
1055        String finderClassName = Role.class.getName();
1056        String finderMethodName = "countByC_C_C";
1057        String[] finderParams = new String[] {
1058                Long.class.getName(), Long.class.getName(), Long.class.getName()
1059            };
1060        Object[] finderArgs = new Object[] {
1061                new Long(companyId), new Long(classNameId), new Long(classPK)
1062            };
1063
1064        Object result = null;
1065
1066        if (finderClassNameCacheEnabled) {
1067            result = FinderCacheUtil.getResult(finderClassName,
1068                    finderMethodName, finderParams, finderArgs, this);
1069        }
1070
1071        if (result == null) {
1072            Session session = null;
1073
1074            try {
1075                session = openSession();
1076
1077                StringBuilder query = new StringBuilder();
1078
1079                query.append("SELECT COUNT(*) ");
1080                query.append("FROM com.liferay.portal.model.Role WHERE ");
1081
1082                query.append("companyId = ?");
1083
1084                query.append(" AND ");
1085
1086                query.append("classNameId = ?");
1087
1088                query.append(" AND ");
1089
1090                query.append("classPK = ?");
1091
1092                query.append(" ");
1093
1094                Query q = session.createQuery(query.toString());
1095
1096                QueryPos qPos = QueryPos.getInstance(q);
1097
1098                qPos.add(companyId);
1099
1100                qPos.add(classNameId);
1101
1102                qPos.add(classPK);
1103
1104                Long count = null;
1105
1106                Iterator<Long> itr = q.list().iterator();
1107
1108                if (itr.hasNext()) {
1109                    count = itr.next();
1110                }
1111
1112                if (count == null) {
1113                    count = new Long(0);
1114                }
1115
1116                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1117                    finderClassName, finderMethodName, finderParams,
1118                    finderArgs, count);
1119
1120                return count.intValue();
1121            }
1122            catch (Exception e) {
1123                throw processException(e);
1124            }
1125            finally {
1126                closeSession(session);
1127            }
1128        }
1129        else {
1130            return ((Long)result).intValue();
1131        }
1132    }
1133
1134    public int countAll() throws SystemException {
1135        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED;
1136        String finderClassName = Role.class.getName();
1137        String finderMethodName = "countAll";
1138        String[] finderParams = new String[] {  };
1139        Object[] finderArgs = new Object[] {  };
1140
1141        Object result = null;
1142
1143        if (finderClassNameCacheEnabled) {
1144            result = FinderCacheUtil.getResult(finderClassName,
1145                    finderMethodName, finderParams, finderArgs, this);
1146        }
1147
1148        if (result == null) {
1149            Session session = null;
1150
1151            try {
1152                session = openSession();
1153
1154                Query q = session.createQuery(
1155                        "SELECT COUNT(*) FROM com.liferay.portal.model.Role");
1156
1157                Long count = null;
1158
1159                Iterator<Long> itr = q.list().iterator();
1160
1161                if (itr.hasNext()) {
1162                    count = itr.next();
1163                }
1164
1165                if (count == null) {
1166                    count = new Long(0);
1167                }
1168
1169                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1170                    finderClassName, finderMethodName, finderParams,
1171                    finderArgs, count);
1172
1173                return count.intValue();
1174            }
1175            catch (Exception e) {
1176                throw processException(e);
1177            }
1178            finally {
1179                closeSession(session);
1180            }
1181        }
1182        else {
1183            return ((Long)result).intValue();
1184        }
1185    }
1186
1187    public List<com.liferay.portal.model.Group> getGroups(long pk)
1188        throws SystemException {
1189        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1190    }
1191
1192    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1193        int end) throws SystemException {
1194        return getGroups(pk, start, end, null);
1195    }
1196
1197    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1198        int end, OrderByComparator obc) throws SystemException {
1199        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1200
1201        String finderClassName = "Groups_Roles";
1202
1203        String finderMethodName = "getGroups";
1204        String[] finderParams = new String[] {
1205                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1206                "com.liferay.portal.kernel.util.OrderByComparator"
1207            };
1208        Object[] finderArgs = new Object[] {
1209                new Long(pk), String.valueOf(start), String.valueOf(end),
1210                String.valueOf(obc)
1211            };
1212
1213        Object result = null;
1214
1215        if (finderClassNameCacheEnabled) {
1216            result = FinderCacheUtil.getResult(finderClassName,
1217                    finderMethodName, finderParams, finderArgs, this);
1218        }
1219
1220        if (result == null) {
1221            Session session = null;
1222
1223            try {
1224                session = openSession();
1225
1226                StringBuilder sb = new StringBuilder();
1227
1228                sb.append(_SQL_GETGROUPS);
1229
1230                if (obc != null) {
1231                    sb.append("ORDER BY ");
1232                    sb.append(obc.getOrderBy());
1233                }
1234
1235                else {
1236                    sb.append("ORDER BY ");
1237
1238                    sb.append("Group_.name ASC");
1239                }
1240
1241                String sql = sb.toString();
1242
1243                SQLQuery q = session.createSQLQuery(sql);
1244
1245                q.addEntity("Group_",
1246                    com.liferay.portal.model.impl.GroupImpl.class);
1247
1248                QueryPos qPos = QueryPos.getInstance(q);
1249
1250                qPos.add(pk);
1251
1252                List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1253                        getDialect(), start, end);
1254
1255                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1256                    finderClassName, finderMethodName, finderParams,
1257                    finderArgs, list);
1258
1259                return list;
1260            }
1261            catch (Exception e) {
1262                throw processException(e);
1263            }
1264            finally {
1265                closeSession(session);
1266            }
1267        }
1268        else {
1269            return (List<com.liferay.portal.model.Group>)result;
1270        }
1271    }
1272
1273    public int getGroupsSize(long pk) throws SystemException {
1274        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1275
1276        String finderClassName = "Groups_Roles";
1277
1278        String finderMethodName = "getGroupsSize";
1279        String[] finderParams = new String[] { Long.class.getName() };
1280        Object[] finderArgs = new Object[] { new Long(pk) };
1281
1282        Object result = null;
1283
1284        if (finderClassNameCacheEnabled) {
1285            result = FinderCacheUtil.getResult(finderClassName,
1286                    finderMethodName, finderParams, finderArgs, this);
1287        }
1288
1289        if (result == null) {
1290            Session session = null;
1291
1292            try {
1293                session = openSession();
1294
1295                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1296
1297                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1298
1299                QueryPos qPos = QueryPos.getInstance(q);
1300
1301                qPos.add(pk);
1302
1303                Long count = null;
1304
1305                Iterator<Long> itr = q.list().iterator();
1306
1307                if (itr.hasNext()) {
1308                    count = itr.next();
1309                }
1310
1311                if (count == null) {
1312                    count = new Long(0);
1313                }
1314
1315                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1316                    finderClassName, finderMethodName, finderParams,
1317                    finderArgs, count);
1318
1319                return count.intValue();
1320            }
1321            catch (Exception e) {
1322                throw processException(e);
1323            }
1324            finally {
1325                closeSession(session);
1326            }
1327        }
1328        else {
1329            return ((Long)result).intValue();
1330        }
1331    }
1332
1333    public boolean containsGroup(long pk, long groupPK)
1334        throws SystemException {
1335        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_GROUPS_ROLES;
1336
1337        String finderClassName = "Groups_Roles";
1338
1339        String finderMethodName = "containsGroups";
1340        String[] finderParams = new String[] {
1341                Long.class.getName(),
1342                
1343                Long.class.getName()
1344            };
1345        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1346
1347        Object result = null;
1348
1349        if (finderClassNameCacheEnabled) {
1350            result = FinderCacheUtil.getResult(finderClassName,
1351                    finderMethodName, finderParams, finderArgs, this);
1352        }
1353
1354        if (result == null) {
1355            try {
1356                Boolean value = Boolean.valueOf(containsGroup.contains(pk,
1357                            groupPK));
1358
1359                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1360                    finderClassName, finderMethodName, finderParams,
1361                    finderArgs, value);
1362
1363                return value.booleanValue();
1364            }
1365            catch (Exception e) {
1366                throw processException(e);
1367            }
1368        }
1369        else {
1370            return ((Boolean)result).booleanValue();
1371        }
1372    }
1373
1374    public boolean containsGroups(long pk) throws SystemException {
1375        if (getGroupsSize(pk) > 0) {
1376            return true;
1377        }
1378        else {
1379            return false;
1380        }
1381    }
1382
1383    public void addGroup(long pk, long groupPK) throws SystemException {
1384        try {
1385            addGroup.add(pk, groupPK);
1386        }
1387        catch (Exception e) {
1388            throw processException(e);
1389        }
1390        finally {
1391            FinderCacheUtil.clearCache("Groups_Roles");
1392        }
1393    }
1394
1395    public void addGroup(long pk, com.liferay.portal.model.Group group)
1396        throws SystemException {
1397        try {
1398            addGroup.add(pk, group.getPrimaryKey());
1399        }
1400        catch (Exception e) {
1401            throw processException(e);
1402        }
1403        finally {
1404            FinderCacheUtil.clearCache("Groups_Roles");
1405        }
1406    }
1407
1408    public void addGroups(long pk, long[] groupPKs) throws SystemException {
1409        try {
1410            for (long groupPK : groupPKs) {
1411                addGroup.add(pk, groupPK);
1412            }
1413        }
1414        catch (Exception e) {
1415            throw processException(e);
1416        }
1417        finally {
1418            FinderCacheUtil.clearCache("Groups_Roles");
1419        }
1420    }
1421
1422    public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1423        throws SystemException {
1424        try {
1425            for (com.liferay.portal.model.Group group : groups) {
1426                addGroup.add(pk, group.getPrimaryKey());
1427            }
1428        }
1429        catch (Exception e) {
1430            throw processException(e);
1431        }
1432        finally {
1433            FinderCacheUtil.clearCache("Groups_Roles");
1434        }
1435    }
1436
1437    public void clearGroups(long pk) throws SystemException {
1438        try {
1439            clearGroups.clear(pk);
1440        }
1441        catch (Exception e) {
1442            throw processException(e);
1443        }
1444        finally {
1445            FinderCacheUtil.clearCache("Groups_Roles");
1446        }
1447    }
1448
1449    public void removeGroup(long pk, long groupPK) throws SystemException {
1450        try {
1451            removeGroup.remove(pk, groupPK);
1452        }
1453        catch (Exception e) {
1454            throw processException(e);
1455        }
1456        finally {
1457            FinderCacheUtil.clearCache("Groups_Roles");
1458        }
1459    }
1460
1461    public void removeGroup(long pk, com.liferay.portal.model.Group group)
1462        throws SystemException {
1463        try {
1464            removeGroup.remove(pk, group.getPrimaryKey());
1465        }
1466        catch (Exception e) {
1467            throw processException(e);
1468        }
1469        finally {
1470            FinderCacheUtil.clearCache("Groups_Roles");
1471        }
1472    }
1473
1474    public void removeGroups(long pk, long[] groupPKs)
1475        throws SystemException {
1476        try {
1477            for (long groupPK : groupPKs) {
1478                removeGroup.remove(pk, groupPK);
1479            }
1480        }
1481        catch (Exception e) {
1482            throw processException(e);
1483        }
1484        finally {
1485            FinderCacheUtil.clearCache("Groups_Roles");
1486        }
1487    }
1488
1489    public void removeGroups(long pk,
1490        List<com.liferay.portal.model.Group> groups) throws SystemException {
1491        try {
1492            for (com.liferay.portal.model.Group group : groups) {
1493                removeGroup.remove(pk, group.getPrimaryKey());
1494            }
1495        }
1496        catch (Exception e) {
1497            throw processException(e);
1498        }
1499        finally {
1500            FinderCacheUtil.clearCache("Groups_Roles");
1501        }
1502    }
1503
1504    public void setGroups(long pk, long[] groupPKs) throws SystemException {
1505        try {
1506            clearGroups.clear(pk);
1507
1508            for (long groupPK : groupPKs) {
1509                addGroup.add(pk, groupPK);
1510            }
1511        }
1512        catch (Exception e) {
1513            throw processException(e);
1514        }
1515        finally {
1516            FinderCacheUtil.clearCache("Groups_Roles");
1517        }
1518    }
1519
1520    public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1521        throws SystemException {
1522        try {
1523            clearGroups.clear(pk);
1524
1525            for (com.liferay.portal.model.Group group : groups) {
1526                addGroup.add(pk, group.getPrimaryKey());
1527            }
1528        }
1529        catch (Exception e) {
1530            throw processException(e);
1531        }
1532        finally {
1533            FinderCacheUtil.clearCache("Groups_Roles");
1534        }
1535    }
1536
1537    public List<com.liferay.portal.model.Permission> getPermissions(long pk)
1538        throws SystemException {
1539        return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1540    }
1541
1542    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
1543        int start, int end) throws SystemException {
1544        return getPermissions(pk, start, end, null);
1545    }
1546
1547    public List<com.liferay.portal.model.Permission> getPermissions(long pk,
1548        int start, int end, OrderByComparator obc) throws SystemException {
1549        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
1550
1551        String finderClassName = "Roles_Permissions";
1552
1553        String finderMethodName = "getPermissions";
1554        String[] finderParams = new String[] {
1555                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1556                "com.liferay.portal.kernel.util.OrderByComparator"
1557            };
1558        Object[] finderArgs = new Object[] {
1559                new Long(pk), String.valueOf(start), String.valueOf(end),
1560                String.valueOf(obc)
1561            };
1562
1563        Object result = null;
1564
1565        if (finderClassNameCacheEnabled) {
1566            result = FinderCacheUtil.getResult(finderClassName,
1567                    finderMethodName, finderParams, finderArgs, this);
1568        }
1569
1570        if (result == null) {
1571            Session session = null;
1572
1573            try {
1574                session = openSession();
1575
1576                StringBuilder sb = new StringBuilder();
1577
1578                sb.append(_SQL_GETPERMISSIONS);
1579
1580                if (obc != null) {
1581                    sb.append("ORDER BY ");
1582                    sb.append(obc.getOrderBy());
1583                }
1584
1585                String sql = sb.toString();
1586
1587                SQLQuery q = session.createSQLQuery(sql);
1588
1589                q.addEntity("Permission_",
1590                    com.liferay.portal.model.impl.PermissionImpl.class);
1591
1592                QueryPos qPos = QueryPos.getInstance(q);
1593
1594                qPos.add(pk);
1595
1596                List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
1597                        getDialect(), start, end);
1598
1599                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1600                    finderClassName, finderMethodName, finderParams,
1601                    finderArgs, list);
1602
1603                return list;
1604            }
1605            catch (Exception e) {
1606                throw processException(e);
1607            }
1608            finally {
1609                closeSession(session);
1610            }
1611        }
1612        else {
1613            return (List<com.liferay.portal.model.Permission>)result;
1614        }
1615    }
1616
1617    public int getPermissionsSize(long pk) throws SystemException {
1618        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
1619
1620        String finderClassName = "Roles_Permissions";
1621
1622        String finderMethodName = "getPermissionsSize";
1623        String[] finderParams = new String[] { Long.class.getName() };
1624        Object[] finderArgs = new Object[] { new Long(pk) };
1625
1626        Object result = null;
1627
1628        if (finderClassNameCacheEnabled) {
1629            result = FinderCacheUtil.getResult(finderClassName,
1630                    finderMethodName, finderParams, finderArgs, this);
1631        }
1632
1633        if (result == null) {
1634            Session session = null;
1635
1636            try {
1637                session = openSession();
1638
1639                SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
1640
1641                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1642
1643                QueryPos qPos = QueryPos.getInstance(q);
1644
1645                qPos.add(pk);
1646
1647                Long count = null;
1648
1649                Iterator<Long> itr = q.list().iterator();
1650
1651                if (itr.hasNext()) {
1652                    count = itr.next();
1653                }
1654
1655                if (count == null) {
1656                    count = new Long(0);
1657                }
1658
1659                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1660                    finderClassName, finderMethodName, finderParams,
1661                    finderArgs, count);
1662
1663                return count.intValue();
1664            }
1665            catch (Exception e) {
1666                throw processException(e);
1667            }
1668            finally {
1669                closeSession(session);
1670            }
1671        }
1672        else {
1673            return ((Long)result).intValue();
1674        }
1675    }
1676
1677    public boolean containsPermission(long pk, long permissionPK)
1678        throws SystemException {
1679        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_ROLES_PERMISSIONS;
1680
1681        String finderClassName = "Roles_Permissions";
1682
1683        String finderMethodName = "containsPermissions";
1684        String[] finderParams = new String[] {
1685                Long.class.getName(),
1686                
1687                Long.class.getName()
1688            };
1689        Object[] finderArgs = new Object[] { new Long(pk), new Long(permissionPK) };
1690
1691        Object result = null;
1692
1693        if (finderClassNameCacheEnabled) {
1694            result = FinderCacheUtil.getResult(finderClassName,
1695                    finderMethodName, finderParams, finderArgs, this);
1696        }
1697
1698        if (result == null) {
1699            try {
1700                Boolean value = Boolean.valueOf(containsPermission.contains(
1701                            pk, permissionPK));
1702
1703                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1704                    finderClassName, finderMethodName, finderParams,
1705                    finderArgs, value);
1706
1707                return value.booleanValue();
1708            }
1709            catch (Exception e) {
1710                throw processException(e);
1711            }
1712        }
1713        else {
1714            return ((Boolean)result).booleanValue();
1715        }
1716    }
1717
1718    public boolean containsPermissions(long pk) throws SystemException {
1719        if (getPermissionsSize(pk) > 0) {
1720            return true;
1721        }
1722        else {
1723            return false;
1724        }
1725    }
1726
1727    public void addPermission(long pk, long permissionPK)
1728        throws SystemException {
1729        try {
1730            addPermission.add(pk, permissionPK);
1731        }
1732        catch (Exception e) {
1733            throw processException(e);
1734        }
1735        finally {
1736            FinderCacheUtil.clearCache("Roles_Permissions");
1737        }
1738    }
1739
1740    public void addPermission(long pk,
1741        com.liferay.portal.model.Permission permission)
1742        throws SystemException {
1743        try {
1744            addPermission.add(pk, permission.getPrimaryKey());
1745        }
1746        catch (Exception e) {
1747            throw processException(e);
1748        }
1749        finally {
1750            FinderCacheUtil.clearCache("Roles_Permissions");
1751        }
1752    }
1753
1754    public void addPermissions(long pk, long[] permissionPKs)
1755        throws SystemException {
1756        try {
1757            for (long permissionPK : permissionPKs) {
1758                addPermission.add(pk, permissionPK);
1759            }
1760        }
1761        catch (Exception e) {
1762            throw processException(e);
1763        }
1764        finally {
1765            FinderCacheUtil.clearCache("Roles_Permissions");
1766        }
1767    }
1768
1769    public void addPermissions(long pk,
1770        List<com.liferay.portal.model.Permission> permissions)
1771        throws SystemException {
1772        try {
1773            for (com.liferay.portal.model.Permission permission : permissions) {
1774                addPermission.add(pk, permission.getPrimaryKey());
1775            }
1776        }
1777        catch (Exception e) {
1778            throw processException(e);
1779        }
1780        finally {
1781            FinderCacheUtil.clearCache("Roles_Permissions");
1782        }
1783    }
1784
1785    public void clearPermissions(long pk) throws SystemException {
1786        try {
1787            clearPermissions.clear(pk);
1788        }
1789        catch (Exception e) {
1790            throw processException(e);
1791        }
1792        finally {
1793            FinderCacheUtil.clearCache("Roles_Permissions");
1794        }
1795    }
1796
1797    public void removePermission(long pk, long permissionPK)
1798        throws SystemException {
1799        try {
1800            removePermission.remove(pk, permissionPK);
1801        }
1802        catch (Exception e) {
1803            throw processException(e);
1804        }
1805        finally {
1806            FinderCacheUtil.clearCache("Roles_Permissions");
1807        }
1808    }
1809
1810    public void removePermission(long pk,
1811        com.liferay.portal.model.Permission permission)
1812        throws SystemException {
1813        try {
1814            removePermission.remove(pk, permission.getPrimaryKey());
1815        }
1816        catch (Exception e) {
1817            throw processException(e);
1818        }
1819        finally {
1820            FinderCacheUtil.clearCache("Roles_Permissions");
1821        }
1822    }
1823
1824    public void removePermissions(long pk, long[] permissionPKs)
1825        throws SystemException {
1826        try {
1827            for (long permissionPK : permissionPKs) {
1828                removePermission.remove(pk, permissionPK);
1829            }
1830        }
1831        catch (Exception e) {
1832            throw processException(e);
1833        }
1834        finally {
1835            FinderCacheUtil.clearCache("Roles_Permissions");
1836        }
1837    }
1838
1839    public void removePermissions(long pk,
1840        List<com.liferay.portal.model.Permission> permissions)
1841        throws SystemException {
1842        try {
1843            for (com.liferay.portal.model.Permission permission : permissions) {
1844                removePermission.remove(pk, permission.getPrimaryKey());
1845            }
1846        }
1847        catch (Exception e) {
1848            throw processException(e);
1849        }
1850        finally {
1851            FinderCacheUtil.clearCache("Roles_Permissions");
1852        }
1853    }
1854
1855    public void setPermissions(long pk, long[] permissionPKs)
1856        throws SystemException {
1857        try {
1858            clearPermissions.clear(pk);
1859
1860            for (long permissionPK : permissionPKs) {
1861                addPermission.add(pk, permissionPK);
1862            }
1863        }
1864        catch (Exception e) {
1865            throw processException(e);
1866        }
1867        finally {
1868            FinderCacheUtil.clearCache("Roles_Permissions");
1869        }
1870    }
1871
1872    public void setPermissions(long pk,
1873        List<com.liferay.portal.model.Permission> permissions)
1874        throws SystemException {
1875        try {
1876            clearPermissions.clear(pk);
1877
1878            for (com.liferay.portal.model.Permission permission : permissions) {
1879                addPermission.add(pk, permission.getPrimaryKey());
1880            }
1881        }
1882        catch (Exception e) {
1883            throw processException(e);
1884        }
1885        finally {
1886            FinderCacheUtil.clearCache("Roles_Permissions");
1887        }
1888    }
1889
1890    public List<com.liferay.portal.model.User> getUsers(long pk)
1891        throws SystemException {
1892        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1893    }
1894
1895    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1896        int end) throws SystemException {
1897        return getUsers(pk, start, end, null);
1898    }
1899
1900    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1901        int end, OrderByComparator obc) throws SystemException {
1902        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_USERS_ROLES;
1903
1904        String finderClassName = "Users_Roles";
1905
1906        String finderMethodName = "getUsers";
1907        String[] finderParams = new String[] {
1908                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1909                "com.liferay.portal.kernel.util.OrderByComparator"
1910            };
1911        Object[] finderArgs = new Object[] {
1912                new Long(pk), String.valueOf(start), String.valueOf(end),
1913                String.valueOf(obc)
1914            };
1915
1916        Object result = null;
1917
1918        if (finderClassNameCacheEnabled) {
1919            result = FinderCacheUtil.getResult(finderClassName,
1920                    finderMethodName, finderParams, finderArgs, this);
1921        }
1922
1923        if (result == null) {
1924            Session session = null;
1925
1926            try {
1927                session = openSession();
1928
1929                StringBuilder sb = new StringBuilder();
1930
1931                sb.append(_SQL_GETUSERS);
1932
1933                if (obc != null) {
1934                    sb.append("ORDER BY ");
1935                    sb.append(obc.getOrderBy());
1936                }
1937
1938                String sql = sb.toString();
1939
1940                SQLQuery q = session.createSQLQuery(sql);
1941
1942                q.addEntity("User_",
1943                    com.liferay.portal.model.impl.UserImpl.class);
1944
1945                QueryPos qPos = QueryPos.getInstance(q);
1946
1947                qPos.add(pk);
1948
1949                List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1950                        getDialect(), start, end);
1951
1952                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1953                    finderClassName, finderMethodName, finderParams,
1954                    finderArgs, list);
1955
1956                return list;
1957            }
1958            catch (Exception e) {
1959                throw processException(e);
1960            }
1961            finally {
1962                closeSession(session);
1963            }
1964        }
1965        else {
1966            return (List<com.liferay.portal.model.User>)result;
1967        }
1968    }
1969
1970    public int getUsersSize(long pk) throws SystemException {
1971        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_USERS_ROLES;
1972
1973        String finderClassName = "Users_Roles";
1974
1975        String finderMethodName = "getUsersSize";
1976        String[] finderParams = new String[] { Long.class.getName() };
1977        Object[] finderArgs = new Object[] { new Long(pk) };
1978
1979        Object result = null;
1980
1981        if (finderClassNameCacheEnabled) {
1982            result = FinderCacheUtil.getResult(finderClassName,
1983                    finderMethodName, finderParams, finderArgs, this);
1984        }
1985
1986        if (result == null) {
1987            Session session = null;
1988
1989            try {
1990                session = openSession();
1991
1992                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1993
1994                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1995
1996                QueryPos qPos = QueryPos.getInstance(q);
1997
1998                qPos.add(pk);
1999
2000                Long count = null;
2001
2002                Iterator<Long> itr = q.list().iterator();
2003
2004                if (itr.hasNext()) {
2005                    count = itr.next();
2006                }
2007
2008                if (count == null) {
2009                    count = new Long(0);
2010                }
2011
2012                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2013                    finderClassName, finderMethodName, finderParams,
2014                    finderArgs, count);
2015
2016                return count.intValue();
2017            }
2018            catch (Exception e) {
2019                throw processException(e);
2020            }
2021            finally {
2022                closeSession(session);
2023            }
2024        }
2025        else {
2026            return ((Long)result).intValue();
2027        }
2028    }
2029
2030    public boolean containsUser(long pk, long userPK) throws SystemException {
2031        boolean finderClassNameCacheEnabled = RoleModelImpl.CACHE_ENABLED_USERS_ROLES;
2032
2033        String finderClassName = "Users_Roles";
2034
2035        String finderMethodName = "containsUsers";
2036        String[] finderParams = new String[] {
2037                Long.class.getName(),
2038                
2039                Long.class.getName()
2040            };
2041        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
2042
2043        Object result = null;
2044
2045        if (finderClassNameCacheEnabled) {
2046            result = FinderCacheUtil.getResult(finderClassName,
2047                    finderMethodName, finderParams, finderArgs, this);
2048        }
2049
2050        if (result == null) {
2051            try {
2052                Boolean value = Boolean.valueOf(containsUser.contains(pk, userPK));
2053
2054                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2055                    finderClassName, finderMethodName, finderParams,
2056                    finderArgs, value);
2057
2058                return value.booleanValue();
2059            }
2060            catch (Exception e) {
2061                throw processException(e);
2062            }
2063        }
2064        else {
2065            return ((Boolean)result).booleanValue();
2066        }
2067    }
2068
2069    public boolean containsUsers(long pk) throws SystemException {
2070        if (getUsersSize(pk) > 0) {
2071            return true;
2072        }
2073        else {
2074            return false;
2075        }
2076    }
2077
2078    public void addUser(long pk, long userPK) throws SystemException {
2079        try {
2080            addUser.add(pk, userPK);
2081        }
2082        catch (Exception e) {
2083            throw processException(e);
2084        }
2085        finally {
2086            FinderCacheUtil.clearCache("Users_Roles");
2087        }
2088    }
2089
2090    public void addUser(long pk, com.liferay.portal.model.User user)
2091        throws SystemException {
2092        try {
2093            addUser.add(pk, user.getPrimaryKey());
2094        }
2095        catch (Exception e) {
2096            throw processException(e);
2097        }
2098        finally {
2099            FinderCacheUtil.clearCache("Users_Roles");
2100        }
2101    }
2102
2103    public void addUsers(long pk, long[] userPKs) throws SystemException {
2104        try {
2105            for (long userPK : userPKs) {
2106                addUser.add(pk, userPK);
2107            }
2108        }
2109        catch (Exception e) {
2110            throw processException(e);
2111        }
2112        finally {
2113            FinderCacheUtil.clearCache("Users_Roles");
2114        }
2115    }
2116
2117    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2118        throws SystemException {
2119        try {
2120            for (com.liferay.portal.model.User user : users) {
2121                addUser.add(pk, user.getPrimaryKey());
2122            }
2123        }
2124        catch (Exception e) {
2125            throw processException(e);
2126        }
2127        finally {
2128            FinderCacheUtil.clearCache("Users_Roles");
2129        }
2130    }
2131
2132    public void clearUsers(long pk) throws SystemException {
2133        try {
2134            clearUsers.clear(pk);
2135        }
2136        catch (Exception e) {
2137            throw processException(e);
2138        }
2139        finally {
2140            FinderCacheUtil.clearCache("Users_Roles");
2141        }
2142    }
2143
2144    public void removeUser(long pk, long userPK) throws SystemException {
2145        try {
2146            removeUser.remove(pk, userPK);
2147        }
2148        catch (Exception e) {
2149            throw processException(e);
2150        }
2151        finally {
2152            FinderCacheUtil.clearCache("Users_Roles");
2153        }
2154    }
2155
2156    public void removeUser(long pk, com.liferay.portal.model.User user)
2157        throws SystemException {
2158        try {
2159            removeUser.remove(pk, user.getPrimaryKey());
2160        }
2161        catch (Exception e) {
2162            throw processException(e);
2163        }
2164        finally {
2165            FinderCacheUtil.clearCache("Users_Roles");
2166        }
2167    }
2168
2169    public void removeUsers(long pk, long[] userPKs) throws SystemException {
2170        try {
2171            for (long userPK : userPKs) {
2172                removeUser.remove(pk, userPK);
2173            }
2174        }
2175        catch (Exception e) {
2176            throw processException(e);
2177        }
2178        finally {
2179            FinderCacheUtil.clearCache("Users_Roles");
2180        }
2181    }
2182
2183    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2184        throws SystemException {
2185        try {
2186            for (com.liferay.portal.model.User user : users) {
2187                removeUser.remove(pk, user.getPrimaryKey());
2188            }
2189        }
2190        catch (Exception e) {
2191            throw processException(e);
2192        }
2193        finally {
2194            FinderCacheUtil.clearCache("Users_Roles");
2195        }
2196    }
2197
2198    public void setUsers(long pk, long[] userPKs) throws SystemException {
2199        try {
2200            clearUsers.clear(pk);
2201
2202            for (long userPK : userPKs) {
2203                addUser.add(pk, userPK);
2204            }
2205        }
2206        catch (Exception e) {
2207            throw processException(e);
2208        }
2209        finally {
2210            FinderCacheUtil.clearCache("Users_Roles");
2211        }
2212    }
2213
2214    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2215        throws SystemException {
2216        try {
2217            clearUsers.clear(pk);
2218
2219            for (com.liferay.portal.model.User user : users) {
2220                addUser.add(pk, user.getPrimaryKey());
2221            }
2222        }
2223        catch (Exception e) {
2224            throw processException(e);
2225        }
2226        finally {
2227            FinderCacheUtil.clearCache("Users_Roles");
2228        }
2229    }
2230
2231    public void registerListener(ModelListener listener) {
2232        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2233
2234        listeners.add(listener);
2235
2236        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2237    }
2238
2239    public void unregisterListener(ModelListener listener) {
2240        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2241
2242        listeners.remove(listener);
2243
2244        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2245    }
2246
2247    public void afterPropertiesSet() {
2248        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2249                    com.liferay.portal.util.PropsUtil.get(
2250                        "value.object.listener.com.liferay.portal.model.Role")));
2251
2252        if (listenerClassNames.length > 0) {
2253            try {
2254                List<ModelListener> listeners = new ArrayList<ModelListener>();
2255
2256                for (String listenerClassName : listenerClassNames) {
2257                    listeners.add((ModelListener)Class.forName(
2258                            listenerClassName).newInstance());
2259                }
2260
2261                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2262            }
2263            catch (Exception e) {
2264                _log.error(e);
2265            }
2266        }
2267
2268        containsGroup = new ContainsGroup(this);
2269
2270        addGroup = new AddGroup(this);
2271        clearGroups = new ClearGroups(this);
2272        removeGroup = new RemoveGroup(this);
2273
2274        containsPermission = new ContainsPermission(this);
2275
2276        addPermission = new AddPermission(this);
2277        clearPermissions = new ClearPermissions(this);
2278        removePermission = new RemovePermission(this);
2279
2280        containsUser = new ContainsUser(this);
2281
2282        addUser = new AddUser(this);
2283        clearUsers = new ClearUsers(this);
2284        removeUser = new RemoveUser(this);
2285    }
2286
2287    protected ContainsGroup containsGroup;
2288    protected AddGroup addGroup;
2289    protected ClearGroups clearGroups;
2290    protected RemoveGroup removeGroup;
2291    protected ContainsPermission containsPermission;
2292    protected AddPermission addPermission;
2293    protected ClearPermissions clearPermissions;
2294    protected RemovePermission removePermission;
2295    protected ContainsUser containsUser;
2296    protected AddUser addUser;
2297    protected ClearUsers clearUsers;
2298    protected RemoveUser removeUser;
2299
2300    protected class ContainsGroup {
2301        protected ContainsGroup(RolePersistenceImpl persistenceImpl) {
2302            super();
2303
2304            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2305                    _SQL_CONTAINSGROUP,
2306                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2307        }
2308
2309        protected boolean contains(long roleId, long groupId) {
2310            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2311                        new Long(roleId), new Long(groupId)
2312                    });
2313
2314            if (results.size() > 0) {
2315                Integer count = results.get(0);
2316
2317                if (count.intValue() > 0) {
2318                    return true;
2319                }
2320            }
2321
2322            return false;
2323        }
2324
2325        private MappingSqlQuery _mappingSqlQuery;
2326    }
2327
2328    protected class AddGroup {
2329        protected AddGroup(RolePersistenceImpl persistenceImpl) {
2330            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2331                    "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
2332                    new int[] { Types.BIGINT, Types.BIGINT });
2333            _persistenceImpl = persistenceImpl;
2334        }
2335
2336        protected void add(long roleId, long groupId) {
2337            if (!_persistenceImpl.containsGroup.contains(roleId, groupId)) {
2338                _sqlUpdate.update(new Object[] {
2339                        new Long(roleId), new Long(groupId)
2340                    });
2341            }
2342        }
2343
2344        private SqlUpdate _sqlUpdate;
2345        private RolePersistenceImpl _persistenceImpl;
2346    }
2347
2348    protected class ClearGroups {
2349        protected ClearGroups(RolePersistenceImpl persistenceImpl) {
2350            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2351                    "DELETE FROM Groups_Roles WHERE roleId = ?",
2352                    new int[] { Types.BIGINT });
2353        }
2354
2355        protected void clear(long roleId) {
2356            _sqlUpdate.update(new Object[] { new Long(roleId) });
2357        }
2358
2359        private SqlUpdate _sqlUpdate;
2360    }
2361
2362    protected class RemoveGroup {
2363        protected RemoveGroup(RolePersistenceImpl persistenceImpl) {
2364            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2365                    "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
2366                    new int[] { Types.BIGINT, Types.BIGINT });
2367        }
2368
2369        protected void remove(long roleId, long groupId) {
2370            _sqlUpdate.update(new Object[] { new Long(roleId), new Long(groupId) });
2371        }
2372
2373        private SqlUpdate _sqlUpdate;
2374    }
2375
2376    protected class ContainsPermission {
2377        protected ContainsPermission(RolePersistenceImpl persistenceImpl) {
2378            super();
2379
2380            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2381                    _SQL_CONTAINSPERMISSION,
2382                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2383        }
2384
2385        protected boolean contains(long roleId, long permissionId) {
2386            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2387                        new Long(roleId), new Long(permissionId)
2388                    });
2389
2390            if (results.size() > 0) {
2391                Integer count = results.get(0);
2392
2393                if (count.intValue() > 0) {
2394                    return true;
2395                }
2396            }
2397
2398            return false;
2399        }
2400
2401        private MappingSqlQuery _mappingSqlQuery;
2402    }
2403
2404    protected class AddPermission {
2405        protected AddPermission(RolePersistenceImpl persistenceImpl) {
2406            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2407                    "INSERT INTO Roles_Permissions (roleId, permissionId) VALUES (?, ?)",
2408                    new int[] { Types.BIGINT, Types.BIGINT });
2409            _persistenceImpl = persistenceImpl;
2410        }
2411
2412        protected void add(long roleId, long permissionId) {
2413            if (!_persistenceImpl.containsPermission.contains(roleId,
2414                        permissionId)) {
2415                _sqlUpdate.update(new Object[] {
2416                        new Long(roleId), new Long(permissionId)
2417                    });
2418            }
2419        }
2420
2421        private SqlUpdate _sqlUpdate;
2422        private RolePersistenceImpl _persistenceImpl;
2423    }
2424
2425    protected class ClearPermissions {
2426        protected ClearPermissions(RolePersistenceImpl persistenceImpl) {
2427            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2428                    "DELETE FROM Roles_Permissions WHERE roleId = ?",
2429                    new int[] { Types.BIGINT });
2430        }
2431
2432        protected void clear(long roleId) {
2433            _sqlUpdate.update(new Object[] { new Long(roleId) });
2434        }
2435
2436        private SqlUpdate _sqlUpdate;
2437    }
2438
2439    protected class RemovePermission {
2440        protected RemovePermission(RolePersistenceImpl persistenceImpl) {
2441            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2442                    "DELETE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?",
2443                    new int[] { Types.BIGINT, Types.BIGINT });
2444        }
2445
2446        protected void remove(long roleId, long permissionId) {
2447            _sqlUpdate.update(new Object[] {
2448                    new Long(roleId), new Long(permissionId)
2449                });
2450        }
2451
2452        private SqlUpdate _sqlUpdate;
2453    }
2454
2455    protected class ContainsUser {
2456        protected ContainsUser(RolePersistenceImpl persistenceImpl) {
2457            super();
2458
2459            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2460                    _SQL_CONTAINSUSER,
2461                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2462        }
2463
2464        protected boolean contains(long roleId, long userId) {
2465            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2466                        new Long(roleId), new Long(userId)
2467                    });
2468
2469            if (results.size() > 0) {
2470                Integer count = results.get(0);
2471
2472                if (count.intValue() > 0) {
2473                    return true;
2474                }
2475            }
2476
2477            return false;
2478        }
2479
2480        private MappingSqlQuery _mappingSqlQuery;
2481    }
2482
2483    protected class AddUser {
2484        protected AddUser(RolePersistenceImpl persistenceImpl) {
2485            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2486                    "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
2487                    new int[] { Types.BIGINT, Types.BIGINT });
2488            _persistenceImpl = persistenceImpl;
2489        }
2490
2491        protected void add(long roleId, long userId) {
2492            if (!_persistenceImpl.containsUser.contains(roleId, userId)) {
2493                _sqlUpdate.update(new Object[] {
2494                        new Long(roleId), new Long(userId)
2495                    });
2496            }
2497        }
2498
2499        private SqlUpdate _sqlUpdate;
2500        private RolePersistenceImpl _persistenceImpl;
2501    }
2502
2503    protected class ClearUsers {
2504        protected ClearUsers(RolePersistenceImpl persistenceImpl) {
2505            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2506                    "DELETE FROM Users_Roles WHERE roleId = ?",
2507                    new int[] { Types.BIGINT });
2508        }
2509
2510        protected void clear(long roleId) {
2511            _sqlUpdate.update(new Object[] { new Long(roleId) });
2512        }
2513
2514        private SqlUpdate _sqlUpdate;
2515    }
2516
2517    protected class RemoveUser {
2518        protected RemoveUser(RolePersistenceImpl persistenceImpl) {
2519            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2520                    "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
2521                    new int[] { Types.BIGINT, Types.BIGINT });
2522        }
2523
2524        protected void remove(long roleId, long userId) {
2525            _sqlUpdate.update(new Object[] { new Long(roleId), new Long(userId) });
2526        }
2527
2528        private SqlUpdate _sqlUpdate;
2529    }
2530
2531    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
2532    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
2533    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
2534    private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Roles_Permissions ON (Roles_Permissions.permissionId = Permission_.permissionId) WHERE (Roles_Permissions.roleId = ?)";
2535    private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ?";
2536    private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?";
2537    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
2538    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
2539    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
2540    private static Log _log = LogFactory.getLog(RolePersistenceImpl.class);
2541    private ModelListener[] _listeners = new ModelListener[0];
2542}