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