001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchResourcePermissionException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.ResourcePermission;
040    import com.liferay.portal.model.impl.ResourcePermissionImpl;
041    import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the resource permission service.
052     *
053     * <p>
054     * Never modify or reference this class directly. Always use {@link ResourcePermissionUtil} to access the resource permission persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
055     * </p>
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see ResourcePermissionPersistence
063     * @see ResourcePermissionUtil
064     * @generated
065     */
066    public class ResourcePermissionPersistenceImpl extends BasePersistenceImpl<ResourcePermission>
067            implements ResourcePermissionPersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = ResourcePermissionImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
072                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
073                            FINDER_CLASS_NAME_LIST, "findByRoleId",
074                            new String[] {
075                                    Long.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
081                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
082                            FINDER_CLASS_NAME_LIST, "countByRoleId",
083                            new String[] { Long.class.getName() });
084            public static final FinderPath FINDER_PATH_FIND_BY_R_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
085                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
086                            FINDER_CLASS_NAME_LIST, "findByR_S",
087                            new String[] {
088                                    Long.class.getName(), Integer.class.getName(),
089                                    
090                            "java.lang.Integer", "java.lang.Integer",
091                                    "com.liferay.portal.kernel.util.OrderByComparator"
092                            });
093            public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
094                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
095                            FINDER_CLASS_NAME_LIST, "countByR_S",
096                            new String[] { Long.class.getName(), Integer.class.getName() });
097            public static final FinderPath FINDER_PATH_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
098                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
099                            FINDER_CLASS_NAME_LIST, "findByC_N_S",
100                            new String[] {
101                                    Long.class.getName(), String.class.getName(),
102                                    Integer.class.getName(),
103                                    
104                            "java.lang.Integer", "java.lang.Integer",
105                                    "com.liferay.portal.kernel.util.OrderByComparator"
106                            });
107            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
108                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
109                            FINDER_CLASS_NAME_LIST, "countByC_N_S",
110                            new String[] {
111                                    Long.class.getName(), String.class.getName(),
112                                    Integer.class.getName()
113                            });
114            public static final FinderPath FINDER_PATH_FIND_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
115                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "findByC_N_S_P",
117                            new String[] {
118                                    Long.class.getName(), String.class.getName(),
119                                    Integer.class.getName(), String.class.getName(),
120                                    
121                            "java.lang.Integer", "java.lang.Integer",
122                                    "com.liferay.portal.kernel.util.OrderByComparator"
123                            });
124            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
125                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
126                            FINDER_CLASS_NAME_LIST, "countByC_N_S_P",
127                            new String[] {
128                                    Long.class.getName(), String.class.getName(),
129                                    Integer.class.getName(), String.class.getName()
130                            });
131            public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
132                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
133                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N_S_P_R",
134                            new String[] {
135                                    Long.class.getName(), String.class.getName(),
136                                    Integer.class.getName(), String.class.getName(),
137                                    Long.class.getName()
138                            });
139            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
140                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
141                            FINDER_CLASS_NAME_LIST, "countByC_N_S_P_R",
142                            new String[] {
143                                    Long.class.getName(), String.class.getName(),
144                                    Integer.class.getName(), String.class.getName(),
145                                    Long.class.getName()
146                            });
147            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
148                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
149                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
150            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
151                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
152                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
153    
154            /**
155             * Caches the resource permission in the entity cache if it is enabled.
156             *
157             * @param resourcePermission the resource permission to cache
158             */
159            public void cacheResult(ResourcePermission resourcePermission) {
160                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
161                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
162                            resourcePermission);
163    
164                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
165                            new Object[] {
166                                    new Long(resourcePermission.getCompanyId()),
167                                    
168                            resourcePermission.getName(),
169                                    new Integer(resourcePermission.getScope()),
170                                    
171                            resourcePermission.getPrimKey(),
172                                    new Long(resourcePermission.getRoleId())
173                            }, resourcePermission);
174            }
175    
176            /**
177             * Caches the resource permissions in the entity cache if it is enabled.
178             *
179             * @param resourcePermissions the resource permissions to cache
180             */
181            public void cacheResult(List<ResourcePermission> resourcePermissions) {
182                    for (ResourcePermission resourcePermission : resourcePermissions) {
183                            if (EntityCacheUtil.getResult(
184                                                    ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
185                                                    ResourcePermissionImpl.class,
186                                                    resourcePermission.getPrimaryKey(), this) == null) {
187                                    cacheResult(resourcePermission);
188                            }
189                    }
190            }
191    
192            /**
193             * Clears the cache for all resource permissions.
194             *
195             * <p>
196             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
197             * </p>
198             */
199            public void clearCache() {
200                    CacheRegistryUtil.clear(ResourcePermissionImpl.class.getName());
201                    EntityCacheUtil.clearCache(ResourcePermissionImpl.class.getName());
202                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
203                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
204            }
205    
206            /**
207             * Clears the cache for the resource permission.
208             *
209             * <p>
210             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
211             * </p>
212             */
213            public void clearCache(ResourcePermission resourcePermission) {
214                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
215                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
216    
217                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
218                            new Object[] {
219                                    new Long(resourcePermission.getCompanyId()),
220                                    
221                            resourcePermission.getName(),
222                                    new Integer(resourcePermission.getScope()),
223                                    
224                            resourcePermission.getPrimKey(),
225                                    new Long(resourcePermission.getRoleId())
226                            });
227            }
228    
229            /**
230             * Creates a new resource permission with the primary key. Does not add the resource permission to the database.
231             *
232             * @param resourcePermissionId the primary key for the new resource permission
233             * @return the new resource permission
234             */
235            public ResourcePermission create(long resourcePermissionId) {
236                    ResourcePermission resourcePermission = new ResourcePermissionImpl();
237    
238                    resourcePermission.setNew(true);
239                    resourcePermission.setPrimaryKey(resourcePermissionId);
240    
241                    return resourcePermission;
242            }
243    
244            /**
245             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
246             *
247             * @param primaryKey the primary key of the resource permission to remove
248             * @return the resource permission that was removed
249             * @throws com.liferay.portal.NoSuchModelException if a resource permission with the primary key could not be found
250             * @throws SystemException if a system exception occurred
251             */
252            public ResourcePermission remove(Serializable primaryKey)
253                    throws NoSuchModelException, SystemException {
254                    return remove(((Long)primaryKey).longValue());
255            }
256    
257            /**
258             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
259             *
260             * @param resourcePermissionId the primary key of the resource permission to remove
261             * @return the resource permission that was removed
262             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
263             * @throws SystemException if a system exception occurred
264             */
265            public ResourcePermission remove(long resourcePermissionId)
266                    throws NoSuchResourcePermissionException, SystemException {
267                    Session session = null;
268    
269                    try {
270                            session = openSession();
271    
272                            ResourcePermission resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
273                                            new Long(resourcePermissionId));
274    
275                            if (resourcePermission == null) {
276                                    if (_log.isWarnEnabled()) {
277                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
278                                                    resourcePermissionId);
279                                    }
280    
281                                    throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
282                                            resourcePermissionId);
283                            }
284    
285                            return remove(resourcePermission);
286                    }
287                    catch (NoSuchResourcePermissionException nsee) {
288                            throw nsee;
289                    }
290                    catch (Exception e) {
291                            throw processException(e);
292                    }
293                    finally {
294                            closeSession(session);
295                    }
296            }
297    
298            protected ResourcePermission removeImpl(
299                    ResourcePermission resourcePermission) throws SystemException {
300                    resourcePermission = toUnwrappedModel(resourcePermission);
301    
302                    Session session = null;
303    
304                    try {
305                            session = openSession();
306    
307                            BatchSessionUtil.delete(session, resourcePermission);
308                    }
309                    catch (Exception e) {
310                            throw processException(e);
311                    }
312                    finally {
313                            closeSession(session);
314                    }
315    
316                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
317    
318                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
319    
320                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
321                            new Object[] {
322                                    new Long(resourcePermissionModelImpl.getCompanyId()),
323                                    
324                            resourcePermissionModelImpl.getName(),
325                                    new Integer(resourcePermissionModelImpl.getScope()),
326                                    
327                            resourcePermissionModelImpl.getPrimKey(),
328                                    new Long(resourcePermissionModelImpl.getRoleId())
329                            });
330    
331                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
332                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
333    
334                    return resourcePermission;
335            }
336    
337            public ResourcePermission updateImpl(
338                    com.liferay.portal.model.ResourcePermission resourcePermission,
339                    boolean merge) throws SystemException {
340                    resourcePermission = toUnwrappedModel(resourcePermission);
341    
342                    boolean isNew = resourcePermission.isNew();
343    
344                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
345    
346                    Session session = null;
347    
348                    try {
349                            session = openSession();
350    
351                            BatchSessionUtil.update(session, resourcePermission, merge);
352    
353                            resourcePermission.setNew(false);
354                    }
355                    catch (Exception e) {
356                            throw processException(e);
357                    }
358                    finally {
359                            closeSession(session);
360                    }
361    
362                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
363    
364                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
365                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
366                            resourcePermission);
367    
368                    if (!isNew &&
369                                    ((resourcePermission.getCompanyId() != resourcePermissionModelImpl.getOriginalCompanyId()) ||
370                                    !Validator.equals(resourcePermission.getName(),
371                                            resourcePermissionModelImpl.getOriginalName()) ||
372                                    (resourcePermission.getScope() != resourcePermissionModelImpl.getOriginalScope()) ||
373                                    !Validator.equals(resourcePermission.getPrimKey(),
374                                            resourcePermissionModelImpl.getOriginalPrimKey()) ||
375                                    (resourcePermission.getRoleId() != resourcePermissionModelImpl.getOriginalRoleId()))) {
376                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
377                                    new Object[] {
378                                            new Long(resourcePermissionModelImpl.getOriginalCompanyId()),
379                                            
380                                    resourcePermissionModelImpl.getOriginalName(),
381                                            new Integer(resourcePermissionModelImpl.getOriginalScope()),
382                                            
383                                    resourcePermissionModelImpl.getOriginalPrimKey(),
384                                            new Long(resourcePermissionModelImpl.getOriginalRoleId())
385                                    });
386                    }
387    
388                    if (isNew ||
389                                    ((resourcePermission.getCompanyId() != resourcePermissionModelImpl.getOriginalCompanyId()) ||
390                                    !Validator.equals(resourcePermission.getName(),
391                                            resourcePermissionModelImpl.getOriginalName()) ||
392                                    (resourcePermission.getScope() != resourcePermissionModelImpl.getOriginalScope()) ||
393                                    !Validator.equals(resourcePermission.getPrimKey(),
394                                            resourcePermissionModelImpl.getOriginalPrimKey()) ||
395                                    (resourcePermission.getRoleId() != resourcePermissionModelImpl.getOriginalRoleId()))) {
396                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
397                                    new Object[] {
398                                            new Long(resourcePermission.getCompanyId()),
399                                            
400                                    resourcePermission.getName(),
401                                            new Integer(resourcePermission.getScope()),
402                                            
403                                    resourcePermission.getPrimKey(),
404                                            new Long(resourcePermission.getRoleId())
405                                    }, resourcePermission);
406                    }
407    
408                    return resourcePermission;
409            }
410    
411            protected ResourcePermission toUnwrappedModel(
412                    ResourcePermission resourcePermission) {
413                    if (resourcePermission instanceof ResourcePermissionImpl) {
414                            return resourcePermission;
415                    }
416    
417                    ResourcePermissionImpl resourcePermissionImpl = new ResourcePermissionImpl();
418    
419                    resourcePermissionImpl.setNew(resourcePermission.isNew());
420                    resourcePermissionImpl.setPrimaryKey(resourcePermission.getPrimaryKey());
421    
422                    resourcePermissionImpl.setResourcePermissionId(resourcePermission.getResourcePermissionId());
423                    resourcePermissionImpl.setCompanyId(resourcePermission.getCompanyId());
424                    resourcePermissionImpl.setName(resourcePermission.getName());
425                    resourcePermissionImpl.setScope(resourcePermission.getScope());
426                    resourcePermissionImpl.setPrimKey(resourcePermission.getPrimKey());
427                    resourcePermissionImpl.setRoleId(resourcePermission.getRoleId());
428                    resourcePermissionImpl.setActionIds(resourcePermission.getActionIds());
429    
430                    return resourcePermissionImpl;
431            }
432    
433            /**
434             * Finds the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
435             *
436             * @param primaryKey the primary key of the resource permission to find
437             * @return the resource permission
438             * @throws com.liferay.portal.NoSuchModelException if a resource permission with the primary key could not be found
439             * @throws SystemException if a system exception occurred
440             */
441            public ResourcePermission findByPrimaryKey(Serializable primaryKey)
442                    throws NoSuchModelException, SystemException {
443                    return findByPrimaryKey(((Long)primaryKey).longValue());
444            }
445    
446            /**
447             * Finds the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchResourcePermissionException} if it could not be found.
448             *
449             * @param resourcePermissionId the primary key of the resource permission to find
450             * @return the resource permission
451             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
452             * @throws SystemException if a system exception occurred
453             */
454            public ResourcePermission findByPrimaryKey(long resourcePermissionId)
455                    throws NoSuchResourcePermissionException, SystemException {
456                    ResourcePermission resourcePermission = fetchByPrimaryKey(resourcePermissionId);
457    
458                    if (resourcePermission == null) {
459                            if (_log.isWarnEnabled()) {
460                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
461                                            resourcePermissionId);
462                            }
463    
464                            throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
465                                    resourcePermissionId);
466                    }
467    
468                    return resourcePermission;
469            }
470    
471            /**
472             * Finds the resource permission with the primary key or returns <code>null</code> if it could not be found.
473             *
474             * @param primaryKey the primary key of the resource permission to find
475             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
476             * @throws SystemException if a system exception occurred
477             */
478            public ResourcePermission fetchByPrimaryKey(Serializable primaryKey)
479                    throws SystemException {
480                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
481            }
482    
483            /**
484             * Finds the resource permission with the primary key or returns <code>null</code> if it could not be found.
485             *
486             * @param resourcePermissionId the primary key of the resource permission to find
487             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
488             * @throws SystemException if a system exception occurred
489             */
490            public ResourcePermission fetchByPrimaryKey(long resourcePermissionId)
491                    throws SystemException {
492                    ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
493                                    ResourcePermissionImpl.class, resourcePermissionId, this);
494    
495                    if (resourcePermission == null) {
496                            Session session = null;
497    
498                            try {
499                                    session = openSession();
500    
501                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
502                                                    new Long(resourcePermissionId));
503                            }
504                            catch (Exception e) {
505                                    throw processException(e);
506                            }
507                            finally {
508                                    if (resourcePermission != null) {
509                                            cacheResult(resourcePermission);
510                                    }
511    
512                                    closeSession(session);
513                            }
514                    }
515    
516                    return resourcePermission;
517            }
518    
519            /**
520             * Finds all the resource permissions where roleId = &#63;.
521             *
522             * @param roleId the role id to search with
523             * @return the matching resource permissions
524             * @throws SystemException if a system exception occurred
525             */
526            public List<ResourcePermission> findByRoleId(long roleId)
527                    throws SystemException {
528                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
529            }
530    
531            /**
532             * Finds a range of all the resource permissions where roleId = &#63;.
533             *
534             * <p>
535             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
536             * </p>
537             *
538             * @param roleId the role id to search with
539             * @param start the lower bound of the range of resource permissions to return
540             * @param end the upper bound of the range of resource permissions to return (not inclusive)
541             * @return the range of matching resource permissions
542             * @throws SystemException if a system exception occurred
543             */
544            public List<ResourcePermission> findByRoleId(long roleId, int start, int end)
545                    throws SystemException {
546                    return findByRoleId(roleId, start, end, null);
547            }
548    
549            /**
550             * Finds an ordered range of all the resource permissions where roleId = &#63;.
551             *
552             * <p>
553             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
554             * </p>
555             *
556             * @param roleId the role id to search with
557             * @param start the lower bound of the range of resource permissions to return
558             * @param end the upper bound of the range of resource permissions to return (not inclusive)
559             * @param orderByComparator the comparator to order the results by
560             * @return the ordered range of matching resource permissions
561             * @throws SystemException if a system exception occurred
562             */
563            public List<ResourcePermission> findByRoleId(long roleId, int start,
564                    int end, OrderByComparator orderByComparator) throws SystemException {
565                    Object[] finderArgs = new Object[] {
566                                    roleId,
567                                    
568                                    String.valueOf(start), String.valueOf(end),
569                                    String.valueOf(orderByComparator)
570                            };
571    
572                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
573                                    finderArgs, this);
574    
575                    if (list == null) {
576                            StringBundler query = null;
577    
578                            if (orderByComparator != null) {
579                                    query = new StringBundler(3 +
580                                                    (orderByComparator.getOrderByFields().length * 3));
581                            }
582                            else {
583                                    query = new StringBundler(2);
584                            }
585    
586                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
587    
588                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
589    
590                            if (orderByComparator != null) {
591                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
592                                            orderByComparator);
593                            }
594    
595                            String sql = query.toString();
596    
597                            Session session = null;
598    
599                            try {
600                                    session = openSession();
601    
602                                    Query q = session.createQuery(sql);
603    
604                                    QueryPos qPos = QueryPos.getInstance(q);
605    
606                                    qPos.add(roleId);
607    
608                                    list = (List<ResourcePermission>)QueryUtil.list(q,
609                                                    getDialect(), start, end);
610                            }
611                            catch (Exception e) {
612                                    throw processException(e);
613                            }
614                            finally {
615                                    if (list == null) {
616                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_ROLEID,
617                                                    finderArgs);
618                                    }
619                                    else {
620                                            cacheResult(list);
621    
622                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
623                                                    finderArgs, list);
624                                    }
625    
626                                    closeSession(session);
627                            }
628                    }
629    
630                    return list;
631            }
632    
633            /**
634             * Finds the first resource permission in the ordered set where roleId = &#63;.
635             *
636             * <p>
637             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
638             * </p>
639             *
640             * @param roleId the role id to search with
641             * @param orderByComparator the comparator to order the set by
642             * @return the first matching resource permission
643             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public ResourcePermission findByRoleId_First(long roleId,
647                    OrderByComparator orderByComparator)
648                    throws NoSuchResourcePermissionException, SystemException {
649                    List<ResourcePermission> list = findByRoleId(roleId, 0, 1,
650                                    orderByComparator);
651    
652                    if (list.isEmpty()) {
653                            StringBundler msg = new StringBundler(4);
654    
655                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
656    
657                            msg.append("roleId=");
658                            msg.append(roleId);
659    
660                            msg.append(StringPool.CLOSE_CURLY_BRACE);
661    
662                            throw new NoSuchResourcePermissionException(msg.toString());
663                    }
664                    else {
665                            return list.get(0);
666                    }
667            }
668    
669            /**
670             * Finds the last resource permission in the ordered set where roleId = &#63;.
671             *
672             * <p>
673             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
674             * </p>
675             *
676             * @param roleId the role id to search with
677             * @param orderByComparator the comparator to order the set by
678             * @return the last matching resource permission
679             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
680             * @throws SystemException if a system exception occurred
681             */
682            public ResourcePermission findByRoleId_Last(long roleId,
683                    OrderByComparator orderByComparator)
684                    throws NoSuchResourcePermissionException, SystemException {
685                    int count = countByRoleId(roleId);
686    
687                    List<ResourcePermission> list = findByRoleId(roleId, count - 1, count,
688                                    orderByComparator);
689    
690                    if (list.isEmpty()) {
691                            StringBundler msg = new StringBundler(4);
692    
693                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
694    
695                            msg.append("roleId=");
696                            msg.append(roleId);
697    
698                            msg.append(StringPool.CLOSE_CURLY_BRACE);
699    
700                            throw new NoSuchResourcePermissionException(msg.toString());
701                    }
702                    else {
703                            return list.get(0);
704                    }
705            }
706    
707            /**
708             * Finds the resource permissions before and after the current resource permission in the ordered set where roleId = &#63;.
709             *
710             * <p>
711             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
712             * </p>
713             *
714             * @param resourcePermissionId the primary key of the current resource permission
715             * @param roleId the role id to search with
716             * @param orderByComparator the comparator to order the set by
717             * @return the previous, current, and next resource permission
718             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
719             * @throws SystemException if a system exception occurred
720             */
721            public ResourcePermission[] findByRoleId_PrevAndNext(
722                    long resourcePermissionId, long roleId,
723                    OrderByComparator orderByComparator)
724                    throws NoSuchResourcePermissionException, SystemException {
725                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
726    
727                    Session session = null;
728    
729                    try {
730                            session = openSession();
731    
732                            ResourcePermission[] array = new ResourcePermissionImpl[3];
733    
734                            array[0] = getByRoleId_PrevAndNext(session, resourcePermission,
735                                            roleId, orderByComparator, true);
736    
737                            array[1] = resourcePermission;
738    
739                            array[2] = getByRoleId_PrevAndNext(session, resourcePermission,
740                                            roleId, orderByComparator, false);
741    
742                            return array;
743                    }
744                    catch (Exception e) {
745                            throw processException(e);
746                    }
747                    finally {
748                            closeSession(session);
749                    }
750            }
751    
752            protected ResourcePermission getByRoleId_PrevAndNext(Session session,
753                    ResourcePermission resourcePermission, long roleId,
754                    OrderByComparator orderByComparator, boolean previous) {
755                    StringBundler query = null;
756    
757                    if (orderByComparator != null) {
758                            query = new StringBundler(6 +
759                                            (orderByComparator.getOrderByFields().length * 6));
760                    }
761                    else {
762                            query = new StringBundler(3);
763                    }
764    
765                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
766    
767                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
768    
769                    if (orderByComparator != null) {
770                            String[] orderByFields = orderByComparator.getOrderByFields();
771    
772                            if (orderByFields.length > 0) {
773                                    query.append(WHERE_AND);
774                            }
775    
776                            for (int i = 0; i < orderByFields.length; i++) {
777                                    query.append(_ORDER_BY_ENTITY_ALIAS);
778                                    query.append(orderByFields[i]);
779    
780                                    if ((i + 1) < orderByFields.length) {
781                                            if (orderByComparator.isAscending() ^ previous) {
782                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
783                                            }
784                                            else {
785                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
786                                            }
787                                    }
788                                    else {
789                                            if (orderByComparator.isAscending() ^ previous) {
790                                                    query.append(WHERE_GREATER_THAN);
791                                            }
792                                            else {
793                                                    query.append(WHERE_LESSER_THAN);
794                                            }
795                                    }
796                            }
797    
798                            query.append(ORDER_BY_CLAUSE);
799    
800                            for (int i = 0; i < orderByFields.length; i++) {
801                                    query.append(_ORDER_BY_ENTITY_ALIAS);
802                                    query.append(orderByFields[i]);
803    
804                                    if ((i + 1) < orderByFields.length) {
805                                            if (orderByComparator.isAscending() ^ previous) {
806                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
807                                            }
808                                            else {
809                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
810                                            }
811                                    }
812                                    else {
813                                            if (orderByComparator.isAscending() ^ previous) {
814                                                    query.append(ORDER_BY_ASC);
815                                            }
816                                            else {
817                                                    query.append(ORDER_BY_DESC);
818                                            }
819                                    }
820                            }
821                    }
822    
823                    String sql = query.toString();
824    
825                    Query q = session.createQuery(sql);
826    
827                    q.setFirstResult(0);
828                    q.setMaxResults(2);
829    
830                    QueryPos qPos = QueryPos.getInstance(q);
831    
832                    qPos.add(roleId);
833    
834                    if (orderByComparator != null) {
835                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
836    
837                            for (Object value : values) {
838                                    qPos.add(value);
839                            }
840                    }
841    
842                    List<ResourcePermission> list = q.list();
843    
844                    if (list.size() == 2) {
845                            return list.get(1);
846                    }
847                    else {
848                            return null;
849                    }
850            }
851    
852            /**
853             * Finds all the resource permissions where roleId = &#63; and scope = &#63;.
854             *
855             * @param roleId the role id to search with
856             * @param scope the scope to search with
857             * @return the matching resource permissions
858             * @throws SystemException if a system exception occurred
859             */
860            public List<ResourcePermission> findByR_S(long roleId, int scope)
861                    throws SystemException {
862                    return findByR_S(roleId, scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
863                            null);
864            }
865    
866            /**
867             * Finds a range of all the resource permissions where roleId = &#63; and scope = &#63;.
868             *
869             * <p>
870             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
871             * </p>
872             *
873             * @param roleId the role id to search with
874             * @param scope the scope to search with
875             * @param start the lower bound of the range of resource permissions to return
876             * @param end the upper bound of the range of resource permissions to return (not inclusive)
877             * @return the range of matching resource permissions
878             * @throws SystemException if a system exception occurred
879             */
880            public List<ResourcePermission> findByR_S(long roleId, int scope,
881                    int start, int end) throws SystemException {
882                    return findByR_S(roleId, scope, start, end, null);
883            }
884    
885            /**
886             * Finds an ordered range of all the resource permissions where roleId = &#63; and scope = &#63;.
887             *
888             * <p>
889             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
890             * </p>
891             *
892             * @param roleId the role id to search with
893             * @param scope the scope to search with
894             * @param start the lower bound of the range of resource permissions to return
895             * @param end the upper bound of the range of resource permissions to return (not inclusive)
896             * @param orderByComparator the comparator to order the results by
897             * @return the ordered range of matching resource permissions
898             * @throws SystemException if a system exception occurred
899             */
900            public List<ResourcePermission> findByR_S(long roleId, int scope,
901                    int start, int end, OrderByComparator orderByComparator)
902                    throws SystemException {
903                    Object[] finderArgs = new Object[] {
904                                    roleId, scope,
905                                    
906                                    String.valueOf(start), String.valueOf(end),
907                                    String.valueOf(orderByComparator)
908                            };
909    
910                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_S,
911                                    finderArgs, this);
912    
913                    if (list == null) {
914                            StringBundler query = null;
915    
916                            if (orderByComparator != null) {
917                                    query = new StringBundler(4 +
918                                                    (orderByComparator.getOrderByFields().length * 3));
919                            }
920                            else {
921                                    query = new StringBundler(3);
922                            }
923    
924                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
925    
926                            query.append(_FINDER_COLUMN_R_S_ROLEID_2);
927    
928                            query.append(_FINDER_COLUMN_R_S_SCOPE_2);
929    
930                            if (orderByComparator != null) {
931                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
932                                            orderByComparator);
933                            }
934    
935                            String sql = query.toString();
936    
937                            Session session = null;
938    
939                            try {
940                                    session = openSession();
941    
942                                    Query q = session.createQuery(sql);
943    
944                                    QueryPos qPos = QueryPos.getInstance(q);
945    
946                                    qPos.add(roleId);
947    
948                                    qPos.add(scope);
949    
950                                    list = (List<ResourcePermission>)QueryUtil.list(q,
951                                                    getDialect(), start, end);
952                            }
953                            catch (Exception e) {
954                                    throw processException(e);
955                            }
956                            finally {
957                                    if (list == null) {
958                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_R_S,
959                                                    finderArgs);
960                                    }
961                                    else {
962                                            cacheResult(list);
963    
964                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_S,
965                                                    finderArgs, list);
966                                    }
967    
968                                    closeSession(session);
969                            }
970                    }
971    
972                    return list;
973            }
974    
975            /**
976             * Finds the first resource permission in the ordered set where roleId = &#63; and scope = &#63;.
977             *
978             * <p>
979             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
980             * </p>
981             *
982             * @param roleId the role id to search with
983             * @param scope the scope to search with
984             * @param orderByComparator the comparator to order the set by
985             * @return the first matching resource permission
986             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
987             * @throws SystemException if a system exception occurred
988             */
989            public ResourcePermission findByR_S_First(long roleId, int scope,
990                    OrderByComparator orderByComparator)
991                    throws NoSuchResourcePermissionException, SystemException {
992                    List<ResourcePermission> list = findByR_S(roleId, scope, 0, 1,
993                                    orderByComparator);
994    
995                    if (list.isEmpty()) {
996                            StringBundler msg = new StringBundler(6);
997    
998                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
999    
1000                            msg.append("roleId=");
1001                            msg.append(roleId);
1002    
1003                            msg.append(", scope=");
1004                            msg.append(scope);
1005    
1006                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1007    
1008                            throw new NoSuchResourcePermissionException(msg.toString());
1009                    }
1010                    else {
1011                            return list.get(0);
1012                    }
1013            }
1014    
1015            /**
1016             * Finds the last resource permission in the ordered set where roleId = &#63; and scope = &#63;.
1017             *
1018             * <p>
1019             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1020             * </p>
1021             *
1022             * @param roleId the role id to search with
1023             * @param scope the scope to search with
1024             * @param orderByComparator the comparator to order the set by
1025             * @return the last matching resource permission
1026             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1027             * @throws SystemException if a system exception occurred
1028             */
1029            public ResourcePermission findByR_S_Last(long roleId, int scope,
1030                    OrderByComparator orderByComparator)
1031                    throws NoSuchResourcePermissionException, SystemException {
1032                    int count = countByR_S(roleId, scope);
1033    
1034                    List<ResourcePermission> list = findByR_S(roleId, scope, count - 1,
1035                                    count, orderByComparator);
1036    
1037                    if (list.isEmpty()) {
1038                            StringBundler msg = new StringBundler(6);
1039    
1040                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1041    
1042                            msg.append("roleId=");
1043                            msg.append(roleId);
1044    
1045                            msg.append(", scope=");
1046                            msg.append(scope);
1047    
1048                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1049    
1050                            throw new NoSuchResourcePermissionException(msg.toString());
1051                    }
1052                    else {
1053                            return list.get(0);
1054                    }
1055            }
1056    
1057            /**
1058             * Finds the resource permissions before and after the current resource permission in the ordered set where roleId = &#63; and scope = &#63;.
1059             *
1060             * <p>
1061             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1062             * </p>
1063             *
1064             * @param resourcePermissionId the primary key of the current resource permission
1065             * @param roleId the role id to search with
1066             * @param scope the scope to search with
1067             * @param orderByComparator the comparator to order the set by
1068             * @return the previous, current, and next resource permission
1069             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1070             * @throws SystemException if a system exception occurred
1071             */
1072            public ResourcePermission[] findByR_S_PrevAndNext(
1073                    long resourcePermissionId, long roleId, int scope,
1074                    OrderByComparator orderByComparator)
1075                    throws NoSuchResourcePermissionException, SystemException {
1076                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1077    
1078                    Session session = null;
1079    
1080                    try {
1081                            session = openSession();
1082    
1083                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1084    
1085                            array[0] = getByR_S_PrevAndNext(session, resourcePermission,
1086                                            roleId, scope, orderByComparator, true);
1087    
1088                            array[1] = resourcePermission;
1089    
1090                            array[2] = getByR_S_PrevAndNext(session, resourcePermission,
1091                                            roleId, scope, orderByComparator, false);
1092    
1093                            return array;
1094                    }
1095                    catch (Exception e) {
1096                            throw processException(e);
1097                    }
1098                    finally {
1099                            closeSession(session);
1100                    }
1101            }
1102    
1103            protected ResourcePermission getByR_S_PrevAndNext(Session session,
1104                    ResourcePermission resourcePermission, long roleId, int scope,
1105                    OrderByComparator orderByComparator, boolean previous) {
1106                    StringBundler query = null;
1107    
1108                    if (orderByComparator != null) {
1109                            query = new StringBundler(6 +
1110                                            (orderByComparator.getOrderByFields().length * 6));
1111                    }
1112                    else {
1113                            query = new StringBundler(3);
1114                    }
1115    
1116                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1117    
1118                    query.append(_FINDER_COLUMN_R_S_ROLEID_2);
1119    
1120                    query.append(_FINDER_COLUMN_R_S_SCOPE_2);
1121    
1122                    if (orderByComparator != null) {
1123                            String[] orderByFields = orderByComparator.getOrderByFields();
1124    
1125                            if (orderByFields.length > 0) {
1126                                    query.append(WHERE_AND);
1127                            }
1128    
1129                            for (int i = 0; i < orderByFields.length; i++) {
1130                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1131                                    query.append(orderByFields[i]);
1132    
1133                                    if ((i + 1) < orderByFields.length) {
1134                                            if (orderByComparator.isAscending() ^ previous) {
1135                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1136                                            }
1137                                            else {
1138                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1139                                            }
1140                                    }
1141                                    else {
1142                                            if (orderByComparator.isAscending() ^ previous) {
1143                                                    query.append(WHERE_GREATER_THAN);
1144                                            }
1145                                            else {
1146                                                    query.append(WHERE_LESSER_THAN);
1147                                            }
1148                                    }
1149                            }
1150    
1151                            query.append(ORDER_BY_CLAUSE);
1152    
1153                            for (int i = 0; i < orderByFields.length; i++) {
1154                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1155                                    query.append(orderByFields[i]);
1156    
1157                                    if ((i + 1) < orderByFields.length) {
1158                                            if (orderByComparator.isAscending() ^ previous) {
1159                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1160                                            }
1161                                            else {
1162                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1163                                            }
1164                                    }
1165                                    else {
1166                                            if (orderByComparator.isAscending() ^ previous) {
1167                                                    query.append(ORDER_BY_ASC);
1168                                            }
1169                                            else {
1170                                                    query.append(ORDER_BY_DESC);
1171                                            }
1172                                    }
1173                            }
1174                    }
1175    
1176                    String sql = query.toString();
1177    
1178                    Query q = session.createQuery(sql);
1179    
1180                    q.setFirstResult(0);
1181                    q.setMaxResults(2);
1182    
1183                    QueryPos qPos = QueryPos.getInstance(q);
1184    
1185                    qPos.add(roleId);
1186    
1187                    qPos.add(scope);
1188    
1189                    if (orderByComparator != null) {
1190                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
1191    
1192                            for (Object value : values) {
1193                                    qPos.add(value);
1194                            }
1195                    }
1196    
1197                    List<ResourcePermission> list = q.list();
1198    
1199                    if (list.size() == 2) {
1200                            return list.get(1);
1201                    }
1202                    else {
1203                            return null;
1204                    }
1205            }
1206    
1207            /**
1208             * Finds all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1209             *
1210             * @param companyId the company id to search with
1211             * @param name the name to search with
1212             * @param scope the scope to search with
1213             * @return the matching resource permissions
1214             * @throws SystemException if a system exception occurred
1215             */
1216            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1217                    int scope) throws SystemException {
1218                    return findByC_N_S(companyId, name, scope, QueryUtil.ALL_POS,
1219                            QueryUtil.ALL_POS, null);
1220            }
1221    
1222            /**
1223             * Finds a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1224             *
1225             * <p>
1226             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1227             * </p>
1228             *
1229             * @param companyId the company id to search with
1230             * @param name the name to search with
1231             * @param scope the scope to search with
1232             * @param start the lower bound of the range of resource permissions to return
1233             * @param end the upper bound of the range of resource permissions to return (not inclusive)
1234             * @return the range of matching resource permissions
1235             * @throws SystemException if a system exception occurred
1236             */
1237            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1238                    int scope, int start, int end) throws SystemException {
1239                    return findByC_N_S(companyId, name, scope, start, end, null);
1240            }
1241    
1242            /**
1243             * Finds an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1244             *
1245             * <p>
1246             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1247             * </p>
1248             *
1249             * @param companyId the company id to search with
1250             * @param name the name to search with
1251             * @param scope the scope to search with
1252             * @param start the lower bound of the range of resource permissions to return
1253             * @param end the upper bound of the range of resource permissions to return (not inclusive)
1254             * @param orderByComparator the comparator to order the results by
1255             * @return the ordered range of matching resource permissions
1256             * @throws SystemException if a system exception occurred
1257             */
1258            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1259                    int scope, int start, int end, OrderByComparator orderByComparator)
1260                    throws SystemException {
1261                    Object[] finderArgs = new Object[] {
1262                                    companyId, name, scope,
1263                                    
1264                                    String.valueOf(start), String.valueOf(end),
1265                                    String.valueOf(orderByComparator)
1266                            };
1267    
1268                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_N_S,
1269                                    finderArgs, this);
1270    
1271                    if (list == null) {
1272                            StringBundler query = null;
1273    
1274                            if (orderByComparator != null) {
1275                                    query = new StringBundler(5 +
1276                                                    (orderByComparator.getOrderByFields().length * 3));
1277                            }
1278                            else {
1279                                    query = new StringBundler(4);
1280                            }
1281    
1282                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1283    
1284                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1285    
1286                            if (name == null) {
1287                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1288                            }
1289                            else {
1290                                    if (name.equals(StringPool.BLANK)) {
1291                                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1292                                    }
1293                                    else {
1294                                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1295                                    }
1296                            }
1297    
1298                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1299    
1300                            if (orderByComparator != null) {
1301                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1302                                            orderByComparator);
1303                            }
1304    
1305                            String sql = query.toString();
1306    
1307                            Session session = null;
1308    
1309                            try {
1310                                    session = openSession();
1311    
1312                                    Query q = session.createQuery(sql);
1313    
1314                                    QueryPos qPos = QueryPos.getInstance(q);
1315    
1316                                    qPos.add(companyId);
1317    
1318                                    if (name != null) {
1319                                            qPos.add(name);
1320                                    }
1321    
1322                                    qPos.add(scope);
1323    
1324                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1325                                                    getDialect(), start, end);
1326                            }
1327                            catch (Exception e) {
1328                                    throw processException(e);
1329                            }
1330                            finally {
1331                                    if (list == null) {
1332                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_N_S,
1333                                                    finderArgs);
1334                                    }
1335                                    else {
1336                                            cacheResult(list);
1337    
1338                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_N_S,
1339                                                    finderArgs, list);
1340                                    }
1341    
1342                                    closeSession(session);
1343                            }
1344                    }
1345    
1346                    return list;
1347            }
1348    
1349            /**
1350             * Finds the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
1351             *
1352             * <p>
1353             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1354             * </p>
1355             *
1356             * @param companyId the company id to search with
1357             * @param name the name to search with
1358             * @param scope the scope to search with
1359             * @param orderByComparator the comparator to order the set by
1360             * @return the first matching resource permission
1361             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1362             * @throws SystemException if a system exception occurred
1363             */
1364            public ResourcePermission findByC_N_S_First(long companyId, String name,
1365                    int scope, OrderByComparator orderByComparator)
1366                    throws NoSuchResourcePermissionException, SystemException {
1367                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope, 0,
1368                                    1, orderByComparator);
1369    
1370                    if (list.isEmpty()) {
1371                            StringBundler msg = new StringBundler(8);
1372    
1373                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1374    
1375                            msg.append("companyId=");
1376                            msg.append(companyId);
1377    
1378                            msg.append(", name=");
1379                            msg.append(name);
1380    
1381                            msg.append(", scope=");
1382                            msg.append(scope);
1383    
1384                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1385    
1386                            throw new NoSuchResourcePermissionException(msg.toString());
1387                    }
1388                    else {
1389                            return list.get(0);
1390                    }
1391            }
1392    
1393            /**
1394             * Finds the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
1395             *
1396             * <p>
1397             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1398             * </p>
1399             *
1400             * @param companyId the company id to search with
1401             * @param name the name to search with
1402             * @param scope the scope to search with
1403             * @param orderByComparator the comparator to order the set by
1404             * @return the last matching resource permission
1405             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1406             * @throws SystemException if a system exception occurred
1407             */
1408            public ResourcePermission findByC_N_S_Last(long companyId, String name,
1409                    int scope, OrderByComparator orderByComparator)
1410                    throws NoSuchResourcePermissionException, SystemException {
1411                    int count = countByC_N_S(companyId, name, scope);
1412    
1413                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope,
1414                                    count - 1, count, orderByComparator);
1415    
1416                    if (list.isEmpty()) {
1417                            StringBundler msg = new StringBundler(8);
1418    
1419                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1420    
1421                            msg.append("companyId=");
1422                            msg.append(companyId);
1423    
1424                            msg.append(", name=");
1425                            msg.append(name);
1426    
1427                            msg.append(", scope=");
1428                            msg.append(scope);
1429    
1430                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1431    
1432                            throw new NoSuchResourcePermissionException(msg.toString());
1433                    }
1434                    else {
1435                            return list.get(0);
1436                    }
1437            }
1438    
1439            /**
1440             * Finds the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
1441             *
1442             * <p>
1443             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1444             * </p>
1445             *
1446             * @param resourcePermissionId the primary key of the current resource permission
1447             * @param companyId the company id to search with
1448             * @param name the name to search with
1449             * @param scope the scope to search with
1450             * @param orderByComparator the comparator to order the set by
1451             * @return the previous, current, and next resource permission
1452             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1453             * @throws SystemException if a system exception occurred
1454             */
1455            public ResourcePermission[] findByC_N_S_PrevAndNext(
1456                    long resourcePermissionId, long companyId, String name, int scope,
1457                    OrderByComparator orderByComparator)
1458                    throws NoSuchResourcePermissionException, SystemException {
1459                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1460    
1461                    Session session = null;
1462    
1463                    try {
1464                            session = openSession();
1465    
1466                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1467    
1468                            array[0] = getByC_N_S_PrevAndNext(session, resourcePermission,
1469                                            companyId, name, scope, orderByComparator, true);
1470    
1471                            array[1] = resourcePermission;
1472    
1473                            array[2] = getByC_N_S_PrevAndNext(session, resourcePermission,
1474                                            companyId, name, scope, orderByComparator, false);
1475    
1476                            return array;
1477                    }
1478                    catch (Exception e) {
1479                            throw processException(e);
1480                    }
1481                    finally {
1482                            closeSession(session);
1483                    }
1484            }
1485    
1486            protected ResourcePermission getByC_N_S_PrevAndNext(Session session,
1487                    ResourcePermission resourcePermission, long companyId, String name,
1488                    int scope, OrderByComparator orderByComparator, boolean previous) {
1489                    StringBundler query = null;
1490    
1491                    if (orderByComparator != null) {
1492                            query = new StringBundler(6 +
1493                                            (orderByComparator.getOrderByFields().length * 6));
1494                    }
1495                    else {
1496                            query = new StringBundler(3);
1497                    }
1498    
1499                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1500    
1501                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1502    
1503                    if (name == null) {
1504                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1505                    }
1506                    else {
1507                            if (name.equals(StringPool.BLANK)) {
1508                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1509                            }
1510                            else {
1511                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1512                            }
1513                    }
1514    
1515                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1516    
1517                    if (orderByComparator != null) {
1518                            String[] orderByFields = orderByComparator.getOrderByFields();
1519    
1520                            if (orderByFields.length > 0) {
1521                                    query.append(WHERE_AND);
1522                            }
1523    
1524                            for (int i = 0; i < orderByFields.length; i++) {
1525                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1526                                    query.append(orderByFields[i]);
1527    
1528                                    if ((i + 1) < orderByFields.length) {
1529                                            if (orderByComparator.isAscending() ^ previous) {
1530                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1531                                            }
1532                                            else {
1533                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1534                                            }
1535                                    }
1536                                    else {
1537                                            if (orderByComparator.isAscending() ^ previous) {
1538                                                    query.append(WHERE_GREATER_THAN);
1539                                            }
1540                                            else {
1541                                                    query.append(WHERE_LESSER_THAN);
1542                                            }
1543                                    }
1544                            }
1545    
1546                            query.append(ORDER_BY_CLAUSE);
1547    
1548                            for (int i = 0; i < orderByFields.length; i++) {
1549                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1550                                    query.append(orderByFields[i]);
1551    
1552                                    if ((i + 1) < orderByFields.length) {
1553                                            if (orderByComparator.isAscending() ^ previous) {
1554                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1555                                            }
1556                                            else {
1557                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1558                                            }
1559                                    }
1560                                    else {
1561                                            if (orderByComparator.isAscending() ^ previous) {
1562                                                    query.append(ORDER_BY_ASC);
1563                                            }
1564                                            else {
1565                                                    query.append(ORDER_BY_DESC);
1566                                            }
1567                                    }
1568                            }
1569                    }
1570    
1571                    String sql = query.toString();
1572    
1573                    Query q = session.createQuery(sql);
1574    
1575                    q.setFirstResult(0);
1576                    q.setMaxResults(2);
1577    
1578                    QueryPos qPos = QueryPos.getInstance(q);
1579    
1580                    qPos.add(companyId);
1581    
1582                    if (name != null) {
1583                            qPos.add(name);
1584                    }
1585    
1586                    qPos.add(scope);
1587    
1588                    if (orderByComparator != null) {
1589                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
1590    
1591                            for (Object value : values) {
1592                                    qPos.add(value);
1593                            }
1594                    }
1595    
1596                    List<ResourcePermission> list = q.list();
1597    
1598                    if (list.size() == 2) {
1599                            return list.get(1);
1600                    }
1601                    else {
1602                            return null;
1603                    }
1604            }
1605    
1606            /**
1607             * Finds all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
1608             *
1609             * @param companyId the company id to search with
1610             * @param name the name to search with
1611             * @param scope the scope to search with
1612             * @param primKey the prim key to search with
1613             * @return the matching resource permissions
1614             * @throws SystemException if a system exception occurred
1615             */
1616            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1617                    int scope, String primKey) throws SystemException {
1618                    return findByC_N_S_P(companyId, name, scope, primKey,
1619                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1620            }
1621    
1622            /**
1623             * Finds a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
1624             *
1625             * <p>
1626             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1627             * </p>
1628             *
1629             * @param companyId the company id to search with
1630             * @param name the name to search with
1631             * @param scope the scope to search with
1632             * @param primKey the prim key to search with
1633             * @param start the lower bound of the range of resource permissions to return
1634             * @param end the upper bound of the range of resource permissions to return (not inclusive)
1635             * @return the range of matching resource permissions
1636             * @throws SystemException if a system exception occurred
1637             */
1638            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1639                    int scope, String primKey, int start, int end)
1640                    throws SystemException {
1641                    return findByC_N_S_P(companyId, name, scope, primKey, start, end, null);
1642            }
1643    
1644            /**
1645             * Finds an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
1646             *
1647             * <p>
1648             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1649             * </p>
1650             *
1651             * @param companyId the company id to search with
1652             * @param name the name to search with
1653             * @param scope the scope to search with
1654             * @param primKey the prim key to search with
1655             * @param start the lower bound of the range of resource permissions to return
1656             * @param end the upper bound of the range of resource permissions to return (not inclusive)
1657             * @param orderByComparator the comparator to order the results by
1658             * @return the ordered range of matching resource permissions
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1662                    int scope, String primKey, int start, int end,
1663                    OrderByComparator orderByComparator) throws SystemException {
1664                    Object[] finderArgs = new Object[] {
1665                                    companyId, name, scope, primKey,
1666                                    
1667                                    String.valueOf(start), String.valueOf(end),
1668                                    String.valueOf(orderByComparator)
1669                            };
1670    
1671                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_N_S_P,
1672                                    finderArgs, this);
1673    
1674                    if (list == null) {
1675                            StringBundler query = null;
1676    
1677                            if (orderByComparator != null) {
1678                                    query = new StringBundler(6 +
1679                                                    (orderByComparator.getOrderByFields().length * 3));
1680                            }
1681                            else {
1682                                    query = new StringBundler(5);
1683                            }
1684    
1685                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1686    
1687                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
1688    
1689                            if (name == null) {
1690                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
1691                            }
1692                            else {
1693                                    if (name.equals(StringPool.BLANK)) {
1694                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
1695                                    }
1696                                    else {
1697                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
1698                                    }
1699                            }
1700    
1701                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
1702    
1703                            if (primKey == null) {
1704                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
1705                            }
1706                            else {
1707                                    if (primKey.equals(StringPool.BLANK)) {
1708                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
1709                                    }
1710                                    else {
1711                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
1712                                    }
1713                            }
1714    
1715                            if (orderByComparator != null) {
1716                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1717                                            orderByComparator);
1718                            }
1719    
1720                            String sql = query.toString();
1721    
1722                            Session session = null;
1723    
1724                            try {
1725                                    session = openSession();
1726    
1727                                    Query q = session.createQuery(sql);
1728    
1729                                    QueryPos qPos = QueryPos.getInstance(q);
1730    
1731                                    qPos.add(companyId);
1732    
1733                                    if (name != null) {
1734                                            qPos.add(name);
1735                                    }
1736    
1737                                    qPos.add(scope);
1738    
1739                                    if (primKey != null) {
1740                                            qPos.add(primKey);
1741                                    }
1742    
1743                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1744                                                    getDialect(), start, end);
1745                            }
1746                            catch (Exception e) {
1747                                    throw processException(e);
1748                            }
1749                            finally {
1750                                    if (list == null) {
1751                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_C_N_S_P,
1752                                                    finderArgs);
1753                                    }
1754                                    else {
1755                                            cacheResult(list);
1756    
1757                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_N_S_P,
1758                                                    finderArgs, list);
1759                                    }
1760    
1761                                    closeSession(session);
1762                            }
1763                    }
1764    
1765                    return list;
1766            }
1767    
1768            /**
1769             * Finds the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
1770             *
1771             * <p>
1772             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1773             * </p>
1774             *
1775             * @param companyId the company id to search with
1776             * @param name the name to search with
1777             * @param scope the scope to search with
1778             * @param primKey the prim key to search with
1779             * @param orderByComparator the comparator to order the set by
1780             * @return the first matching resource permission
1781             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1782             * @throws SystemException if a system exception occurred
1783             */
1784            public ResourcePermission findByC_N_S_P_First(long companyId, String name,
1785                    int scope, String primKey, OrderByComparator orderByComparator)
1786                    throws NoSuchResourcePermissionException, SystemException {
1787                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
1788                                    primKey, 0, 1, orderByComparator);
1789    
1790                    if (list.isEmpty()) {
1791                            StringBundler msg = new StringBundler(10);
1792    
1793                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1794    
1795                            msg.append("companyId=");
1796                            msg.append(companyId);
1797    
1798                            msg.append(", name=");
1799                            msg.append(name);
1800    
1801                            msg.append(", scope=");
1802                            msg.append(scope);
1803    
1804                            msg.append(", primKey=");
1805                            msg.append(primKey);
1806    
1807                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1808    
1809                            throw new NoSuchResourcePermissionException(msg.toString());
1810                    }
1811                    else {
1812                            return list.get(0);
1813                    }
1814            }
1815    
1816            /**
1817             * Finds the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
1818             *
1819             * <p>
1820             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1821             * </p>
1822             *
1823             * @param companyId the company id to search with
1824             * @param name the name to search with
1825             * @param scope the scope to search with
1826             * @param primKey the prim key to search with
1827             * @param orderByComparator the comparator to order the set by
1828             * @return the last matching resource permission
1829             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1830             * @throws SystemException if a system exception occurred
1831             */
1832            public ResourcePermission findByC_N_S_P_Last(long companyId, String name,
1833                    int scope, String primKey, OrderByComparator orderByComparator)
1834                    throws NoSuchResourcePermissionException, SystemException {
1835                    int count = countByC_N_S_P(companyId, name, scope, primKey);
1836    
1837                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
1838                                    primKey, count - 1, count, orderByComparator);
1839    
1840                    if (list.isEmpty()) {
1841                            StringBundler msg = new StringBundler(10);
1842    
1843                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1844    
1845                            msg.append("companyId=");
1846                            msg.append(companyId);
1847    
1848                            msg.append(", name=");
1849                            msg.append(name);
1850    
1851                            msg.append(", scope=");
1852                            msg.append(scope);
1853    
1854                            msg.append(", primKey=");
1855                            msg.append(primKey);
1856    
1857                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1858    
1859                            throw new NoSuchResourcePermissionException(msg.toString());
1860                    }
1861                    else {
1862                            return list.get(0);
1863                    }
1864            }
1865    
1866            /**
1867             * Finds the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
1868             *
1869             * <p>
1870             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1871             * </p>
1872             *
1873             * @param resourcePermissionId the primary key of the current resource permission
1874             * @param companyId the company id to search with
1875             * @param name the name to search with
1876             * @param scope the scope to search with
1877             * @param primKey the prim key to search with
1878             * @param orderByComparator the comparator to order the set by
1879             * @return the previous, current, and next resource permission
1880             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1881             * @throws SystemException if a system exception occurred
1882             */
1883            public ResourcePermission[] findByC_N_S_P_PrevAndNext(
1884                    long resourcePermissionId, long companyId, String name, int scope,
1885                    String primKey, OrderByComparator orderByComparator)
1886                    throws NoSuchResourcePermissionException, SystemException {
1887                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1888    
1889                    Session session = null;
1890    
1891                    try {
1892                            session = openSession();
1893    
1894                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1895    
1896                            array[0] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
1897                                            companyId, name, scope, primKey, orderByComparator, true);
1898    
1899                            array[1] = resourcePermission;
1900    
1901                            array[2] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
1902                                            companyId, name, scope, primKey, orderByComparator, false);
1903    
1904                            return array;
1905                    }
1906                    catch (Exception e) {
1907                            throw processException(e);
1908                    }
1909                    finally {
1910                            closeSession(session);
1911                    }
1912            }
1913    
1914            protected ResourcePermission getByC_N_S_P_PrevAndNext(Session session,
1915                    ResourcePermission resourcePermission, long companyId, String name,
1916                    int scope, String primKey, OrderByComparator orderByComparator,
1917                    boolean previous) {
1918                    StringBundler query = null;
1919    
1920                    if (orderByComparator != null) {
1921                            query = new StringBundler(6 +
1922                                            (orderByComparator.getOrderByFields().length * 6));
1923                    }
1924                    else {
1925                            query = new StringBundler(3);
1926                    }
1927    
1928                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1929    
1930                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
1931    
1932                    if (name == null) {
1933                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
1934                    }
1935                    else {
1936                            if (name.equals(StringPool.BLANK)) {
1937                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
1938                            }
1939                            else {
1940                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
1941                            }
1942                    }
1943    
1944                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
1945    
1946                    if (primKey == null) {
1947                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
1948                    }
1949                    else {
1950                            if (primKey.equals(StringPool.BLANK)) {
1951                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
1952                            }
1953                            else {
1954                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
1955                            }
1956                    }
1957    
1958                    if (orderByComparator != null) {
1959                            String[] orderByFields = orderByComparator.getOrderByFields();
1960    
1961                            if (orderByFields.length > 0) {
1962                                    query.append(WHERE_AND);
1963                            }
1964    
1965                            for (int i = 0; i < orderByFields.length; i++) {
1966                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1967                                    query.append(orderByFields[i]);
1968    
1969                                    if ((i + 1) < orderByFields.length) {
1970                                            if (orderByComparator.isAscending() ^ previous) {
1971                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1972                                            }
1973                                            else {
1974                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1975                                            }
1976                                    }
1977                                    else {
1978                                            if (orderByComparator.isAscending() ^ previous) {
1979                                                    query.append(WHERE_GREATER_THAN);
1980                                            }
1981                                            else {
1982                                                    query.append(WHERE_LESSER_THAN);
1983                                            }
1984                                    }
1985                            }
1986    
1987                            query.append(ORDER_BY_CLAUSE);
1988    
1989                            for (int i = 0; i < orderByFields.length; i++) {
1990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1991                                    query.append(orderByFields[i]);
1992    
1993                                    if ((i + 1) < orderByFields.length) {
1994                                            if (orderByComparator.isAscending() ^ previous) {
1995                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1996                                            }
1997                                            else {
1998                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1999                                            }
2000                                    }
2001                                    else {
2002                                            if (orderByComparator.isAscending() ^ previous) {
2003                                                    query.append(ORDER_BY_ASC);
2004                                            }
2005                                            else {
2006                                                    query.append(ORDER_BY_DESC);
2007                                            }
2008                                    }
2009                            }
2010                    }
2011    
2012                    String sql = query.toString();
2013    
2014                    Query q = session.createQuery(sql);
2015    
2016                    q.setFirstResult(0);
2017                    q.setMaxResults(2);
2018    
2019                    QueryPos qPos = QueryPos.getInstance(q);
2020    
2021                    qPos.add(companyId);
2022    
2023                    if (name != null) {
2024                            qPos.add(name);
2025                    }
2026    
2027                    qPos.add(scope);
2028    
2029                    if (primKey != null) {
2030                            qPos.add(primKey);
2031                    }
2032    
2033                    if (orderByComparator != null) {
2034                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
2035    
2036                            for (Object value : values) {
2037                                    qPos.add(value);
2038                            }
2039                    }
2040    
2041                    List<ResourcePermission> list = q.list();
2042    
2043                    if (list.size() == 2) {
2044                            return list.get(1);
2045                    }
2046                    else {
2047                            return null;
2048                    }
2049            }
2050    
2051            /**
2052             * Finds the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; or throws a {@link com.liferay.portal.NoSuchResourcePermissionException} if it could not be found.
2053             *
2054             * @param companyId the company id to search with
2055             * @param name the name to search with
2056             * @param scope the scope to search with
2057             * @param primKey the prim key to search with
2058             * @param roleId the role id to search with
2059             * @return the matching resource permission
2060             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2061             * @throws SystemException if a system exception occurred
2062             */
2063            public ResourcePermission findByC_N_S_P_R(long companyId, String name,
2064                    int scope, String primKey, long roleId)
2065                    throws NoSuchResourcePermissionException, SystemException {
2066                    ResourcePermission resourcePermission = fetchByC_N_S_P_R(companyId,
2067                                    name, scope, primKey, roleId);
2068    
2069                    if (resourcePermission == null) {
2070                            StringBundler msg = new StringBundler(12);
2071    
2072                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2073    
2074                            msg.append("companyId=");
2075                            msg.append(companyId);
2076    
2077                            msg.append(", name=");
2078                            msg.append(name);
2079    
2080                            msg.append(", scope=");
2081                            msg.append(scope);
2082    
2083                            msg.append(", primKey=");
2084                            msg.append(primKey);
2085    
2086                            msg.append(", roleId=");
2087                            msg.append(roleId);
2088    
2089                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2090    
2091                            if (_log.isWarnEnabled()) {
2092                                    _log.warn(msg.toString());
2093                            }
2094    
2095                            throw new NoSuchResourcePermissionException(msg.toString());
2096                    }
2097    
2098                    return resourcePermission;
2099            }
2100    
2101            /**
2102             * Finds the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2103             *
2104             * @param companyId the company id to search with
2105             * @param name the name to search with
2106             * @param scope the scope to search with
2107             * @param primKey the prim key to search with
2108             * @param roleId the role id to search with
2109             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
2110             * @throws SystemException if a system exception occurred
2111             */
2112            public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
2113                    int scope, String primKey, long roleId) throws SystemException {
2114                    return fetchByC_N_S_P_R(companyId, name, scope, primKey, roleId, true);
2115            }
2116    
2117            /**
2118             * Finds the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2119             *
2120             * @param companyId the company id to search with
2121             * @param name the name to search with
2122             * @param scope the scope to search with
2123             * @param primKey the prim key to search with
2124             * @param roleId the role id to search with
2125             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
2126             * @throws SystemException if a system exception occurred
2127             */
2128            public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
2129                    int scope, String primKey, long roleId, boolean retrieveFromCache)
2130                    throws SystemException {
2131                    Object[] finderArgs = new Object[] {
2132                                    companyId, name, scope, primKey, roleId
2133                            };
2134    
2135                    Object result = null;
2136    
2137                    if (retrieveFromCache) {
2138                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
2139                                            finderArgs, this);
2140                    }
2141    
2142                    if (result == null) {
2143                            StringBundler query = new StringBundler(6);
2144    
2145                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2146    
2147                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
2148    
2149                            if (name == null) {
2150                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
2151                            }
2152                            else {
2153                                    if (name.equals(StringPool.BLANK)) {
2154                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
2155                                    }
2156                                    else {
2157                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
2158                                    }
2159                            }
2160    
2161                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
2162    
2163                            if (primKey == null) {
2164                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
2165                            }
2166                            else {
2167                                    if (primKey.equals(StringPool.BLANK)) {
2168                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
2169                                    }
2170                                    else {
2171                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
2172                                    }
2173                            }
2174    
2175                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
2176    
2177                            String sql = query.toString();
2178    
2179                            Session session = null;
2180    
2181                            try {
2182                                    session = openSession();
2183    
2184                                    Query q = session.createQuery(sql);
2185    
2186                                    QueryPos qPos = QueryPos.getInstance(q);
2187    
2188                                    qPos.add(companyId);
2189    
2190                                    if (name != null) {
2191                                            qPos.add(name);
2192                                    }
2193    
2194                                    qPos.add(scope);
2195    
2196                                    if (primKey != null) {
2197                                            qPos.add(primKey);
2198                                    }
2199    
2200                                    qPos.add(roleId);
2201    
2202                                    List<ResourcePermission> list = q.list();
2203    
2204                                    result = list;
2205    
2206                                    ResourcePermission resourcePermission = null;
2207    
2208                                    if (list.isEmpty()) {
2209                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
2210                                                    finderArgs, list);
2211                                    }
2212                                    else {
2213                                            resourcePermission = list.get(0);
2214    
2215                                            cacheResult(resourcePermission);
2216    
2217                                            if ((resourcePermission.getCompanyId() != companyId) ||
2218                                                            (resourcePermission.getName() == null) ||
2219                                                            !resourcePermission.getName().equals(name) ||
2220                                                            (resourcePermission.getScope() != scope) ||
2221                                                            (resourcePermission.getPrimKey() == null) ||
2222                                                            !resourcePermission.getPrimKey().equals(primKey) ||
2223                                                            (resourcePermission.getRoleId() != roleId)) {
2224                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
2225                                                            finderArgs, resourcePermission);
2226                                            }
2227                                    }
2228    
2229                                    return resourcePermission;
2230                            }
2231                            catch (Exception e) {
2232                                    throw processException(e);
2233                            }
2234                            finally {
2235                                    if (result == null) {
2236                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
2237                                                    finderArgs);
2238                                    }
2239    
2240                                    closeSession(session);
2241                            }
2242                    }
2243                    else {
2244                            if (result instanceof List<?>) {
2245                                    return null;
2246                            }
2247                            else {
2248                                    return (ResourcePermission)result;
2249                            }
2250                    }
2251            }
2252    
2253            /**
2254             * Finds all the resource permissions.
2255             *
2256             * @return the resource permissions
2257             * @throws SystemException if a system exception occurred
2258             */
2259            public List<ResourcePermission> findAll() throws SystemException {
2260                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2261            }
2262    
2263            /**
2264             * Finds a range of all the resource permissions.
2265             *
2266             * <p>
2267             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2268             * </p>
2269             *
2270             * @param start the lower bound of the range of resource permissions to return
2271             * @param end the upper bound of the range of resource permissions to return (not inclusive)
2272             * @return the range of resource permissions
2273             * @throws SystemException if a system exception occurred
2274             */
2275            public List<ResourcePermission> findAll(int start, int end)
2276                    throws SystemException {
2277                    return findAll(start, end, null);
2278            }
2279    
2280            /**
2281             * Finds an ordered range of all the resource permissions.
2282             *
2283             * <p>
2284             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2285             * </p>
2286             *
2287             * @param start the lower bound of the range of resource permissions to return
2288             * @param end the upper bound of the range of resource permissions to return (not inclusive)
2289             * @param orderByComparator the comparator to order the results by
2290             * @return the ordered range of resource permissions
2291             * @throws SystemException if a system exception occurred
2292             */
2293            public List<ResourcePermission> findAll(int start, int end,
2294                    OrderByComparator orderByComparator) throws SystemException {
2295                    Object[] finderArgs = new Object[] {
2296                                    String.valueOf(start), String.valueOf(end),
2297                                    String.valueOf(orderByComparator)
2298                            };
2299    
2300                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2301                                    finderArgs, this);
2302    
2303                    if (list == null) {
2304                            StringBundler query = null;
2305                            String sql = null;
2306    
2307                            if (orderByComparator != null) {
2308                                    query = new StringBundler(2 +
2309                                                    (orderByComparator.getOrderByFields().length * 3));
2310    
2311                                    query.append(_SQL_SELECT_RESOURCEPERMISSION);
2312    
2313                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2314                                            orderByComparator);
2315    
2316                                    sql = query.toString();
2317                            }
2318                            else {
2319                                    sql = _SQL_SELECT_RESOURCEPERMISSION;
2320                            }
2321    
2322                            Session session = null;
2323    
2324                            try {
2325                                    session = openSession();
2326    
2327                                    Query q = session.createQuery(sql);
2328    
2329                                    if (orderByComparator == null) {
2330                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2331                                                            getDialect(), start, end, false);
2332    
2333                                            Collections.sort(list);
2334                                    }
2335                                    else {
2336                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2337                                                            getDialect(), start, end);
2338                                    }
2339                            }
2340                            catch (Exception e) {
2341                                    throw processException(e);
2342                            }
2343                            finally {
2344                                    if (list == null) {
2345                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
2346                                                    finderArgs);
2347                                    }
2348                                    else {
2349                                            cacheResult(list);
2350    
2351                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
2352                                                    list);
2353                                    }
2354    
2355                                    closeSession(session);
2356                            }
2357                    }
2358    
2359                    return list;
2360            }
2361    
2362            /**
2363             * Removes all the resource permissions where roleId = &#63; from the database.
2364             *
2365             * @param roleId the role id to search with
2366             * @throws SystemException if a system exception occurred
2367             */
2368            public void removeByRoleId(long roleId) throws SystemException {
2369                    for (ResourcePermission resourcePermission : findByRoleId(roleId)) {
2370                            remove(resourcePermission);
2371                    }
2372            }
2373    
2374            /**
2375             * Removes all the resource permissions where roleId = &#63; and scope = &#63; from the database.
2376             *
2377             * @param roleId the role id to search with
2378             * @param scope the scope to search with
2379             * @throws SystemException if a system exception occurred
2380             */
2381            public void removeByR_S(long roleId, int scope) throws SystemException {
2382                    for (ResourcePermission resourcePermission : findByR_S(roleId, scope)) {
2383                            remove(resourcePermission);
2384                    }
2385            }
2386    
2387            /**
2388             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; from the database.
2389             *
2390             * @param companyId the company id to search with
2391             * @param name the name to search with
2392             * @param scope the scope to search with
2393             * @throws SystemException if a system exception occurred
2394             */
2395            public void removeByC_N_S(long companyId, String name, int scope)
2396                    throws SystemException {
2397                    for (ResourcePermission resourcePermission : findByC_N_S(companyId,
2398                                    name, scope)) {
2399                            remove(resourcePermission);
2400                    }
2401            }
2402    
2403            /**
2404             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; from the database.
2405             *
2406             * @param companyId the company id to search with
2407             * @param name the name to search with
2408             * @param scope the scope to search with
2409             * @param primKey the prim key to search with
2410             * @throws SystemException if a system exception occurred
2411             */
2412            public void removeByC_N_S_P(long companyId, String name, int scope,
2413                    String primKey) throws SystemException {
2414                    for (ResourcePermission resourcePermission : findByC_N_S_P(companyId,
2415                                    name, scope, primKey)) {
2416                            remove(resourcePermission);
2417                    }
2418            }
2419    
2420            /**
2421             * Removes the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; from the database.
2422             *
2423             * @param companyId the company id to search with
2424             * @param name the name to search with
2425             * @param scope the scope to search with
2426             * @param primKey the prim key to search with
2427             * @param roleId the role id to search with
2428             * @throws SystemException if a system exception occurred
2429             */
2430            public void removeByC_N_S_P_R(long companyId, String name, int scope,
2431                    String primKey, long roleId)
2432                    throws NoSuchResourcePermissionException, SystemException {
2433                    ResourcePermission resourcePermission = findByC_N_S_P_R(companyId,
2434                                    name, scope, primKey, roleId);
2435    
2436                    remove(resourcePermission);
2437            }
2438    
2439            /**
2440             * Removes all the resource permissions from the database.
2441             *
2442             * @throws SystemException if a system exception occurred
2443             */
2444            public void removeAll() throws SystemException {
2445                    for (ResourcePermission resourcePermission : findAll()) {
2446                            remove(resourcePermission);
2447                    }
2448            }
2449    
2450            /**
2451             * Counts all the resource permissions where roleId = &#63;.
2452             *
2453             * @param roleId the role id to search with
2454             * @return the number of matching resource permissions
2455             * @throws SystemException if a system exception occurred
2456             */
2457            public int countByRoleId(long roleId) throws SystemException {
2458                    Object[] finderArgs = new Object[] { roleId };
2459    
2460                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
2461                                    finderArgs, this);
2462    
2463                    if (count == null) {
2464                            StringBundler query = new StringBundler(2);
2465    
2466                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2467    
2468                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
2469    
2470                            String sql = query.toString();
2471    
2472                            Session session = null;
2473    
2474                            try {
2475                                    session = openSession();
2476    
2477                                    Query q = session.createQuery(sql);
2478    
2479                                    QueryPos qPos = QueryPos.getInstance(q);
2480    
2481                                    qPos.add(roleId);
2482    
2483                                    count = (Long)q.uniqueResult();
2484                            }
2485                            catch (Exception e) {
2486                                    throw processException(e);
2487                            }
2488                            finally {
2489                                    if (count == null) {
2490                                            count = Long.valueOf(0);
2491                                    }
2492    
2493                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
2494                                            finderArgs, count);
2495    
2496                                    closeSession(session);
2497                            }
2498                    }
2499    
2500                    return count.intValue();
2501            }
2502    
2503            /**
2504             * Counts all the resource permissions where roleId = &#63; and scope = &#63;.
2505             *
2506             * @param roleId the role id to search with
2507             * @param scope the scope to search with
2508             * @return the number of matching resource permissions
2509             * @throws SystemException if a system exception occurred
2510             */
2511            public int countByR_S(long roleId, int scope) throws SystemException {
2512                    Object[] finderArgs = new Object[] { roleId, scope };
2513    
2514                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_S,
2515                                    finderArgs, this);
2516    
2517                    if (count == null) {
2518                            StringBundler query = new StringBundler(3);
2519    
2520                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2521    
2522                            query.append(_FINDER_COLUMN_R_S_ROLEID_2);
2523    
2524                            query.append(_FINDER_COLUMN_R_S_SCOPE_2);
2525    
2526                            String sql = query.toString();
2527    
2528                            Session session = null;
2529    
2530                            try {
2531                                    session = openSession();
2532    
2533                                    Query q = session.createQuery(sql);
2534    
2535                                    QueryPos qPos = QueryPos.getInstance(q);
2536    
2537                                    qPos.add(roleId);
2538    
2539                                    qPos.add(scope);
2540    
2541                                    count = (Long)q.uniqueResult();
2542                            }
2543                            catch (Exception e) {
2544                                    throw processException(e);
2545                            }
2546                            finally {
2547                                    if (count == null) {
2548                                            count = Long.valueOf(0);
2549                                    }
2550    
2551                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_S, finderArgs,
2552                                            count);
2553    
2554                                    closeSession(session);
2555                            }
2556                    }
2557    
2558                    return count.intValue();
2559            }
2560    
2561            /**
2562             * Counts all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
2563             *
2564             * @param companyId the company id to search with
2565             * @param name the name to search with
2566             * @param scope the scope to search with
2567             * @return the number of matching resource permissions
2568             * @throws SystemException if a system exception occurred
2569             */
2570            public int countByC_N_S(long companyId, String name, int scope)
2571                    throws SystemException {
2572                    Object[] finderArgs = new Object[] { companyId, name, scope };
2573    
2574                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
2575                                    finderArgs, this);
2576    
2577                    if (count == null) {
2578                            StringBundler query = new StringBundler(4);
2579    
2580                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2581    
2582                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2583    
2584                            if (name == null) {
2585                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2586                            }
2587                            else {
2588                                    if (name.equals(StringPool.BLANK)) {
2589                                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2590                                    }
2591                                    else {
2592                                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2593                                    }
2594                            }
2595    
2596                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2597    
2598                            String sql = query.toString();
2599    
2600                            Session session = null;
2601    
2602                            try {
2603                                    session = openSession();
2604    
2605                                    Query q = session.createQuery(sql);
2606    
2607                                    QueryPos qPos = QueryPos.getInstance(q);
2608    
2609                                    qPos.add(companyId);
2610    
2611                                    if (name != null) {
2612                                            qPos.add(name);
2613                                    }
2614    
2615                                    qPos.add(scope);
2616    
2617                                    count = (Long)q.uniqueResult();
2618                            }
2619                            catch (Exception e) {
2620                                    throw processException(e);
2621                            }
2622                            finally {
2623                                    if (count == null) {
2624                                            count = Long.valueOf(0);
2625                                    }
2626    
2627                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
2628                                            finderArgs, count);
2629    
2630                                    closeSession(session);
2631                            }
2632                    }
2633    
2634                    return count.intValue();
2635            }
2636    
2637            /**
2638             * Counts all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2639             *
2640             * @param companyId the company id to search with
2641             * @param name the name to search with
2642             * @param scope the scope to search with
2643             * @param primKey the prim key to search with
2644             * @return the number of matching resource permissions
2645             * @throws SystemException if a system exception occurred
2646             */
2647            public int countByC_N_S_P(long companyId, String name, int scope,
2648                    String primKey) throws SystemException {
2649                    Object[] finderArgs = new Object[] { companyId, name, scope, primKey };
2650    
2651                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P,
2652                                    finderArgs, this);
2653    
2654                    if (count == null) {
2655                            StringBundler query = new StringBundler(5);
2656    
2657                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2658    
2659                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
2660    
2661                            if (name == null) {
2662                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
2663                            }
2664                            else {
2665                                    if (name.equals(StringPool.BLANK)) {
2666                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
2667                                    }
2668                                    else {
2669                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
2670                                    }
2671                            }
2672    
2673                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
2674    
2675                            if (primKey == null) {
2676                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
2677                            }
2678                            else {
2679                                    if (primKey.equals(StringPool.BLANK)) {
2680                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
2681                                    }
2682                                    else {
2683                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
2684                                    }
2685                            }
2686    
2687                            String sql = query.toString();
2688    
2689                            Session session = null;
2690    
2691                            try {
2692                                    session = openSession();
2693    
2694                                    Query q = session.createQuery(sql);
2695    
2696                                    QueryPos qPos = QueryPos.getInstance(q);
2697    
2698                                    qPos.add(companyId);
2699    
2700                                    if (name != null) {
2701                                            qPos.add(name);
2702                                    }
2703    
2704                                    qPos.add(scope);
2705    
2706                                    if (primKey != null) {
2707                                            qPos.add(primKey);
2708                                    }
2709    
2710                                    count = (Long)q.uniqueResult();
2711                            }
2712                            catch (Exception e) {
2713                                    throw processException(e);
2714                            }
2715                            finally {
2716                                    if (count == null) {
2717                                            count = Long.valueOf(0);
2718                                    }
2719    
2720                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P,
2721                                            finderArgs, count);
2722    
2723                                    closeSession(session);
2724                            }
2725                    }
2726    
2727                    return count.intValue();
2728            }
2729    
2730            /**
2731             * Counts all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
2732             *
2733             * @param companyId the company id to search with
2734             * @param name the name to search with
2735             * @param scope the scope to search with
2736             * @param primKey the prim key to search with
2737             * @param roleId the role id to search with
2738             * @return the number of matching resource permissions
2739             * @throws SystemException if a system exception occurred
2740             */
2741            public int countByC_N_S_P_R(long companyId, String name, int scope,
2742                    String primKey, long roleId) throws SystemException {
2743                    Object[] finderArgs = new Object[] {
2744                                    companyId, name, scope, primKey, roleId
2745                            };
2746    
2747                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
2748                                    finderArgs, this);
2749    
2750                    if (count == null) {
2751                            StringBundler query = new StringBundler(6);
2752    
2753                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2754    
2755                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
2756    
2757                            if (name == null) {
2758                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
2759                            }
2760                            else {
2761                                    if (name.equals(StringPool.BLANK)) {
2762                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
2763                                    }
2764                                    else {
2765                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
2766                                    }
2767                            }
2768    
2769                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
2770    
2771                            if (primKey == null) {
2772                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
2773                            }
2774                            else {
2775                                    if (primKey.equals(StringPool.BLANK)) {
2776                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
2777                                    }
2778                                    else {
2779                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
2780                                    }
2781                            }
2782    
2783                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
2784    
2785                            String sql = query.toString();
2786    
2787                            Session session = null;
2788    
2789                            try {
2790                                    session = openSession();
2791    
2792                                    Query q = session.createQuery(sql);
2793    
2794                                    QueryPos qPos = QueryPos.getInstance(q);
2795    
2796                                    qPos.add(companyId);
2797    
2798                                    if (name != null) {
2799                                            qPos.add(name);
2800                                    }
2801    
2802                                    qPos.add(scope);
2803    
2804                                    if (primKey != null) {
2805                                            qPos.add(primKey);
2806                                    }
2807    
2808                                    qPos.add(roleId);
2809    
2810                                    count = (Long)q.uniqueResult();
2811                            }
2812                            catch (Exception e) {
2813                                    throw processException(e);
2814                            }
2815                            finally {
2816                                    if (count == null) {
2817                                            count = Long.valueOf(0);
2818                                    }
2819    
2820                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
2821                                            finderArgs, count);
2822    
2823                                    closeSession(session);
2824                            }
2825                    }
2826    
2827                    return count.intValue();
2828            }
2829    
2830            /**
2831             * Counts all the resource permissions.
2832             *
2833             * @return the number of resource permissions
2834             * @throws SystemException if a system exception occurred
2835             */
2836            public int countAll() throws SystemException {
2837                    Object[] finderArgs = new Object[0];
2838    
2839                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2840                                    finderArgs, this);
2841    
2842                    if (count == null) {
2843                            Session session = null;
2844    
2845                            try {
2846                                    session = openSession();
2847    
2848                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEPERMISSION);
2849    
2850                                    count = (Long)q.uniqueResult();
2851                            }
2852                            catch (Exception e) {
2853                                    throw processException(e);
2854                            }
2855                            finally {
2856                                    if (count == null) {
2857                                            count = Long.valueOf(0);
2858                                    }
2859    
2860                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2861                                            count);
2862    
2863                                    closeSession(session);
2864                            }
2865                    }
2866    
2867                    return count.intValue();
2868            }
2869    
2870            /**
2871             * Initializes the resource permission persistence.
2872             */
2873            public void afterPropertiesSet() {
2874                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2875                                            com.liferay.portal.util.PropsUtil.get(
2876                                                    "value.object.listener.com.liferay.portal.model.ResourcePermission")));
2877    
2878                    if (listenerClassNames.length > 0) {
2879                            try {
2880                                    List<ModelListener<ResourcePermission>> listenersList = new ArrayList<ModelListener<ResourcePermission>>();
2881    
2882                                    for (String listenerClassName : listenerClassNames) {
2883                                            listenersList.add((ModelListener<ResourcePermission>)InstanceFactory.newInstance(
2884                                                            listenerClassName));
2885                                    }
2886    
2887                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2888                            }
2889                            catch (Exception e) {
2890                                    _log.error(e);
2891                            }
2892                    }
2893            }
2894    
2895            public void destroy() {
2896                    EntityCacheUtil.removeCache(ResourcePermissionImpl.class.getName());
2897                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2898                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2899            }
2900    
2901            @BeanReference(type = AccountPersistence.class)
2902            protected AccountPersistence accountPersistence;
2903            @BeanReference(type = AddressPersistence.class)
2904            protected AddressPersistence addressPersistence;
2905            @BeanReference(type = BrowserTrackerPersistence.class)
2906            protected BrowserTrackerPersistence browserTrackerPersistence;
2907            @BeanReference(type = ClassNamePersistence.class)
2908            protected ClassNamePersistence classNamePersistence;
2909            @BeanReference(type = ClusterGroupPersistence.class)
2910            protected ClusterGroupPersistence clusterGroupPersistence;
2911            @BeanReference(type = CompanyPersistence.class)
2912            protected CompanyPersistence companyPersistence;
2913            @BeanReference(type = ContactPersistence.class)
2914            protected ContactPersistence contactPersistence;
2915            @BeanReference(type = CountryPersistence.class)
2916            protected CountryPersistence countryPersistence;
2917            @BeanReference(type = EmailAddressPersistence.class)
2918            protected EmailAddressPersistence emailAddressPersistence;
2919            @BeanReference(type = GroupPersistence.class)
2920            protected GroupPersistence groupPersistence;
2921            @BeanReference(type = ImagePersistence.class)
2922            protected ImagePersistence imagePersistence;
2923            @BeanReference(type = LayoutPersistence.class)
2924            protected LayoutPersistence layoutPersistence;
2925            @BeanReference(type = LayoutPrototypePersistence.class)
2926            protected LayoutPrototypePersistence layoutPrototypePersistence;
2927            @BeanReference(type = LayoutSetPersistence.class)
2928            protected LayoutSetPersistence layoutSetPersistence;
2929            @BeanReference(type = LayoutSetPrototypePersistence.class)
2930            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2931            @BeanReference(type = ListTypePersistence.class)
2932            protected ListTypePersistence listTypePersistence;
2933            @BeanReference(type = LockPersistence.class)
2934            protected LockPersistence lockPersistence;
2935            @BeanReference(type = MembershipRequestPersistence.class)
2936            protected MembershipRequestPersistence membershipRequestPersistence;
2937            @BeanReference(type = OrganizationPersistence.class)
2938            protected OrganizationPersistence organizationPersistence;
2939            @BeanReference(type = OrgGroupPermissionPersistence.class)
2940            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2941            @BeanReference(type = OrgGroupRolePersistence.class)
2942            protected OrgGroupRolePersistence orgGroupRolePersistence;
2943            @BeanReference(type = OrgLaborPersistence.class)
2944            protected OrgLaborPersistence orgLaborPersistence;
2945            @BeanReference(type = PasswordPolicyPersistence.class)
2946            protected PasswordPolicyPersistence passwordPolicyPersistence;
2947            @BeanReference(type = PasswordPolicyRelPersistence.class)
2948            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2949            @BeanReference(type = PasswordTrackerPersistence.class)
2950            protected PasswordTrackerPersistence passwordTrackerPersistence;
2951            @BeanReference(type = PermissionPersistence.class)
2952            protected PermissionPersistence permissionPersistence;
2953            @BeanReference(type = PhonePersistence.class)
2954            protected PhonePersistence phonePersistence;
2955            @BeanReference(type = PluginSettingPersistence.class)
2956            protected PluginSettingPersistence pluginSettingPersistence;
2957            @BeanReference(type = PortletPersistence.class)
2958            protected PortletPersistence portletPersistence;
2959            @BeanReference(type = PortletItemPersistence.class)
2960            protected PortletItemPersistence portletItemPersistence;
2961            @BeanReference(type = PortletPreferencesPersistence.class)
2962            protected PortletPreferencesPersistence portletPreferencesPersistence;
2963            @BeanReference(type = RegionPersistence.class)
2964            protected RegionPersistence regionPersistence;
2965            @BeanReference(type = ReleasePersistence.class)
2966            protected ReleasePersistence releasePersistence;
2967            @BeanReference(type = ResourcePersistence.class)
2968            protected ResourcePersistence resourcePersistence;
2969            @BeanReference(type = ResourceActionPersistence.class)
2970            protected ResourceActionPersistence resourceActionPersistence;
2971            @BeanReference(type = ResourceCodePersistence.class)
2972            protected ResourceCodePersistence resourceCodePersistence;
2973            @BeanReference(type = ResourcePermissionPersistence.class)
2974            protected ResourcePermissionPersistence resourcePermissionPersistence;
2975            @BeanReference(type = RolePersistence.class)
2976            protected RolePersistence rolePersistence;
2977            @BeanReference(type = ServiceComponentPersistence.class)
2978            protected ServiceComponentPersistence serviceComponentPersistence;
2979            @BeanReference(type = ShardPersistence.class)
2980            protected ShardPersistence shardPersistence;
2981            @BeanReference(type = SubscriptionPersistence.class)
2982            protected SubscriptionPersistence subscriptionPersistence;
2983            @BeanReference(type = TicketPersistence.class)
2984            protected TicketPersistence ticketPersistence;
2985            @BeanReference(type = TeamPersistence.class)
2986            protected TeamPersistence teamPersistence;
2987            @BeanReference(type = UserPersistence.class)
2988            protected UserPersistence userPersistence;
2989            @BeanReference(type = UserGroupPersistence.class)
2990            protected UserGroupPersistence userGroupPersistence;
2991            @BeanReference(type = UserGroupGroupRolePersistence.class)
2992            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2993            @BeanReference(type = UserGroupRolePersistence.class)
2994            protected UserGroupRolePersistence userGroupRolePersistence;
2995            @BeanReference(type = UserIdMapperPersistence.class)
2996            protected UserIdMapperPersistence userIdMapperPersistence;
2997            @BeanReference(type = UserTrackerPersistence.class)
2998            protected UserTrackerPersistence userTrackerPersistence;
2999            @BeanReference(type = UserTrackerPathPersistence.class)
3000            protected UserTrackerPathPersistence userTrackerPathPersistence;
3001            @BeanReference(type = WebDAVPropsPersistence.class)
3002            protected WebDAVPropsPersistence webDAVPropsPersistence;
3003            @BeanReference(type = WebsitePersistence.class)
3004            protected WebsitePersistence websitePersistence;
3005            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
3006            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
3007            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
3008            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
3009            private static final String _SQL_SELECT_RESOURCEPERMISSION = "SELECT resourcePermission FROM ResourcePermission resourcePermission";
3010            private static final String _SQL_SELECT_RESOURCEPERMISSION_WHERE = "SELECT resourcePermission FROM ResourcePermission resourcePermission WHERE ";
3011            private static final String _SQL_COUNT_RESOURCEPERMISSION = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission";
3012            private static final String _SQL_COUNT_RESOURCEPERMISSION_WHERE = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission WHERE ";
3013            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourcePermission.roleId = ?";
3014            private static final String _FINDER_COLUMN_R_S_ROLEID_2 = "resourcePermission.roleId = ? AND ";
3015            private static final String _FINDER_COLUMN_R_S_SCOPE_2 = "resourcePermission.scope = ?";
3016            private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3017            private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourcePermission.name IS NULL AND ";
3018            private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourcePermission.name = ? AND ";
3019            private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
3020            private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourcePermission.scope = ?";
3021            private static final String _FINDER_COLUMN_C_N_S_P_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3022            private static final String _FINDER_COLUMN_C_N_S_P_NAME_1 = "resourcePermission.name IS NULL AND ";
3023            private static final String _FINDER_COLUMN_C_N_S_P_NAME_2 = "resourcePermission.name = ? AND ";
3024            private static final String _FINDER_COLUMN_C_N_S_P_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
3025            private static final String _FINDER_COLUMN_C_N_S_P_SCOPE_2 = "resourcePermission.scope = ? AND ";
3026            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_1 = "resourcePermission.primKey IS NULL";
3027            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_2 = "resourcePermission.primKey = ?";
3028            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?)";
3029            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3030            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_1 = "resourcePermission.name IS NULL AND ";
3031            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_2 = "resourcePermission.name = ? AND ";
3032            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
3033            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_2 = "resourcePermission.scope = ? AND ";
3034            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
3035            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
3036            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
3037            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_2 = "resourcePermission.roleId = ?";
3038            private static final String _ORDER_BY_ENTITY_ALIAS = "resourcePermission.";
3039            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourcePermission exists with the primary key ";
3040            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourcePermission exists with the key {";
3041            private static Log _log = LogFactoryUtil.getLog(ResourcePermissionPersistenceImpl.class);
3042    }