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