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