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