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