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