001    /**
002     * Copyright (c) 2000-2012 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.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.ArrayUtil;
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.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.model.ModelListener;
041    import com.liferay.portal.model.ResourcePermission;
042    import com.liferay.portal.model.impl.ResourcePermissionImpl;
043    import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
044    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045    
046    import java.io.Serializable;
047    
048    import java.util.ArrayList;
049    import java.util.Collections;
050    import java.util.List;
051    
052    /**
053     * The persistence implementation for the resource permission service.
054     *
055     * <p>
056     * Caching information and settings can be found in <code>portal.properties</code>
057     * </p>
058     *
059     * @author Brian Wing Shun Chan
060     * @see ResourcePermissionPersistence
061     * @see ResourcePermissionUtil
062     * @generated
063     */
064    public class ResourcePermissionPersistenceImpl extends BasePersistenceImpl<ResourcePermission>
065            implements ResourcePermissionPersistence {
066            /*
067             * NOTE FOR DEVELOPERS:
068             *
069             * 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.
070             */
071            public static final String FINDER_CLASS_NAME_ENTITY = ResourcePermissionImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List1";
074            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List2";
076            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
077                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
078                            ResourcePermissionImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
081                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
082                            ResourcePermissionImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
085                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
088                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
089                            ResourcePermissionImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByScope",
091                            new String[] {
092                                    Integer.class.getName(),
093                                    
094                            Integer.class.getName(), Integer.class.getName(),
095                                    OrderByComparator.class.getName()
096                            });
097            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
098                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
099                            ResourcePermissionImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByScope",
101                            new String[] { Integer.class.getName() },
102                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
104                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByScope",
106                            new String[] { Integer.class.getName() });
107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
108                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
109                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByScope",
110                            new String[] { Integer.class.getName() });
111    
112            /**
113             * Returns all the resource permissions where scope = &#63;.
114             *
115             * @param scope the scope
116             * @return the matching resource permissions
117             * @throws SystemException if a system exception occurred
118             */
119            public List<ResourcePermission> findByScope(int scope)
120                    throws SystemException {
121                    return findByScope(scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the resource permissions where scope = &#63;.
126             *
127             * <p>
128             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param scope the scope
132             * @param start the lower bound of the range of resource permissions
133             * @param end the upper bound of the range of resource permissions (not inclusive)
134             * @return the range of matching resource permissions
135             * @throws SystemException if a system exception occurred
136             */
137            public List<ResourcePermission> findByScope(int scope, int start, int end)
138                    throws SystemException {
139                    return findByScope(scope, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the resource permissions where scope = &#63;.
144             *
145             * <p>
146             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param scope the scope
150             * @param start the lower bound of the range of resource permissions
151             * @param end the upper bound of the range of resource permissions (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching resource permissions
154             * @throws SystemException if a system exception occurred
155             */
156            public List<ResourcePermission> findByScope(int scope, int start, int end,
157                    OrderByComparator orderByComparator) throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE;
166                            finderArgs = new Object[] { scope };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE;
170                            finderArgs = new Object[] { scope, start, end, orderByComparator };
171                    }
172    
173                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (ResourcePermission resourcePermission : list) {
178                                    if ((scope != resourcePermission.getScope())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
198    
199                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
200    
201                            if (orderByComparator != null) {
202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
203                                            orderByComparator);
204                            }
205                            else
206                             if (pagination) {
207                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
208                            }
209    
210                            String sql = query.toString();
211    
212                            Session session = null;
213    
214                            try {
215                                    session = openSession();
216    
217                                    Query q = session.createQuery(sql);
218    
219                                    QueryPos qPos = QueryPos.getInstance(q);
220    
221                                    qPos.add(scope);
222    
223                                    if (!pagination) {
224                                            list = (List<ResourcePermission>)QueryUtil.list(q,
225                                                            getDialect(), start, end, false);
226    
227                                            Collections.sort(list);
228    
229                                            list = new UnmodifiableList<ResourcePermission>(list);
230                                    }
231                                    else {
232                                            list = (List<ResourcePermission>)QueryUtil.list(q,
233                                                            getDialect(), start, end);
234                                    }
235    
236                                    cacheResult(list);
237    
238                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
239                            }
240                            catch (Exception e) {
241                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
242    
243                                    throw processException(e);
244                            }
245                            finally {
246                                    closeSession(session);
247                            }
248                    }
249    
250                    return list;
251            }
252    
253            /**
254             * Returns the first resource permission in the ordered set where scope = &#63;.
255             *
256             * @param scope the scope
257             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
258             * @return the first matching resource permission
259             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
260             * @throws SystemException if a system exception occurred
261             */
262            public ResourcePermission findByScope_First(int scope,
263                    OrderByComparator orderByComparator)
264                    throws NoSuchResourcePermissionException, SystemException {
265                    ResourcePermission resourcePermission = fetchByScope_First(scope,
266                                    orderByComparator);
267    
268                    if (resourcePermission != null) {
269                            return resourcePermission;
270                    }
271    
272                    StringBundler msg = new StringBundler(4);
273    
274                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
275    
276                    msg.append("scope=");
277                    msg.append(scope);
278    
279                    msg.append(StringPool.CLOSE_CURLY_BRACE);
280    
281                    throw new NoSuchResourcePermissionException(msg.toString());
282            }
283    
284            /**
285             * Returns the first resource permission in the ordered set where scope = &#63;.
286             *
287             * @param scope the scope
288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
289             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
290             * @throws SystemException if a system exception occurred
291             */
292            public ResourcePermission fetchByScope_First(int scope,
293                    OrderByComparator orderByComparator) throws SystemException {
294                    List<ResourcePermission> list = findByScope(scope, 0, 1,
295                                    orderByComparator);
296    
297                    if (!list.isEmpty()) {
298                            return list.get(0);
299                    }
300    
301                    return null;
302            }
303    
304            /**
305             * Returns the last resource permission in the ordered set where scope = &#63;.
306             *
307             * @param scope the scope
308             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
309             * @return the last matching resource permission
310             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
311             * @throws SystemException if a system exception occurred
312             */
313            public ResourcePermission findByScope_Last(int scope,
314                    OrderByComparator orderByComparator)
315                    throws NoSuchResourcePermissionException, SystemException {
316                    ResourcePermission resourcePermission = fetchByScope_Last(scope,
317                                    orderByComparator);
318    
319                    if (resourcePermission != null) {
320                            return resourcePermission;
321                    }
322    
323                    StringBundler msg = new StringBundler(4);
324    
325                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
326    
327                    msg.append("scope=");
328                    msg.append(scope);
329    
330                    msg.append(StringPool.CLOSE_CURLY_BRACE);
331    
332                    throw new NoSuchResourcePermissionException(msg.toString());
333            }
334    
335            /**
336             * Returns the last resource permission in the ordered set where scope = &#63;.
337             *
338             * @param scope the scope
339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
340             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
341             * @throws SystemException if a system exception occurred
342             */
343            public ResourcePermission fetchByScope_Last(int scope,
344                    OrderByComparator orderByComparator) throws SystemException {
345                    int count = countByScope(scope);
346    
347                    List<ResourcePermission> list = findByScope(scope, count - 1, count,
348                                    orderByComparator);
349    
350                    if (!list.isEmpty()) {
351                            return list.get(0);
352                    }
353    
354                    return null;
355            }
356    
357            /**
358             * Returns the resource permissions before and after the current resource permission in the ordered set where scope = &#63;.
359             *
360             * @param resourcePermissionId the primary key of the current resource permission
361             * @param scope the scope
362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
363             * @return the previous, current, and next resource permission
364             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
365             * @throws SystemException if a system exception occurred
366             */
367            public ResourcePermission[] findByScope_PrevAndNext(
368                    long resourcePermissionId, int scope,
369                    OrderByComparator orderByComparator)
370                    throws NoSuchResourcePermissionException, SystemException {
371                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
372    
373                    Session session = null;
374    
375                    try {
376                            session = openSession();
377    
378                            ResourcePermission[] array = new ResourcePermissionImpl[3];
379    
380                            array[0] = getByScope_PrevAndNext(session, resourcePermission,
381                                            scope, orderByComparator, true);
382    
383                            array[1] = resourcePermission;
384    
385                            array[2] = getByScope_PrevAndNext(session, resourcePermission,
386                                            scope, orderByComparator, false);
387    
388                            return array;
389                    }
390                    catch (Exception e) {
391                            throw processException(e);
392                    }
393                    finally {
394                            closeSession(session);
395                    }
396            }
397    
398            protected ResourcePermission getByScope_PrevAndNext(Session session,
399                    ResourcePermission resourcePermission, int scope,
400                    OrderByComparator orderByComparator, boolean previous) {
401                    StringBundler query = null;
402    
403                    if (orderByComparator != null) {
404                            query = new StringBundler(6 +
405                                            (orderByComparator.getOrderByFields().length * 6));
406                    }
407                    else {
408                            query = new StringBundler(3);
409                    }
410    
411                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
412    
413                    query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
414    
415                    if (orderByComparator != null) {
416                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
417    
418                            if (orderByConditionFields.length > 0) {
419                                    query.append(WHERE_AND);
420                            }
421    
422                            for (int i = 0; i < orderByConditionFields.length; i++) {
423                                    query.append(_ORDER_BY_ENTITY_ALIAS);
424                                    query.append(orderByConditionFields[i]);
425    
426                                    if ((i + 1) < orderByConditionFields.length) {
427                                            if (orderByComparator.isAscending() ^ previous) {
428                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
429                                            }
430                                            else {
431                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
432                                            }
433                                    }
434                                    else {
435                                            if (orderByComparator.isAscending() ^ previous) {
436                                                    query.append(WHERE_GREATER_THAN);
437                                            }
438                                            else {
439                                                    query.append(WHERE_LESSER_THAN);
440                                            }
441                                    }
442                            }
443    
444                            query.append(ORDER_BY_CLAUSE);
445    
446                            String[] orderByFields = orderByComparator.getOrderByFields();
447    
448                            for (int i = 0; i < orderByFields.length; i++) {
449                                    query.append(_ORDER_BY_ENTITY_ALIAS);
450                                    query.append(orderByFields[i]);
451    
452                                    if ((i + 1) < orderByFields.length) {
453                                            if (orderByComparator.isAscending() ^ previous) {
454                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
455                                            }
456                                            else {
457                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
458                                            }
459                                    }
460                                    else {
461                                            if (orderByComparator.isAscending() ^ previous) {
462                                                    query.append(ORDER_BY_ASC);
463                                            }
464                                            else {
465                                                    query.append(ORDER_BY_DESC);
466                                            }
467                                    }
468                            }
469                    }
470                    else {
471                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
472                    }
473    
474                    String sql = query.toString();
475    
476                    Query q = session.createQuery(sql);
477    
478                    q.setFirstResult(0);
479                    q.setMaxResults(2);
480    
481                    QueryPos qPos = QueryPos.getInstance(q);
482    
483                    qPos.add(scope);
484    
485                    if (orderByComparator != null) {
486                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
487    
488                            for (Object value : values) {
489                                    qPos.add(value);
490                            }
491                    }
492    
493                    List<ResourcePermission> list = q.list();
494    
495                    if (list.size() == 2) {
496                            return list.get(1);
497                    }
498                    else {
499                            return null;
500                    }
501            }
502    
503            /**
504             * Returns all the resource permissions where scope = any &#63;.
505             *
506             * <p>
507             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
508             * </p>
509             *
510             * @param scopes the scopes
511             * @return the matching resource permissions
512             * @throws SystemException if a system exception occurred
513             */
514            public List<ResourcePermission> findByScope(int[] scopes)
515                    throws SystemException {
516                    return findByScope(scopes, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
517            }
518    
519            /**
520             * Returns a range of all the resource permissions where scope = any &#63;.
521             *
522             * <p>
523             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
524             * </p>
525             *
526             * @param scopes the scopes
527             * @param start the lower bound of the range of resource permissions
528             * @param end the upper bound of the range of resource permissions (not inclusive)
529             * @return the range of matching resource permissions
530             * @throws SystemException if a system exception occurred
531             */
532            public List<ResourcePermission> findByScope(int[] scopes, int start, int end)
533                    throws SystemException {
534                    return findByScope(scopes, start, end, null);
535            }
536    
537            /**
538             * Returns an ordered range of all the resource permissions where scope = any &#63;.
539             *
540             * <p>
541             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
542             * </p>
543             *
544             * @param scopes the scopes
545             * @param start the lower bound of the range of resource permissions
546             * @param end the upper bound of the range of resource permissions (not inclusive)
547             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
548             * @return the ordered range of matching resource permissions
549             * @throws SystemException if a system exception occurred
550             */
551            public List<ResourcePermission> findByScope(int[] scopes, int start,
552                    int end, OrderByComparator orderByComparator) throws SystemException {
553                    if ((scopes != null) && (scopes.length == 1)) {
554                            return findByScope(scopes[0], start, end, orderByComparator);
555                    }
556    
557                    boolean pagination = true;
558                    Object[] finderArgs = null;
559    
560                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
561                                    (orderByComparator == null)) {
562                            pagination = false;
563                            finderArgs = new Object[] { StringUtil.merge(scopes) };
564                    }
565                    else {
566                            finderArgs = new Object[] {
567                                            StringUtil.merge(scopes),
568                                            
569                                            start, end, orderByComparator
570                                    };
571                    }
572    
573                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE,
574                                    finderArgs, this);
575    
576                    if ((list != null) && !list.isEmpty()) {
577                            for (ResourcePermission resourcePermission : list) {
578                                    if (!ArrayUtil.contains(scopes, resourcePermission.getScope())) {
579                                            list = null;
580    
581                                            break;
582                                    }
583                            }
584                    }
585    
586                    if (list == null) {
587                            StringBundler query = new StringBundler();
588    
589                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
590    
591                            boolean conjunctionable = false;
592    
593                            if ((scopes == null) || (scopes.length > 0)) {
594                                    if (conjunctionable) {
595                                            query.append(WHERE_AND);
596                                    }
597    
598                                    query.append(StringPool.OPEN_PARENTHESIS);
599    
600                                    for (int i = 0; i < scopes.length; i++) {
601                                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_5);
602    
603                                            if ((i + 1) < scopes.length) {
604                                                    query.append(WHERE_OR);
605                                            }
606                                    }
607    
608                                    query.append(StringPool.CLOSE_PARENTHESIS);
609    
610                                    conjunctionable = true;
611                            }
612    
613                            if (orderByComparator != null) {
614                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
615                                            orderByComparator);
616                            }
617                            else
618                             if (pagination) {
619                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
620                            }
621    
622                            String sql = query.toString();
623    
624                            Session session = null;
625    
626                            try {
627                                    session = openSession();
628    
629                                    Query q = session.createQuery(sql);
630    
631                                    QueryPos qPos = QueryPos.getInstance(q);
632    
633                                    if (scopes != null) {
634                                            qPos.add(scopes);
635                                    }
636    
637                                    if (!pagination) {
638                                            list = (List<ResourcePermission>)QueryUtil.list(q,
639                                                            getDialect(), start, end, false);
640    
641                                            Collections.sort(list);
642    
643                                            list = new UnmodifiableList<ResourcePermission>(list);
644                                    }
645                                    else {
646                                            list = (List<ResourcePermission>)QueryUtil.list(q,
647                                                            getDialect(), start, end);
648                                    }
649    
650                                    cacheResult(list);
651    
652                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE,
653                                            finderArgs, list);
654                            }
655                            catch (Exception e) {
656                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE,
657                                            finderArgs);
658    
659                                    throw processException(e);
660                            }
661                            finally {
662                                    closeSession(session);
663                            }
664                    }
665    
666                    return list;
667            }
668    
669            /**
670             * Removes all the resource permissions where scope = &#63; from the database.
671             *
672             * @param scope the scope
673             * @throws SystemException if a system exception occurred
674             */
675            public void removeByScope(int scope) throws SystemException {
676                    for (ResourcePermission resourcePermission : findByScope(scope,
677                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
678                            remove(resourcePermission);
679                    }
680            }
681    
682            /**
683             * Returns the number of resource permissions where scope = &#63;.
684             *
685             * @param scope the scope
686             * @return the number of matching resource permissions
687             * @throws SystemException if a system exception occurred
688             */
689            public int countByScope(int scope) throws SystemException {
690                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SCOPE;
691    
692                    Object[] finderArgs = new Object[] { scope };
693    
694                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
695                                    this);
696    
697                    if (count == null) {
698                            StringBundler query = new StringBundler(2);
699    
700                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
701    
702                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
703    
704                            String sql = query.toString();
705    
706                            Session session = null;
707    
708                            try {
709                                    session = openSession();
710    
711                                    Query q = session.createQuery(sql);
712    
713                                    QueryPos qPos = QueryPos.getInstance(q);
714    
715                                    qPos.add(scope);
716    
717                                    count = (Long)q.uniqueResult();
718    
719                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
720                            }
721                            catch (Exception e) {
722                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
723    
724                                    throw processException(e);
725                            }
726                            finally {
727                                    closeSession(session);
728                            }
729                    }
730    
731                    return count.intValue();
732            }
733    
734            /**
735             * Returns the number of resource permissions where scope = any &#63;.
736             *
737             * @param scopes the scopes
738             * @return the number of matching resource permissions
739             * @throws SystemException if a system exception occurred
740             */
741            public int countByScope(int[] scopes) throws SystemException {
742                    Object[] finderArgs = new Object[] { StringUtil.merge(scopes) };
743    
744                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE,
745                                    finderArgs, this);
746    
747                    if (count == null) {
748                            StringBundler query = new StringBundler();
749    
750                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
751    
752                            boolean conjunctionable = false;
753    
754                            if ((scopes == null) || (scopes.length > 0)) {
755                                    if (conjunctionable) {
756                                            query.append(WHERE_AND);
757                                    }
758    
759                                    query.append(StringPool.OPEN_PARENTHESIS);
760    
761                                    for (int i = 0; i < scopes.length; i++) {
762                                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_5);
763    
764                                            if ((i + 1) < scopes.length) {
765                                                    query.append(WHERE_OR);
766                                            }
767                                    }
768    
769                                    query.append(StringPool.CLOSE_PARENTHESIS);
770    
771                                    conjunctionable = true;
772                            }
773    
774                            String sql = query.toString();
775    
776                            Session session = null;
777    
778                            try {
779                                    session = openSession();
780    
781                                    Query q = session.createQuery(sql);
782    
783                                    QueryPos qPos = QueryPos.getInstance(q);
784    
785                                    if (scopes != null) {
786                                            qPos.add(scopes);
787                                    }
788    
789                                    count = (Long)q.uniqueResult();
790    
791                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE,
792                                            finderArgs, count);
793                            }
794                            catch (Exception e) {
795                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE,
796                                            finderArgs);
797    
798                                    throw processException(e);
799                            }
800                            finally {
801                                    closeSession(session);
802                            }
803                    }
804    
805                    return count.intValue();
806            }
807    
808            private static final String _FINDER_COLUMN_SCOPE_SCOPE_2 = "resourcePermission.scope = ?";
809            private static final String _FINDER_COLUMN_SCOPE_SCOPE_5 = "(" +
810                    _removeConjunction(_FINDER_COLUMN_SCOPE_SCOPE_2) + ")";
811            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
812                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
813                            ResourcePermissionImpl.class,
814                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
815                            new String[] {
816                                    Long.class.getName(),
817                                    
818                            Integer.class.getName(), Integer.class.getName(),
819                                    OrderByComparator.class.getName()
820                            });
821            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
822                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
823                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
824                            ResourcePermissionImpl.class,
825                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
826                            new String[] { Long.class.getName() },
827                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
828            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
829                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
830                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
831                            new String[] { Long.class.getName() });
832    
833            /**
834             * Returns all the resource permissions where roleId = &#63;.
835             *
836             * @param roleId the role ID
837             * @return the matching resource permissions
838             * @throws SystemException if a system exception occurred
839             */
840            public List<ResourcePermission> findByRoleId(long roleId)
841                    throws SystemException {
842                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
843            }
844    
845            /**
846             * Returns a range of all the resource permissions where roleId = &#63;.
847             *
848             * <p>
849             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
850             * </p>
851             *
852             * @param roleId the role ID
853             * @param start the lower bound of the range of resource permissions
854             * @param end the upper bound of the range of resource permissions (not inclusive)
855             * @return the range of matching resource permissions
856             * @throws SystemException if a system exception occurred
857             */
858            public List<ResourcePermission> findByRoleId(long roleId, int start, int end)
859                    throws SystemException {
860                    return findByRoleId(roleId, start, end, null);
861            }
862    
863            /**
864             * Returns an ordered range of all the resource permissions where roleId = &#63;.
865             *
866             * <p>
867             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
868             * </p>
869             *
870             * @param roleId the role ID
871             * @param start the lower bound of the range of resource permissions
872             * @param end the upper bound of the range of resource permissions (not inclusive)
873             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
874             * @return the ordered range of matching resource permissions
875             * @throws SystemException if a system exception occurred
876             */
877            public List<ResourcePermission> findByRoleId(long roleId, int start,
878                    int end, OrderByComparator orderByComparator) throws SystemException {
879                    boolean pagination = true;
880                    FinderPath finderPath = null;
881                    Object[] finderArgs = null;
882    
883                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
884                                    (orderByComparator == null)) {
885                            pagination = false;
886                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
887                            finderArgs = new Object[] { roleId };
888                    }
889                    else {
890                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
891                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
892                    }
893    
894                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
895                                    finderArgs, this);
896    
897                    if ((list != null) && !list.isEmpty()) {
898                            for (ResourcePermission resourcePermission : list) {
899                                    if ((roleId != resourcePermission.getRoleId())) {
900                                            list = null;
901    
902                                            break;
903                                    }
904                            }
905                    }
906    
907                    if (list == null) {
908                            StringBundler query = null;
909    
910                            if (orderByComparator != null) {
911                                    query = new StringBundler(3 +
912                                                    (orderByComparator.getOrderByFields().length * 3));
913                            }
914                            else {
915                                    query = new StringBundler(3);
916                            }
917    
918                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
919    
920                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
921    
922                            if (orderByComparator != null) {
923                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
924                                            orderByComparator);
925                            }
926                            else
927                             if (pagination) {
928                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
929                            }
930    
931                            String sql = query.toString();
932    
933                            Session session = null;
934    
935                            try {
936                                    session = openSession();
937    
938                                    Query q = session.createQuery(sql);
939    
940                                    QueryPos qPos = QueryPos.getInstance(q);
941    
942                                    qPos.add(roleId);
943    
944                                    if (!pagination) {
945                                            list = (List<ResourcePermission>)QueryUtil.list(q,
946                                                            getDialect(), start, end, false);
947    
948                                            Collections.sort(list);
949    
950                                            list = new UnmodifiableList<ResourcePermission>(list);
951                                    }
952                                    else {
953                                            list = (List<ResourcePermission>)QueryUtil.list(q,
954                                                            getDialect(), start, end);
955                                    }
956    
957                                    cacheResult(list);
958    
959                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
960                            }
961                            catch (Exception e) {
962                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
963    
964                                    throw processException(e);
965                            }
966                            finally {
967                                    closeSession(session);
968                            }
969                    }
970    
971                    return list;
972            }
973    
974            /**
975             * Returns the first resource permission in the ordered set where roleId = &#63;.
976             *
977             * @param roleId the role ID
978             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
979             * @return the first matching resource permission
980             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
981             * @throws SystemException if a system exception occurred
982             */
983            public ResourcePermission findByRoleId_First(long roleId,
984                    OrderByComparator orderByComparator)
985                    throws NoSuchResourcePermissionException, SystemException {
986                    ResourcePermission resourcePermission = fetchByRoleId_First(roleId,
987                                    orderByComparator);
988    
989                    if (resourcePermission != null) {
990                            return resourcePermission;
991                    }
992    
993                    StringBundler msg = new StringBundler(4);
994    
995                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
996    
997                    msg.append("roleId=");
998                    msg.append(roleId);
999    
1000                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1001    
1002                    throw new NoSuchResourcePermissionException(msg.toString());
1003            }
1004    
1005            /**
1006             * Returns the first resource permission in the ordered set where roleId = &#63;.
1007             *
1008             * @param roleId the role ID
1009             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1010             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
1011             * @throws SystemException if a system exception occurred
1012             */
1013            public ResourcePermission fetchByRoleId_First(long roleId,
1014                    OrderByComparator orderByComparator) throws SystemException {
1015                    List<ResourcePermission> list = findByRoleId(roleId, 0, 1,
1016                                    orderByComparator);
1017    
1018                    if (!list.isEmpty()) {
1019                            return list.get(0);
1020                    }
1021    
1022                    return null;
1023            }
1024    
1025            /**
1026             * Returns the last resource permission in the ordered set where roleId = &#63;.
1027             *
1028             * @param roleId the role ID
1029             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1030             * @return the last matching resource permission
1031             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1032             * @throws SystemException if a system exception occurred
1033             */
1034            public ResourcePermission findByRoleId_Last(long roleId,
1035                    OrderByComparator orderByComparator)
1036                    throws NoSuchResourcePermissionException, SystemException {
1037                    ResourcePermission resourcePermission = fetchByRoleId_Last(roleId,
1038                                    orderByComparator);
1039    
1040                    if (resourcePermission != null) {
1041                            return resourcePermission;
1042                    }
1043    
1044                    StringBundler msg = new StringBundler(4);
1045    
1046                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1047    
1048                    msg.append("roleId=");
1049                    msg.append(roleId);
1050    
1051                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1052    
1053                    throw new NoSuchResourcePermissionException(msg.toString());
1054            }
1055    
1056            /**
1057             * Returns the last resource permission in the ordered set where roleId = &#63;.
1058             *
1059             * @param roleId the role ID
1060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1061             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
1062             * @throws SystemException if a system exception occurred
1063             */
1064            public ResourcePermission fetchByRoleId_Last(long roleId,
1065                    OrderByComparator orderByComparator) throws SystemException {
1066                    int count = countByRoleId(roleId);
1067    
1068                    List<ResourcePermission> list = findByRoleId(roleId, count - 1, count,
1069                                    orderByComparator);
1070    
1071                    if (!list.isEmpty()) {
1072                            return list.get(0);
1073                    }
1074    
1075                    return null;
1076            }
1077    
1078            /**
1079             * Returns the resource permissions before and after the current resource permission in the ordered set where roleId = &#63;.
1080             *
1081             * @param resourcePermissionId the primary key of the current resource permission
1082             * @param roleId the role ID
1083             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1084             * @return the previous, current, and next resource permission
1085             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1086             * @throws SystemException if a system exception occurred
1087             */
1088            public ResourcePermission[] findByRoleId_PrevAndNext(
1089                    long resourcePermissionId, long roleId,
1090                    OrderByComparator orderByComparator)
1091                    throws NoSuchResourcePermissionException, SystemException {
1092                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1093    
1094                    Session session = null;
1095    
1096                    try {
1097                            session = openSession();
1098    
1099                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1100    
1101                            array[0] = getByRoleId_PrevAndNext(session, resourcePermission,
1102                                            roleId, orderByComparator, true);
1103    
1104                            array[1] = resourcePermission;
1105    
1106                            array[2] = getByRoleId_PrevAndNext(session, resourcePermission,
1107                                            roleId, orderByComparator, false);
1108    
1109                            return array;
1110                    }
1111                    catch (Exception e) {
1112                            throw processException(e);
1113                    }
1114                    finally {
1115                            closeSession(session);
1116                    }
1117            }
1118    
1119            protected ResourcePermission getByRoleId_PrevAndNext(Session session,
1120                    ResourcePermission resourcePermission, long roleId,
1121                    OrderByComparator orderByComparator, boolean previous) {
1122                    StringBundler query = null;
1123    
1124                    if (orderByComparator != null) {
1125                            query = new StringBundler(6 +
1126                                            (orderByComparator.getOrderByFields().length * 6));
1127                    }
1128                    else {
1129                            query = new StringBundler(3);
1130                    }
1131    
1132                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1133    
1134                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1135    
1136                    if (orderByComparator != null) {
1137                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1138    
1139                            if (orderByConditionFields.length > 0) {
1140                                    query.append(WHERE_AND);
1141                            }
1142    
1143                            for (int i = 0; i < orderByConditionFields.length; i++) {
1144                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1145                                    query.append(orderByConditionFields[i]);
1146    
1147                                    if ((i + 1) < orderByConditionFields.length) {
1148                                            if (orderByComparator.isAscending() ^ previous) {
1149                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1150                                            }
1151                                            else {
1152                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1153                                            }
1154                                    }
1155                                    else {
1156                                            if (orderByComparator.isAscending() ^ previous) {
1157                                                    query.append(WHERE_GREATER_THAN);
1158                                            }
1159                                            else {
1160                                                    query.append(WHERE_LESSER_THAN);
1161                                            }
1162                                    }
1163                            }
1164    
1165                            query.append(ORDER_BY_CLAUSE);
1166    
1167                            String[] orderByFields = orderByComparator.getOrderByFields();
1168    
1169                            for (int i = 0; i < orderByFields.length; i++) {
1170                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1171                                    query.append(orderByFields[i]);
1172    
1173                                    if ((i + 1) < orderByFields.length) {
1174                                            if (orderByComparator.isAscending() ^ previous) {
1175                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1176                                            }
1177                                            else {
1178                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1179                                            }
1180                                    }
1181                                    else {
1182                                            if (orderByComparator.isAscending() ^ previous) {
1183                                                    query.append(ORDER_BY_ASC);
1184                                            }
1185                                            else {
1186                                                    query.append(ORDER_BY_DESC);
1187                                            }
1188                                    }
1189                            }
1190                    }
1191                    else {
1192                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1193                    }
1194    
1195                    String sql = query.toString();
1196    
1197                    Query q = session.createQuery(sql);
1198    
1199                    q.setFirstResult(0);
1200                    q.setMaxResults(2);
1201    
1202                    QueryPos qPos = QueryPos.getInstance(q);
1203    
1204                    qPos.add(roleId);
1205    
1206                    if (orderByComparator != null) {
1207                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
1208    
1209                            for (Object value : values) {
1210                                    qPos.add(value);
1211                            }
1212                    }
1213    
1214                    List<ResourcePermission> list = q.list();
1215    
1216                    if (list.size() == 2) {
1217                            return list.get(1);
1218                    }
1219                    else {
1220                            return null;
1221                    }
1222            }
1223    
1224            /**
1225             * Removes all the resource permissions where roleId = &#63; from the database.
1226             *
1227             * @param roleId the role ID
1228             * @throws SystemException if a system exception occurred
1229             */
1230            public void removeByRoleId(long roleId) throws SystemException {
1231                    for (ResourcePermission resourcePermission : findByRoleId(roleId,
1232                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1233                            remove(resourcePermission);
1234                    }
1235            }
1236    
1237            /**
1238             * Returns the number of resource permissions where roleId = &#63;.
1239             *
1240             * @param roleId the role ID
1241             * @return the number of matching resource permissions
1242             * @throws SystemException if a system exception occurred
1243             */
1244            public int countByRoleId(long roleId) throws SystemException {
1245                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1246    
1247                    Object[] finderArgs = new Object[] { roleId };
1248    
1249                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1250                                    this);
1251    
1252                    if (count == null) {
1253                            StringBundler query = new StringBundler(2);
1254    
1255                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
1256    
1257                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1258    
1259                            String sql = query.toString();
1260    
1261                            Session session = null;
1262    
1263                            try {
1264                                    session = openSession();
1265    
1266                                    Query q = session.createQuery(sql);
1267    
1268                                    QueryPos qPos = QueryPos.getInstance(q);
1269    
1270                                    qPos.add(roleId);
1271    
1272                                    count = (Long)q.uniqueResult();
1273    
1274                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1275                            }
1276                            catch (Exception e) {
1277                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1278    
1279                                    throw processException(e);
1280                            }
1281                            finally {
1282                                    closeSession(session);
1283                            }
1284                    }
1285    
1286                    return count.intValue();
1287            }
1288    
1289            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourcePermission.roleId = ?";
1290            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1291                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
1292                            ResourcePermissionImpl.class,
1293                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
1294                            new String[] {
1295                                    Long.class.getName(), String.class.getName(),
1296                                    
1297                            Integer.class.getName(), Integer.class.getName(),
1298                                    OrderByComparator.class.getName()
1299                            });
1300            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1301                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1302                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_P",
1303                            new String[] { Long.class.getName(), String.class.getName() });
1304    
1305            /**
1306             * Returns all the resource permissions where companyId = &#63; and primKey LIKE &#63;.
1307             *
1308             * @param companyId the company ID
1309             * @param primKey the prim key
1310             * @return the matching resource permissions
1311             * @throws SystemException if a system exception occurred
1312             */
1313            public List<ResourcePermission> findByC_P(long companyId, String primKey)
1314                    throws SystemException {
1315                    return findByC_P(companyId, primKey, QueryUtil.ALL_POS,
1316                            QueryUtil.ALL_POS, null);
1317            }
1318    
1319            /**
1320             * Returns a range of all the resource permissions where companyId = &#63; and primKey LIKE &#63;.
1321             *
1322             * <p>
1323             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1324             * </p>
1325             *
1326             * @param companyId the company ID
1327             * @param primKey the prim key
1328             * @param start the lower bound of the range of resource permissions
1329             * @param end the upper bound of the range of resource permissions (not inclusive)
1330             * @return the range of matching resource permissions
1331             * @throws SystemException if a system exception occurred
1332             */
1333            public List<ResourcePermission> findByC_P(long companyId, String primKey,
1334                    int start, int end) throws SystemException {
1335                    return findByC_P(companyId, primKey, start, end, null);
1336            }
1337    
1338            /**
1339             * Returns an ordered range of all the resource permissions where companyId = &#63; and primKey LIKE &#63;.
1340             *
1341             * <p>
1342             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1343             * </p>
1344             *
1345             * @param companyId the company ID
1346             * @param primKey the prim key
1347             * @param start the lower bound of the range of resource permissions
1348             * @param end the upper bound of the range of resource permissions (not inclusive)
1349             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1350             * @return the ordered range of matching resource permissions
1351             * @throws SystemException if a system exception occurred
1352             */
1353            public List<ResourcePermission> findByC_P(long companyId, String primKey,
1354                    int start, int end, OrderByComparator orderByComparator)
1355                    throws SystemException {
1356                    boolean pagination = true;
1357                    FinderPath finderPath = null;
1358                    Object[] finderArgs = null;
1359    
1360                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
1361                    finderArgs = new Object[] {
1362                                    companyId, primKey,
1363                                    
1364                                    start, end, orderByComparator
1365                            };
1366    
1367                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1368                                    finderArgs, this);
1369    
1370                    if ((list != null) && !list.isEmpty()) {
1371                            for (ResourcePermission resourcePermission : list) {
1372                                    if ((companyId != resourcePermission.getCompanyId()) ||
1373                                                    !Validator.equals(primKey,
1374                                                            resourcePermission.getPrimKey())) {
1375                                            list = null;
1376    
1377                                            break;
1378                                    }
1379                            }
1380                    }
1381    
1382                    if (list == null) {
1383                            StringBundler query = null;
1384    
1385                            if (orderByComparator != null) {
1386                                    query = new StringBundler(4 +
1387                                                    (orderByComparator.getOrderByFields().length * 3));
1388                            }
1389                            else {
1390                                    query = new StringBundler(4);
1391                            }
1392    
1393                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1394    
1395                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1396    
1397                            if (primKey == null) {
1398                                    query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1399                            }
1400                            else {
1401                                    if (primKey.equals(StringPool.BLANK)) {
1402                                            query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1403                                    }
1404                                    else {
1405                                            query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1406                                    }
1407                            }
1408    
1409                            if (orderByComparator != null) {
1410                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1411                                            orderByComparator);
1412                            }
1413                            else
1414                             if (pagination) {
1415                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1416                            }
1417    
1418                            String sql = query.toString();
1419    
1420                            Session session = null;
1421    
1422                            try {
1423                                    session = openSession();
1424    
1425                                    Query q = session.createQuery(sql);
1426    
1427                                    QueryPos qPos = QueryPos.getInstance(q);
1428    
1429                                    qPos.add(companyId);
1430    
1431                                    if (primKey != null) {
1432                                            qPos.add(primKey);
1433                                    }
1434    
1435                                    if (!pagination) {
1436                                            list = (List<ResourcePermission>)QueryUtil.list(q,
1437                                                            getDialect(), start, end, false);
1438    
1439                                            Collections.sort(list);
1440    
1441                                            list = new UnmodifiableList<ResourcePermission>(list);
1442                                    }
1443                                    else {
1444                                            list = (List<ResourcePermission>)QueryUtil.list(q,
1445                                                            getDialect(), start, end);
1446                                    }
1447    
1448                                    cacheResult(list);
1449    
1450                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1451                            }
1452                            catch (Exception e) {
1453                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1454    
1455                                    throw processException(e);
1456                            }
1457                            finally {
1458                                    closeSession(session);
1459                            }
1460                    }
1461    
1462                    return list;
1463            }
1464    
1465            /**
1466             * Returns the first resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1467             *
1468             * @param companyId the company ID
1469             * @param primKey the prim key
1470             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1471             * @return the first matching resource permission
1472             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1473             * @throws SystemException if a system exception occurred
1474             */
1475            public ResourcePermission findByC_P_First(long companyId, String primKey,
1476                    OrderByComparator orderByComparator)
1477                    throws NoSuchResourcePermissionException, SystemException {
1478                    ResourcePermission resourcePermission = fetchByC_P_First(companyId,
1479                                    primKey, orderByComparator);
1480    
1481                    if (resourcePermission != null) {
1482                            return resourcePermission;
1483                    }
1484    
1485                    StringBundler msg = new StringBundler(6);
1486    
1487                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1488    
1489                    msg.append("companyId=");
1490                    msg.append(companyId);
1491    
1492                    msg.append(", primKey=");
1493                    msg.append(primKey);
1494    
1495                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1496    
1497                    throw new NoSuchResourcePermissionException(msg.toString());
1498            }
1499    
1500            /**
1501             * Returns the first resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1502             *
1503             * @param companyId the company ID
1504             * @param primKey the prim key
1505             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1506             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public ResourcePermission fetchByC_P_First(long companyId, String primKey,
1510                    OrderByComparator orderByComparator) throws SystemException {
1511                    List<ResourcePermission> list = findByC_P(companyId, primKey, 0, 1,
1512                                    orderByComparator);
1513    
1514                    if (!list.isEmpty()) {
1515                            return list.get(0);
1516                    }
1517    
1518                    return null;
1519            }
1520    
1521            /**
1522             * Returns the last resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1523             *
1524             * @param companyId the company ID
1525             * @param primKey the prim key
1526             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1527             * @return the last matching resource permission
1528             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1529             * @throws SystemException if a system exception occurred
1530             */
1531            public ResourcePermission findByC_P_Last(long companyId, String primKey,
1532                    OrderByComparator orderByComparator)
1533                    throws NoSuchResourcePermissionException, SystemException {
1534                    ResourcePermission resourcePermission = fetchByC_P_Last(companyId,
1535                                    primKey, orderByComparator);
1536    
1537                    if (resourcePermission != null) {
1538                            return resourcePermission;
1539                    }
1540    
1541                    StringBundler msg = new StringBundler(6);
1542    
1543                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1544    
1545                    msg.append("companyId=");
1546                    msg.append(companyId);
1547    
1548                    msg.append(", primKey=");
1549                    msg.append(primKey);
1550    
1551                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1552    
1553                    throw new NoSuchResourcePermissionException(msg.toString());
1554            }
1555    
1556            /**
1557             * Returns the last resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1558             *
1559             * @param companyId the company ID
1560             * @param primKey the prim key
1561             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1562             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
1563             * @throws SystemException if a system exception occurred
1564             */
1565            public ResourcePermission fetchByC_P_Last(long companyId, String primKey,
1566                    OrderByComparator orderByComparator) throws SystemException {
1567                    int count = countByC_P(companyId, primKey);
1568    
1569                    List<ResourcePermission> list = findByC_P(companyId, primKey,
1570                                    count - 1, count, orderByComparator);
1571    
1572                    if (!list.isEmpty()) {
1573                            return list.get(0);
1574                    }
1575    
1576                    return null;
1577            }
1578    
1579            /**
1580             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1581             *
1582             * @param resourcePermissionId the primary key of the current resource permission
1583             * @param companyId the company ID
1584             * @param primKey the prim key
1585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1586             * @return the previous, current, and next resource permission
1587             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1588             * @throws SystemException if a system exception occurred
1589             */
1590            public ResourcePermission[] findByC_P_PrevAndNext(
1591                    long resourcePermissionId, long companyId, String primKey,
1592                    OrderByComparator orderByComparator)
1593                    throws NoSuchResourcePermissionException, SystemException {
1594                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1595    
1596                    Session session = null;
1597    
1598                    try {
1599                            session = openSession();
1600    
1601                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1602    
1603                            array[0] = getByC_P_PrevAndNext(session, resourcePermission,
1604                                            companyId, primKey, orderByComparator, true);
1605    
1606                            array[1] = resourcePermission;
1607    
1608                            array[2] = getByC_P_PrevAndNext(session, resourcePermission,
1609                                            companyId, primKey, orderByComparator, false);
1610    
1611                            return array;
1612                    }
1613                    catch (Exception e) {
1614                            throw processException(e);
1615                    }
1616                    finally {
1617                            closeSession(session);
1618                    }
1619            }
1620    
1621            protected ResourcePermission getByC_P_PrevAndNext(Session session,
1622                    ResourcePermission resourcePermission, long companyId, String primKey,
1623                    OrderByComparator orderByComparator, boolean previous) {
1624                    StringBundler query = null;
1625    
1626                    if (orderByComparator != null) {
1627                            query = new StringBundler(6 +
1628                                            (orderByComparator.getOrderByFields().length * 6));
1629                    }
1630                    else {
1631                            query = new StringBundler(3);
1632                    }
1633    
1634                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1635    
1636                    query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1637    
1638                    if (primKey == null) {
1639                            query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1640                    }
1641                    else {
1642                            if (primKey.equals(StringPool.BLANK)) {
1643                                    query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1644                            }
1645                            else {
1646                                    query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1647                            }
1648                    }
1649    
1650                    if (orderByComparator != null) {
1651                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1652    
1653                            if (orderByConditionFields.length > 0) {
1654                                    query.append(WHERE_AND);
1655                            }
1656    
1657                            for (int i = 0; i < orderByConditionFields.length; i++) {
1658                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1659                                    query.append(orderByConditionFields[i]);
1660    
1661                                    if ((i + 1) < orderByConditionFields.length) {
1662                                            if (orderByComparator.isAscending() ^ previous) {
1663                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1664                                            }
1665                                            else {
1666                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1667                                            }
1668                                    }
1669                                    else {
1670                                            if (orderByComparator.isAscending() ^ previous) {
1671                                                    query.append(WHERE_GREATER_THAN);
1672                                            }
1673                                            else {
1674                                                    query.append(WHERE_LESSER_THAN);
1675                                            }
1676                                    }
1677                            }
1678    
1679                            query.append(ORDER_BY_CLAUSE);
1680    
1681                            String[] orderByFields = orderByComparator.getOrderByFields();
1682    
1683                            for (int i = 0; i < orderByFields.length; i++) {
1684                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1685                                    query.append(orderByFields[i]);
1686    
1687                                    if ((i + 1) < orderByFields.length) {
1688                                            if (orderByComparator.isAscending() ^ previous) {
1689                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1690                                            }
1691                                            else {
1692                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1693                                            }
1694                                    }
1695                                    else {
1696                                            if (orderByComparator.isAscending() ^ previous) {
1697                                                    query.append(ORDER_BY_ASC);
1698                                            }
1699                                            else {
1700                                                    query.append(ORDER_BY_DESC);
1701                                            }
1702                                    }
1703                            }
1704                    }
1705                    else {
1706                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1707                    }
1708    
1709                    String sql = query.toString();
1710    
1711                    Query q = session.createQuery(sql);
1712    
1713                    q.setFirstResult(0);
1714                    q.setMaxResults(2);
1715    
1716                    QueryPos qPos = QueryPos.getInstance(q);
1717    
1718                    qPos.add(companyId);
1719    
1720                    if (primKey != null) {
1721                            qPos.add(primKey);
1722                    }
1723    
1724                    if (orderByComparator != null) {
1725                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
1726    
1727                            for (Object value : values) {
1728                                    qPos.add(value);
1729                            }
1730                    }
1731    
1732                    List<ResourcePermission> list = q.list();
1733    
1734                    if (list.size() == 2) {
1735                            return list.get(1);
1736                    }
1737                    else {
1738                            return null;
1739                    }
1740            }
1741    
1742            /**
1743             * Removes all the resource permissions where companyId = &#63; and primKey LIKE &#63; from the database.
1744             *
1745             * @param companyId the company ID
1746             * @param primKey the prim key
1747             * @throws SystemException if a system exception occurred
1748             */
1749            public void removeByC_P(long companyId, String primKey)
1750                    throws SystemException {
1751                    for (ResourcePermission resourcePermission : findByC_P(companyId,
1752                                    primKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1753                            remove(resourcePermission);
1754                    }
1755            }
1756    
1757            /**
1758             * Returns the number of resource permissions where companyId = &#63; and primKey LIKE &#63;.
1759             *
1760             * @param companyId the company ID
1761             * @param primKey the prim key
1762             * @return the number of matching resource permissions
1763             * @throws SystemException if a system exception occurred
1764             */
1765            public int countByC_P(long companyId, String primKey)
1766                    throws SystemException {
1767                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_P;
1768    
1769                    Object[] finderArgs = new Object[] { companyId, primKey };
1770    
1771                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1772                                    this);
1773    
1774                    if (count == null) {
1775                            StringBundler query = new StringBundler(3);
1776    
1777                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
1778    
1779                            query.append(_FINDER_COLUMN_C_P_COMPANYID_2);
1780    
1781                            if (primKey == null) {
1782                                    query.append(_FINDER_COLUMN_C_P_PRIMKEY_1);
1783                            }
1784                            else {
1785                                    if (primKey.equals(StringPool.BLANK)) {
1786                                            query.append(_FINDER_COLUMN_C_P_PRIMKEY_3);
1787                                    }
1788                                    else {
1789                                            query.append(_FINDER_COLUMN_C_P_PRIMKEY_2);
1790                                    }
1791                            }
1792    
1793                            String sql = query.toString();
1794    
1795                            Session session = null;
1796    
1797                            try {
1798                                    session = openSession();
1799    
1800                                    Query q = session.createQuery(sql);
1801    
1802                                    QueryPos qPos = QueryPos.getInstance(q);
1803    
1804                                    qPos.add(companyId);
1805    
1806                                    if (primKey != null) {
1807                                            qPos.add(primKey);
1808                                    }
1809    
1810                                    count = (Long)q.uniqueResult();
1811    
1812                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1813                            }
1814                            catch (Exception e) {
1815                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1816    
1817                                    throw processException(e);
1818                            }
1819                            finally {
1820                                    closeSession(session);
1821                            }
1822                    }
1823    
1824                    return count.intValue();
1825            }
1826    
1827            private static final String _FINDER_COLUMN_C_P_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
1828            private static final String _FINDER_COLUMN_C_P_PRIMKEY_1 = "resourcePermission.primKey LIKE NULL";
1829            private static final String _FINDER_COLUMN_C_P_PRIMKEY_2 = "resourcePermission.primKey LIKE ?";
1830            private static final String _FINDER_COLUMN_C_P_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey LIKE ?)";
1831            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1832                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
1833                            ResourcePermissionImpl.class,
1834                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S",
1835                            new String[] {
1836                                    Long.class.getName(), String.class.getName(),
1837                                    Integer.class.getName(),
1838                                    
1839                            Integer.class.getName(), Integer.class.getName(),
1840                                    OrderByComparator.class.getName()
1841                            });
1842            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1843                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
1844                            ResourcePermissionImpl.class,
1845                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S",
1846                            new String[] {
1847                                    Long.class.getName(), String.class.getName(),
1848                                    Integer.class.getName()
1849                            },
1850                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
1851                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
1852                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK);
1853            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1854                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1855                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S",
1856                            new String[] {
1857                                    Long.class.getName(), String.class.getName(),
1858                                    Integer.class.getName()
1859                            });
1860    
1861            /**
1862             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1863             *
1864             * @param companyId the company ID
1865             * @param name the name
1866             * @param scope the scope
1867             * @return the matching resource permissions
1868             * @throws SystemException if a system exception occurred
1869             */
1870            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1871                    int scope) throws SystemException {
1872                    return findByC_N_S(companyId, name, scope, QueryUtil.ALL_POS,
1873                            QueryUtil.ALL_POS, null);
1874            }
1875    
1876            /**
1877             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1878             *
1879             * <p>
1880             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1881             * </p>
1882             *
1883             * @param companyId the company ID
1884             * @param name the name
1885             * @param scope the scope
1886             * @param start the lower bound of the range of resource permissions
1887             * @param end the upper bound of the range of resource permissions (not inclusive)
1888             * @return the range of matching resource permissions
1889             * @throws SystemException if a system exception occurred
1890             */
1891            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1892                    int scope, int start, int end) throws SystemException {
1893                    return findByC_N_S(companyId, name, scope, start, end, null);
1894            }
1895    
1896            /**
1897             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1898             *
1899             * <p>
1900             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1901             * </p>
1902             *
1903             * @param companyId the company ID
1904             * @param name the name
1905             * @param scope the scope
1906             * @param start the lower bound of the range of resource permissions
1907             * @param end the upper bound of the range of resource permissions (not inclusive)
1908             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1909             * @return the ordered range of matching resource permissions
1910             * @throws SystemException if a system exception occurred
1911             */
1912            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1913                    int scope, int start, int end, OrderByComparator orderByComparator)
1914                    throws SystemException {
1915                    boolean pagination = true;
1916                    FinderPath finderPath = null;
1917                    Object[] finderArgs = null;
1918    
1919                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1920                                    (orderByComparator == null)) {
1921                            pagination = false;
1922                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S;
1923                            finderArgs = new Object[] { companyId, name, scope };
1924                    }
1925                    else {
1926                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S;
1927                            finderArgs = new Object[] {
1928                                            companyId, name, scope,
1929                                            
1930                                            start, end, orderByComparator
1931                                    };
1932                    }
1933    
1934                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1935                                    finderArgs, this);
1936    
1937                    if ((list != null) && !list.isEmpty()) {
1938                            for (ResourcePermission resourcePermission : list) {
1939                                    if ((companyId != resourcePermission.getCompanyId()) ||
1940                                                    !Validator.equals(name, resourcePermission.getName()) ||
1941                                                    (scope != resourcePermission.getScope())) {
1942                                            list = null;
1943    
1944                                            break;
1945                                    }
1946                            }
1947                    }
1948    
1949                    if (list == null) {
1950                            StringBundler query = null;
1951    
1952                            if (orderByComparator != null) {
1953                                    query = new StringBundler(5 +
1954                                                    (orderByComparator.getOrderByFields().length * 3));
1955                            }
1956                            else {
1957                                    query = new StringBundler(5);
1958                            }
1959    
1960                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1961    
1962                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1963    
1964                            if (name == null) {
1965                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1966                            }
1967                            else {
1968                                    if (name.equals(StringPool.BLANK)) {
1969                                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1970                                    }
1971                                    else {
1972                                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1973                                    }
1974                            }
1975    
1976                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1977    
1978                            if (orderByComparator != null) {
1979                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1980                                            orderByComparator);
1981                            }
1982                            else
1983                             if (pagination) {
1984                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1985                            }
1986    
1987                            String sql = query.toString();
1988    
1989                            Session session = null;
1990    
1991                            try {
1992                                    session = openSession();
1993    
1994                                    Query q = session.createQuery(sql);
1995    
1996                                    QueryPos qPos = QueryPos.getInstance(q);
1997    
1998                                    qPos.add(companyId);
1999    
2000                                    if (name != null) {
2001                                            qPos.add(name);
2002                                    }
2003    
2004                                    qPos.add(scope);
2005    
2006                                    if (!pagination) {
2007                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2008                                                            getDialect(), start, end, false);
2009    
2010                                            Collections.sort(list);
2011    
2012                                            list = new UnmodifiableList<ResourcePermission>(list);
2013                                    }
2014                                    else {
2015                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2016                                                            getDialect(), start, end);
2017                                    }
2018    
2019                                    cacheResult(list);
2020    
2021                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2022                            }
2023                            catch (Exception e) {
2024                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2025    
2026                                    throw processException(e);
2027                            }
2028                            finally {
2029                                    closeSession(session);
2030                            }
2031                    }
2032    
2033                    return list;
2034            }
2035    
2036            /**
2037             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2038             *
2039             * @param companyId the company ID
2040             * @param name the name
2041             * @param scope the scope
2042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2043             * @return the first matching resource permission
2044             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2045             * @throws SystemException if a system exception occurred
2046             */
2047            public ResourcePermission findByC_N_S_First(long companyId, String name,
2048                    int scope, OrderByComparator orderByComparator)
2049                    throws NoSuchResourcePermissionException, SystemException {
2050                    ResourcePermission resourcePermission = fetchByC_N_S_First(companyId,
2051                                    name, scope, orderByComparator);
2052    
2053                    if (resourcePermission != null) {
2054                            return resourcePermission;
2055                    }
2056    
2057                    StringBundler msg = new StringBundler(8);
2058    
2059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2060    
2061                    msg.append("companyId=");
2062                    msg.append(companyId);
2063    
2064                    msg.append(", name=");
2065                    msg.append(name);
2066    
2067                    msg.append(", scope=");
2068                    msg.append(scope);
2069    
2070                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2071    
2072                    throw new NoSuchResourcePermissionException(msg.toString());
2073            }
2074    
2075            /**
2076             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2077             *
2078             * @param companyId the company ID
2079             * @param name the name
2080             * @param scope the scope
2081             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2082             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
2083             * @throws SystemException if a system exception occurred
2084             */
2085            public ResourcePermission fetchByC_N_S_First(long companyId, String name,
2086                    int scope, OrderByComparator orderByComparator)
2087                    throws SystemException {
2088                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope, 0,
2089                                    1, orderByComparator);
2090    
2091                    if (!list.isEmpty()) {
2092                            return list.get(0);
2093                    }
2094    
2095                    return null;
2096            }
2097    
2098            /**
2099             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2100             *
2101             * @param companyId the company ID
2102             * @param name the name
2103             * @param scope the scope
2104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2105             * @return the last matching resource permission
2106             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2107             * @throws SystemException if a system exception occurred
2108             */
2109            public ResourcePermission findByC_N_S_Last(long companyId, String name,
2110                    int scope, OrderByComparator orderByComparator)
2111                    throws NoSuchResourcePermissionException, SystemException {
2112                    ResourcePermission resourcePermission = fetchByC_N_S_Last(companyId,
2113                                    name, scope, orderByComparator);
2114    
2115                    if (resourcePermission != null) {
2116                            return resourcePermission;
2117                    }
2118    
2119                    StringBundler msg = new StringBundler(8);
2120    
2121                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2122    
2123                    msg.append("companyId=");
2124                    msg.append(companyId);
2125    
2126                    msg.append(", name=");
2127                    msg.append(name);
2128    
2129                    msg.append(", scope=");
2130                    msg.append(scope);
2131    
2132                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2133    
2134                    throw new NoSuchResourcePermissionException(msg.toString());
2135            }
2136    
2137            /**
2138             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2139             *
2140             * @param companyId the company ID
2141             * @param name the name
2142             * @param scope the scope
2143             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2144             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
2145             * @throws SystemException if a system exception occurred
2146             */
2147            public ResourcePermission fetchByC_N_S_Last(long companyId, String name,
2148                    int scope, OrderByComparator orderByComparator)
2149                    throws SystemException {
2150                    int count = countByC_N_S(companyId, name, scope);
2151    
2152                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope,
2153                                    count - 1, count, orderByComparator);
2154    
2155                    if (!list.isEmpty()) {
2156                            return list.get(0);
2157                    }
2158    
2159                    return null;
2160            }
2161    
2162            /**
2163             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2164             *
2165             * @param resourcePermissionId the primary key of the current resource permission
2166             * @param companyId the company ID
2167             * @param name the name
2168             * @param scope the scope
2169             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2170             * @return the previous, current, and next resource permission
2171             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2172             * @throws SystemException if a system exception occurred
2173             */
2174            public ResourcePermission[] findByC_N_S_PrevAndNext(
2175                    long resourcePermissionId, long companyId, String name, int scope,
2176                    OrderByComparator orderByComparator)
2177                    throws NoSuchResourcePermissionException, SystemException {
2178                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2179    
2180                    Session session = null;
2181    
2182                    try {
2183                            session = openSession();
2184    
2185                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2186    
2187                            array[0] = getByC_N_S_PrevAndNext(session, resourcePermission,
2188                                            companyId, name, scope, orderByComparator, true);
2189    
2190                            array[1] = resourcePermission;
2191    
2192                            array[2] = getByC_N_S_PrevAndNext(session, resourcePermission,
2193                                            companyId, name, scope, orderByComparator, false);
2194    
2195                            return array;
2196                    }
2197                    catch (Exception e) {
2198                            throw processException(e);
2199                    }
2200                    finally {
2201                            closeSession(session);
2202                    }
2203            }
2204    
2205            protected ResourcePermission getByC_N_S_PrevAndNext(Session session,
2206                    ResourcePermission resourcePermission, long companyId, String name,
2207                    int scope, OrderByComparator orderByComparator, boolean previous) {
2208                    StringBundler query = null;
2209    
2210                    if (orderByComparator != null) {
2211                            query = new StringBundler(6 +
2212                                            (orderByComparator.getOrderByFields().length * 6));
2213                    }
2214                    else {
2215                            query = new StringBundler(3);
2216                    }
2217    
2218                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2219    
2220                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2221    
2222                    if (name == null) {
2223                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2224                    }
2225                    else {
2226                            if (name.equals(StringPool.BLANK)) {
2227                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2228                            }
2229                            else {
2230                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2231                            }
2232                    }
2233    
2234                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2235    
2236                    if (orderByComparator != null) {
2237                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2238    
2239                            if (orderByConditionFields.length > 0) {
2240                                    query.append(WHERE_AND);
2241                            }
2242    
2243                            for (int i = 0; i < orderByConditionFields.length; i++) {
2244                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2245                                    query.append(orderByConditionFields[i]);
2246    
2247                                    if ((i + 1) < orderByConditionFields.length) {
2248                                            if (orderByComparator.isAscending() ^ previous) {
2249                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2250                                            }
2251                                            else {
2252                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2253                                            }
2254                                    }
2255                                    else {
2256                                            if (orderByComparator.isAscending() ^ previous) {
2257                                                    query.append(WHERE_GREATER_THAN);
2258                                            }
2259                                            else {
2260                                                    query.append(WHERE_LESSER_THAN);
2261                                            }
2262                                    }
2263                            }
2264    
2265                            query.append(ORDER_BY_CLAUSE);
2266    
2267                            String[] orderByFields = orderByComparator.getOrderByFields();
2268    
2269                            for (int i = 0; i < orderByFields.length; i++) {
2270                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2271                                    query.append(orderByFields[i]);
2272    
2273                                    if ((i + 1) < orderByFields.length) {
2274                                            if (orderByComparator.isAscending() ^ previous) {
2275                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2276                                            }
2277                                            else {
2278                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2279                                            }
2280                                    }
2281                                    else {
2282                                            if (orderByComparator.isAscending() ^ previous) {
2283                                                    query.append(ORDER_BY_ASC);
2284                                            }
2285                                            else {
2286                                                    query.append(ORDER_BY_DESC);
2287                                            }
2288                                    }
2289                            }
2290                    }
2291                    else {
2292                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
2293                    }
2294    
2295                    String sql = query.toString();
2296    
2297                    Query q = session.createQuery(sql);
2298    
2299                    q.setFirstResult(0);
2300                    q.setMaxResults(2);
2301    
2302                    QueryPos qPos = QueryPos.getInstance(q);
2303    
2304                    qPos.add(companyId);
2305    
2306                    if (name != null) {
2307                            qPos.add(name);
2308                    }
2309    
2310                    qPos.add(scope);
2311    
2312                    if (orderByComparator != null) {
2313                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
2314    
2315                            for (Object value : values) {
2316                                    qPos.add(value);
2317                            }
2318                    }
2319    
2320                    List<ResourcePermission> list = q.list();
2321    
2322                    if (list.size() == 2) {
2323                            return list.get(1);
2324                    }
2325                    else {
2326                            return null;
2327                    }
2328            }
2329    
2330            /**
2331             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; from the database.
2332             *
2333             * @param companyId the company ID
2334             * @param name the name
2335             * @param scope the scope
2336             * @throws SystemException if a system exception occurred
2337             */
2338            public void removeByC_N_S(long companyId, String name, int scope)
2339                    throws SystemException {
2340                    for (ResourcePermission resourcePermission : findByC_N_S(companyId,
2341                                    name, scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2342                            remove(resourcePermission);
2343                    }
2344            }
2345    
2346            /**
2347             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
2348             *
2349             * @param companyId the company ID
2350             * @param name the name
2351             * @param scope the scope
2352             * @return the number of matching resource permissions
2353             * @throws SystemException if a system exception occurred
2354             */
2355            public int countByC_N_S(long companyId, String name, int scope)
2356                    throws SystemException {
2357                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S;
2358    
2359                    Object[] finderArgs = new Object[] { companyId, name, scope };
2360    
2361                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2362                                    this);
2363    
2364                    if (count == null) {
2365                            StringBundler query = new StringBundler(4);
2366    
2367                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2368    
2369                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2370    
2371                            if (name == null) {
2372                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2373                            }
2374                            else {
2375                                    if (name.equals(StringPool.BLANK)) {
2376                                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2377                                    }
2378                                    else {
2379                                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2380                                    }
2381                            }
2382    
2383                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2384    
2385                            String sql = query.toString();
2386    
2387                            Session session = null;
2388    
2389                            try {
2390                                    session = openSession();
2391    
2392                                    Query q = session.createQuery(sql);
2393    
2394                                    QueryPos qPos = QueryPos.getInstance(q);
2395    
2396                                    qPos.add(companyId);
2397    
2398                                    if (name != null) {
2399                                            qPos.add(name);
2400                                    }
2401    
2402                                    qPos.add(scope);
2403    
2404                                    count = (Long)q.uniqueResult();
2405    
2406                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2407                            }
2408                            catch (Exception e) {
2409                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2410    
2411                                    throw processException(e);
2412                            }
2413                            finally {
2414                                    closeSession(session);
2415                            }
2416                    }
2417    
2418                    return count.intValue();
2419            }
2420    
2421            private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
2422            private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourcePermission.name IS NULL AND ";
2423            private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourcePermission.name = ? AND ";
2424            private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
2425            private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourcePermission.scope = ?";
2426            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
2427                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
2428                            ResourcePermissionImpl.class,
2429                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P_R",
2430                            new String[] {
2431                                    Long.class.getName(), String.class.getName(),
2432                                    Long.class.getName(),
2433                                    
2434                            Integer.class.getName(), Integer.class.getName(),
2435                                    OrderByComparator.class.getName()
2436                            });
2437            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
2438                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
2439                            ResourcePermissionImpl.class,
2440                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P_R",
2441                            new String[] {
2442                                    Long.class.getName(), String.class.getName(),
2443                                    Long.class.getName()
2444                            },
2445                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
2446                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
2447                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
2448            public static final FinderPath FINDER_PATH_COUNT_BY_C_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
2449                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2450                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P_R",
2451                            new String[] {
2452                                    Long.class.getName(), String.class.getName(),
2453                                    Long.class.getName()
2454                            });
2455    
2456            /**
2457             * Returns all the resource permissions where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2458             *
2459             * @param companyId the company ID
2460             * @param primKey the prim key
2461             * @param roleId the role ID
2462             * @return the matching resource permissions
2463             * @throws SystemException if a system exception occurred
2464             */
2465            public List<ResourcePermission> findByC_P_R(long companyId, String primKey,
2466                    long roleId) throws SystemException {
2467                    return findByC_P_R(companyId, primKey, roleId, QueryUtil.ALL_POS,
2468                            QueryUtil.ALL_POS, null);
2469            }
2470    
2471            /**
2472             * Returns a range of all the resource permissions where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2473             *
2474             * <p>
2475             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2476             * </p>
2477             *
2478             * @param companyId the company ID
2479             * @param primKey the prim key
2480             * @param roleId the role ID
2481             * @param start the lower bound of the range of resource permissions
2482             * @param end the upper bound of the range of resource permissions (not inclusive)
2483             * @return the range of matching resource permissions
2484             * @throws SystemException if a system exception occurred
2485             */
2486            public List<ResourcePermission> findByC_P_R(long companyId, String primKey,
2487                    long roleId, int start, int end) throws SystemException {
2488                    return findByC_P_R(companyId, primKey, roleId, start, end, null);
2489            }
2490    
2491            /**
2492             * Returns an ordered range of all the resource permissions where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2493             *
2494             * <p>
2495             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2496             * </p>
2497             *
2498             * @param companyId the company ID
2499             * @param primKey the prim key
2500             * @param roleId the role ID
2501             * @param start the lower bound of the range of resource permissions
2502             * @param end the upper bound of the range of resource permissions (not inclusive)
2503             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2504             * @return the ordered range of matching resource permissions
2505             * @throws SystemException if a system exception occurred
2506             */
2507            public List<ResourcePermission> findByC_P_R(long companyId, String primKey,
2508                    long roleId, int start, int end, OrderByComparator orderByComparator)
2509                    throws SystemException {
2510                    boolean pagination = true;
2511                    FinderPath finderPath = null;
2512                    Object[] finderArgs = null;
2513    
2514                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2515                                    (orderByComparator == null)) {
2516                            pagination = false;
2517                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_R;
2518                            finderArgs = new Object[] { companyId, primKey, roleId };
2519                    }
2520                    else {
2521                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P_R;
2522                            finderArgs = new Object[] {
2523                                            companyId, primKey, roleId,
2524                                            
2525                                            start, end, orderByComparator
2526                                    };
2527                    }
2528    
2529                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
2530                                    finderArgs, this);
2531    
2532                    if ((list != null) && !list.isEmpty()) {
2533                            for (ResourcePermission resourcePermission : list) {
2534                                    if ((companyId != resourcePermission.getCompanyId()) ||
2535                                                    !Validator.equals(primKey,
2536                                                            resourcePermission.getPrimKey()) ||
2537                                                    (roleId != resourcePermission.getRoleId())) {
2538                                            list = null;
2539    
2540                                            break;
2541                                    }
2542                            }
2543                    }
2544    
2545                    if (list == null) {
2546                            StringBundler query = null;
2547    
2548                            if (orderByComparator != null) {
2549                                    query = new StringBundler(5 +
2550                                                    (orderByComparator.getOrderByFields().length * 3));
2551                            }
2552                            else {
2553                                    query = new StringBundler(5);
2554                            }
2555    
2556                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2557    
2558                            query.append(_FINDER_COLUMN_C_P_R_COMPANYID_2);
2559    
2560                            if (primKey == null) {
2561                                    query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_1);
2562                            }
2563                            else {
2564                                    if (primKey.equals(StringPool.BLANK)) {
2565                                            query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_3);
2566                                    }
2567                                    else {
2568                                            query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_2);
2569                                    }
2570                            }
2571    
2572                            query.append(_FINDER_COLUMN_C_P_R_ROLEID_2);
2573    
2574                            if (orderByComparator != null) {
2575                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2576                                            orderByComparator);
2577                            }
2578                            else
2579                             if (pagination) {
2580                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
2581                            }
2582    
2583                            String sql = query.toString();
2584    
2585                            Session session = null;
2586    
2587                            try {
2588                                    session = openSession();
2589    
2590                                    Query q = session.createQuery(sql);
2591    
2592                                    QueryPos qPos = QueryPos.getInstance(q);
2593    
2594                                    qPos.add(companyId);
2595    
2596                                    if (primKey != null) {
2597                                            qPos.add(primKey);
2598                                    }
2599    
2600                                    qPos.add(roleId);
2601    
2602                                    if (!pagination) {
2603                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2604                                                            getDialect(), start, end, false);
2605    
2606                                            Collections.sort(list);
2607    
2608                                            list = new UnmodifiableList<ResourcePermission>(list);
2609                                    }
2610                                    else {
2611                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2612                                                            getDialect(), start, end);
2613                                    }
2614    
2615                                    cacheResult(list);
2616    
2617                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2618                            }
2619                            catch (Exception e) {
2620                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2621    
2622                                    throw processException(e);
2623                            }
2624                            finally {
2625                                    closeSession(session);
2626                            }
2627                    }
2628    
2629                    return list;
2630            }
2631    
2632            /**
2633             * Returns the first resource permission in the ordered set where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2634             *
2635             * @param companyId the company ID
2636             * @param primKey the prim key
2637             * @param roleId the role ID
2638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2639             * @return the first matching resource permission
2640             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2641             * @throws SystemException if a system exception occurred
2642             */
2643            public ResourcePermission findByC_P_R_First(long companyId, String primKey,
2644                    long roleId, OrderByComparator orderByComparator)
2645                    throws NoSuchResourcePermissionException, SystemException {
2646                    ResourcePermission resourcePermission = fetchByC_P_R_First(companyId,
2647                                    primKey, roleId, orderByComparator);
2648    
2649                    if (resourcePermission != null) {
2650                            return resourcePermission;
2651                    }
2652    
2653                    StringBundler msg = new StringBundler(8);
2654    
2655                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2656    
2657                    msg.append("companyId=");
2658                    msg.append(companyId);
2659    
2660                    msg.append(", primKey=");
2661                    msg.append(primKey);
2662    
2663                    msg.append(", roleId=");
2664                    msg.append(roleId);
2665    
2666                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2667    
2668                    throw new NoSuchResourcePermissionException(msg.toString());
2669            }
2670    
2671            /**
2672             * Returns the first resource permission in the ordered set where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2673             *
2674             * @param companyId the company ID
2675             * @param primKey the prim key
2676             * @param roleId the role ID
2677             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2678             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
2679             * @throws SystemException if a system exception occurred
2680             */
2681            public ResourcePermission fetchByC_P_R_First(long companyId,
2682                    String primKey, long roleId, OrderByComparator orderByComparator)
2683                    throws SystemException {
2684                    List<ResourcePermission> list = findByC_P_R(companyId, primKey, roleId,
2685                                    0, 1, orderByComparator);
2686    
2687                    if (!list.isEmpty()) {
2688                            return list.get(0);
2689                    }
2690    
2691                    return null;
2692            }
2693    
2694            /**
2695             * Returns the last resource permission in the ordered set where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2696             *
2697             * @param companyId the company ID
2698             * @param primKey the prim key
2699             * @param roleId the role ID
2700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2701             * @return the last matching resource permission
2702             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2703             * @throws SystemException if a system exception occurred
2704             */
2705            public ResourcePermission findByC_P_R_Last(long companyId, String primKey,
2706                    long roleId, OrderByComparator orderByComparator)
2707                    throws NoSuchResourcePermissionException, SystemException {
2708                    ResourcePermission resourcePermission = fetchByC_P_R_Last(companyId,
2709                                    primKey, roleId, orderByComparator);
2710    
2711                    if (resourcePermission != null) {
2712                            return resourcePermission;
2713                    }
2714    
2715                    StringBundler msg = new StringBundler(8);
2716    
2717                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2718    
2719                    msg.append("companyId=");
2720                    msg.append(companyId);
2721    
2722                    msg.append(", primKey=");
2723                    msg.append(primKey);
2724    
2725                    msg.append(", roleId=");
2726                    msg.append(roleId);
2727    
2728                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2729    
2730                    throw new NoSuchResourcePermissionException(msg.toString());
2731            }
2732    
2733            /**
2734             * Returns the last resource permission in the ordered set where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2735             *
2736             * @param companyId the company ID
2737             * @param primKey the prim key
2738             * @param roleId the role ID
2739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2740             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
2741             * @throws SystemException if a system exception occurred
2742             */
2743            public ResourcePermission fetchByC_P_R_Last(long companyId, String primKey,
2744                    long roleId, OrderByComparator orderByComparator)
2745                    throws SystemException {
2746                    int count = countByC_P_R(companyId, primKey, roleId);
2747    
2748                    List<ResourcePermission> list = findByC_P_R(companyId, primKey, roleId,
2749                                    count - 1, count, orderByComparator);
2750    
2751                    if (!list.isEmpty()) {
2752                            return list.get(0);
2753                    }
2754    
2755                    return null;
2756            }
2757    
2758            /**
2759             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2760             *
2761             * @param resourcePermissionId the primary key of the current resource permission
2762             * @param companyId the company ID
2763             * @param primKey the prim key
2764             * @param roleId the role ID
2765             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2766             * @return the previous, current, and next resource permission
2767             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2768             * @throws SystemException if a system exception occurred
2769             */
2770            public ResourcePermission[] findByC_P_R_PrevAndNext(
2771                    long resourcePermissionId, long companyId, String primKey, long roleId,
2772                    OrderByComparator orderByComparator)
2773                    throws NoSuchResourcePermissionException, SystemException {
2774                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2775    
2776                    Session session = null;
2777    
2778                    try {
2779                            session = openSession();
2780    
2781                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2782    
2783                            array[0] = getByC_P_R_PrevAndNext(session, resourcePermission,
2784                                            companyId, primKey, roleId, orderByComparator, true);
2785    
2786                            array[1] = resourcePermission;
2787    
2788                            array[2] = getByC_P_R_PrevAndNext(session, resourcePermission,
2789                                            companyId, primKey, roleId, orderByComparator, false);
2790    
2791                            return array;
2792                    }
2793                    catch (Exception e) {
2794                            throw processException(e);
2795                    }
2796                    finally {
2797                            closeSession(session);
2798                    }
2799            }
2800    
2801            protected ResourcePermission getByC_P_R_PrevAndNext(Session session,
2802                    ResourcePermission resourcePermission, long companyId, String primKey,
2803                    long roleId, OrderByComparator orderByComparator, boolean previous) {
2804                    StringBundler query = null;
2805    
2806                    if (orderByComparator != null) {
2807                            query = new StringBundler(6 +
2808                                            (orderByComparator.getOrderByFields().length * 6));
2809                    }
2810                    else {
2811                            query = new StringBundler(3);
2812                    }
2813    
2814                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2815    
2816                    query.append(_FINDER_COLUMN_C_P_R_COMPANYID_2);
2817    
2818                    if (primKey == null) {
2819                            query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_1);
2820                    }
2821                    else {
2822                            if (primKey.equals(StringPool.BLANK)) {
2823                                    query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_3);
2824                            }
2825                            else {
2826                                    query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_2);
2827                            }
2828                    }
2829    
2830                    query.append(_FINDER_COLUMN_C_P_R_ROLEID_2);
2831    
2832                    if (orderByComparator != null) {
2833                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2834    
2835                            if (orderByConditionFields.length > 0) {
2836                                    query.append(WHERE_AND);
2837                            }
2838    
2839                            for (int i = 0; i < orderByConditionFields.length; i++) {
2840                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2841                                    query.append(orderByConditionFields[i]);
2842    
2843                                    if ((i + 1) < orderByConditionFields.length) {
2844                                            if (orderByComparator.isAscending() ^ previous) {
2845                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2846                                            }
2847                                            else {
2848                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2849                                            }
2850                                    }
2851                                    else {
2852                                            if (orderByComparator.isAscending() ^ previous) {
2853                                                    query.append(WHERE_GREATER_THAN);
2854                                            }
2855                                            else {
2856                                                    query.append(WHERE_LESSER_THAN);
2857                                            }
2858                                    }
2859                            }
2860    
2861                            query.append(ORDER_BY_CLAUSE);
2862    
2863                            String[] orderByFields = orderByComparator.getOrderByFields();
2864    
2865                            for (int i = 0; i < orderByFields.length; i++) {
2866                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2867                                    query.append(orderByFields[i]);
2868    
2869                                    if ((i + 1) < orderByFields.length) {
2870                                            if (orderByComparator.isAscending() ^ previous) {
2871                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2872                                            }
2873                                            else {
2874                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2875                                            }
2876                                    }
2877                                    else {
2878                                            if (orderByComparator.isAscending() ^ previous) {
2879                                                    query.append(ORDER_BY_ASC);
2880                                            }
2881                                            else {
2882                                                    query.append(ORDER_BY_DESC);
2883                                            }
2884                                    }
2885                            }
2886                    }
2887                    else {
2888                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
2889                    }
2890    
2891                    String sql = query.toString();
2892    
2893                    Query q = session.createQuery(sql);
2894    
2895                    q.setFirstResult(0);
2896                    q.setMaxResults(2);
2897    
2898                    QueryPos qPos = QueryPos.getInstance(q);
2899    
2900                    qPos.add(companyId);
2901    
2902                    if (primKey != null) {
2903                            qPos.add(primKey);
2904                    }
2905    
2906                    qPos.add(roleId);
2907    
2908                    if (orderByComparator != null) {
2909                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
2910    
2911                            for (Object value : values) {
2912                                    qPos.add(value);
2913                            }
2914                    }
2915    
2916                    List<ResourcePermission> list = q.list();
2917    
2918                    if (list.size() == 2) {
2919                            return list.get(1);
2920                    }
2921                    else {
2922                            return null;
2923                    }
2924            }
2925    
2926            /**
2927             * Removes all the resource permissions where companyId = &#63; and primKey = &#63; and roleId = &#63; from the database.
2928             *
2929             * @param companyId the company ID
2930             * @param primKey the prim key
2931             * @param roleId the role ID
2932             * @throws SystemException if a system exception occurred
2933             */
2934            public void removeByC_P_R(long companyId, String primKey, long roleId)
2935                    throws SystemException {
2936                    for (ResourcePermission resourcePermission : findByC_P_R(companyId,
2937                                    primKey, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2938                            remove(resourcePermission);
2939                    }
2940            }
2941    
2942            /**
2943             * Returns the number of resource permissions where companyId = &#63; and primKey = &#63; and roleId = &#63;.
2944             *
2945             * @param companyId the company ID
2946             * @param primKey the prim key
2947             * @param roleId the role ID
2948             * @return the number of matching resource permissions
2949             * @throws SystemException if a system exception occurred
2950             */
2951            public int countByC_P_R(long companyId, String primKey, long roleId)
2952                    throws SystemException {
2953                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P_R;
2954    
2955                    Object[] finderArgs = new Object[] { companyId, primKey, roleId };
2956    
2957                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2958                                    this);
2959    
2960                    if (count == null) {
2961                            StringBundler query = new StringBundler(4);
2962    
2963                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2964    
2965                            query.append(_FINDER_COLUMN_C_P_R_COMPANYID_2);
2966    
2967                            if (primKey == null) {
2968                                    query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_1);
2969                            }
2970                            else {
2971                                    if (primKey.equals(StringPool.BLANK)) {
2972                                            query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_3);
2973                                    }
2974                                    else {
2975                                            query.append(_FINDER_COLUMN_C_P_R_PRIMKEY_2);
2976                                    }
2977                            }
2978    
2979                            query.append(_FINDER_COLUMN_C_P_R_ROLEID_2);
2980    
2981                            String sql = query.toString();
2982    
2983                            Session session = null;
2984    
2985                            try {
2986                                    session = openSession();
2987    
2988                                    Query q = session.createQuery(sql);
2989    
2990                                    QueryPos qPos = QueryPos.getInstance(q);
2991    
2992                                    qPos.add(companyId);
2993    
2994                                    if (primKey != null) {
2995                                            qPos.add(primKey);
2996                                    }
2997    
2998                                    qPos.add(roleId);
2999    
3000                                    count = (Long)q.uniqueResult();
3001    
3002                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3003                            }
3004                            catch (Exception e) {
3005                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3006    
3007                                    throw processException(e);
3008                            }
3009                            finally {
3010                                    closeSession(session);
3011                            }
3012                    }
3013    
3014                    return count.intValue();
3015            }
3016    
3017            private static final String _FINDER_COLUMN_C_P_R_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3018            private static final String _FINDER_COLUMN_C_P_R_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
3019            private static final String _FINDER_COLUMN_C_P_R_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
3020            private static final String _FINDER_COLUMN_C_P_R_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
3021            private static final String _FINDER_COLUMN_C_P_R_ROLEID_2 = "resourcePermission.roleId = ?";
3022            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3023                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3024                            ResourcePermissionImpl.class,
3025                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P",
3026                            new String[] {
3027                                    Long.class.getName(), String.class.getName(),
3028                                    Integer.class.getName(), String.class.getName(),
3029                                    
3030                            Integer.class.getName(), Integer.class.getName(),
3031                                    OrderByComparator.class.getName()
3032                            });
3033            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P =
3034                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3035                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3036                            ResourcePermissionImpl.class,
3037                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P",
3038                            new String[] {
3039                                    Long.class.getName(), String.class.getName(),
3040                                    Integer.class.getName(), String.class.getName()
3041                            },
3042                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
3043                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
3044                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
3045                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK);
3046            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3047                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3048                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P",
3049                            new String[] {
3050                                    Long.class.getName(), String.class.getName(),
3051                                    Integer.class.getName(), String.class.getName()
3052                            });
3053    
3054            /**
3055             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3056             *
3057             * @param companyId the company ID
3058             * @param name the name
3059             * @param scope the scope
3060             * @param primKey the prim key
3061             * @return the matching resource permissions
3062             * @throws SystemException if a system exception occurred
3063             */
3064            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
3065                    int scope, String primKey) throws SystemException {
3066                    return findByC_N_S_P(companyId, name, scope, primKey,
3067                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3068            }
3069    
3070            /**
3071             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3072             *
3073             * <p>
3074             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3075             * </p>
3076             *
3077             * @param companyId the company ID
3078             * @param name the name
3079             * @param scope the scope
3080             * @param primKey the prim key
3081             * @param start the lower bound of the range of resource permissions
3082             * @param end the upper bound of the range of resource permissions (not inclusive)
3083             * @return the range of matching resource permissions
3084             * @throws SystemException if a system exception occurred
3085             */
3086            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
3087                    int scope, String primKey, int start, int end)
3088                    throws SystemException {
3089                    return findByC_N_S_P(companyId, name, scope, primKey, start, end, null);
3090            }
3091    
3092            /**
3093             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3094             *
3095             * <p>
3096             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3097             * </p>
3098             *
3099             * @param companyId the company ID
3100             * @param name the name
3101             * @param scope the scope
3102             * @param primKey the prim key
3103             * @param start the lower bound of the range of resource permissions
3104             * @param end the upper bound of the range of resource permissions (not inclusive)
3105             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3106             * @return the ordered range of matching resource permissions
3107             * @throws SystemException if a system exception occurred
3108             */
3109            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
3110                    int scope, String primKey, int start, int end,
3111                    OrderByComparator orderByComparator) throws SystemException {
3112                    boolean pagination = true;
3113                    FinderPath finderPath = null;
3114                    Object[] finderArgs = null;
3115    
3116                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3117                                    (orderByComparator == null)) {
3118                            pagination = false;
3119                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P;
3120                            finderArgs = new Object[] { companyId, name, scope, primKey };
3121                    }
3122                    else {
3123                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P;
3124                            finderArgs = new Object[] {
3125                                            companyId, name, scope, primKey,
3126                                            
3127                                            start, end, orderByComparator
3128                                    };
3129                    }
3130    
3131                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
3132                                    finderArgs, this);
3133    
3134                    if ((list != null) && !list.isEmpty()) {
3135                            for (ResourcePermission resourcePermission : list) {
3136                                    if ((companyId != resourcePermission.getCompanyId()) ||
3137                                                    !Validator.equals(name, resourcePermission.getName()) ||
3138                                                    (scope != resourcePermission.getScope()) ||
3139                                                    !Validator.equals(primKey,
3140                                                            resourcePermission.getPrimKey())) {
3141                                            list = null;
3142    
3143                                            break;
3144                                    }
3145                            }
3146                    }
3147    
3148                    if (list == null) {
3149                            StringBundler query = null;
3150    
3151                            if (orderByComparator != null) {
3152                                    query = new StringBundler(6 +
3153                                                    (orderByComparator.getOrderByFields().length * 3));
3154                            }
3155                            else {
3156                                    query = new StringBundler(6);
3157                            }
3158    
3159                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3160    
3161                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
3162    
3163                            if (name == null) {
3164                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
3165                            }
3166                            else {
3167                                    if (name.equals(StringPool.BLANK)) {
3168                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
3169                                    }
3170                                    else {
3171                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
3172                                    }
3173                            }
3174    
3175                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
3176    
3177                            if (primKey == null) {
3178                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
3179                            }
3180                            else {
3181                                    if (primKey.equals(StringPool.BLANK)) {
3182                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
3183                                    }
3184                                    else {
3185                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
3186                                    }
3187                            }
3188    
3189                            if (orderByComparator != null) {
3190                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3191                                            orderByComparator);
3192                            }
3193                            else
3194                             if (pagination) {
3195                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
3196                            }
3197    
3198                            String sql = query.toString();
3199    
3200                            Session session = null;
3201    
3202                            try {
3203                                    session = openSession();
3204    
3205                                    Query q = session.createQuery(sql);
3206    
3207                                    QueryPos qPos = QueryPos.getInstance(q);
3208    
3209                                    qPos.add(companyId);
3210    
3211                                    if (name != null) {
3212                                            qPos.add(name);
3213                                    }
3214    
3215                                    qPos.add(scope);
3216    
3217                                    if (primKey != null) {
3218                                            qPos.add(primKey);
3219                                    }
3220    
3221                                    if (!pagination) {
3222                                            list = (List<ResourcePermission>)QueryUtil.list(q,
3223                                                            getDialect(), start, end, false);
3224    
3225                                            Collections.sort(list);
3226    
3227                                            list = new UnmodifiableList<ResourcePermission>(list);
3228                                    }
3229                                    else {
3230                                            list = (List<ResourcePermission>)QueryUtil.list(q,
3231                                                            getDialect(), start, end);
3232                                    }
3233    
3234                                    cacheResult(list);
3235    
3236                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3237                            }
3238                            catch (Exception e) {
3239                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3240    
3241                                    throw processException(e);
3242                            }
3243                            finally {
3244                                    closeSession(session);
3245                            }
3246                    }
3247    
3248                    return list;
3249            }
3250    
3251            /**
3252             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3253             *
3254             * @param companyId the company ID
3255             * @param name the name
3256             * @param scope the scope
3257             * @param primKey the prim key
3258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3259             * @return the first matching resource permission
3260             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
3261             * @throws SystemException if a system exception occurred
3262             */
3263            public ResourcePermission findByC_N_S_P_First(long companyId, String name,
3264                    int scope, String primKey, OrderByComparator orderByComparator)
3265                    throws NoSuchResourcePermissionException, SystemException {
3266                    ResourcePermission resourcePermission = fetchByC_N_S_P_First(companyId,
3267                                    name, scope, primKey, orderByComparator);
3268    
3269                    if (resourcePermission != null) {
3270                            return resourcePermission;
3271                    }
3272    
3273                    StringBundler msg = new StringBundler(10);
3274    
3275                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3276    
3277                    msg.append("companyId=");
3278                    msg.append(companyId);
3279    
3280                    msg.append(", name=");
3281                    msg.append(name);
3282    
3283                    msg.append(", scope=");
3284                    msg.append(scope);
3285    
3286                    msg.append(", primKey=");
3287                    msg.append(primKey);
3288    
3289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3290    
3291                    throw new NoSuchResourcePermissionException(msg.toString());
3292            }
3293    
3294            /**
3295             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3296             *
3297             * @param companyId the company ID
3298             * @param name the name
3299             * @param scope the scope
3300             * @param primKey the prim key
3301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3302             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
3303             * @throws SystemException if a system exception occurred
3304             */
3305            public ResourcePermission fetchByC_N_S_P_First(long companyId, String name,
3306                    int scope, String primKey, OrderByComparator orderByComparator)
3307                    throws SystemException {
3308                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
3309                                    primKey, 0, 1, orderByComparator);
3310    
3311                    if (!list.isEmpty()) {
3312                            return list.get(0);
3313                    }
3314    
3315                    return null;
3316            }
3317    
3318            /**
3319             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3320             *
3321             * @param companyId the company ID
3322             * @param name the name
3323             * @param scope the scope
3324             * @param primKey the prim key
3325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3326             * @return the last matching resource permission
3327             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
3328             * @throws SystemException if a system exception occurred
3329             */
3330            public ResourcePermission findByC_N_S_P_Last(long companyId, String name,
3331                    int scope, String primKey, OrderByComparator orderByComparator)
3332                    throws NoSuchResourcePermissionException, SystemException {
3333                    ResourcePermission resourcePermission = fetchByC_N_S_P_Last(companyId,
3334                                    name, scope, primKey, orderByComparator);
3335    
3336                    if (resourcePermission != null) {
3337                            return resourcePermission;
3338                    }
3339    
3340                    StringBundler msg = new StringBundler(10);
3341    
3342                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3343    
3344                    msg.append("companyId=");
3345                    msg.append(companyId);
3346    
3347                    msg.append(", name=");
3348                    msg.append(name);
3349    
3350                    msg.append(", scope=");
3351                    msg.append(scope);
3352    
3353                    msg.append(", primKey=");
3354                    msg.append(primKey);
3355    
3356                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3357    
3358                    throw new NoSuchResourcePermissionException(msg.toString());
3359            }
3360    
3361            /**
3362             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3363             *
3364             * @param companyId the company ID
3365             * @param name the name
3366             * @param scope the scope
3367             * @param primKey the prim key
3368             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3369             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
3370             * @throws SystemException if a system exception occurred
3371             */
3372            public ResourcePermission fetchByC_N_S_P_Last(long companyId, String name,
3373                    int scope, String primKey, OrderByComparator orderByComparator)
3374                    throws SystemException {
3375                    int count = countByC_N_S_P(companyId, name, scope, primKey);
3376    
3377                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
3378                                    primKey, count - 1, count, orderByComparator);
3379    
3380                    if (!list.isEmpty()) {
3381                            return list.get(0);
3382                    }
3383    
3384                    return null;
3385            }
3386    
3387            /**
3388             * Returns 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;.
3389             *
3390             * @param resourcePermissionId the primary key of the current resource permission
3391             * @param companyId the company ID
3392             * @param name the name
3393             * @param scope the scope
3394             * @param primKey the prim key
3395             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3396             * @return the previous, current, and next resource permission
3397             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
3398             * @throws SystemException if a system exception occurred
3399             */
3400            public ResourcePermission[] findByC_N_S_P_PrevAndNext(
3401                    long resourcePermissionId, long companyId, String name, int scope,
3402                    String primKey, OrderByComparator orderByComparator)
3403                    throws NoSuchResourcePermissionException, SystemException {
3404                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
3405    
3406                    Session session = null;
3407    
3408                    try {
3409                            session = openSession();
3410    
3411                            ResourcePermission[] array = new ResourcePermissionImpl[3];
3412    
3413                            array[0] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
3414                                            companyId, name, scope, primKey, orderByComparator, true);
3415    
3416                            array[1] = resourcePermission;
3417    
3418                            array[2] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
3419                                            companyId, name, scope, primKey, orderByComparator, false);
3420    
3421                            return array;
3422                    }
3423                    catch (Exception e) {
3424                            throw processException(e);
3425                    }
3426                    finally {
3427                            closeSession(session);
3428                    }
3429            }
3430    
3431            protected ResourcePermission getByC_N_S_P_PrevAndNext(Session session,
3432                    ResourcePermission resourcePermission, long companyId, String name,
3433                    int scope, String primKey, OrderByComparator orderByComparator,
3434                    boolean previous) {
3435                    StringBundler query = null;
3436    
3437                    if (orderByComparator != null) {
3438                            query = new StringBundler(6 +
3439                                            (orderByComparator.getOrderByFields().length * 6));
3440                    }
3441                    else {
3442                            query = new StringBundler(3);
3443                    }
3444    
3445                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3446    
3447                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
3448    
3449                    if (name == null) {
3450                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
3451                    }
3452                    else {
3453                            if (name.equals(StringPool.BLANK)) {
3454                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
3455                            }
3456                            else {
3457                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
3458                            }
3459                    }
3460    
3461                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
3462    
3463                    if (primKey == null) {
3464                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
3465                    }
3466                    else {
3467                            if (primKey.equals(StringPool.BLANK)) {
3468                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
3469                            }
3470                            else {
3471                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
3472                            }
3473                    }
3474    
3475                    if (orderByComparator != null) {
3476                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3477    
3478                            if (orderByConditionFields.length > 0) {
3479                                    query.append(WHERE_AND);
3480                            }
3481    
3482                            for (int i = 0; i < orderByConditionFields.length; i++) {
3483                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3484                                    query.append(orderByConditionFields[i]);
3485    
3486                                    if ((i + 1) < orderByConditionFields.length) {
3487                                            if (orderByComparator.isAscending() ^ previous) {
3488                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3489                                            }
3490                                            else {
3491                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3492                                            }
3493                                    }
3494                                    else {
3495                                            if (orderByComparator.isAscending() ^ previous) {
3496                                                    query.append(WHERE_GREATER_THAN);
3497                                            }
3498                                            else {
3499                                                    query.append(WHERE_LESSER_THAN);
3500                                            }
3501                                    }
3502                            }
3503    
3504                            query.append(ORDER_BY_CLAUSE);
3505    
3506                            String[] orderByFields = orderByComparator.getOrderByFields();
3507    
3508                            for (int i = 0; i < orderByFields.length; i++) {
3509                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3510                                    query.append(orderByFields[i]);
3511    
3512                                    if ((i + 1) < orderByFields.length) {
3513                                            if (orderByComparator.isAscending() ^ previous) {
3514                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3515                                            }
3516                                            else {
3517                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3518                                            }
3519                                    }
3520                                    else {
3521                                            if (orderByComparator.isAscending() ^ previous) {
3522                                                    query.append(ORDER_BY_ASC);
3523                                            }
3524                                            else {
3525                                                    query.append(ORDER_BY_DESC);
3526                                            }
3527                                    }
3528                            }
3529                    }
3530                    else {
3531                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
3532                    }
3533    
3534                    String sql = query.toString();
3535    
3536                    Query q = session.createQuery(sql);
3537    
3538                    q.setFirstResult(0);
3539                    q.setMaxResults(2);
3540    
3541                    QueryPos qPos = QueryPos.getInstance(q);
3542    
3543                    qPos.add(companyId);
3544    
3545                    if (name != null) {
3546                            qPos.add(name);
3547                    }
3548    
3549                    qPos.add(scope);
3550    
3551                    if (primKey != null) {
3552                            qPos.add(primKey);
3553                    }
3554    
3555                    if (orderByComparator != null) {
3556                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
3557    
3558                            for (Object value : values) {
3559                                    qPos.add(value);
3560                            }
3561                    }
3562    
3563                    List<ResourcePermission> list = q.list();
3564    
3565                    if (list.size() == 2) {
3566                            return list.get(1);
3567                    }
3568                    else {
3569                            return null;
3570                    }
3571            }
3572    
3573            /**
3574             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; from the database.
3575             *
3576             * @param companyId the company ID
3577             * @param name the name
3578             * @param scope the scope
3579             * @param primKey the prim key
3580             * @throws SystemException if a system exception occurred
3581             */
3582            public void removeByC_N_S_P(long companyId, String name, int scope,
3583                    String primKey) throws SystemException {
3584                    for (ResourcePermission resourcePermission : findByC_N_S_P(companyId,
3585                                    name, scope, primKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3586                            remove(resourcePermission);
3587                    }
3588            }
3589    
3590            /**
3591             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3592             *
3593             * @param companyId the company ID
3594             * @param name the name
3595             * @param scope the scope
3596             * @param primKey the prim key
3597             * @return the number of matching resource permissions
3598             * @throws SystemException if a system exception occurred
3599             */
3600            public int countByC_N_S_P(long companyId, String name, int scope,
3601                    String primKey) throws SystemException {
3602                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S_P;
3603    
3604                    Object[] finderArgs = new Object[] { companyId, name, scope, primKey };
3605    
3606                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3607                                    this);
3608    
3609                    if (count == null) {
3610                            StringBundler query = new StringBundler(5);
3611    
3612                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
3613    
3614                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
3615    
3616                            if (name == null) {
3617                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
3618                            }
3619                            else {
3620                                    if (name.equals(StringPool.BLANK)) {
3621                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
3622                                    }
3623                                    else {
3624                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
3625                                    }
3626                            }
3627    
3628                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
3629    
3630                            if (primKey == null) {
3631                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
3632                            }
3633                            else {
3634                                    if (primKey.equals(StringPool.BLANK)) {
3635                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
3636                                    }
3637                                    else {
3638                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
3639                                    }
3640                            }
3641    
3642                            String sql = query.toString();
3643    
3644                            Session session = null;
3645    
3646                            try {
3647                                    session = openSession();
3648    
3649                                    Query q = session.createQuery(sql);
3650    
3651                                    QueryPos qPos = QueryPos.getInstance(q);
3652    
3653                                    qPos.add(companyId);
3654    
3655                                    if (name != null) {
3656                                            qPos.add(name);
3657                                    }
3658    
3659                                    qPos.add(scope);
3660    
3661                                    if (primKey != null) {
3662                                            qPos.add(primKey);
3663                                    }
3664    
3665                                    count = (Long)q.uniqueResult();
3666    
3667                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3668                            }
3669                            catch (Exception e) {
3670                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3671    
3672                                    throw processException(e);
3673                            }
3674                            finally {
3675                                    closeSession(session);
3676                            }
3677                    }
3678    
3679                    return count.intValue();
3680            }
3681    
3682            private static final String _FINDER_COLUMN_C_N_S_P_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3683            private static final String _FINDER_COLUMN_C_N_S_P_NAME_1 = "resourcePermission.name IS NULL AND ";
3684            private static final String _FINDER_COLUMN_C_N_S_P_NAME_2 = "resourcePermission.name = ? AND ";
3685            private static final String _FINDER_COLUMN_C_N_S_P_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
3686            private static final String _FINDER_COLUMN_C_N_S_P_SCOPE_2 = "resourcePermission.scope = ? AND ";
3687            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_1 = "resourcePermission.primKey IS NULL";
3688            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_2 = "resourcePermission.primKey = ?";
3689            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?)";
3690            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_O = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3691                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3692                            ResourcePermissionImpl.class,
3693                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_P_O",
3694                            new String[] {
3695                                    Long.class.getName(), String.class.getName(),
3696                                    String.class.getName(), Long.class.getName(),
3697                                    
3698                            Integer.class.getName(), Integer.class.getName(),
3699                                    OrderByComparator.class.getName()
3700                            });
3701            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O =
3702                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3703                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3704                            ResourcePermissionImpl.class,
3705                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_P_O",
3706                            new String[] {
3707                                    Long.class.getName(), String.class.getName(),
3708                                    String.class.getName(), Long.class.getName()
3709                            },
3710                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
3711                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
3712                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
3713                            ResourcePermissionModelImpl.OWNERID_COLUMN_BITMASK);
3714            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_P_O = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3715                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3716                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_P_O",
3717                            new String[] {
3718                                    Long.class.getName(), String.class.getName(),
3719                                    String.class.getName(), Long.class.getName()
3720                            });
3721    
3722            /**
3723             * Returns all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
3724             *
3725             * @param companyId the company ID
3726             * @param name the name
3727             * @param primKey the prim key
3728             * @param ownerId the owner ID
3729             * @return the matching resource permissions
3730             * @throws SystemException if a system exception occurred
3731             */
3732            public List<ResourcePermission> findByC_N_P_O(long companyId, String name,
3733                    String primKey, long ownerId) throws SystemException {
3734                    return findByC_N_P_O(companyId, name, primKey, ownerId,
3735                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3736            }
3737    
3738            /**
3739             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
3740             *
3741             * <p>
3742             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3743             * </p>
3744             *
3745             * @param companyId the company ID
3746             * @param name the name
3747             * @param primKey the prim key
3748             * @param ownerId the owner ID
3749             * @param start the lower bound of the range of resource permissions
3750             * @param end the upper bound of the range of resource permissions (not inclusive)
3751             * @return the range of matching resource permissions
3752             * @throws SystemException if a system exception occurred
3753             */
3754            public List<ResourcePermission> findByC_N_P_O(long companyId, String name,
3755                    String primKey, long ownerId, int start, int end)
3756                    throws SystemException {
3757                    return findByC_N_P_O(companyId, name, primKey, ownerId, start, end, null);
3758            }
3759    
3760            /**
3761             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
3762             *
3763             * <p>
3764             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3765             * </p>
3766             *
3767             * @param companyId the company ID
3768             * @param name the name
3769             * @param primKey the prim key
3770             * @param ownerId the owner ID
3771             * @param start the lower bound of the range of resource permissions
3772             * @param end the upper bound of the range of resource permissions (not inclusive)
3773             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3774             * @return the ordered range of matching resource permissions
3775             * @throws SystemException if a system exception occurred
3776             */
3777            public List<ResourcePermission> findByC_N_P_O(long companyId, String name,
3778                    String primKey, long ownerId, int start, int end,
3779                    OrderByComparator orderByComparator) throws SystemException {
3780                    boolean pagination = true;
3781                    FinderPath finderPath = null;
3782                    Object[] finderArgs = null;
3783    
3784                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3785                                    (orderByComparator == null)) {
3786                            pagination = false;
3787                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O;
3788                            finderArgs = new Object[] { companyId, name, primKey, ownerId };
3789                    }
3790                    else {
3791                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_O;
3792                            finderArgs = new Object[] {
3793                                            companyId, name, primKey, ownerId,
3794                                            
3795                                            start, end, orderByComparator
3796                                    };
3797                    }
3798    
3799                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
3800                                    finderArgs, this);
3801    
3802                    if ((list != null) && !list.isEmpty()) {
3803                            for (ResourcePermission resourcePermission : list) {
3804                                    if ((companyId != resourcePermission.getCompanyId()) ||
3805                                                    !Validator.equals(name, resourcePermission.getName()) ||
3806                                                    !Validator.equals(primKey,
3807                                                            resourcePermission.getPrimKey()) ||
3808                                                    (ownerId != resourcePermission.getOwnerId())) {
3809                                            list = null;
3810    
3811                                            break;
3812                                    }
3813                            }
3814                    }
3815    
3816                    if (list == null) {
3817                            StringBundler query = null;
3818    
3819                            if (orderByComparator != null) {
3820                                    query = new StringBundler(6 +
3821                                                    (orderByComparator.getOrderByFields().length * 3));
3822                            }
3823                            else {
3824                                    query = new StringBundler(6);
3825                            }
3826    
3827                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3828    
3829                            query.append(_FINDER_COLUMN_C_N_P_O_COMPANYID_2);
3830    
3831                            if (name == null) {
3832                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_1);
3833                            }
3834                            else {
3835                                    if (name.equals(StringPool.BLANK)) {
3836                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_3);
3837                                    }
3838                                    else {
3839                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_2);
3840                                    }
3841                            }
3842    
3843                            if (primKey == null) {
3844                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_1);
3845                            }
3846                            else {
3847                                    if (primKey.equals(StringPool.BLANK)) {
3848                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_3);
3849                                    }
3850                                    else {
3851                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_2);
3852                                    }
3853                            }
3854    
3855                            query.append(_FINDER_COLUMN_C_N_P_O_OWNERID_2);
3856    
3857                            if (orderByComparator != null) {
3858                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3859                                            orderByComparator);
3860                            }
3861                            else
3862                             if (pagination) {
3863                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
3864                            }
3865    
3866                            String sql = query.toString();
3867    
3868                            Session session = null;
3869    
3870                            try {
3871                                    session = openSession();
3872    
3873                                    Query q = session.createQuery(sql);
3874    
3875                                    QueryPos qPos = QueryPos.getInstance(q);
3876    
3877                                    qPos.add(companyId);
3878    
3879                                    if (name != null) {
3880                                            qPos.add(name);
3881                                    }
3882    
3883                                    if (primKey != null) {
3884                                            qPos.add(primKey);
3885                                    }
3886    
3887                                    qPos.add(ownerId);
3888    
3889                                    if (!pagination) {
3890                                            list = (List<ResourcePermission>)QueryUtil.list(q,
3891                                                            getDialect(), start, end, false);
3892    
3893                                            Collections.sort(list);
3894    
3895                                            list = new UnmodifiableList<ResourcePermission>(list);
3896                                    }
3897                                    else {
3898                                            list = (List<ResourcePermission>)QueryUtil.list(q,
3899                                                            getDialect(), start, end);
3900                                    }
3901    
3902                                    cacheResult(list);
3903    
3904                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3905                            }
3906                            catch (Exception e) {
3907                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3908    
3909                                    throw processException(e);
3910                            }
3911                            finally {
3912                                    closeSession(session);
3913                            }
3914                    }
3915    
3916                    return list;
3917            }
3918    
3919            /**
3920             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
3921             *
3922             * @param companyId the company ID
3923             * @param name the name
3924             * @param primKey the prim key
3925             * @param ownerId the owner ID
3926             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3927             * @return the first matching resource permission
3928             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
3929             * @throws SystemException if a system exception occurred
3930             */
3931            public ResourcePermission findByC_N_P_O_First(long companyId, String name,
3932                    String primKey, long ownerId, OrderByComparator orderByComparator)
3933                    throws NoSuchResourcePermissionException, SystemException {
3934                    ResourcePermission resourcePermission = fetchByC_N_P_O_First(companyId,
3935                                    name, primKey, ownerId, orderByComparator);
3936    
3937                    if (resourcePermission != null) {
3938                            return resourcePermission;
3939                    }
3940    
3941                    StringBundler msg = new StringBundler(10);
3942    
3943                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3944    
3945                    msg.append("companyId=");
3946                    msg.append(companyId);
3947    
3948                    msg.append(", name=");
3949                    msg.append(name);
3950    
3951                    msg.append(", primKey=");
3952                    msg.append(primKey);
3953    
3954                    msg.append(", ownerId=");
3955                    msg.append(ownerId);
3956    
3957                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3958    
3959                    throw new NoSuchResourcePermissionException(msg.toString());
3960            }
3961    
3962            /**
3963             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
3964             *
3965             * @param companyId the company ID
3966             * @param name the name
3967             * @param primKey the prim key
3968             * @param ownerId the owner ID
3969             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3970             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
3971             * @throws SystemException if a system exception occurred
3972             */
3973            public ResourcePermission fetchByC_N_P_O_First(long companyId, String name,
3974                    String primKey, long ownerId, OrderByComparator orderByComparator)
3975                    throws SystemException {
3976                    List<ResourcePermission> list = findByC_N_P_O(companyId, name, primKey,
3977                                    ownerId, 0, 1, orderByComparator);
3978    
3979                    if (!list.isEmpty()) {
3980                            return list.get(0);
3981                    }
3982    
3983                    return null;
3984            }
3985    
3986            /**
3987             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
3988             *
3989             * @param companyId the company ID
3990             * @param name the name
3991             * @param primKey the prim key
3992             * @param ownerId the owner ID
3993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3994             * @return the last matching resource permission
3995             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
3996             * @throws SystemException if a system exception occurred
3997             */
3998            public ResourcePermission findByC_N_P_O_Last(long companyId, String name,
3999                    String primKey, long ownerId, OrderByComparator orderByComparator)
4000                    throws NoSuchResourcePermissionException, SystemException {
4001                    ResourcePermission resourcePermission = fetchByC_N_P_O_Last(companyId,
4002                                    name, primKey, ownerId, orderByComparator);
4003    
4004                    if (resourcePermission != null) {
4005                            return resourcePermission;
4006                    }
4007    
4008                    StringBundler msg = new StringBundler(10);
4009    
4010                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4011    
4012                    msg.append("companyId=");
4013                    msg.append(companyId);
4014    
4015                    msg.append(", name=");
4016                    msg.append(name);
4017    
4018                    msg.append(", primKey=");
4019                    msg.append(primKey);
4020    
4021                    msg.append(", ownerId=");
4022                    msg.append(ownerId);
4023    
4024                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4025    
4026                    throw new NoSuchResourcePermissionException(msg.toString());
4027            }
4028    
4029            /**
4030             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
4031             *
4032             * @param companyId the company ID
4033             * @param name the name
4034             * @param primKey the prim key
4035             * @param ownerId the owner ID
4036             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4037             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
4038             * @throws SystemException if a system exception occurred
4039             */
4040            public ResourcePermission fetchByC_N_P_O_Last(long companyId, String name,
4041                    String primKey, long ownerId, OrderByComparator orderByComparator)
4042                    throws SystemException {
4043                    int count = countByC_N_P_O(companyId, name, primKey, ownerId);
4044    
4045                    List<ResourcePermission> list = findByC_N_P_O(companyId, name, primKey,
4046                                    ownerId, count - 1, count, orderByComparator);
4047    
4048                    if (!list.isEmpty()) {
4049                            return list.get(0);
4050                    }
4051    
4052                    return null;
4053            }
4054    
4055            /**
4056             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
4057             *
4058             * @param resourcePermissionId the primary key of the current resource permission
4059             * @param companyId the company ID
4060             * @param name the name
4061             * @param primKey the prim key
4062             * @param ownerId the owner ID
4063             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4064             * @return the previous, current, and next resource permission
4065             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4066             * @throws SystemException if a system exception occurred
4067             */
4068            public ResourcePermission[] findByC_N_P_O_PrevAndNext(
4069                    long resourcePermissionId, long companyId, String name, String primKey,
4070                    long ownerId, OrderByComparator orderByComparator)
4071                    throws NoSuchResourcePermissionException, SystemException {
4072                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
4073    
4074                    Session session = null;
4075    
4076                    try {
4077                            session = openSession();
4078    
4079                            ResourcePermission[] array = new ResourcePermissionImpl[3];
4080    
4081                            array[0] = getByC_N_P_O_PrevAndNext(session, resourcePermission,
4082                                            companyId, name, primKey, ownerId, orderByComparator, true);
4083    
4084                            array[1] = resourcePermission;
4085    
4086                            array[2] = getByC_N_P_O_PrevAndNext(session, resourcePermission,
4087                                            companyId, name, primKey, ownerId, orderByComparator, false);
4088    
4089                            return array;
4090                    }
4091                    catch (Exception e) {
4092                            throw processException(e);
4093                    }
4094                    finally {
4095                            closeSession(session);
4096                    }
4097            }
4098    
4099            protected ResourcePermission getByC_N_P_O_PrevAndNext(Session session,
4100                    ResourcePermission resourcePermission, long companyId, String name,
4101                    String primKey, long ownerId, OrderByComparator orderByComparator,
4102                    boolean previous) {
4103                    StringBundler query = null;
4104    
4105                    if (orderByComparator != null) {
4106                            query = new StringBundler(6 +
4107                                            (orderByComparator.getOrderByFields().length * 6));
4108                    }
4109                    else {
4110                            query = new StringBundler(3);
4111                    }
4112    
4113                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4114    
4115                    query.append(_FINDER_COLUMN_C_N_P_O_COMPANYID_2);
4116    
4117                    if (name == null) {
4118                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_1);
4119                    }
4120                    else {
4121                            if (name.equals(StringPool.BLANK)) {
4122                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_3);
4123                            }
4124                            else {
4125                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_2);
4126                            }
4127                    }
4128    
4129                    if (primKey == null) {
4130                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_1);
4131                    }
4132                    else {
4133                            if (primKey.equals(StringPool.BLANK)) {
4134                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_3);
4135                            }
4136                            else {
4137                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_2);
4138                            }
4139                    }
4140    
4141                    query.append(_FINDER_COLUMN_C_N_P_O_OWNERID_2);
4142    
4143                    if (orderByComparator != null) {
4144                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4145    
4146                            if (orderByConditionFields.length > 0) {
4147                                    query.append(WHERE_AND);
4148                            }
4149    
4150                            for (int i = 0; i < orderByConditionFields.length; i++) {
4151                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4152                                    query.append(orderByConditionFields[i]);
4153    
4154                                    if ((i + 1) < orderByConditionFields.length) {
4155                                            if (orderByComparator.isAscending() ^ previous) {
4156                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4157                                            }
4158                                            else {
4159                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4160                                            }
4161                                    }
4162                                    else {
4163                                            if (orderByComparator.isAscending() ^ previous) {
4164                                                    query.append(WHERE_GREATER_THAN);
4165                                            }
4166                                            else {
4167                                                    query.append(WHERE_LESSER_THAN);
4168                                            }
4169                                    }
4170                            }
4171    
4172                            query.append(ORDER_BY_CLAUSE);
4173    
4174                            String[] orderByFields = orderByComparator.getOrderByFields();
4175    
4176                            for (int i = 0; i < orderByFields.length; i++) {
4177                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4178                                    query.append(orderByFields[i]);
4179    
4180                                    if ((i + 1) < orderByFields.length) {
4181                                            if (orderByComparator.isAscending() ^ previous) {
4182                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4183                                            }
4184                                            else {
4185                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4186                                            }
4187                                    }
4188                                    else {
4189                                            if (orderByComparator.isAscending() ^ previous) {
4190                                                    query.append(ORDER_BY_ASC);
4191                                            }
4192                                            else {
4193                                                    query.append(ORDER_BY_DESC);
4194                                            }
4195                                    }
4196                            }
4197                    }
4198                    else {
4199                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
4200                    }
4201    
4202                    String sql = query.toString();
4203    
4204                    Query q = session.createQuery(sql);
4205    
4206                    q.setFirstResult(0);
4207                    q.setMaxResults(2);
4208    
4209                    QueryPos qPos = QueryPos.getInstance(q);
4210    
4211                    qPos.add(companyId);
4212    
4213                    if (name != null) {
4214                            qPos.add(name);
4215                    }
4216    
4217                    if (primKey != null) {
4218                            qPos.add(primKey);
4219                    }
4220    
4221                    qPos.add(ownerId);
4222    
4223                    if (orderByComparator != null) {
4224                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
4225    
4226                            for (Object value : values) {
4227                                    qPos.add(value);
4228                            }
4229                    }
4230    
4231                    List<ResourcePermission> list = q.list();
4232    
4233                    if (list.size() == 2) {
4234                            return list.get(1);
4235                    }
4236                    else {
4237                            return null;
4238                    }
4239            }
4240    
4241            /**
4242             * Removes all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63; from the database.
4243             *
4244             * @param companyId the company ID
4245             * @param name the name
4246             * @param primKey the prim key
4247             * @param ownerId the owner ID
4248             * @throws SystemException if a system exception occurred
4249             */
4250            public void removeByC_N_P_O(long companyId, String name, String primKey,
4251                    long ownerId) throws SystemException {
4252                    for (ResourcePermission resourcePermission : findByC_N_P_O(companyId,
4253                                    name, primKey, ownerId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4254                                    null)) {
4255                            remove(resourcePermission);
4256                    }
4257            }
4258    
4259            /**
4260             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
4261             *
4262             * @param companyId the company ID
4263             * @param name the name
4264             * @param primKey the prim key
4265             * @param ownerId the owner ID
4266             * @return the number of matching resource permissions
4267             * @throws SystemException if a system exception occurred
4268             */
4269            public int countByC_N_P_O(long companyId, String name, String primKey,
4270                    long ownerId) throws SystemException {
4271                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_P_O;
4272    
4273                    Object[] finderArgs = new Object[] { companyId, name, primKey, ownerId };
4274    
4275                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4276                                    this);
4277    
4278                    if (count == null) {
4279                            StringBundler query = new StringBundler(5);
4280    
4281                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
4282    
4283                            query.append(_FINDER_COLUMN_C_N_P_O_COMPANYID_2);
4284    
4285                            if (name == null) {
4286                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_1);
4287                            }
4288                            else {
4289                                    if (name.equals(StringPool.BLANK)) {
4290                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_3);
4291                                    }
4292                                    else {
4293                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_2);
4294                                    }
4295                            }
4296    
4297                            if (primKey == null) {
4298                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_1);
4299                            }
4300                            else {
4301                                    if (primKey.equals(StringPool.BLANK)) {
4302                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_3);
4303                                    }
4304                                    else {
4305                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_2);
4306                                    }
4307                            }
4308    
4309                            query.append(_FINDER_COLUMN_C_N_P_O_OWNERID_2);
4310    
4311                            String sql = query.toString();
4312    
4313                            Session session = null;
4314    
4315                            try {
4316                                    session = openSession();
4317    
4318                                    Query q = session.createQuery(sql);
4319    
4320                                    QueryPos qPos = QueryPos.getInstance(q);
4321    
4322                                    qPos.add(companyId);
4323    
4324                                    if (name != null) {
4325                                            qPos.add(name);
4326                                    }
4327    
4328                                    if (primKey != null) {
4329                                            qPos.add(primKey);
4330                                    }
4331    
4332                                    qPos.add(ownerId);
4333    
4334                                    count = (Long)q.uniqueResult();
4335    
4336                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4337                            }
4338                            catch (Exception e) {
4339                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4340    
4341                                    throw processException(e);
4342                            }
4343                            finally {
4344                                    closeSession(session);
4345                            }
4346                    }
4347    
4348                    return count.intValue();
4349            }
4350    
4351            private static final String _FINDER_COLUMN_C_N_P_O_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
4352            private static final String _FINDER_COLUMN_C_N_P_O_NAME_1 = "resourcePermission.name IS NULL AND ";
4353            private static final String _FINDER_COLUMN_C_N_P_O_NAME_2 = "resourcePermission.name = ? AND ";
4354            private static final String _FINDER_COLUMN_C_N_P_O_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
4355            private static final String _FINDER_COLUMN_C_N_P_O_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
4356            private static final String _FINDER_COLUMN_C_N_P_O_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
4357            private static final String _FINDER_COLUMN_C_N_P_O_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
4358            private static final String _FINDER_COLUMN_C_N_P_O_OWNERID_2 = "resourcePermission.ownerId = ?";
4359            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R =
4360                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4361                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
4362                            ResourcePermissionImpl.class,
4363                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P_R",
4364                            new String[] {
4365                                    Long.class.getName(), String.class.getName(),
4366                                    Integer.class.getName(), String.class.getName(),
4367                                    Long.class.getName(),
4368                                    
4369                            Integer.class.getName(), Integer.class.getName(),
4370                                    OrderByComparator.class.getName()
4371                            });
4372            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R =
4373                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4374                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
4375                            ResourcePermissionImpl.class,
4376                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P_R",
4377                            new String[] {
4378                                    Long.class.getName(), String.class.getName(),
4379                                    Integer.class.getName(), String.class.getName(),
4380                                    Long.class.getName()
4381                            },
4382                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
4383                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
4384                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
4385                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
4386                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
4387            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4388                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
4389                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R",
4390                            new String[] {
4391                                    Long.class.getName(), String.class.getName(),
4392                                    Integer.class.getName(), String.class.getName(),
4393                                    Long.class.getName()
4394                            });
4395            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R =
4396                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4397                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
4398                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_N_S_P_R",
4399                            new String[] {
4400                                    Long.class.getName(), String.class.getName(),
4401                                    Integer.class.getName(), String.class.getName(),
4402                                    Long.class.getName()
4403                            });
4404    
4405            /**
4406             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4407             *
4408             * @param companyId the company ID
4409             * @param name the name
4410             * @param scope the scope
4411             * @param primKey the prim key
4412             * @param roleId the role ID
4413             * @return the matching resource permissions
4414             * @throws SystemException if a system exception occurred
4415             */
4416            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
4417                    String name, int scope, String primKey, long roleId)
4418                    throws SystemException {
4419                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleId,
4420                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4421            }
4422    
4423            /**
4424             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4425             *
4426             * <p>
4427             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4428             * </p>
4429             *
4430             * @param companyId the company ID
4431             * @param name the name
4432             * @param scope the scope
4433             * @param primKey the prim key
4434             * @param roleId the role ID
4435             * @param start the lower bound of the range of resource permissions
4436             * @param end the upper bound of the range of resource permissions (not inclusive)
4437             * @return the range of matching resource permissions
4438             * @throws SystemException if a system exception occurred
4439             */
4440            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
4441                    String name, int scope, String primKey, long roleId, int start, int end)
4442                    throws SystemException {
4443                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleId, start,
4444                            end, null);
4445            }
4446    
4447            /**
4448             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4449             *
4450             * <p>
4451             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4452             * </p>
4453             *
4454             * @param companyId the company ID
4455             * @param name the name
4456             * @param scope the scope
4457             * @param primKey the prim key
4458             * @param roleId the role ID
4459             * @param start the lower bound of the range of resource permissions
4460             * @param end the upper bound of the range of resource permissions (not inclusive)
4461             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4462             * @return the ordered range of matching resource permissions
4463             * @throws SystemException if a system exception occurred
4464             */
4465            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
4466                    String name, int scope, String primKey, long roleId, int start,
4467                    int end, OrderByComparator orderByComparator) throws SystemException {
4468                    boolean pagination = true;
4469                    FinderPath finderPath = null;
4470                    Object[] finderArgs = null;
4471    
4472                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4473                                    (orderByComparator == null)) {
4474                            pagination = false;
4475                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R;
4476                            finderArgs = new Object[] { companyId, name, scope, primKey, roleId };
4477                    }
4478                    else {
4479                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R;
4480                            finderArgs = new Object[] {
4481                                            companyId, name, scope, primKey, roleId,
4482                                            
4483                                            start, end, orderByComparator
4484                                    };
4485                    }
4486    
4487                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
4488                                    finderArgs, this);
4489    
4490                    if ((list != null) && !list.isEmpty()) {
4491                            for (ResourcePermission resourcePermission : list) {
4492                                    if ((companyId != resourcePermission.getCompanyId()) ||
4493                                                    !Validator.equals(name, resourcePermission.getName()) ||
4494                                                    (scope != resourcePermission.getScope()) ||
4495                                                    !Validator.equals(primKey,
4496                                                            resourcePermission.getPrimKey()) ||
4497                                                    (roleId != resourcePermission.getRoleId())) {
4498                                            list = null;
4499    
4500                                            break;
4501                                    }
4502                            }
4503                    }
4504    
4505                    if (list == null) {
4506                            StringBundler query = null;
4507    
4508                            if (orderByComparator != null) {
4509                                    query = new StringBundler(7 +
4510                                                    (orderByComparator.getOrderByFields().length * 3));
4511                            }
4512                            else {
4513                                    query = new StringBundler(7);
4514                            }
4515    
4516                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4517    
4518                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
4519    
4520                            if (name == null) {
4521                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
4522                            }
4523                            else {
4524                                    if (name.equals(StringPool.BLANK)) {
4525                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
4526                                    }
4527                                    else {
4528                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
4529                                    }
4530                            }
4531    
4532                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
4533    
4534                            if (primKey == null) {
4535                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
4536                            }
4537                            else {
4538                                    if (primKey.equals(StringPool.BLANK)) {
4539                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
4540                                    }
4541                                    else {
4542                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
4543                                    }
4544                            }
4545    
4546                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
4547    
4548                            if (orderByComparator != null) {
4549                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4550                                            orderByComparator);
4551                            }
4552                            else
4553                             if (pagination) {
4554                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
4555                            }
4556    
4557                            String sql = query.toString();
4558    
4559                            Session session = null;
4560    
4561                            try {
4562                                    session = openSession();
4563    
4564                                    Query q = session.createQuery(sql);
4565    
4566                                    QueryPos qPos = QueryPos.getInstance(q);
4567    
4568                                    qPos.add(companyId);
4569    
4570                                    if (name != null) {
4571                                            qPos.add(name);
4572                                    }
4573    
4574                                    qPos.add(scope);
4575    
4576                                    if (primKey != null) {
4577                                            qPos.add(primKey);
4578                                    }
4579    
4580                                    qPos.add(roleId);
4581    
4582                                    if (!pagination) {
4583                                            list = (List<ResourcePermission>)QueryUtil.list(q,
4584                                                            getDialect(), start, end, false);
4585    
4586                                            Collections.sort(list);
4587    
4588                                            list = new UnmodifiableList<ResourcePermission>(list);
4589                                    }
4590                                    else {
4591                                            list = (List<ResourcePermission>)QueryUtil.list(q,
4592                                                            getDialect(), start, end);
4593                                    }
4594    
4595                                    cacheResult(list);
4596    
4597                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4598                            }
4599                            catch (Exception e) {
4600                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4601    
4602                                    throw processException(e);
4603                            }
4604                            finally {
4605                                    closeSession(session);
4606                            }
4607                    }
4608    
4609                    return list;
4610            }
4611    
4612            /**
4613             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4614             *
4615             * @param companyId the company ID
4616             * @param name the name
4617             * @param scope the scope
4618             * @param primKey the prim key
4619             * @param roleId the role ID
4620             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4621             * @return the first matching resource permission
4622             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
4623             * @throws SystemException if a system exception occurred
4624             */
4625            public ResourcePermission findByC_N_S_P_R_First(long companyId,
4626                    String name, int scope, String primKey, long roleId,
4627                    OrderByComparator orderByComparator)
4628                    throws NoSuchResourcePermissionException, SystemException {
4629                    ResourcePermission resourcePermission = fetchByC_N_S_P_R_First(companyId,
4630                                    name, scope, primKey, roleId, orderByComparator);
4631    
4632                    if (resourcePermission != null) {
4633                            return resourcePermission;
4634                    }
4635    
4636                    StringBundler msg = new StringBundler(12);
4637    
4638                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4639    
4640                    msg.append("companyId=");
4641                    msg.append(companyId);
4642    
4643                    msg.append(", name=");
4644                    msg.append(name);
4645    
4646                    msg.append(", scope=");
4647                    msg.append(scope);
4648    
4649                    msg.append(", primKey=");
4650                    msg.append(primKey);
4651    
4652                    msg.append(", roleId=");
4653                    msg.append(roleId);
4654    
4655                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4656    
4657                    throw new NoSuchResourcePermissionException(msg.toString());
4658            }
4659    
4660            /**
4661             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4662             *
4663             * @param companyId the company ID
4664             * @param name the name
4665             * @param scope the scope
4666             * @param primKey the prim key
4667             * @param roleId the role ID
4668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4669             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
4670             * @throws SystemException if a system exception occurred
4671             */
4672            public ResourcePermission fetchByC_N_S_P_R_First(long companyId,
4673                    String name, int scope, String primKey, long roleId,
4674                    OrderByComparator orderByComparator) throws SystemException {
4675                    List<ResourcePermission> list = findByC_N_S_P_R(companyId, name, scope,
4676                                    primKey, roleId, 0, 1, orderByComparator);
4677    
4678                    if (!list.isEmpty()) {
4679                            return list.get(0);
4680                    }
4681    
4682                    return null;
4683            }
4684    
4685            /**
4686             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4687             *
4688             * @param companyId the company ID
4689             * @param name the name
4690             * @param scope the scope
4691             * @param primKey the prim key
4692             * @param roleId the role ID
4693             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4694             * @return the last matching resource permission
4695             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
4696             * @throws SystemException if a system exception occurred
4697             */
4698            public ResourcePermission findByC_N_S_P_R_Last(long companyId, String name,
4699                    int scope, String primKey, long roleId,
4700                    OrderByComparator orderByComparator)
4701                    throws NoSuchResourcePermissionException, SystemException {
4702                    ResourcePermission resourcePermission = fetchByC_N_S_P_R_Last(companyId,
4703                                    name, scope, primKey, roleId, orderByComparator);
4704    
4705                    if (resourcePermission != null) {
4706                            return resourcePermission;
4707                    }
4708    
4709                    StringBundler msg = new StringBundler(12);
4710    
4711                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4712    
4713                    msg.append("companyId=");
4714                    msg.append(companyId);
4715    
4716                    msg.append(", name=");
4717                    msg.append(name);
4718    
4719                    msg.append(", scope=");
4720                    msg.append(scope);
4721    
4722                    msg.append(", primKey=");
4723                    msg.append(primKey);
4724    
4725                    msg.append(", roleId=");
4726                    msg.append(roleId);
4727    
4728                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4729    
4730                    throw new NoSuchResourcePermissionException(msg.toString());
4731            }
4732    
4733            /**
4734             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
4735             *
4736             * @param companyId the company ID
4737             * @param name the name
4738             * @param scope the scope
4739             * @param primKey the prim key
4740             * @param roleId the role ID
4741             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4742             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
4743             * @throws SystemException if a system exception occurred
4744             */
4745            public ResourcePermission fetchByC_N_S_P_R_Last(long companyId,
4746                    String name, int scope, String primKey, long roleId,
4747                    OrderByComparator orderByComparator) throws SystemException {
4748                    int count = countByC_N_S_P_R(companyId, name, scope, primKey, roleId);
4749    
4750                    List<ResourcePermission> list = findByC_N_S_P_R(companyId, name, scope,
4751                                    primKey, roleId, count - 1, count, orderByComparator);
4752    
4753                    if (!list.isEmpty()) {
4754                            return list.get(0);
4755                    }
4756    
4757                    return null;
4758            }
4759    
4760            /**
4761             * Returns 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; and roleId = &#63;.
4762             *
4763             * @param resourcePermissionId the primary key of the current resource permission
4764             * @param companyId the company ID
4765             * @param name the name
4766             * @param scope the scope
4767             * @param primKey the prim key
4768             * @param roleId the role ID
4769             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4770             * @return the previous, current, and next resource permission
4771             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4772             * @throws SystemException if a system exception occurred
4773             */
4774            public ResourcePermission[] findByC_N_S_P_R_PrevAndNext(
4775                    long resourcePermissionId, long companyId, String name, int scope,
4776                    String primKey, long roleId, OrderByComparator orderByComparator)
4777                    throws NoSuchResourcePermissionException, SystemException {
4778                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
4779    
4780                    Session session = null;
4781    
4782                    try {
4783                            session = openSession();
4784    
4785                            ResourcePermission[] array = new ResourcePermissionImpl[3];
4786    
4787                            array[0] = getByC_N_S_P_R_PrevAndNext(session, resourcePermission,
4788                                            companyId, name, scope, primKey, roleId, orderByComparator,
4789                                            true);
4790    
4791                            array[1] = resourcePermission;
4792    
4793                            array[2] = getByC_N_S_P_R_PrevAndNext(session, resourcePermission,
4794                                            companyId, name, scope, primKey, roleId, orderByComparator,
4795                                            false);
4796    
4797                            return array;
4798                    }
4799                    catch (Exception e) {
4800                            throw processException(e);
4801                    }
4802                    finally {
4803                            closeSession(session);
4804                    }
4805            }
4806    
4807            protected ResourcePermission getByC_N_S_P_R_PrevAndNext(Session session,
4808                    ResourcePermission resourcePermission, long companyId, String name,
4809                    int scope, String primKey, long roleId,
4810                    OrderByComparator orderByComparator, boolean previous) {
4811                    StringBundler query = null;
4812    
4813                    if (orderByComparator != null) {
4814                            query = new StringBundler(6 +
4815                                            (orderByComparator.getOrderByFields().length * 6));
4816                    }
4817                    else {
4818                            query = new StringBundler(3);
4819                    }
4820    
4821                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4822    
4823                    query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
4824    
4825                    if (name == null) {
4826                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
4827                    }
4828                    else {
4829                            if (name.equals(StringPool.BLANK)) {
4830                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
4831                            }
4832                            else {
4833                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
4834                            }
4835                    }
4836    
4837                    query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
4838    
4839                    if (primKey == null) {
4840                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
4841                    }
4842                    else {
4843                            if (primKey.equals(StringPool.BLANK)) {
4844                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
4845                            }
4846                            else {
4847                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
4848                            }
4849                    }
4850    
4851                    query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
4852    
4853                    if (orderByComparator != null) {
4854                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4855    
4856                            if (orderByConditionFields.length > 0) {
4857                                    query.append(WHERE_AND);
4858                            }
4859    
4860                            for (int i = 0; i < orderByConditionFields.length; i++) {
4861                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4862                                    query.append(orderByConditionFields[i]);
4863    
4864                                    if ((i + 1) < orderByConditionFields.length) {
4865                                            if (orderByComparator.isAscending() ^ previous) {
4866                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4867                                            }
4868                                            else {
4869                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4870                                            }
4871                                    }
4872                                    else {
4873                                            if (orderByComparator.isAscending() ^ previous) {
4874                                                    query.append(WHERE_GREATER_THAN);
4875                                            }
4876                                            else {
4877                                                    query.append(WHERE_LESSER_THAN);
4878                                            }
4879                                    }
4880                            }
4881    
4882                            query.append(ORDER_BY_CLAUSE);
4883    
4884                            String[] orderByFields = orderByComparator.getOrderByFields();
4885    
4886                            for (int i = 0; i < orderByFields.length; i++) {
4887                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4888                                    query.append(orderByFields[i]);
4889    
4890                                    if ((i + 1) < orderByFields.length) {
4891                                            if (orderByComparator.isAscending() ^ previous) {
4892                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4893                                            }
4894                                            else {
4895                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4896                                            }
4897                                    }
4898                                    else {
4899                                            if (orderByComparator.isAscending() ^ previous) {
4900                                                    query.append(ORDER_BY_ASC);
4901                                            }
4902                                            else {
4903                                                    query.append(ORDER_BY_DESC);
4904                                            }
4905                                    }
4906                            }
4907                    }
4908                    else {
4909                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
4910                    }
4911    
4912                    String sql = query.toString();
4913    
4914                    Query q = session.createQuery(sql);
4915    
4916                    q.setFirstResult(0);
4917                    q.setMaxResults(2);
4918    
4919                    QueryPos qPos = QueryPos.getInstance(q);
4920    
4921                    qPos.add(companyId);
4922    
4923                    if (name != null) {
4924                            qPos.add(name);
4925                    }
4926    
4927                    qPos.add(scope);
4928    
4929                    if (primKey != null) {
4930                            qPos.add(primKey);
4931                    }
4932    
4933                    qPos.add(roleId);
4934    
4935                    if (orderByComparator != null) {
4936                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
4937    
4938                            for (Object value : values) {
4939                                    qPos.add(value);
4940                            }
4941                    }
4942    
4943                    List<ResourcePermission> list = q.list();
4944    
4945                    if (list.size() == 2) {
4946                            return list.get(1);
4947                    }
4948                    else {
4949                            return null;
4950                    }
4951            }
4952    
4953            /**
4954             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
4955             *
4956             * <p>
4957             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4958             * </p>
4959             *
4960             * @param companyId the company ID
4961             * @param name the name
4962             * @param scope the scope
4963             * @param primKey the prim key
4964             * @param roleIds the role IDs
4965             * @return the matching resource permissions
4966             * @throws SystemException if a system exception occurred
4967             */
4968            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
4969                    String name, int scope, String primKey, long[] roleIds)
4970                    throws SystemException {
4971                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds,
4972                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4973            }
4974    
4975            /**
4976             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
4977             *
4978             * <p>
4979             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4980             * </p>
4981             *
4982             * @param companyId the company ID
4983             * @param name the name
4984             * @param scope the scope
4985             * @param primKey the prim key
4986             * @param roleIds the role IDs
4987             * @param start the lower bound of the range of resource permissions
4988             * @param end the upper bound of the range of resource permissions (not inclusive)
4989             * @return the range of matching resource permissions
4990             * @throws SystemException if a system exception occurred
4991             */
4992            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
4993                    String name, int scope, String primKey, long[] roleIds, int start,
4994                    int end) throws SystemException {
4995                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds, start,
4996                            end, null);
4997            }
4998    
4999            /**
5000             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
5001             *
5002             * <p>
5003             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5004             * </p>
5005             *
5006             * @param companyId the company ID
5007             * @param name the name
5008             * @param scope the scope
5009             * @param primKey the prim key
5010             * @param roleIds the role IDs
5011             * @param start the lower bound of the range of resource permissions
5012             * @param end the upper bound of the range of resource permissions (not inclusive)
5013             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5014             * @return the ordered range of matching resource permissions
5015             * @throws SystemException if a system exception occurred
5016             */
5017            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
5018                    String name, int scope, String primKey, long[] roleIds, int start,
5019                    int end, OrderByComparator orderByComparator) throws SystemException {
5020                    if ((roleIds != null) && (roleIds.length == 1)) {
5021                            return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds[0],
5022                                    start, end, orderByComparator);
5023                    }
5024    
5025                    boolean pagination = true;
5026                    Object[] finderArgs = null;
5027    
5028                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5029                                    (orderByComparator == null)) {
5030                            pagination = false;
5031                            finderArgs = new Object[] {
5032                                            companyId, name, scope, primKey, StringUtil.merge(roleIds)
5033                                    };
5034                    }
5035                    else {
5036                            finderArgs = new Object[] {
5037                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
5038                                            
5039                                            start, end, orderByComparator
5040                                    };
5041                    }
5042    
5043                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R,
5044                                    finderArgs, this);
5045    
5046                    if ((list != null) && !list.isEmpty()) {
5047                            for (ResourcePermission resourcePermission : list) {
5048                                    if ((companyId != resourcePermission.getCompanyId()) ||
5049                                                    !Validator.equals(name, resourcePermission.getName()) ||
5050                                                    (scope != resourcePermission.getScope()) ||
5051                                                    !Validator.equals(primKey,
5052                                                            resourcePermission.getPrimKey()) ||
5053                                                    !ArrayUtil.contains(roleIds,
5054                                                            resourcePermission.getRoleId())) {
5055                                            list = null;
5056    
5057                                            break;
5058                                    }
5059                            }
5060                    }
5061    
5062                    if (list == null) {
5063                            StringBundler query = new StringBundler();
5064    
5065                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
5066    
5067                            boolean conjunctionable = false;
5068    
5069                            if (conjunctionable) {
5070                                    query.append(WHERE_AND);
5071                            }
5072    
5073                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_5);
5074    
5075                            conjunctionable = true;
5076    
5077                            if (conjunctionable) {
5078                                    query.append(WHERE_AND);
5079                            }
5080    
5081                            if (name == null) {
5082                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_4);
5083                            }
5084                            else {
5085                                    if (name.equals(StringPool.BLANK)) {
5086                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_6);
5087                                    }
5088                                    else {
5089                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_5);
5090                                    }
5091                            }
5092    
5093                            conjunctionable = true;
5094    
5095                            if (conjunctionable) {
5096                                    query.append(WHERE_AND);
5097                            }
5098    
5099                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_5);
5100    
5101                            conjunctionable = true;
5102    
5103                            if (conjunctionable) {
5104                                    query.append(WHERE_AND);
5105                            }
5106    
5107                            if (primKey == null) {
5108                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_4);
5109                            }
5110                            else {
5111                                    if (primKey.equals(StringPool.BLANK)) {
5112                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_6);
5113                                    }
5114                                    else {
5115                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_5);
5116                                    }
5117                            }
5118    
5119                            conjunctionable = true;
5120    
5121                            if ((roleIds == null) || (roleIds.length > 0)) {
5122                                    if (conjunctionable) {
5123                                            query.append(WHERE_AND);
5124                                    }
5125    
5126                                    query.append(StringPool.OPEN_PARENTHESIS);
5127    
5128                                    for (int i = 0; i < roleIds.length; i++) {
5129                                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_5);
5130    
5131                                            if ((i + 1) < roleIds.length) {
5132                                                    query.append(WHERE_OR);
5133                                            }
5134                                    }
5135    
5136                                    query.append(StringPool.CLOSE_PARENTHESIS);
5137    
5138                                    conjunctionable = true;
5139                            }
5140    
5141                            if (orderByComparator != null) {
5142                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5143                                            orderByComparator);
5144                            }
5145                            else
5146                             if (pagination) {
5147                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
5148                            }
5149    
5150                            String sql = query.toString();
5151    
5152                            Session session = null;
5153    
5154                            try {
5155                                    session = openSession();
5156    
5157                                    Query q = session.createQuery(sql);
5158    
5159                                    QueryPos qPos = QueryPos.getInstance(q);
5160    
5161                                    qPos.add(companyId);
5162    
5163                                    if (name != null) {
5164                                            qPos.add(name);
5165                                    }
5166    
5167                                    qPos.add(scope);
5168    
5169                                    if (primKey != null) {
5170                                            qPos.add(primKey);
5171                                    }
5172    
5173                                    if (roleIds != null) {
5174                                            qPos.add(roleIds);
5175                                    }
5176    
5177                                    if (!pagination) {
5178                                            list = (List<ResourcePermission>)QueryUtil.list(q,
5179                                                            getDialect(), start, end, false);
5180    
5181                                            Collections.sort(list);
5182    
5183                                            list = new UnmodifiableList<ResourcePermission>(list);
5184                                    }
5185                                    else {
5186                                            list = (List<ResourcePermission>)QueryUtil.list(q,
5187                                                            getDialect(), start, end);
5188                                    }
5189    
5190                                    cacheResult(list);
5191    
5192                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R,
5193                                            finderArgs, list);
5194                            }
5195                            catch (Exception e) {
5196                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R,
5197                                            finderArgs);
5198    
5199                                    throw processException(e);
5200                            }
5201                            finally {
5202                                    closeSession(session);
5203                            }
5204                    }
5205    
5206                    return list;
5207            }
5208    
5209            /**
5210             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; from the database.
5211             *
5212             * @param companyId the company ID
5213             * @param name the name
5214             * @param scope the scope
5215             * @param primKey the prim key
5216             * @param roleId the role ID
5217             * @throws SystemException if a system exception occurred
5218             */
5219            public void removeByC_N_S_P_R(long companyId, String name, int scope,
5220                    String primKey, long roleId) throws SystemException {
5221                    for (ResourcePermission resourcePermission : findByC_N_S_P_R(
5222                                    companyId, name, scope, primKey, roleId, QueryUtil.ALL_POS,
5223                                    QueryUtil.ALL_POS, null)) {
5224                            remove(resourcePermission);
5225                    }
5226            }
5227    
5228            /**
5229             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
5230             *
5231             * @param companyId the company ID
5232             * @param name the name
5233             * @param scope the scope
5234             * @param primKey the prim key
5235             * @param roleId the role ID
5236             * @return the number of matching resource permissions
5237             * @throws SystemException if a system exception occurred
5238             */
5239            public int countByC_N_S_P_R(long companyId, String name, int scope,
5240                    String primKey, long roleId) throws SystemException {
5241                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S_P_R;
5242    
5243                    Object[] finderArgs = new Object[] {
5244                                    companyId, name, scope, primKey, roleId
5245                            };
5246    
5247                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5248                                    this);
5249    
5250                    if (count == null) {
5251                            StringBundler query = new StringBundler(6);
5252    
5253                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5254    
5255                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
5256    
5257                            if (name == null) {
5258                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
5259                            }
5260                            else {
5261                                    if (name.equals(StringPool.BLANK)) {
5262                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
5263                                    }
5264                                    else {
5265                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
5266                                    }
5267                            }
5268    
5269                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
5270    
5271                            if (primKey == null) {
5272                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
5273                            }
5274                            else {
5275                                    if (primKey.equals(StringPool.BLANK)) {
5276                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
5277                                    }
5278                                    else {
5279                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
5280                                    }
5281                            }
5282    
5283                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
5284    
5285                            String sql = query.toString();
5286    
5287                            Session session = null;
5288    
5289                            try {
5290                                    session = openSession();
5291    
5292                                    Query q = session.createQuery(sql);
5293    
5294                                    QueryPos qPos = QueryPos.getInstance(q);
5295    
5296                                    qPos.add(companyId);
5297    
5298                                    if (name != null) {
5299                                            qPos.add(name);
5300                                    }
5301    
5302                                    qPos.add(scope);
5303    
5304                                    if (primKey != null) {
5305                                            qPos.add(primKey);
5306                                    }
5307    
5308                                    qPos.add(roleId);
5309    
5310                                    count = (Long)q.uniqueResult();
5311    
5312                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5313                            }
5314                            catch (Exception e) {
5315                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5316    
5317                                    throw processException(e);
5318                            }
5319                            finally {
5320                                    closeSession(session);
5321                            }
5322                    }
5323    
5324                    return count.intValue();
5325            }
5326    
5327            /**
5328             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
5329             *
5330             * @param companyId the company ID
5331             * @param name the name
5332             * @param scope the scope
5333             * @param primKey the prim key
5334             * @param roleIds the role IDs
5335             * @return the number of matching resource permissions
5336             * @throws SystemException if a system exception occurred
5337             */
5338            public int countByC_N_S_P_R(long companyId, String name, int scope,
5339                    String primKey, long[] roleIds) throws SystemException {
5340                    Object[] finderArgs = new Object[] {
5341                                    companyId, name, scope, primKey, StringUtil.merge(roleIds)
5342                            };
5343    
5344                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R,
5345                                    finderArgs, this);
5346    
5347                    if (count == null) {
5348                            StringBundler query = new StringBundler();
5349    
5350                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5351    
5352                            boolean conjunctionable = false;
5353    
5354                            if (conjunctionable) {
5355                                    query.append(WHERE_AND);
5356                            }
5357    
5358                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_5);
5359    
5360                            conjunctionable = true;
5361    
5362                            if (conjunctionable) {
5363                                    query.append(WHERE_AND);
5364                            }
5365    
5366                            if (name == null) {
5367                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_4);
5368                            }
5369                            else {
5370                                    if (name.equals(StringPool.BLANK)) {
5371                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_6);
5372                                    }
5373                                    else {
5374                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_5);
5375                                    }
5376                            }
5377    
5378                            conjunctionable = true;
5379    
5380                            if (conjunctionable) {
5381                                    query.append(WHERE_AND);
5382                            }
5383    
5384                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_5);
5385    
5386                            conjunctionable = true;
5387    
5388                            if (conjunctionable) {
5389                                    query.append(WHERE_AND);
5390                            }
5391    
5392                            if (primKey == null) {
5393                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_4);
5394                            }
5395                            else {
5396                                    if (primKey.equals(StringPool.BLANK)) {
5397                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_6);
5398                                    }
5399                                    else {
5400                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_5);
5401                                    }
5402                            }
5403    
5404                            conjunctionable = true;
5405    
5406                            if ((roleIds == null) || (roleIds.length > 0)) {
5407                                    if (conjunctionable) {
5408                                            query.append(WHERE_AND);
5409                                    }
5410    
5411                                    query.append(StringPool.OPEN_PARENTHESIS);
5412    
5413                                    for (int i = 0; i < roleIds.length; i++) {
5414                                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_5);
5415    
5416                                            if ((i + 1) < roleIds.length) {
5417                                                    query.append(WHERE_OR);
5418                                            }
5419                                    }
5420    
5421                                    query.append(StringPool.CLOSE_PARENTHESIS);
5422    
5423                                    conjunctionable = true;
5424                            }
5425    
5426                            String sql = query.toString();
5427    
5428                            Session session = null;
5429    
5430                            try {
5431                                    session = openSession();
5432    
5433                                    Query q = session.createQuery(sql);
5434    
5435                                    QueryPos qPos = QueryPos.getInstance(q);
5436    
5437                                    qPos.add(companyId);
5438    
5439                                    if (name != null) {
5440                                            qPos.add(name);
5441                                    }
5442    
5443                                    qPos.add(scope);
5444    
5445                                    if (primKey != null) {
5446                                            qPos.add(primKey);
5447                                    }
5448    
5449                                    if (roleIds != null) {
5450                                            qPos.add(roleIds);
5451                                    }
5452    
5453                                    count = (Long)q.uniqueResult();
5454    
5455                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R,
5456                                            finderArgs, count);
5457                            }
5458                            catch (Exception e) {
5459                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R,
5460                                            finderArgs);
5461    
5462                                    throw processException(e);
5463                            }
5464                            finally {
5465                                    closeSession(session);
5466                            }
5467                    }
5468    
5469                    return count.intValue();
5470            }
5471    
5472            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
5473            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_5 = "(" +
5474                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2) + ")";
5475            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_1 = "resourcePermission.name IS NULL AND ";
5476            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_2 = "resourcePermission.name = ? AND ";
5477            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
5478            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_4 = "(" +
5479                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_NAME_1) + ")";
5480            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_5 = "(" +
5481                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_NAME_2) + ")";
5482            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_6 = "(" +
5483                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_NAME_3) + ")";
5484            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_2 = "resourcePermission.scope = ? AND ";
5485            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_5 = "(" +
5486                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2) + ")";
5487            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
5488            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
5489            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
5490            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_4 = "(" +
5491                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1) + ")";
5492            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_5 = "(" +
5493                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2) + ")";
5494            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_6 = "(" +
5495                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3) + ")";
5496            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_2 = "resourcePermission.roleId = ?";
5497            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_5 = "(" +
5498                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2) + ")";
5499            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_R_A =
5500                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
5501                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
5502                            ResourcePermissionImpl.class,
5503                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_P_R_A",
5504                            new String[] {
5505                                    Long.class.getName(), String.class.getName(),
5506                                    String.class.getName(), Long.class.getName(),
5507                                    Long.class.getName(),
5508                                    
5509                            Integer.class.getName(), Integer.class.getName(),
5510                                    OrderByComparator.class.getName()
5511                            });
5512            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A =
5513                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
5514                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
5515                            ResourcePermissionImpl.class,
5516                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_P_R_A",
5517                            new String[] {
5518                                    Long.class.getName(), String.class.getName(),
5519                                    String.class.getName(), Long.class.getName(),
5520                                    Long.class.getName()
5521                            },
5522                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
5523                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
5524                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
5525                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK |
5526                            ResourcePermissionModelImpl.ACTIONIDS_COLUMN_BITMASK);
5527            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_P_R_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
5528                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
5529                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_P_R_A",
5530                            new String[] {
5531                                    Long.class.getName(), String.class.getName(),
5532                                    String.class.getName(), Long.class.getName(),
5533                                    Long.class.getName()
5534                            });
5535    
5536            /**
5537             * Returns all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5538             *
5539             * @param companyId the company ID
5540             * @param name the name
5541             * @param primKey the prim key
5542             * @param roleId the role ID
5543             * @param actionIds the action IDs
5544             * @return the matching resource permissions
5545             * @throws SystemException if a system exception occurred
5546             */
5547            public List<ResourcePermission> findByC_N_P_R_A(long companyId,
5548                    String name, String primKey, long roleId, long actionIds)
5549                    throws SystemException {
5550                    return findByC_N_P_R_A(companyId, name, primKey, roleId, actionIds,
5551                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5552            }
5553    
5554            /**
5555             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5556             *
5557             * <p>
5558             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5559             * </p>
5560             *
5561             * @param companyId the company ID
5562             * @param name the name
5563             * @param primKey the prim key
5564             * @param roleId the role ID
5565             * @param actionIds the action IDs
5566             * @param start the lower bound of the range of resource permissions
5567             * @param end the upper bound of the range of resource permissions (not inclusive)
5568             * @return the range of matching resource permissions
5569             * @throws SystemException if a system exception occurred
5570             */
5571            public List<ResourcePermission> findByC_N_P_R_A(long companyId,
5572                    String name, String primKey, long roleId, long actionIds, int start,
5573                    int end) throws SystemException {
5574                    return findByC_N_P_R_A(companyId, name, primKey, roleId, actionIds,
5575                            start, end, null);
5576            }
5577    
5578            /**
5579             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5580             *
5581             * <p>
5582             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5583             * </p>
5584             *
5585             * @param companyId the company ID
5586             * @param name the name
5587             * @param primKey the prim key
5588             * @param roleId the role ID
5589             * @param actionIds the action IDs
5590             * @param start the lower bound of the range of resource permissions
5591             * @param end the upper bound of the range of resource permissions (not inclusive)
5592             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5593             * @return the ordered range of matching resource permissions
5594             * @throws SystemException if a system exception occurred
5595             */
5596            public List<ResourcePermission> findByC_N_P_R_A(long companyId,
5597                    String name, String primKey, long roleId, long actionIds, int start,
5598                    int end, OrderByComparator orderByComparator) throws SystemException {
5599                    boolean pagination = true;
5600                    FinderPath finderPath = null;
5601                    Object[] finderArgs = null;
5602    
5603                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5604                                    (orderByComparator == null)) {
5605                            pagination = false;
5606                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A;
5607                            finderArgs = new Object[] {
5608                                            companyId, name, primKey, roleId, actionIds
5609                                    };
5610                    }
5611                    else {
5612                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_R_A;
5613                            finderArgs = new Object[] {
5614                                            companyId, name, primKey, roleId, actionIds,
5615                                            
5616                                            start, end, orderByComparator
5617                                    };
5618                    }
5619    
5620                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
5621                                    finderArgs, this);
5622    
5623                    if ((list != null) && !list.isEmpty()) {
5624                            for (ResourcePermission resourcePermission : list) {
5625                                    if ((companyId != resourcePermission.getCompanyId()) ||
5626                                                    !Validator.equals(name, resourcePermission.getName()) ||
5627                                                    !Validator.equals(primKey,
5628                                                            resourcePermission.getPrimKey()) ||
5629                                                    (roleId != resourcePermission.getRoleId()) ||
5630                                                    (actionIds != resourcePermission.getActionIds())) {
5631                                            list = null;
5632    
5633                                            break;
5634                                    }
5635                            }
5636                    }
5637    
5638                    if (list == null) {
5639                            StringBundler query = null;
5640    
5641                            if (orderByComparator != null) {
5642                                    query = new StringBundler(7 +
5643                                                    (orderByComparator.getOrderByFields().length * 3));
5644                            }
5645                            else {
5646                                    query = new StringBundler(7);
5647                            }
5648    
5649                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
5650    
5651                            query.append(_FINDER_COLUMN_C_N_P_R_A_COMPANYID_2);
5652    
5653                            if (name == null) {
5654                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_1);
5655                            }
5656                            else {
5657                                    if (name.equals(StringPool.BLANK)) {
5658                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_3);
5659                                    }
5660                                    else {
5661                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_2);
5662                                    }
5663                            }
5664    
5665                            if (primKey == null) {
5666                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1);
5667                            }
5668                            else {
5669                                    if (primKey.equals(StringPool.BLANK)) {
5670                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3);
5671                                    }
5672                                    else {
5673                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2);
5674                                    }
5675                            }
5676    
5677                            query.append(_FINDER_COLUMN_C_N_P_R_A_ROLEID_2);
5678    
5679                            query.append(_FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2);
5680    
5681                            if (orderByComparator != null) {
5682                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5683                                            orderByComparator);
5684                            }
5685                            else
5686                             if (pagination) {
5687                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
5688                            }
5689    
5690                            String sql = query.toString();
5691    
5692                            Session session = null;
5693    
5694                            try {
5695                                    session = openSession();
5696    
5697                                    Query q = session.createQuery(sql);
5698    
5699                                    QueryPos qPos = QueryPos.getInstance(q);
5700    
5701                                    qPos.add(companyId);
5702    
5703                                    if (name != null) {
5704                                            qPos.add(name);
5705                                    }
5706    
5707                                    if (primKey != null) {
5708                                            qPos.add(primKey);
5709                                    }
5710    
5711                                    qPos.add(roleId);
5712    
5713                                    qPos.add(actionIds);
5714    
5715                                    if (!pagination) {
5716                                            list = (List<ResourcePermission>)QueryUtil.list(q,
5717                                                            getDialect(), start, end, false);
5718    
5719                                            Collections.sort(list);
5720    
5721                                            list = new UnmodifiableList<ResourcePermission>(list);
5722                                    }
5723                                    else {
5724                                            list = (List<ResourcePermission>)QueryUtil.list(q,
5725                                                            getDialect(), start, end);
5726                                    }
5727    
5728                                    cacheResult(list);
5729    
5730                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5731                            }
5732                            catch (Exception e) {
5733                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5734    
5735                                    throw processException(e);
5736                            }
5737                            finally {
5738                                    closeSession(session);
5739                            }
5740                    }
5741    
5742                    return list;
5743            }
5744    
5745            /**
5746             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5747             *
5748             * @param companyId the company ID
5749             * @param name the name
5750             * @param primKey the prim key
5751             * @param roleId the role ID
5752             * @param actionIds the action IDs
5753             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5754             * @return the first matching resource permission
5755             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
5756             * @throws SystemException if a system exception occurred
5757             */
5758            public ResourcePermission findByC_N_P_R_A_First(long companyId,
5759                    String name, String primKey, long roleId, long actionIds,
5760                    OrderByComparator orderByComparator)
5761                    throws NoSuchResourcePermissionException, SystemException {
5762                    ResourcePermission resourcePermission = fetchByC_N_P_R_A_First(companyId,
5763                                    name, primKey, roleId, actionIds, orderByComparator);
5764    
5765                    if (resourcePermission != null) {
5766                            return resourcePermission;
5767                    }
5768    
5769                    StringBundler msg = new StringBundler(12);
5770    
5771                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5772    
5773                    msg.append("companyId=");
5774                    msg.append(companyId);
5775    
5776                    msg.append(", name=");
5777                    msg.append(name);
5778    
5779                    msg.append(", primKey=");
5780                    msg.append(primKey);
5781    
5782                    msg.append(", roleId=");
5783                    msg.append(roleId);
5784    
5785                    msg.append(", actionIds=");
5786                    msg.append(actionIds);
5787    
5788                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5789    
5790                    throw new NoSuchResourcePermissionException(msg.toString());
5791            }
5792    
5793            /**
5794             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5795             *
5796             * @param companyId the company ID
5797             * @param name the name
5798             * @param primKey the prim key
5799             * @param roleId the role ID
5800             * @param actionIds the action IDs
5801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5802             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
5803             * @throws SystemException if a system exception occurred
5804             */
5805            public ResourcePermission fetchByC_N_P_R_A_First(long companyId,
5806                    String name, String primKey, long roleId, long actionIds,
5807                    OrderByComparator orderByComparator) throws SystemException {
5808                    List<ResourcePermission> list = findByC_N_P_R_A(companyId, name,
5809                                    primKey, roleId, actionIds, 0, 1, orderByComparator);
5810    
5811                    if (!list.isEmpty()) {
5812                            return list.get(0);
5813                    }
5814    
5815                    return null;
5816            }
5817    
5818            /**
5819             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5820             *
5821             * @param companyId the company ID
5822             * @param name the name
5823             * @param primKey the prim key
5824             * @param roleId the role ID
5825             * @param actionIds the action IDs
5826             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5827             * @return the last matching resource permission
5828             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
5829             * @throws SystemException if a system exception occurred
5830             */
5831            public ResourcePermission findByC_N_P_R_A_Last(long companyId, String name,
5832                    String primKey, long roleId, long actionIds,
5833                    OrderByComparator orderByComparator)
5834                    throws NoSuchResourcePermissionException, SystemException {
5835                    ResourcePermission resourcePermission = fetchByC_N_P_R_A_Last(companyId,
5836                                    name, primKey, roleId, actionIds, orderByComparator);
5837    
5838                    if (resourcePermission != null) {
5839                            return resourcePermission;
5840                    }
5841    
5842                    StringBundler msg = new StringBundler(12);
5843    
5844                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5845    
5846                    msg.append("companyId=");
5847                    msg.append(companyId);
5848    
5849                    msg.append(", name=");
5850                    msg.append(name);
5851    
5852                    msg.append(", primKey=");
5853                    msg.append(primKey);
5854    
5855                    msg.append(", roleId=");
5856                    msg.append(roleId);
5857    
5858                    msg.append(", actionIds=");
5859                    msg.append(actionIds);
5860    
5861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5862    
5863                    throw new NoSuchResourcePermissionException(msg.toString());
5864            }
5865    
5866            /**
5867             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5868             *
5869             * @param companyId the company ID
5870             * @param name the name
5871             * @param primKey the prim key
5872             * @param roleId the role ID
5873             * @param actionIds the action IDs
5874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5875             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
5876             * @throws SystemException if a system exception occurred
5877             */
5878            public ResourcePermission fetchByC_N_P_R_A_Last(long companyId,
5879                    String name, String primKey, long roleId, long actionIds,
5880                    OrderByComparator orderByComparator) throws SystemException {
5881                    int count = countByC_N_P_R_A(companyId, name, primKey, roleId, actionIds);
5882    
5883                    List<ResourcePermission> list = findByC_N_P_R_A(companyId, name,
5884                                    primKey, roleId, actionIds, count - 1, count, orderByComparator);
5885    
5886                    if (!list.isEmpty()) {
5887                            return list.get(0);
5888                    }
5889    
5890                    return null;
5891            }
5892    
5893            /**
5894             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
5895             *
5896             * @param resourcePermissionId the primary key of the current resource permission
5897             * @param companyId the company ID
5898             * @param name the name
5899             * @param primKey the prim key
5900             * @param roleId the role ID
5901             * @param actionIds the action IDs
5902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5903             * @return the previous, current, and next resource permission
5904             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
5905             * @throws SystemException if a system exception occurred
5906             */
5907            public ResourcePermission[] findByC_N_P_R_A_PrevAndNext(
5908                    long resourcePermissionId, long companyId, String name, String primKey,
5909                    long roleId, long actionIds, OrderByComparator orderByComparator)
5910                    throws NoSuchResourcePermissionException, SystemException {
5911                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
5912    
5913                    Session session = null;
5914    
5915                    try {
5916                            session = openSession();
5917    
5918                            ResourcePermission[] array = new ResourcePermissionImpl[3];
5919    
5920                            array[0] = getByC_N_P_R_A_PrevAndNext(session, resourcePermission,
5921                                            companyId, name, primKey, roleId, actionIds,
5922                                            orderByComparator, true);
5923    
5924                            array[1] = resourcePermission;
5925    
5926                            array[2] = getByC_N_P_R_A_PrevAndNext(session, resourcePermission,
5927                                            companyId, name, primKey, roleId, actionIds,
5928                                            orderByComparator, false);
5929    
5930                            return array;
5931                    }
5932                    catch (Exception e) {
5933                            throw processException(e);
5934                    }
5935                    finally {
5936                            closeSession(session);
5937                    }
5938            }
5939    
5940            protected ResourcePermission getByC_N_P_R_A_PrevAndNext(Session session,
5941                    ResourcePermission resourcePermission, long companyId, String name,
5942                    String primKey, long roleId, long actionIds,
5943                    OrderByComparator orderByComparator, boolean previous) {
5944                    StringBundler query = null;
5945    
5946                    if (orderByComparator != null) {
5947                            query = new StringBundler(6 +
5948                                            (orderByComparator.getOrderByFields().length * 6));
5949                    }
5950                    else {
5951                            query = new StringBundler(3);
5952                    }
5953    
5954                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
5955    
5956                    query.append(_FINDER_COLUMN_C_N_P_R_A_COMPANYID_2);
5957    
5958                    if (name == null) {
5959                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_1);
5960                    }
5961                    else {
5962                            if (name.equals(StringPool.BLANK)) {
5963                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_3);
5964                            }
5965                            else {
5966                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_2);
5967                            }
5968                    }
5969    
5970                    if (primKey == null) {
5971                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1);
5972                    }
5973                    else {
5974                            if (primKey.equals(StringPool.BLANK)) {
5975                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3);
5976                            }
5977                            else {
5978                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2);
5979                            }
5980                    }
5981    
5982                    query.append(_FINDER_COLUMN_C_N_P_R_A_ROLEID_2);
5983    
5984                    query.append(_FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2);
5985    
5986                    if (orderByComparator != null) {
5987                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5988    
5989                            if (orderByConditionFields.length > 0) {
5990                                    query.append(WHERE_AND);
5991                            }
5992    
5993                            for (int i = 0; i < orderByConditionFields.length; i++) {
5994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5995                                    query.append(orderByConditionFields[i]);
5996    
5997                                    if ((i + 1) < orderByConditionFields.length) {
5998                                            if (orderByComparator.isAscending() ^ previous) {
5999                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6000                                            }
6001                                            else {
6002                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6003                                            }
6004                                    }
6005                                    else {
6006                                            if (orderByComparator.isAscending() ^ previous) {
6007                                                    query.append(WHERE_GREATER_THAN);
6008                                            }
6009                                            else {
6010                                                    query.append(WHERE_LESSER_THAN);
6011                                            }
6012                                    }
6013                            }
6014    
6015                            query.append(ORDER_BY_CLAUSE);
6016    
6017                            String[] orderByFields = orderByComparator.getOrderByFields();
6018    
6019                            for (int i = 0; i < orderByFields.length; i++) {
6020                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6021                                    query.append(orderByFields[i]);
6022    
6023                                    if ((i + 1) < orderByFields.length) {
6024                                            if (orderByComparator.isAscending() ^ previous) {
6025                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6026                                            }
6027                                            else {
6028                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6029                                            }
6030                                    }
6031                                    else {
6032                                            if (orderByComparator.isAscending() ^ previous) {
6033                                                    query.append(ORDER_BY_ASC);
6034                                            }
6035                                            else {
6036                                                    query.append(ORDER_BY_DESC);
6037                                            }
6038                                    }
6039                            }
6040                    }
6041                    else {
6042                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
6043                    }
6044    
6045                    String sql = query.toString();
6046    
6047                    Query q = session.createQuery(sql);
6048    
6049                    q.setFirstResult(0);
6050                    q.setMaxResults(2);
6051    
6052                    QueryPos qPos = QueryPos.getInstance(q);
6053    
6054                    qPos.add(companyId);
6055    
6056                    if (name != null) {
6057                            qPos.add(name);
6058                    }
6059    
6060                    if (primKey != null) {
6061                            qPos.add(primKey);
6062                    }
6063    
6064                    qPos.add(roleId);
6065    
6066                    qPos.add(actionIds);
6067    
6068                    if (orderByComparator != null) {
6069                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
6070    
6071                            for (Object value : values) {
6072                                    qPos.add(value);
6073                            }
6074                    }
6075    
6076                    List<ResourcePermission> list = q.list();
6077    
6078                    if (list.size() == 2) {
6079                            return list.get(1);
6080                    }
6081                    else {
6082                            return null;
6083                    }
6084            }
6085    
6086            /**
6087             * Removes all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63; from the database.
6088             *
6089             * @param companyId the company ID
6090             * @param name the name
6091             * @param primKey the prim key
6092             * @param roleId the role ID
6093             * @param actionIds the action IDs
6094             * @throws SystemException if a system exception occurred
6095             */
6096            public void removeByC_N_P_R_A(long companyId, String name, String primKey,
6097                    long roleId, long actionIds) throws SystemException {
6098                    for (ResourcePermission resourcePermission : findByC_N_P_R_A(
6099                                    companyId, name, primKey, roleId, actionIds, QueryUtil.ALL_POS,
6100                                    QueryUtil.ALL_POS, null)) {
6101                            remove(resourcePermission);
6102                    }
6103            }
6104    
6105            /**
6106             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6107             *
6108             * @param companyId the company ID
6109             * @param name the name
6110             * @param primKey the prim key
6111             * @param roleId the role ID
6112             * @param actionIds the action IDs
6113             * @return the number of matching resource permissions
6114             * @throws SystemException if a system exception occurred
6115             */
6116            public int countByC_N_P_R_A(long companyId, String name, String primKey,
6117                    long roleId, long actionIds) throws SystemException {
6118                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_P_R_A;
6119    
6120                    Object[] finderArgs = new Object[] {
6121                                    companyId, name, primKey, roleId, actionIds
6122                            };
6123    
6124                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6125                                    this);
6126    
6127                    if (count == null) {
6128                            StringBundler query = new StringBundler(6);
6129    
6130                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6131    
6132                            query.append(_FINDER_COLUMN_C_N_P_R_A_COMPANYID_2);
6133    
6134                            if (name == null) {
6135                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_1);
6136                            }
6137                            else {
6138                                    if (name.equals(StringPool.BLANK)) {
6139                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_3);
6140                                    }
6141                                    else {
6142                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_2);
6143                                    }
6144                            }
6145    
6146                            if (primKey == null) {
6147                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1);
6148                            }
6149                            else {
6150                                    if (primKey.equals(StringPool.BLANK)) {
6151                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3);
6152                                    }
6153                                    else {
6154                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2);
6155                                    }
6156                            }
6157    
6158                            query.append(_FINDER_COLUMN_C_N_P_R_A_ROLEID_2);
6159    
6160                            query.append(_FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2);
6161    
6162                            String sql = query.toString();
6163    
6164                            Session session = null;
6165    
6166                            try {
6167                                    session = openSession();
6168    
6169                                    Query q = session.createQuery(sql);
6170    
6171                                    QueryPos qPos = QueryPos.getInstance(q);
6172    
6173                                    qPos.add(companyId);
6174    
6175                                    if (name != null) {
6176                                            qPos.add(name);
6177                                    }
6178    
6179                                    if (primKey != null) {
6180                                            qPos.add(primKey);
6181                                    }
6182    
6183                                    qPos.add(roleId);
6184    
6185                                    qPos.add(actionIds);
6186    
6187                                    count = (Long)q.uniqueResult();
6188    
6189                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6190                            }
6191                            catch (Exception e) {
6192                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6193    
6194                                    throw processException(e);
6195                            }
6196                            finally {
6197                                    closeSession(session);
6198                            }
6199                    }
6200    
6201                    return count.intValue();
6202            }
6203    
6204            private static final String _FINDER_COLUMN_C_N_P_R_A_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6205            private static final String _FINDER_COLUMN_C_N_P_R_A_NAME_1 = "resourcePermission.name IS NULL AND ";
6206            private static final String _FINDER_COLUMN_C_N_P_R_A_NAME_2 = "resourcePermission.name = ? AND ";
6207            private static final String _FINDER_COLUMN_C_N_P_R_A_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6208            private static final String _FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
6209            private static final String _FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
6210            private static final String _FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
6211            private static final String _FINDER_COLUMN_C_N_P_R_A_ROLEID_2 = "resourcePermission.roleId = ? AND ";
6212            private static final String _FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2 = "resourcePermission.actionIds = ?";
6213            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A =
6214                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
6215                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
6216                            ResourcePermissionImpl.class,
6217                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P_R_A",
6218                            new String[] {
6219                                    Long.class.getName(), String.class.getName(),
6220                                    Integer.class.getName(), String.class.getName(),
6221                                    Long.class.getName(), Long.class.getName(),
6222                                    
6223                            Integer.class.getName(), Integer.class.getName(),
6224                                    OrderByComparator.class.getName()
6225                            });
6226            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A =
6227                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
6228                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
6229                            ResourcePermissionImpl.class,
6230                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P_R_A",
6231                            new String[] {
6232                                    Long.class.getName(), String.class.getName(),
6233                                    Integer.class.getName(), String.class.getName(),
6234                                    Long.class.getName(), Long.class.getName()
6235                            },
6236                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
6237                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
6238                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
6239                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
6240                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK |
6241                            ResourcePermissionModelImpl.ACTIONIDS_COLUMN_BITMASK);
6242            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
6243                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
6244                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R_A",
6245                            new String[] {
6246                                    Long.class.getName(), String.class.getName(),
6247                                    Integer.class.getName(), String.class.getName(),
6248                                    Long.class.getName(), Long.class.getName()
6249                            });
6250            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R_A =
6251                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
6252                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
6253                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_N_S_P_R_A",
6254                            new String[] {
6255                                    Long.class.getName(), String.class.getName(),
6256                                    Integer.class.getName(), String.class.getName(),
6257                                    Long.class.getName(), Long.class.getName()
6258                            });
6259    
6260            /**
6261             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6262             *
6263             * @param companyId the company ID
6264             * @param name the name
6265             * @param scope the scope
6266             * @param primKey the prim key
6267             * @param roleId the role ID
6268             * @param actionIds the action IDs
6269             * @return the matching resource permissions
6270             * @throws SystemException if a system exception occurred
6271             */
6272            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
6273                    String name, int scope, String primKey, long roleId, long actionIds)
6274                    throws SystemException {
6275                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleId,
6276                            actionIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6277            }
6278    
6279            /**
6280             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6281             *
6282             * <p>
6283             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6284             * </p>
6285             *
6286             * @param companyId the company ID
6287             * @param name the name
6288             * @param scope the scope
6289             * @param primKey the prim key
6290             * @param roleId the role ID
6291             * @param actionIds the action IDs
6292             * @param start the lower bound of the range of resource permissions
6293             * @param end the upper bound of the range of resource permissions (not inclusive)
6294             * @return the range of matching resource permissions
6295             * @throws SystemException if a system exception occurred
6296             */
6297            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
6298                    String name, int scope, String primKey, long roleId, long actionIds,
6299                    int start, int end) throws SystemException {
6300                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleId,
6301                            actionIds, start, end, null);
6302            }
6303    
6304            /**
6305             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6306             *
6307             * <p>
6308             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6309             * </p>
6310             *
6311             * @param companyId the company ID
6312             * @param name the name
6313             * @param scope the scope
6314             * @param primKey the prim key
6315             * @param roleId the role ID
6316             * @param actionIds the action IDs
6317             * @param start the lower bound of the range of resource permissions
6318             * @param end the upper bound of the range of resource permissions (not inclusive)
6319             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6320             * @return the ordered range of matching resource permissions
6321             * @throws SystemException if a system exception occurred
6322             */
6323            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
6324                    String name, int scope, String primKey, long roleId, long actionIds,
6325                    int start, int end, OrderByComparator orderByComparator)
6326                    throws SystemException {
6327                    boolean pagination = true;
6328                    FinderPath finderPath = null;
6329                    Object[] finderArgs = null;
6330    
6331                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6332                                    (orderByComparator == null)) {
6333                            pagination = false;
6334                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A;
6335                            finderArgs = new Object[] {
6336                                            companyId, name, scope, primKey, roleId, actionIds
6337                                    };
6338                    }
6339                    else {
6340                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A;
6341                            finderArgs = new Object[] {
6342                                            companyId, name, scope, primKey, roleId, actionIds,
6343                                            
6344                                            start, end, orderByComparator
6345                                    };
6346                    }
6347    
6348                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
6349                                    finderArgs, this);
6350    
6351                    if ((list != null) && !list.isEmpty()) {
6352                            for (ResourcePermission resourcePermission : list) {
6353                                    if ((companyId != resourcePermission.getCompanyId()) ||
6354                                                    !Validator.equals(name, resourcePermission.getName()) ||
6355                                                    (scope != resourcePermission.getScope()) ||
6356                                                    !Validator.equals(primKey,
6357                                                            resourcePermission.getPrimKey()) ||
6358                                                    (roleId != resourcePermission.getRoleId()) ||
6359                                                    (actionIds != resourcePermission.getActionIds())) {
6360                                            list = null;
6361    
6362                                            break;
6363                                    }
6364                            }
6365                    }
6366    
6367                    if (list == null) {
6368                            StringBundler query = null;
6369    
6370                            if (orderByComparator != null) {
6371                                    query = new StringBundler(8 +
6372                                                    (orderByComparator.getOrderByFields().length * 3));
6373                            }
6374                            else {
6375                                    query = new StringBundler(8);
6376                            }
6377    
6378                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
6379    
6380                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2);
6381    
6382                            if (name == null) {
6383                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1);
6384                            }
6385                            else {
6386                                    if (name.equals(StringPool.BLANK)) {
6387                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3);
6388                                    }
6389                                    else {
6390                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2);
6391                                    }
6392                            }
6393    
6394                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2);
6395    
6396                            if (primKey == null) {
6397                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1);
6398                            }
6399                            else {
6400                                    if (primKey.equals(StringPool.BLANK)) {
6401                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3);
6402                                    }
6403                                    else {
6404                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2);
6405                                    }
6406                            }
6407    
6408                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2);
6409    
6410                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2);
6411    
6412                            if (orderByComparator != null) {
6413                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6414                                            orderByComparator);
6415                            }
6416                            else
6417                             if (pagination) {
6418                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
6419                            }
6420    
6421                            String sql = query.toString();
6422    
6423                            Session session = null;
6424    
6425                            try {
6426                                    session = openSession();
6427    
6428                                    Query q = session.createQuery(sql);
6429    
6430                                    QueryPos qPos = QueryPos.getInstance(q);
6431    
6432                                    qPos.add(companyId);
6433    
6434                                    if (name != null) {
6435                                            qPos.add(name);
6436                                    }
6437    
6438                                    qPos.add(scope);
6439    
6440                                    if (primKey != null) {
6441                                            qPos.add(primKey);
6442                                    }
6443    
6444                                    qPos.add(roleId);
6445    
6446                                    qPos.add(actionIds);
6447    
6448                                    if (!pagination) {
6449                                            list = (List<ResourcePermission>)QueryUtil.list(q,
6450                                                            getDialect(), start, end, false);
6451    
6452                                            Collections.sort(list);
6453    
6454                                            list = new UnmodifiableList<ResourcePermission>(list);
6455                                    }
6456                                    else {
6457                                            list = (List<ResourcePermission>)QueryUtil.list(q,
6458                                                            getDialect(), start, end);
6459                                    }
6460    
6461                                    cacheResult(list);
6462    
6463                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6464                            }
6465                            catch (Exception e) {
6466                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6467    
6468                                    throw processException(e);
6469                            }
6470                            finally {
6471                                    closeSession(session);
6472                            }
6473                    }
6474    
6475                    return list;
6476            }
6477    
6478            /**
6479             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6480             *
6481             * @param companyId the company ID
6482             * @param name the name
6483             * @param scope the scope
6484             * @param primKey the prim key
6485             * @param roleId the role ID
6486             * @param actionIds the action IDs
6487             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6488             * @return the first matching resource permission
6489             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
6490             * @throws SystemException if a system exception occurred
6491             */
6492            public ResourcePermission findByC_N_S_P_R_A_First(long companyId,
6493                    String name, int scope, String primKey, long roleId, long actionIds,
6494                    OrderByComparator orderByComparator)
6495                    throws NoSuchResourcePermissionException, SystemException {
6496                    ResourcePermission resourcePermission = fetchByC_N_S_P_R_A_First(companyId,
6497                                    name, scope, primKey, roleId, actionIds, orderByComparator);
6498    
6499                    if (resourcePermission != null) {
6500                            return resourcePermission;
6501                    }
6502    
6503                    StringBundler msg = new StringBundler(14);
6504    
6505                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6506    
6507                    msg.append("companyId=");
6508                    msg.append(companyId);
6509    
6510                    msg.append(", name=");
6511                    msg.append(name);
6512    
6513                    msg.append(", scope=");
6514                    msg.append(scope);
6515    
6516                    msg.append(", primKey=");
6517                    msg.append(primKey);
6518    
6519                    msg.append(", roleId=");
6520                    msg.append(roleId);
6521    
6522                    msg.append(", actionIds=");
6523                    msg.append(actionIds);
6524    
6525                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6526    
6527                    throw new NoSuchResourcePermissionException(msg.toString());
6528            }
6529    
6530            /**
6531             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6532             *
6533             * @param companyId the company ID
6534             * @param name the name
6535             * @param scope the scope
6536             * @param primKey the prim key
6537             * @param roleId the role ID
6538             * @param actionIds the action IDs
6539             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6540             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
6541             * @throws SystemException if a system exception occurred
6542             */
6543            public ResourcePermission fetchByC_N_S_P_R_A_First(long companyId,
6544                    String name, int scope, String primKey, long roleId, long actionIds,
6545                    OrderByComparator orderByComparator) throws SystemException {
6546                    List<ResourcePermission> list = findByC_N_S_P_R_A(companyId, name,
6547                                    scope, primKey, roleId, actionIds, 0, 1, orderByComparator);
6548    
6549                    if (!list.isEmpty()) {
6550                            return list.get(0);
6551                    }
6552    
6553                    return null;
6554            }
6555    
6556            /**
6557             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6558             *
6559             * @param companyId the company ID
6560             * @param name the name
6561             * @param scope the scope
6562             * @param primKey the prim key
6563             * @param roleId the role ID
6564             * @param actionIds the action IDs
6565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6566             * @return the last matching resource permission
6567             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
6568             * @throws SystemException if a system exception occurred
6569             */
6570            public ResourcePermission findByC_N_S_P_R_A_Last(long companyId,
6571                    String name, int scope, String primKey, long roleId, long actionIds,
6572                    OrderByComparator orderByComparator)
6573                    throws NoSuchResourcePermissionException, SystemException {
6574                    ResourcePermission resourcePermission = fetchByC_N_S_P_R_A_Last(companyId,
6575                                    name, scope, primKey, roleId, actionIds, orderByComparator);
6576    
6577                    if (resourcePermission != null) {
6578                            return resourcePermission;
6579                    }
6580    
6581                    StringBundler msg = new StringBundler(14);
6582    
6583                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6584    
6585                    msg.append("companyId=");
6586                    msg.append(companyId);
6587    
6588                    msg.append(", name=");
6589                    msg.append(name);
6590    
6591                    msg.append(", scope=");
6592                    msg.append(scope);
6593    
6594                    msg.append(", primKey=");
6595                    msg.append(primKey);
6596    
6597                    msg.append(", roleId=");
6598                    msg.append(roleId);
6599    
6600                    msg.append(", actionIds=");
6601                    msg.append(actionIds);
6602    
6603                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6604    
6605                    throw new NoSuchResourcePermissionException(msg.toString());
6606            }
6607    
6608            /**
6609             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6610             *
6611             * @param companyId the company ID
6612             * @param name the name
6613             * @param scope the scope
6614             * @param primKey the prim key
6615             * @param roleId the role ID
6616             * @param actionIds the action IDs
6617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6618             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
6619             * @throws SystemException if a system exception occurred
6620             */
6621            public ResourcePermission fetchByC_N_S_P_R_A_Last(long companyId,
6622                    String name, int scope, String primKey, long roleId, long actionIds,
6623                    OrderByComparator orderByComparator) throws SystemException {
6624                    int count = countByC_N_S_P_R_A(companyId, name, scope, primKey, roleId,
6625                                    actionIds);
6626    
6627                    List<ResourcePermission> list = findByC_N_S_P_R_A(companyId, name,
6628                                    scope, primKey, roleId, actionIds, count - 1, count,
6629                                    orderByComparator);
6630    
6631                    if (!list.isEmpty()) {
6632                            return list.get(0);
6633                    }
6634    
6635                    return null;
6636            }
6637    
6638            /**
6639             * Returns 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; and roleId = &#63; and actionIds = &#63;.
6640             *
6641             * @param resourcePermissionId the primary key of the current resource permission
6642             * @param companyId the company ID
6643             * @param name the name
6644             * @param scope the scope
6645             * @param primKey the prim key
6646             * @param roleId the role ID
6647             * @param actionIds the action IDs
6648             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6649             * @return the previous, current, and next resource permission
6650             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
6651             * @throws SystemException if a system exception occurred
6652             */
6653            public ResourcePermission[] findByC_N_S_P_R_A_PrevAndNext(
6654                    long resourcePermissionId, long companyId, String name, int scope,
6655                    String primKey, long roleId, long actionIds,
6656                    OrderByComparator orderByComparator)
6657                    throws NoSuchResourcePermissionException, SystemException {
6658                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
6659    
6660                    Session session = null;
6661    
6662                    try {
6663                            session = openSession();
6664    
6665                            ResourcePermission[] array = new ResourcePermissionImpl[3];
6666    
6667                            array[0] = getByC_N_S_P_R_A_PrevAndNext(session,
6668                                            resourcePermission, companyId, name, scope, primKey,
6669                                            roleId, actionIds, orderByComparator, true);
6670    
6671                            array[1] = resourcePermission;
6672    
6673                            array[2] = getByC_N_S_P_R_A_PrevAndNext(session,
6674                                            resourcePermission, companyId, name, scope, primKey,
6675                                            roleId, actionIds, orderByComparator, false);
6676    
6677                            return array;
6678                    }
6679                    catch (Exception e) {
6680                            throw processException(e);
6681                    }
6682                    finally {
6683                            closeSession(session);
6684                    }
6685            }
6686    
6687            protected ResourcePermission getByC_N_S_P_R_A_PrevAndNext(Session session,
6688                    ResourcePermission resourcePermission, long companyId, String name,
6689                    int scope, String primKey, long roleId, long actionIds,
6690                    OrderByComparator orderByComparator, boolean previous) {
6691                    StringBundler query = null;
6692    
6693                    if (orderByComparator != null) {
6694                            query = new StringBundler(6 +
6695                                            (orderByComparator.getOrderByFields().length * 6));
6696                    }
6697                    else {
6698                            query = new StringBundler(3);
6699                    }
6700    
6701                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
6702    
6703                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2);
6704    
6705                    if (name == null) {
6706                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1);
6707                    }
6708                    else {
6709                            if (name.equals(StringPool.BLANK)) {
6710                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3);
6711                            }
6712                            else {
6713                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2);
6714                            }
6715                    }
6716    
6717                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2);
6718    
6719                    if (primKey == null) {
6720                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1);
6721                    }
6722                    else {
6723                            if (primKey.equals(StringPool.BLANK)) {
6724                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3);
6725                            }
6726                            else {
6727                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2);
6728                            }
6729                    }
6730    
6731                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2);
6732    
6733                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2);
6734    
6735                    if (orderByComparator != null) {
6736                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6737    
6738                            if (orderByConditionFields.length > 0) {
6739                                    query.append(WHERE_AND);
6740                            }
6741    
6742                            for (int i = 0; i < orderByConditionFields.length; i++) {
6743                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6744                                    query.append(orderByConditionFields[i]);
6745    
6746                                    if ((i + 1) < orderByConditionFields.length) {
6747                                            if (orderByComparator.isAscending() ^ previous) {
6748                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6749                                            }
6750                                            else {
6751                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6752                                            }
6753                                    }
6754                                    else {
6755                                            if (orderByComparator.isAscending() ^ previous) {
6756                                                    query.append(WHERE_GREATER_THAN);
6757                                            }
6758                                            else {
6759                                                    query.append(WHERE_LESSER_THAN);
6760                                            }
6761                                    }
6762                            }
6763    
6764                            query.append(ORDER_BY_CLAUSE);
6765    
6766                            String[] orderByFields = orderByComparator.getOrderByFields();
6767    
6768                            for (int i = 0; i < orderByFields.length; i++) {
6769                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6770                                    query.append(orderByFields[i]);
6771    
6772                                    if ((i + 1) < orderByFields.length) {
6773                                            if (orderByComparator.isAscending() ^ previous) {
6774                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6775                                            }
6776                                            else {
6777                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6778                                            }
6779                                    }
6780                                    else {
6781                                            if (orderByComparator.isAscending() ^ previous) {
6782                                                    query.append(ORDER_BY_ASC);
6783                                            }
6784                                            else {
6785                                                    query.append(ORDER_BY_DESC);
6786                                            }
6787                                    }
6788                            }
6789                    }
6790                    else {
6791                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
6792                    }
6793    
6794                    String sql = query.toString();
6795    
6796                    Query q = session.createQuery(sql);
6797    
6798                    q.setFirstResult(0);
6799                    q.setMaxResults(2);
6800    
6801                    QueryPos qPos = QueryPos.getInstance(q);
6802    
6803                    qPos.add(companyId);
6804    
6805                    if (name != null) {
6806                            qPos.add(name);
6807                    }
6808    
6809                    qPos.add(scope);
6810    
6811                    if (primKey != null) {
6812                            qPos.add(primKey);
6813                    }
6814    
6815                    qPos.add(roleId);
6816    
6817                    qPos.add(actionIds);
6818    
6819                    if (orderByComparator != null) {
6820                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
6821    
6822                            for (Object value : values) {
6823                                    qPos.add(value);
6824                            }
6825                    }
6826    
6827                    List<ResourcePermission> list = q.list();
6828    
6829                    if (list.size() == 2) {
6830                            return list.get(1);
6831                    }
6832                    else {
6833                            return null;
6834                    }
6835            }
6836    
6837            /**
6838             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
6839             *
6840             * <p>
6841             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6842             * </p>
6843             *
6844             * @param companyId the company ID
6845             * @param name the name
6846             * @param scope the scope
6847             * @param primKey the prim key
6848             * @param roleIds the role IDs
6849             * @param actionIds the action IDs
6850             * @return the matching resource permissions
6851             * @throws SystemException if a system exception occurred
6852             */
6853            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
6854                    String name, int scope, String primKey, long[] roleIds, long actionIds)
6855                    throws SystemException {
6856                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleIds,
6857                            actionIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6858            }
6859    
6860            /**
6861             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
6862             *
6863             * <p>
6864             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6865             * </p>
6866             *
6867             * @param companyId the company ID
6868             * @param name the name
6869             * @param scope the scope
6870             * @param primKey the prim key
6871             * @param roleIds the role IDs
6872             * @param actionIds the action IDs
6873             * @param start the lower bound of the range of resource permissions
6874             * @param end the upper bound of the range of resource permissions (not inclusive)
6875             * @return the range of matching resource permissions
6876             * @throws SystemException if a system exception occurred
6877             */
6878            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
6879                    String name, int scope, String primKey, long[] roleIds, long actionIds,
6880                    int start, int end) throws SystemException {
6881                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleIds,
6882                            actionIds, start, end, null);
6883            }
6884    
6885            /**
6886             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
6887             *
6888             * <p>
6889             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6890             * </p>
6891             *
6892             * @param companyId the company ID
6893             * @param name the name
6894             * @param scope the scope
6895             * @param primKey the prim key
6896             * @param roleIds the role IDs
6897             * @param actionIds the action IDs
6898             * @param start the lower bound of the range of resource permissions
6899             * @param end the upper bound of the range of resource permissions (not inclusive)
6900             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6901             * @return the ordered range of matching resource permissions
6902             * @throws SystemException if a system exception occurred
6903             */
6904            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
6905                    String name, int scope, String primKey, long[] roleIds, long actionIds,
6906                    int start, int end, OrderByComparator orderByComparator)
6907                    throws SystemException {
6908                    if ((roleIds != null) && (roleIds.length == 1)) {
6909                            return findByC_N_S_P_R_A(companyId, name, scope, primKey,
6910                                    roleIds[0], actionIds, start, end, orderByComparator);
6911                    }
6912    
6913                    boolean pagination = true;
6914                    Object[] finderArgs = null;
6915    
6916                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6917                                    (orderByComparator == null)) {
6918                            pagination = false;
6919                            finderArgs = new Object[] {
6920                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
6921                                            actionIds
6922                                    };
6923                    }
6924                    else {
6925                            finderArgs = new Object[] {
6926                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
6927                                            actionIds,
6928                                            
6929                                            start, end, orderByComparator
6930                                    };
6931                    }
6932    
6933                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A,
6934                                    finderArgs, this);
6935    
6936                    if ((list != null) && !list.isEmpty()) {
6937                            for (ResourcePermission resourcePermission : list) {
6938                                    if ((companyId != resourcePermission.getCompanyId()) ||
6939                                                    !Validator.equals(name, resourcePermission.getName()) ||
6940                                                    (scope != resourcePermission.getScope()) ||
6941                                                    !Validator.equals(primKey,
6942                                                            resourcePermission.getPrimKey()) ||
6943                                                    !ArrayUtil.contains(roleIds,
6944                                                            resourcePermission.getRoleId()) ||
6945                                                    (actionIds != resourcePermission.getActionIds())) {
6946                                            list = null;
6947    
6948                                            break;
6949                                    }
6950                            }
6951                    }
6952    
6953                    if (list == null) {
6954                            StringBundler query = new StringBundler();
6955    
6956                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
6957    
6958                            boolean conjunctionable = false;
6959    
6960                            if (conjunctionable) {
6961                                    query.append(WHERE_AND);
6962                            }
6963    
6964                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_5);
6965    
6966                            conjunctionable = true;
6967    
6968                            if (conjunctionable) {
6969                                    query.append(WHERE_AND);
6970                            }
6971    
6972                            if (name == null) {
6973                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_4);
6974                            }
6975                            else {
6976                                    if (name.equals(StringPool.BLANK)) {
6977                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_6);
6978                                    }
6979                                    else {
6980                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_5);
6981                                    }
6982                            }
6983    
6984                            conjunctionable = true;
6985    
6986                            if (conjunctionable) {
6987                                    query.append(WHERE_AND);
6988                            }
6989    
6990                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_5);
6991    
6992                            conjunctionable = true;
6993    
6994                            if (conjunctionable) {
6995                                    query.append(WHERE_AND);
6996                            }
6997    
6998                            if (primKey == null) {
6999                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_4);
7000                            }
7001                            else {
7002                                    if (primKey.equals(StringPool.BLANK)) {
7003                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_6);
7004                                    }
7005                                    else {
7006                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_5);
7007                                    }
7008                            }
7009    
7010                            conjunctionable = true;
7011    
7012                            if ((roleIds == null) || (roleIds.length > 0)) {
7013                                    if (conjunctionable) {
7014                                            query.append(WHERE_AND);
7015                                    }
7016    
7017                                    query.append(StringPool.OPEN_PARENTHESIS);
7018    
7019                                    for (int i = 0; i < roleIds.length; i++) {
7020                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_5);
7021    
7022                                            if ((i + 1) < roleIds.length) {
7023                                                    query.append(WHERE_OR);
7024                                            }
7025                                    }
7026    
7027                                    query.append(StringPool.CLOSE_PARENTHESIS);
7028    
7029                                    conjunctionable = true;
7030                            }
7031    
7032                            if (conjunctionable) {
7033                                    query.append(WHERE_AND);
7034                            }
7035    
7036                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_5);
7037    
7038                            conjunctionable = true;
7039    
7040                            if (orderByComparator != null) {
7041                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7042                                            orderByComparator);
7043                            }
7044                            else
7045                             if (pagination) {
7046                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
7047                            }
7048    
7049                            String sql = query.toString();
7050    
7051                            Session session = null;
7052    
7053                            try {
7054                                    session = openSession();
7055    
7056                                    Query q = session.createQuery(sql);
7057    
7058                                    QueryPos qPos = QueryPos.getInstance(q);
7059    
7060                                    qPos.add(companyId);
7061    
7062                                    if (name != null) {
7063                                            qPos.add(name);
7064                                    }
7065    
7066                                    qPos.add(scope);
7067    
7068                                    if (primKey != null) {
7069                                            qPos.add(primKey);
7070                                    }
7071    
7072                                    if (roleIds != null) {
7073                                            qPos.add(roleIds);
7074                                    }
7075    
7076                                    qPos.add(actionIds);
7077    
7078                                    if (!pagination) {
7079                                            list = (List<ResourcePermission>)QueryUtil.list(q,
7080                                                            getDialect(), start, end, false);
7081    
7082                                            Collections.sort(list);
7083    
7084                                            list = new UnmodifiableList<ResourcePermission>(list);
7085                                    }
7086                                    else {
7087                                            list = (List<ResourcePermission>)QueryUtil.list(q,
7088                                                            getDialect(), start, end);
7089                                    }
7090    
7091                                    cacheResult(list);
7092    
7093                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A,
7094                                            finderArgs, list);
7095                            }
7096                            catch (Exception e) {
7097                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A,
7098                                            finderArgs);
7099    
7100                                    throw processException(e);
7101                            }
7102                            finally {
7103                                    closeSession(session);
7104                            }
7105                    }
7106    
7107                    return list;
7108            }
7109    
7110            /**
7111             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63; from the database.
7112             *
7113             * @param companyId the company ID
7114             * @param name the name
7115             * @param scope the scope
7116             * @param primKey the prim key
7117             * @param roleId the role ID
7118             * @param actionIds the action IDs
7119             * @throws SystemException if a system exception occurred
7120             */
7121            public void removeByC_N_S_P_R_A(long companyId, String name, int scope,
7122                    String primKey, long roleId, long actionIds) throws SystemException {
7123                    for (ResourcePermission resourcePermission : findByC_N_S_P_R_A(
7124                                    companyId, name, scope, primKey, roleId, actionIds,
7125                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7126                            remove(resourcePermission);
7127                    }
7128            }
7129    
7130            /**
7131             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
7132             *
7133             * @param companyId the company ID
7134             * @param name the name
7135             * @param scope the scope
7136             * @param primKey the prim key
7137             * @param roleId the role ID
7138             * @param actionIds the action IDs
7139             * @return the number of matching resource permissions
7140             * @throws SystemException if a system exception occurred
7141             */
7142            public int countByC_N_S_P_R_A(long companyId, String name, int scope,
7143                    String primKey, long roleId, long actionIds) throws SystemException {
7144                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S_P_R_A;
7145    
7146                    Object[] finderArgs = new Object[] {
7147                                    companyId, name, scope, primKey, roleId, actionIds
7148                            };
7149    
7150                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7151                                    this);
7152    
7153                    if (count == null) {
7154                            StringBundler query = new StringBundler(7);
7155    
7156                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
7157    
7158                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2);
7159    
7160                            if (name == null) {
7161                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1);
7162                            }
7163                            else {
7164                                    if (name.equals(StringPool.BLANK)) {
7165                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3);
7166                                    }
7167                                    else {
7168                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2);
7169                                    }
7170                            }
7171    
7172                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2);
7173    
7174                            if (primKey == null) {
7175                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1);
7176                            }
7177                            else {
7178                                    if (primKey.equals(StringPool.BLANK)) {
7179                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3);
7180                                    }
7181                                    else {
7182                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2);
7183                                    }
7184                            }
7185    
7186                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2);
7187    
7188                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2);
7189    
7190                            String sql = query.toString();
7191    
7192                            Session session = null;
7193    
7194                            try {
7195                                    session = openSession();
7196    
7197                                    Query q = session.createQuery(sql);
7198    
7199                                    QueryPos qPos = QueryPos.getInstance(q);
7200    
7201                                    qPos.add(companyId);
7202    
7203                                    if (name != null) {
7204                                            qPos.add(name);
7205                                    }
7206    
7207                                    qPos.add(scope);
7208    
7209                                    if (primKey != null) {
7210                                            qPos.add(primKey);
7211                                    }
7212    
7213                                    qPos.add(roleId);
7214    
7215                                    qPos.add(actionIds);
7216    
7217                                    count = (Long)q.uniqueResult();
7218    
7219                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7220                            }
7221                            catch (Exception e) {
7222                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7223    
7224                                    throw processException(e);
7225                            }
7226                            finally {
7227                                    closeSession(session);
7228                            }
7229                    }
7230    
7231                    return count.intValue();
7232            }
7233    
7234            /**
7235             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
7236             *
7237             * @param companyId the company ID
7238             * @param name the name
7239             * @param scope the scope
7240             * @param primKey the prim key
7241             * @param roleIds the role IDs
7242             * @param actionIds the action IDs
7243             * @return the number of matching resource permissions
7244             * @throws SystemException if a system exception occurred
7245             */
7246            public int countByC_N_S_P_R_A(long companyId, String name, int scope,
7247                    String primKey, long[] roleIds, long actionIds)
7248                    throws SystemException {
7249                    Object[] finderArgs = new Object[] {
7250                                    companyId, name, scope, primKey, StringUtil.merge(roleIds),
7251                                    actionIds
7252                            };
7253    
7254                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R_A,
7255                                    finderArgs, this);
7256    
7257                    if (count == null) {
7258                            StringBundler query = new StringBundler();
7259    
7260                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
7261    
7262                            boolean conjunctionable = false;
7263    
7264                            if (conjunctionable) {
7265                                    query.append(WHERE_AND);
7266                            }
7267    
7268                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_5);
7269    
7270                            conjunctionable = true;
7271    
7272                            if (conjunctionable) {
7273                                    query.append(WHERE_AND);
7274                            }
7275    
7276                            if (name == null) {
7277                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_4);
7278                            }
7279                            else {
7280                                    if (name.equals(StringPool.BLANK)) {
7281                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_6);
7282                                    }
7283                                    else {
7284                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_5);
7285                                    }
7286                            }
7287    
7288                            conjunctionable = true;
7289    
7290                            if (conjunctionable) {
7291                                    query.append(WHERE_AND);
7292                            }
7293    
7294                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_5);
7295    
7296                            conjunctionable = true;
7297    
7298                            if (conjunctionable) {
7299                                    query.append(WHERE_AND);
7300                            }
7301    
7302                            if (primKey == null) {
7303                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_4);
7304                            }
7305                            else {
7306                                    if (primKey.equals(StringPool.BLANK)) {
7307                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_6);
7308                                    }
7309                                    else {
7310                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_5);
7311                                    }
7312                            }
7313    
7314                            conjunctionable = true;
7315    
7316                            if ((roleIds == null) || (roleIds.length > 0)) {
7317                                    if (conjunctionable) {
7318                                            query.append(WHERE_AND);
7319                                    }
7320    
7321                                    query.append(StringPool.OPEN_PARENTHESIS);
7322    
7323                                    for (int i = 0; i < roleIds.length; i++) {
7324                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_5);
7325    
7326                                            if ((i + 1) < roleIds.length) {
7327                                                    query.append(WHERE_OR);
7328                                            }
7329                                    }
7330    
7331                                    query.append(StringPool.CLOSE_PARENTHESIS);
7332    
7333                                    conjunctionable = true;
7334                            }
7335    
7336                            if (conjunctionable) {
7337                                    query.append(WHERE_AND);
7338                            }
7339    
7340                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_5);
7341    
7342                            conjunctionable = true;
7343    
7344                            String sql = query.toString();
7345    
7346                            Session session = null;
7347    
7348                            try {
7349                                    session = openSession();
7350    
7351                                    Query q = session.createQuery(sql);
7352    
7353                                    QueryPos qPos = QueryPos.getInstance(q);
7354    
7355                                    qPos.add(companyId);
7356    
7357                                    if (name != null) {
7358                                            qPos.add(name);
7359                                    }
7360    
7361                                    qPos.add(scope);
7362    
7363                                    if (primKey != null) {
7364                                            qPos.add(primKey);
7365                                    }
7366    
7367                                    if (roleIds != null) {
7368                                            qPos.add(roleIds);
7369                                    }
7370    
7371                                    qPos.add(actionIds);
7372    
7373                                    count = (Long)q.uniqueResult();
7374    
7375                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R_A,
7376                                            finderArgs, count);
7377                            }
7378                            catch (Exception e) {
7379                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R_A,
7380                                            finderArgs);
7381    
7382                                    throw processException(e);
7383                            }
7384                            finally {
7385                                    closeSession(session);
7386                            }
7387                    }
7388    
7389                    return count.intValue();
7390            }
7391    
7392            private static final String _FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
7393            private static final String _FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_5 = "(" +
7394                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2) + ")";
7395            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_1 = "resourcePermission.name IS NULL AND ";
7396            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_2 = "resourcePermission.name = ? AND ";
7397            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
7398            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_4 = "(" +
7399                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1) + ")";
7400            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_5 = "(" +
7401                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2) + ")";
7402            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_6 = "(" +
7403                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3) + ")";
7404            private static final String _FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2 = "resourcePermission.scope = ? AND ";
7405            private static final String _FINDER_COLUMN_C_N_S_P_R_A_SCOPE_5 = "(" +
7406                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2) + ")";
7407            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
7408            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
7409            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
7410            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_4 = "(" +
7411                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1) + ")";
7412            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_5 = "(" +
7413                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2) + ")";
7414            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_6 = "(" +
7415                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3) + ")";
7416            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2 = "resourcePermission.roleId = ? AND ";
7417            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ROLEID_5 = "(" +
7418                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2) + ")";
7419            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2 = "resourcePermission.actionIds = ?";
7420            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_5 = "(" +
7421                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2) + ")";
7422            public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
7423                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
7424                            ResourcePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
7425                            "fetchByC_N_S_P_R_O_A",
7426                            new String[] {
7427                                    Long.class.getName(), String.class.getName(),
7428                                    Integer.class.getName(), String.class.getName(),
7429                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
7430                            },
7431                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
7432                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
7433                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
7434                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
7435                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK |
7436                            ResourcePermissionModelImpl.OWNERID_COLUMN_BITMASK |
7437                            ResourcePermissionModelImpl.ACTIONIDS_COLUMN_BITMASK);
7438            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
7439                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
7440                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R_O_A",
7441                            new String[] {
7442                                    Long.class.getName(), String.class.getName(),
7443                                    Integer.class.getName(), String.class.getName(),
7444                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
7445                            });
7446    
7447            /**
7448             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; or throws a {@link com.liferay.portal.NoSuchResourcePermissionException} if it could not be found.
7449             *
7450             * @param companyId the company ID
7451             * @param name the name
7452             * @param scope the scope
7453             * @param primKey the prim key
7454             * @param roleId the role ID
7455             * @param ownerId the owner ID
7456             * @param actionIds the action IDs
7457             * @return the matching resource permission
7458             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
7459             * @throws SystemException if a system exception occurred
7460             */
7461            public ResourcePermission findByC_N_S_P_R_O_A(long companyId, String name,
7462                    int scope, String primKey, long roleId, long ownerId, long actionIds)
7463                    throws NoSuchResourcePermissionException, SystemException {
7464                    ResourcePermission resourcePermission = fetchByC_N_S_P_R_O_A(companyId,
7465                                    name, scope, primKey, roleId, ownerId, actionIds);
7466    
7467                    if (resourcePermission == null) {
7468                            StringBundler msg = new StringBundler(16);
7469    
7470                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7471    
7472                            msg.append("companyId=");
7473                            msg.append(companyId);
7474    
7475                            msg.append(", name=");
7476                            msg.append(name);
7477    
7478                            msg.append(", scope=");
7479                            msg.append(scope);
7480    
7481                            msg.append(", primKey=");
7482                            msg.append(primKey);
7483    
7484                            msg.append(", roleId=");
7485                            msg.append(roleId);
7486    
7487                            msg.append(", ownerId=");
7488                            msg.append(ownerId);
7489    
7490                            msg.append(", actionIds=");
7491                            msg.append(actionIds);
7492    
7493                            msg.append(StringPool.CLOSE_CURLY_BRACE);
7494    
7495                            if (_log.isWarnEnabled()) {
7496                                    _log.warn(msg.toString());
7497                            }
7498    
7499                            throw new NoSuchResourcePermissionException(msg.toString());
7500                    }
7501    
7502                    return resourcePermission;
7503            }
7504    
7505            /**
7506             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
7507             *
7508             * @param companyId the company ID
7509             * @param name the name
7510             * @param scope the scope
7511             * @param primKey the prim key
7512             * @param roleId the role ID
7513             * @param ownerId the owner ID
7514             * @param actionIds the action IDs
7515             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
7516             * @throws SystemException if a system exception occurred
7517             */
7518            public ResourcePermission fetchByC_N_S_P_R_O_A(long companyId, String name,
7519                    int scope, String primKey, long roleId, long ownerId, long actionIds)
7520                    throws SystemException {
7521                    return fetchByC_N_S_P_R_O_A(companyId, name, scope, primKey, roleId,
7522                            ownerId, actionIds, true);
7523            }
7524    
7525            /**
7526             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
7527             *
7528             * @param companyId the company ID
7529             * @param name the name
7530             * @param scope the scope
7531             * @param primKey the prim key
7532             * @param roleId the role ID
7533             * @param ownerId the owner ID
7534             * @param actionIds the action IDs
7535             * @param retrieveFromCache whether to use the finder cache
7536             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
7537             * @throws SystemException if a system exception occurred
7538             */
7539            public ResourcePermission fetchByC_N_S_P_R_O_A(long companyId, String name,
7540                    int scope, String primKey, long roleId, long ownerId, long actionIds,
7541                    boolean retrieveFromCache) throws SystemException {
7542                    Object[] finderArgs = new Object[] {
7543                                    companyId, name, scope, primKey, roleId, ownerId, actionIds
7544                            };
7545    
7546                    Object result = null;
7547    
7548                    if (retrieveFromCache) {
7549                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
7550                                            finderArgs, this);
7551                    }
7552    
7553                    if (result instanceof ResourcePermission) {
7554                            ResourcePermission resourcePermission = (ResourcePermission)result;
7555    
7556                            if ((companyId != resourcePermission.getCompanyId()) ||
7557                                            !Validator.equals(name, resourcePermission.getName()) ||
7558                                            (scope != resourcePermission.getScope()) ||
7559                                            !Validator.equals(primKey, resourcePermission.getPrimKey()) ||
7560                                            (roleId != resourcePermission.getRoleId()) ||
7561                                            (ownerId != resourcePermission.getOwnerId()) ||
7562                                            (actionIds != resourcePermission.getActionIds())) {
7563                                    result = null;
7564                            }
7565                    }
7566    
7567                    if (result == null) {
7568                            StringBundler query = new StringBundler(9);
7569    
7570                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
7571    
7572                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_COMPANYID_2);
7573    
7574                            if (name == null) {
7575                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_1);
7576                            }
7577                            else {
7578                                    if (name.equals(StringPool.BLANK)) {
7579                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_3);
7580                                    }
7581                                    else {
7582                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_2);
7583                                    }
7584                            }
7585    
7586                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_SCOPE_2);
7587    
7588                            if (primKey == null) {
7589                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_1);
7590                            }
7591                            else {
7592                                    if (primKey.equals(StringPool.BLANK)) {
7593                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_3);
7594                                    }
7595                                    else {
7596                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_2);
7597                                    }
7598                            }
7599    
7600                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ROLEID_2);
7601    
7602                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_OWNERID_2);
7603    
7604                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ACTIONIDS_2);
7605    
7606                            String sql = query.toString();
7607    
7608                            Session session = null;
7609    
7610                            try {
7611                                    session = openSession();
7612    
7613                                    Query q = session.createQuery(sql);
7614    
7615                                    QueryPos qPos = QueryPos.getInstance(q);
7616    
7617                                    qPos.add(companyId);
7618    
7619                                    if (name != null) {
7620                                            qPos.add(name);
7621                                    }
7622    
7623                                    qPos.add(scope);
7624    
7625                                    if (primKey != null) {
7626                                            qPos.add(primKey);
7627                                    }
7628    
7629                                    qPos.add(roleId);
7630    
7631                                    qPos.add(ownerId);
7632    
7633                                    qPos.add(actionIds);
7634    
7635                                    List<ResourcePermission> list = q.list();
7636    
7637                                    if (list.isEmpty()) {
7638                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
7639                                                    finderArgs, list);
7640                                    }
7641                                    else {
7642                                            if ((list.size() > 1) && _log.isWarnEnabled()) {
7643                                                    _log.warn(
7644                                                            "ResourcePermissionPersistenceImpl.fetchByC_N_S_P_R_O_A(long, String, int, String, long, long, long, boolean) with parameters (" +
7645                                                            StringUtil.merge(finderArgs) +
7646                                                            ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
7647                                            }
7648    
7649                                            ResourcePermission resourcePermission = list.get(0);
7650    
7651                                            result = resourcePermission;
7652    
7653                                            cacheResult(resourcePermission);
7654    
7655                                            if ((resourcePermission.getCompanyId() != companyId) ||
7656                                                            (resourcePermission.getName() == null) ||
7657                                                            !resourcePermission.getName().equals(name) ||
7658                                                            (resourcePermission.getScope() != scope) ||
7659                                                            (resourcePermission.getPrimKey() == null) ||
7660                                                            !resourcePermission.getPrimKey().equals(primKey) ||
7661                                                            (resourcePermission.getRoleId() != roleId) ||
7662                                                            (resourcePermission.getOwnerId() != ownerId) ||
7663                                                            (resourcePermission.getActionIds() != actionIds)) {
7664                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
7665                                                            finderArgs, resourcePermission);
7666                                            }
7667                                    }
7668                            }
7669                            catch (Exception e) {
7670                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
7671                                            finderArgs);
7672    
7673                                    throw processException(e);
7674                            }
7675                            finally {
7676                                    closeSession(session);
7677                            }
7678                    }
7679    
7680                    if (result instanceof List<?>) {
7681                            return null;
7682                    }
7683                    else {
7684                            return (ResourcePermission)result;
7685                    }
7686            }
7687    
7688            /**
7689             * Removes the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; from the database.
7690             *
7691             * @param companyId the company ID
7692             * @param name the name
7693             * @param scope the scope
7694             * @param primKey the prim key
7695             * @param roleId the role ID
7696             * @param ownerId the owner ID
7697             * @param actionIds the action IDs
7698             * @return the resource permission that was removed
7699             * @throws SystemException if a system exception occurred
7700             */
7701            public ResourcePermission removeByC_N_S_P_R_O_A(long companyId,
7702                    String name, int scope, String primKey, long roleId, long ownerId,
7703                    long actionIds)
7704                    throws NoSuchResourcePermissionException, SystemException {
7705                    ResourcePermission resourcePermission = findByC_N_S_P_R_O_A(companyId,
7706                                    name, scope, primKey, roleId, ownerId, actionIds);
7707    
7708                    return remove(resourcePermission);
7709            }
7710    
7711            /**
7712             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63;.
7713             *
7714             * @param companyId the company ID
7715             * @param name the name
7716             * @param scope the scope
7717             * @param primKey the prim key
7718             * @param roleId the role ID
7719             * @param ownerId the owner ID
7720             * @param actionIds the action IDs
7721             * @return the number of matching resource permissions
7722             * @throws SystemException if a system exception occurred
7723             */
7724            public int countByC_N_S_P_R_O_A(long companyId, String name, int scope,
7725                    String primKey, long roleId, long ownerId, long actionIds)
7726                    throws SystemException {
7727                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A;
7728    
7729                    Object[] finderArgs = new Object[] {
7730                                    companyId, name, scope, primKey, roleId, ownerId, actionIds
7731                            };
7732    
7733                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7734                                    this);
7735    
7736                    if (count == null) {
7737                            StringBundler query = new StringBundler(8);
7738    
7739                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
7740    
7741                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_COMPANYID_2);
7742    
7743                            if (name == null) {
7744                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_1);
7745                            }
7746                            else {
7747                                    if (name.equals(StringPool.BLANK)) {
7748                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_3);
7749                                    }
7750                                    else {
7751                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_2);
7752                                    }
7753                            }
7754    
7755                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_SCOPE_2);
7756    
7757                            if (primKey == null) {
7758                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_1);
7759                            }
7760                            else {
7761                                    if (primKey.equals(StringPool.BLANK)) {
7762                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_3);
7763                                    }
7764                                    else {
7765                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_2);
7766                                    }
7767                            }
7768    
7769                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ROLEID_2);
7770    
7771                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_OWNERID_2);
7772    
7773                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ACTIONIDS_2);
7774    
7775                            String sql = query.toString();
7776    
7777                            Session session = null;
7778    
7779                            try {
7780                                    session = openSession();
7781    
7782                                    Query q = session.createQuery(sql);
7783    
7784                                    QueryPos qPos = QueryPos.getInstance(q);
7785    
7786                                    qPos.add(companyId);
7787    
7788                                    if (name != null) {
7789                                            qPos.add(name);
7790                                    }
7791    
7792                                    qPos.add(scope);
7793    
7794                                    if (primKey != null) {
7795                                            qPos.add(primKey);
7796                                    }
7797    
7798                                    qPos.add(roleId);
7799    
7800                                    qPos.add(ownerId);
7801    
7802                                    qPos.add(actionIds);
7803    
7804                                    count = (Long)q.uniqueResult();
7805    
7806                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7807                            }
7808                            catch (Exception e) {
7809                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7810    
7811                                    throw processException(e);
7812                            }
7813                            finally {
7814                                    closeSession(session);
7815                            }
7816                    }
7817    
7818                    return count.intValue();
7819            }
7820    
7821            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
7822            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_NAME_1 = "resourcePermission.name IS NULL AND ";
7823            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_NAME_2 = "resourcePermission.name = ? AND ";
7824            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
7825            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_SCOPE_2 = "resourcePermission.scope = ? AND ";
7826            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
7827            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
7828            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
7829            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_ROLEID_2 = "resourcePermission.roleId = ? AND ";
7830            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_OWNERID_2 = "resourcePermission.ownerId = ? AND ";
7831            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_ACTIONIDS_2 = "resourcePermission.actionIds = ?";
7832    
7833            /**
7834             * Caches the resource permission in the entity cache if it is enabled.
7835             *
7836             * @param resourcePermission the resource permission
7837             */
7838            public void cacheResult(ResourcePermission resourcePermission) {
7839                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
7840                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
7841                            resourcePermission);
7842    
7843                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
7844                            new Object[] {
7845                                    Long.valueOf(resourcePermission.getCompanyId()),
7846                                    
7847                            resourcePermission.getName(),
7848                                    Integer.valueOf(resourcePermission.getScope()),
7849                                    
7850                            resourcePermission.getPrimKey(),
7851                                    Long.valueOf(resourcePermission.getRoleId()),
7852                                    Long.valueOf(resourcePermission.getOwnerId()),
7853                                    Long.valueOf(resourcePermission.getActionIds())
7854                            }, resourcePermission);
7855    
7856                    resourcePermission.resetOriginalValues();
7857            }
7858    
7859            /**
7860             * Caches the resource permissions in the entity cache if it is enabled.
7861             *
7862             * @param resourcePermissions the resource permissions
7863             */
7864            public void cacheResult(List<ResourcePermission> resourcePermissions) {
7865                    for (ResourcePermission resourcePermission : resourcePermissions) {
7866                            if (EntityCacheUtil.getResult(
7867                                                    ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
7868                                                    ResourcePermissionImpl.class,
7869                                                    resourcePermission.getPrimaryKey()) == null) {
7870                                    cacheResult(resourcePermission);
7871                            }
7872                            else {
7873                                    resourcePermission.resetOriginalValues();
7874                            }
7875                    }
7876            }
7877    
7878            /**
7879             * Clears the cache for all resource permissions.
7880             *
7881             * <p>
7882             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7883             * </p>
7884             */
7885            @Override
7886            public void clearCache() {
7887                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7888                            CacheRegistryUtil.clear(ResourcePermissionImpl.class.getName());
7889                    }
7890    
7891                    EntityCacheUtil.clearCache(ResourcePermissionImpl.class.getName());
7892    
7893                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7894                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7895                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7896            }
7897    
7898            /**
7899             * Clears the cache for the resource permission.
7900             *
7901             * <p>
7902             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7903             * </p>
7904             */
7905            @Override
7906            public void clearCache(ResourcePermission resourcePermission) {
7907                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
7908                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
7909    
7910                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7911                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7912    
7913                    clearUniqueFindersCache(resourcePermission);
7914            }
7915    
7916            @Override
7917            public void clearCache(List<ResourcePermission> resourcePermissions) {
7918                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7919                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7920    
7921                    for (ResourcePermission resourcePermission : resourcePermissions) {
7922                            EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
7923                                    ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
7924    
7925                            clearUniqueFindersCache(resourcePermission);
7926                    }
7927            }
7928    
7929            protected void cacheUniqueFindersCache(
7930                    ResourcePermission resourcePermission) {
7931                    if (resourcePermission.isNew()) {
7932                            Object[] args = new Object[] {
7933                                            Long.valueOf(resourcePermission.getCompanyId()),
7934                                            
7935                                            resourcePermission.getName(),
7936                                            Integer.valueOf(resourcePermission.getScope()),
7937                                            
7938                                            resourcePermission.getPrimKey(),
7939                                            Long.valueOf(resourcePermission.getRoleId()),
7940                                            Long.valueOf(resourcePermission.getOwnerId()),
7941                                            Long.valueOf(resourcePermission.getActionIds())
7942                                    };
7943    
7944                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A, args,
7945                                    Long.valueOf(1));
7946                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A, args,
7947                                    resourcePermission);
7948                    }
7949                    else {
7950                            ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
7951    
7952                            if ((resourcePermissionModelImpl.getColumnBitmask() &
7953                                            FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A.getColumnBitmask()) != 0) {
7954                                    Object[] args = new Object[] {
7955                                                    Long.valueOf(resourcePermission.getCompanyId()),
7956                                                    
7957                                                    resourcePermission.getName(),
7958                                                    Integer.valueOf(resourcePermission.getScope()),
7959                                                    
7960                                                    resourcePermission.getPrimKey(),
7961                                                    Long.valueOf(resourcePermission.getRoleId()),
7962                                                    Long.valueOf(resourcePermission.getOwnerId()),
7963                                                    Long.valueOf(resourcePermission.getActionIds())
7964                                            };
7965    
7966                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A,
7967                                            args, Long.valueOf(1));
7968                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
7969                                            args, resourcePermission);
7970                            }
7971                    }
7972            }
7973    
7974            protected void clearUniqueFindersCache(
7975                    ResourcePermission resourcePermission) {
7976                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
7977    
7978                    Object[] args = new Object[] {
7979                                    Long.valueOf(resourcePermission.getCompanyId()),
7980                                    
7981                                    resourcePermission.getName(),
7982                                    Integer.valueOf(resourcePermission.getScope()),
7983                                    
7984                                    resourcePermission.getPrimKey(),
7985                                    Long.valueOf(resourcePermission.getRoleId()),
7986                                    Long.valueOf(resourcePermission.getOwnerId()),
7987                                    Long.valueOf(resourcePermission.getActionIds())
7988                            };
7989    
7990                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A, args);
7991                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A, args);
7992    
7993                    if ((resourcePermissionModelImpl.getColumnBitmask() &
7994                                    FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A.getColumnBitmask()) != 0) {
7995                            args = new Object[] {
7996                                            Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
7997                                            
7998                                            resourcePermissionModelImpl.getOriginalName(),
7999                                            Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
8000                                            
8001                                            resourcePermissionModelImpl.getOriginalPrimKey(),
8002                                            Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId()),
8003                                            Long.valueOf(resourcePermissionModelImpl.getOriginalOwnerId()),
8004                                            Long.valueOf(resourcePermissionModelImpl.getOriginalActionIds())
8005                                    };
8006    
8007                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A,
8008                                    args);
8009                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
8010                                    args);
8011                    }
8012            }
8013    
8014            /**
8015             * Creates a new resource permission with the primary key. Does not add the resource permission to the database.
8016             *
8017             * @param resourcePermissionId the primary key for the new resource permission
8018             * @return the new resource permission
8019             */
8020            public ResourcePermission create(long resourcePermissionId) {
8021                    ResourcePermission resourcePermission = new ResourcePermissionImpl();
8022    
8023                    resourcePermission.setNew(true);
8024                    resourcePermission.setPrimaryKey(resourcePermissionId);
8025    
8026                    return resourcePermission;
8027            }
8028    
8029            /**
8030             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
8031             *
8032             * @param resourcePermissionId the primary key of the resource permission
8033             * @return the resource permission that was removed
8034             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
8035             * @throws SystemException if a system exception occurred
8036             */
8037            public ResourcePermission remove(long resourcePermissionId)
8038                    throws NoSuchResourcePermissionException, SystemException {
8039                    return remove(Long.valueOf(resourcePermissionId));
8040            }
8041    
8042            /**
8043             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
8044             *
8045             * @param primaryKey the primary key of the resource permission
8046             * @return the resource permission that was removed
8047             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
8048             * @throws SystemException if a system exception occurred
8049             */
8050            @Override
8051            public ResourcePermission remove(Serializable primaryKey)
8052                    throws NoSuchResourcePermissionException, SystemException {
8053                    Session session = null;
8054    
8055                    try {
8056                            session = openSession();
8057    
8058                            ResourcePermission resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
8059                                            primaryKey);
8060    
8061                            if (resourcePermission == null) {
8062                                    if (_log.isWarnEnabled()) {
8063                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8064                                    }
8065    
8066                                    throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8067                                            primaryKey);
8068                            }
8069    
8070                            return remove(resourcePermission);
8071                    }
8072                    catch (NoSuchResourcePermissionException nsee) {
8073                            throw nsee;
8074                    }
8075                    catch (Exception e) {
8076                            throw processException(e);
8077                    }
8078                    finally {
8079                            closeSession(session);
8080                    }
8081            }
8082    
8083            @Override
8084            protected ResourcePermission removeImpl(
8085                    ResourcePermission resourcePermission) throws SystemException {
8086                    resourcePermission = toUnwrappedModel(resourcePermission);
8087    
8088                    Session session = null;
8089    
8090                    try {
8091                            session = openSession();
8092    
8093                            if (!session.contains(resourcePermission)) {
8094                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
8095                                                    resourcePermission.getPrimaryKeyObj());
8096                            }
8097    
8098                            if (resourcePermission != null) {
8099                                    session.delete(resourcePermission);
8100                            }
8101                    }
8102                    catch (Exception e) {
8103                            throw processException(e);
8104                    }
8105                    finally {
8106                            closeSession(session);
8107                    }
8108    
8109                    if (resourcePermission != null) {
8110                            clearCache(resourcePermission);
8111                    }
8112    
8113                    return resourcePermission;
8114            }
8115    
8116            @Override
8117            public ResourcePermission updateImpl(
8118                    com.liferay.portal.model.ResourcePermission resourcePermission)
8119                    throws SystemException {
8120                    resourcePermission = toUnwrappedModel(resourcePermission);
8121    
8122                    boolean isNew = resourcePermission.isNew();
8123    
8124                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
8125    
8126                    Session session = null;
8127    
8128                    try {
8129                            session = openSession();
8130    
8131                            if (resourcePermission.isNew()) {
8132                                    session.save(resourcePermission);
8133    
8134                                    resourcePermission.setNew(false);
8135                            }
8136                            else {
8137                                    session.merge(resourcePermission);
8138                            }
8139                    }
8140                    catch (Exception e) {
8141                            throw processException(e);
8142                    }
8143                    finally {
8144                            closeSession(session);
8145                    }
8146    
8147                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8148    
8149                    if (isNew || !ResourcePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
8150                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8151                    }
8152    
8153                    else {
8154                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8155                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE.getColumnBitmask()) != 0) {
8156                                    Object[] args = new Object[] {
8157                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope())
8158                                            };
8159    
8160                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SCOPE, args);
8161                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE,
8162                                            args);
8163    
8164                                    args = new Object[] {
8165                                                    Integer.valueOf(resourcePermissionModelImpl.getScope())
8166                                            };
8167    
8168                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SCOPE, args);
8169                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE,
8170                                            args);
8171                            }
8172    
8173                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8174                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
8175                                    Object[] args = new Object[] {
8176                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId())
8177                                            };
8178    
8179                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
8180                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
8181                                            args);
8182    
8183                                    args = new Object[] {
8184                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId())
8185                                            };
8186    
8187                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
8188                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
8189                                            args);
8190                            }
8191    
8192                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8193                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S.getColumnBitmask()) != 0) {
8194                                    Object[] args = new Object[] {
8195                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8196                                                    
8197                                                    resourcePermissionModelImpl.getOriginalName(),
8198                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope())
8199                                            };
8200    
8201                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
8202                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S,
8203                                            args);
8204    
8205                                    args = new Object[] {
8206                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8207                                                    
8208                                                    resourcePermissionModelImpl.getName(),
8209                                                    Integer.valueOf(resourcePermissionModelImpl.getScope())
8210                                            };
8211    
8212                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
8213                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S,
8214                                            args);
8215                            }
8216    
8217                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8218                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_R.getColumnBitmask()) != 0) {
8219                                    Object[] args = new Object[] {
8220                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8221                                                    
8222                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
8223                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId())
8224                                            };
8225    
8226                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P_R, args);
8227                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_R,
8228                                            args);
8229    
8230                                    args = new Object[] {
8231                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8232                                                    
8233                                                    resourcePermissionModelImpl.getPrimKey(),
8234                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId())
8235                                            };
8236    
8237                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P_R, args);
8238                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P_R,
8239                                            args);
8240                            }
8241    
8242                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8243                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P.getColumnBitmask()) != 0) {
8244                                    Object[] args = new Object[] {
8245                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8246                                                    
8247                                                    resourcePermissionModelImpl.getOriginalName(),
8248                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
8249                                                    
8250                                                    resourcePermissionModelImpl.getOriginalPrimKey()
8251                                            };
8252    
8253                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P, args);
8254                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P,
8255                                            args);
8256    
8257                                    args = new Object[] {
8258                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8259                                                    
8260                                                    resourcePermissionModelImpl.getName(),
8261                                                    Integer.valueOf(resourcePermissionModelImpl.getScope()),
8262                                                    
8263                                                    resourcePermissionModelImpl.getPrimKey()
8264                                            };
8265    
8266                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P, args);
8267                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P,
8268                                            args);
8269                            }
8270    
8271                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8272                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O.getColumnBitmask()) != 0) {
8273                                    Object[] args = new Object[] {
8274                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8275                                                    
8276                                                    resourcePermissionModelImpl.getOriginalName(),
8277                                                    
8278                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
8279                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalOwnerId())
8280                                            };
8281    
8282                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_O, args);
8283                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O,
8284                                            args);
8285    
8286                                    args = new Object[] {
8287                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8288                                                    
8289                                                    resourcePermissionModelImpl.getName(),
8290                                                    
8291                                                    resourcePermissionModelImpl.getPrimKey(),
8292                                                    Long.valueOf(resourcePermissionModelImpl.getOwnerId())
8293                                            };
8294    
8295                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_O, args);
8296                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O,
8297                                            args);
8298                            }
8299    
8300                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8301                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R.getColumnBitmask()) != 0) {
8302                                    Object[] args = new Object[] {
8303                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8304                                                    
8305                                                    resourcePermissionModelImpl.getOriginalName(),
8306                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
8307                                                    
8308                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
8309                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId())
8310                                            };
8311    
8312                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
8313                                            args);
8314                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R,
8315                                            args);
8316    
8317                                    args = new Object[] {
8318                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8319                                                    
8320                                                    resourcePermissionModelImpl.getName(),
8321                                                    Integer.valueOf(resourcePermissionModelImpl.getScope()),
8322                                                    
8323                                                    resourcePermissionModelImpl.getPrimKey(),
8324                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId())
8325                                            };
8326    
8327                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
8328                                            args);
8329                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R,
8330                                            args);
8331                            }
8332    
8333                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8334                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A.getColumnBitmask()) != 0) {
8335                                    Object[] args = new Object[] {
8336                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8337                                                    
8338                                                    resourcePermissionModelImpl.getOriginalName(),
8339                                                    
8340                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
8341                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId()),
8342                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalActionIds())
8343                                            };
8344    
8345                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_R_A,
8346                                            args);
8347                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A,
8348                                            args);
8349    
8350                                    args = new Object[] {
8351                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8352                                                    
8353                                                    resourcePermissionModelImpl.getName(),
8354                                                    
8355                                                    resourcePermissionModelImpl.getPrimKey(),
8356                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId()),
8357                                                    Long.valueOf(resourcePermissionModelImpl.getActionIds())
8358                                            };
8359    
8360                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_R_A,
8361                                            args);
8362                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A,
8363                                            args);
8364                            }
8365    
8366                            if ((resourcePermissionModelImpl.getColumnBitmask() &
8367                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A.getColumnBitmask()) != 0) {
8368                                    Object[] args = new Object[] {
8369                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
8370                                                    
8371                                                    resourcePermissionModelImpl.getOriginalName(),
8372                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
8373                                                    
8374                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
8375                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId()),
8376                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalActionIds())
8377                                            };
8378    
8379                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
8380                                            args);
8381                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A,
8382                                            args);
8383    
8384                                    args = new Object[] {
8385                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
8386                                                    
8387                                                    resourcePermissionModelImpl.getName(),
8388                                                    Integer.valueOf(resourcePermissionModelImpl.getScope()),
8389                                                    
8390                                                    resourcePermissionModelImpl.getPrimKey(),
8391                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId()),
8392                                                    Long.valueOf(resourcePermissionModelImpl.getActionIds())
8393                                            };
8394    
8395                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
8396                                            args);
8397                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A,
8398                                            args);
8399                            }
8400                    }
8401    
8402                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
8403                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
8404                            resourcePermission);
8405    
8406                    clearUniqueFindersCache(resourcePermission);
8407                    cacheUniqueFindersCache(resourcePermission);
8408    
8409                    return resourcePermission;
8410            }
8411    
8412            protected ResourcePermission toUnwrappedModel(
8413                    ResourcePermission resourcePermission) {
8414                    if (resourcePermission instanceof ResourcePermissionImpl) {
8415                            return resourcePermission;
8416                    }
8417    
8418                    ResourcePermissionImpl resourcePermissionImpl = new ResourcePermissionImpl();
8419    
8420                    resourcePermissionImpl.setNew(resourcePermission.isNew());
8421                    resourcePermissionImpl.setPrimaryKey(resourcePermission.getPrimaryKey());
8422    
8423                    resourcePermissionImpl.setResourcePermissionId(resourcePermission.getResourcePermissionId());
8424                    resourcePermissionImpl.setCompanyId(resourcePermission.getCompanyId());
8425                    resourcePermissionImpl.setName(resourcePermission.getName());
8426                    resourcePermissionImpl.setScope(resourcePermission.getScope());
8427                    resourcePermissionImpl.setPrimKey(resourcePermission.getPrimKey());
8428                    resourcePermissionImpl.setRoleId(resourcePermission.getRoleId());
8429                    resourcePermissionImpl.setOwnerId(resourcePermission.getOwnerId());
8430                    resourcePermissionImpl.setActionIds(resourcePermission.getActionIds());
8431    
8432                    return resourcePermissionImpl;
8433            }
8434    
8435            /**
8436             * Returns the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8437             *
8438             * @param primaryKey the primary key of the resource permission
8439             * @return the resource permission
8440             * @throws com.liferay.portal.NoSuchModelException if a resource permission with the primary key could not be found
8441             * @throws SystemException if a system exception occurred
8442             */
8443            @Override
8444            public ResourcePermission findByPrimaryKey(Serializable primaryKey)
8445                    throws NoSuchModelException, SystemException {
8446                    return findByPrimaryKey(((Long)primaryKey).longValue());
8447            }
8448    
8449            /**
8450             * Returns the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchResourcePermissionException} if it could not be found.
8451             *
8452             * @param resourcePermissionId the primary key of the resource permission
8453             * @return the resource permission
8454             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
8455             * @throws SystemException if a system exception occurred
8456             */
8457            public ResourcePermission findByPrimaryKey(long resourcePermissionId)
8458                    throws NoSuchResourcePermissionException, SystemException {
8459                    ResourcePermission resourcePermission = fetchByPrimaryKey(resourcePermissionId);
8460    
8461                    if (resourcePermission == null) {
8462                            if (_log.isWarnEnabled()) {
8463                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8464                                            resourcePermissionId);
8465                            }
8466    
8467                            throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8468                                    resourcePermissionId);
8469                    }
8470    
8471                    return resourcePermission;
8472            }
8473    
8474            /**
8475             * Returns the resource permission with the primary key or returns <code>null</code> if it could not be found.
8476             *
8477             * @param primaryKey the primary key of the resource permission
8478             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
8479             * @throws SystemException if a system exception occurred
8480             */
8481            @Override
8482            public ResourcePermission fetchByPrimaryKey(Serializable primaryKey)
8483                    throws SystemException {
8484                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
8485            }
8486    
8487            /**
8488             * Returns the resource permission with the primary key or returns <code>null</code> if it could not be found.
8489             *
8490             * @param resourcePermissionId the primary key of the resource permission
8491             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
8492             * @throws SystemException if a system exception occurred
8493             */
8494            public ResourcePermission fetchByPrimaryKey(long resourcePermissionId)
8495                    throws SystemException {
8496                    ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
8497                                    ResourcePermissionImpl.class, resourcePermissionId);
8498    
8499                    if (resourcePermission == _nullResourcePermission) {
8500                            return null;
8501                    }
8502    
8503                    if (resourcePermission == null) {
8504                            Session session = null;
8505    
8506                            try {
8507                                    session = openSession();
8508    
8509                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
8510                                                    Long.valueOf(resourcePermissionId));
8511    
8512                                    if (resourcePermission != null) {
8513                                            cacheResult(resourcePermission);
8514                                    }
8515                                    else {
8516                                            EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
8517                                                    ResourcePermissionImpl.class, resourcePermissionId,
8518                                                    _nullResourcePermission);
8519                                    }
8520                            }
8521                            catch (Exception e) {
8522                                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
8523                                            ResourcePermissionImpl.class, resourcePermissionId);
8524    
8525                                    throw processException(e);
8526                            }
8527                            finally {
8528                                    closeSession(session);
8529                            }
8530                    }
8531    
8532                    return resourcePermission;
8533            }
8534    
8535            /**
8536             * Returns all the resource permissions.
8537             *
8538             * @return the resource permissions
8539             * @throws SystemException if a system exception occurred
8540             */
8541            public List<ResourcePermission> findAll() throws SystemException {
8542                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8543            }
8544    
8545            /**
8546             * Returns a range of all the resource permissions.
8547             *
8548             * <p>
8549             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8550             * </p>
8551             *
8552             * @param start the lower bound of the range of resource permissions
8553             * @param end the upper bound of the range of resource permissions (not inclusive)
8554             * @return the range of resource permissions
8555             * @throws SystemException if a system exception occurred
8556             */
8557            public List<ResourcePermission> findAll(int start, int end)
8558                    throws SystemException {
8559                    return findAll(start, end, null);
8560            }
8561    
8562            /**
8563             * Returns an ordered range of all the resource permissions.
8564             *
8565             * <p>
8566             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.ResourcePermissionModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8567             * </p>
8568             *
8569             * @param start the lower bound of the range of resource permissions
8570             * @param end the upper bound of the range of resource permissions (not inclusive)
8571             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8572             * @return the ordered range of resource permissions
8573             * @throws SystemException if a system exception occurred
8574             */
8575            public List<ResourcePermission> findAll(int start, int end,
8576                    OrderByComparator orderByComparator) throws SystemException {
8577                    boolean pagination = true;
8578                    FinderPath finderPath = null;
8579                    Object[] finderArgs = null;
8580    
8581                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8582                                    (orderByComparator == null)) {
8583                            pagination = false;
8584                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
8585                            finderArgs = FINDER_ARGS_EMPTY;
8586                    }
8587                    else {
8588                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
8589                            finderArgs = new Object[] { start, end, orderByComparator };
8590                    }
8591    
8592                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
8593                                    finderArgs, this);
8594    
8595                    if (list == null) {
8596                            StringBundler query = null;
8597                            String sql = null;
8598    
8599                            if (orderByComparator != null) {
8600                                    query = new StringBundler(2 +
8601                                                    (orderByComparator.getOrderByFields().length * 3));
8602    
8603                                    query.append(_SQL_SELECT_RESOURCEPERMISSION);
8604    
8605                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8606                                            orderByComparator);
8607    
8608                                    sql = query.toString();
8609                            }
8610                            else {
8611                                    sql = _SQL_SELECT_RESOURCEPERMISSION;
8612    
8613                                    if (pagination) {
8614                                            sql = sql.concat(ResourcePermissionModelImpl.ORDER_BY_JPQL);
8615                                    }
8616                            }
8617    
8618                            Session session = null;
8619    
8620                            try {
8621                                    session = openSession();
8622    
8623                                    Query q = session.createQuery(sql);
8624    
8625                                    if (!pagination) {
8626                                            list = (List<ResourcePermission>)QueryUtil.list(q,
8627                                                            getDialect(), start, end, false);
8628    
8629                                            Collections.sort(list);
8630    
8631                                            list = new UnmodifiableList<ResourcePermission>(list);
8632                                    }
8633                                    else {
8634                                            list = (List<ResourcePermission>)QueryUtil.list(q,
8635                                                            getDialect(), start, end);
8636                                    }
8637    
8638                                    cacheResult(list);
8639    
8640                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8641                            }
8642                            catch (Exception e) {
8643                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8644    
8645                                    throw processException(e);
8646                            }
8647                            finally {
8648                                    closeSession(session);
8649                            }
8650                    }
8651    
8652                    return list;
8653            }
8654    
8655            /**
8656             * Removes all the resource permissions from the database.
8657             *
8658             * @throws SystemException if a system exception occurred
8659             */
8660            public void removeAll() throws SystemException {
8661                    for (ResourcePermission resourcePermission : findAll()) {
8662                            remove(resourcePermission);
8663                    }
8664            }
8665    
8666            /**
8667             * Returns the number of resource permissions.
8668             *
8669             * @return the number of resource permissions
8670             * @throws SystemException if a system exception occurred
8671             */
8672            public int countAll() throws SystemException {
8673                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
8674                                    FINDER_ARGS_EMPTY, this);
8675    
8676                    if (count == null) {
8677                            Session session = null;
8678    
8679                            try {
8680                                    session = openSession();
8681    
8682                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEPERMISSION);
8683    
8684                                    count = (Long)q.uniqueResult();
8685    
8686                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
8687                                            FINDER_ARGS_EMPTY, count);
8688                            }
8689                            catch (Exception e) {
8690                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
8691                                            FINDER_ARGS_EMPTY);
8692    
8693                                    throw processException(e);
8694                            }
8695                            finally {
8696                                    closeSession(session);
8697                            }
8698                    }
8699    
8700                    return count.intValue();
8701            }
8702    
8703            /**
8704             * Initializes the resource permission persistence.
8705             */
8706            public void afterPropertiesSet() {
8707                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
8708                                            com.liferay.portal.util.PropsUtil.get(
8709                                                    "value.object.listener.com.liferay.portal.model.ResourcePermission")));
8710    
8711                    if (listenerClassNames.length > 0) {
8712                            try {
8713                                    List<ModelListener<ResourcePermission>> listenersList = new ArrayList<ModelListener<ResourcePermission>>();
8714    
8715                                    for (String listenerClassName : listenerClassNames) {
8716                                            listenersList.add((ModelListener<ResourcePermission>)InstanceFactory.newInstance(
8717                                                            listenerClassName));
8718                                    }
8719    
8720                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8721                            }
8722                            catch (Exception e) {
8723                                    _log.error(e);
8724                            }
8725                    }
8726            }
8727    
8728            public void destroy() {
8729                    EntityCacheUtil.removeCache(ResourcePermissionImpl.class.getName());
8730                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8731                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8732                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8733            }
8734    
8735            private static final String _SQL_SELECT_RESOURCEPERMISSION = "SELECT resourcePermission FROM ResourcePermission resourcePermission";
8736            private static final String _SQL_SELECT_RESOURCEPERMISSION_WHERE = "SELECT resourcePermission FROM ResourcePermission resourcePermission WHERE ";
8737            private static final String _SQL_COUNT_RESOURCEPERMISSION = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission";
8738            private static final String _SQL_COUNT_RESOURCEPERMISSION_WHERE = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission WHERE ";
8739    
8740            private static String _removeConjunction(String sql) {
8741                    int pos = sql.indexOf(" AND ");
8742    
8743                    if (pos != -1) {
8744                            sql = sql.substring(0, pos);
8745                    }
8746    
8747                    return sql;
8748            }
8749    
8750            private static final String _ORDER_BY_ENTITY_ALIAS = "resourcePermission.";
8751            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourcePermission exists with the primary key ";
8752            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourcePermission exists with the key {";
8753            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
8754            private static Log _log = LogFactoryUtil.getLog(ResourcePermissionPersistenceImpl.class);
8755            private static ResourcePermission _nullResourcePermission = new ResourcePermissionImpl() {
8756                            @Override
8757                            public Object clone() {
8758                                    return this;
8759                            }
8760    
8761                            @Override
8762                            public CacheModel<ResourcePermission> toCacheModel() {
8763                                    return _nullResourcePermissionCacheModel;
8764                            }
8765                    };
8766    
8767            private static CacheModel<ResourcePermission> _nullResourcePermissionCacheModel =
8768                    new CacheModel<ResourcePermission>() {
8769                            public ResourcePermission toEntityModel() {
8770                                    return _nullResourcePermission;
8771                            }
8772                    };
8773    }