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