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