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