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