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