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