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