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