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