1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.NoSuchPermissionException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
22  import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
23  import com.liferay.portal.kernel.dao.jdbc.RowMapper;
24  import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
25  import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
26  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.FinderPath;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.SQLQuery;
33  import com.liferay.portal.kernel.dao.orm.Session;
34  import com.liferay.portal.kernel.dao.orm.Type;
35  import com.liferay.portal.kernel.exception.SystemException;
36  import com.liferay.portal.kernel.log.Log;
37  import com.liferay.portal.kernel.log.LogFactoryUtil;
38  import com.liferay.portal.kernel.util.GetterUtil;
39  import com.liferay.portal.kernel.util.InstanceFactory;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.SetUtil;
42  import com.liferay.portal.kernel.util.StringBundler;
43  import com.liferay.portal.kernel.util.StringPool;
44  import com.liferay.portal.kernel.util.StringUtil;
45  import com.liferay.portal.kernel.util.Validator;
46  import com.liferay.portal.model.ModelListener;
47  import com.liferay.portal.model.Permission;
48  import com.liferay.portal.model.impl.PermissionImpl;
49  import com.liferay.portal.model.impl.PermissionModelImpl;
50  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
51  
52  import java.io.Serializable;
53  
54  import java.sql.Types;
55  
56  import java.util.ArrayList;
57  import java.util.Collections;
58  import java.util.List;
59  import java.util.Set;
60  
61  /**
62   * <a href="PermissionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
63   *
64   * <p>
65   * ServiceBuilder generated this class. Modifications in this class will be
66   * overwritten the next time is generated.
67   * </p>
68   *
69   * @author    Brian Wing Shun Chan
70   * @see       PermissionPersistence
71   * @see       PermissionUtil
72   * @generated
73   */
74  public class PermissionPersistenceImpl extends BasePersistenceImpl<Permission>
75      implements PermissionPersistence {
76      public static final String FINDER_CLASS_NAME_ENTITY = PermissionImpl.class.getName();
77      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
78          ".List";
79      public static final FinderPath FINDER_PATH_FIND_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
80              PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
81              "findByResourceId",
82              new String[] {
83                  Long.class.getName(),
84                  
85              "java.lang.Integer", "java.lang.Integer",
86                  "com.liferay.portal.kernel.util.OrderByComparator"
87              });
88      public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
89              PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
90              "countByResourceId", new String[] { Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FETCH_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
92              PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
93              "fetchByA_R",
94              new String[] { String.class.getName(), Long.class.getName() });
95      public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
96              PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
97              "countByA_R",
98              new String[] { String.class.getName(), Long.class.getName() });
99      public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
100             PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101             "findAll", new String[0]);
102     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
103             PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104             "countAll", new String[0]);
105 
106     public void cacheResult(Permission permission) {
107         EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
108             PermissionImpl.class, permission.getPrimaryKey(), permission);
109 
110         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
111             new Object[] {
112                 permission.getActionId(), new Long(permission.getResourceId())
113             }, permission);
114     }
115 
116     public void cacheResult(List<Permission> permissions) {
117         for (Permission permission : permissions) {
118             if (EntityCacheUtil.getResult(
119                         PermissionModelImpl.ENTITY_CACHE_ENABLED,
120                         PermissionImpl.class, permission.getPrimaryKey(), this) == null) {
121                 cacheResult(permission);
122             }
123         }
124     }
125 
126     public void clearCache() {
127         CacheRegistry.clear(PermissionImpl.class.getName());
128         EntityCacheUtil.clearCache(PermissionImpl.class.getName());
129         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
130         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
131     }
132 
133     public void clearCache(Permission permission) {
134         EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
135             PermissionImpl.class, permission.getPrimaryKey());
136 
137         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
138             new Object[] {
139                 permission.getActionId(), new Long(permission.getResourceId())
140             });
141     }
142 
143     public Permission create(long permissionId) {
144         Permission permission = new PermissionImpl();
145 
146         permission.setNew(true);
147         permission.setPrimaryKey(permissionId);
148 
149         return permission;
150     }
151 
152     public Permission remove(Serializable primaryKey)
153         throws NoSuchModelException, SystemException {
154         return remove(((Long)primaryKey).longValue());
155     }
156 
157     public Permission remove(long permissionId)
158         throws NoSuchPermissionException, SystemException {
159         Session session = null;
160 
161         try {
162             session = openSession();
163 
164             Permission permission = (Permission)session.get(PermissionImpl.class,
165                     new Long(permissionId));
166 
167             if (permission == null) {
168                 if (_log.isWarnEnabled()) {
169                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
170                 }
171 
172                 throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
173                     permissionId);
174             }
175 
176             return remove(permission);
177         }
178         catch (NoSuchPermissionException nsee) {
179             throw nsee;
180         }
181         catch (Exception e) {
182             throw processException(e);
183         }
184         finally {
185             closeSession(session);
186         }
187     }
188 
189     public Permission remove(Permission permission) throws SystemException {
190         for (ModelListener<Permission> listener : listeners) {
191             listener.onBeforeRemove(permission);
192         }
193 
194         permission = removeImpl(permission);
195 
196         for (ModelListener<Permission> listener : listeners) {
197             listener.onAfterRemove(permission);
198         }
199 
200         return permission;
201     }
202 
203     protected Permission removeImpl(Permission permission)
204         throws SystemException {
205         permission = toUnwrappedModel(permission);
206 
207         try {
208             clearGroups.clear(permission.getPrimaryKey());
209         }
210         catch (Exception e) {
211             throw processException(e);
212         }
213         finally {
214             FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
215         }
216 
217         try {
218             clearRoles.clear(permission.getPrimaryKey());
219         }
220         catch (Exception e) {
221             throw processException(e);
222         }
223         finally {
224             FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
225         }
226 
227         try {
228             clearUsers.clear(permission.getPrimaryKey());
229         }
230         catch (Exception e) {
231             throw processException(e);
232         }
233         finally {
234             FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
235         }
236 
237         Session session = null;
238 
239         try {
240             session = openSession();
241 
242             if (permission.isCachedModel() || BatchSessionUtil.isEnabled()) {
243                 Object staleObject = session.get(PermissionImpl.class,
244                         permission.getPrimaryKeyObj());
245 
246                 if (staleObject != null) {
247                     session.evict(staleObject);
248                 }
249             }
250 
251             session.delete(permission);
252 
253             session.flush();
254         }
255         catch (Exception e) {
256             throw processException(e);
257         }
258         finally {
259             closeSession(session);
260         }
261 
262         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
263 
264         PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
265 
266         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
267             new Object[] {
268                 permissionModelImpl.getOriginalActionId(),
269                 new Long(permissionModelImpl.getOriginalResourceId())
270             });
271 
272         EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
273             PermissionImpl.class, permission.getPrimaryKey());
274 
275         return permission;
276     }
277 
278     public Permission updateImpl(
279         com.liferay.portal.model.Permission permission, boolean merge)
280         throws SystemException {
281         permission = toUnwrappedModel(permission);
282 
283         boolean isNew = permission.isNew();
284 
285         PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
286 
287         Session session = null;
288 
289         try {
290             session = openSession();
291 
292             BatchSessionUtil.update(session, permission, merge);
293 
294             permission.setNew(false);
295         }
296         catch (Exception e) {
297             throw processException(e);
298         }
299         finally {
300             closeSession(session);
301         }
302 
303         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
304 
305         EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
306             PermissionImpl.class, permission.getPrimaryKey(), permission);
307 
308         if (!isNew &&
309                 (!Validator.equals(permission.getActionId(),
310                     permissionModelImpl.getOriginalActionId()) ||
311                 (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
312             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
313                 new Object[] {
314                     permissionModelImpl.getOriginalActionId(),
315                     new Long(permissionModelImpl.getOriginalResourceId())
316                 });
317         }
318 
319         if (isNew ||
320                 (!Validator.equals(permission.getActionId(),
321                     permissionModelImpl.getOriginalActionId()) ||
322                 (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
323             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
324                 new Object[] {
325                     permission.getActionId(),
326                     new Long(permission.getResourceId())
327                 }, permission);
328         }
329 
330         return permission;
331     }
332 
333     protected Permission toUnwrappedModel(Permission permission) {
334         if (permission instanceof PermissionImpl) {
335             return permission;
336         }
337 
338         PermissionImpl permissionImpl = new PermissionImpl();
339 
340         permissionImpl.setNew(permission.isNew());
341         permissionImpl.setPrimaryKey(permission.getPrimaryKey());
342 
343         permissionImpl.setPermissionId(permission.getPermissionId());
344         permissionImpl.setCompanyId(permission.getCompanyId());
345         permissionImpl.setActionId(permission.getActionId());
346         permissionImpl.setResourceId(permission.getResourceId());
347 
348         return permissionImpl;
349     }
350 
351     public Permission findByPrimaryKey(Serializable primaryKey)
352         throws NoSuchModelException, SystemException {
353         return findByPrimaryKey(((Long)primaryKey).longValue());
354     }
355 
356     public Permission findByPrimaryKey(long permissionId)
357         throws NoSuchPermissionException, SystemException {
358         Permission permission = fetchByPrimaryKey(permissionId);
359 
360         if (permission == null) {
361             if (_log.isWarnEnabled()) {
362                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
363             }
364 
365             throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
366                 permissionId);
367         }
368 
369         return permission;
370     }
371 
372     public Permission fetchByPrimaryKey(Serializable primaryKey)
373         throws SystemException {
374         return fetchByPrimaryKey(((Long)primaryKey).longValue());
375     }
376 
377     public Permission fetchByPrimaryKey(long permissionId)
378         throws SystemException {
379         Permission permission = (Permission)EntityCacheUtil.getResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
380                 PermissionImpl.class, permissionId, this);
381 
382         if (permission == null) {
383             Session session = null;
384 
385             try {
386                 session = openSession();
387 
388                 permission = (Permission)session.get(PermissionImpl.class,
389                         new Long(permissionId));
390             }
391             catch (Exception e) {
392                 throw processException(e);
393             }
394             finally {
395                 if (permission != null) {
396                     cacheResult(permission);
397                 }
398 
399                 closeSession(session);
400             }
401         }
402 
403         return permission;
404     }
405 
406     public List<Permission> findByResourceId(long resourceId)
407         throws SystemException {
408         return findByResourceId(resourceId, QueryUtil.ALL_POS,
409             QueryUtil.ALL_POS, null);
410     }
411 
412     public List<Permission> findByResourceId(long resourceId, int start, int end)
413         throws SystemException {
414         return findByResourceId(resourceId, start, end, null);
415     }
416 
417     public List<Permission> findByResourceId(long resourceId, int start,
418         int end, OrderByComparator orderByComparator) throws SystemException {
419         Object[] finderArgs = new Object[] {
420                 new Long(resourceId),
421                 
422                 String.valueOf(start), String.valueOf(end),
423                 String.valueOf(orderByComparator)
424             };
425 
426         List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RESOURCEID,
427                 finderArgs, this);
428 
429         if (list == null) {
430             Session session = null;
431 
432             try {
433                 session = openSession();
434 
435                 StringBundler query = null;
436 
437                 if (orderByComparator != null) {
438                     query = new StringBundler(3 +
439                             (orderByComparator.getOrderByFields().length * 3));
440                 }
441                 else {
442                     query = new StringBundler(2);
443                 }
444 
445                 query.append(_SQL_SELECT_PERMISSION_WHERE);
446 
447                 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
448 
449                 if (orderByComparator != null) {
450                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
451                         orderByComparator);
452                 }
453 
454                 String sql = query.toString();
455 
456                 Query q = session.createQuery(sql);
457 
458                 QueryPos qPos = QueryPos.getInstance(q);
459 
460                 qPos.add(resourceId);
461 
462                 list = (List<Permission>)QueryUtil.list(q, getDialect(), start,
463                         end);
464             }
465             catch (Exception e) {
466                 throw processException(e);
467             }
468             finally {
469                 if (list == null) {
470                     list = new ArrayList<Permission>();
471                 }
472 
473                 cacheResult(list);
474 
475                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RESOURCEID,
476                     finderArgs, list);
477 
478                 closeSession(session);
479             }
480         }
481 
482         return list;
483     }
484 
485     public Permission findByResourceId_First(long resourceId,
486         OrderByComparator orderByComparator)
487         throws NoSuchPermissionException, SystemException {
488         List<Permission> list = findByResourceId(resourceId, 0, 1,
489                 orderByComparator);
490 
491         if (list.isEmpty()) {
492             StringBundler msg = new StringBundler(4);
493 
494             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
495 
496             msg.append("resourceId=");
497             msg.append(resourceId);
498 
499             msg.append(StringPool.CLOSE_CURLY_BRACE);
500 
501             throw new NoSuchPermissionException(msg.toString());
502         }
503         else {
504             return list.get(0);
505         }
506     }
507 
508     public Permission findByResourceId_Last(long resourceId,
509         OrderByComparator orderByComparator)
510         throws NoSuchPermissionException, SystemException {
511         int count = countByResourceId(resourceId);
512 
513         List<Permission> list = findByResourceId(resourceId, count - 1, count,
514                 orderByComparator);
515 
516         if (list.isEmpty()) {
517             StringBundler msg = new StringBundler(4);
518 
519             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
520 
521             msg.append("resourceId=");
522             msg.append(resourceId);
523 
524             msg.append(StringPool.CLOSE_CURLY_BRACE);
525 
526             throw new NoSuchPermissionException(msg.toString());
527         }
528         else {
529             return list.get(0);
530         }
531     }
532 
533     public Permission[] findByResourceId_PrevAndNext(long permissionId,
534         long resourceId, OrderByComparator orderByComparator)
535         throws NoSuchPermissionException, SystemException {
536         Permission permission = findByPrimaryKey(permissionId);
537 
538         Session session = null;
539 
540         try {
541             session = openSession();
542 
543             Permission[] array = new PermissionImpl[3];
544 
545             array[0] = getByResourceId_PrevAndNext(session, permission,
546                     resourceId, orderByComparator, true);
547 
548             array[1] = permission;
549 
550             array[2] = getByResourceId_PrevAndNext(session, permission,
551                     resourceId, orderByComparator, false);
552 
553             return array;
554         }
555         catch (Exception e) {
556             throw processException(e);
557         }
558         finally {
559             closeSession(session);
560         }
561     }
562 
563     protected Permission getByResourceId_PrevAndNext(Session session,
564         Permission permission, long resourceId,
565         OrderByComparator orderByComparator, boolean previous) {
566         StringBundler query = null;
567 
568         if (orderByComparator != null) {
569             query = new StringBundler(6 +
570                     (orderByComparator.getOrderByFields().length * 6));
571         }
572         else {
573             query = new StringBundler(3);
574         }
575 
576         query.append(_SQL_SELECT_PERMISSION_WHERE);
577 
578         query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
579 
580         if (orderByComparator != null) {
581             String[] orderByFields = orderByComparator.getOrderByFields();
582 
583             if (orderByFields.length > 0) {
584                 query.append(WHERE_AND);
585             }
586 
587             for (int i = 0; i < orderByFields.length; i++) {
588                 query.append(_ORDER_BY_ENTITY_ALIAS);
589                 query.append(orderByFields[i]);
590 
591                 if ((i + 1) < orderByFields.length) {
592                     if (orderByComparator.isAscending() ^ previous) {
593                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
594                     }
595                     else {
596                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
597                     }
598                 }
599                 else {
600                     if (orderByComparator.isAscending() ^ previous) {
601                         query.append(WHERE_GREATER_THAN);
602                     }
603                     else {
604                         query.append(WHERE_LESSER_THAN);
605                     }
606                 }
607             }
608 
609             query.append(ORDER_BY_CLAUSE);
610 
611             for (int i = 0; i < orderByFields.length; i++) {
612                 query.append(_ORDER_BY_ENTITY_ALIAS);
613                 query.append(orderByFields[i]);
614 
615                 if ((i + 1) < orderByFields.length) {
616                     if (orderByComparator.isAscending() ^ previous) {
617                         query.append(ORDER_BY_ASC_HAS_NEXT);
618                     }
619                     else {
620                         query.append(ORDER_BY_DESC_HAS_NEXT);
621                     }
622                 }
623                 else {
624                     if (orderByComparator.isAscending() ^ previous) {
625                         query.append(ORDER_BY_ASC);
626                     }
627                     else {
628                         query.append(ORDER_BY_DESC);
629                     }
630                 }
631             }
632         }
633 
634         String sql = query.toString();
635 
636         Query q = session.createQuery(sql);
637 
638         q.setFirstResult(0);
639         q.setMaxResults(2);
640 
641         QueryPos qPos = QueryPos.getInstance(q);
642 
643         qPos.add(resourceId);
644 
645         if (orderByComparator != null) {
646             Object[] values = orderByComparator.getOrderByValues(permission);
647 
648             for (Object value : values) {
649                 qPos.add(value);
650             }
651         }
652 
653         List<Permission> list = q.list();
654 
655         if (list.size() == 2) {
656             return list.get(1);
657         }
658         else {
659             return null;
660         }
661     }
662 
663     public Permission findByA_R(String actionId, long resourceId)
664         throws NoSuchPermissionException, SystemException {
665         Permission permission = fetchByA_R(actionId, resourceId);
666 
667         if (permission == null) {
668             StringBundler msg = new StringBundler(6);
669 
670             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
671 
672             msg.append("actionId=");
673             msg.append(actionId);
674 
675             msg.append(", resourceId=");
676             msg.append(resourceId);
677 
678             msg.append(StringPool.CLOSE_CURLY_BRACE);
679 
680             if (_log.isWarnEnabled()) {
681                 _log.warn(msg.toString());
682             }
683 
684             throw new NoSuchPermissionException(msg.toString());
685         }
686 
687         return permission;
688     }
689 
690     public Permission fetchByA_R(String actionId, long resourceId)
691         throws SystemException {
692         return fetchByA_R(actionId, resourceId, true);
693     }
694 
695     public Permission fetchByA_R(String actionId, long resourceId,
696         boolean retrieveFromCache) throws SystemException {
697         Object[] finderArgs = new Object[] { actionId, new Long(resourceId) };
698 
699         Object result = null;
700 
701         if (retrieveFromCache) {
702             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A_R,
703                     finderArgs, this);
704         }
705 
706         if (result == null) {
707             Session session = null;
708 
709             try {
710                 session = openSession();
711 
712                 StringBundler query = new StringBundler(3);
713 
714                 query.append(_SQL_SELECT_PERMISSION_WHERE);
715 
716                 if (actionId == null) {
717                     query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
718                 }
719                 else {
720                     if (actionId.equals(StringPool.BLANK)) {
721                         query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
722                     }
723                     else {
724                         query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
725                     }
726                 }
727 
728                 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
729 
730                 String sql = query.toString();
731 
732                 Query q = session.createQuery(sql);
733 
734                 QueryPos qPos = QueryPos.getInstance(q);
735 
736                 if (actionId != null) {
737                     qPos.add(actionId);
738                 }
739 
740                 qPos.add(resourceId);
741 
742                 List<Permission> list = q.list();
743 
744                 result = list;
745 
746                 Permission permission = null;
747 
748                 if (list.isEmpty()) {
749                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
750                         finderArgs, list);
751                 }
752                 else {
753                     permission = list.get(0);
754 
755                     cacheResult(permission);
756 
757                     if ((permission.getActionId() == null) ||
758                             !permission.getActionId().equals(actionId) ||
759                             (permission.getResourceId() != resourceId)) {
760                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
761                             finderArgs, permission);
762                     }
763                 }
764 
765                 return permission;
766             }
767             catch (Exception e) {
768                 throw processException(e);
769             }
770             finally {
771                 if (result == null) {
772                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
773                         finderArgs, new ArrayList<Permission>());
774                 }
775 
776                 closeSession(session);
777             }
778         }
779         else {
780             if (result instanceof List<?>) {
781                 return null;
782             }
783             else {
784                 return (Permission)result;
785             }
786         }
787     }
788 
789     public List<Permission> findAll() throws SystemException {
790         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
791     }
792 
793     public List<Permission> findAll(int start, int end)
794         throws SystemException {
795         return findAll(start, end, null);
796     }
797 
798     public List<Permission> findAll(int start, int end,
799         OrderByComparator orderByComparator) throws SystemException {
800         Object[] finderArgs = new Object[] {
801                 String.valueOf(start), String.valueOf(end),
802                 String.valueOf(orderByComparator)
803             };
804 
805         List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
806                 finderArgs, this);
807 
808         if (list == null) {
809             Session session = null;
810 
811             try {
812                 session = openSession();
813 
814                 StringBundler query = null;
815                 String sql = null;
816 
817                 if (orderByComparator != null) {
818                     query = new StringBundler(2 +
819                             (orderByComparator.getOrderByFields().length * 3));
820 
821                     query.append(_SQL_SELECT_PERMISSION);
822 
823                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
824                         orderByComparator);
825 
826                     sql = query.toString();
827                 }
828 
829                 sql = _SQL_SELECT_PERMISSION;
830 
831                 Query q = session.createQuery(sql);
832 
833                 if (orderByComparator == null) {
834                     list = (List<Permission>)QueryUtil.list(q, getDialect(),
835                             start, end, false);
836 
837                     Collections.sort(list);
838                 }
839                 else {
840                     list = (List<Permission>)QueryUtil.list(q, getDialect(),
841                             start, end);
842                 }
843             }
844             catch (Exception e) {
845                 throw processException(e);
846             }
847             finally {
848                 if (list == null) {
849                     list = new ArrayList<Permission>();
850                 }
851 
852                 cacheResult(list);
853 
854                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
855 
856                 closeSession(session);
857             }
858         }
859 
860         return list;
861     }
862 
863     public void removeByResourceId(long resourceId) throws SystemException {
864         for (Permission permission : findByResourceId(resourceId)) {
865             remove(permission);
866         }
867     }
868 
869     public void removeByA_R(String actionId, long resourceId)
870         throws NoSuchPermissionException, SystemException {
871         Permission permission = findByA_R(actionId, resourceId);
872 
873         remove(permission);
874     }
875 
876     public void removeAll() throws SystemException {
877         for (Permission permission : findAll()) {
878             remove(permission);
879         }
880     }
881 
882     public int countByResourceId(long resourceId) throws SystemException {
883         Object[] finderArgs = new Object[] { new Long(resourceId) };
884 
885         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEID,
886                 finderArgs, this);
887 
888         if (count == null) {
889             Session session = null;
890 
891             try {
892                 session = openSession();
893 
894                 StringBundler query = new StringBundler(2);
895 
896                 query.append(_SQL_COUNT_PERMISSION_WHERE);
897 
898                 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
899 
900                 String sql = query.toString();
901 
902                 Query q = session.createQuery(sql);
903 
904                 QueryPos qPos = QueryPos.getInstance(q);
905 
906                 qPos.add(resourceId);
907 
908                 count = (Long)q.uniqueResult();
909             }
910             catch (Exception e) {
911                 throw processException(e);
912             }
913             finally {
914                 if (count == null) {
915                     count = Long.valueOf(0);
916                 }
917 
918                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEID,
919                     finderArgs, count);
920 
921                 closeSession(session);
922             }
923         }
924 
925         return count.intValue();
926     }
927 
928     public int countByA_R(String actionId, long resourceId)
929         throws SystemException {
930         Object[] finderArgs = new Object[] { actionId, new Long(resourceId) };
931 
932         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
933                 finderArgs, this);
934 
935         if (count == null) {
936             Session session = null;
937 
938             try {
939                 session = openSession();
940 
941                 StringBundler query = new StringBundler(3);
942 
943                 query.append(_SQL_COUNT_PERMISSION_WHERE);
944 
945                 if (actionId == null) {
946                     query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
947                 }
948                 else {
949                     if (actionId.equals(StringPool.BLANK)) {
950                         query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
951                     }
952                     else {
953                         query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
954                     }
955                 }
956 
957                 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
958 
959                 String sql = query.toString();
960 
961                 Query q = session.createQuery(sql);
962 
963                 QueryPos qPos = QueryPos.getInstance(q);
964 
965                 if (actionId != null) {
966                     qPos.add(actionId);
967                 }
968 
969                 qPos.add(resourceId);
970 
971                 count = (Long)q.uniqueResult();
972             }
973             catch (Exception e) {
974                 throw processException(e);
975             }
976             finally {
977                 if (count == null) {
978                     count = Long.valueOf(0);
979                 }
980 
981                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
982                     count);
983 
984                 closeSession(session);
985             }
986         }
987 
988         return count.intValue();
989     }
990 
991     public int countAll() throws SystemException {
992         Object[] finderArgs = new Object[0];
993 
994         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
995                 finderArgs, this);
996 
997         if (count == null) {
998             Session session = null;
999 
1000            try {
1001                session = openSession();
1002
1003                Query q = session.createQuery(_SQL_COUNT_PERMISSION);
1004
1005                count = (Long)q.uniqueResult();
1006            }
1007            catch (Exception e) {
1008                throw processException(e);
1009            }
1010            finally {
1011                if (count == null) {
1012                    count = Long.valueOf(0);
1013                }
1014
1015                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1016                    count);
1017
1018                closeSession(session);
1019            }
1020        }
1021
1022        return count.intValue();
1023    }
1024
1025    public List<com.liferay.portal.model.Group> getGroups(long pk)
1026        throws SystemException {
1027        return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1028    }
1029
1030    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1031        int end) throws SystemException {
1032        return getGroups(pk, start, end, null);
1033    }
1034
1035    public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1036            PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1037            PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1038            "getGroups",
1039            new String[] {
1040                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1041                "com.liferay.portal.kernel.util.OrderByComparator"
1042            });
1043
1044    public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1045        int end, OrderByComparator orderByComparator) throws SystemException {
1046        Object[] finderArgs = new Object[] {
1047                new Long(pk), String.valueOf(start), String.valueOf(end),
1048                String.valueOf(orderByComparator)
1049            };
1050
1051        List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1052                finderArgs, this);
1053
1054        if (list == null) {
1055            Session session = null;
1056
1057            try {
1058                session = openSession();
1059
1060                String sql = null;
1061
1062                if (orderByComparator != null) {
1063                    sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1064                                        .concat(orderByComparator.getOrderBy());
1065                }
1066
1067                else {
1068                    sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1069                }
1070
1071                SQLQuery q = session.createSQLQuery(sql);
1072
1073                q.addEntity("Group_",
1074                    com.liferay.portal.model.impl.GroupImpl.class);
1075
1076                QueryPos qPos = QueryPos.getInstance(q);
1077
1078                qPos.add(pk);
1079
1080                list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1081                        getDialect(), start, end);
1082            }
1083            catch (Exception e) {
1084                throw processException(e);
1085            }
1086            finally {
1087                if (list == null) {
1088                    list = new ArrayList<com.liferay.portal.model.Group>();
1089                }
1090
1091                groupPersistence.cacheResult(list);
1092
1093                FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1094                    list);
1095
1096                closeSession(session);
1097            }
1098        }
1099
1100        return list;
1101    }
1102
1103    public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1104            PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1105            PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1106            "getGroupsSize", new String[] { Long.class.getName() });
1107
1108    public int getGroupsSize(long pk) throws SystemException {
1109        Object[] finderArgs = new Object[] { new Long(pk) };
1110
1111        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1112                finderArgs, this);
1113
1114        if (count == null) {
1115            Session session = null;
1116
1117            try {
1118                session = openSession();
1119
1120                SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1121
1122                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1123
1124                QueryPos qPos = QueryPos.getInstance(q);
1125
1126                qPos.add(pk);
1127
1128                count = (Long)q.uniqueResult();
1129            }
1130            catch (Exception e) {
1131                throw processException(e);
1132            }
1133            finally {
1134                if (count == null) {
1135                    count = Long.valueOf(0);
1136                }
1137
1138                FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1139                    finderArgs, count);
1140
1141                closeSession(session);
1142            }
1143        }
1144
1145        return count.intValue();
1146    }
1147
1148    public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1149            PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1150            PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1151            "containsGroup",
1152            new String[] { Long.class.getName(), Long.class.getName() });
1153
1154    public boolean containsGroup(long pk, long groupPK)
1155        throws SystemException {
1156        Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1157
1158        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1159                finderArgs, this);
1160
1161        if (value == null) {
1162            try {
1163                value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1164            }
1165            catch (Exception e) {
1166                throw processException(e);
1167            }
1168            finally {
1169                if (value == null) {
1170                    value = Boolean.FALSE;
1171                }
1172
1173                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1174                    finderArgs, value);
1175            }
1176        }
1177
1178        return value.booleanValue();
1179    }
1180
1181    public boolean containsGroups(long pk) throws SystemException {
1182        if (getGroupsSize(pk) > 0) {
1183            return true;
1184        }
1185        else {
1186            return false;
1187        }
1188    }
1189
1190    public void addGroup(long pk, long groupPK) throws SystemException {
1191        try {
1192            addGroup.add(pk, groupPK);
1193        }
1194        catch (Exception e) {
1195            throw processException(e);
1196        }
1197        finally {
1198            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1199        }
1200    }
1201
1202    public void addGroup(long pk, com.liferay.portal.model.Group group)
1203        throws SystemException {
1204        try {
1205            addGroup.add(pk, group.getPrimaryKey());
1206        }
1207        catch (Exception e) {
1208            throw processException(e);
1209        }
1210        finally {
1211            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1212        }
1213    }
1214
1215    public void addGroups(long pk, long[] groupPKs) throws SystemException {
1216        try {
1217            for (long groupPK : groupPKs) {
1218                addGroup.add(pk, groupPK);
1219            }
1220        }
1221        catch (Exception e) {
1222            throw processException(e);
1223        }
1224        finally {
1225            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1226        }
1227    }
1228
1229    public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1230        throws SystemException {
1231        try {
1232            for (com.liferay.portal.model.Group group : groups) {
1233                addGroup.add(pk, group.getPrimaryKey());
1234            }
1235        }
1236        catch (Exception e) {
1237            throw processException(e);
1238        }
1239        finally {
1240            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1241        }
1242    }
1243
1244    public void clearGroups(long pk) throws SystemException {
1245        try {
1246            clearGroups.clear(pk);
1247        }
1248        catch (Exception e) {
1249            throw processException(e);
1250        }
1251        finally {
1252            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1253        }
1254    }
1255
1256    public void removeGroup(long pk, long groupPK) throws SystemException {
1257        try {
1258            removeGroup.remove(pk, groupPK);
1259        }
1260        catch (Exception e) {
1261            throw processException(e);
1262        }
1263        finally {
1264            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1265        }
1266    }
1267
1268    public void removeGroup(long pk, com.liferay.portal.model.Group group)
1269        throws SystemException {
1270        try {
1271            removeGroup.remove(pk, group.getPrimaryKey());
1272        }
1273        catch (Exception e) {
1274            throw processException(e);
1275        }
1276        finally {
1277            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1278        }
1279    }
1280
1281    public void removeGroups(long pk, long[] groupPKs)
1282        throws SystemException {
1283        try {
1284            for (long groupPK : groupPKs) {
1285                removeGroup.remove(pk, groupPK);
1286            }
1287        }
1288        catch (Exception e) {
1289            throw processException(e);
1290        }
1291        finally {
1292            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1293        }
1294    }
1295
1296    public void removeGroups(long pk,
1297        List<com.liferay.portal.model.Group> groups) throws SystemException {
1298        try {
1299            for (com.liferay.portal.model.Group group : groups) {
1300                removeGroup.remove(pk, group.getPrimaryKey());
1301            }
1302        }
1303        catch (Exception e) {
1304            throw processException(e);
1305        }
1306        finally {
1307            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1308        }
1309    }
1310
1311    public void setGroups(long pk, long[] groupPKs) throws SystemException {
1312        try {
1313            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1314
1315            List<com.liferay.portal.model.Group> groups = getGroups(pk);
1316
1317            for (com.liferay.portal.model.Group group : groups) {
1318                if (!groupPKSet.contains(group.getPrimaryKey())) {
1319                    removeGroup.remove(pk, group.getPrimaryKey());
1320                }
1321                else {
1322                    groupPKSet.remove(group.getPrimaryKey());
1323                }
1324            }
1325
1326            for (Long groupPK : groupPKSet) {
1327                addGroup.add(pk, groupPK);
1328            }
1329        }
1330        catch (Exception e) {
1331            throw processException(e);
1332        }
1333        finally {
1334            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1335        }
1336    }
1337
1338    public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1339        throws SystemException {
1340        try {
1341            long[] groupPKs = new long[groups.size()];
1342
1343            for (int i = 0; i < groups.size(); i++) {
1344                com.liferay.portal.model.Group group = groups.get(i);
1345
1346                groupPKs[i] = group.getPrimaryKey();
1347            }
1348
1349            setGroups(pk, groupPKs);
1350        }
1351        catch (Exception e) {
1352            throw processException(e);
1353        }
1354        finally {
1355            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1356        }
1357    }
1358
1359    public List<com.liferay.portal.model.Role> getRoles(long pk)
1360        throws SystemException {
1361        return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1362    }
1363
1364    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1365        int end) throws SystemException {
1366        return getRoles(pk, start, end, null);
1367    }
1368
1369    public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1370            PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1371            PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1372            "getRoles",
1373            new String[] {
1374                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1375                "com.liferay.portal.kernel.util.OrderByComparator"
1376            });
1377
1378    public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1379        int end, OrderByComparator orderByComparator) throws SystemException {
1380        Object[] finderArgs = new Object[] {
1381                new Long(pk), String.valueOf(start), String.valueOf(end),
1382                String.valueOf(orderByComparator)
1383            };
1384
1385        List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
1386                finderArgs, this);
1387
1388        if (list == null) {
1389            Session session = null;
1390
1391            try {
1392                session = openSession();
1393
1394                String sql = null;
1395
1396                if (orderByComparator != null) {
1397                    sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
1398                                       .concat(orderByComparator.getOrderBy());
1399                }
1400
1401                else {
1402                    sql = _SQL_GETROLES.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
1403                }
1404
1405                SQLQuery q = session.createSQLQuery(sql);
1406
1407                q.addEntity("Role_",
1408                    com.liferay.portal.model.impl.RoleImpl.class);
1409
1410                QueryPos qPos = QueryPos.getInstance(q);
1411
1412                qPos.add(pk);
1413
1414                list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
1415                        getDialect(), start, end);
1416            }
1417            catch (Exception e) {
1418                throw processException(e);
1419            }
1420            finally {
1421                if (list == null) {
1422                    list = new ArrayList<com.liferay.portal.model.Role>();
1423                }
1424
1425                rolePersistence.cacheResult(list);
1426
1427                FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES, finderArgs,
1428                    list);
1429
1430                closeSession(session);
1431            }
1432        }
1433
1434        return list;
1435    }
1436
1437    public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1438            PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1439            PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1440            "getRolesSize", new String[] { Long.class.getName() });
1441
1442    public int getRolesSize(long pk) throws SystemException {
1443        Object[] finderArgs = new Object[] { new Long(pk) };
1444
1445        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
1446                finderArgs, this);
1447
1448        if (count == null) {
1449            Session session = null;
1450
1451            try {
1452                session = openSession();
1453
1454                SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
1455
1456                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1457
1458                QueryPos qPos = QueryPos.getInstance(q);
1459
1460                qPos.add(pk);
1461
1462                count = (Long)q.uniqueResult();
1463            }
1464            catch (Exception e) {
1465                throw processException(e);
1466            }
1467            finally {
1468                if (count == null) {
1469                    count = Long.valueOf(0);
1470                }
1471
1472                FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
1473                    finderArgs, count);
1474
1475                closeSession(session);
1476            }
1477        }
1478
1479        return count.intValue();
1480    }
1481
1482    public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1483            PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1484            PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1485            "containsRole",
1486            new String[] { Long.class.getName(), Long.class.getName() });
1487
1488    public boolean containsRole(long pk, long rolePK) throws SystemException {
1489        Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
1490
1491        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
1492                finderArgs, this);
1493
1494        if (value == null) {
1495            try {
1496                value = Boolean.valueOf(containsRole.contains(pk, rolePK));
1497            }
1498            catch (Exception e) {
1499                throw processException(e);
1500            }
1501            finally {
1502                if (value == null) {
1503                    value = Boolean.FALSE;
1504                }
1505
1506                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
1507                    finderArgs, value);
1508            }
1509        }
1510
1511        return value.booleanValue();
1512    }
1513
1514    public boolean containsRoles(long pk) throws SystemException {
1515        if (getRolesSize(pk) > 0) {
1516            return true;
1517        }
1518        else {
1519            return false;
1520        }
1521    }
1522
1523    public void addRole(long pk, long rolePK) throws SystemException {
1524        try {
1525            addRole.add(pk, rolePK);
1526        }
1527        catch (Exception e) {
1528            throw processException(e);
1529        }
1530        finally {
1531            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1532        }
1533    }
1534
1535    public void addRole(long pk, com.liferay.portal.model.Role role)
1536        throws SystemException {
1537        try {
1538            addRole.add(pk, role.getPrimaryKey());
1539        }
1540        catch (Exception e) {
1541            throw processException(e);
1542        }
1543        finally {
1544            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1545        }
1546    }
1547
1548    public void addRoles(long pk, long[] rolePKs) throws SystemException {
1549        try {
1550            for (long rolePK : rolePKs) {
1551                addRole.add(pk, rolePK);
1552            }
1553        }
1554        catch (Exception e) {
1555            throw processException(e);
1556        }
1557        finally {
1558            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1559        }
1560    }
1561
1562    public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
1563        throws SystemException {
1564        try {
1565            for (com.liferay.portal.model.Role role : roles) {
1566                addRole.add(pk, role.getPrimaryKey());
1567            }
1568        }
1569        catch (Exception e) {
1570            throw processException(e);
1571        }
1572        finally {
1573            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1574        }
1575    }
1576
1577    public void clearRoles(long pk) throws SystemException {
1578        try {
1579            clearRoles.clear(pk);
1580        }
1581        catch (Exception e) {
1582            throw processException(e);
1583        }
1584        finally {
1585            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1586        }
1587    }
1588
1589    public void removeRole(long pk, long rolePK) throws SystemException {
1590        try {
1591            removeRole.remove(pk, rolePK);
1592        }
1593        catch (Exception e) {
1594            throw processException(e);
1595        }
1596        finally {
1597            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1598        }
1599    }
1600
1601    public void removeRole(long pk, com.liferay.portal.model.Role role)
1602        throws SystemException {
1603        try {
1604            removeRole.remove(pk, role.getPrimaryKey());
1605        }
1606        catch (Exception e) {
1607            throw processException(e);
1608        }
1609        finally {
1610            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1611        }
1612    }
1613
1614    public void removeRoles(long pk, long[] rolePKs) throws SystemException {
1615        try {
1616            for (long rolePK : rolePKs) {
1617                removeRole.remove(pk, rolePK);
1618            }
1619        }
1620        catch (Exception e) {
1621            throw processException(e);
1622        }
1623        finally {
1624            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1625        }
1626    }
1627
1628    public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
1629        throws SystemException {
1630        try {
1631            for (com.liferay.portal.model.Role role : roles) {
1632                removeRole.remove(pk, role.getPrimaryKey());
1633            }
1634        }
1635        catch (Exception e) {
1636            throw processException(e);
1637        }
1638        finally {
1639            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1640        }
1641    }
1642
1643    public void setRoles(long pk, long[] rolePKs) throws SystemException {
1644        try {
1645            Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
1646
1647            List<com.liferay.portal.model.Role> roles = getRoles(pk);
1648
1649            for (com.liferay.portal.model.Role role : roles) {
1650                if (!rolePKSet.contains(role.getPrimaryKey())) {
1651                    removeRole.remove(pk, role.getPrimaryKey());
1652                }
1653                else {
1654                    rolePKSet.remove(role.getPrimaryKey());
1655                }
1656            }
1657
1658            for (Long rolePK : rolePKSet) {
1659                addRole.add(pk, rolePK);
1660            }
1661        }
1662        catch (Exception e) {
1663            throw processException(e);
1664        }
1665        finally {
1666            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1667        }
1668    }
1669
1670    public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
1671        throws SystemException {
1672        try {
1673            long[] rolePKs = new long[roles.size()];
1674
1675            for (int i = 0; i < roles.size(); i++) {
1676                com.liferay.portal.model.Role role = roles.get(i);
1677
1678                rolePKs[i] = role.getPrimaryKey();
1679            }
1680
1681            setRoles(pk, rolePKs);
1682        }
1683        catch (Exception e) {
1684            throw processException(e);
1685        }
1686        finally {
1687            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1688        }
1689    }
1690
1691    public List<com.liferay.portal.model.User> getUsers(long pk)
1692        throws SystemException {
1693        return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1694    }
1695
1696    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1697        int end) throws SystemException {
1698        return getUsers(pk, start, end, null);
1699    }
1700
1701    public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1702            PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1703            PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
1704            "getUsers",
1705            new String[] {
1706                Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1707                "com.liferay.portal.kernel.util.OrderByComparator"
1708            });
1709
1710    public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1711        int end, OrderByComparator orderByComparator) throws SystemException {
1712        Object[] finderArgs = new Object[] {
1713                new Long(pk), String.valueOf(start), String.valueOf(end),
1714                String.valueOf(orderByComparator)
1715            };
1716
1717        List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1718                finderArgs, this);
1719
1720        if (list == null) {
1721            Session session = null;
1722
1723            try {
1724                session = openSession();
1725
1726                String sql = null;
1727
1728                if (orderByComparator != null) {
1729                    sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
1730                                       .concat(orderByComparator.getOrderBy());
1731                }
1732
1733                sql = _SQL_GETUSERS;
1734
1735                SQLQuery q = session.createSQLQuery(sql);
1736
1737                q.addEntity("User_",
1738                    com.liferay.portal.model.impl.UserImpl.class);
1739
1740                QueryPos qPos = QueryPos.getInstance(q);
1741
1742                qPos.add(pk);
1743
1744                list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1745                        getDialect(), start, end);
1746            }
1747            catch (Exception e) {
1748                throw processException(e);
1749            }
1750            finally {
1751                if (list == null) {
1752                    list = new ArrayList<com.liferay.portal.model.User>();
1753                }
1754
1755                userPersistence.cacheResult(list);
1756
1757                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1758                    list);
1759
1760                closeSession(session);
1761            }
1762        }
1763
1764        return list;
1765    }
1766
1767    public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1768            PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1769            PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
1770            "getUsersSize", new String[] { Long.class.getName() });
1771
1772    public int getUsersSize(long pk) throws SystemException {
1773        Object[] finderArgs = new Object[] { new Long(pk) };
1774
1775        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1776                finderArgs, this);
1777
1778        if (count == null) {
1779            Session session = null;
1780
1781            try {
1782                session = openSession();
1783
1784                SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1785
1786                q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1787
1788                QueryPos qPos = QueryPos.getInstance(q);
1789
1790                qPos.add(pk);
1791
1792                count = (Long)q.uniqueResult();
1793            }
1794            catch (Exception e) {
1795                throw processException(e);
1796            }
1797            finally {
1798                if (count == null) {
1799                    count = Long.valueOf(0);
1800                }
1801
1802                FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1803                    finderArgs, count);
1804
1805                closeSession(session);
1806            }
1807        }
1808
1809        return count.intValue();
1810    }
1811
1812    public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1813            PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1814            PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
1815            "containsUser",
1816            new String[] { Long.class.getName(), Long.class.getName() });
1817
1818    public boolean containsUser(long pk, long userPK) throws SystemException {
1819        Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
1820
1821        Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1822                finderArgs, this);
1823
1824        if (value == null) {
1825            try {
1826                value = Boolean.valueOf(containsUser.contains(pk, userPK));
1827            }
1828            catch (Exception e) {
1829                throw processException(e);
1830            }
1831            finally {
1832                if (value == null) {
1833                    value = Boolean.FALSE;
1834                }
1835
1836                FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1837                    finderArgs, value);
1838            }
1839        }
1840
1841        return value.booleanValue();
1842    }
1843
1844    public boolean containsUsers(long pk) throws SystemException {
1845        if (getUsersSize(pk) > 0) {
1846            return true;
1847        }
1848        else {
1849            return false;
1850        }
1851    }
1852
1853    public void addUser(long pk, long userPK) throws SystemException {
1854        try {
1855            addUser.add(pk, userPK);
1856        }
1857        catch (Exception e) {
1858            throw processException(e);
1859        }
1860        finally {
1861            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1862        }
1863    }
1864
1865    public void addUser(long pk, com.liferay.portal.model.User user)
1866        throws SystemException {
1867        try {
1868            addUser.add(pk, user.getPrimaryKey());
1869        }
1870        catch (Exception e) {
1871            throw processException(e);
1872        }
1873        finally {
1874            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1875        }
1876    }
1877
1878    public void addUsers(long pk, long[] userPKs) throws SystemException {
1879        try {
1880            for (long userPK : userPKs) {
1881                addUser.add(pk, userPK);
1882            }
1883        }
1884        catch (Exception e) {
1885            throw processException(e);
1886        }
1887        finally {
1888            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1889        }
1890    }
1891
1892    public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1893        throws SystemException {
1894        try {
1895            for (com.liferay.portal.model.User user : users) {
1896                addUser.add(pk, user.getPrimaryKey());
1897            }
1898        }
1899        catch (Exception e) {
1900            throw processException(e);
1901        }
1902        finally {
1903            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1904        }
1905    }
1906
1907    public void clearUsers(long pk) throws SystemException {
1908        try {
1909            clearUsers.clear(pk);
1910        }
1911        catch (Exception e) {
1912            throw processException(e);
1913        }
1914        finally {
1915            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1916        }
1917    }
1918
1919    public void removeUser(long pk, long userPK) throws SystemException {
1920        try {
1921            removeUser.remove(pk, userPK);
1922        }
1923        catch (Exception e) {
1924            throw processException(e);
1925        }
1926        finally {
1927            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1928        }
1929    }
1930
1931    public void removeUser(long pk, com.liferay.portal.model.User user)
1932        throws SystemException {
1933        try {
1934            removeUser.remove(pk, user.getPrimaryKey());
1935        }
1936        catch (Exception e) {
1937            throw processException(e);
1938        }
1939        finally {
1940            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1941        }
1942    }
1943
1944    public void removeUsers(long pk, long[] userPKs) throws SystemException {
1945        try {
1946            for (long userPK : userPKs) {
1947                removeUser.remove(pk, userPK);
1948            }
1949        }
1950        catch (Exception e) {
1951            throw processException(e);
1952        }
1953        finally {
1954            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1955        }
1956    }
1957
1958    public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1959        throws SystemException {
1960        try {
1961            for (com.liferay.portal.model.User user : users) {
1962                removeUser.remove(pk, user.getPrimaryKey());
1963            }
1964        }
1965        catch (Exception e) {
1966            throw processException(e);
1967        }
1968        finally {
1969            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1970        }
1971    }
1972
1973    public void setUsers(long pk, long[] userPKs) throws SystemException {
1974        try {
1975            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
1976
1977            List<com.liferay.portal.model.User> users = getUsers(pk);
1978
1979            for (com.liferay.portal.model.User user : users) {
1980                if (!userPKSet.contains(user.getPrimaryKey())) {
1981                    removeUser.remove(pk, user.getPrimaryKey());
1982                }
1983                else {
1984                    userPKSet.remove(user.getPrimaryKey());
1985                }
1986            }
1987
1988            for (Long userPK : userPKSet) {
1989                addUser.add(pk, userPK);
1990            }
1991        }
1992        catch (Exception e) {
1993            throw processException(e);
1994        }
1995        finally {
1996            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
1997        }
1998    }
1999
2000    public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2001        throws SystemException {
2002        try {
2003            long[] userPKs = new long[users.size()];
2004
2005            for (int i = 0; i < users.size(); i++) {
2006                com.liferay.portal.model.User user = users.get(i);
2007
2008                userPKs[i] = user.getPrimaryKey();
2009            }
2010
2011            setUsers(pk, userPKs);
2012        }
2013        catch (Exception e) {
2014            throw processException(e);
2015        }
2016        finally {
2017            FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2018        }
2019    }
2020
2021    public void afterPropertiesSet() {
2022        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2023                    com.liferay.portal.util.PropsUtil.get(
2024                        "value.object.listener.com.liferay.portal.model.Permission")));
2025
2026        if (listenerClassNames.length > 0) {
2027            try {
2028                List<ModelListener<Permission>> listenersList = new ArrayList<ModelListener<Permission>>();
2029
2030                for (String listenerClassName : listenerClassNames) {
2031                    listenersList.add((ModelListener<Permission>)InstanceFactory.newInstance(
2032                            listenerClassName));
2033                }
2034
2035                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2036            }
2037            catch (Exception e) {
2038                _log.error(e);
2039            }
2040        }
2041
2042        containsGroup = new ContainsGroup(this);
2043
2044        addGroup = new AddGroup(this);
2045        clearGroups = new ClearGroups(this);
2046        removeGroup = new RemoveGroup(this);
2047
2048        containsRole = new ContainsRole(this);
2049
2050        addRole = new AddRole(this);
2051        clearRoles = new ClearRoles(this);
2052        removeRole = new RemoveRole(this);
2053
2054        containsUser = new ContainsUser(this);
2055
2056        addUser = new AddUser(this);
2057        clearUsers = new ClearUsers(this);
2058        removeUser = new RemoveUser(this);
2059    }
2060
2061    @BeanReference(type = AccountPersistence.class)
2062    protected AccountPersistence accountPersistence;
2063    @BeanReference(type = AddressPersistence.class)
2064    protected AddressPersistence addressPersistence;
2065    @BeanReference(type = BrowserTrackerPersistence.class)
2066    protected BrowserTrackerPersistence browserTrackerPersistence;
2067    @BeanReference(type = ClassNamePersistence.class)
2068    protected ClassNamePersistence classNamePersistence;
2069    @BeanReference(type = CompanyPersistence.class)
2070    protected CompanyPersistence companyPersistence;
2071    @BeanReference(type = ContactPersistence.class)
2072    protected ContactPersistence contactPersistence;
2073    @BeanReference(type = CountryPersistence.class)
2074    protected CountryPersistence countryPersistence;
2075    @BeanReference(type = EmailAddressPersistence.class)
2076    protected EmailAddressPersistence emailAddressPersistence;
2077    @BeanReference(type = GroupPersistence.class)
2078    protected GroupPersistence groupPersistence;
2079    @BeanReference(type = ImagePersistence.class)
2080    protected ImagePersistence imagePersistence;
2081    @BeanReference(type = LayoutPersistence.class)
2082    protected LayoutPersistence layoutPersistence;
2083    @BeanReference(type = LayoutPrototypePersistence.class)
2084    protected LayoutPrototypePersistence layoutPrototypePersistence;
2085    @BeanReference(type = LayoutSetPersistence.class)
2086    protected LayoutSetPersistence layoutSetPersistence;
2087    @BeanReference(type = LayoutSetPrototypePersistence.class)
2088    protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2089    @BeanReference(type = ListTypePersistence.class)
2090    protected ListTypePersistence listTypePersistence;
2091    @BeanReference(type = LockPersistence.class)
2092    protected LockPersistence lockPersistence;
2093    @BeanReference(type = MembershipRequestPersistence.class)
2094    protected MembershipRequestPersistence membershipRequestPersistence;
2095    @BeanReference(type = OrganizationPersistence.class)
2096    protected OrganizationPersistence organizationPersistence;
2097    @BeanReference(type = OrgGroupPermissionPersistence.class)
2098    protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2099    @BeanReference(type = OrgGroupRolePersistence.class)
2100    protected OrgGroupRolePersistence orgGroupRolePersistence;
2101    @BeanReference(type = OrgLaborPersistence.class)
2102    protected OrgLaborPersistence orgLaborPersistence;
2103    @BeanReference(type = PasswordPolicyPersistence.class)
2104    protected PasswordPolicyPersistence passwordPolicyPersistence;
2105    @BeanReference(type = PasswordPolicyRelPersistence.class)
2106    protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2107    @BeanReference(type = PasswordTrackerPersistence.class)
2108    protected PasswordTrackerPersistence passwordTrackerPersistence;
2109    @BeanReference(type = PermissionPersistence.class)
2110    protected PermissionPersistence permissionPersistence;
2111    @BeanReference(type = PhonePersistence.class)
2112    protected PhonePersistence phonePersistence;
2113    @BeanReference(type = PluginSettingPersistence.class)
2114    protected PluginSettingPersistence pluginSettingPersistence;
2115    @BeanReference(type = PortletPersistence.class)
2116    protected PortletPersistence portletPersistence;
2117    @BeanReference(type = PortletItemPersistence.class)
2118    protected PortletItemPersistence portletItemPersistence;
2119    @BeanReference(type = PortletPreferencesPersistence.class)
2120    protected PortletPreferencesPersistence portletPreferencesPersistence;
2121    @BeanReference(type = RegionPersistence.class)
2122    protected RegionPersistence regionPersistence;
2123    @BeanReference(type = ReleasePersistence.class)
2124    protected ReleasePersistence releasePersistence;
2125    @BeanReference(type = ResourcePersistence.class)
2126    protected ResourcePersistence resourcePersistence;
2127    @BeanReference(type = ResourceActionPersistence.class)
2128    protected ResourceActionPersistence resourceActionPersistence;
2129    @BeanReference(type = ResourceCodePersistence.class)
2130    protected ResourceCodePersistence resourceCodePersistence;
2131    @BeanReference(type = ResourcePermissionPersistence.class)
2132    protected ResourcePermissionPersistence resourcePermissionPersistence;
2133    @BeanReference(type = RolePersistence.class)
2134    protected RolePersistence rolePersistence;
2135    @BeanReference(type = ServiceComponentPersistence.class)
2136    protected ServiceComponentPersistence serviceComponentPersistence;
2137    @BeanReference(type = ShardPersistence.class)
2138    protected ShardPersistence shardPersistence;
2139    @BeanReference(type = SubscriptionPersistence.class)
2140    protected SubscriptionPersistence subscriptionPersistence;
2141    @BeanReference(type = TicketPersistence.class)
2142    protected TicketPersistence ticketPersistence;
2143    @BeanReference(type = TeamPersistence.class)
2144    protected TeamPersistence teamPersistence;
2145    @BeanReference(type = UserPersistence.class)
2146    protected UserPersistence userPersistence;
2147    @BeanReference(type = UserGroupPersistence.class)
2148    protected UserGroupPersistence userGroupPersistence;
2149    @BeanReference(type = UserGroupGroupRolePersistence.class)
2150    protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2151    @BeanReference(type = UserGroupRolePersistence.class)
2152    protected UserGroupRolePersistence userGroupRolePersistence;
2153    @BeanReference(type = UserIdMapperPersistence.class)
2154    protected UserIdMapperPersistence userIdMapperPersistence;
2155    @BeanReference(type = UserTrackerPersistence.class)
2156    protected UserTrackerPersistence userTrackerPersistence;
2157    @BeanReference(type = UserTrackerPathPersistence.class)
2158    protected UserTrackerPathPersistence userTrackerPathPersistence;
2159    @BeanReference(type = WebDAVPropsPersistence.class)
2160    protected WebDAVPropsPersistence webDAVPropsPersistence;
2161    @BeanReference(type = WebsitePersistence.class)
2162    protected WebsitePersistence websitePersistence;
2163    @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2164    protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2165    @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2166    protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2167    protected ContainsGroup containsGroup;
2168    protected AddGroup addGroup;
2169    protected ClearGroups clearGroups;
2170    protected RemoveGroup removeGroup;
2171    protected ContainsRole containsRole;
2172    protected AddRole addRole;
2173    protected ClearRoles clearRoles;
2174    protected RemoveRole removeRole;
2175    protected ContainsUser containsUser;
2176    protected AddUser addUser;
2177    protected ClearUsers clearUsers;
2178    protected RemoveUser removeUser;
2179
2180    protected class ContainsGroup {
2181        protected ContainsGroup(PermissionPersistenceImpl persistenceImpl) {
2182            super();
2183
2184            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2185                    _SQL_CONTAINSGROUP,
2186                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2187        }
2188
2189        protected boolean contains(long permissionId, long groupId) {
2190            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2191                        new Long(permissionId), new Long(groupId)
2192                    });
2193
2194            if (results.size() > 0) {
2195                Integer count = results.get(0);
2196
2197                if (count.intValue() > 0) {
2198                    return true;
2199                }
2200            }
2201
2202            return false;
2203        }
2204
2205        private MappingSqlQuery<Integer> _mappingSqlQuery;
2206    }
2207
2208    protected class AddGroup {
2209        protected AddGroup(PermissionPersistenceImpl persistenceImpl) {
2210            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2211                    "INSERT INTO Groups_Permissions (permissionId, groupId) VALUES (?, ?)",
2212                    new int[] { Types.BIGINT, Types.BIGINT });
2213            _persistenceImpl = persistenceImpl;
2214        }
2215
2216        protected void add(long permissionId, long groupId)
2217            throws SystemException {
2218            if (!_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2219                ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2220
2221                for (ModelListener<Permission> listener : listeners) {
2222                    listener.onBeforeAddAssociation(permissionId,
2223                        com.liferay.portal.model.Group.class.getName(), groupId);
2224                }
2225
2226                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2227                    listener.onBeforeAddAssociation(groupId,
2228                        Permission.class.getName(), permissionId);
2229                }
2230
2231                _sqlUpdate.update(new Object[] {
2232                        new Long(permissionId), new Long(groupId)
2233                    });
2234
2235                for (ModelListener<Permission> listener : listeners) {
2236                    listener.onAfterAddAssociation(permissionId,
2237                        com.liferay.portal.model.Group.class.getName(), groupId);
2238                }
2239
2240                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2241                    listener.onAfterAddAssociation(groupId,
2242                        Permission.class.getName(), permissionId);
2243                }
2244            }
2245        }
2246
2247        private SqlUpdate _sqlUpdate;
2248        private PermissionPersistenceImpl _persistenceImpl;
2249    }
2250
2251    protected class ClearGroups {
2252        protected ClearGroups(PermissionPersistenceImpl persistenceImpl) {
2253            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2254                    "DELETE FROM Groups_Permissions WHERE permissionId = ?",
2255                    new int[] { Types.BIGINT });
2256        }
2257
2258        protected void clear(long permissionId) throws SystemException {
2259            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2260
2261            List<com.liferay.portal.model.Group> groups = null;
2262
2263            if ((listeners.length > 0) || (groupListeners.length > 0)) {
2264                groups = getGroups(permissionId);
2265
2266                for (com.liferay.portal.model.Group group : groups) {
2267                    for (ModelListener<Permission> listener : listeners) {
2268                        listener.onBeforeRemoveAssociation(permissionId,
2269                            com.liferay.portal.model.Group.class.getName(),
2270                            group.getPrimaryKey());
2271                    }
2272
2273                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2274                        listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2275                            Permission.class.getName(), permissionId);
2276                    }
2277                }
2278            }
2279
2280            _sqlUpdate.update(new Object[] { new Long(permissionId) });
2281
2282            if ((listeners.length > 0) || (groupListeners.length > 0)) {
2283                for (com.liferay.portal.model.Group group : groups) {
2284                    for (ModelListener<Permission> listener : listeners) {
2285                        listener.onAfterRemoveAssociation(permissionId,
2286                            com.liferay.portal.model.Group.class.getName(),
2287                            group.getPrimaryKey());
2288                    }
2289
2290                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2291                        listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2292                            Permission.class.getName(), permissionId);
2293                    }
2294                }
2295            }
2296        }
2297
2298        private SqlUpdate _sqlUpdate;
2299    }
2300
2301    protected class RemoveGroup {
2302        protected RemoveGroup(PermissionPersistenceImpl persistenceImpl) {
2303            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2304                    "DELETE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?",
2305                    new int[] { Types.BIGINT, Types.BIGINT });
2306            _persistenceImpl = persistenceImpl;
2307        }
2308
2309        protected void remove(long permissionId, long groupId)
2310            throws SystemException {
2311            if (_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2312                ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2313
2314                for (ModelListener<Permission> listener : listeners) {
2315                    listener.onBeforeRemoveAssociation(permissionId,
2316                        com.liferay.portal.model.Group.class.getName(), groupId);
2317                }
2318
2319                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2320                    listener.onBeforeRemoveAssociation(groupId,
2321                        Permission.class.getName(), permissionId);
2322                }
2323
2324                _sqlUpdate.update(new Object[] {
2325                        new Long(permissionId), new Long(groupId)
2326                    });
2327
2328                for (ModelListener<Permission> listener : listeners) {
2329                    listener.onAfterRemoveAssociation(permissionId,
2330                        com.liferay.portal.model.Group.class.getName(), groupId);
2331                }
2332
2333                for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2334                    listener.onAfterRemoveAssociation(groupId,
2335                        Permission.class.getName(), permissionId);
2336                }
2337            }
2338        }
2339
2340        private SqlUpdate _sqlUpdate;
2341        private PermissionPersistenceImpl _persistenceImpl;
2342    }
2343
2344    protected class ContainsRole {
2345        protected ContainsRole(PermissionPersistenceImpl persistenceImpl) {
2346            super();
2347
2348            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2349                    _SQL_CONTAINSROLE,
2350                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2351        }
2352
2353        protected boolean contains(long permissionId, long roleId) {
2354            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2355                        new Long(permissionId), new Long(roleId)
2356                    });
2357
2358            if (results.size() > 0) {
2359                Integer count = results.get(0);
2360
2361                if (count.intValue() > 0) {
2362                    return true;
2363                }
2364            }
2365
2366            return false;
2367        }
2368
2369        private MappingSqlQuery<Integer> _mappingSqlQuery;
2370    }
2371
2372    protected class AddRole {
2373        protected AddRole(PermissionPersistenceImpl persistenceImpl) {
2374            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2375                    "INSERT INTO Roles_Permissions (permissionId, roleId) VALUES (?, ?)",
2376                    new int[] { Types.BIGINT, Types.BIGINT });
2377            _persistenceImpl = persistenceImpl;
2378        }
2379
2380        protected void add(long permissionId, long roleId)
2381            throws SystemException {
2382            if (!_persistenceImpl.containsRole.contains(permissionId, roleId)) {
2383                ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2384
2385                for (ModelListener<Permission> listener : listeners) {
2386                    listener.onBeforeAddAssociation(permissionId,
2387                        com.liferay.portal.model.Role.class.getName(), roleId);
2388                }
2389
2390                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2391                    listener.onBeforeAddAssociation(roleId,
2392                        Permission.class.getName(), permissionId);
2393                }
2394
2395                _sqlUpdate.update(new Object[] {
2396                        new Long(permissionId), new Long(roleId)
2397                    });
2398
2399                for (ModelListener<Permission> listener : listeners) {
2400                    listener.onAfterAddAssociation(permissionId,
2401                        com.liferay.portal.model.Role.class.getName(), roleId);
2402                }
2403
2404                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2405                    listener.onAfterAddAssociation(roleId,
2406                        Permission.class.getName(), permissionId);
2407                }
2408            }
2409        }
2410
2411        private SqlUpdate _sqlUpdate;
2412        private PermissionPersistenceImpl _persistenceImpl;
2413    }
2414
2415    protected class ClearRoles {
2416        protected ClearRoles(PermissionPersistenceImpl persistenceImpl) {
2417            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2418                    "DELETE FROM Roles_Permissions WHERE permissionId = ?",
2419                    new int[] { Types.BIGINT });
2420        }
2421
2422        protected void clear(long permissionId) throws SystemException {
2423            ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2424
2425            List<com.liferay.portal.model.Role> roles = null;
2426
2427            if ((listeners.length > 0) || (roleListeners.length > 0)) {
2428                roles = getRoles(permissionId);
2429
2430                for (com.liferay.portal.model.Role role : roles) {
2431                    for (ModelListener<Permission> listener : listeners) {
2432                        listener.onBeforeRemoveAssociation(permissionId,
2433                            com.liferay.portal.model.Role.class.getName(),
2434                            role.getPrimaryKey());
2435                    }
2436
2437                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2438                        listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
2439                            Permission.class.getName(), permissionId);
2440                    }
2441                }
2442            }
2443
2444            _sqlUpdate.update(new Object[] { new Long(permissionId) });
2445
2446            if ((listeners.length > 0) || (roleListeners.length > 0)) {
2447                for (com.liferay.portal.model.Role role : roles) {
2448                    for (ModelListener<Permission> listener : listeners) {
2449                        listener.onAfterRemoveAssociation(permissionId,
2450                            com.liferay.portal.model.Role.class.getName(),
2451                            role.getPrimaryKey());
2452                    }
2453
2454                    for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2455                        listener.onAfterRemoveAssociation(role.getPrimaryKey(),
2456                            Permission.class.getName(), permissionId);
2457                    }
2458                }
2459            }
2460        }
2461
2462        private SqlUpdate _sqlUpdate;
2463    }
2464
2465    protected class RemoveRole {
2466        protected RemoveRole(PermissionPersistenceImpl persistenceImpl) {
2467            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2468                    "DELETE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?",
2469                    new int[] { Types.BIGINT, Types.BIGINT });
2470            _persistenceImpl = persistenceImpl;
2471        }
2472
2473        protected void remove(long permissionId, long roleId)
2474            throws SystemException {
2475            if (_persistenceImpl.containsRole.contains(permissionId, roleId)) {
2476                ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2477
2478                for (ModelListener<Permission> listener : listeners) {
2479                    listener.onBeforeRemoveAssociation(permissionId,
2480                        com.liferay.portal.model.Role.class.getName(), roleId);
2481                }
2482
2483                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2484                    listener.onBeforeRemoveAssociation(roleId,
2485                        Permission.class.getName(), permissionId);
2486                }
2487
2488                _sqlUpdate.update(new Object[] {
2489                        new Long(permissionId), new Long(roleId)
2490                    });
2491
2492                for (ModelListener<Permission> listener : listeners) {
2493                    listener.onAfterRemoveAssociation(permissionId,
2494                        com.liferay.portal.model.Role.class.getName(), roleId);
2495                }
2496
2497                for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2498                    listener.onAfterRemoveAssociation(roleId,
2499                        Permission.class.getName(), permissionId);
2500                }
2501            }
2502        }
2503
2504        private SqlUpdate _sqlUpdate;
2505        private PermissionPersistenceImpl _persistenceImpl;
2506    }
2507
2508    protected class ContainsUser {
2509        protected ContainsUser(PermissionPersistenceImpl persistenceImpl) {
2510            super();
2511
2512            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2513                    _SQL_CONTAINSUSER,
2514                    new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2515        }
2516
2517        protected boolean contains(long permissionId, long userId) {
2518            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2519                        new Long(permissionId), new Long(userId)
2520                    });
2521
2522            if (results.size() > 0) {
2523                Integer count = results.get(0);
2524
2525                if (count.intValue() > 0) {
2526                    return true;
2527                }
2528            }
2529
2530            return false;
2531        }
2532
2533        private MappingSqlQuery<Integer> _mappingSqlQuery;
2534    }
2535
2536    protected class AddUser {
2537        protected AddUser(PermissionPersistenceImpl persistenceImpl) {
2538            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2539                    "INSERT INTO Users_Permissions (permissionId, userId) VALUES (?, ?)",
2540                    new int[] { Types.BIGINT, Types.BIGINT });
2541            _persistenceImpl = persistenceImpl;
2542        }
2543
2544        protected void add(long permissionId, long userId)
2545            throws SystemException {
2546            if (!_persistenceImpl.containsUser.contains(permissionId, userId)) {
2547                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2548
2549                for (ModelListener<Permission> listener : listeners) {
2550                    listener.onBeforeAddAssociation(permissionId,
2551                        com.liferay.portal.model.User.class.getName(), userId);
2552                }
2553
2554                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2555                    listener.onBeforeAddAssociation(userId,
2556                        Permission.class.getName(), permissionId);
2557                }
2558
2559                _sqlUpdate.update(new Object[] {
2560                        new Long(permissionId), new Long(userId)
2561                    });
2562
2563                for (ModelListener<Permission> listener : listeners) {
2564                    listener.onAfterAddAssociation(permissionId,
2565                        com.liferay.portal.model.User.class.getName(), userId);
2566                }
2567
2568                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2569                    listener.onAfterAddAssociation(userId,
2570                        Permission.class.getName(), permissionId);
2571                }
2572            }
2573        }
2574
2575        private SqlUpdate _sqlUpdate;
2576        private PermissionPersistenceImpl _persistenceImpl;
2577    }
2578
2579    protected class ClearUsers {
2580        protected ClearUsers(PermissionPersistenceImpl persistenceImpl) {
2581            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2582                    "DELETE FROM Users_Permissions WHERE permissionId = ?",
2583                    new int[] { Types.BIGINT });
2584        }
2585
2586        protected void clear(long permissionId) throws SystemException {
2587            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2588
2589            List<com.liferay.portal.model.User> users = null;
2590
2591            if ((listeners.length > 0) || (userListeners.length > 0)) {
2592                users = getUsers(permissionId);
2593
2594                for (com.liferay.portal.model.User user : users) {
2595                    for (ModelListener<Permission> listener : listeners) {
2596                        listener.onBeforeRemoveAssociation(permissionId,
2597                            com.liferay.portal.model.User.class.getName(),
2598                            user.getPrimaryKey());
2599                    }
2600
2601                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2602                        listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2603                            Permission.class.getName(), permissionId);
2604                    }
2605                }
2606            }
2607
2608            _sqlUpdate.update(new Object[] { new Long(permissionId) });
2609
2610            if ((listeners.length > 0) || (userListeners.length > 0)) {
2611                for (com.liferay.portal.model.User user : users) {
2612                    for (ModelListener<Permission> listener : listeners) {
2613                        listener.onAfterRemoveAssociation(permissionId,
2614                            com.liferay.portal.model.User.class.getName(),
2615                            user.getPrimaryKey());
2616                    }
2617
2618                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2619                        listener.onAfterRemoveAssociation(user.getPrimaryKey(),
2620                            Permission.class.getName(), permissionId);
2621                    }
2622                }
2623            }
2624        }
2625
2626        private SqlUpdate _sqlUpdate;
2627    }
2628
2629    protected class RemoveUser {
2630        protected RemoveUser(PermissionPersistenceImpl persistenceImpl) {
2631            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2632                    "DELETE FROM Users_Permissions WHERE permissionId = ? AND userId = ?",
2633                    new int[] { Types.BIGINT, Types.BIGINT });
2634            _persistenceImpl = persistenceImpl;
2635        }
2636
2637        protected void remove(long permissionId, long userId)
2638            throws SystemException {
2639            if (_persistenceImpl.containsUser.contains(permissionId, userId)) {
2640                ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2641
2642                for (ModelListener<Permission> listener : listeners) {
2643                    listener.onBeforeRemoveAssociation(permissionId,
2644                        com.liferay.portal.model.User.class.getName(), userId);
2645                }
2646
2647                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2648                    listener.onBeforeRemoveAssociation(userId,
2649                        Permission.class.getName(), permissionId);
2650                }
2651
2652                _sqlUpdate.update(new Object[] {
2653                        new Long(permissionId), new Long(userId)
2654                    });
2655
2656                for (ModelListener<Permission> listener : listeners) {
2657                    listener.onAfterRemoveAssociation(permissionId,
2658                        com.liferay.portal.model.User.class.getName(), userId);
2659                }
2660
2661                for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2662                    listener.onAfterRemoveAssociation(userId,
2663                        Permission.class.getName(), permissionId);
2664                }
2665            }
2666        }
2667
2668        private SqlUpdate _sqlUpdate;
2669        private PermissionPersistenceImpl _persistenceImpl;
2670    }
2671
2672    private static final String _SQL_SELECT_PERMISSION = "SELECT permission FROM Permission permission";
2673    private static final String _SQL_SELECT_PERMISSION_WHERE = "SELECT permission FROM Permission permission WHERE ";
2674    private static final String _SQL_COUNT_PERMISSION = "SELECT COUNT(permission) FROM Permission permission";
2675    private static final String _SQL_COUNT_PERMISSION_WHERE = "SELECT COUNT(permission) FROM Permission permission WHERE ";
2676    private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Permissions ON (Groups_Permissions.groupId = Group_.groupId) WHERE (Groups_Permissions.permissionId = ?)";
2677    private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ?";
2678    private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?";
2679    private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Roles_Permissions ON (Roles_Permissions.roleId = Role_.roleId) WHERE (Roles_Permissions.permissionId = ?)";
2680    private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ?";
2681    private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?";
2682    private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Permissions ON (Users_Permissions.userId = User_.userId) WHERE (Users_Permissions.permissionId = ?)";
2683    private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ?";
2684    private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ? AND userId = ?";
2685    private static final String _FINDER_COLUMN_RESOURCEID_RESOURCEID_2 = "permission.resourceId = ?";
2686    private static final String _FINDER_COLUMN_A_R_ACTIONID_1 = "permission.actionId IS NULL AND ";
2687    private static final String _FINDER_COLUMN_A_R_ACTIONID_2 = "permission.actionId = ? AND ";
2688    private static final String _FINDER_COLUMN_A_R_ACTIONID_3 = "(permission.actionId IS NULL OR permission.actionId = ?) AND ";
2689    private static final String _FINDER_COLUMN_A_R_RESOURCEID_2 = "permission.resourceId = ?";
2690    private static final String _ORDER_BY_ENTITY_ALIAS = "permission.";
2691    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Permission exists with the primary key ";
2692    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Permission exists with the key {";
2693    private static Log _log = LogFactoryUtil.getLog(PermissionPersistenceImpl.class);
2694}