1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.NoSuchResourcePermissionException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.annotation.BeanReference;
28  import com.liferay.portal.kernel.cache.CacheRegistry;
29  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
30  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
31  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
32  import com.liferay.portal.kernel.dao.orm.FinderPath;
33  import com.liferay.portal.kernel.dao.orm.Query;
34  import com.liferay.portal.kernel.dao.orm.QueryPos;
35  import com.liferay.portal.kernel.dao.orm.QueryUtil;
36  import com.liferay.portal.kernel.dao.orm.Session;
37  import com.liferay.portal.kernel.log.Log;
38  import com.liferay.portal.kernel.log.LogFactoryUtil;
39  import com.liferay.portal.kernel.util.GetterUtil;
40  import com.liferay.portal.kernel.util.OrderByComparator;
41  import com.liferay.portal.kernel.util.StringPool;
42  import com.liferay.portal.kernel.util.StringUtil;
43  import com.liferay.portal.kernel.util.Validator;
44  import com.liferay.portal.model.ModelListener;
45  import com.liferay.portal.model.ResourcePermission;
46  import com.liferay.portal.model.impl.ResourcePermissionImpl;
47  import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
48  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.List;
53  
54  /**
55   * <a href="ResourcePermissionPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   */
60  public class ResourcePermissionPersistenceImpl extends BasePersistenceImpl
61      implements ResourcePermissionPersistence {
62      public static final String FINDER_CLASS_NAME_ENTITY = ResourcePermissionImpl.class.getName();
63      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
64          ".List";
65      public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
66              ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
67              FINDER_CLASS_NAME_LIST, "findByRoleId",
68              new String[] { Long.class.getName() });
69      public static final FinderPath FINDER_PATH_FIND_BY_OBC_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
70              ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
71              FINDER_CLASS_NAME_LIST, "findByRoleId",
72              new String[] {
73                  Long.class.getName(),
74                  
75              "java.lang.Integer", "java.lang.Integer",
76                  "com.liferay.portal.kernel.util.OrderByComparator"
77              });
78      public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
79              ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
80              FINDER_CLASS_NAME_LIST, "countByRoleId",
81              new String[] { Long.class.getName() });
82      public static final FinderPath FINDER_PATH_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
83              ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
84              FINDER_CLASS_NAME_LIST, "findByC_N_S",
85              new String[] {
86                  Long.class.getName(), String.class.getName(),
87                  Integer.class.getName()
88              });
89      public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
90              ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
91              FINDER_CLASS_NAME_LIST, "findByC_N_S",
92              new String[] {
93                  Long.class.getName(), String.class.getName(),
94                  Integer.class.getName(),
95                  
96              "java.lang.Integer", "java.lang.Integer",
97                  "com.liferay.portal.kernel.util.OrderByComparator"
98              });
99      public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
100             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
101             FINDER_CLASS_NAME_LIST, "countByC_N_S",
102             new String[] {
103                 Long.class.getName(), String.class.getName(),
104                 Integer.class.getName()
105             });
106     public static final FinderPath FINDER_PATH_FIND_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
107             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
108             FINDER_CLASS_NAME_LIST, "findByC_N_S_P",
109             new String[] {
110                 Long.class.getName(), String.class.getName(),
111                 Integer.class.getName(), String.class.getName()
112             });
113     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
114             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
115             FINDER_CLASS_NAME_LIST, "findByC_N_S_P",
116             new String[] {
117                 Long.class.getName(), String.class.getName(),
118                 Integer.class.getName(), String.class.getName(),
119                 
120             "java.lang.Integer", "java.lang.Integer",
121                 "com.liferay.portal.kernel.util.OrderByComparator"
122             });
123     public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
124             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
125             FINDER_CLASS_NAME_LIST, "countByC_N_S_P",
126             new String[] {
127                 Long.class.getName(), String.class.getName(),
128                 Integer.class.getName(), String.class.getName()
129             });
130     public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
131             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
132             FINDER_CLASS_NAME_ENTITY, "fetchByC_N_S_P_R",
133             new String[] {
134                 Long.class.getName(), String.class.getName(),
135                 Integer.class.getName(), String.class.getName(),
136                 Long.class.getName()
137             });
138     public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
139             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
140             FINDER_CLASS_NAME_LIST, "countByC_N_S_P_R",
141             new String[] {
142                 Long.class.getName(), String.class.getName(),
143                 Integer.class.getName(), String.class.getName(),
144                 Long.class.getName()
145             });
146     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
147             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
148             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
149     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
150             ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
151             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
152 
153     public void cacheResult(ResourcePermission resourcePermission) {
154         EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
155             ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
156             resourcePermission);
157 
158         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
159             new Object[] {
160                 new Long(resourcePermission.getCompanyId()),
161                 
162             resourcePermission.getName(),
163                 new Integer(resourcePermission.getScope()),
164                 
165             resourcePermission.getPrimKey(),
166                 new Long(resourcePermission.getRoleId())
167             }, resourcePermission);
168     }
169 
170     public void cacheResult(List<ResourcePermission> resourcePermissions) {
171         for (ResourcePermission resourcePermission : resourcePermissions) {
172             if (EntityCacheUtil.getResult(
173                         ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
174                         ResourcePermissionImpl.class,
175                         resourcePermission.getPrimaryKey(), this) == null) {
176                 cacheResult(resourcePermission);
177             }
178         }
179     }
180 
181     public void clearCache() {
182         CacheRegistry.clear(ResourcePermissionImpl.class.getName());
183         EntityCacheUtil.clearCache(ResourcePermissionImpl.class.getName());
184         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
185         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
186     }
187 
188     public ResourcePermission create(long resourcePermissionId) {
189         ResourcePermission resourcePermission = new ResourcePermissionImpl();
190 
191         resourcePermission.setNew(true);
192         resourcePermission.setPrimaryKey(resourcePermissionId);
193 
194         return resourcePermission;
195     }
196 
197     public ResourcePermission remove(long resourcePermissionId)
198         throws NoSuchResourcePermissionException, SystemException {
199         Session session = null;
200 
201         try {
202             session = openSession();
203 
204             ResourcePermission resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
205                     new Long(resourcePermissionId));
206 
207             if (resourcePermission == null) {
208                 if (_log.isWarnEnabled()) {
209                     _log.warn(
210                         "No ResourcePermission exists with the primary key " +
211                         resourcePermissionId);
212                 }
213 
214                 throw new NoSuchResourcePermissionException(
215                     "No ResourcePermission exists with the primary key " +
216                     resourcePermissionId);
217             }
218 
219             return remove(resourcePermission);
220         }
221         catch (NoSuchResourcePermissionException nsee) {
222             throw nsee;
223         }
224         catch (Exception e) {
225             throw processException(e);
226         }
227         finally {
228             closeSession(session);
229         }
230     }
231 
232     public ResourcePermission remove(ResourcePermission resourcePermission)
233         throws SystemException {
234         for (ModelListener<ResourcePermission> listener : listeners) {
235             listener.onBeforeRemove(resourcePermission);
236         }
237 
238         resourcePermission = removeImpl(resourcePermission);
239 
240         for (ModelListener<ResourcePermission> listener : listeners) {
241             listener.onAfterRemove(resourcePermission);
242         }
243 
244         return resourcePermission;
245     }
246 
247     protected ResourcePermission removeImpl(
248         ResourcePermission resourcePermission) throws SystemException {
249         Session session = null;
250 
251         try {
252             session = openSession();
253 
254             if (resourcePermission.isCachedModel() ||
255                     BatchSessionUtil.isEnabled()) {
256                 Object staleObject = session.get(ResourcePermissionImpl.class,
257                         resourcePermission.getPrimaryKeyObj());
258 
259                 if (staleObject != null) {
260                     session.evict(staleObject);
261                 }
262             }
263 
264             session.delete(resourcePermission);
265 
266             session.flush();
267         }
268         catch (Exception e) {
269             throw processException(e);
270         }
271         finally {
272             closeSession(session);
273         }
274 
275         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
276 
277         ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
278 
279         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
280             new Object[] {
281                 new Long(resourcePermissionModelImpl.getOriginalCompanyId()),
282                 
283             resourcePermissionModelImpl.getOriginalName(),
284                 new Integer(resourcePermissionModelImpl.getOriginalScope()),
285                 
286             resourcePermissionModelImpl.getOriginalPrimKey(),
287                 new Long(resourcePermissionModelImpl.getOriginalRoleId())
288             });
289 
290         EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
291             ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
292 
293         return resourcePermission;
294     }
295 
296     /**
297      * @deprecated Use <code>update(ResourcePermission resourcePermission, boolean merge)</code>.
298      */
299     public ResourcePermission update(ResourcePermission resourcePermission)
300         throws SystemException {
301         if (_log.isWarnEnabled()) {
302             _log.warn(
303                 "Using the deprecated update(ResourcePermission resourcePermission) method. Use update(ResourcePermission resourcePermission, boolean merge) instead.");
304         }
305 
306         return update(resourcePermission, false);
307     }
308 
309     /**
310      * Add, update, or merge, the entity. This method also calls the model
311      * listeners to trigger the proper events associated with adding, deleting,
312      * or updating an entity.
313      *
314      * @param        resourcePermission the entity to add, update, or merge
315      * @param        merge boolean value for whether to merge the entity. The
316      *                default value is false. Setting merge to true is more
317      *                expensive and should only be true when resourcePermission is
318      *                transient. See LEP-5473 for a detailed discussion of this
319      *                method.
320      * @return        true if the portlet can be displayed via Ajax
321      */
322     public ResourcePermission update(ResourcePermission resourcePermission,
323         boolean merge) throws SystemException {
324         boolean isNew = resourcePermission.isNew();
325 
326         for (ModelListener<ResourcePermission> listener : listeners) {
327             if (isNew) {
328                 listener.onBeforeCreate(resourcePermission);
329             }
330             else {
331                 listener.onBeforeUpdate(resourcePermission);
332             }
333         }
334 
335         resourcePermission = updateImpl(resourcePermission, merge);
336 
337         for (ModelListener<ResourcePermission> listener : listeners) {
338             if (isNew) {
339                 listener.onAfterCreate(resourcePermission);
340             }
341             else {
342                 listener.onAfterUpdate(resourcePermission);
343             }
344         }
345 
346         return resourcePermission;
347     }
348 
349     public ResourcePermission updateImpl(
350         com.liferay.portal.model.ResourcePermission resourcePermission,
351         boolean merge) throws SystemException {
352         boolean isNew = resourcePermission.isNew();
353 
354         ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
355 
356         Session session = null;
357 
358         try {
359             session = openSession();
360 
361             BatchSessionUtil.update(session, resourcePermission, merge);
362 
363             resourcePermission.setNew(false);
364         }
365         catch (Exception e) {
366             throw processException(e);
367         }
368         finally {
369             closeSession(session);
370         }
371 
372         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
373 
374         EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
375             ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
376             resourcePermission);
377 
378         if (!isNew &&
379                 ((resourcePermission.getCompanyId() != resourcePermissionModelImpl.getOriginalCompanyId()) ||
380                 !Validator.equals(resourcePermission.getName(),
381                     resourcePermissionModelImpl.getOriginalName()) ||
382                 (resourcePermission.getScope() != resourcePermissionModelImpl.getOriginalScope()) ||
383                 !Validator.equals(resourcePermission.getPrimKey(),
384                     resourcePermissionModelImpl.getOriginalPrimKey()) ||
385                 (resourcePermission.getRoleId() != resourcePermissionModelImpl.getOriginalRoleId()))) {
386             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
387                 new Object[] {
388                     new Long(resourcePermissionModelImpl.getOriginalCompanyId()),
389                     
390                 resourcePermissionModelImpl.getOriginalName(),
391                     new Integer(resourcePermissionModelImpl.getOriginalScope()),
392                     
393                 resourcePermissionModelImpl.getOriginalPrimKey(),
394                     new Long(resourcePermissionModelImpl.getOriginalRoleId())
395                 });
396         }
397 
398         if (isNew ||
399                 ((resourcePermission.getCompanyId() != resourcePermissionModelImpl.getOriginalCompanyId()) ||
400                 !Validator.equals(resourcePermission.getName(),
401                     resourcePermissionModelImpl.getOriginalName()) ||
402                 (resourcePermission.getScope() != resourcePermissionModelImpl.getOriginalScope()) ||
403                 !Validator.equals(resourcePermission.getPrimKey(),
404                     resourcePermissionModelImpl.getOriginalPrimKey()) ||
405                 (resourcePermission.getRoleId() != resourcePermissionModelImpl.getOriginalRoleId()))) {
406             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
407                 new Object[] {
408                     new Long(resourcePermission.getCompanyId()),
409                     
410                 resourcePermission.getName(),
411                     new Integer(resourcePermission.getScope()),
412                     
413                 resourcePermission.getPrimKey(),
414                     new Long(resourcePermission.getRoleId())
415                 }, resourcePermission);
416         }
417 
418         return resourcePermission;
419     }
420 
421     public ResourcePermission findByPrimaryKey(long resourcePermissionId)
422         throws NoSuchResourcePermissionException, SystemException {
423         ResourcePermission resourcePermission = fetchByPrimaryKey(resourcePermissionId);
424 
425         if (resourcePermission == null) {
426             if (_log.isWarnEnabled()) {
427                 _log.warn("No ResourcePermission exists with the primary key " +
428                     resourcePermissionId);
429             }
430 
431             throw new NoSuchResourcePermissionException(
432                 "No ResourcePermission exists with the primary key " +
433                 resourcePermissionId);
434         }
435 
436         return resourcePermission;
437     }
438 
439     public ResourcePermission fetchByPrimaryKey(long resourcePermissionId)
440         throws SystemException {
441         ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
442                 ResourcePermissionImpl.class, resourcePermissionId, this);
443 
444         if (resourcePermission == null) {
445             Session session = null;
446 
447             try {
448                 session = openSession();
449 
450                 resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
451                         new Long(resourcePermissionId));
452             }
453             catch (Exception e) {
454                 throw processException(e);
455             }
456             finally {
457                 if (resourcePermission != null) {
458                     cacheResult(resourcePermission);
459                 }
460 
461                 closeSession(session);
462             }
463         }
464 
465         return resourcePermission;
466     }
467 
468     public List<ResourcePermission> findByRoleId(long roleId)
469         throws SystemException {
470         Object[] finderArgs = new Object[] { new Long(roleId) };
471 
472         List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
473                 finderArgs, this);
474 
475         if (list == null) {
476             Session session = null;
477 
478             try {
479                 session = openSession();
480 
481                 StringBuilder query = new StringBuilder();
482 
483                 query.append(
484                     "FROM com.liferay.portal.model.ResourcePermission WHERE ");
485 
486                 query.append("roleId = ?");
487 
488                 query.append(" ");
489 
490                 Query q = session.createQuery(query.toString());
491 
492                 QueryPos qPos = QueryPos.getInstance(q);
493 
494                 qPos.add(roleId);
495 
496                 list = q.list();
497             }
498             catch (Exception e) {
499                 throw processException(e);
500             }
501             finally {
502                 if (list == null) {
503                     list = new ArrayList<ResourcePermission>();
504                 }
505 
506                 cacheResult(list);
507 
508                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
509                     finderArgs, list);
510 
511                 closeSession(session);
512             }
513         }
514 
515         return list;
516     }
517 
518     public List<ResourcePermission> findByRoleId(long roleId, int start, int end)
519         throws SystemException {
520         return findByRoleId(roleId, start, end, null);
521     }
522 
523     public List<ResourcePermission> findByRoleId(long roleId, int start,
524         int end, OrderByComparator obc) throws SystemException {
525         Object[] finderArgs = new Object[] {
526                 new Long(roleId),
527                 
528                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
529             };
530 
531         List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_ROLEID,
532                 finderArgs, this);
533 
534         if (list == null) {
535             Session session = null;
536 
537             try {
538                 session = openSession();
539 
540                 StringBuilder query = new StringBuilder();
541 
542                 query.append(
543                     "FROM com.liferay.portal.model.ResourcePermission WHERE ");
544 
545                 query.append("roleId = ?");
546 
547                 query.append(" ");
548 
549                 if (obc != null) {
550                     query.append("ORDER BY ");
551                     query.append(obc.getOrderBy());
552                 }
553 
554                 Query q = session.createQuery(query.toString());
555 
556                 QueryPos qPos = QueryPos.getInstance(q);
557 
558                 qPos.add(roleId);
559 
560                 list = (List<ResourcePermission>)QueryUtil.list(q,
561                         getDialect(), start, end);
562             }
563             catch (Exception e) {
564                 throw processException(e);
565             }
566             finally {
567                 if (list == null) {
568                     list = new ArrayList<ResourcePermission>();
569                 }
570 
571                 cacheResult(list);
572 
573                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_ROLEID,
574                     finderArgs, list);
575 
576                 closeSession(session);
577             }
578         }
579 
580         return list;
581     }
582 
583     public ResourcePermission findByRoleId_First(long roleId,
584         OrderByComparator obc)
585         throws NoSuchResourcePermissionException, SystemException {
586         List<ResourcePermission> list = findByRoleId(roleId, 0, 1, obc);
587 
588         if (list.isEmpty()) {
589             StringBuilder msg = new StringBuilder();
590 
591             msg.append("No ResourcePermission exists with the key {");
592 
593             msg.append("roleId=" + roleId);
594 
595             msg.append(StringPool.CLOSE_CURLY_BRACE);
596 
597             throw new NoSuchResourcePermissionException(msg.toString());
598         }
599         else {
600             return list.get(0);
601         }
602     }
603 
604     public ResourcePermission findByRoleId_Last(long roleId,
605         OrderByComparator obc)
606         throws NoSuchResourcePermissionException, SystemException {
607         int count = countByRoleId(roleId);
608 
609         List<ResourcePermission> list = findByRoleId(roleId, count - 1, count,
610                 obc);
611 
612         if (list.isEmpty()) {
613             StringBuilder msg = new StringBuilder();
614 
615             msg.append("No ResourcePermission exists with the key {");
616 
617             msg.append("roleId=" + roleId);
618 
619             msg.append(StringPool.CLOSE_CURLY_BRACE);
620 
621             throw new NoSuchResourcePermissionException(msg.toString());
622         }
623         else {
624             return list.get(0);
625         }
626     }
627 
628     public ResourcePermission[] findByRoleId_PrevAndNext(
629         long resourcePermissionId, long roleId, OrderByComparator obc)
630         throws NoSuchResourcePermissionException, SystemException {
631         ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
632 
633         int count = countByRoleId(roleId);
634 
635         Session session = null;
636 
637         try {
638             session = openSession();
639 
640             StringBuilder query = new StringBuilder();
641 
642             query.append(
643                 "FROM com.liferay.portal.model.ResourcePermission WHERE ");
644 
645             query.append("roleId = ?");
646 
647             query.append(" ");
648 
649             if (obc != null) {
650                 query.append("ORDER BY ");
651                 query.append(obc.getOrderBy());
652             }
653 
654             Query q = session.createQuery(query.toString());
655 
656             QueryPos qPos = QueryPos.getInstance(q);
657 
658             qPos.add(roleId);
659 
660             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
661                     resourcePermission);
662 
663             ResourcePermission[] array = new ResourcePermissionImpl[3];
664 
665             array[0] = (ResourcePermission)objArray[0];
666             array[1] = (ResourcePermission)objArray[1];
667             array[2] = (ResourcePermission)objArray[2];
668 
669             return array;
670         }
671         catch (Exception e) {
672             throw processException(e);
673         }
674         finally {
675             closeSession(session);
676         }
677     }
678 
679     public List<ResourcePermission> findByC_N_S(long companyId, String name,
680         int scope) throws SystemException {
681         Object[] finderArgs = new Object[] {
682                 new Long(companyId),
683                 
684                 name, new Integer(scope)
685             };
686 
687         List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_N_S,
688                 finderArgs, this);
689 
690         if (list == null) {
691             Session session = null;
692 
693             try {
694                 session = openSession();
695 
696                 StringBuilder query = new StringBuilder();
697 
698                 query.append(
699                     "FROM com.liferay.portal.model.ResourcePermission WHERE ");
700 
701                 query.append("companyId = ?");
702 
703                 query.append(" AND ");
704 
705                 if (name == null) {
706                     query.append("name IS NULL");
707                 }
708                 else {
709                     query.append("name = ?");
710                 }
711 
712                 query.append(" AND ");
713 
714                 query.append("scope = ?");
715 
716                 query.append(" ");
717 
718                 Query q = session.createQuery(query.toString());
719 
720                 QueryPos qPos = QueryPos.getInstance(q);
721 
722                 qPos.add(companyId);
723 
724                 if (name != null) {
725                     qPos.add(name);
726                 }
727 
728                 qPos.add(scope);
729 
730                 list = q.list();
731             }
732             catch (Exception e) {
733                 throw processException(e);
734             }
735             finally {
736                 if (list == null) {
737                     list = new ArrayList<ResourcePermission>();
738                 }
739 
740                 cacheResult(list);
741 
742                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_N_S,
743                     finderArgs, list);
744 
745                 closeSession(session);
746             }
747         }
748 
749         return list;
750     }
751 
752     public List<ResourcePermission> findByC_N_S(long companyId, String name,
753         int scope, int start, int end) throws SystemException {
754         return findByC_N_S(companyId, name, scope, start, end, null);
755     }
756 
757     public List<ResourcePermission> findByC_N_S(long companyId, String name,
758         int scope, int start, int end, OrderByComparator obc)
759         throws SystemException {
760         Object[] finderArgs = new Object[] {
761                 new Long(companyId),
762                 
763                 name, new Integer(scope),
764                 
765                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
766             };
767 
768         List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_N_S,
769                 finderArgs, this);
770 
771         if (list == null) {
772             Session session = null;
773 
774             try {
775                 session = openSession();
776 
777                 StringBuilder query = new StringBuilder();
778 
779                 query.append(
780                     "FROM com.liferay.portal.model.ResourcePermission WHERE ");
781 
782                 query.append("companyId = ?");
783 
784                 query.append(" AND ");
785 
786                 if (name == null) {
787                     query.append("name IS NULL");
788                 }
789                 else {
790                     query.append("name = ?");
791                 }
792 
793                 query.append(" AND ");
794 
795                 query.append("scope = ?");
796 
797                 query.append(" ");
798 
799                 if (obc != null) {
800                     query.append("ORDER BY ");
801                     query.append(obc.getOrderBy());
802                 }
803 
804                 Query q = session.createQuery(query.toString());
805 
806                 QueryPos qPos = QueryPos.getInstance(q);
807 
808                 qPos.add(companyId);
809 
810                 if (name != null) {
811                     qPos.add(name);
812                 }
813 
814                 qPos.add(scope);
815 
816                 list = (List<ResourcePermission>)QueryUtil.list(q,
817                         getDialect(), start, end);
818             }
819             catch (Exception e) {
820                 throw processException(e);
821             }
822             finally {
823                 if (list == null) {
824                     list = new ArrayList<ResourcePermission>();
825                 }
826 
827                 cacheResult(list);
828 
829                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_N_S,
830                     finderArgs, list);
831 
832                 closeSession(session);
833             }
834         }
835 
836         return list;
837     }
838 
839     public ResourcePermission findByC_N_S_First(long companyId, String name,
840         int scope, OrderByComparator obc)
841         throws NoSuchResourcePermissionException, SystemException {
842         List<ResourcePermission> list = findByC_N_S(companyId, name, scope, 0,
843                 1, obc);
844 
845         if (list.isEmpty()) {
846             StringBuilder msg = new StringBuilder();
847 
848             msg.append("No ResourcePermission exists with the key {");
849 
850             msg.append("companyId=" + companyId);
851 
852             msg.append(", ");
853             msg.append("name=" + name);
854 
855             msg.append(", ");
856             msg.append("scope=" + scope);
857 
858             msg.append(StringPool.CLOSE_CURLY_BRACE);
859 
860             throw new NoSuchResourcePermissionException(msg.toString());
861         }
862         else {
863             return list.get(0);
864         }
865     }
866 
867     public ResourcePermission findByC_N_S_Last(long companyId, String name,
868         int scope, OrderByComparator obc)
869         throws NoSuchResourcePermissionException, SystemException {
870         int count = countByC_N_S(companyId, name, scope);
871 
872         List<ResourcePermission> list = findByC_N_S(companyId, name, scope,
873                 count - 1, count, obc);
874 
875         if (list.isEmpty()) {
876             StringBuilder msg = new StringBuilder();
877 
878             msg.append("No ResourcePermission exists with the key {");
879 
880             msg.append("companyId=" + companyId);
881 
882             msg.append(", ");
883             msg.append("name=" + name);
884 
885             msg.append(", ");
886             msg.append("scope=" + scope);
887 
888             msg.append(StringPool.CLOSE_CURLY_BRACE);
889 
890             throw new NoSuchResourcePermissionException(msg.toString());
891         }
892         else {
893             return list.get(0);
894         }
895     }
896 
897     public ResourcePermission[] findByC_N_S_PrevAndNext(
898         long resourcePermissionId, long companyId, String name, int scope,
899         OrderByComparator obc)
900         throws NoSuchResourcePermissionException, SystemException {
901         ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
902 
903         int count = countByC_N_S(companyId, name, scope);
904 
905         Session session = null;
906 
907         try {
908             session = openSession();
909 
910             StringBuilder query = new StringBuilder();
911 
912             query.append(
913                 "FROM com.liferay.portal.model.ResourcePermission WHERE ");
914 
915             query.append("companyId = ?");
916 
917             query.append(" AND ");
918 
919             if (name == null) {
920                 query.append("name IS NULL");
921             }
922             else {
923                 query.append("name = ?");
924             }
925 
926             query.append(" AND ");
927 
928             query.append("scope = ?");
929 
930             query.append(" ");
931 
932             if (obc != null) {
933                 query.append("ORDER BY ");
934                 query.append(obc.getOrderBy());
935             }
936 
937             Query q = session.createQuery(query.toString());
938 
939             QueryPos qPos = QueryPos.getInstance(q);
940 
941             qPos.add(companyId);
942 
943             if (name != null) {
944                 qPos.add(name);
945             }
946 
947             qPos.add(scope);
948 
949             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
950                     resourcePermission);
951 
952             ResourcePermission[] array = new ResourcePermissionImpl[3];
953 
954             array[0] = (ResourcePermission)objArray[0];
955             array[1] = (ResourcePermission)objArray[1];
956             array[2] = (ResourcePermission)objArray[2];
957 
958             return array;
959         }
960         catch (Exception e) {
961             throw processException(e);
962         }
963         finally {
964             closeSession(session);
965         }
966     }
967 
968     public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
969         int scope, String primKey) throws SystemException {
970         Object[] finderArgs = new Object[] {
971                 new Long(companyId),
972                 
973                 name, new Integer(scope),
974                 
975                 primKey
976             };
977 
978         List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_N_S_P,
979                 finderArgs, this);
980 
981         if (list == null) {
982             Session session = null;
983 
984             try {
985                 session = openSession();
986 
987                 StringBuilder query = new StringBuilder();
988 
989                 query.append(
990                     "FROM com.liferay.portal.model.ResourcePermission WHERE ");
991 
992                 query.append("companyId = ?");
993 
994                 query.append(" AND ");
995 
996                 if (name == null) {
997                     query.append("name IS NULL");
998                 }
999                 else {
1000                    query.append("name = ?");
1001                }
1002
1003                query.append(" AND ");
1004
1005                query.append("scope = ?");
1006
1007                query.append(" AND ");
1008
1009                if (primKey == null) {
1010                    query.append("primKey IS NULL");
1011                }
1012                else {
1013                    query.append("primKey = ?");
1014                }
1015
1016                query.append(" ");
1017
1018                Query q = session.createQuery(query.toString());
1019
1020                QueryPos qPos = QueryPos.getInstance(q);
1021
1022                qPos.add(companyId);
1023
1024                if (name != null) {
1025                    qPos.add(name);
1026                }
1027
1028                qPos.add(scope);
1029
1030                if (primKey != null) {
1031                    qPos.add(primKey);
1032                }
1033
1034                list = q.list();
1035            }
1036            catch (Exception e) {
1037                throw processException(e);
1038            }
1039            finally {
1040                if (list == null) {
1041                    list = new ArrayList<ResourcePermission>();
1042                }
1043
1044                cacheResult(list);
1045
1046                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_N_S_P,
1047                    finderArgs, list);
1048
1049                closeSession(session);
1050            }
1051        }
1052
1053        return list;
1054    }
1055
1056    public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1057        int scope, String primKey, int start, int end)
1058        throws SystemException {
1059        return findByC_N_S_P(companyId, name, scope, primKey, start, end, null);
1060    }
1061
1062    public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1063        int scope, String primKey, int start, int end, OrderByComparator obc)
1064        throws SystemException {
1065        Object[] finderArgs = new Object[] {
1066                new Long(companyId),
1067                
1068                name, new Integer(scope),
1069                
1070                primKey,
1071                
1072                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1073            };
1074
1075        List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_N_S_P,
1076                finderArgs, this);
1077
1078        if (list == null) {
1079            Session session = null;
1080
1081            try {
1082                session = openSession();
1083
1084                StringBuilder query = new StringBuilder();
1085
1086                query.append(
1087                    "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1088
1089                query.append("companyId = ?");
1090
1091                query.append(" AND ");
1092
1093                if (name == null) {
1094                    query.append("name IS NULL");
1095                }
1096                else {
1097                    query.append("name = ?");
1098                }
1099
1100                query.append(" AND ");
1101
1102                query.append("scope = ?");
1103
1104                query.append(" AND ");
1105
1106                if (primKey == null) {
1107                    query.append("primKey IS NULL");
1108                }
1109                else {
1110                    query.append("primKey = ?");
1111                }
1112
1113                query.append(" ");
1114
1115                if (obc != null) {
1116                    query.append("ORDER BY ");
1117                    query.append(obc.getOrderBy());
1118                }
1119
1120                Query q = session.createQuery(query.toString());
1121
1122                QueryPos qPos = QueryPos.getInstance(q);
1123
1124                qPos.add(companyId);
1125
1126                if (name != null) {
1127                    qPos.add(name);
1128                }
1129
1130                qPos.add(scope);
1131
1132                if (primKey != null) {
1133                    qPos.add(primKey);
1134                }
1135
1136                list = (List<ResourcePermission>)QueryUtil.list(q,
1137                        getDialect(), start, end);
1138            }
1139            catch (Exception e) {
1140                throw processException(e);
1141            }
1142            finally {
1143                if (list == null) {
1144                    list = new ArrayList<ResourcePermission>();
1145                }
1146
1147                cacheResult(list);
1148
1149                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_N_S_P,
1150                    finderArgs, list);
1151
1152                closeSession(session);
1153            }
1154        }
1155
1156        return list;
1157    }
1158
1159    public ResourcePermission findByC_N_S_P_First(long companyId, String name,
1160        int scope, String primKey, OrderByComparator obc)
1161        throws NoSuchResourcePermissionException, SystemException {
1162        List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
1163                primKey, 0, 1, obc);
1164
1165        if (list.isEmpty()) {
1166            StringBuilder msg = new StringBuilder();
1167
1168            msg.append("No ResourcePermission exists with the key {");
1169
1170            msg.append("companyId=" + companyId);
1171
1172            msg.append(", ");
1173            msg.append("name=" + name);
1174
1175            msg.append(", ");
1176            msg.append("scope=" + scope);
1177
1178            msg.append(", ");
1179            msg.append("primKey=" + primKey);
1180
1181            msg.append(StringPool.CLOSE_CURLY_BRACE);
1182
1183            throw new NoSuchResourcePermissionException(msg.toString());
1184        }
1185        else {
1186            return list.get(0);
1187        }
1188    }
1189
1190    public ResourcePermission findByC_N_S_P_Last(long companyId, String name,
1191        int scope, String primKey, OrderByComparator obc)
1192        throws NoSuchResourcePermissionException, SystemException {
1193        int count = countByC_N_S_P(companyId, name, scope, primKey);
1194
1195        List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
1196                primKey, count - 1, count, obc);
1197
1198        if (list.isEmpty()) {
1199            StringBuilder msg = new StringBuilder();
1200
1201            msg.append("No ResourcePermission exists with the key {");
1202
1203            msg.append("companyId=" + companyId);
1204
1205            msg.append(", ");
1206            msg.append("name=" + name);
1207
1208            msg.append(", ");
1209            msg.append("scope=" + scope);
1210
1211            msg.append(", ");
1212            msg.append("primKey=" + primKey);
1213
1214            msg.append(StringPool.CLOSE_CURLY_BRACE);
1215
1216            throw new NoSuchResourcePermissionException(msg.toString());
1217        }
1218        else {
1219            return list.get(0);
1220        }
1221    }
1222
1223    public ResourcePermission[] findByC_N_S_P_PrevAndNext(
1224        long resourcePermissionId, long companyId, String name, int scope,
1225        String primKey, OrderByComparator obc)
1226        throws NoSuchResourcePermissionException, SystemException {
1227        ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1228
1229        int count = countByC_N_S_P(companyId, name, scope, primKey);
1230
1231        Session session = null;
1232
1233        try {
1234            session = openSession();
1235
1236            StringBuilder query = new StringBuilder();
1237
1238            query.append(
1239                "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1240
1241            query.append("companyId = ?");
1242
1243            query.append(" AND ");
1244
1245            if (name == null) {
1246                query.append("name IS NULL");
1247            }
1248            else {
1249                query.append("name = ?");
1250            }
1251
1252            query.append(" AND ");
1253
1254            query.append("scope = ?");
1255
1256            query.append(" AND ");
1257
1258            if (primKey == null) {
1259                query.append("primKey IS NULL");
1260            }
1261            else {
1262                query.append("primKey = ?");
1263            }
1264
1265            query.append(" ");
1266
1267            if (obc != null) {
1268                query.append("ORDER BY ");
1269                query.append(obc.getOrderBy());
1270            }
1271
1272            Query q = session.createQuery(query.toString());
1273
1274            QueryPos qPos = QueryPos.getInstance(q);
1275
1276            qPos.add(companyId);
1277
1278            if (name != null) {
1279                qPos.add(name);
1280            }
1281
1282            qPos.add(scope);
1283
1284            if (primKey != null) {
1285                qPos.add(primKey);
1286            }
1287
1288            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1289                    resourcePermission);
1290
1291            ResourcePermission[] array = new ResourcePermissionImpl[3];
1292
1293            array[0] = (ResourcePermission)objArray[0];
1294            array[1] = (ResourcePermission)objArray[1];
1295            array[2] = (ResourcePermission)objArray[2];
1296
1297            return array;
1298        }
1299        catch (Exception e) {
1300            throw processException(e);
1301        }
1302        finally {
1303            closeSession(session);
1304        }
1305    }
1306
1307    public ResourcePermission findByC_N_S_P_R(long companyId, String name,
1308        int scope, String primKey, long roleId)
1309        throws NoSuchResourcePermissionException, SystemException {
1310        ResourcePermission resourcePermission = fetchByC_N_S_P_R(companyId,
1311                name, scope, primKey, roleId);
1312
1313        if (resourcePermission == null) {
1314            StringBuilder msg = new StringBuilder();
1315
1316            msg.append("No ResourcePermission exists with the key {");
1317
1318            msg.append("companyId=" + companyId);
1319
1320            msg.append(", ");
1321            msg.append("name=" + name);
1322
1323            msg.append(", ");
1324            msg.append("scope=" + scope);
1325
1326            msg.append(", ");
1327            msg.append("primKey=" + primKey);
1328
1329            msg.append(", ");
1330            msg.append("roleId=" + roleId);
1331
1332            msg.append(StringPool.CLOSE_CURLY_BRACE);
1333
1334            if (_log.isWarnEnabled()) {
1335                _log.warn(msg.toString());
1336            }
1337
1338            throw new NoSuchResourcePermissionException(msg.toString());
1339        }
1340
1341        return resourcePermission;
1342    }
1343
1344    public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
1345        int scope, String primKey, long roleId) throws SystemException {
1346        return fetchByC_N_S_P_R(companyId, name, scope, primKey, roleId, true);
1347    }
1348
1349    public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
1350        int scope, String primKey, long roleId, boolean retrieveFromCache)
1351        throws SystemException {
1352        Object[] finderArgs = new Object[] {
1353                new Long(companyId),
1354                
1355                name, new Integer(scope),
1356                
1357                primKey, new Long(roleId)
1358            };
1359
1360        Object result = null;
1361
1362        if (retrieveFromCache) {
1363            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1364                    finderArgs, this);
1365        }
1366
1367        if (result == null) {
1368            Session session = null;
1369
1370            try {
1371                session = openSession();
1372
1373                StringBuilder query = new StringBuilder();
1374
1375                query.append(
1376                    "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1377
1378                query.append("companyId = ?");
1379
1380                query.append(" AND ");
1381
1382                if (name == null) {
1383                    query.append("name IS NULL");
1384                }
1385                else {
1386                    query.append("name = ?");
1387                }
1388
1389                query.append(" AND ");
1390
1391                query.append("scope = ?");
1392
1393                query.append(" AND ");
1394
1395                if (primKey == null) {
1396                    query.append("primKey IS NULL");
1397                }
1398                else {
1399                    query.append("primKey = ?");
1400                }
1401
1402                query.append(" AND ");
1403
1404                query.append("roleId = ?");
1405
1406                query.append(" ");
1407
1408                Query q = session.createQuery(query.toString());
1409
1410                QueryPos qPos = QueryPos.getInstance(q);
1411
1412                qPos.add(companyId);
1413
1414                if (name != null) {
1415                    qPos.add(name);
1416                }
1417
1418                qPos.add(scope);
1419
1420                if (primKey != null) {
1421                    qPos.add(primKey);
1422                }
1423
1424                qPos.add(roleId);
1425
1426                List<ResourcePermission> list = q.list();
1427
1428                result = list;
1429
1430                ResourcePermission resourcePermission = null;
1431
1432                if (list.isEmpty()) {
1433                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1434                        finderArgs, list);
1435                }
1436                else {
1437                    resourcePermission = list.get(0);
1438
1439                    cacheResult(resourcePermission);
1440
1441                    if ((resourcePermission.getCompanyId() != companyId) ||
1442                            (resourcePermission.getName() == null) ||
1443                            !resourcePermission.getName().equals(name) ||
1444                            (resourcePermission.getScope() != scope) ||
1445                            (resourcePermission.getPrimKey() == null) ||
1446                            !resourcePermission.getPrimKey().equals(primKey) ||
1447                            (resourcePermission.getRoleId() != roleId)) {
1448                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1449                            finderArgs, resourcePermission);
1450                    }
1451                }
1452
1453                return resourcePermission;
1454            }
1455            catch (Exception e) {
1456                throw processException(e);
1457            }
1458            finally {
1459                if (result == null) {
1460                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1461                        finderArgs, new ArrayList<ResourcePermission>());
1462                }
1463
1464                closeSession(session);
1465            }
1466        }
1467        else {
1468            if (result instanceof List) {
1469                return null;
1470            }
1471            else {
1472                return (ResourcePermission)result;
1473            }
1474        }
1475    }
1476
1477    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1478        throws SystemException {
1479        Session session = null;
1480
1481        try {
1482            session = openSession();
1483
1484            dynamicQuery.compile(session);
1485
1486            return dynamicQuery.list();
1487        }
1488        catch (Exception e) {
1489            throw processException(e);
1490        }
1491        finally {
1492            closeSession(session);
1493        }
1494    }
1495
1496    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1497        int start, int end) throws SystemException {
1498        Session session = null;
1499
1500        try {
1501            session = openSession();
1502
1503            dynamicQuery.setLimit(start, end);
1504
1505            dynamicQuery.compile(session);
1506
1507            return dynamicQuery.list();
1508        }
1509        catch (Exception e) {
1510            throw processException(e);
1511        }
1512        finally {
1513            closeSession(session);
1514        }
1515    }
1516
1517    public List<ResourcePermission> findAll() throws SystemException {
1518        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1519    }
1520
1521    public List<ResourcePermission> findAll(int start, int end)
1522        throws SystemException {
1523        return findAll(start, end, null);
1524    }
1525
1526    public List<ResourcePermission> findAll(int start, int end,
1527        OrderByComparator obc) throws SystemException {
1528        Object[] finderArgs = new Object[] {
1529                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1530            };
1531
1532        List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1533                finderArgs, this);
1534
1535        if (list == null) {
1536            Session session = null;
1537
1538            try {
1539                session = openSession();
1540
1541                StringBuilder query = new StringBuilder();
1542
1543                query.append(
1544                    "FROM com.liferay.portal.model.ResourcePermission ");
1545
1546                if (obc != null) {
1547                    query.append("ORDER BY ");
1548                    query.append(obc.getOrderBy());
1549                }
1550
1551                Query q = session.createQuery(query.toString());
1552
1553                if (obc == null) {
1554                    list = (List<ResourcePermission>)QueryUtil.list(q,
1555                            getDialect(), start, end, false);
1556
1557                    Collections.sort(list);
1558                }
1559                else {
1560                    list = (List<ResourcePermission>)QueryUtil.list(q,
1561                            getDialect(), start, end);
1562                }
1563            }
1564            catch (Exception e) {
1565                throw processException(e);
1566            }
1567            finally {
1568                if (list == null) {
1569                    list = new ArrayList<ResourcePermission>();
1570                }
1571
1572                cacheResult(list);
1573
1574                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1575
1576                closeSession(session);
1577            }
1578        }
1579
1580        return list;
1581    }
1582
1583    public void removeByRoleId(long roleId) throws SystemException {
1584        for (ResourcePermission resourcePermission : findByRoleId(roleId)) {
1585            remove(resourcePermission);
1586        }
1587    }
1588
1589    public void removeByC_N_S(long companyId, String name, int scope)
1590        throws SystemException {
1591        for (ResourcePermission resourcePermission : findByC_N_S(companyId,
1592                name, scope)) {
1593            remove(resourcePermission);
1594        }
1595    }
1596
1597    public void removeByC_N_S_P(long companyId, String name, int scope,
1598        String primKey) throws SystemException {
1599        for (ResourcePermission resourcePermission : findByC_N_S_P(companyId,
1600                name, scope, primKey)) {
1601            remove(resourcePermission);
1602        }
1603    }
1604
1605    public void removeByC_N_S_P_R(long companyId, String name, int scope,
1606        String primKey, long roleId)
1607        throws NoSuchResourcePermissionException, SystemException {
1608        ResourcePermission resourcePermission = findByC_N_S_P_R(companyId,
1609                name, scope, primKey, roleId);
1610
1611        remove(resourcePermission);
1612    }
1613
1614    public void removeAll() throws SystemException {
1615        for (ResourcePermission resourcePermission : findAll()) {
1616            remove(resourcePermission);
1617        }
1618    }
1619
1620    public int countByRoleId(long roleId) throws SystemException {
1621        Object[] finderArgs = new Object[] { new Long(roleId) };
1622
1623        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1624                finderArgs, this);
1625
1626        if (count == null) {
1627            Session session = null;
1628
1629            try {
1630                session = openSession();
1631
1632                StringBuilder query = new StringBuilder();
1633
1634                query.append("SELECT COUNT(*) ");
1635                query.append(
1636                    "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1637
1638                query.append("roleId = ?");
1639
1640                query.append(" ");
1641
1642                Query q = session.createQuery(query.toString());
1643
1644                QueryPos qPos = QueryPos.getInstance(q);
1645
1646                qPos.add(roleId);
1647
1648                count = (Long)q.uniqueResult();
1649            }
1650            catch (Exception e) {
1651                throw processException(e);
1652            }
1653            finally {
1654                if (count == null) {
1655                    count = Long.valueOf(0);
1656                }
1657
1658                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1659                    finderArgs, count);
1660
1661                closeSession(session);
1662            }
1663        }
1664
1665        return count.intValue();
1666    }
1667
1668    public int countByC_N_S(long companyId, String name, int scope)
1669        throws SystemException {
1670        Object[] finderArgs = new Object[] {
1671                new Long(companyId),
1672                
1673                name, new Integer(scope)
1674            };
1675
1676        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
1677                finderArgs, this);
1678
1679        if (count == null) {
1680            Session session = null;
1681
1682            try {
1683                session = openSession();
1684
1685                StringBuilder query = new StringBuilder();
1686
1687                query.append("SELECT COUNT(*) ");
1688                query.append(
1689                    "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1690
1691                query.append("companyId = ?");
1692
1693                query.append(" AND ");
1694
1695                if (name == null) {
1696                    query.append("name IS NULL");
1697                }
1698                else {
1699                    query.append("name = ?");
1700                }
1701
1702                query.append(" AND ");
1703
1704                query.append("scope = ?");
1705
1706                query.append(" ");
1707
1708                Query q = session.createQuery(query.toString());
1709
1710                QueryPos qPos = QueryPos.getInstance(q);
1711
1712                qPos.add(companyId);
1713
1714                if (name != null) {
1715                    qPos.add(name);
1716                }
1717
1718                qPos.add(scope);
1719
1720                count = (Long)q.uniqueResult();
1721            }
1722            catch (Exception e) {
1723                throw processException(e);
1724            }
1725            finally {
1726                if (count == null) {
1727                    count = Long.valueOf(0);
1728                }
1729
1730                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
1731                    finderArgs, count);
1732
1733                closeSession(session);
1734            }
1735        }
1736
1737        return count.intValue();
1738    }
1739
1740    public int countByC_N_S_P(long companyId, String name, int scope,
1741        String primKey) throws SystemException {
1742        Object[] finderArgs = new Object[] {
1743                new Long(companyId),
1744                
1745                name, new Integer(scope),
1746                
1747                primKey
1748            };
1749
1750        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P,
1751                finderArgs, this);
1752
1753        if (count == null) {
1754            Session session = null;
1755
1756            try {
1757                session = openSession();
1758
1759                StringBuilder query = new StringBuilder();
1760
1761                query.append("SELECT COUNT(*) ");
1762                query.append(
1763                    "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1764
1765                query.append("companyId = ?");
1766
1767                query.append(" AND ");
1768
1769                if (name == null) {
1770                    query.append("name IS NULL");
1771                }
1772                else {
1773                    query.append("name = ?");
1774                }
1775
1776                query.append(" AND ");
1777
1778                query.append("scope = ?");
1779
1780                query.append(" AND ");
1781
1782                if (primKey == null) {
1783                    query.append("primKey IS NULL");
1784                }
1785                else {
1786                    query.append("primKey = ?");
1787                }
1788
1789                query.append(" ");
1790
1791                Query q = session.createQuery(query.toString());
1792
1793                QueryPos qPos = QueryPos.getInstance(q);
1794
1795                qPos.add(companyId);
1796
1797                if (name != null) {
1798                    qPos.add(name);
1799                }
1800
1801                qPos.add(scope);
1802
1803                if (primKey != null) {
1804                    qPos.add(primKey);
1805                }
1806
1807                count = (Long)q.uniqueResult();
1808            }
1809            catch (Exception e) {
1810                throw processException(e);
1811            }
1812            finally {
1813                if (count == null) {
1814                    count = Long.valueOf(0);
1815                }
1816
1817                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P,
1818                    finderArgs, count);
1819
1820                closeSession(session);
1821            }
1822        }
1823
1824        return count.intValue();
1825    }
1826
1827    public int countByC_N_S_P_R(long companyId, String name, int scope,
1828        String primKey, long roleId) throws SystemException {
1829        Object[] finderArgs = new Object[] {
1830                new Long(companyId),
1831                
1832                name, new Integer(scope),
1833                
1834                primKey, new Long(roleId)
1835            };
1836
1837        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
1838                finderArgs, this);
1839
1840        if (count == null) {
1841            Session session = null;
1842
1843            try {
1844                session = openSession();
1845
1846                StringBuilder query = new StringBuilder();
1847
1848                query.append("SELECT COUNT(*) ");
1849                query.append(
1850                    "FROM com.liferay.portal.model.ResourcePermission WHERE ");
1851
1852                query.append("companyId = ?");
1853
1854                query.append(" AND ");
1855
1856                if (name == null) {
1857                    query.append("name IS NULL");
1858                }
1859                else {
1860                    query.append("name = ?");
1861                }
1862
1863                query.append(" AND ");
1864
1865                query.append("scope = ?");
1866
1867                query.append(" AND ");
1868
1869                if (primKey == null) {
1870                    query.append("primKey IS NULL");
1871                }
1872                else {
1873                    query.append("primKey = ?");
1874                }
1875
1876                query.append(" AND ");
1877
1878                query.append("roleId = ?");
1879
1880                query.append(" ");
1881
1882                Query q = session.createQuery(query.toString());
1883
1884                QueryPos qPos = QueryPos.getInstance(q);
1885
1886                qPos.add(companyId);
1887
1888                if (name != null) {
1889                    qPos.add(name);
1890                }
1891
1892                qPos.add(scope);
1893
1894                if (primKey != null) {
1895                    qPos.add(primKey);
1896                }
1897
1898                qPos.add(roleId);
1899
1900                count = (Long)q.uniqueResult();
1901            }
1902            catch (Exception e) {
1903                throw processException(e);
1904            }
1905            finally {
1906                if (count == null) {
1907                    count = Long.valueOf(0);
1908                }
1909
1910                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
1911                    finderArgs, count);
1912
1913                closeSession(session);
1914            }
1915        }
1916
1917        return count.intValue();
1918    }
1919
1920    public int countAll() throws SystemException {
1921        Object[] finderArgs = new Object[0];
1922
1923        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1924                finderArgs, this);
1925
1926        if (count == null) {
1927            Session session = null;
1928
1929            try {
1930                session = openSession();
1931
1932                Query q = session.createQuery(
1933                        "SELECT COUNT(*) FROM com.liferay.portal.model.ResourcePermission");
1934
1935                count = (Long)q.uniqueResult();
1936            }
1937            catch (Exception e) {
1938                throw processException(e);
1939            }
1940            finally {
1941                if (count == null) {
1942                    count = Long.valueOf(0);
1943                }
1944
1945                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1946                    count);
1947
1948                closeSession(session);
1949            }
1950        }
1951
1952        return count.intValue();
1953    }
1954
1955    public void afterPropertiesSet() {
1956        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1957                    com.liferay.portal.util.PropsUtil.get(
1958                        "value.object.listener.com.liferay.portal.model.ResourcePermission")));
1959
1960        if (listenerClassNames.length > 0) {
1961            try {
1962                List<ModelListener<ResourcePermission>> listenersList = new ArrayList<ModelListener<ResourcePermission>>();
1963
1964                for (String listenerClassName : listenerClassNames) {
1965                    listenersList.add((ModelListener<ResourcePermission>)Class.forName(
1966                            listenerClassName).newInstance());
1967                }
1968
1969                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1970            }
1971            catch (Exception e) {
1972                _log.error(e);
1973            }
1974        }
1975    }
1976
1977    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
1978    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1979    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
1980    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1981    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
1982    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1983    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
1984    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1985    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
1986    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1987    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
1988    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1989    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
1990    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1991    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
1992    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1993    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
1994    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1995    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
1996    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1997    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
1998    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1999    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
2000    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
2001    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
2002    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
2003    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
2004    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
2005    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
2006    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
2007    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
2008    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2009    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
2010    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
2011    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
2012    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
2013    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
2014    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
2015    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
2016    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2017    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
2018    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
2019    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
2020    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
2021    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
2022    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
2023    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
2024    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
2025    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
2026    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
2027    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
2028    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
2029    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
2030    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
2031    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
2032    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
2033    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
2034    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
2035    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2036    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2037    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
2038    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
2039    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
2040    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
2041    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
2042    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
2043    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
2044    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
2045    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
2046    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
2047    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
2048    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
2049    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
2050    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
2051    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2052    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2053    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
2054    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
2055    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
2056    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
2057    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
2058    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
2059    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
2060    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
2061    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
2062    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
2063    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
2064    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
2065    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
2066    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
2067    private static Log _log = LogFactoryUtil.getLog(ResourcePermissionPersistenceImpl.class);
2068}