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