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.NoSuchResourceBlockPermissionException;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.StringBundler;
031    import com.liferay.portal.kernel.util.StringPool;
032    import com.liferay.portal.model.CacheModel;
033    import com.liferay.portal.model.MVCCModel;
034    import com.liferay.portal.model.ResourceBlockPermission;
035    import com.liferay.portal.model.impl.ResourceBlockPermissionImpl;
036    import com.liferay.portal.model.impl.ResourceBlockPermissionModelImpl;
037    import com.liferay.portal.service.persistence.ResourceBlockPermissionPersistence;
038    
039    import java.io.Serializable;
040    
041    import java.util.Collections;
042    import java.util.HashMap;
043    import java.util.HashSet;
044    import java.util.Iterator;
045    import java.util.List;
046    import java.util.Map;
047    import java.util.Set;
048    
049    /**
050     * The persistence implementation for the resource block permission service.
051     *
052     * <p>
053     * Caching information and settings can be found in <code>portal.properties</code>
054     * </p>
055     *
056     * @author Brian Wing Shun Chan
057     * @see ResourceBlockPermissionPersistence
058     * @see com.liferay.portal.service.persistence.ResourceBlockPermissionUtil
059     * @generated
060     */
061    @ProviderType
062    public class ResourceBlockPermissionPersistenceImpl extends BasePersistenceImpl<ResourceBlockPermission>
063            implements ResourceBlockPermissionPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link ResourceBlockPermissionUtil} to access the resource block permission persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockPermissionImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
075                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
076                            ResourceBlockPermissionImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
079                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
080                            ResourceBlockPermissionImpl.class,
081                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
083                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
084                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID =
086                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
087                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
088                            ResourceBlockPermissionImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByResourceBlockId",
090                            new String[] {
091                                    Long.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID =
097                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
098                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
099                            ResourceBlockPermissionImpl.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourceBlockId",
101                            new String[] { Long.class.getName() },
102                            ResourceBlockPermissionModelImpl.RESOURCEBLOCKID_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEBLOCKID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
104                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
106                            "countByResourceBlockId", new String[] { Long.class.getName() });
107    
108            /**
109             * Returns all the resource block permissions where resourceBlockId = &#63;.
110             *
111             * @param resourceBlockId the resource block ID
112             * @return the matching resource block permissions
113             */
114            @Override
115            public List<ResourceBlockPermission> findByResourceBlockId(
116                    long resourceBlockId) {
117                    return findByResourceBlockId(resourceBlockId, QueryUtil.ALL_POS,
118                            QueryUtil.ALL_POS, null);
119            }
120    
121            /**
122             * Returns a range of all the resource block permissions where resourceBlockId = &#63;.
123             *
124             * <p>
125             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ResourceBlockPermissionModelImpl}. 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.
126             * </p>
127             *
128             * @param resourceBlockId the resource block ID
129             * @param start the lower bound of the range of resource block permissions
130             * @param end the upper bound of the range of resource block permissions (not inclusive)
131             * @return the range of matching resource block permissions
132             */
133            @Override
134            public List<ResourceBlockPermission> findByResourceBlockId(
135                    long resourceBlockId, int start, int end) {
136                    return findByResourceBlockId(resourceBlockId, start, end, null);
137            }
138    
139            /**
140             * Returns an ordered range of all the resource block permissions where resourceBlockId = &#63;.
141             *
142             * <p>
143             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ResourceBlockPermissionModelImpl}. 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.
144             * </p>
145             *
146             * @param resourceBlockId the resource block ID
147             * @param start the lower bound of the range of resource block permissions
148             * @param end the upper bound of the range of resource block permissions (not inclusive)
149             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
150             * @return the ordered range of matching resource block permissions
151             */
152            @Override
153            public List<ResourceBlockPermission> findByResourceBlockId(
154                    long resourceBlockId, int start, int end,
155                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
156                    boolean pagination = true;
157                    FinderPath finderPath = null;
158                    Object[] finderArgs = null;
159    
160                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161                                    (orderByComparator == null)) {
162                            pagination = false;
163                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID;
164                            finderArgs = new Object[] { resourceBlockId };
165                    }
166                    else {
167                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID;
168                            finderArgs = new Object[] {
169                                            resourceBlockId,
170                                            
171                                            start, end, orderByComparator
172                                    };
173                    }
174    
175                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (ResourceBlockPermission resourceBlockPermission : list) {
180                                    if ((resourceBlockId != resourceBlockPermission.getResourceBlockId())) {
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_RESOURCEBLOCKPERMISSION_WHERE);
200    
201                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
202    
203                            if (orderByComparator != null) {
204                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
205                                            orderByComparator);
206                            }
207                            else
208                             if (pagination) {
209                                    query.append(ResourceBlockPermissionModelImpl.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(resourceBlockId);
224    
225                                    if (!pagination) {
226                                            list = (List<ResourceBlockPermission>)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<ResourceBlockPermission>)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 block permission in the ordered set where resourceBlockId = &#63;.
257             *
258             * @param resourceBlockId the resource block ID
259             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
260             * @return the first matching resource block permission
261             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
262             */
263            @Override
264            public ResourceBlockPermission findByResourceBlockId_First(
265                    long resourceBlockId,
266                    OrderByComparator<ResourceBlockPermission> orderByComparator)
267                    throws NoSuchResourceBlockPermissionException {
268                    ResourceBlockPermission resourceBlockPermission = fetchByResourceBlockId_First(resourceBlockId,
269                                    orderByComparator);
270    
271                    if (resourceBlockPermission != null) {
272                            return resourceBlockPermission;
273                    }
274    
275                    StringBundler msg = new StringBundler(4);
276    
277                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278    
279                    msg.append("resourceBlockId=");
280                    msg.append(resourceBlockId);
281    
282                    msg.append(StringPool.CLOSE_CURLY_BRACE);
283    
284                    throw new NoSuchResourceBlockPermissionException(msg.toString());
285            }
286    
287            /**
288             * Returns the first resource block permission in the ordered set where resourceBlockId = &#63;.
289             *
290             * @param resourceBlockId the resource block ID
291             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
292             * @return the first matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
293             */
294            @Override
295            public ResourceBlockPermission fetchByResourceBlockId_First(
296                    long resourceBlockId,
297                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
298                    List<ResourceBlockPermission> list = findByResourceBlockId(resourceBlockId,
299                                    0, 1, orderByComparator);
300    
301                    if (!list.isEmpty()) {
302                            return list.get(0);
303                    }
304    
305                    return null;
306            }
307    
308            /**
309             * Returns the last resource block permission in the ordered set where resourceBlockId = &#63;.
310             *
311             * @param resourceBlockId the resource block ID
312             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
313             * @return the last matching resource block permission
314             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
315             */
316            @Override
317            public ResourceBlockPermission findByResourceBlockId_Last(
318                    long resourceBlockId,
319                    OrderByComparator<ResourceBlockPermission> orderByComparator)
320                    throws NoSuchResourceBlockPermissionException {
321                    ResourceBlockPermission resourceBlockPermission = fetchByResourceBlockId_Last(resourceBlockId,
322                                    orderByComparator);
323    
324                    if (resourceBlockPermission != null) {
325                            return resourceBlockPermission;
326                    }
327    
328                    StringBundler msg = new StringBundler(4);
329    
330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
331    
332                    msg.append("resourceBlockId=");
333                    msg.append(resourceBlockId);
334    
335                    msg.append(StringPool.CLOSE_CURLY_BRACE);
336    
337                    throw new NoSuchResourceBlockPermissionException(msg.toString());
338            }
339    
340            /**
341             * Returns the last resource block permission in the ordered set where resourceBlockId = &#63;.
342             *
343             * @param resourceBlockId the resource block ID
344             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
345             * @return the last matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
346             */
347            @Override
348            public ResourceBlockPermission fetchByResourceBlockId_Last(
349                    long resourceBlockId,
350                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
351                    int count = countByResourceBlockId(resourceBlockId);
352    
353                    if (count == 0) {
354                            return null;
355                    }
356    
357                    List<ResourceBlockPermission> list = findByResourceBlockId(resourceBlockId,
358                                    count - 1, count, orderByComparator);
359    
360                    if (!list.isEmpty()) {
361                            return list.get(0);
362                    }
363    
364                    return null;
365            }
366    
367            /**
368             * Returns the resource block permissions before and after the current resource block permission in the ordered set where resourceBlockId = &#63;.
369             *
370             * @param resourceBlockPermissionId the primary key of the current resource block permission
371             * @param resourceBlockId the resource block ID
372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
373             * @return the previous, current, and next resource block permission
374             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
375             */
376            @Override
377            public ResourceBlockPermission[] findByResourceBlockId_PrevAndNext(
378                    long resourceBlockPermissionId, long resourceBlockId,
379                    OrderByComparator<ResourceBlockPermission> orderByComparator)
380                    throws NoSuchResourceBlockPermissionException {
381                    ResourceBlockPermission resourceBlockPermission = findByPrimaryKey(resourceBlockPermissionId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            ResourceBlockPermission[] array = new ResourceBlockPermissionImpl[3];
389    
390                            array[0] = getByResourceBlockId_PrevAndNext(session,
391                                            resourceBlockPermission, resourceBlockId,
392                                            orderByComparator, true);
393    
394                            array[1] = resourceBlockPermission;
395    
396                            array[2] = getByResourceBlockId_PrevAndNext(session,
397                                            resourceBlockPermission, resourceBlockId,
398                                            orderByComparator, false);
399    
400                            return array;
401                    }
402                    catch (Exception e) {
403                            throw processException(e);
404                    }
405                    finally {
406                            closeSession(session);
407                    }
408            }
409    
410            protected ResourceBlockPermission getByResourceBlockId_PrevAndNext(
411                    Session session, ResourceBlockPermission resourceBlockPermission,
412                    long resourceBlockId,
413                    OrderByComparator<ResourceBlockPermission> orderByComparator,
414                    boolean previous) {
415                    StringBundler query = null;
416    
417                    if (orderByComparator != null) {
418                            query = new StringBundler(6 +
419                                            (orderByComparator.getOrderByFields().length * 6));
420                    }
421                    else {
422                            query = new StringBundler(3);
423                    }
424    
425                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
426    
427                    query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
428    
429                    if (orderByComparator != null) {
430                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
431    
432                            if (orderByConditionFields.length > 0) {
433                                    query.append(WHERE_AND);
434                            }
435    
436                            for (int i = 0; i < orderByConditionFields.length; i++) {
437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
438                                    query.append(orderByConditionFields[i]);
439    
440                                    if ((i + 1) < orderByConditionFields.length) {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
443                                            }
444                                            else {
445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
446                                            }
447                                    }
448                                    else {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(WHERE_GREATER_THAN);
451                                            }
452                                            else {
453                                                    query.append(WHERE_LESSER_THAN);
454                                            }
455                                    }
456                            }
457    
458                            query.append(ORDER_BY_CLAUSE);
459    
460                            String[] orderByFields = orderByComparator.getOrderByFields();
461    
462                            for (int i = 0; i < orderByFields.length; i++) {
463                                    query.append(_ORDER_BY_ENTITY_ALIAS);
464                                    query.append(orderByFields[i]);
465    
466                                    if ((i + 1) < orderByFields.length) {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
469                                            }
470                                            else {
471                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
472                                            }
473                                    }
474                                    else {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(ORDER_BY_ASC);
477                                            }
478                                            else {
479                                                    query.append(ORDER_BY_DESC);
480                                            }
481                                    }
482                            }
483                    }
484                    else {
485                            query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
486                    }
487    
488                    String sql = query.toString();
489    
490                    Query q = session.createQuery(sql);
491    
492                    q.setFirstResult(0);
493                    q.setMaxResults(2);
494    
495                    QueryPos qPos = QueryPos.getInstance(q);
496    
497                    qPos.add(resourceBlockId);
498    
499                    if (orderByComparator != null) {
500                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlockPermission);
501    
502                            for (Object value : values) {
503                                    qPos.add(value);
504                            }
505                    }
506    
507                    List<ResourceBlockPermission> list = q.list();
508    
509                    if (list.size() == 2) {
510                            return list.get(1);
511                    }
512                    else {
513                            return null;
514                    }
515            }
516    
517            /**
518             * Removes all the resource block permissions where resourceBlockId = &#63; from the database.
519             *
520             * @param resourceBlockId the resource block ID
521             */
522            @Override
523            public void removeByResourceBlockId(long resourceBlockId) {
524                    for (ResourceBlockPermission resourceBlockPermission : findByResourceBlockId(
525                                    resourceBlockId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
526                            remove(resourceBlockPermission);
527                    }
528            }
529    
530            /**
531             * Returns the number of resource block permissions where resourceBlockId = &#63;.
532             *
533             * @param resourceBlockId the resource block ID
534             * @return the number of matching resource block permissions
535             */
536            @Override
537            public int countByResourceBlockId(long resourceBlockId) {
538                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RESOURCEBLOCKID;
539    
540                    Object[] finderArgs = new Object[] { resourceBlockId };
541    
542                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
543                                    this);
544    
545                    if (count == null) {
546                            StringBundler query = new StringBundler(2);
547    
548                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
549    
550                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
551    
552                            String sql = query.toString();
553    
554                            Session session = null;
555    
556                            try {
557                                    session = openSession();
558    
559                                    Query q = session.createQuery(sql);
560    
561                                    QueryPos qPos = QueryPos.getInstance(q);
562    
563                                    qPos.add(resourceBlockId);
564    
565                                    count = (Long)q.uniqueResult();
566    
567                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
568                            }
569                            catch (Exception e) {
570                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
571    
572                                    throw processException(e);
573                            }
574                            finally {
575                                    closeSession(session);
576                            }
577                    }
578    
579                    return count.intValue();
580            }
581    
582            private static final String _FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2 =
583                    "resourceBlockPermission.resourceBlockId = ?";
584            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
585                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
586                            ResourceBlockPermissionImpl.class,
587                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
588                            new String[] {
589                                    Long.class.getName(),
590                                    
591                            Integer.class.getName(), Integer.class.getName(),
592                                    OrderByComparator.class.getName()
593                            });
594            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
595                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
596                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
597                            ResourceBlockPermissionImpl.class,
598                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
599                            new String[] { Long.class.getName() },
600                            ResourceBlockPermissionModelImpl.ROLEID_COLUMN_BITMASK);
601            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
602                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
603                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
604                            new String[] { Long.class.getName() });
605    
606            /**
607             * Returns all the resource block permissions where roleId = &#63;.
608             *
609             * @param roleId the role ID
610             * @return the matching resource block permissions
611             */
612            @Override
613            public List<ResourceBlockPermission> findByRoleId(long roleId) {
614                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
615            }
616    
617            /**
618             * Returns a range of all the resource block permissions where roleId = &#63;.
619             *
620             * <p>
621             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ResourceBlockPermissionModelImpl}. 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.
622             * </p>
623             *
624             * @param roleId the role ID
625             * @param start the lower bound of the range of resource block permissions
626             * @param end the upper bound of the range of resource block permissions (not inclusive)
627             * @return the range of matching resource block permissions
628             */
629            @Override
630            public List<ResourceBlockPermission> findByRoleId(long roleId, int start,
631                    int end) {
632                    return findByRoleId(roleId, start, end, null);
633            }
634    
635            /**
636             * Returns an ordered range of all the resource block permissions where roleId = &#63;.
637             *
638             * <p>
639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ResourceBlockPermissionModelImpl}. 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.
640             * </p>
641             *
642             * @param roleId the role ID
643             * @param start the lower bound of the range of resource block permissions
644             * @param end the upper bound of the range of resource block permissions (not inclusive)
645             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
646             * @return the ordered range of matching resource block permissions
647             */
648            @Override
649            public List<ResourceBlockPermission> findByRoleId(long roleId, int start,
650                    int end, OrderByComparator<ResourceBlockPermission> orderByComparator) {
651                    boolean pagination = true;
652                    FinderPath finderPath = null;
653                    Object[] finderArgs = null;
654    
655                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
656                                    (orderByComparator == null)) {
657                            pagination = false;
658                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
659                            finderArgs = new Object[] { roleId };
660                    }
661                    else {
662                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
663                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
664                    }
665    
666                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
667                                    finderArgs, this);
668    
669                    if ((list != null) && !list.isEmpty()) {
670                            for (ResourceBlockPermission resourceBlockPermission : list) {
671                                    if ((roleId != resourceBlockPermission.getRoleId())) {
672                                            list = null;
673    
674                                            break;
675                                    }
676                            }
677                    }
678    
679                    if (list == null) {
680                            StringBundler query = null;
681    
682                            if (orderByComparator != null) {
683                                    query = new StringBundler(3 +
684                                                    (orderByComparator.getOrderByFields().length * 3));
685                            }
686                            else {
687                                    query = new StringBundler(3);
688                            }
689    
690                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
691    
692                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
693    
694                            if (orderByComparator != null) {
695                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
696                                            orderByComparator);
697                            }
698                            else
699                             if (pagination) {
700                                    query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
701                            }
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(roleId);
715    
716                                    if (!pagination) {
717                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
718                                                            getDialect(), start, end, false);
719    
720                                            Collections.sort(list);
721    
722                                            list = Collections.unmodifiableList(list);
723                                    }
724                                    else {
725                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
726                                                            getDialect(), start, end);
727                                    }
728    
729                                    cacheResult(list);
730    
731                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
732                            }
733                            catch (Exception e) {
734                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
735    
736                                    throw processException(e);
737                            }
738                            finally {
739                                    closeSession(session);
740                            }
741                    }
742    
743                    return list;
744            }
745    
746            /**
747             * Returns the first resource block permission in the ordered set where roleId = &#63;.
748             *
749             * @param roleId the role ID
750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
751             * @return the first matching resource block permission
752             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
753             */
754            @Override
755            public ResourceBlockPermission findByRoleId_First(long roleId,
756                    OrderByComparator<ResourceBlockPermission> orderByComparator)
757                    throws NoSuchResourceBlockPermissionException {
758                    ResourceBlockPermission resourceBlockPermission = fetchByRoleId_First(roleId,
759                                    orderByComparator);
760    
761                    if (resourceBlockPermission != null) {
762                            return resourceBlockPermission;
763                    }
764    
765                    StringBundler msg = new StringBundler(4);
766    
767                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
768    
769                    msg.append("roleId=");
770                    msg.append(roleId);
771    
772                    msg.append(StringPool.CLOSE_CURLY_BRACE);
773    
774                    throw new NoSuchResourceBlockPermissionException(msg.toString());
775            }
776    
777            /**
778             * Returns the first resource block permission in the ordered set where roleId = &#63;.
779             *
780             * @param roleId the role ID
781             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
782             * @return the first matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
783             */
784            @Override
785            public ResourceBlockPermission fetchByRoleId_First(long roleId,
786                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
787                    List<ResourceBlockPermission> list = findByRoleId(roleId, 0, 1,
788                                    orderByComparator);
789    
790                    if (!list.isEmpty()) {
791                            return list.get(0);
792                    }
793    
794                    return null;
795            }
796    
797            /**
798             * Returns the last resource block permission in the ordered set where roleId = &#63;.
799             *
800             * @param roleId the role ID
801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
802             * @return the last matching resource block permission
803             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
804             */
805            @Override
806            public ResourceBlockPermission findByRoleId_Last(long roleId,
807                    OrderByComparator<ResourceBlockPermission> orderByComparator)
808                    throws NoSuchResourceBlockPermissionException {
809                    ResourceBlockPermission resourceBlockPermission = fetchByRoleId_Last(roleId,
810                                    orderByComparator);
811    
812                    if (resourceBlockPermission != null) {
813                            return resourceBlockPermission;
814                    }
815    
816                    StringBundler msg = new StringBundler(4);
817    
818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
819    
820                    msg.append("roleId=");
821                    msg.append(roleId);
822    
823                    msg.append(StringPool.CLOSE_CURLY_BRACE);
824    
825                    throw new NoSuchResourceBlockPermissionException(msg.toString());
826            }
827    
828            /**
829             * Returns the last resource block permission in the ordered set where roleId = &#63;.
830             *
831             * @param roleId the role ID
832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
833             * @return the last matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
834             */
835            @Override
836            public ResourceBlockPermission fetchByRoleId_Last(long roleId,
837                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
838                    int count = countByRoleId(roleId);
839    
840                    if (count == 0) {
841                            return null;
842                    }
843    
844                    List<ResourceBlockPermission> list = findByRoleId(roleId, count - 1,
845                                    count, orderByComparator);
846    
847                    if (!list.isEmpty()) {
848                            return list.get(0);
849                    }
850    
851                    return null;
852            }
853    
854            /**
855             * Returns the resource block permissions before and after the current resource block permission in the ordered set where roleId = &#63;.
856             *
857             * @param resourceBlockPermissionId the primary key of the current resource block permission
858             * @param roleId the role ID
859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
860             * @return the previous, current, and next resource block permission
861             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
862             */
863            @Override
864            public ResourceBlockPermission[] findByRoleId_PrevAndNext(
865                    long resourceBlockPermissionId, long roleId,
866                    OrderByComparator<ResourceBlockPermission> orderByComparator)
867                    throws NoSuchResourceBlockPermissionException {
868                    ResourceBlockPermission resourceBlockPermission = findByPrimaryKey(resourceBlockPermissionId);
869    
870                    Session session = null;
871    
872                    try {
873                            session = openSession();
874    
875                            ResourceBlockPermission[] array = new ResourceBlockPermissionImpl[3];
876    
877                            array[0] = getByRoleId_PrevAndNext(session,
878                                            resourceBlockPermission, roleId, orderByComparator, true);
879    
880                            array[1] = resourceBlockPermission;
881    
882                            array[2] = getByRoleId_PrevAndNext(session,
883                                            resourceBlockPermission, roleId, orderByComparator, false);
884    
885                            return array;
886                    }
887                    catch (Exception e) {
888                            throw processException(e);
889                    }
890                    finally {
891                            closeSession(session);
892                    }
893            }
894    
895            protected ResourceBlockPermission getByRoleId_PrevAndNext(Session session,
896                    ResourceBlockPermission resourceBlockPermission, long roleId,
897                    OrderByComparator<ResourceBlockPermission> orderByComparator,
898                    boolean previous) {
899                    StringBundler query = null;
900    
901                    if (orderByComparator != null) {
902                            query = new StringBundler(6 +
903                                            (orderByComparator.getOrderByFields().length * 6));
904                    }
905                    else {
906                            query = new StringBundler(3);
907                    }
908    
909                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
910    
911                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
912    
913                    if (orderByComparator != null) {
914                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
915    
916                            if (orderByConditionFields.length > 0) {
917                                    query.append(WHERE_AND);
918                            }
919    
920                            for (int i = 0; i < orderByConditionFields.length; i++) {
921                                    query.append(_ORDER_BY_ENTITY_ALIAS);
922                                    query.append(orderByConditionFields[i]);
923    
924                                    if ((i + 1) < orderByConditionFields.length) {
925                                            if (orderByComparator.isAscending() ^ previous) {
926                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
927                                            }
928                                            else {
929                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
930                                            }
931                                    }
932                                    else {
933                                            if (orderByComparator.isAscending() ^ previous) {
934                                                    query.append(WHERE_GREATER_THAN);
935                                            }
936                                            else {
937                                                    query.append(WHERE_LESSER_THAN);
938                                            }
939                                    }
940                            }
941    
942                            query.append(ORDER_BY_CLAUSE);
943    
944                            String[] orderByFields = orderByComparator.getOrderByFields();
945    
946                            for (int i = 0; i < orderByFields.length; i++) {
947                                    query.append(_ORDER_BY_ENTITY_ALIAS);
948                                    query.append(orderByFields[i]);
949    
950                                    if ((i + 1) < orderByFields.length) {
951                                            if (orderByComparator.isAscending() ^ previous) {
952                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
953                                            }
954                                            else {
955                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
956                                            }
957                                    }
958                                    else {
959                                            if (orderByComparator.isAscending() ^ previous) {
960                                                    query.append(ORDER_BY_ASC);
961                                            }
962                                            else {
963                                                    query.append(ORDER_BY_DESC);
964                                            }
965                                    }
966                            }
967                    }
968                    else {
969                            query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
970                    }
971    
972                    String sql = query.toString();
973    
974                    Query q = session.createQuery(sql);
975    
976                    q.setFirstResult(0);
977                    q.setMaxResults(2);
978    
979                    QueryPos qPos = QueryPos.getInstance(q);
980    
981                    qPos.add(roleId);
982    
983                    if (orderByComparator != null) {
984                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlockPermission);
985    
986                            for (Object value : values) {
987                                    qPos.add(value);
988                            }
989                    }
990    
991                    List<ResourceBlockPermission> list = q.list();
992    
993                    if (list.size() == 2) {
994                            return list.get(1);
995                    }
996                    else {
997                            return null;
998                    }
999            }
1000    
1001            /**
1002             * Removes all the resource block permissions where roleId = &#63; from the database.
1003             *
1004             * @param roleId the role ID
1005             */
1006            @Override
1007            public void removeByRoleId(long roleId) {
1008                    for (ResourceBlockPermission resourceBlockPermission : findByRoleId(
1009                                    roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1010                            remove(resourceBlockPermission);
1011                    }
1012            }
1013    
1014            /**
1015             * Returns the number of resource block permissions where roleId = &#63;.
1016             *
1017             * @param roleId the role ID
1018             * @return the number of matching resource block permissions
1019             */
1020            @Override
1021            public int countByRoleId(long roleId) {
1022                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1023    
1024                    Object[] finderArgs = new Object[] { roleId };
1025    
1026                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1027                                    this);
1028    
1029                    if (count == null) {
1030                            StringBundler query = new StringBundler(2);
1031    
1032                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1033    
1034                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1035    
1036                            String sql = query.toString();
1037    
1038                            Session session = null;
1039    
1040                            try {
1041                                    session = openSession();
1042    
1043                                    Query q = session.createQuery(sql);
1044    
1045                                    QueryPos qPos = QueryPos.getInstance(q);
1046    
1047                                    qPos.add(roleId);
1048    
1049                                    count = (Long)q.uniqueResult();
1050    
1051                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1052                            }
1053                            catch (Exception e) {
1054                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1055    
1056                                    throw processException(e);
1057                            }
1058                            finally {
1059                                    closeSession(session);
1060                            }
1061                    }
1062    
1063                    return count.intValue();
1064            }
1065    
1066            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourceBlockPermission.roleId = ?";
1067            public static final FinderPath FINDER_PATH_FETCH_BY_R_R = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1068                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
1069                            ResourceBlockPermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
1070                            "fetchByR_R",
1071                            new String[] { Long.class.getName(), Long.class.getName() },
1072                            ResourceBlockPermissionModelImpl.RESOURCEBLOCKID_COLUMN_BITMASK |
1073                            ResourceBlockPermissionModelImpl.ROLEID_COLUMN_BITMASK);
1074            public static final FinderPath FINDER_PATH_COUNT_BY_R_R = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1075                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1076                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_R",
1077                            new String[] { Long.class.getName(), Long.class.getName() });
1078    
1079            /**
1080             * Returns the resource block permission where resourceBlockId = &#63; and roleId = &#63; or throws a {@link NoSuchResourceBlockPermissionException} if it could not be found.
1081             *
1082             * @param resourceBlockId the resource block ID
1083             * @param roleId the role ID
1084             * @return the matching resource block permission
1085             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
1086             */
1087            @Override
1088            public ResourceBlockPermission findByR_R(long resourceBlockId, long roleId)
1089                    throws NoSuchResourceBlockPermissionException {
1090                    ResourceBlockPermission resourceBlockPermission = fetchByR_R(resourceBlockId,
1091                                    roleId);
1092    
1093                    if (resourceBlockPermission == null) {
1094                            StringBundler msg = new StringBundler(6);
1095    
1096                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1097    
1098                            msg.append("resourceBlockId=");
1099                            msg.append(resourceBlockId);
1100    
1101                            msg.append(", roleId=");
1102                            msg.append(roleId);
1103    
1104                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1105    
1106                            if (_log.isWarnEnabled()) {
1107                                    _log.warn(msg.toString());
1108                            }
1109    
1110                            throw new NoSuchResourceBlockPermissionException(msg.toString());
1111                    }
1112    
1113                    return resourceBlockPermission;
1114            }
1115    
1116            /**
1117             * Returns the resource block permission where resourceBlockId = &#63; and roleId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1118             *
1119             * @param resourceBlockId the resource block ID
1120             * @param roleId the role ID
1121             * @return the matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
1122             */
1123            @Override
1124            public ResourceBlockPermission fetchByR_R(long resourceBlockId, long roleId) {
1125                    return fetchByR_R(resourceBlockId, roleId, true);
1126            }
1127    
1128            /**
1129             * Returns the resource block permission where resourceBlockId = &#63; and roleId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1130             *
1131             * @param resourceBlockId the resource block ID
1132             * @param roleId the role ID
1133             * @param retrieveFromCache whether to use the finder cache
1134             * @return the matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
1135             */
1136            @Override
1137            public ResourceBlockPermission fetchByR_R(long resourceBlockId,
1138                    long roleId, boolean retrieveFromCache) {
1139                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
1140    
1141                    Object result = null;
1142    
1143                    if (retrieveFromCache) {
1144                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_R,
1145                                            finderArgs, this);
1146                    }
1147    
1148                    if (result instanceof ResourceBlockPermission) {
1149                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)result;
1150    
1151                            if ((resourceBlockId != resourceBlockPermission.getResourceBlockId()) ||
1152                                            (roleId != resourceBlockPermission.getRoleId())) {
1153                                    result = null;
1154                            }
1155                    }
1156    
1157                    if (result == null) {
1158                            StringBundler query = new StringBundler(4);
1159    
1160                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
1161    
1162                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1163    
1164                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1165    
1166                            String sql = query.toString();
1167    
1168                            Session session = null;
1169    
1170                            try {
1171                                    session = openSession();
1172    
1173                                    Query q = session.createQuery(sql);
1174    
1175                                    QueryPos qPos = QueryPos.getInstance(q);
1176    
1177                                    qPos.add(resourceBlockId);
1178    
1179                                    qPos.add(roleId);
1180    
1181                                    List<ResourceBlockPermission> list = q.list();
1182    
1183                                    if (list.isEmpty()) {
1184                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1185                                                    finderArgs, list);
1186                                    }
1187                                    else {
1188                                            ResourceBlockPermission resourceBlockPermission = list.get(0);
1189    
1190                                            result = resourceBlockPermission;
1191    
1192                                            cacheResult(resourceBlockPermission);
1193    
1194                                            if ((resourceBlockPermission.getResourceBlockId() != resourceBlockId) ||
1195                                                            (resourceBlockPermission.getRoleId() != roleId)) {
1196                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1197                                                            finderArgs, resourceBlockPermission);
1198                                            }
1199                                    }
1200                            }
1201                            catch (Exception e) {
1202                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R,
1203                                            finderArgs);
1204    
1205                                    throw processException(e);
1206                            }
1207                            finally {
1208                                    closeSession(session);
1209                            }
1210                    }
1211    
1212                    if (result instanceof List<?>) {
1213                            return null;
1214                    }
1215                    else {
1216                            return (ResourceBlockPermission)result;
1217                    }
1218            }
1219    
1220            /**
1221             * Removes the resource block permission where resourceBlockId = &#63; and roleId = &#63; from the database.
1222             *
1223             * @param resourceBlockId the resource block ID
1224             * @param roleId the role ID
1225             * @return the resource block permission that was removed
1226             */
1227            @Override
1228            public ResourceBlockPermission removeByR_R(long resourceBlockId, long roleId)
1229                    throws NoSuchResourceBlockPermissionException {
1230                    ResourceBlockPermission resourceBlockPermission = findByR_R(resourceBlockId,
1231                                    roleId);
1232    
1233                    return remove(resourceBlockPermission);
1234            }
1235    
1236            /**
1237             * Returns the number of resource block permissions where resourceBlockId = &#63; and roleId = &#63;.
1238             *
1239             * @param resourceBlockId the resource block ID
1240             * @param roleId the role ID
1241             * @return the number of matching resource block permissions
1242             */
1243            @Override
1244            public int countByR_R(long resourceBlockId, long roleId) {
1245                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_R;
1246    
1247                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
1248    
1249                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1250                                    this);
1251    
1252                    if (count == null) {
1253                            StringBundler query = new StringBundler(3);
1254    
1255                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1256    
1257                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1258    
1259                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1260    
1261                            String sql = query.toString();
1262    
1263                            Session session = null;
1264    
1265                            try {
1266                                    session = openSession();
1267    
1268                                    Query q = session.createQuery(sql);
1269    
1270                                    QueryPos qPos = QueryPos.getInstance(q);
1271    
1272                                    qPos.add(resourceBlockId);
1273    
1274                                    qPos.add(roleId);
1275    
1276                                    count = (Long)q.uniqueResult();
1277    
1278                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1279                            }
1280                            catch (Exception e) {
1281                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1282    
1283                                    throw processException(e);
1284                            }
1285                            finally {
1286                                    closeSession(session);
1287                            }
1288                    }
1289    
1290                    return count.intValue();
1291            }
1292    
1293            private static final String _FINDER_COLUMN_R_R_RESOURCEBLOCKID_2 = "resourceBlockPermission.resourceBlockId = ? AND ";
1294            private static final String _FINDER_COLUMN_R_R_ROLEID_2 = "resourceBlockPermission.roleId = ?";
1295    
1296            public ResourceBlockPermissionPersistenceImpl() {
1297                    setModelClass(ResourceBlockPermission.class);
1298            }
1299    
1300            /**
1301             * Caches the resource block permission in the entity cache if it is enabled.
1302             *
1303             * @param resourceBlockPermission the resource block permission
1304             */
1305            @Override
1306            public void cacheResult(ResourceBlockPermission resourceBlockPermission) {
1307                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1308                            ResourceBlockPermissionImpl.class,
1309                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
1310    
1311                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1312                            new Object[] {
1313                                    resourceBlockPermission.getResourceBlockId(),
1314                                    resourceBlockPermission.getRoleId()
1315                            }, resourceBlockPermission);
1316    
1317                    resourceBlockPermission.resetOriginalValues();
1318            }
1319    
1320            /**
1321             * Caches the resource block permissions in the entity cache if it is enabled.
1322             *
1323             * @param resourceBlockPermissions the resource block permissions
1324             */
1325            @Override
1326            public void cacheResult(
1327                    List<ResourceBlockPermission> resourceBlockPermissions) {
1328                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
1329                            if (EntityCacheUtil.getResult(
1330                                                    ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1331                                                    ResourceBlockPermissionImpl.class,
1332                                                    resourceBlockPermission.getPrimaryKey()) == null) {
1333                                    cacheResult(resourceBlockPermission);
1334                            }
1335                            else {
1336                                    resourceBlockPermission.resetOriginalValues();
1337                            }
1338                    }
1339            }
1340    
1341            /**
1342             * Clears the cache for all resource block permissions.
1343             *
1344             * <p>
1345             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1346             * </p>
1347             */
1348            @Override
1349            public void clearCache() {
1350                    EntityCacheUtil.clearCache(ResourceBlockPermissionImpl.class);
1351    
1352                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1353                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1354                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1355            }
1356    
1357            /**
1358             * Clears the cache for the resource block permission.
1359             *
1360             * <p>
1361             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1362             * </p>
1363             */
1364            @Override
1365            public void clearCache(ResourceBlockPermission resourceBlockPermission) {
1366                    EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1367                            ResourceBlockPermissionImpl.class,
1368                            resourceBlockPermission.getPrimaryKey());
1369    
1370                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1371                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1372    
1373                    clearUniqueFindersCache(resourceBlockPermission);
1374            }
1375    
1376            @Override
1377            public void clearCache(
1378                    List<ResourceBlockPermission> resourceBlockPermissions) {
1379                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1380                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1381    
1382                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
1383                            EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1384                                    ResourceBlockPermissionImpl.class,
1385                                    resourceBlockPermission.getPrimaryKey());
1386    
1387                            clearUniqueFindersCache(resourceBlockPermission);
1388                    }
1389            }
1390    
1391            protected void cacheUniqueFindersCache(
1392                    ResourceBlockPermission resourceBlockPermission) {
1393                    if (resourceBlockPermission.isNew()) {
1394                            Object[] args = new Object[] {
1395                                            resourceBlockPermission.getResourceBlockId(),
1396                                            resourceBlockPermission.getRoleId()
1397                                    };
1398    
1399                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, args,
1400                                    Long.valueOf(1));
1401                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R, args,
1402                                    resourceBlockPermission);
1403                    }
1404                    else {
1405                            ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1406    
1407                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1408                                            FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
1409                                    Object[] args = new Object[] {
1410                                                    resourceBlockPermission.getResourceBlockId(),
1411                                                    resourceBlockPermission.getRoleId()
1412                                            };
1413    
1414                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, args,
1415                                            Long.valueOf(1));
1416                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R, args,
1417                                            resourceBlockPermission);
1418                            }
1419                    }
1420            }
1421    
1422            protected void clearUniqueFindersCache(
1423                    ResourceBlockPermission resourceBlockPermission) {
1424                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1425    
1426                    Object[] args = new Object[] {
1427                                    resourceBlockPermission.getResourceBlockId(),
1428                                    resourceBlockPermission.getRoleId()
1429                            };
1430    
1431                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
1432                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
1433    
1434                    if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1435                                    FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
1436                            args = new Object[] {
1437                                            resourceBlockPermissionModelImpl.getOriginalResourceBlockId(),
1438                                            resourceBlockPermissionModelImpl.getOriginalRoleId()
1439                                    };
1440    
1441                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
1442                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
1443                    }
1444            }
1445    
1446            /**
1447             * Creates a new resource block permission with the primary key. Does not add the resource block permission to the database.
1448             *
1449             * @param resourceBlockPermissionId the primary key for the new resource block permission
1450             * @return the new resource block permission
1451             */
1452            @Override
1453            public ResourceBlockPermission create(long resourceBlockPermissionId) {
1454                    ResourceBlockPermission resourceBlockPermission = new ResourceBlockPermissionImpl();
1455    
1456                    resourceBlockPermission.setNew(true);
1457                    resourceBlockPermission.setPrimaryKey(resourceBlockPermissionId);
1458    
1459                    return resourceBlockPermission;
1460            }
1461    
1462            /**
1463             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
1464             *
1465             * @param resourceBlockPermissionId the primary key of the resource block permission
1466             * @return the resource block permission that was removed
1467             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1468             */
1469            @Override
1470            public ResourceBlockPermission remove(long resourceBlockPermissionId)
1471                    throws NoSuchResourceBlockPermissionException {
1472                    return remove((Serializable)resourceBlockPermissionId);
1473            }
1474    
1475            /**
1476             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
1477             *
1478             * @param primaryKey the primary key of the resource block permission
1479             * @return the resource block permission that was removed
1480             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1481             */
1482            @Override
1483            public ResourceBlockPermission remove(Serializable primaryKey)
1484                    throws NoSuchResourceBlockPermissionException {
1485                    Session session = null;
1486    
1487                    try {
1488                            session = openSession();
1489    
1490                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1491                                            primaryKey);
1492    
1493                            if (resourceBlockPermission == null) {
1494                                    if (_log.isWarnEnabled()) {
1495                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1496                                    }
1497    
1498                                    throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1499                                            primaryKey);
1500                            }
1501    
1502                            return remove(resourceBlockPermission);
1503                    }
1504                    catch (NoSuchResourceBlockPermissionException nsee) {
1505                            throw nsee;
1506                    }
1507                    catch (Exception e) {
1508                            throw processException(e);
1509                    }
1510                    finally {
1511                            closeSession(session);
1512                    }
1513            }
1514    
1515            @Override
1516            protected ResourceBlockPermission removeImpl(
1517                    ResourceBlockPermission resourceBlockPermission) {
1518                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
1519    
1520                    Session session = null;
1521    
1522                    try {
1523                            session = openSession();
1524    
1525                            if (!session.contains(resourceBlockPermission)) {
1526                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1527                                                    resourceBlockPermission.getPrimaryKeyObj());
1528                            }
1529    
1530                            if (resourceBlockPermission != null) {
1531                                    session.delete(resourceBlockPermission);
1532                            }
1533                    }
1534                    catch (Exception e) {
1535                            throw processException(e);
1536                    }
1537                    finally {
1538                            closeSession(session);
1539                    }
1540    
1541                    if (resourceBlockPermission != null) {
1542                            clearCache(resourceBlockPermission);
1543                    }
1544    
1545                    return resourceBlockPermission;
1546            }
1547    
1548            @Override
1549            public ResourceBlockPermission updateImpl(
1550                    ResourceBlockPermission resourceBlockPermission) {
1551                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
1552    
1553                    boolean isNew = resourceBlockPermission.isNew();
1554    
1555                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1556    
1557                    Session session = null;
1558    
1559                    try {
1560                            session = openSession();
1561    
1562                            if (resourceBlockPermission.isNew()) {
1563                                    session.save(resourceBlockPermission);
1564    
1565                                    resourceBlockPermission.setNew(false);
1566                            }
1567                            else {
1568                                    session.merge(resourceBlockPermission);
1569                            }
1570                    }
1571                    catch (Exception e) {
1572                            throw processException(e);
1573                    }
1574                    finally {
1575                            closeSession(session);
1576                    }
1577    
1578                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1579    
1580                    if (isNew || !ResourceBlockPermissionModelImpl.COLUMN_BITMASK_ENABLED) {
1581                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1582                    }
1583    
1584                    else {
1585                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1586                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID.getColumnBitmask()) != 0) {
1587                                    Object[] args = new Object[] {
1588                                                    resourceBlockPermissionModelImpl.getOriginalResourceBlockId()
1589                                            };
1590    
1591                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1592                                            args);
1593                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
1594                                            args);
1595    
1596                                    args = new Object[] {
1597                                                    resourceBlockPermissionModelImpl.getResourceBlockId()
1598                                            };
1599    
1600                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1601                                            args);
1602                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
1603                                            args);
1604                            }
1605    
1606                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1607                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1608                                    Object[] args = new Object[] {
1609                                                    resourceBlockPermissionModelImpl.getOriginalRoleId()
1610                                            };
1611    
1612                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1613                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1614                                            args);
1615    
1616                                    args = new Object[] { resourceBlockPermissionModelImpl.getRoleId() };
1617    
1618                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1619                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1620                                            args);
1621                            }
1622                    }
1623    
1624                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1625                            ResourceBlockPermissionImpl.class,
1626                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission,
1627                            false);
1628    
1629                    clearUniqueFindersCache(resourceBlockPermission);
1630                    cacheUniqueFindersCache(resourceBlockPermission);
1631    
1632                    resourceBlockPermission.resetOriginalValues();
1633    
1634                    return resourceBlockPermission;
1635            }
1636    
1637            protected ResourceBlockPermission toUnwrappedModel(
1638                    ResourceBlockPermission resourceBlockPermission) {
1639                    if (resourceBlockPermission instanceof ResourceBlockPermissionImpl) {
1640                            return resourceBlockPermission;
1641                    }
1642    
1643                    ResourceBlockPermissionImpl resourceBlockPermissionImpl = new ResourceBlockPermissionImpl();
1644    
1645                    resourceBlockPermissionImpl.setNew(resourceBlockPermission.isNew());
1646                    resourceBlockPermissionImpl.setPrimaryKey(resourceBlockPermission.getPrimaryKey());
1647    
1648                    resourceBlockPermissionImpl.setMvccVersion(resourceBlockPermission.getMvccVersion());
1649                    resourceBlockPermissionImpl.setResourceBlockPermissionId(resourceBlockPermission.getResourceBlockPermissionId());
1650                    resourceBlockPermissionImpl.setResourceBlockId(resourceBlockPermission.getResourceBlockId());
1651                    resourceBlockPermissionImpl.setRoleId(resourceBlockPermission.getRoleId());
1652                    resourceBlockPermissionImpl.setActionIds(resourceBlockPermission.getActionIds());
1653    
1654                    return resourceBlockPermissionImpl;
1655            }
1656    
1657            /**
1658             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1659             *
1660             * @param primaryKey the primary key of the resource block permission
1661             * @return the resource block permission
1662             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1663             */
1664            @Override
1665            public ResourceBlockPermission findByPrimaryKey(Serializable primaryKey)
1666                    throws NoSuchResourceBlockPermissionException {
1667                    ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(primaryKey);
1668    
1669                    if (resourceBlockPermission == null) {
1670                            if (_log.isWarnEnabled()) {
1671                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1672                            }
1673    
1674                            throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1675                                    primaryKey);
1676                    }
1677    
1678                    return resourceBlockPermission;
1679            }
1680    
1681            /**
1682             * Returns the resource block permission with the primary key or throws a {@link NoSuchResourceBlockPermissionException} if it could not be found.
1683             *
1684             * @param resourceBlockPermissionId the primary key of the resource block permission
1685             * @return the resource block permission
1686             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1687             */
1688            @Override
1689            public ResourceBlockPermission findByPrimaryKey(
1690                    long resourceBlockPermissionId)
1691                    throws NoSuchResourceBlockPermissionException {
1692                    return findByPrimaryKey((Serializable)resourceBlockPermissionId);
1693            }
1694    
1695            /**
1696             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
1697             *
1698             * @param primaryKey the primary key of the resource block permission
1699             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
1700             */
1701            @Override
1702            public ResourceBlockPermission fetchByPrimaryKey(Serializable primaryKey) {
1703                    ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)EntityCacheUtil.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1704                                    ResourceBlockPermissionImpl.class, primaryKey);
1705    
1706                    if (resourceBlockPermission == _nullResourceBlockPermission) {
1707                            return null;
1708                    }
1709    
1710                    if (resourceBlockPermission == null) {
1711                            Session session = null;
1712    
1713                            try {
1714                                    session = openSession();
1715    
1716                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1717                                                    primaryKey);
1718    
1719                                    if (resourceBlockPermission != null) {
1720                                            cacheResult(resourceBlockPermission);
1721                                    }
1722                                    else {
1723                                            EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1724                                                    ResourceBlockPermissionImpl.class, primaryKey,
1725                                                    _nullResourceBlockPermission);
1726                                    }
1727                            }
1728                            catch (Exception e) {
1729                                    EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1730                                            ResourceBlockPermissionImpl.class, primaryKey);
1731    
1732                                    throw processException(e);
1733                            }
1734                            finally {
1735                                    closeSession(session);
1736                            }
1737                    }
1738    
1739                    return resourceBlockPermission;
1740            }
1741    
1742            /**
1743             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
1744             *
1745             * @param resourceBlockPermissionId the primary key of the resource block permission
1746             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
1747             */
1748            @Override
1749            public ResourceBlockPermission fetchByPrimaryKey(
1750                    long resourceBlockPermissionId) {
1751                    return fetchByPrimaryKey((Serializable)resourceBlockPermissionId);
1752            }
1753    
1754            @Override
1755            public Map<Serializable, ResourceBlockPermission> fetchByPrimaryKeys(
1756                    Set<Serializable> primaryKeys) {
1757                    if (primaryKeys.isEmpty()) {
1758                            return Collections.emptyMap();
1759                    }
1760    
1761                    Map<Serializable, ResourceBlockPermission> map = new HashMap<Serializable, ResourceBlockPermission>();
1762    
1763                    if (primaryKeys.size() == 1) {
1764                            Iterator<Serializable> iterator = primaryKeys.iterator();
1765    
1766                            Serializable primaryKey = iterator.next();
1767    
1768                            ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(primaryKey);
1769    
1770                            if (resourceBlockPermission != null) {
1771                                    map.put(primaryKey, resourceBlockPermission);
1772                            }
1773    
1774                            return map;
1775                    }
1776    
1777                    Set<Serializable> uncachedPrimaryKeys = null;
1778    
1779                    for (Serializable primaryKey : primaryKeys) {
1780                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)EntityCacheUtil.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1781                                            ResourceBlockPermissionImpl.class, primaryKey);
1782    
1783                            if (resourceBlockPermission == null) {
1784                                    if (uncachedPrimaryKeys == null) {
1785                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1786                                    }
1787    
1788                                    uncachedPrimaryKeys.add(primaryKey);
1789                            }
1790                            else {
1791                                    map.put(primaryKey, resourceBlockPermission);
1792                            }
1793                    }
1794    
1795                    if (uncachedPrimaryKeys == null) {
1796                            return map;
1797                    }
1798    
1799                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1800                                    1);
1801    
1802                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE_PKS_IN);
1803    
1804                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1805                            query.append(String.valueOf(primaryKey));
1806    
1807                            query.append(StringPool.COMMA);
1808                    }
1809    
1810                    query.setIndex(query.index() - 1);
1811    
1812                    query.append(StringPool.CLOSE_PARENTHESIS);
1813    
1814                    String sql = query.toString();
1815    
1816                    Session session = null;
1817    
1818                    try {
1819                            session = openSession();
1820    
1821                            Query q = session.createQuery(sql);
1822    
1823                            for (ResourceBlockPermission resourceBlockPermission : (List<ResourceBlockPermission>)q.list()) {
1824                                    map.put(resourceBlockPermission.getPrimaryKeyObj(),
1825                                            resourceBlockPermission);
1826    
1827                                    cacheResult(resourceBlockPermission);
1828    
1829                                    uncachedPrimaryKeys.remove(resourceBlockPermission.getPrimaryKeyObj());
1830                            }
1831    
1832                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1833                                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1834                                            ResourceBlockPermissionImpl.class, primaryKey,
1835                                            _nullResourceBlockPermission);
1836                            }
1837                    }
1838                    catch (Exception e) {
1839                            throw processException(e);
1840                    }
1841                    finally {
1842                            closeSession(session);
1843                    }
1844    
1845                    return map;
1846            }
1847    
1848            /**
1849             * Returns all the resource block permissions.
1850             *
1851             * @return the resource block permissions
1852             */
1853            @Override
1854            public List<ResourceBlockPermission> findAll() {
1855                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1856            }
1857    
1858            /**
1859             * Returns a range of all the resource block permissions.
1860             *
1861             * <p>
1862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ResourceBlockPermissionModelImpl}. 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.
1863             * </p>
1864             *
1865             * @param start the lower bound of the range of resource block permissions
1866             * @param end the upper bound of the range of resource block permissions (not inclusive)
1867             * @return the range of resource block permissions
1868             */
1869            @Override
1870            public List<ResourceBlockPermission> findAll(int start, int end) {
1871                    return findAll(start, end, null);
1872            }
1873    
1874            /**
1875             * Returns an ordered range of all the resource block permissions.
1876             *
1877             * <p>
1878             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ResourceBlockPermissionModelImpl}. 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.
1879             * </p>
1880             *
1881             * @param start the lower bound of the range of resource block permissions
1882             * @param end the upper bound of the range of resource block permissions (not inclusive)
1883             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1884             * @return the ordered range of resource block permissions
1885             */
1886            @Override
1887            public List<ResourceBlockPermission> findAll(int start, int end,
1888                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
1889                    boolean pagination = true;
1890                    FinderPath finderPath = null;
1891                    Object[] finderArgs = null;
1892    
1893                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1894                                    (orderByComparator == null)) {
1895                            pagination = false;
1896                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1897                            finderArgs = FINDER_ARGS_EMPTY;
1898                    }
1899                    else {
1900                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1901                            finderArgs = new Object[] { start, end, orderByComparator };
1902                    }
1903    
1904                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
1905                                    finderArgs, this);
1906    
1907                    if (list == null) {
1908                            StringBundler query = null;
1909                            String sql = null;
1910    
1911                            if (orderByComparator != null) {
1912                                    query = new StringBundler(2 +
1913                                                    (orderByComparator.getOrderByFields().length * 3));
1914    
1915                                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION);
1916    
1917                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1918                                            orderByComparator);
1919    
1920                                    sql = query.toString();
1921                            }
1922                            else {
1923                                    sql = _SQL_SELECT_RESOURCEBLOCKPERMISSION;
1924    
1925                                    if (pagination) {
1926                                            sql = sql.concat(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
1927                                    }
1928                            }
1929    
1930                            Session session = null;
1931    
1932                            try {
1933                                    session = openSession();
1934    
1935                                    Query q = session.createQuery(sql);
1936    
1937                                    if (!pagination) {
1938                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1939                                                            getDialect(), start, end, false);
1940    
1941                                            Collections.sort(list);
1942    
1943                                            list = Collections.unmodifiableList(list);
1944                                    }
1945                                    else {
1946                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1947                                                            getDialect(), start, end);
1948                                    }
1949    
1950                                    cacheResult(list);
1951    
1952                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1953                            }
1954                            catch (Exception e) {
1955                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1956    
1957                                    throw processException(e);
1958                            }
1959                            finally {
1960                                    closeSession(session);
1961                            }
1962                    }
1963    
1964                    return list;
1965            }
1966    
1967            /**
1968             * Removes all the resource block permissions from the database.
1969             *
1970             */
1971            @Override
1972            public void removeAll() {
1973                    for (ResourceBlockPermission resourceBlockPermission : findAll()) {
1974                            remove(resourceBlockPermission);
1975                    }
1976            }
1977    
1978            /**
1979             * Returns the number of resource block permissions.
1980             *
1981             * @return the number of resource block permissions
1982             */
1983            @Override
1984            public int countAll() {
1985                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1986                                    FINDER_ARGS_EMPTY, this);
1987    
1988                    if (count == null) {
1989                            Session session = null;
1990    
1991                            try {
1992                                    session = openSession();
1993    
1994                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCKPERMISSION);
1995    
1996                                    count = (Long)q.uniqueResult();
1997    
1998                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1999                                            FINDER_ARGS_EMPTY, count);
2000                            }
2001                            catch (Exception e) {
2002                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2003                                            FINDER_ARGS_EMPTY);
2004    
2005                                    throw processException(e);
2006                            }
2007                            finally {
2008                                    closeSession(session);
2009                            }
2010                    }
2011    
2012                    return count.intValue();
2013            }
2014    
2015            /**
2016             * Initializes the resource block permission persistence.
2017             */
2018            public void afterPropertiesSet() {
2019            }
2020    
2021            public void destroy() {
2022                    EntityCacheUtil.removeCache(ResourceBlockPermissionImpl.class.getName());
2023                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2024                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2025                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2026            }
2027    
2028            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission";
2029            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE_PKS_IN =
2030                    "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE resourceBlockPermissionId IN (";
2031            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE ";
2032            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission";
2033            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission WHERE ";
2034            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlockPermission.";
2035            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlockPermission exists with the primary key ";
2036            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlockPermission exists with the key {";
2037            private static final Log _log = LogFactoryUtil.getLog(ResourceBlockPermissionPersistenceImpl.class);
2038            private static final ResourceBlockPermission _nullResourceBlockPermission = new ResourceBlockPermissionImpl() {
2039                            @Override
2040                            public Object clone() {
2041                                    return this;
2042                            }
2043    
2044                            @Override
2045                            public CacheModel<ResourceBlockPermission> toCacheModel() {
2046                                    return _nullResourceBlockPermissionCacheModel;
2047                            }
2048                    };
2049    
2050            private static final CacheModel<ResourceBlockPermission> _nullResourceBlockPermissionCacheModel =
2051                    new NullCacheModel();
2052    
2053            private static class NullCacheModel implements CacheModel<ResourceBlockPermission>,
2054                    MVCCModel {
2055                    @Override
2056                    public long getMvccVersion() {
2057                            return -1;
2058                    }
2059    
2060                    @Override
2061                    public void setMvccVersion(long mvccVersion) {
2062                    }
2063    
2064                    @Override
2065                    public ResourceBlockPermission toEntityModel() {
2066                            return _nullResourceBlockPermission;
2067                    }
2068            }
2069    }