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