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