001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchResourcePermissionException;
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.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.CharPool;
031    import com.liferay.portal.kernel.util.OrderByComparator;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.Validator;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.MVCCModel;
038    import com.liferay.portal.model.ResourcePermission;
039    import com.liferay.portal.model.impl.ResourcePermissionImpl;
040    import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
041    import com.liferay.portal.service.persistence.ResourcePermissionPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.util.ArrayList;
046    import java.util.Collections;
047    import java.util.HashMap;
048    import java.util.HashSet;
049    import java.util.Iterator;
050    import java.util.List;
051    import java.util.Map;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the resource permission service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see ResourcePermissionPersistence
063     * @see com.liferay.portal.service.persistence.ResourcePermissionUtil
064     * @generated
065     */
066    @ProviderType
067    public class ResourcePermissionPersistenceImpl extends BasePersistenceImpl<ResourcePermission>
068            implements ResourcePermissionPersistence {
069            /*
070             * NOTE FOR DEVELOPERS:
071             *
072             * 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.
073             */
074            public static final String FINDER_CLASS_NAME_ENTITY = ResourcePermissionImpl.class.getName();
075            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List1";
077            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List2";
079            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
080                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
081                            ResourcePermissionImpl.class,
082                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
084                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
085                            ResourcePermissionImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
088                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
091                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
092                            ResourcePermissionImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByScope",
094                            new String[] {
095                                    Integer.class.getName(),
096                                    
097                            Integer.class.getName(), Integer.class.getName(),
098                                    OrderByComparator.class.getName()
099                            });
100            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
101                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
102                            ResourcePermissionImpl.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByScope",
104                            new String[] { Integer.class.getName() },
105                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
107                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByScope",
109                            new String[] { Integer.class.getName() });
110            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
111                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByScope",
113                            new String[] { Integer.class.getName() });
114    
115            /**
116             * Returns all the resource permissions where scope = &#63;.
117             *
118             * @param scope the scope
119             * @return the matching resource permissions
120             */
121            @Override
122            public List<ResourcePermission> findByScope(int scope) {
123                    return findByScope(scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124            }
125    
126            /**
127             * Returns a range of all the resource permissions where scope = &#63;.
128             *
129             * <p>
130             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
131             * </p>
132             *
133             * @param scope the scope
134             * @param start the lower bound of the range of resource permissions
135             * @param end the upper bound of the range of resource permissions (not inclusive)
136             * @return the range of matching resource permissions
137             */
138            @Override
139            public List<ResourcePermission> findByScope(int scope, int start, int end) {
140                    return findByScope(scope, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the resource permissions where scope = &#63;.
145             *
146             * <p>
147             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
148             * </p>
149             *
150             * @param scope the scope
151             * @param start the lower bound of the range of resource permissions
152             * @param end the upper bound of the range of resource permissions (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching resource permissions
155             */
156            @Override
157            public List<ResourcePermission> findByScope(int scope, int start, int end,
158                    OrderByComparator<ResourcePermission> orderByComparator) {
159                    boolean pagination = true;
160                    FinderPath finderPath = null;
161                    Object[] finderArgs = null;
162    
163                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164                                    (orderByComparator == null)) {
165                            pagination = false;
166                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE;
167                            finderArgs = new Object[] { scope };
168                    }
169                    else {
170                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE;
171                            finderArgs = new Object[] { scope, start, end, orderByComparator };
172                    }
173    
174                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
175                                    finderArgs, this);
176    
177                    if ((list != null) && !list.isEmpty()) {
178                            for (ResourcePermission resourcePermission : list) {
179                                    if ((scope != resourcePermission.getScope())) {
180                                            list = null;
181    
182                                            break;
183                                    }
184                            }
185                    }
186    
187                    if (list == null) {
188                            StringBundler query = null;
189    
190                            if (orderByComparator != null) {
191                                    query = new StringBundler(3 +
192                                                    (orderByComparator.getOrderByFields().length * 3));
193                            }
194                            else {
195                                    query = new StringBundler(3);
196                            }
197    
198                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
199    
200                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
201    
202                            if (orderByComparator != null) {
203                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
204                                            orderByComparator);
205                            }
206                            else
207                             if (pagination) {
208                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
209                            }
210    
211                            String sql = query.toString();
212    
213                            Session session = null;
214    
215                            try {
216                                    session = openSession();
217    
218                                    Query q = session.createQuery(sql);
219    
220                                    QueryPos qPos = QueryPos.getInstance(q);
221    
222                                    qPos.add(scope);
223    
224                                    if (!pagination) {
225                                            list = (List<ResourcePermission>)QueryUtil.list(q,
226                                                            getDialect(), start, end, false);
227    
228                                            Collections.sort(list);
229    
230                                            list = Collections.unmodifiableList(list);
231                                    }
232                                    else {
233                                            list = (List<ResourcePermission>)QueryUtil.list(q,
234                                                            getDialect(), start, end);
235                                    }
236    
237                                    cacheResult(list);
238    
239                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
240                            }
241                            catch (Exception e) {
242                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
243    
244                                    throw processException(e);
245                            }
246                            finally {
247                                    closeSession(session);
248                            }
249                    }
250    
251                    return list;
252            }
253    
254            /**
255             * Returns the first resource permission in the ordered set where scope = &#63;.
256             *
257             * @param scope the scope
258             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
259             * @return the first matching resource permission
260             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
261             */
262            @Override
263            public ResourcePermission findByScope_First(int scope,
264                    OrderByComparator<ResourcePermission> orderByComparator)
265                    throws NoSuchResourcePermissionException {
266                    ResourcePermission resourcePermission = fetchByScope_First(scope,
267                                    orderByComparator);
268    
269                    if (resourcePermission != null) {
270                            return resourcePermission;
271                    }
272    
273                    StringBundler msg = new StringBundler(4);
274    
275                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
276    
277                    msg.append("scope=");
278                    msg.append(scope);
279    
280                    msg.append(StringPool.CLOSE_CURLY_BRACE);
281    
282                    throw new NoSuchResourcePermissionException(msg.toString());
283            }
284    
285            /**
286             * Returns the first resource permission in the ordered set where scope = &#63;.
287             *
288             * @param scope the scope
289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
290             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
291             */
292            @Override
293            public ResourcePermission fetchByScope_First(int scope,
294                    OrderByComparator<ResourcePermission> orderByComparator) {
295                    List<ResourcePermission> list = findByScope(scope, 0, 1,
296                                    orderByComparator);
297    
298                    if (!list.isEmpty()) {
299                            return list.get(0);
300                    }
301    
302                    return null;
303            }
304    
305            /**
306             * Returns the last resource permission in the ordered set where scope = &#63;.
307             *
308             * @param scope the scope
309             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
310             * @return the last matching resource permission
311             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
312             */
313            @Override
314            public ResourcePermission findByScope_Last(int scope,
315                    OrderByComparator<ResourcePermission> orderByComparator)
316                    throws NoSuchResourcePermissionException {
317                    ResourcePermission resourcePermission = fetchByScope_Last(scope,
318                                    orderByComparator);
319    
320                    if (resourcePermission != null) {
321                            return resourcePermission;
322                    }
323    
324                    StringBundler msg = new StringBundler(4);
325    
326                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327    
328                    msg.append("scope=");
329                    msg.append(scope);
330    
331                    msg.append(StringPool.CLOSE_CURLY_BRACE);
332    
333                    throw new NoSuchResourcePermissionException(msg.toString());
334            }
335    
336            /**
337             * Returns the last resource permission in the ordered set where scope = &#63;.
338             *
339             * @param scope the scope
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
342             */
343            @Override
344            public ResourcePermission fetchByScope_Last(int scope,
345                    OrderByComparator<ResourcePermission> orderByComparator) {
346                    int count = countByScope(scope);
347    
348                    if (count == 0) {
349                            return null;
350                    }
351    
352                    List<ResourcePermission> list = findByScope(scope, count - 1, count,
353                                    orderByComparator);
354    
355                    if (!list.isEmpty()) {
356                            return list.get(0);
357                    }
358    
359                    return null;
360            }
361    
362            /**
363             * Returns the resource permissions before and after the current resource permission in the ordered set where scope = &#63;.
364             *
365             * @param resourcePermissionId the primary key of the current resource permission
366             * @param scope the scope
367             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
368             * @return the previous, current, and next resource permission
369             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
370             */
371            @Override
372            public ResourcePermission[] findByScope_PrevAndNext(
373                    long resourcePermissionId, int scope,
374                    OrderByComparator<ResourcePermission> orderByComparator)
375                    throws NoSuchResourcePermissionException {
376                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
377    
378                    Session session = null;
379    
380                    try {
381                            session = openSession();
382    
383                            ResourcePermission[] array = new ResourcePermissionImpl[3];
384    
385                            array[0] = getByScope_PrevAndNext(session, resourcePermission,
386                                            scope, orderByComparator, true);
387    
388                            array[1] = resourcePermission;
389    
390                            array[2] = getByScope_PrevAndNext(session, resourcePermission,
391                                            scope, orderByComparator, false);
392    
393                            return array;
394                    }
395                    catch (Exception e) {
396                            throw processException(e);
397                    }
398                    finally {
399                            closeSession(session);
400                    }
401            }
402    
403            protected ResourcePermission getByScope_PrevAndNext(Session session,
404                    ResourcePermission resourcePermission, int scope,
405                    OrderByComparator<ResourcePermission> orderByComparator,
406                    boolean previous) {
407                    StringBundler query = null;
408    
409                    if (orderByComparator != null) {
410                            query = new StringBundler(6 +
411                                            (orderByComparator.getOrderByFields().length * 6));
412                    }
413                    else {
414                            query = new StringBundler(3);
415                    }
416    
417                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
418    
419                    query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
420    
421                    if (orderByComparator != null) {
422                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
423    
424                            if (orderByConditionFields.length > 0) {
425                                    query.append(WHERE_AND);
426                            }
427    
428                            for (int i = 0; i < orderByConditionFields.length; i++) {
429                                    query.append(_ORDER_BY_ENTITY_ALIAS);
430                                    query.append(orderByConditionFields[i]);
431    
432                                    if ((i + 1) < orderByConditionFields.length) {
433                                            if (orderByComparator.isAscending() ^ previous) {
434                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
435                                            }
436                                            else {
437                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
438                                            }
439                                    }
440                                    else {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(WHERE_GREATER_THAN);
443                                            }
444                                            else {
445                                                    query.append(WHERE_LESSER_THAN);
446                                            }
447                                    }
448                            }
449    
450                            query.append(ORDER_BY_CLAUSE);
451    
452                            String[] orderByFields = orderByComparator.getOrderByFields();
453    
454                            for (int i = 0; i < orderByFields.length; i++) {
455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
456                                    query.append(orderByFields[i]);
457    
458                                    if ((i + 1) < orderByFields.length) {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
461                                            }
462                                            else {
463                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
464                                            }
465                                    }
466                                    else {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(ORDER_BY_ASC);
469                                            }
470                                            else {
471                                                    query.append(ORDER_BY_DESC);
472                                            }
473                                    }
474                            }
475                    }
476                    else {
477                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
478                    }
479    
480                    String sql = query.toString();
481    
482                    Query q = session.createQuery(sql);
483    
484                    q.setFirstResult(0);
485                    q.setMaxResults(2);
486    
487                    QueryPos qPos = QueryPos.getInstance(q);
488    
489                    qPos.add(scope);
490    
491                    if (orderByComparator != null) {
492                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
493    
494                            for (Object value : values) {
495                                    qPos.add(value);
496                            }
497                    }
498    
499                    List<ResourcePermission> list = q.list();
500    
501                    if (list.size() == 2) {
502                            return list.get(1);
503                    }
504                    else {
505                            return null;
506                    }
507            }
508    
509            /**
510             * Returns all the resource permissions where scope = any &#63;.
511             *
512             * <p>
513             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
514             * </p>
515             *
516             * @param scopes the scopes
517             * @return the matching resource permissions
518             */
519            @Override
520            public List<ResourcePermission> findByScope(int[] scopes) {
521                    return findByScope(scopes, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
522            }
523    
524            /**
525             * Returns a range of all the resource permissions where scope = any &#63;.
526             *
527             * <p>
528             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
529             * </p>
530             *
531             * @param scopes the scopes
532             * @param start the lower bound of the range of resource permissions
533             * @param end the upper bound of the range of resource permissions (not inclusive)
534             * @return the range of matching resource permissions
535             */
536            @Override
537            public List<ResourcePermission> findByScope(int[] scopes, int start, int end) {
538                    return findByScope(scopes, start, end, null);
539            }
540    
541            /**
542             * Returns an ordered range of all the resource permissions where scope = any &#63;.
543             *
544             * <p>
545             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
546             * </p>
547             *
548             * @param scopes the scopes
549             * @param start the lower bound of the range of resource permissions
550             * @param end the upper bound of the range of resource permissions (not inclusive)
551             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
552             * @return the ordered range of matching resource permissions
553             */
554            @Override
555            public List<ResourcePermission> findByScope(int[] scopes, int start,
556                    int end, OrderByComparator<ResourcePermission> orderByComparator) {
557                    if (scopes == null) {
558                            scopes = new int[0];
559                    }
560                    else {
561                            scopes = ArrayUtil.unique(scopes);
562                    }
563    
564                    if (scopes.length == 1) {
565                            return findByScope(scopes[0], start, end, orderByComparator);
566                    }
567    
568                    boolean pagination = true;
569                    Object[] finderArgs = null;
570    
571                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
572                                    (orderByComparator == null)) {
573                            pagination = false;
574                            finderArgs = new Object[] { StringUtil.merge(scopes) };
575                    }
576                    else {
577                            finderArgs = new Object[] {
578                                            StringUtil.merge(scopes),
579                                            
580                                            start, end, orderByComparator
581                                    };
582                    }
583    
584                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE,
585                                    finderArgs, this);
586    
587                    if ((list != null) && !list.isEmpty()) {
588                            for (ResourcePermission resourcePermission : list) {
589                                    if (!ArrayUtil.contains(scopes, resourcePermission.getScope())) {
590                                            list = null;
591    
592                                            break;
593                                    }
594                            }
595                    }
596    
597                    if (list == null) {
598                            StringBundler query = new StringBundler();
599    
600                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
601    
602                            if (scopes.length > 0) {
603                                    query.append(StringPool.OPEN_PARENTHESIS);
604    
605                                    query.append(_FINDER_COLUMN_SCOPE_SCOPE_7);
606    
607                                    query.append(StringUtil.merge(scopes));
608    
609                                    query.append(StringPool.CLOSE_PARENTHESIS);
610    
611                                    query.append(StringPool.CLOSE_PARENTHESIS);
612                            }
613    
614                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
615                                                    1)), query.index() - 1);
616    
617                            if (orderByComparator != null) {
618                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
619                                            orderByComparator);
620                            }
621                            else
622                             if (pagination) {
623                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
624                            }
625    
626                            String sql = query.toString();
627    
628                            Session session = null;
629    
630                            try {
631                                    session = openSession();
632    
633                                    Query q = session.createQuery(sql);
634    
635                                    if (!pagination) {
636                                            list = (List<ResourcePermission>)QueryUtil.list(q,
637                                                            getDialect(), start, end, false);
638    
639                                            Collections.sort(list);
640    
641                                            list = Collections.unmodifiableList(list);
642                                    }
643                                    else {
644                                            list = (List<ResourcePermission>)QueryUtil.list(q,
645                                                            getDialect(), start, end);
646                                    }
647    
648                                    cacheResult(list);
649    
650                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE,
651                                            finderArgs, list);
652                            }
653                            catch (Exception e) {
654                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE,
655                                            finderArgs);
656    
657                                    throw processException(e);
658                            }
659                            finally {
660                                    closeSession(session);
661                            }
662                    }
663    
664                    return list;
665            }
666    
667            /**
668             * Removes all the resource permissions where scope = &#63; from the database.
669             *
670             * @param scope the scope
671             */
672            @Override
673            public void removeByScope(int scope) {
674                    for (ResourcePermission resourcePermission : findByScope(scope,
675                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
676                            remove(resourcePermission);
677                    }
678            }
679    
680            /**
681             * Returns the number of resource permissions where scope = &#63;.
682             *
683             * @param scope the scope
684             * @return the number of matching resource permissions
685             */
686            @Override
687            public int countByScope(int scope) {
688                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SCOPE;
689    
690                    Object[] finderArgs = new Object[] { scope };
691    
692                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
693                                    this);
694    
695                    if (count == null) {
696                            StringBundler query = new StringBundler(2);
697    
698                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
699    
700                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
701    
702                            String sql = query.toString();
703    
704                            Session session = null;
705    
706                            try {
707                                    session = openSession();
708    
709                                    Query q = session.createQuery(sql);
710    
711                                    QueryPos qPos = QueryPos.getInstance(q);
712    
713                                    qPos.add(scope);
714    
715                                    count = (Long)q.uniqueResult();
716    
717                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
718                            }
719                            catch (Exception e) {
720                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
721    
722                                    throw processException(e);
723                            }
724                            finally {
725                                    closeSession(session);
726                            }
727                    }
728    
729                    return count.intValue();
730            }
731    
732            /**
733             * Returns the number of resource permissions where scope = any &#63;.
734             *
735             * @param scopes the scopes
736             * @return the number of matching resource permissions
737             */
738            @Override
739            public int countByScope(int[] scopes) {
740                    if (scopes == null) {
741                            scopes = new int[0];
742                    }
743                    else {
744                            scopes = ArrayUtil.unique(scopes);
745                    }
746    
747                    Object[] finderArgs = new Object[] { StringUtil.merge(scopes) };
748    
749                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE,
750                                    finderArgs, this);
751    
752                    if (count == null) {
753                            StringBundler query = new StringBundler();
754    
755                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
756    
757                            if (scopes.length > 0) {
758                                    query.append(StringPool.OPEN_PARENTHESIS);
759    
760                                    query.append(_FINDER_COLUMN_SCOPE_SCOPE_7);
761    
762                                    query.append(StringUtil.merge(scopes));
763    
764                                    query.append(StringPool.CLOSE_PARENTHESIS);
765    
766                                    query.append(StringPool.CLOSE_PARENTHESIS);
767                            }
768    
769                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
770                                                    1)), query.index() - 1);
771    
772                            String sql = query.toString();
773    
774                            Session session = null;
775    
776                            try {
777                                    session = openSession();
778    
779                                    Query q = session.createQuery(sql);
780    
781                                    count = (Long)q.uniqueResult();
782    
783                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE,
784                                            finderArgs, count);
785                            }
786                            catch (Exception e) {
787                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_SCOPE,
788                                            finderArgs);
789    
790                                    throw processException(e);
791                            }
792                            finally {
793                                    closeSession(session);
794                            }
795                    }
796    
797                    return count.intValue();
798            }
799    
800            private static final String _FINDER_COLUMN_SCOPE_SCOPE_2 = "resourcePermission.scope = ?";
801            private static final String _FINDER_COLUMN_SCOPE_SCOPE_7 = "resourcePermission.scope IN (";
802            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
803                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
804                            ResourcePermissionImpl.class,
805                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
806                            new String[] {
807                                    Long.class.getName(),
808                                    
809                            Integer.class.getName(), Integer.class.getName(),
810                                    OrderByComparator.class.getName()
811                            });
812            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
813                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
814                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
815                            ResourcePermissionImpl.class,
816                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
817                            new String[] { Long.class.getName() },
818                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
819            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
820                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
821                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
822                            new String[] { Long.class.getName() });
823    
824            /**
825             * Returns all the resource permissions where roleId = &#63;.
826             *
827             * @param roleId the role ID
828             * @return the matching resource permissions
829             */
830            @Override
831            public List<ResourcePermission> findByRoleId(long roleId) {
832                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
833            }
834    
835            /**
836             * Returns a range of all the resource permissions where roleId = &#63;.
837             *
838             * <p>
839             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
840             * </p>
841             *
842             * @param roleId the role ID
843             * @param start the lower bound of the range of resource permissions
844             * @param end the upper bound of the range of resource permissions (not inclusive)
845             * @return the range of matching resource permissions
846             */
847            @Override
848            public List<ResourcePermission> findByRoleId(long roleId, int start, int end) {
849                    return findByRoleId(roleId, start, end, null);
850            }
851    
852            /**
853             * Returns an ordered range of all the resource permissions where roleId = &#63;.
854             *
855             * <p>
856             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
857             * </p>
858             *
859             * @param roleId the role ID
860             * @param start the lower bound of the range of resource permissions
861             * @param end the upper bound of the range of resource permissions (not inclusive)
862             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
863             * @return the ordered range of matching resource permissions
864             */
865            @Override
866            public List<ResourcePermission> findByRoleId(long roleId, int start,
867                    int end, OrderByComparator<ResourcePermission> orderByComparator) {
868                    boolean pagination = true;
869                    FinderPath finderPath = null;
870                    Object[] finderArgs = null;
871    
872                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
873                                    (orderByComparator == null)) {
874                            pagination = false;
875                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
876                            finderArgs = new Object[] { roleId };
877                    }
878                    else {
879                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
880                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
881                    }
882    
883                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
884                                    finderArgs, this);
885    
886                    if ((list != null) && !list.isEmpty()) {
887                            for (ResourcePermission resourcePermission : list) {
888                                    if ((roleId != resourcePermission.getRoleId())) {
889                                            list = null;
890    
891                                            break;
892                                    }
893                            }
894                    }
895    
896                    if (list == null) {
897                            StringBundler query = null;
898    
899                            if (orderByComparator != null) {
900                                    query = new StringBundler(3 +
901                                                    (orderByComparator.getOrderByFields().length * 3));
902                            }
903                            else {
904                                    query = new StringBundler(3);
905                            }
906    
907                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
908    
909                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
910    
911                            if (orderByComparator != null) {
912                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
913                                            orderByComparator);
914                            }
915                            else
916                             if (pagination) {
917                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
918                            }
919    
920                            String sql = query.toString();
921    
922                            Session session = null;
923    
924                            try {
925                                    session = openSession();
926    
927                                    Query q = session.createQuery(sql);
928    
929                                    QueryPos qPos = QueryPos.getInstance(q);
930    
931                                    qPos.add(roleId);
932    
933                                    if (!pagination) {
934                                            list = (List<ResourcePermission>)QueryUtil.list(q,
935                                                            getDialect(), start, end, false);
936    
937                                            Collections.sort(list);
938    
939                                            list = Collections.unmodifiableList(list);
940                                    }
941                                    else {
942                                            list = (List<ResourcePermission>)QueryUtil.list(q,
943                                                            getDialect(), start, end);
944                                    }
945    
946                                    cacheResult(list);
947    
948                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
949                            }
950                            catch (Exception e) {
951                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
952    
953                                    throw processException(e);
954                            }
955                            finally {
956                                    closeSession(session);
957                            }
958                    }
959    
960                    return list;
961            }
962    
963            /**
964             * Returns the first resource permission in the ordered set where roleId = &#63;.
965             *
966             * @param roleId the role ID
967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
968             * @return the first matching resource permission
969             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
970             */
971            @Override
972            public ResourcePermission findByRoleId_First(long roleId,
973                    OrderByComparator<ResourcePermission> orderByComparator)
974                    throws NoSuchResourcePermissionException {
975                    ResourcePermission resourcePermission = fetchByRoleId_First(roleId,
976                                    orderByComparator);
977    
978                    if (resourcePermission != null) {
979                            return resourcePermission;
980                    }
981    
982                    StringBundler msg = new StringBundler(4);
983    
984                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
985    
986                    msg.append("roleId=");
987                    msg.append(roleId);
988    
989                    msg.append(StringPool.CLOSE_CURLY_BRACE);
990    
991                    throw new NoSuchResourcePermissionException(msg.toString());
992            }
993    
994            /**
995             * Returns the first resource permission in the ordered set where roleId = &#63;.
996             *
997             * @param roleId the role ID
998             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
999             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
1000             */
1001            @Override
1002            public ResourcePermission fetchByRoleId_First(long roleId,
1003                    OrderByComparator<ResourcePermission> orderByComparator) {
1004                    List<ResourcePermission> list = findByRoleId(roleId, 0, 1,
1005                                    orderByComparator);
1006    
1007                    if (!list.isEmpty()) {
1008                            return list.get(0);
1009                    }
1010    
1011                    return null;
1012            }
1013    
1014            /**
1015             * Returns the last resource permission in the ordered set where roleId = &#63;.
1016             *
1017             * @param roleId the role ID
1018             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1019             * @return the last matching resource permission
1020             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
1021             */
1022            @Override
1023            public ResourcePermission findByRoleId_Last(long roleId,
1024                    OrderByComparator<ResourcePermission> orderByComparator)
1025                    throws NoSuchResourcePermissionException {
1026                    ResourcePermission resourcePermission = fetchByRoleId_Last(roleId,
1027                                    orderByComparator);
1028    
1029                    if (resourcePermission != null) {
1030                            return resourcePermission;
1031                    }
1032    
1033                    StringBundler msg = new StringBundler(4);
1034    
1035                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1036    
1037                    msg.append("roleId=");
1038                    msg.append(roleId);
1039    
1040                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1041    
1042                    throw new NoSuchResourcePermissionException(msg.toString());
1043            }
1044    
1045            /**
1046             * Returns the last resource permission in the ordered set where roleId = &#63;.
1047             *
1048             * @param roleId the role ID
1049             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1050             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
1051             */
1052            @Override
1053            public ResourcePermission fetchByRoleId_Last(long roleId,
1054                    OrderByComparator<ResourcePermission> orderByComparator) {
1055                    int count = countByRoleId(roleId);
1056    
1057                    if (count == 0) {
1058                            return null;
1059                    }
1060    
1061                    List<ResourcePermission> list = findByRoleId(roleId, count - 1, count,
1062                                    orderByComparator);
1063    
1064                    if (!list.isEmpty()) {
1065                            return list.get(0);
1066                    }
1067    
1068                    return null;
1069            }
1070    
1071            /**
1072             * Returns the resource permissions before and after the current resource permission in the ordered set where roleId = &#63;.
1073             *
1074             * @param resourcePermissionId the primary key of the current resource permission
1075             * @param roleId the role ID
1076             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1077             * @return the previous, current, and next resource permission
1078             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1079             */
1080            @Override
1081            public ResourcePermission[] findByRoleId_PrevAndNext(
1082                    long resourcePermissionId, long roleId,
1083                    OrderByComparator<ResourcePermission> orderByComparator)
1084                    throws NoSuchResourcePermissionException {
1085                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1086    
1087                    Session session = null;
1088    
1089                    try {
1090                            session = openSession();
1091    
1092                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1093    
1094                            array[0] = getByRoleId_PrevAndNext(session, resourcePermission,
1095                                            roleId, orderByComparator, true);
1096    
1097                            array[1] = resourcePermission;
1098    
1099                            array[2] = getByRoleId_PrevAndNext(session, resourcePermission,
1100                                            roleId, orderByComparator, false);
1101    
1102                            return array;
1103                    }
1104                    catch (Exception e) {
1105                            throw processException(e);
1106                    }
1107                    finally {
1108                            closeSession(session);
1109                    }
1110            }
1111    
1112            protected ResourcePermission getByRoleId_PrevAndNext(Session session,
1113                    ResourcePermission resourcePermission, long roleId,
1114                    OrderByComparator<ResourcePermission> orderByComparator,
1115                    boolean previous) {
1116                    StringBundler query = null;
1117    
1118                    if (orderByComparator != null) {
1119                            query = new StringBundler(6 +
1120                                            (orderByComparator.getOrderByFields().length * 6));
1121                    }
1122                    else {
1123                            query = new StringBundler(3);
1124                    }
1125    
1126                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1127    
1128                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1129    
1130                    if (orderByComparator != null) {
1131                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1132    
1133                            if (orderByConditionFields.length > 0) {
1134                                    query.append(WHERE_AND);
1135                            }
1136    
1137                            for (int i = 0; i < orderByConditionFields.length; i++) {
1138                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1139                                    query.append(orderByConditionFields[i]);
1140    
1141                                    if ((i + 1) < orderByConditionFields.length) {
1142                                            if (orderByComparator.isAscending() ^ previous) {
1143                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1144                                            }
1145                                            else {
1146                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1147                                            }
1148                                    }
1149                                    else {
1150                                            if (orderByComparator.isAscending() ^ previous) {
1151                                                    query.append(WHERE_GREATER_THAN);
1152                                            }
1153                                            else {
1154                                                    query.append(WHERE_LESSER_THAN);
1155                                            }
1156                                    }
1157                            }
1158    
1159                            query.append(ORDER_BY_CLAUSE);
1160    
1161                            String[] orderByFields = orderByComparator.getOrderByFields();
1162    
1163                            for (int i = 0; i < orderByFields.length; i++) {
1164                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1165                                    query.append(orderByFields[i]);
1166    
1167                                    if ((i + 1) < orderByFields.length) {
1168                                            if (orderByComparator.isAscending() ^ previous) {
1169                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1170                                            }
1171                                            else {
1172                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1173                                            }
1174                                    }
1175                                    else {
1176                                            if (orderByComparator.isAscending() ^ previous) {
1177                                                    query.append(ORDER_BY_ASC);
1178                                            }
1179                                            else {
1180                                                    query.append(ORDER_BY_DESC);
1181                                            }
1182                                    }
1183                            }
1184                    }
1185                    else {
1186                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1187                    }
1188    
1189                    String sql = query.toString();
1190    
1191                    Query q = session.createQuery(sql);
1192    
1193                    q.setFirstResult(0);
1194                    q.setMaxResults(2);
1195    
1196                    QueryPos qPos = QueryPos.getInstance(q);
1197    
1198                    qPos.add(roleId);
1199    
1200                    if (orderByComparator != null) {
1201                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
1202    
1203                            for (Object value : values) {
1204                                    qPos.add(value);
1205                            }
1206                    }
1207    
1208                    List<ResourcePermission> list = q.list();
1209    
1210                    if (list.size() == 2) {
1211                            return list.get(1);
1212                    }
1213                    else {
1214                            return null;
1215                    }
1216            }
1217    
1218            /**
1219             * Removes all the resource permissions where roleId = &#63; from the database.
1220             *
1221             * @param roleId the role ID
1222             */
1223            @Override
1224            public void removeByRoleId(long roleId) {
1225                    for (ResourcePermission resourcePermission : findByRoleId(roleId,
1226                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1227                            remove(resourcePermission);
1228                    }
1229            }
1230    
1231            /**
1232             * Returns the number of resource permissions where roleId = &#63;.
1233             *
1234             * @param roleId the role ID
1235             * @return the number of matching resource permissions
1236             */
1237            @Override
1238            public int countByRoleId(long roleId) {
1239                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1240    
1241                    Object[] finderArgs = new Object[] { roleId };
1242    
1243                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1244                                    this);
1245    
1246                    if (count == null) {
1247                            StringBundler query = new StringBundler(2);
1248    
1249                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
1250    
1251                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1252    
1253                            String sql = query.toString();
1254    
1255                            Session session = null;
1256    
1257                            try {
1258                                    session = openSession();
1259    
1260                                    Query q = session.createQuery(sql);
1261    
1262                                    QueryPos qPos = QueryPos.getInstance(q);
1263    
1264                                    qPos.add(roleId);
1265    
1266                                    count = (Long)q.uniqueResult();
1267    
1268                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1269                            }
1270                            catch (Exception e) {
1271                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1272    
1273                                    throw processException(e);
1274                            }
1275                            finally {
1276                                    closeSession(session);
1277                            }
1278                    }
1279    
1280                    return count.intValue();
1281            }
1282    
1283            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourcePermission.roleId = ?";
1284            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_LIKEP = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1285                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
1286                            ResourcePermissionImpl.class,
1287                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_LikeP",
1288                            new String[] {
1289                                    Long.class.getName(), String.class.getName(),
1290                                    
1291                            Integer.class.getName(), Integer.class.getName(),
1292                                    OrderByComparator.class.getName()
1293                            });
1294            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_LIKEP = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1295                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1296                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_LikeP",
1297                            new String[] { Long.class.getName(), String.class.getName() });
1298    
1299            /**
1300             * Returns all the resource permissions where companyId = &#63; and primKey LIKE &#63;.
1301             *
1302             * @param companyId the company ID
1303             * @param primKey the prim key
1304             * @return the matching resource permissions
1305             */
1306            @Override
1307            public List<ResourcePermission> findByC_LikeP(long companyId, String primKey) {
1308                    return findByC_LikeP(companyId, primKey, QueryUtil.ALL_POS,
1309                            QueryUtil.ALL_POS, null);
1310            }
1311    
1312            /**
1313             * Returns a range of all the resource permissions where companyId = &#63; and primKey LIKE &#63;.
1314             *
1315             * <p>
1316             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1317             * </p>
1318             *
1319             * @param companyId the company ID
1320             * @param primKey the prim key
1321             * @param start the lower bound of the range of resource permissions
1322             * @param end the upper bound of the range of resource permissions (not inclusive)
1323             * @return the range of matching resource permissions
1324             */
1325            @Override
1326            public List<ResourcePermission> findByC_LikeP(long companyId,
1327                    String primKey, int start, int end) {
1328                    return findByC_LikeP(companyId, primKey, start, end, null);
1329            }
1330    
1331            /**
1332             * Returns an ordered range of all the resource permissions where companyId = &#63; and primKey LIKE &#63;.
1333             *
1334             * <p>
1335             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1336             * </p>
1337             *
1338             * @param companyId the company ID
1339             * @param primKey the prim key
1340             * @param start the lower bound of the range of resource permissions
1341             * @param end the upper bound of the range of resource permissions (not inclusive)
1342             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1343             * @return the ordered range of matching resource permissions
1344             */
1345            @Override
1346            public List<ResourcePermission> findByC_LikeP(long companyId,
1347                    String primKey, int start, int end,
1348                    OrderByComparator<ResourcePermission> orderByComparator) {
1349                    boolean pagination = true;
1350                    FinderPath finderPath = null;
1351                    Object[] finderArgs = null;
1352    
1353                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_LIKEP;
1354                    finderArgs = new Object[] {
1355                                    companyId, primKey,
1356                                    
1357                                    start, end, orderByComparator
1358                            };
1359    
1360                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1361                                    finderArgs, this);
1362    
1363                    if ((list != null) && !list.isEmpty()) {
1364                            for (ResourcePermission resourcePermission : list) {
1365                                    if ((companyId != resourcePermission.getCompanyId()) ||
1366                                                    !StringUtil.wildcardMatches(
1367                                                            resourcePermission.getPrimKey(), primKey,
1368                                                            CharPool.UNDERLINE, CharPool.PERCENT,
1369                                                            CharPool.BACK_SLASH, true)) {
1370                                            list = null;
1371    
1372                                            break;
1373                                    }
1374                            }
1375                    }
1376    
1377                    if (list == null) {
1378                            StringBundler query = null;
1379    
1380                            if (orderByComparator != null) {
1381                                    query = new StringBundler(4 +
1382                                                    (orderByComparator.getOrderByFields().length * 3));
1383                            }
1384                            else {
1385                                    query = new StringBundler(4);
1386                            }
1387    
1388                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1389    
1390                            query.append(_FINDER_COLUMN_C_LIKEP_COMPANYID_2);
1391    
1392                            boolean bindPrimKey = false;
1393    
1394                            if (primKey == null) {
1395                                    query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_1);
1396                            }
1397                            else if (primKey.equals(StringPool.BLANK)) {
1398                                    query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_3);
1399                            }
1400                            else {
1401                                    bindPrimKey = true;
1402    
1403                                    query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_2);
1404                            }
1405    
1406                            if (orderByComparator != null) {
1407                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1408                                            orderByComparator);
1409                            }
1410                            else
1411                             if (pagination) {
1412                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1413                            }
1414    
1415                            String sql = query.toString();
1416    
1417                            Session session = null;
1418    
1419                            try {
1420                                    session = openSession();
1421    
1422                                    Query q = session.createQuery(sql);
1423    
1424                                    QueryPos qPos = QueryPos.getInstance(q);
1425    
1426                                    qPos.add(companyId);
1427    
1428                                    if (bindPrimKey) {
1429                                            qPos.add(primKey);
1430                                    }
1431    
1432                                    if (!pagination) {
1433                                            list = (List<ResourcePermission>)QueryUtil.list(q,
1434                                                            getDialect(), start, end, false);
1435    
1436                                            Collections.sort(list);
1437    
1438                                            list = Collections.unmodifiableList(list);
1439                                    }
1440                                    else {
1441                                            list = (List<ResourcePermission>)QueryUtil.list(q,
1442                                                            getDialect(), start, end);
1443                                    }
1444    
1445                                    cacheResult(list);
1446    
1447                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1448                            }
1449                            catch (Exception e) {
1450                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1451    
1452                                    throw processException(e);
1453                            }
1454                            finally {
1455                                    closeSession(session);
1456                            }
1457                    }
1458    
1459                    return list;
1460            }
1461    
1462            /**
1463             * Returns the first resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1464             *
1465             * @param companyId the company ID
1466             * @param primKey the prim key
1467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1468             * @return the first matching resource permission
1469             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
1470             */
1471            @Override
1472            public ResourcePermission findByC_LikeP_First(long companyId,
1473                    String primKey, OrderByComparator<ResourcePermission> orderByComparator)
1474                    throws NoSuchResourcePermissionException {
1475                    ResourcePermission resourcePermission = fetchByC_LikeP_First(companyId,
1476                                    primKey, orderByComparator);
1477    
1478                    if (resourcePermission != null) {
1479                            return resourcePermission;
1480                    }
1481    
1482                    StringBundler msg = new StringBundler(6);
1483    
1484                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1485    
1486                    msg.append("companyId=");
1487                    msg.append(companyId);
1488    
1489                    msg.append(", primKey=");
1490                    msg.append(primKey);
1491    
1492                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1493    
1494                    throw new NoSuchResourcePermissionException(msg.toString());
1495            }
1496    
1497            /**
1498             * Returns the first resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1499             *
1500             * @param companyId the company ID
1501             * @param primKey the prim key
1502             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1503             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
1504             */
1505            @Override
1506            public ResourcePermission fetchByC_LikeP_First(long companyId,
1507                    String primKey, OrderByComparator<ResourcePermission> orderByComparator) {
1508                    List<ResourcePermission> list = findByC_LikeP(companyId, primKey, 0, 1,
1509                                    orderByComparator);
1510    
1511                    if (!list.isEmpty()) {
1512                            return list.get(0);
1513                    }
1514    
1515                    return null;
1516            }
1517    
1518            /**
1519             * Returns the last resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1520             *
1521             * @param companyId the company ID
1522             * @param primKey the prim key
1523             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1524             * @return the last matching resource permission
1525             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
1526             */
1527            @Override
1528            public ResourcePermission findByC_LikeP_Last(long companyId,
1529                    String primKey, OrderByComparator<ResourcePermission> orderByComparator)
1530                    throws NoSuchResourcePermissionException {
1531                    ResourcePermission resourcePermission = fetchByC_LikeP_Last(companyId,
1532                                    primKey, orderByComparator);
1533    
1534                    if (resourcePermission != null) {
1535                            return resourcePermission;
1536                    }
1537    
1538                    StringBundler msg = new StringBundler(6);
1539    
1540                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1541    
1542                    msg.append("companyId=");
1543                    msg.append(companyId);
1544    
1545                    msg.append(", primKey=");
1546                    msg.append(primKey);
1547    
1548                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1549    
1550                    throw new NoSuchResourcePermissionException(msg.toString());
1551            }
1552    
1553            /**
1554             * Returns the last resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1555             *
1556             * @param companyId the company ID
1557             * @param primKey the prim key
1558             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1559             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
1560             */
1561            @Override
1562            public ResourcePermission fetchByC_LikeP_Last(long companyId,
1563                    String primKey, OrderByComparator<ResourcePermission> orderByComparator) {
1564                    int count = countByC_LikeP(companyId, primKey);
1565    
1566                    if (count == 0) {
1567                            return null;
1568                    }
1569    
1570                    List<ResourcePermission> list = findByC_LikeP(companyId, primKey,
1571                                    count - 1, count, orderByComparator);
1572    
1573                    if (!list.isEmpty()) {
1574                            return list.get(0);
1575                    }
1576    
1577                    return null;
1578            }
1579    
1580            /**
1581             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and primKey LIKE &#63;.
1582             *
1583             * @param resourcePermissionId the primary key of the current resource permission
1584             * @param companyId the company ID
1585             * @param primKey the prim key
1586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1587             * @return the previous, current, and next resource permission
1588             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1589             */
1590            @Override
1591            public ResourcePermission[] findByC_LikeP_PrevAndNext(
1592                    long resourcePermissionId, long companyId, String primKey,
1593                    OrderByComparator<ResourcePermission> orderByComparator)
1594                    throws NoSuchResourcePermissionException {
1595                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1596    
1597                    Session session = null;
1598    
1599                    try {
1600                            session = openSession();
1601    
1602                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1603    
1604                            array[0] = getByC_LikeP_PrevAndNext(session, resourcePermission,
1605                                            companyId, primKey, orderByComparator, true);
1606    
1607                            array[1] = resourcePermission;
1608    
1609                            array[2] = getByC_LikeP_PrevAndNext(session, resourcePermission,
1610                                            companyId, primKey, orderByComparator, false);
1611    
1612                            return array;
1613                    }
1614                    catch (Exception e) {
1615                            throw processException(e);
1616                    }
1617                    finally {
1618                            closeSession(session);
1619                    }
1620            }
1621    
1622            protected ResourcePermission getByC_LikeP_PrevAndNext(Session session,
1623                    ResourcePermission resourcePermission, long companyId, String primKey,
1624                    OrderByComparator<ResourcePermission> orderByComparator,
1625                    boolean previous) {
1626                    StringBundler query = null;
1627    
1628                    if (orderByComparator != null) {
1629                            query = new StringBundler(6 +
1630                                            (orderByComparator.getOrderByFields().length * 6));
1631                    }
1632                    else {
1633                            query = new StringBundler(3);
1634                    }
1635    
1636                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1637    
1638                    query.append(_FINDER_COLUMN_C_LIKEP_COMPANYID_2);
1639    
1640                    boolean bindPrimKey = false;
1641    
1642                    if (primKey == null) {
1643                            query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_1);
1644                    }
1645                    else if (primKey.equals(StringPool.BLANK)) {
1646                            query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_3);
1647                    }
1648                    else {
1649                            bindPrimKey = true;
1650    
1651                            query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_2);
1652                    }
1653    
1654                    if (orderByComparator != null) {
1655                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1656    
1657                            if (orderByConditionFields.length > 0) {
1658                                    query.append(WHERE_AND);
1659                            }
1660    
1661                            for (int i = 0; i < orderByConditionFields.length; i++) {
1662                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1663                                    query.append(orderByConditionFields[i]);
1664    
1665                                    if ((i + 1) < orderByConditionFields.length) {
1666                                            if (orderByComparator.isAscending() ^ previous) {
1667                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1668                                            }
1669                                            else {
1670                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1671                                            }
1672                                    }
1673                                    else {
1674                                            if (orderByComparator.isAscending() ^ previous) {
1675                                                    query.append(WHERE_GREATER_THAN);
1676                                            }
1677                                            else {
1678                                                    query.append(WHERE_LESSER_THAN);
1679                                            }
1680                                    }
1681                            }
1682    
1683                            query.append(ORDER_BY_CLAUSE);
1684    
1685                            String[] orderByFields = orderByComparator.getOrderByFields();
1686    
1687                            for (int i = 0; i < orderByFields.length; i++) {
1688                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1689                                    query.append(orderByFields[i]);
1690    
1691                                    if ((i + 1) < orderByFields.length) {
1692                                            if (orderByComparator.isAscending() ^ previous) {
1693                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1694                                            }
1695                                            else {
1696                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1697                                            }
1698                                    }
1699                                    else {
1700                                            if (orderByComparator.isAscending() ^ previous) {
1701                                                    query.append(ORDER_BY_ASC);
1702                                            }
1703                                            else {
1704                                                    query.append(ORDER_BY_DESC);
1705                                            }
1706                                    }
1707                            }
1708                    }
1709                    else {
1710                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1711                    }
1712    
1713                    String sql = query.toString();
1714    
1715                    Query q = session.createQuery(sql);
1716    
1717                    q.setFirstResult(0);
1718                    q.setMaxResults(2);
1719    
1720                    QueryPos qPos = QueryPos.getInstance(q);
1721    
1722                    qPos.add(companyId);
1723    
1724                    if (bindPrimKey) {
1725                            qPos.add(primKey);
1726                    }
1727    
1728                    if (orderByComparator != null) {
1729                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
1730    
1731                            for (Object value : values) {
1732                                    qPos.add(value);
1733                            }
1734                    }
1735    
1736                    List<ResourcePermission> list = q.list();
1737    
1738                    if (list.size() == 2) {
1739                            return list.get(1);
1740                    }
1741                    else {
1742                            return null;
1743                    }
1744            }
1745    
1746            /**
1747             * Removes all the resource permissions where companyId = &#63; and primKey LIKE &#63; from the database.
1748             *
1749             * @param companyId the company ID
1750             * @param primKey the prim key
1751             */
1752            @Override
1753            public void removeByC_LikeP(long companyId, String primKey) {
1754                    for (ResourcePermission resourcePermission : findByC_LikeP(companyId,
1755                                    primKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1756                            remove(resourcePermission);
1757                    }
1758            }
1759    
1760            /**
1761             * Returns the number of resource permissions where companyId = &#63; and primKey LIKE &#63;.
1762             *
1763             * @param companyId the company ID
1764             * @param primKey the prim key
1765             * @return the number of matching resource permissions
1766             */
1767            @Override
1768            public int countByC_LikeP(long companyId, String primKey) {
1769                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_LIKEP;
1770    
1771                    Object[] finderArgs = new Object[] { companyId, primKey };
1772    
1773                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1774                                    this);
1775    
1776                    if (count == null) {
1777                            StringBundler query = new StringBundler(3);
1778    
1779                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
1780    
1781                            query.append(_FINDER_COLUMN_C_LIKEP_COMPANYID_2);
1782    
1783                            boolean bindPrimKey = false;
1784    
1785                            if (primKey == null) {
1786                                    query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_1);
1787                            }
1788                            else if (primKey.equals(StringPool.BLANK)) {
1789                                    query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_3);
1790                            }
1791                            else {
1792                                    bindPrimKey = true;
1793    
1794                                    query.append(_FINDER_COLUMN_C_LIKEP_PRIMKEY_2);
1795                            }
1796    
1797                            String sql = query.toString();
1798    
1799                            Session session = null;
1800    
1801                            try {
1802                                    session = openSession();
1803    
1804                                    Query q = session.createQuery(sql);
1805    
1806                                    QueryPos qPos = QueryPos.getInstance(q);
1807    
1808                                    qPos.add(companyId);
1809    
1810                                    if (bindPrimKey) {
1811                                            qPos.add(primKey);
1812                                    }
1813    
1814                                    count = (Long)q.uniqueResult();
1815    
1816                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1817                            }
1818                            catch (Exception e) {
1819                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1820    
1821                                    throw processException(e);
1822                            }
1823                            finally {
1824                                    closeSession(session);
1825                            }
1826                    }
1827    
1828                    return count.intValue();
1829            }
1830    
1831            private static final String _FINDER_COLUMN_C_LIKEP_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
1832            private static final String _FINDER_COLUMN_C_LIKEP_PRIMKEY_1 = "resourcePermission.primKey LIKE NULL";
1833            private static final String _FINDER_COLUMN_C_LIKEP_PRIMKEY_2 = "resourcePermission.primKey LIKE ?";
1834            private static final String _FINDER_COLUMN_C_LIKEP_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey LIKE '')";
1835            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1836                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
1837                            ResourcePermissionImpl.class,
1838                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S",
1839                            new String[] {
1840                                    Long.class.getName(), String.class.getName(),
1841                                    Integer.class.getName(),
1842                                    
1843                            Integer.class.getName(), Integer.class.getName(),
1844                                    OrderByComparator.class.getName()
1845                            });
1846            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1847                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
1848                            ResourcePermissionImpl.class,
1849                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S",
1850                            new String[] {
1851                                    Long.class.getName(), String.class.getName(),
1852                                    Integer.class.getName()
1853                            },
1854                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
1855                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
1856                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK);
1857            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
1858                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1859                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S",
1860                            new String[] {
1861                                    Long.class.getName(), String.class.getName(),
1862                                    Integer.class.getName()
1863                            });
1864    
1865            /**
1866             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1867             *
1868             * @param companyId the company ID
1869             * @param name the name
1870             * @param scope the scope
1871             * @return the matching resource permissions
1872             */
1873            @Override
1874            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1875                    int scope) {
1876                    return findByC_N_S(companyId, name, scope, QueryUtil.ALL_POS,
1877                            QueryUtil.ALL_POS, null);
1878            }
1879    
1880            /**
1881             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1882             *
1883             * <p>
1884             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1885             * </p>
1886             *
1887             * @param companyId the company ID
1888             * @param name the name
1889             * @param scope the scope
1890             * @param start the lower bound of the range of resource permissions
1891             * @param end the upper bound of the range of resource permissions (not inclusive)
1892             * @return the range of matching resource permissions
1893             */
1894            @Override
1895            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1896                    int scope, int start, int end) {
1897                    return findByC_N_S(companyId, name, scope, start, end, null);
1898            }
1899    
1900            /**
1901             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1902             *
1903             * <p>
1904             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1905             * </p>
1906             *
1907             * @param companyId the company ID
1908             * @param name the name
1909             * @param scope the scope
1910             * @param start the lower bound of the range of resource permissions
1911             * @param end the upper bound of the range of resource permissions (not inclusive)
1912             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1913             * @return the ordered range of matching resource permissions
1914             */
1915            @Override
1916            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1917                    int scope, int start, int end,
1918                    OrderByComparator<ResourcePermission> orderByComparator) {
1919                    boolean pagination = true;
1920                    FinderPath finderPath = null;
1921                    Object[] finderArgs = null;
1922    
1923                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1924                                    (orderByComparator == null)) {
1925                            pagination = false;
1926                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S;
1927                            finderArgs = new Object[] { companyId, name, scope };
1928                    }
1929                    else {
1930                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S;
1931                            finderArgs = new Object[] {
1932                                            companyId, name, scope,
1933                                            
1934                                            start, end, orderByComparator
1935                                    };
1936                    }
1937    
1938                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1939                                    finderArgs, this);
1940    
1941                    if ((list != null) && !list.isEmpty()) {
1942                            for (ResourcePermission resourcePermission : list) {
1943                                    if ((companyId != resourcePermission.getCompanyId()) ||
1944                                                    !Validator.equals(name, resourcePermission.getName()) ||
1945                                                    (scope != resourcePermission.getScope())) {
1946                                            list = null;
1947    
1948                                            break;
1949                                    }
1950                            }
1951                    }
1952    
1953                    if (list == null) {
1954                            StringBundler query = null;
1955    
1956                            if (orderByComparator != null) {
1957                                    query = new StringBundler(5 +
1958                                                    (orderByComparator.getOrderByFields().length * 3));
1959                            }
1960                            else {
1961                                    query = new StringBundler(5);
1962                            }
1963    
1964                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1965    
1966                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1967    
1968                            boolean bindName = false;
1969    
1970                            if (name == null) {
1971                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1972                            }
1973                            else if (name.equals(StringPool.BLANK)) {
1974                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1975                            }
1976                            else {
1977                                    bindName = true;
1978    
1979                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1980                            }
1981    
1982                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1983    
1984                            if (orderByComparator != null) {
1985                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1986                                            orderByComparator);
1987                            }
1988                            else
1989                             if (pagination) {
1990                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
1991                            }
1992    
1993                            String sql = query.toString();
1994    
1995                            Session session = null;
1996    
1997                            try {
1998                                    session = openSession();
1999    
2000                                    Query q = session.createQuery(sql);
2001    
2002                                    QueryPos qPos = QueryPos.getInstance(q);
2003    
2004                                    qPos.add(companyId);
2005    
2006                                    if (bindName) {
2007                                            qPos.add(name);
2008                                    }
2009    
2010                                    qPos.add(scope);
2011    
2012                                    if (!pagination) {
2013                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2014                                                            getDialect(), start, end, false);
2015    
2016                                            Collections.sort(list);
2017    
2018                                            list = Collections.unmodifiableList(list);
2019                                    }
2020                                    else {
2021                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2022                                                            getDialect(), start, end);
2023                                    }
2024    
2025                                    cacheResult(list);
2026    
2027                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2028                            }
2029                            catch (Exception e) {
2030                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2031    
2032                                    throw processException(e);
2033                            }
2034                            finally {
2035                                    closeSession(session);
2036                            }
2037                    }
2038    
2039                    return list;
2040            }
2041    
2042            /**
2043             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2044             *
2045             * @param companyId the company ID
2046             * @param name the name
2047             * @param scope the scope
2048             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2049             * @return the first matching resource permission
2050             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
2051             */
2052            @Override
2053            public ResourcePermission findByC_N_S_First(long companyId, String name,
2054                    int scope, OrderByComparator<ResourcePermission> orderByComparator)
2055                    throws NoSuchResourcePermissionException {
2056                    ResourcePermission resourcePermission = fetchByC_N_S_First(companyId,
2057                                    name, scope, orderByComparator);
2058    
2059                    if (resourcePermission != null) {
2060                            return resourcePermission;
2061                    }
2062    
2063                    StringBundler msg = new StringBundler(8);
2064    
2065                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2066    
2067                    msg.append("companyId=");
2068                    msg.append(companyId);
2069    
2070                    msg.append(", name=");
2071                    msg.append(name);
2072    
2073                    msg.append(", scope=");
2074                    msg.append(scope);
2075    
2076                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2077    
2078                    throw new NoSuchResourcePermissionException(msg.toString());
2079            }
2080    
2081            /**
2082             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2083             *
2084             * @param companyId the company ID
2085             * @param name the name
2086             * @param scope the scope
2087             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2088             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
2089             */
2090            @Override
2091            public ResourcePermission fetchByC_N_S_First(long companyId, String name,
2092                    int scope, OrderByComparator<ResourcePermission> orderByComparator) {
2093                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope, 0,
2094                                    1, orderByComparator);
2095    
2096                    if (!list.isEmpty()) {
2097                            return list.get(0);
2098                    }
2099    
2100                    return null;
2101            }
2102    
2103            /**
2104             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2105             *
2106             * @param companyId the company ID
2107             * @param name the name
2108             * @param scope the scope
2109             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2110             * @return the last matching resource permission
2111             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
2112             */
2113            @Override
2114            public ResourcePermission findByC_N_S_Last(long companyId, String name,
2115                    int scope, OrderByComparator<ResourcePermission> orderByComparator)
2116                    throws NoSuchResourcePermissionException {
2117                    ResourcePermission resourcePermission = fetchByC_N_S_Last(companyId,
2118                                    name, scope, orderByComparator);
2119    
2120                    if (resourcePermission != null) {
2121                            return resourcePermission;
2122                    }
2123    
2124                    StringBundler msg = new StringBundler(8);
2125    
2126                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2127    
2128                    msg.append("companyId=");
2129                    msg.append(companyId);
2130    
2131                    msg.append(", name=");
2132                    msg.append(name);
2133    
2134                    msg.append(", scope=");
2135                    msg.append(scope);
2136    
2137                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2138    
2139                    throw new NoSuchResourcePermissionException(msg.toString());
2140            }
2141    
2142            /**
2143             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2144             *
2145             * @param companyId the company ID
2146             * @param name the name
2147             * @param scope the scope
2148             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2149             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
2150             */
2151            @Override
2152            public ResourcePermission fetchByC_N_S_Last(long companyId, String name,
2153                    int scope, OrderByComparator<ResourcePermission> orderByComparator) {
2154                    int count = countByC_N_S(companyId, name, scope);
2155    
2156                    if (count == 0) {
2157                            return null;
2158                    }
2159    
2160                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope,
2161                                    count - 1, count, orderByComparator);
2162    
2163                    if (!list.isEmpty()) {
2164                            return list.get(0);
2165                    }
2166    
2167                    return null;
2168            }
2169    
2170            /**
2171             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2172             *
2173             * @param resourcePermissionId the primary key of the current resource permission
2174             * @param companyId the company ID
2175             * @param name the name
2176             * @param scope the scope
2177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2178             * @return the previous, current, and next resource permission
2179             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2180             */
2181            @Override
2182            public ResourcePermission[] findByC_N_S_PrevAndNext(
2183                    long resourcePermissionId, long companyId, String name, int scope,
2184                    OrderByComparator<ResourcePermission> orderByComparator)
2185                    throws NoSuchResourcePermissionException {
2186                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2187    
2188                    Session session = null;
2189    
2190                    try {
2191                            session = openSession();
2192    
2193                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2194    
2195                            array[0] = getByC_N_S_PrevAndNext(session, resourcePermission,
2196                                            companyId, name, scope, orderByComparator, true);
2197    
2198                            array[1] = resourcePermission;
2199    
2200                            array[2] = getByC_N_S_PrevAndNext(session, resourcePermission,
2201                                            companyId, name, scope, orderByComparator, false);
2202    
2203                            return array;
2204                    }
2205                    catch (Exception e) {
2206                            throw processException(e);
2207                    }
2208                    finally {
2209                            closeSession(session);
2210                    }
2211            }
2212    
2213            protected ResourcePermission getByC_N_S_PrevAndNext(Session session,
2214                    ResourcePermission resourcePermission, long companyId, String name,
2215                    int scope, OrderByComparator<ResourcePermission> orderByComparator,
2216                    boolean previous) {
2217                    StringBundler query = null;
2218    
2219                    if (orderByComparator != null) {
2220                            query = new StringBundler(6 +
2221                                            (orderByComparator.getOrderByFields().length * 6));
2222                    }
2223                    else {
2224                            query = new StringBundler(3);
2225                    }
2226    
2227                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2228    
2229                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2230    
2231                    boolean bindName = false;
2232    
2233                    if (name == null) {
2234                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2235                    }
2236                    else if (name.equals(StringPool.BLANK)) {
2237                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2238                    }
2239                    else {
2240                            bindName = true;
2241    
2242                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2243                    }
2244    
2245                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2246    
2247                    if (orderByComparator != null) {
2248                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2249    
2250                            if (orderByConditionFields.length > 0) {
2251                                    query.append(WHERE_AND);
2252                            }
2253    
2254                            for (int i = 0; i < orderByConditionFields.length; i++) {
2255                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2256                                    query.append(orderByConditionFields[i]);
2257    
2258                                    if ((i + 1) < orderByConditionFields.length) {
2259                                            if (orderByComparator.isAscending() ^ previous) {
2260                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2261                                            }
2262                                            else {
2263                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2264                                            }
2265                                    }
2266                                    else {
2267                                            if (orderByComparator.isAscending() ^ previous) {
2268                                                    query.append(WHERE_GREATER_THAN);
2269                                            }
2270                                            else {
2271                                                    query.append(WHERE_LESSER_THAN);
2272                                            }
2273                                    }
2274                            }
2275    
2276                            query.append(ORDER_BY_CLAUSE);
2277    
2278                            String[] orderByFields = orderByComparator.getOrderByFields();
2279    
2280                            for (int i = 0; i < orderByFields.length; i++) {
2281                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2282                                    query.append(orderByFields[i]);
2283    
2284                                    if ((i + 1) < orderByFields.length) {
2285                                            if (orderByComparator.isAscending() ^ previous) {
2286                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2287                                            }
2288                                            else {
2289                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2290                                            }
2291                                    }
2292                                    else {
2293                                            if (orderByComparator.isAscending() ^ previous) {
2294                                                    query.append(ORDER_BY_ASC);
2295                                            }
2296                                            else {
2297                                                    query.append(ORDER_BY_DESC);
2298                                            }
2299                                    }
2300                            }
2301                    }
2302                    else {
2303                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
2304                    }
2305    
2306                    String sql = query.toString();
2307    
2308                    Query q = session.createQuery(sql);
2309    
2310                    q.setFirstResult(0);
2311                    q.setMaxResults(2);
2312    
2313                    QueryPos qPos = QueryPos.getInstance(q);
2314    
2315                    qPos.add(companyId);
2316    
2317                    if (bindName) {
2318                            qPos.add(name);
2319                    }
2320    
2321                    qPos.add(scope);
2322    
2323                    if (orderByComparator != null) {
2324                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
2325    
2326                            for (Object value : values) {
2327                                    qPos.add(value);
2328                            }
2329                    }
2330    
2331                    List<ResourcePermission> list = q.list();
2332    
2333                    if (list.size() == 2) {
2334                            return list.get(1);
2335                    }
2336                    else {
2337                            return null;
2338                    }
2339            }
2340    
2341            /**
2342             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; from the database.
2343             *
2344             * @param companyId the company ID
2345             * @param name the name
2346             * @param scope the scope
2347             */
2348            @Override
2349            public void removeByC_N_S(long companyId, String name, int scope) {
2350                    for (ResourcePermission resourcePermission : findByC_N_S(companyId,
2351                                    name, scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2352                            remove(resourcePermission);
2353                    }
2354            }
2355    
2356            /**
2357             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
2358             *
2359             * @param companyId the company ID
2360             * @param name the name
2361             * @param scope the scope
2362             * @return the number of matching resource permissions
2363             */
2364            @Override
2365            public int countByC_N_S(long companyId, String name, int scope) {
2366                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S;
2367    
2368                    Object[] finderArgs = new Object[] { companyId, name, scope };
2369    
2370                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2371                                    this);
2372    
2373                    if (count == null) {
2374                            StringBundler query = new StringBundler(4);
2375    
2376                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2377    
2378                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2379    
2380                            boolean bindName = false;
2381    
2382                            if (name == null) {
2383                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2384                            }
2385                            else if (name.equals(StringPool.BLANK)) {
2386                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2387                            }
2388                            else {
2389                                    bindName = true;
2390    
2391                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2392                            }
2393    
2394                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2395    
2396                            String sql = query.toString();
2397    
2398                            Session session = null;
2399    
2400                            try {
2401                                    session = openSession();
2402    
2403                                    Query q = session.createQuery(sql);
2404    
2405                                    QueryPos qPos = QueryPos.getInstance(q);
2406    
2407                                    qPos.add(companyId);
2408    
2409                                    if (bindName) {
2410                                            qPos.add(name);
2411                                    }
2412    
2413                                    qPos.add(scope);
2414    
2415                                    count = (Long)q.uniqueResult();
2416    
2417                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2418                            }
2419                            catch (Exception e) {
2420                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2421    
2422                                    throw processException(e);
2423                            }
2424                            finally {
2425                                    closeSession(session);
2426                            }
2427                    }
2428    
2429                    return count.intValue();
2430            }
2431    
2432            private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
2433            private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourcePermission.name IS NULL AND ";
2434            private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourcePermission.name = ? AND ";
2435            private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = '') AND ";
2436            private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourcePermission.scope = ?";
2437            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
2438                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
2439                            ResourcePermissionImpl.class,
2440                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P",
2441                            new String[] {
2442                                    Long.class.getName(), String.class.getName(),
2443                                    Integer.class.getName(), String.class.getName(),
2444                                    
2445                            Integer.class.getName(), Integer.class.getName(),
2446                                    OrderByComparator.class.getName()
2447                            });
2448            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P =
2449                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
2450                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
2451                            ResourcePermissionImpl.class,
2452                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P",
2453                            new String[] {
2454                                    Long.class.getName(), String.class.getName(),
2455                                    Integer.class.getName(), String.class.getName()
2456                            },
2457                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
2458                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
2459                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
2460                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK);
2461            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
2462                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2463                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P",
2464                            new String[] {
2465                                    Long.class.getName(), String.class.getName(),
2466                                    Integer.class.getName(), String.class.getName()
2467                            });
2468    
2469            /**
2470             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2471             *
2472             * @param companyId the company ID
2473             * @param name the name
2474             * @param scope the scope
2475             * @param primKey the prim key
2476             * @return the matching resource permissions
2477             */
2478            @Override
2479            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
2480                    int scope, String primKey) {
2481                    return findByC_N_S_P(companyId, name, scope, primKey,
2482                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2483            }
2484    
2485            /**
2486             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2487             *
2488             * <p>
2489             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2490             * </p>
2491             *
2492             * @param companyId the company ID
2493             * @param name the name
2494             * @param scope the scope
2495             * @param primKey the prim key
2496             * @param start the lower bound of the range of resource permissions
2497             * @param end the upper bound of the range of resource permissions (not inclusive)
2498             * @return the range of matching resource permissions
2499             */
2500            @Override
2501            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
2502                    int scope, String primKey, int start, int end) {
2503                    return findByC_N_S_P(companyId, name, scope, primKey, start, end, null);
2504            }
2505    
2506            /**
2507             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2508             *
2509             * <p>
2510             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
2511             * </p>
2512             *
2513             * @param companyId the company ID
2514             * @param name the name
2515             * @param scope the scope
2516             * @param primKey the prim key
2517             * @param start the lower bound of the range of resource permissions
2518             * @param end the upper bound of the range of resource permissions (not inclusive)
2519             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2520             * @return the ordered range of matching resource permissions
2521             */
2522            @Override
2523            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
2524                    int scope, String primKey, int start, int end,
2525                    OrderByComparator<ResourcePermission> orderByComparator) {
2526                    boolean pagination = true;
2527                    FinderPath finderPath = null;
2528                    Object[] finderArgs = null;
2529    
2530                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2531                                    (orderByComparator == null)) {
2532                            pagination = false;
2533                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P;
2534                            finderArgs = new Object[] { companyId, name, scope, primKey };
2535                    }
2536                    else {
2537                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P;
2538                            finderArgs = new Object[] {
2539                                            companyId, name, scope, primKey,
2540                                            
2541                                            start, end, orderByComparator
2542                                    };
2543                    }
2544    
2545                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
2546                                    finderArgs, this);
2547    
2548                    if ((list != null) && !list.isEmpty()) {
2549                            for (ResourcePermission resourcePermission : list) {
2550                                    if ((companyId != resourcePermission.getCompanyId()) ||
2551                                                    !Validator.equals(name, resourcePermission.getName()) ||
2552                                                    (scope != resourcePermission.getScope()) ||
2553                                                    !Validator.equals(primKey,
2554                                                            resourcePermission.getPrimKey())) {
2555                                            list = null;
2556    
2557                                            break;
2558                                    }
2559                            }
2560                    }
2561    
2562                    if (list == null) {
2563                            StringBundler query = null;
2564    
2565                            if (orderByComparator != null) {
2566                                    query = new StringBundler(6 +
2567                                                    (orderByComparator.getOrderByFields().length * 3));
2568                            }
2569                            else {
2570                                    query = new StringBundler(6);
2571                            }
2572    
2573                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2574    
2575                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
2576    
2577                            boolean bindName = false;
2578    
2579                            if (name == null) {
2580                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
2581                            }
2582                            else if (name.equals(StringPool.BLANK)) {
2583                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
2584                            }
2585                            else {
2586                                    bindName = true;
2587    
2588                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
2589                            }
2590    
2591                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
2592    
2593                            boolean bindPrimKey = false;
2594    
2595                            if (primKey == null) {
2596                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
2597                            }
2598                            else if (primKey.equals(StringPool.BLANK)) {
2599                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
2600                            }
2601                            else {
2602                                    bindPrimKey = true;
2603    
2604                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
2605                            }
2606    
2607                            if (orderByComparator != null) {
2608                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2609                                            orderByComparator);
2610                            }
2611                            else
2612                             if (pagination) {
2613                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
2614                            }
2615    
2616                            String sql = query.toString();
2617    
2618                            Session session = null;
2619    
2620                            try {
2621                                    session = openSession();
2622    
2623                                    Query q = session.createQuery(sql);
2624    
2625                                    QueryPos qPos = QueryPos.getInstance(q);
2626    
2627                                    qPos.add(companyId);
2628    
2629                                    if (bindName) {
2630                                            qPos.add(name);
2631                                    }
2632    
2633                                    qPos.add(scope);
2634    
2635                                    if (bindPrimKey) {
2636                                            qPos.add(primKey);
2637                                    }
2638    
2639                                    if (!pagination) {
2640                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2641                                                            getDialect(), start, end, false);
2642    
2643                                            Collections.sort(list);
2644    
2645                                            list = Collections.unmodifiableList(list);
2646                                    }
2647                                    else {
2648                                            list = (List<ResourcePermission>)QueryUtil.list(q,
2649                                                            getDialect(), start, end);
2650                                    }
2651    
2652                                    cacheResult(list);
2653    
2654                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2655                            }
2656                            catch (Exception e) {
2657                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2658    
2659                                    throw processException(e);
2660                            }
2661                            finally {
2662                                    closeSession(session);
2663                            }
2664                    }
2665    
2666                    return list;
2667            }
2668    
2669            /**
2670             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2671             *
2672             * @param companyId the company ID
2673             * @param name the name
2674             * @param scope the scope
2675             * @param primKey the prim key
2676             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2677             * @return the first matching resource permission
2678             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
2679             */
2680            @Override
2681            public ResourcePermission findByC_N_S_P_First(long companyId, String name,
2682                    int scope, String primKey,
2683                    OrderByComparator<ResourcePermission> orderByComparator)
2684                    throws NoSuchResourcePermissionException {
2685                    ResourcePermission resourcePermission = fetchByC_N_S_P_First(companyId,
2686                                    name, scope, primKey, orderByComparator);
2687    
2688                    if (resourcePermission != null) {
2689                            return resourcePermission;
2690                    }
2691    
2692                    StringBundler msg = new StringBundler(10);
2693    
2694                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2695    
2696                    msg.append("companyId=");
2697                    msg.append(companyId);
2698    
2699                    msg.append(", name=");
2700                    msg.append(name);
2701    
2702                    msg.append(", scope=");
2703                    msg.append(scope);
2704    
2705                    msg.append(", primKey=");
2706                    msg.append(primKey);
2707    
2708                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2709    
2710                    throw new NoSuchResourcePermissionException(msg.toString());
2711            }
2712    
2713            /**
2714             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2715             *
2716             * @param companyId the company ID
2717             * @param name the name
2718             * @param scope the scope
2719             * @param primKey the prim key
2720             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2721             * @return the first matching resource permission, or <code>null</code> if a matching resource permission could not be found
2722             */
2723            @Override
2724            public ResourcePermission fetchByC_N_S_P_First(long companyId, String name,
2725                    int scope, String primKey,
2726                    OrderByComparator<ResourcePermission> orderByComparator) {
2727                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
2728                                    primKey, 0, 1, orderByComparator);
2729    
2730                    if (!list.isEmpty()) {
2731                            return list.get(0);
2732                    }
2733    
2734                    return null;
2735            }
2736    
2737            /**
2738             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2739             *
2740             * @param companyId the company ID
2741             * @param name the name
2742             * @param scope the scope
2743             * @param primKey the prim key
2744             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2745             * @return the last matching resource permission
2746             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
2747             */
2748            @Override
2749            public ResourcePermission findByC_N_S_P_Last(long companyId, String name,
2750                    int scope, String primKey,
2751                    OrderByComparator<ResourcePermission> orderByComparator)
2752                    throws NoSuchResourcePermissionException {
2753                    ResourcePermission resourcePermission = fetchByC_N_S_P_Last(companyId,
2754                                    name, scope, primKey, orderByComparator);
2755    
2756                    if (resourcePermission != null) {
2757                            return resourcePermission;
2758                    }
2759    
2760                    StringBundler msg = new StringBundler(10);
2761    
2762                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2763    
2764                    msg.append("companyId=");
2765                    msg.append(companyId);
2766    
2767                    msg.append(", name=");
2768                    msg.append(name);
2769    
2770                    msg.append(", scope=");
2771                    msg.append(scope);
2772    
2773                    msg.append(", primKey=");
2774                    msg.append(primKey);
2775    
2776                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2777    
2778                    throw new NoSuchResourcePermissionException(msg.toString());
2779            }
2780    
2781            /**
2782             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2783             *
2784             * @param companyId the company ID
2785             * @param name the name
2786             * @param scope the scope
2787             * @param primKey the prim key
2788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2789             * @return the last matching resource permission, or <code>null</code> if a matching resource permission could not be found
2790             */
2791            @Override
2792            public ResourcePermission fetchByC_N_S_P_Last(long companyId, String name,
2793                    int scope, String primKey,
2794                    OrderByComparator<ResourcePermission> orderByComparator) {
2795                    int count = countByC_N_S_P(companyId, name, scope, primKey);
2796    
2797                    if (count == 0) {
2798                            return null;
2799                    }
2800    
2801                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
2802                                    primKey, count - 1, count, orderByComparator);
2803    
2804                    if (!list.isEmpty()) {
2805                            return list.get(0);
2806                    }
2807    
2808                    return null;
2809            }
2810    
2811            /**
2812             * 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;.
2813             *
2814             * @param resourcePermissionId the primary key of the current resource permission
2815             * @param companyId the company ID
2816             * @param name the name
2817             * @param scope the scope
2818             * @param primKey the prim key
2819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2820             * @return the previous, current, and next resource permission
2821             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2822             */
2823            @Override
2824            public ResourcePermission[] findByC_N_S_P_PrevAndNext(
2825                    long resourcePermissionId, long companyId, String name, int scope,
2826                    String primKey, OrderByComparator<ResourcePermission> orderByComparator)
2827                    throws NoSuchResourcePermissionException {
2828                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2829    
2830                    Session session = null;
2831    
2832                    try {
2833                            session = openSession();
2834    
2835                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2836    
2837                            array[0] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
2838                                            companyId, name, scope, primKey, orderByComparator, true);
2839    
2840                            array[1] = resourcePermission;
2841    
2842                            array[2] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
2843                                            companyId, name, scope, primKey, orderByComparator, false);
2844    
2845                            return array;
2846                    }
2847                    catch (Exception e) {
2848                            throw processException(e);
2849                    }
2850                    finally {
2851                            closeSession(session);
2852                    }
2853            }
2854    
2855            protected ResourcePermission getByC_N_S_P_PrevAndNext(Session session,
2856                    ResourcePermission resourcePermission, long companyId, String name,
2857                    int scope, String primKey,
2858                    OrderByComparator<ResourcePermission> orderByComparator,
2859                    boolean previous) {
2860                    StringBundler query = null;
2861    
2862                    if (orderByComparator != null) {
2863                            query = new StringBundler(6 +
2864                                            (orderByComparator.getOrderByFields().length * 6));
2865                    }
2866                    else {
2867                            query = new StringBundler(3);
2868                    }
2869    
2870                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2871    
2872                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
2873    
2874                    boolean bindName = false;
2875    
2876                    if (name == null) {
2877                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
2878                    }
2879                    else if (name.equals(StringPool.BLANK)) {
2880                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
2881                    }
2882                    else {
2883                            bindName = true;
2884    
2885                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
2886                    }
2887    
2888                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
2889    
2890                    boolean bindPrimKey = false;
2891    
2892                    if (primKey == null) {
2893                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
2894                    }
2895                    else if (primKey.equals(StringPool.BLANK)) {
2896                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
2897                    }
2898                    else {
2899                            bindPrimKey = true;
2900    
2901                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
2902                    }
2903    
2904                    if (orderByComparator != null) {
2905                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2906    
2907                            if (orderByConditionFields.length > 0) {
2908                                    query.append(WHERE_AND);
2909                            }
2910    
2911                            for (int i = 0; i < orderByConditionFields.length; i++) {
2912                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2913                                    query.append(orderByConditionFields[i]);
2914    
2915                                    if ((i + 1) < orderByConditionFields.length) {
2916                                            if (orderByComparator.isAscending() ^ previous) {
2917                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2918                                            }
2919                                            else {
2920                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2921                                            }
2922                                    }
2923                                    else {
2924                                            if (orderByComparator.isAscending() ^ previous) {
2925                                                    query.append(WHERE_GREATER_THAN);
2926                                            }
2927                                            else {
2928                                                    query.append(WHERE_LESSER_THAN);
2929                                            }
2930                                    }
2931                            }
2932    
2933                            query.append(ORDER_BY_CLAUSE);
2934    
2935                            String[] orderByFields = orderByComparator.getOrderByFields();
2936    
2937                            for (int i = 0; i < orderByFields.length; i++) {
2938                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2939                                    query.append(orderByFields[i]);
2940    
2941                                    if ((i + 1) < orderByFields.length) {
2942                                            if (orderByComparator.isAscending() ^ previous) {
2943                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2944                                            }
2945                                            else {
2946                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2947                                            }
2948                                    }
2949                                    else {
2950                                            if (orderByComparator.isAscending() ^ previous) {
2951                                                    query.append(ORDER_BY_ASC);
2952                                            }
2953                                            else {
2954                                                    query.append(ORDER_BY_DESC);
2955                                            }
2956                                    }
2957                            }
2958                    }
2959                    else {
2960                            query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
2961                    }
2962    
2963                    String sql = query.toString();
2964    
2965                    Query q = session.createQuery(sql);
2966    
2967                    q.setFirstResult(0);
2968                    q.setMaxResults(2);
2969    
2970                    QueryPos qPos = QueryPos.getInstance(q);
2971    
2972                    qPos.add(companyId);
2973    
2974                    if (bindName) {
2975                            qPos.add(name);
2976                    }
2977    
2978                    qPos.add(scope);
2979    
2980                    if (bindPrimKey) {
2981                            qPos.add(primKey);
2982                    }
2983    
2984                    if (orderByComparator != null) {
2985                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
2986    
2987                            for (Object value : values) {
2988                                    qPos.add(value);
2989                            }
2990                    }
2991    
2992                    List<ResourcePermission> list = q.list();
2993    
2994                    if (list.size() == 2) {
2995                            return list.get(1);
2996                    }
2997                    else {
2998                            return null;
2999                    }
3000            }
3001    
3002            /**
3003             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; from the database.
3004             *
3005             * @param companyId the company ID
3006             * @param name the name
3007             * @param scope the scope
3008             * @param primKey the prim key
3009             */
3010            @Override
3011            public void removeByC_N_S_P(long companyId, String name, int scope,
3012                    String primKey) {
3013                    for (ResourcePermission resourcePermission : findByC_N_S_P(companyId,
3014                                    name, scope, primKey, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3015                            remove(resourcePermission);
3016                    }
3017            }
3018    
3019            /**
3020             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
3021             *
3022             * @param companyId the company ID
3023             * @param name the name
3024             * @param scope the scope
3025             * @param primKey the prim key
3026             * @return the number of matching resource permissions
3027             */
3028            @Override
3029            public int countByC_N_S_P(long companyId, String name, int scope,
3030                    String primKey) {
3031                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S_P;
3032    
3033                    Object[] finderArgs = new Object[] { companyId, name, scope, primKey };
3034    
3035                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3036                                    this);
3037    
3038                    if (count == null) {
3039                            StringBundler query = new StringBundler(5);
3040    
3041                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
3042    
3043                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
3044    
3045                            boolean bindName = false;
3046    
3047                            if (name == null) {
3048                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
3049                            }
3050                            else if (name.equals(StringPool.BLANK)) {
3051                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
3052                            }
3053                            else {
3054                                    bindName = true;
3055    
3056                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
3057                            }
3058    
3059                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
3060    
3061                            boolean bindPrimKey = false;
3062    
3063                            if (primKey == null) {
3064                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
3065                            }
3066                            else if (primKey.equals(StringPool.BLANK)) {
3067                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
3068                            }
3069                            else {
3070                                    bindPrimKey = true;
3071    
3072                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
3073                            }
3074    
3075                            String sql = query.toString();
3076    
3077                            Session session = null;
3078    
3079                            try {
3080                                    session = openSession();
3081    
3082                                    Query q = session.createQuery(sql);
3083    
3084                                    QueryPos qPos = QueryPos.getInstance(q);
3085    
3086                                    qPos.add(companyId);
3087    
3088                                    if (bindName) {
3089                                            qPos.add(name);
3090                                    }
3091    
3092                                    qPos.add(scope);
3093    
3094                                    if (bindPrimKey) {
3095                                            qPos.add(primKey);
3096                                    }
3097    
3098                                    count = (Long)q.uniqueResult();
3099    
3100                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3101                            }
3102                            catch (Exception e) {
3103                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3104    
3105                                    throw processException(e);
3106                            }
3107                            finally {
3108                                    closeSession(session);
3109                            }
3110                    }
3111    
3112                    return count.intValue();
3113            }
3114    
3115            private static final String _FINDER_COLUMN_C_N_S_P_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3116            private static final String _FINDER_COLUMN_C_N_S_P_NAME_1 = "resourcePermission.name IS NULL AND ";
3117            private static final String _FINDER_COLUMN_C_N_S_P_NAME_2 = "resourcePermission.name = ? AND ";
3118            private static final String _FINDER_COLUMN_C_N_S_P_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = '') AND ";
3119            private static final String _FINDER_COLUMN_C_N_S_P_SCOPE_2 = "resourcePermission.scope = ? AND ";
3120            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_1 = "resourcePermission.primKey IS NULL";
3121            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_2 = "resourcePermission.primKey = ?";
3122            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = '')";
3123            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R =
3124                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3125                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3126                            ResourcePermissionImpl.class,
3127                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P_R",
3128                            new String[] {
3129                                    Long.class.getName(), String.class.getName(),
3130                                    Integer.class.getName(), String.class.getName(),
3131                                    Long.class.getName(),
3132                                    
3133                            Integer.class.getName(), Integer.class.getName(),
3134                                    OrderByComparator.class.getName()
3135                            });
3136            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R =
3137                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3138                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3139                            ResourcePermissionImpl.class,
3140                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P_R",
3141                            new String[] {
3142                                    Long.class.getName(), String.class.getName(),
3143                                    Integer.class.getName(), String.class.getName(),
3144                                    Long.class.getName()
3145                            },
3146                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
3147                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
3148                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
3149                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
3150                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
3151            public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3152                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
3153                            ResourcePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
3154                            "fetchByC_N_S_P_R",
3155                            new String[] {
3156                                    Long.class.getName(), String.class.getName(),
3157                                    Integer.class.getName(), String.class.getName(),
3158                                    Long.class.getName()
3159                            },
3160                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
3161                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
3162                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
3163                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
3164                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
3165            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3166                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3167                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R",
3168                            new String[] {
3169                                    Long.class.getName(), String.class.getName(),
3170                                    Integer.class.getName(), String.class.getName(),
3171                                    Long.class.getName()
3172                            });
3173            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R =
3174                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3175                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
3176                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_N_S_P_R",
3177                            new String[] {
3178                                    Long.class.getName(), String.class.getName(),
3179                                    Integer.class.getName(), String.class.getName(),
3180                                    Long.class.getName()
3181                            });
3182    
3183            /**
3184             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
3185             *
3186             * <p>
3187             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3188             * </p>
3189             *
3190             * @param companyId the company ID
3191             * @param name the name
3192             * @param scope the scope
3193             * @param primKey the prim key
3194             * @param roleIds the role IDs
3195             * @return the matching resource permissions
3196             */
3197            @Override
3198            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3199                    String name, int scope, String primKey, long[] roleIds) {
3200                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds,
3201                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3202            }
3203    
3204            /**
3205             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
3206             *
3207             * <p>
3208             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3209             * </p>
3210             *
3211             * @param companyId the company ID
3212             * @param name the name
3213             * @param scope the scope
3214             * @param primKey the prim key
3215             * @param roleIds the role IDs
3216             * @param start the lower bound of the range of resource permissions
3217             * @param end the upper bound of the range of resource permissions (not inclusive)
3218             * @return the range of matching resource permissions
3219             */
3220            @Override
3221            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3222                    String name, int scope, String primKey, long[] roleIds, int start,
3223                    int end) {
3224                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds, start,
3225                            end, null);
3226            }
3227    
3228            /**
3229             * 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;.
3230             *
3231             * <p>
3232             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
3233             * </p>
3234             *
3235             * @param companyId the company ID
3236             * @param name the name
3237             * @param scope the scope
3238             * @param primKey the prim key
3239             * @param roleIds the role IDs
3240             * @param start the lower bound of the range of resource permissions
3241             * @param end the upper bound of the range of resource permissions (not inclusive)
3242             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3243             * @return the ordered range of matching resource permissions
3244             */
3245            @Override
3246            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3247                    String name, int scope, String primKey, long[] roleIds, int start,
3248                    int end, OrderByComparator<ResourcePermission> orderByComparator) {
3249                    if (roleIds == null) {
3250                            roleIds = new long[0];
3251                    }
3252                    else {
3253                            roleIds = ArrayUtil.unique(roleIds);
3254                    }
3255    
3256                    if (roleIds.length == 1) {
3257                            ResourcePermission resourcePermission = fetchByC_N_S_P_R(companyId,
3258                                            name, scope, primKey, roleIds[0]);
3259    
3260                            if (resourcePermission == null) {
3261                                    return Collections.emptyList();
3262                            }
3263                            else {
3264                                    List<ResourcePermission> list = new ArrayList<ResourcePermission>(1);
3265    
3266                                    list.add(resourcePermission);
3267    
3268                                    return list;
3269                            }
3270                    }
3271    
3272                    boolean pagination = true;
3273                    Object[] finderArgs = null;
3274    
3275                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3276                                    (orderByComparator == null)) {
3277                            pagination = false;
3278                            finderArgs = new Object[] {
3279                                            companyId, name, scope, primKey, StringUtil.merge(roleIds)
3280                                    };
3281                    }
3282                    else {
3283                            finderArgs = new Object[] {
3284                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
3285                                            
3286                                            start, end, orderByComparator
3287                                    };
3288                    }
3289    
3290                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R,
3291                                    finderArgs, this);
3292    
3293                    if ((list != null) && !list.isEmpty()) {
3294                            for (ResourcePermission resourcePermission : list) {
3295                                    if ((companyId != resourcePermission.getCompanyId()) ||
3296                                                    !Validator.equals(name, resourcePermission.getName()) ||
3297                                                    (scope != resourcePermission.getScope()) ||
3298                                                    !Validator.equals(primKey,
3299                                                            resourcePermission.getPrimKey()) ||
3300                                                    !ArrayUtil.contains(roleIds,
3301                                                            resourcePermission.getRoleId())) {
3302                                            list = null;
3303    
3304                                            break;
3305                                    }
3306                            }
3307                    }
3308    
3309                    if (list == null) {
3310                            StringBundler query = new StringBundler();
3311    
3312                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3313    
3314                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
3315    
3316                            boolean bindName = false;
3317    
3318                            if (name == null) {
3319                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
3320                            }
3321                            else if (name.equals(StringPool.BLANK)) {
3322                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
3323                            }
3324                            else {
3325                                    bindName = true;
3326    
3327                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
3328                            }
3329    
3330                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
3331    
3332                            boolean bindPrimKey = false;
3333    
3334                            if (primKey == null) {
3335                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
3336                            }
3337                            else if (primKey.equals(StringPool.BLANK)) {
3338                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
3339                            }
3340                            else {
3341                                    bindPrimKey = true;
3342    
3343                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
3344                            }
3345    
3346                            if (roleIds.length > 0) {
3347                                    query.append(StringPool.OPEN_PARENTHESIS);
3348    
3349                                    query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_7);
3350    
3351                                    query.append(StringUtil.merge(roleIds));
3352    
3353                                    query.append(StringPool.CLOSE_PARENTHESIS);
3354    
3355                                    query.append(StringPool.CLOSE_PARENTHESIS);
3356                            }
3357    
3358                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3359                                                    1)), query.index() - 1);
3360    
3361                            if (orderByComparator != null) {
3362                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3363                                            orderByComparator);
3364                            }
3365                            else
3366                             if (pagination) {
3367                                    query.append(ResourcePermissionModelImpl.ORDER_BY_JPQL);
3368                            }
3369    
3370                            String sql = query.toString();
3371    
3372                            Session session = null;
3373    
3374                            try {
3375                                    session = openSession();
3376    
3377                                    Query q = session.createQuery(sql);
3378    
3379                                    QueryPos qPos = QueryPos.getInstance(q);
3380    
3381                                    qPos.add(companyId);
3382    
3383                                    if (bindName) {
3384                                            qPos.add(name);
3385                                    }
3386    
3387                                    qPos.add(scope);
3388    
3389                                    if (bindPrimKey) {
3390                                            qPos.add(primKey);
3391                                    }
3392    
3393                                    if (!pagination) {
3394                                            list = (List<ResourcePermission>)QueryUtil.list(q,
3395                                                            getDialect(), start, end, false);
3396    
3397                                            Collections.sort(list);
3398    
3399                                            list = Collections.unmodifiableList(list);
3400                                    }
3401                                    else {
3402                                            list = (List<ResourcePermission>)QueryUtil.list(q,
3403                                                            getDialect(), start, end);
3404                                    }
3405    
3406                                    cacheResult(list);
3407    
3408                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R,
3409                                            finderArgs, list);
3410                            }
3411                            catch (Exception e) {
3412                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R,
3413                                            finderArgs);
3414    
3415                                    throw processException(e);
3416                            }
3417                            finally {
3418                                    closeSession(session);
3419                            }
3420                    }
3421    
3422                    return list;
3423            }
3424    
3425            /**
3426             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; or throws a {@link NoSuchResourcePermissionException} if it could not be found.
3427             *
3428             * @param companyId the company ID
3429             * @param name the name
3430             * @param scope the scope
3431             * @param primKey the prim key
3432             * @param roleId the role ID
3433             * @return the matching resource permission
3434             * @throws NoSuchResourcePermissionException if a matching resource permission could not be found
3435             */
3436            @Override
3437            public ResourcePermission findByC_N_S_P_R(long companyId, String name,
3438                    int scope, String primKey, long roleId)
3439                    throws NoSuchResourcePermissionException {
3440                    ResourcePermission resourcePermission = fetchByC_N_S_P_R(companyId,
3441                                    name, scope, primKey, roleId);
3442    
3443                    if (resourcePermission == null) {
3444                            StringBundler msg = new StringBundler(12);
3445    
3446                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3447    
3448                            msg.append("companyId=");
3449                            msg.append(companyId);
3450    
3451                            msg.append(", name=");
3452                            msg.append(name);
3453    
3454                            msg.append(", scope=");
3455                            msg.append(scope);
3456    
3457                            msg.append(", primKey=");
3458                            msg.append(primKey);
3459    
3460                            msg.append(", roleId=");
3461                            msg.append(roleId);
3462    
3463                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3464    
3465                            if (_log.isWarnEnabled()) {
3466                                    _log.warn(msg.toString());
3467                            }
3468    
3469                            throw new NoSuchResourcePermissionException(msg.toString());
3470                    }
3471    
3472                    return resourcePermission;
3473            }
3474    
3475            /**
3476             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
3477             *
3478             * @param companyId the company ID
3479             * @param name the name
3480             * @param scope the scope
3481             * @param primKey the prim key
3482             * @param roleId the role ID
3483             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
3484             */
3485            @Override
3486            public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
3487                    int scope, String primKey, long roleId) {
3488                    return fetchByC_N_S_P_R(companyId, name, scope, primKey, roleId, true);
3489            }
3490    
3491            /**
3492             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
3493             *
3494             * @param companyId the company ID
3495             * @param name the name
3496             * @param scope the scope
3497             * @param primKey the prim key
3498             * @param roleId the role ID
3499             * @param retrieveFromCache whether to use the finder cache
3500             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
3501             */
3502            @Override
3503            public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
3504                    int scope, String primKey, long roleId, boolean retrieveFromCache) {
3505                    Object[] finderArgs = new Object[] {
3506                                    companyId, name, scope, primKey, roleId
3507                            };
3508    
3509                    Object result = null;
3510    
3511                    if (retrieveFromCache) {
3512                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
3513                                            finderArgs, this);
3514                    }
3515    
3516                    if (result instanceof ResourcePermission) {
3517                            ResourcePermission resourcePermission = (ResourcePermission)result;
3518    
3519                            if ((companyId != resourcePermission.getCompanyId()) ||
3520                                            !Validator.equals(name, resourcePermission.getName()) ||
3521                                            (scope != resourcePermission.getScope()) ||
3522                                            !Validator.equals(primKey, resourcePermission.getPrimKey()) ||
3523                                            (roleId != resourcePermission.getRoleId())) {
3524                                    result = null;
3525                            }
3526                    }
3527    
3528                    if (result == null) {
3529                            StringBundler query = new StringBundler(7);
3530    
3531                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3532    
3533                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
3534    
3535                            boolean bindName = false;
3536    
3537                            if (name == null) {
3538                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
3539                            }
3540                            else if (name.equals(StringPool.BLANK)) {
3541                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
3542                            }
3543                            else {
3544                                    bindName = true;
3545    
3546                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
3547                            }
3548    
3549                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
3550    
3551                            boolean bindPrimKey = false;
3552    
3553                            if (primKey == null) {
3554                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
3555                            }
3556                            else if (primKey.equals(StringPool.BLANK)) {
3557                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
3558                            }
3559                            else {
3560                                    bindPrimKey = true;
3561    
3562                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
3563                            }
3564    
3565                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
3566    
3567                            String sql = query.toString();
3568    
3569                            Session session = null;
3570    
3571                            try {
3572                                    session = openSession();
3573    
3574                                    Query q = session.createQuery(sql);
3575    
3576                                    QueryPos qPos = QueryPos.getInstance(q);
3577    
3578                                    qPos.add(companyId);
3579    
3580                                    if (bindName) {
3581                                            qPos.add(name);
3582                                    }
3583    
3584                                    qPos.add(scope);
3585    
3586                                    if (bindPrimKey) {
3587                                            qPos.add(primKey);
3588                                    }
3589    
3590                                    qPos.add(roleId);
3591    
3592                                    List<ResourcePermission> list = q.list();
3593    
3594                                    if (list.isEmpty()) {
3595                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
3596                                                    finderArgs, list);
3597                                    }
3598                                    else {
3599                                            ResourcePermission resourcePermission = list.get(0);
3600    
3601                                            result = resourcePermission;
3602    
3603                                            cacheResult(resourcePermission);
3604    
3605                                            if ((resourcePermission.getCompanyId() != companyId) ||
3606                                                            (resourcePermission.getName() == null) ||
3607                                                            !resourcePermission.getName().equals(name) ||
3608                                                            (resourcePermission.getScope() != scope) ||
3609                                                            (resourcePermission.getPrimKey() == null) ||
3610                                                            !resourcePermission.getPrimKey().equals(primKey) ||
3611                                                            (resourcePermission.getRoleId() != roleId)) {
3612                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
3613                                                            finderArgs, resourcePermission);
3614                                            }
3615                                    }
3616                            }
3617                            catch (Exception e) {
3618                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
3619                                            finderArgs);
3620    
3621                                    throw processException(e);
3622                            }
3623                            finally {
3624                                    closeSession(session);
3625                            }
3626                    }
3627    
3628                    if (result instanceof List<?>) {
3629                            return null;
3630                    }
3631                    else {
3632                            return (ResourcePermission)result;
3633                    }
3634            }
3635    
3636            /**
3637             * Removes the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; from the database.
3638             *
3639             * @param companyId the company ID
3640             * @param name the name
3641             * @param scope the scope
3642             * @param primKey the prim key
3643             * @param roleId the role ID
3644             * @return the resource permission that was removed
3645             */
3646            @Override
3647            public ResourcePermission removeByC_N_S_P_R(long companyId, String name,
3648                    int scope, String primKey, long roleId)
3649                    throws NoSuchResourcePermissionException {
3650                    ResourcePermission resourcePermission = findByC_N_S_P_R(companyId,
3651                                    name, scope, primKey, roleId);
3652    
3653                    return remove(resourcePermission);
3654            }
3655    
3656            /**
3657             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3658             *
3659             * @param companyId the company ID
3660             * @param name the name
3661             * @param scope the scope
3662             * @param primKey the prim key
3663             * @param roleId the role ID
3664             * @return the number of matching resource permissions
3665             */
3666            @Override
3667            public int countByC_N_S_P_R(long companyId, String name, int scope,
3668                    String primKey, long roleId) {
3669                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N_S_P_R;
3670    
3671                    Object[] finderArgs = new Object[] {
3672                                    companyId, name, scope, primKey, roleId
3673                            };
3674    
3675                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3676                                    this);
3677    
3678                    if (count == null) {
3679                            StringBundler query = new StringBundler(6);
3680    
3681                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
3682    
3683                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
3684    
3685                            boolean bindName = false;
3686    
3687                            if (name == null) {
3688                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
3689                            }
3690                            else if (name.equals(StringPool.BLANK)) {
3691                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
3692                            }
3693                            else {
3694                                    bindName = true;
3695    
3696                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
3697                            }
3698    
3699                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
3700    
3701                            boolean bindPrimKey = false;
3702    
3703                            if (primKey == null) {
3704                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
3705                            }
3706                            else if (primKey.equals(StringPool.BLANK)) {
3707                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
3708                            }
3709                            else {
3710                                    bindPrimKey = true;
3711    
3712                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
3713                            }
3714    
3715                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
3716    
3717                            String sql = query.toString();
3718    
3719                            Session session = null;
3720    
3721                            try {
3722                                    session = openSession();
3723    
3724                                    Query q = session.createQuery(sql);
3725    
3726                                    QueryPos qPos = QueryPos.getInstance(q);
3727    
3728                                    qPos.add(companyId);
3729    
3730                                    if (bindName) {
3731                                            qPos.add(name);
3732                                    }
3733    
3734                                    qPos.add(scope);
3735    
3736                                    if (bindPrimKey) {
3737                                            qPos.add(primKey);
3738                                    }
3739    
3740                                    qPos.add(roleId);
3741    
3742                                    count = (Long)q.uniqueResult();
3743    
3744                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3745                            }
3746                            catch (Exception e) {
3747                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3748    
3749                                    throw processException(e);
3750                            }
3751                            finally {
3752                                    closeSession(session);
3753                            }
3754                    }
3755    
3756                    return count.intValue();
3757            }
3758    
3759            /**
3760             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
3761             *
3762             * @param companyId the company ID
3763             * @param name the name
3764             * @param scope the scope
3765             * @param primKey the prim key
3766             * @param roleIds the role IDs
3767             * @return the number of matching resource permissions
3768             */
3769            @Override
3770            public int countByC_N_S_P_R(long companyId, String name, int scope,
3771                    String primKey, long[] roleIds) {
3772                    if (roleIds == null) {
3773                            roleIds = new long[0];
3774                    }
3775                    else {
3776                            roleIds = ArrayUtil.unique(roleIds);
3777                    }
3778    
3779                    Object[] finderArgs = new Object[] {
3780                                    companyId, name, scope, primKey, StringUtil.merge(roleIds)
3781                            };
3782    
3783                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R,
3784                                    finderArgs, this);
3785    
3786                    if (count == null) {
3787                            StringBundler query = new StringBundler();
3788    
3789                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
3790    
3791                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
3792    
3793                            boolean bindName = false;
3794    
3795                            if (name == null) {
3796                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
3797                            }
3798                            else if (name.equals(StringPool.BLANK)) {
3799                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
3800                            }
3801                            else {
3802                                    bindName = true;
3803    
3804                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
3805                            }
3806    
3807                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
3808    
3809                            boolean bindPrimKey = false;
3810    
3811                            if (primKey == null) {
3812                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
3813                            }
3814                            else if (primKey.equals(StringPool.BLANK)) {
3815                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
3816                            }
3817                            else {
3818                                    bindPrimKey = true;
3819    
3820                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
3821                            }
3822    
3823                            if (roleIds.length > 0) {
3824                                    query.append(StringPool.OPEN_PARENTHESIS);
3825    
3826                                    query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_7);
3827    
3828                                    query.append(StringUtil.merge(roleIds));
3829    
3830                                    query.append(StringPool.CLOSE_PARENTHESIS);
3831    
3832                                    query.append(StringPool.CLOSE_PARENTHESIS);
3833                            }
3834    
3835                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3836                                                    1)), query.index() - 1);
3837    
3838                            String sql = query.toString();
3839    
3840                            Session session = null;
3841    
3842                            try {
3843                                    session = openSession();
3844    
3845                                    Query q = session.createQuery(sql);
3846    
3847                                    QueryPos qPos = QueryPos.getInstance(q);
3848    
3849                                    qPos.add(companyId);
3850    
3851                                    if (bindName) {
3852                                            qPos.add(name);
3853                                    }
3854    
3855                                    qPos.add(scope);
3856    
3857                                    if (bindPrimKey) {
3858                                            qPos.add(primKey);
3859                                    }
3860    
3861                                    count = (Long)q.uniqueResult();
3862    
3863                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R,
3864                                            finderArgs, count);
3865                            }
3866                            catch (Exception e) {
3867                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_N_S_P_R,
3868                                            finderArgs);
3869    
3870                                    throw processException(e);
3871                            }
3872                            finally {
3873                                    closeSession(session);
3874                            }
3875                    }
3876    
3877                    return count.intValue();
3878            }
3879    
3880            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
3881            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_1 = "resourcePermission.name IS NULL AND ";
3882            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_2 = "resourcePermission.name = ? AND ";
3883            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = '') AND ";
3884            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_2 = "resourcePermission.scope = ? AND ";
3885            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
3886            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
3887            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = '') AND ";
3888            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_2 = "resourcePermission.roleId = ?";
3889            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_7 = "resourcePermission.roleId IN (";
3890    
3891            public ResourcePermissionPersistenceImpl() {
3892                    setModelClass(ResourcePermission.class);
3893            }
3894    
3895            /**
3896             * Caches the resource permission in the entity cache if it is enabled.
3897             *
3898             * @param resourcePermission the resource permission
3899             */
3900            @Override
3901            public void cacheResult(ResourcePermission resourcePermission) {
3902                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3903                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
3904                            resourcePermission);
3905    
3906                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
3907                            new Object[] {
3908                                    resourcePermission.getCompanyId(), resourcePermission.getName(),
3909                                    resourcePermission.getScope(), resourcePermission.getPrimKey(),
3910                                    resourcePermission.getRoleId()
3911                            }, resourcePermission);
3912    
3913                    resourcePermission.resetOriginalValues();
3914            }
3915    
3916            /**
3917             * Caches the resource permissions in the entity cache if it is enabled.
3918             *
3919             * @param resourcePermissions the resource permissions
3920             */
3921            @Override
3922            public void cacheResult(List<ResourcePermission> resourcePermissions) {
3923                    for (ResourcePermission resourcePermission : resourcePermissions) {
3924                            if (EntityCacheUtil.getResult(
3925                                                    ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3926                                                    ResourcePermissionImpl.class,
3927                                                    resourcePermission.getPrimaryKey()) == null) {
3928                                    cacheResult(resourcePermission);
3929                            }
3930                            else {
3931                                    resourcePermission.resetOriginalValues();
3932                            }
3933                    }
3934            }
3935    
3936            /**
3937             * Clears the cache for all resource permissions.
3938             *
3939             * <p>
3940             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3941             * </p>
3942             */
3943            @Override
3944            public void clearCache() {
3945                    EntityCacheUtil.clearCache(ResourcePermissionImpl.class);
3946    
3947                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3948                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3949                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3950            }
3951    
3952            /**
3953             * Clears the cache for the resource permission.
3954             *
3955             * <p>
3956             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3957             * </p>
3958             */
3959            @Override
3960            public void clearCache(ResourcePermission resourcePermission) {
3961                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3962                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
3963    
3964                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3965                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3966    
3967                    clearUniqueFindersCache(resourcePermission);
3968            }
3969    
3970            @Override
3971            public void clearCache(List<ResourcePermission> resourcePermissions) {
3972                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3973                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3974    
3975                    for (ResourcePermission resourcePermission : resourcePermissions) {
3976                            EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
3977                                    ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
3978    
3979                            clearUniqueFindersCache(resourcePermission);
3980                    }
3981            }
3982    
3983            protected void cacheUniqueFindersCache(
3984                    ResourcePermission resourcePermission) {
3985                    if (resourcePermission.isNew()) {
3986                            Object[] args = new Object[] {
3987                                            resourcePermission.getCompanyId(),
3988                                            resourcePermission.getName(), resourcePermission.getScope(),
3989                                            resourcePermission.getPrimKey(),
3990                                            resourcePermission.getRoleId()
3991                                    };
3992    
3993                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R, args,
3994                                    Long.valueOf(1));
3995                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R, args,
3996                                    resourcePermission);
3997                    }
3998                    else {
3999                            ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
4000    
4001                            if ((resourcePermissionModelImpl.getColumnBitmask() &
4002                                            FINDER_PATH_FETCH_BY_C_N_S_P_R.getColumnBitmask()) != 0) {
4003                                    Object[] args = new Object[] {
4004                                                    resourcePermission.getCompanyId(),
4005                                                    resourcePermission.getName(),
4006                                                    resourcePermission.getScope(),
4007                                                    resourcePermission.getPrimKey(),
4008                                                    resourcePermission.getRoleId()
4009                                            };
4010    
4011                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R, args,
4012                                            Long.valueOf(1));
4013                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R, args,
4014                                            resourcePermission);
4015                            }
4016                    }
4017            }
4018    
4019            protected void clearUniqueFindersCache(
4020                    ResourcePermission resourcePermission) {
4021                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
4022    
4023                    Object[] args = new Object[] {
4024                                    resourcePermission.getCompanyId(), resourcePermission.getName(),
4025                                    resourcePermission.getScope(), resourcePermission.getPrimKey(),
4026                                    resourcePermission.getRoleId()
4027                            };
4028    
4029                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R, args);
4030                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R, args);
4031    
4032                    if ((resourcePermissionModelImpl.getColumnBitmask() &
4033                                    FINDER_PATH_FETCH_BY_C_N_S_P_R.getColumnBitmask()) != 0) {
4034                            args = new Object[] {
4035                                            resourcePermissionModelImpl.getOriginalCompanyId(),
4036                                            resourcePermissionModelImpl.getOriginalName(),
4037                                            resourcePermissionModelImpl.getOriginalScope(),
4038                                            resourcePermissionModelImpl.getOriginalPrimKey(),
4039                                            resourcePermissionModelImpl.getOriginalRoleId()
4040                                    };
4041    
4042                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R, args);
4043                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R, args);
4044                    }
4045            }
4046    
4047            /**
4048             * Creates a new resource permission with the primary key. Does not add the resource permission to the database.
4049             *
4050             * @param resourcePermissionId the primary key for the new resource permission
4051             * @return the new resource permission
4052             */
4053            @Override
4054            public ResourcePermission create(long resourcePermissionId) {
4055                    ResourcePermission resourcePermission = new ResourcePermissionImpl();
4056    
4057                    resourcePermission.setNew(true);
4058                    resourcePermission.setPrimaryKey(resourcePermissionId);
4059    
4060                    return resourcePermission;
4061            }
4062    
4063            /**
4064             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
4065             *
4066             * @param resourcePermissionId the primary key of the resource permission
4067             * @return the resource permission that was removed
4068             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4069             */
4070            @Override
4071            public ResourcePermission remove(long resourcePermissionId)
4072                    throws NoSuchResourcePermissionException {
4073                    return remove((Serializable)resourcePermissionId);
4074            }
4075    
4076            /**
4077             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
4078             *
4079             * @param primaryKey the primary key of the resource permission
4080             * @return the resource permission that was removed
4081             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4082             */
4083            @Override
4084            public ResourcePermission remove(Serializable primaryKey)
4085                    throws NoSuchResourcePermissionException {
4086                    Session session = null;
4087    
4088                    try {
4089                            session = openSession();
4090    
4091                            ResourcePermission resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
4092                                            primaryKey);
4093    
4094                            if (resourcePermission == null) {
4095                                    if (_log.isWarnEnabled()) {
4096                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4097                                    }
4098    
4099                                    throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4100                                            primaryKey);
4101                            }
4102    
4103                            return remove(resourcePermission);
4104                    }
4105                    catch (NoSuchResourcePermissionException nsee) {
4106                            throw nsee;
4107                    }
4108                    catch (Exception e) {
4109                            throw processException(e);
4110                    }
4111                    finally {
4112                            closeSession(session);
4113                    }
4114            }
4115    
4116            @Override
4117            protected ResourcePermission removeImpl(
4118                    ResourcePermission resourcePermission) {
4119                    resourcePermission = toUnwrappedModel(resourcePermission);
4120    
4121                    Session session = null;
4122    
4123                    try {
4124                            session = openSession();
4125    
4126                            if (!session.contains(resourcePermission)) {
4127                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
4128                                                    resourcePermission.getPrimaryKeyObj());
4129                            }
4130    
4131                            if (resourcePermission != null) {
4132                                    session.delete(resourcePermission);
4133                            }
4134                    }
4135                    catch (Exception e) {
4136                            throw processException(e);
4137                    }
4138                    finally {
4139                            closeSession(session);
4140                    }
4141    
4142                    if (resourcePermission != null) {
4143                            clearCache(resourcePermission);
4144                    }
4145    
4146                    return resourcePermission;
4147            }
4148    
4149            @Override
4150            public ResourcePermission updateImpl(ResourcePermission resourcePermission) {
4151                    resourcePermission = toUnwrappedModel(resourcePermission);
4152    
4153                    boolean isNew = resourcePermission.isNew();
4154    
4155                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
4156    
4157                    Session session = null;
4158    
4159                    try {
4160                            session = openSession();
4161    
4162                            if (resourcePermission.isNew()) {
4163                                    session.save(resourcePermission);
4164    
4165                                    resourcePermission.setNew(false);
4166                            }
4167                            else {
4168                                    session.merge(resourcePermission);
4169                            }
4170                    }
4171                    catch (Exception e) {
4172                            throw processException(e);
4173                    }
4174                    finally {
4175                            closeSession(session);
4176                    }
4177    
4178                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4179    
4180                    if (isNew || !ResourcePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
4181                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4182                    }
4183    
4184                    else {
4185                            if ((resourcePermissionModelImpl.getColumnBitmask() &
4186                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE.getColumnBitmask()) != 0) {
4187                                    Object[] args = new Object[] {
4188                                                    resourcePermissionModelImpl.getOriginalScope()
4189                                            };
4190    
4191                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SCOPE, args);
4192                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE,
4193                                            args);
4194    
4195                                    args = new Object[] { resourcePermissionModelImpl.getScope() };
4196    
4197                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SCOPE, args);
4198                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE,
4199                                            args);
4200                            }
4201    
4202                            if ((resourcePermissionModelImpl.getColumnBitmask() &
4203                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
4204                                    Object[] args = new Object[] {
4205                                                    resourcePermissionModelImpl.getOriginalRoleId()
4206                                            };
4207    
4208                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
4209                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
4210                                            args);
4211    
4212                                    args = new Object[] { resourcePermissionModelImpl.getRoleId() };
4213    
4214                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
4215                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
4216                                            args);
4217                            }
4218    
4219                            if ((resourcePermissionModelImpl.getColumnBitmask() &
4220                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S.getColumnBitmask()) != 0) {
4221                                    Object[] args = new Object[] {
4222                                                    resourcePermissionModelImpl.getOriginalCompanyId(),
4223                                                    resourcePermissionModelImpl.getOriginalName(),
4224                                                    resourcePermissionModelImpl.getOriginalScope()
4225                                            };
4226    
4227                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
4228                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S,
4229                                            args);
4230    
4231                                    args = new Object[] {
4232                                                    resourcePermissionModelImpl.getCompanyId(),
4233                                                    resourcePermissionModelImpl.getName(),
4234                                                    resourcePermissionModelImpl.getScope()
4235                                            };
4236    
4237                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
4238                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S,
4239                                            args);
4240                            }
4241    
4242                            if ((resourcePermissionModelImpl.getColumnBitmask() &
4243                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P.getColumnBitmask()) != 0) {
4244                                    Object[] args = new Object[] {
4245                                                    resourcePermissionModelImpl.getOriginalCompanyId(),
4246                                                    resourcePermissionModelImpl.getOriginalName(),
4247                                                    resourcePermissionModelImpl.getOriginalScope(),
4248                                                    resourcePermissionModelImpl.getOriginalPrimKey()
4249                                            };
4250    
4251                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P, args);
4252                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P,
4253                                            args);
4254    
4255                                    args = new Object[] {
4256                                                    resourcePermissionModelImpl.getCompanyId(),
4257                                                    resourcePermissionModelImpl.getName(),
4258                                                    resourcePermissionModelImpl.getScope(),
4259                                                    resourcePermissionModelImpl.getPrimKey()
4260                                            };
4261    
4262                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P, args);
4263                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P,
4264                                            args);
4265                            }
4266    
4267                            if ((resourcePermissionModelImpl.getColumnBitmask() &
4268                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R.getColumnBitmask()) != 0) {
4269                                    Object[] args = new Object[] {
4270                                                    resourcePermissionModelImpl.getOriginalCompanyId(),
4271                                                    resourcePermissionModelImpl.getOriginalName(),
4272                                                    resourcePermissionModelImpl.getOriginalScope(),
4273                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
4274                                                    resourcePermissionModelImpl.getOriginalRoleId()
4275                                            };
4276    
4277                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
4278                                            args);
4279                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R,
4280                                            args);
4281    
4282                                    args = new Object[] {
4283                                                    resourcePermissionModelImpl.getCompanyId(),
4284                                                    resourcePermissionModelImpl.getName(),
4285                                                    resourcePermissionModelImpl.getScope(),
4286                                                    resourcePermissionModelImpl.getPrimKey(),
4287                                                    resourcePermissionModelImpl.getRoleId()
4288                                            };
4289    
4290                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
4291                                            args);
4292                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R,
4293                                            args);
4294                            }
4295                    }
4296    
4297                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4298                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
4299                            resourcePermission, false);
4300    
4301                    clearUniqueFindersCache(resourcePermission);
4302                    cacheUniqueFindersCache(resourcePermission);
4303    
4304                    resourcePermission.resetOriginalValues();
4305    
4306                    return resourcePermission;
4307            }
4308    
4309            protected ResourcePermission toUnwrappedModel(
4310                    ResourcePermission resourcePermission) {
4311                    if (resourcePermission instanceof ResourcePermissionImpl) {
4312                            return resourcePermission;
4313                    }
4314    
4315                    ResourcePermissionImpl resourcePermissionImpl = new ResourcePermissionImpl();
4316    
4317                    resourcePermissionImpl.setNew(resourcePermission.isNew());
4318                    resourcePermissionImpl.setPrimaryKey(resourcePermission.getPrimaryKey());
4319    
4320                    resourcePermissionImpl.setMvccVersion(resourcePermission.getMvccVersion());
4321                    resourcePermissionImpl.setResourcePermissionId(resourcePermission.getResourcePermissionId());
4322                    resourcePermissionImpl.setCompanyId(resourcePermission.getCompanyId());
4323                    resourcePermissionImpl.setName(resourcePermission.getName());
4324                    resourcePermissionImpl.setScope(resourcePermission.getScope());
4325                    resourcePermissionImpl.setPrimKey(resourcePermission.getPrimKey());
4326                    resourcePermissionImpl.setRoleId(resourcePermission.getRoleId());
4327                    resourcePermissionImpl.setOwnerId(resourcePermission.getOwnerId());
4328                    resourcePermissionImpl.setActionIds(resourcePermission.getActionIds());
4329    
4330                    return resourcePermissionImpl;
4331            }
4332    
4333            /**
4334             * Returns the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
4335             *
4336             * @param primaryKey the primary key of the resource permission
4337             * @return the resource permission
4338             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4339             */
4340            @Override
4341            public ResourcePermission findByPrimaryKey(Serializable primaryKey)
4342                    throws NoSuchResourcePermissionException {
4343                    ResourcePermission resourcePermission = fetchByPrimaryKey(primaryKey);
4344    
4345                    if (resourcePermission == null) {
4346                            if (_log.isWarnEnabled()) {
4347                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4348                            }
4349    
4350                            throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4351                                    primaryKey);
4352                    }
4353    
4354                    return resourcePermission;
4355            }
4356    
4357            /**
4358             * Returns the resource permission with the primary key or throws a {@link NoSuchResourcePermissionException} if it could not be found.
4359             *
4360             * @param resourcePermissionId the primary key of the resource permission
4361             * @return the resource permission
4362             * @throws NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4363             */
4364            @Override
4365            public ResourcePermission findByPrimaryKey(long resourcePermissionId)
4366                    throws NoSuchResourcePermissionException {
4367                    return findByPrimaryKey((Serializable)resourcePermissionId);
4368            }
4369    
4370            /**
4371             * Returns the resource permission with the primary key or returns <code>null</code> if it could not be found.
4372             *
4373             * @param primaryKey the primary key of the resource permission
4374             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
4375             */
4376            @Override
4377            public ResourcePermission fetchByPrimaryKey(Serializable primaryKey) {
4378                    ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4379                                    ResourcePermissionImpl.class, primaryKey);
4380    
4381                    if (resourcePermission == _nullResourcePermission) {
4382                            return null;
4383                    }
4384    
4385                    if (resourcePermission == null) {
4386                            Session session = null;
4387    
4388                            try {
4389                                    session = openSession();
4390    
4391                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
4392                                                    primaryKey);
4393    
4394                                    if (resourcePermission != null) {
4395                                            cacheResult(resourcePermission);
4396                                    }
4397                                    else {
4398                                            EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4399                                                    ResourcePermissionImpl.class, primaryKey,
4400                                                    _nullResourcePermission);
4401                                    }
4402                            }
4403                            catch (Exception e) {
4404                                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4405                                            ResourcePermissionImpl.class, primaryKey);
4406    
4407                                    throw processException(e);
4408                            }
4409                            finally {
4410                                    closeSession(session);
4411                            }
4412                    }
4413    
4414                    return resourcePermission;
4415            }
4416    
4417            /**
4418             * Returns the resource permission with the primary key or returns <code>null</code> if it could not be found.
4419             *
4420             * @param resourcePermissionId the primary key of the resource permission
4421             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
4422             */
4423            @Override
4424            public ResourcePermission fetchByPrimaryKey(long resourcePermissionId) {
4425                    return fetchByPrimaryKey((Serializable)resourcePermissionId);
4426            }
4427    
4428            @Override
4429            public Map<Serializable, ResourcePermission> fetchByPrimaryKeys(
4430                    Set<Serializable> primaryKeys) {
4431                    if (primaryKeys.isEmpty()) {
4432                            return Collections.emptyMap();
4433                    }
4434    
4435                    Map<Serializable, ResourcePermission> map = new HashMap<Serializable, ResourcePermission>();
4436    
4437                    if (primaryKeys.size() == 1) {
4438                            Iterator<Serializable> iterator = primaryKeys.iterator();
4439    
4440                            Serializable primaryKey = iterator.next();
4441    
4442                            ResourcePermission resourcePermission = fetchByPrimaryKey(primaryKey);
4443    
4444                            if (resourcePermission != null) {
4445                                    map.put(primaryKey, resourcePermission);
4446                            }
4447    
4448                            return map;
4449                    }
4450    
4451                    Set<Serializable> uncachedPrimaryKeys = null;
4452    
4453                    for (Serializable primaryKey : primaryKeys) {
4454                            ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4455                                            ResourcePermissionImpl.class, primaryKey);
4456    
4457                            if (resourcePermission == null) {
4458                                    if (uncachedPrimaryKeys == null) {
4459                                            uncachedPrimaryKeys = new HashSet<Serializable>();
4460                                    }
4461    
4462                                    uncachedPrimaryKeys.add(primaryKey);
4463                            }
4464                            else {
4465                                    map.put(primaryKey, resourcePermission);
4466                            }
4467                    }
4468    
4469                    if (uncachedPrimaryKeys == null) {
4470                            return map;
4471                    }
4472    
4473                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
4474                                    1);
4475    
4476                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE_PKS_IN);
4477    
4478                    for (Serializable primaryKey : uncachedPrimaryKeys) {
4479                            query.append(String.valueOf(primaryKey));
4480    
4481                            query.append(StringPool.COMMA);
4482                    }
4483    
4484                    query.setIndex(query.index() - 1);
4485    
4486                    query.append(StringPool.CLOSE_PARENTHESIS);
4487    
4488                    String sql = query.toString();
4489    
4490                    Session session = null;
4491    
4492                    try {
4493                            session = openSession();
4494    
4495                            Query q = session.createQuery(sql);
4496    
4497                            for (ResourcePermission resourcePermission : (List<ResourcePermission>)q.list()) {
4498                                    map.put(resourcePermission.getPrimaryKeyObj(),
4499                                            resourcePermission);
4500    
4501                                    cacheResult(resourcePermission);
4502    
4503                                    uncachedPrimaryKeys.remove(resourcePermission.getPrimaryKeyObj());
4504                            }
4505    
4506                            for (Serializable primaryKey : uncachedPrimaryKeys) {
4507                                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
4508                                            ResourcePermissionImpl.class, primaryKey,
4509                                            _nullResourcePermission);
4510                            }
4511                    }
4512                    catch (Exception e) {
4513                            throw processException(e);
4514                    }
4515                    finally {
4516                            closeSession(session);
4517                    }
4518    
4519                    return map;
4520            }
4521    
4522            /**
4523             * Returns all the resource permissions.
4524             *
4525             * @return the resource permissions
4526             */
4527            @Override
4528            public List<ResourcePermission> findAll() {
4529                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4530            }
4531    
4532            /**
4533             * Returns a range of all the resource permissions.
4534             *
4535             * <p>
4536             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4537             * </p>
4538             *
4539             * @param start the lower bound of the range of resource permissions
4540             * @param end the upper bound of the range of resource permissions (not inclusive)
4541             * @return the range of resource permissions
4542             */
4543            @Override
4544            public List<ResourcePermission> findAll(int start, int end) {
4545                    return findAll(start, end, null);
4546            }
4547    
4548            /**
4549             * Returns an ordered range of all the resource permissions.
4550             *
4551             * <p>
4552             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
4553             * </p>
4554             *
4555             * @param start the lower bound of the range of resource permissions
4556             * @param end the upper bound of the range of resource permissions (not inclusive)
4557             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4558             * @return the ordered range of resource permissions
4559             */
4560            @Override
4561            public List<ResourcePermission> findAll(int start, int end,
4562                    OrderByComparator<ResourcePermission> orderByComparator) {
4563                    boolean pagination = true;
4564                    FinderPath finderPath = null;
4565                    Object[] finderArgs = null;
4566    
4567                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4568                                    (orderByComparator == null)) {
4569                            pagination = false;
4570                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4571                            finderArgs = FINDER_ARGS_EMPTY;
4572                    }
4573                    else {
4574                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4575                            finderArgs = new Object[] { start, end, orderByComparator };
4576                    }
4577    
4578                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
4579                                    finderArgs, this);
4580    
4581                    if (list == null) {
4582                            StringBundler query = null;
4583                            String sql = null;
4584    
4585                            if (orderByComparator != null) {
4586                                    query = new StringBundler(2 +
4587                                                    (orderByComparator.getOrderByFields().length * 3));
4588    
4589                                    query.append(_SQL_SELECT_RESOURCEPERMISSION);
4590    
4591                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4592                                            orderByComparator);
4593    
4594                                    sql = query.toString();
4595                            }
4596                            else {
4597                                    sql = _SQL_SELECT_RESOURCEPERMISSION;
4598    
4599                                    if (pagination) {
4600                                            sql = sql.concat(ResourcePermissionModelImpl.ORDER_BY_JPQL);
4601                                    }
4602                            }
4603    
4604                            Session session = null;
4605    
4606                            try {
4607                                    session = openSession();
4608    
4609                                    Query q = session.createQuery(sql);
4610    
4611                                    if (!pagination) {
4612                                            list = (List<ResourcePermission>)QueryUtil.list(q,
4613                                                            getDialect(), start, end, false);
4614    
4615                                            Collections.sort(list);
4616    
4617                                            list = Collections.unmodifiableList(list);
4618                                    }
4619                                    else {
4620                                            list = (List<ResourcePermission>)QueryUtil.list(q,
4621                                                            getDialect(), start, end);
4622                                    }
4623    
4624                                    cacheResult(list);
4625    
4626                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4627                            }
4628                            catch (Exception e) {
4629                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4630    
4631                                    throw processException(e);
4632                            }
4633                            finally {
4634                                    closeSession(session);
4635                            }
4636                    }
4637    
4638                    return list;
4639            }
4640    
4641            /**
4642             * Removes all the resource permissions from the database.
4643             *
4644             */
4645            @Override
4646            public void removeAll() {
4647                    for (ResourcePermission resourcePermission : findAll()) {
4648                            remove(resourcePermission);
4649                    }
4650            }
4651    
4652            /**
4653             * Returns the number of resource permissions.
4654             *
4655             * @return the number of resource permissions
4656             */
4657            @Override
4658            public int countAll() {
4659                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4660                                    FINDER_ARGS_EMPTY, this);
4661    
4662                    if (count == null) {
4663                            Session session = null;
4664    
4665                            try {
4666                                    session = openSession();
4667    
4668                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEPERMISSION);
4669    
4670                                    count = (Long)q.uniqueResult();
4671    
4672                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4673                                            FINDER_ARGS_EMPTY, count);
4674                            }
4675                            catch (Exception e) {
4676                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4677                                            FINDER_ARGS_EMPTY);
4678    
4679                                    throw processException(e);
4680                            }
4681                            finally {
4682                                    closeSession(session);
4683                            }
4684                    }
4685    
4686                    return count.intValue();
4687            }
4688    
4689            /**
4690             * Initializes the resource permission persistence.
4691             */
4692            public void afterPropertiesSet() {
4693            }
4694    
4695            public void destroy() {
4696                    EntityCacheUtil.removeCache(ResourcePermissionImpl.class.getName());
4697                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4698                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4699                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4700            }
4701    
4702            private static final String _SQL_SELECT_RESOURCEPERMISSION = "SELECT resourcePermission FROM ResourcePermission resourcePermission";
4703            private static final String _SQL_SELECT_RESOURCEPERMISSION_WHERE_PKS_IN = "SELECT resourcePermission FROM ResourcePermission resourcePermission WHERE resourcePermissionId IN (";
4704            private static final String _SQL_SELECT_RESOURCEPERMISSION_WHERE = "SELECT resourcePermission FROM ResourcePermission resourcePermission WHERE ";
4705            private static final String _SQL_COUNT_RESOURCEPERMISSION = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission";
4706            private static final String _SQL_COUNT_RESOURCEPERMISSION_WHERE = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission WHERE ";
4707            private static final String _ORDER_BY_ENTITY_ALIAS = "resourcePermission.";
4708            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourcePermission exists with the primary key ";
4709            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourcePermission exists with the key {";
4710            private static final Log _log = LogFactoryUtil.getLog(ResourcePermissionPersistenceImpl.class);
4711            private static final ResourcePermission _nullResourcePermission = new ResourcePermissionImpl() {
4712                            @Override
4713                            public Object clone() {
4714                                    return this;
4715                            }
4716    
4717                            @Override
4718                            public CacheModel<ResourcePermission> toCacheModel() {
4719                                    return _nullResourcePermissionCacheModel;
4720                            }
4721                    };
4722    
4723            private static final CacheModel<ResourcePermission> _nullResourcePermissionCacheModel =
4724                    new NullCacheModel();
4725    
4726            private static class NullCacheModel implements CacheModel<ResourcePermission>,
4727                    MVCCModel {
4728                    @Override
4729                    public long getMvccVersion() {
4730                            return -1;
4731                    }
4732    
4733                    @Override
4734                    public void setMvccVersion(long mvccVersion) {
4735                    }
4736    
4737                    @Override
4738                    public ResourcePermission toEntityModel() {
4739                            return _nullResourcePermission;
4740                    }
4741            }
4742    }