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