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            public ResourceBlockPermissionPersistenceImpl() {
1322                    setModelClass(ResourceBlockPermission.class);
1323            }
1324    
1325            /**
1326             * Caches the resource block permission in the entity cache if it is enabled.
1327             *
1328             * @param resourceBlockPermission the resource block permission
1329             */
1330            @Override
1331            public void cacheResult(ResourceBlockPermission resourceBlockPermission) {
1332                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1333                            ResourceBlockPermissionImpl.class,
1334                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
1335    
1336                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1337                            new Object[] {
1338                                    resourceBlockPermission.getResourceBlockId(),
1339                                    resourceBlockPermission.getRoleId()
1340                            }, resourceBlockPermission);
1341    
1342                    resourceBlockPermission.resetOriginalValues();
1343            }
1344    
1345            /**
1346             * Caches the resource block permissions in the entity cache if it is enabled.
1347             *
1348             * @param resourceBlockPermissions the resource block permissions
1349             */
1350            @Override
1351            public void cacheResult(
1352                    List<ResourceBlockPermission> resourceBlockPermissions) {
1353                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
1354                            if (EntityCacheUtil.getResult(
1355                                                    ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1356                                                    ResourceBlockPermissionImpl.class,
1357                                                    resourceBlockPermission.getPrimaryKey()) == null) {
1358                                    cacheResult(resourceBlockPermission);
1359                            }
1360                            else {
1361                                    resourceBlockPermission.resetOriginalValues();
1362                            }
1363                    }
1364            }
1365    
1366            /**
1367             * Clears the cache for all resource block permissions.
1368             *
1369             * <p>
1370             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1371             * </p>
1372             */
1373            @Override
1374            public void clearCache() {
1375                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1376                            CacheRegistryUtil.clear(ResourceBlockPermissionImpl.class.getName());
1377                    }
1378    
1379                    EntityCacheUtil.clearCache(ResourceBlockPermissionImpl.class.getName());
1380    
1381                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1382                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1383                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1384            }
1385    
1386            /**
1387             * Clears the cache for the resource block permission.
1388             *
1389             * <p>
1390             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1391             * </p>
1392             */
1393            @Override
1394            public void clearCache(ResourceBlockPermission resourceBlockPermission) {
1395                    EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1396                            ResourceBlockPermissionImpl.class,
1397                            resourceBlockPermission.getPrimaryKey());
1398    
1399                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1400                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1401    
1402                    clearUniqueFindersCache(resourceBlockPermission);
1403            }
1404    
1405            @Override
1406            public void clearCache(
1407                    List<ResourceBlockPermission> resourceBlockPermissions) {
1408                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1409                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1410    
1411                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
1412                            EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1413                                    ResourceBlockPermissionImpl.class,
1414                                    resourceBlockPermission.getPrimaryKey());
1415    
1416                            clearUniqueFindersCache(resourceBlockPermission);
1417                    }
1418            }
1419    
1420            protected void cacheUniqueFindersCache(
1421                    ResourceBlockPermission resourceBlockPermission) {
1422                    if (resourceBlockPermission.isNew()) {
1423                            Object[] args = new Object[] {
1424                                            resourceBlockPermission.getResourceBlockId(),
1425                                            resourceBlockPermission.getRoleId()
1426                                    };
1427    
1428                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, args,
1429                                    Long.valueOf(1));
1430                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R, args,
1431                                    resourceBlockPermission);
1432                    }
1433                    else {
1434                            ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1435    
1436                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1437                                            FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
1438                                    Object[] args = new Object[] {
1439                                                    resourceBlockPermission.getResourceBlockId(),
1440                                                    resourceBlockPermission.getRoleId()
1441                                            };
1442    
1443                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, args,
1444                                            Long.valueOf(1));
1445                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R, args,
1446                                            resourceBlockPermission);
1447                            }
1448                    }
1449            }
1450    
1451            protected void clearUniqueFindersCache(
1452                    ResourceBlockPermission resourceBlockPermission) {
1453                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1454    
1455                    Object[] args = new Object[] {
1456                                    resourceBlockPermission.getResourceBlockId(),
1457                                    resourceBlockPermission.getRoleId()
1458                            };
1459    
1460                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
1461                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
1462    
1463                    if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1464                                    FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
1465                            args = new Object[] {
1466                                            resourceBlockPermissionModelImpl.getOriginalResourceBlockId(),
1467                                            resourceBlockPermissionModelImpl.getOriginalRoleId()
1468                                    };
1469    
1470                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
1471                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
1472                    }
1473            }
1474    
1475            /**
1476             * Creates a new resource block permission with the primary key. Does not add the resource block permission to the database.
1477             *
1478             * @param resourceBlockPermissionId the primary key for the new resource block permission
1479             * @return the new resource block permission
1480             */
1481            @Override
1482            public ResourceBlockPermission create(long resourceBlockPermissionId) {
1483                    ResourceBlockPermission resourceBlockPermission = new ResourceBlockPermissionImpl();
1484    
1485                    resourceBlockPermission.setNew(true);
1486                    resourceBlockPermission.setPrimaryKey(resourceBlockPermissionId);
1487    
1488                    return resourceBlockPermission;
1489            }
1490    
1491            /**
1492             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
1493             *
1494             * @param resourceBlockPermissionId the primary key of the resource block permission
1495             * @return the resource block permission that was removed
1496             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1497             * @throws SystemException if a system exception occurred
1498             */
1499            @Override
1500            public ResourceBlockPermission remove(long resourceBlockPermissionId)
1501                    throws NoSuchResourceBlockPermissionException, SystemException {
1502                    return remove((Serializable)resourceBlockPermissionId);
1503            }
1504    
1505            /**
1506             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
1507             *
1508             * @param primaryKey the primary key of the resource block permission
1509             * @return the resource block permission that was removed
1510             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1511             * @throws SystemException if a system exception occurred
1512             */
1513            @Override
1514            public ResourceBlockPermission remove(Serializable primaryKey)
1515                    throws NoSuchResourceBlockPermissionException, SystemException {
1516                    Session session = null;
1517    
1518                    try {
1519                            session = openSession();
1520    
1521                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1522                                            primaryKey);
1523    
1524                            if (resourceBlockPermission == null) {
1525                                    if (_log.isWarnEnabled()) {
1526                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1527                                    }
1528    
1529                                    throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1530                                            primaryKey);
1531                            }
1532    
1533                            return remove(resourceBlockPermission);
1534                    }
1535                    catch (NoSuchResourceBlockPermissionException nsee) {
1536                            throw nsee;
1537                    }
1538                    catch (Exception e) {
1539                            throw processException(e);
1540                    }
1541                    finally {
1542                            closeSession(session);
1543                    }
1544            }
1545    
1546            @Override
1547            protected ResourceBlockPermission removeImpl(
1548                    ResourceBlockPermission resourceBlockPermission)
1549                    throws SystemException {
1550                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
1551    
1552                    Session session = null;
1553    
1554                    try {
1555                            session = openSession();
1556    
1557                            if (!session.contains(resourceBlockPermission)) {
1558                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1559                                                    resourceBlockPermission.getPrimaryKeyObj());
1560                            }
1561    
1562                            if (resourceBlockPermission != null) {
1563                                    session.delete(resourceBlockPermission);
1564                            }
1565                    }
1566                    catch (Exception e) {
1567                            throw processException(e);
1568                    }
1569                    finally {
1570                            closeSession(session);
1571                    }
1572    
1573                    if (resourceBlockPermission != null) {
1574                            clearCache(resourceBlockPermission);
1575                    }
1576    
1577                    return resourceBlockPermission;
1578            }
1579    
1580            @Override
1581            public ResourceBlockPermission updateImpl(
1582                    com.liferay.portal.model.ResourceBlockPermission resourceBlockPermission)
1583                    throws SystemException {
1584                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
1585    
1586                    boolean isNew = resourceBlockPermission.isNew();
1587    
1588                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1589    
1590                    Session session = null;
1591    
1592                    try {
1593                            session = openSession();
1594    
1595                            if (resourceBlockPermission.isNew()) {
1596                                    session.save(resourceBlockPermission);
1597    
1598                                    resourceBlockPermission.setNew(false);
1599                            }
1600                            else {
1601                                    session.merge(resourceBlockPermission);
1602                            }
1603                    }
1604                    catch (Exception e) {
1605                            throw processException(e);
1606                    }
1607                    finally {
1608                            closeSession(session);
1609                    }
1610    
1611                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1612    
1613                    if (isNew || !ResourceBlockPermissionModelImpl.COLUMN_BITMASK_ENABLED) {
1614                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1615                    }
1616    
1617                    else {
1618                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1619                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID.getColumnBitmask()) != 0) {
1620                                    Object[] args = new Object[] {
1621                                                    resourceBlockPermissionModelImpl.getOriginalResourceBlockId()
1622                                            };
1623    
1624                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1625                                            args);
1626                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
1627                                            args);
1628    
1629                                    args = new Object[] {
1630                                                    resourceBlockPermissionModelImpl.getResourceBlockId()
1631                                            };
1632    
1633                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1634                                            args);
1635                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
1636                                            args);
1637                            }
1638    
1639                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1640                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1641                                    Object[] args = new Object[] {
1642                                                    resourceBlockPermissionModelImpl.getOriginalRoleId()
1643                                            };
1644    
1645                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1646                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1647                                            args);
1648    
1649                                    args = new Object[] { resourceBlockPermissionModelImpl.getRoleId() };
1650    
1651                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1652                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1653                                            args);
1654                            }
1655                    }
1656    
1657                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1658                            ResourceBlockPermissionImpl.class,
1659                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
1660    
1661                    clearUniqueFindersCache(resourceBlockPermission);
1662                    cacheUniqueFindersCache(resourceBlockPermission);
1663    
1664                    return resourceBlockPermission;
1665            }
1666    
1667            protected ResourceBlockPermission toUnwrappedModel(
1668                    ResourceBlockPermission resourceBlockPermission) {
1669                    if (resourceBlockPermission instanceof ResourceBlockPermissionImpl) {
1670                            return resourceBlockPermission;
1671                    }
1672    
1673                    ResourceBlockPermissionImpl resourceBlockPermissionImpl = new ResourceBlockPermissionImpl();
1674    
1675                    resourceBlockPermissionImpl.setNew(resourceBlockPermission.isNew());
1676                    resourceBlockPermissionImpl.setPrimaryKey(resourceBlockPermission.getPrimaryKey());
1677    
1678                    resourceBlockPermissionImpl.setResourceBlockPermissionId(resourceBlockPermission.getResourceBlockPermissionId());
1679                    resourceBlockPermissionImpl.setResourceBlockId(resourceBlockPermission.getResourceBlockId());
1680                    resourceBlockPermissionImpl.setRoleId(resourceBlockPermission.getRoleId());
1681                    resourceBlockPermissionImpl.setActionIds(resourceBlockPermission.getActionIds());
1682    
1683                    return resourceBlockPermissionImpl;
1684            }
1685    
1686            /**
1687             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1688             *
1689             * @param primaryKey the primary key of the resource block permission
1690             * @return the resource block permission
1691             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1692             * @throws SystemException if a system exception occurred
1693             */
1694            @Override
1695            public ResourceBlockPermission findByPrimaryKey(Serializable primaryKey)
1696                    throws NoSuchResourceBlockPermissionException, SystemException {
1697                    ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(primaryKey);
1698    
1699                    if (resourceBlockPermission == null) {
1700                            if (_log.isWarnEnabled()) {
1701                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1702                            }
1703    
1704                            throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1705                                    primaryKey);
1706                    }
1707    
1708                    return resourceBlockPermission;
1709            }
1710    
1711            /**
1712             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchResourceBlockPermissionException} if it could not be found.
1713             *
1714             * @param resourceBlockPermissionId the primary key of the resource block permission
1715             * @return the resource block permission
1716             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1717             * @throws SystemException if a system exception occurred
1718             */
1719            @Override
1720            public ResourceBlockPermission findByPrimaryKey(
1721                    long resourceBlockPermissionId)
1722                    throws NoSuchResourceBlockPermissionException, SystemException {
1723                    return findByPrimaryKey((Serializable)resourceBlockPermissionId);
1724            }
1725    
1726            /**
1727             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
1728             *
1729             * @param primaryKey the primary key of the resource block permission
1730             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
1731             * @throws SystemException if a system exception occurred
1732             */
1733            @Override
1734            public ResourceBlockPermission fetchByPrimaryKey(Serializable primaryKey)
1735                    throws SystemException {
1736                    ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)EntityCacheUtil.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1737                                    ResourceBlockPermissionImpl.class, primaryKey);
1738    
1739                    if (resourceBlockPermission == _nullResourceBlockPermission) {
1740                            return null;
1741                    }
1742    
1743                    if (resourceBlockPermission == null) {
1744                            Session session = null;
1745    
1746                            try {
1747                                    session = openSession();
1748    
1749                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1750                                                    primaryKey);
1751    
1752                                    if (resourceBlockPermission != null) {
1753                                            cacheResult(resourceBlockPermission);
1754                                    }
1755                                    else {
1756                                            EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1757                                                    ResourceBlockPermissionImpl.class, primaryKey,
1758                                                    _nullResourceBlockPermission);
1759                                    }
1760                            }
1761                            catch (Exception e) {
1762                                    EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1763                                            ResourceBlockPermissionImpl.class, primaryKey);
1764    
1765                                    throw processException(e);
1766                            }
1767                            finally {
1768                                    closeSession(session);
1769                            }
1770                    }
1771    
1772                    return resourceBlockPermission;
1773            }
1774    
1775            /**
1776             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
1777             *
1778             * @param resourceBlockPermissionId the primary key of the resource block permission
1779             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
1780             * @throws SystemException if a system exception occurred
1781             */
1782            @Override
1783            public ResourceBlockPermission fetchByPrimaryKey(
1784                    long resourceBlockPermissionId) throws SystemException {
1785                    return fetchByPrimaryKey((Serializable)resourceBlockPermissionId);
1786            }
1787    
1788            /**
1789             * Returns all the resource block permissions.
1790             *
1791             * @return the resource block permissions
1792             * @throws SystemException if a system exception occurred
1793             */
1794            @Override
1795            public List<ResourceBlockPermission> findAll() throws SystemException {
1796                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1797            }
1798    
1799            /**
1800             * Returns a range of all the resource block permissions.
1801             *
1802             * <p>
1803             * 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.
1804             * </p>
1805             *
1806             * @param start the lower bound of the range of resource block permissions
1807             * @param end the upper bound of the range of resource block permissions (not inclusive)
1808             * @return the range of resource block permissions
1809             * @throws SystemException if a system exception occurred
1810             */
1811            @Override
1812            public List<ResourceBlockPermission> findAll(int start, int end)
1813                    throws SystemException {
1814                    return findAll(start, end, null);
1815            }
1816    
1817            /**
1818             * Returns an ordered range of all the resource block permissions.
1819             *
1820             * <p>
1821             * 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.
1822             * </p>
1823             *
1824             * @param start the lower bound of the range of resource block permissions
1825             * @param end the upper bound of the range of resource block permissions (not inclusive)
1826             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1827             * @return the ordered range of resource block permissions
1828             * @throws SystemException if a system exception occurred
1829             */
1830            @Override
1831            public List<ResourceBlockPermission> findAll(int start, int end,
1832                    OrderByComparator orderByComparator) throws SystemException {
1833                    boolean pagination = true;
1834                    FinderPath finderPath = null;
1835                    Object[] finderArgs = null;
1836    
1837                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1838                                    (orderByComparator == null)) {
1839                            pagination = false;
1840                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1841                            finderArgs = FINDER_ARGS_EMPTY;
1842                    }
1843                    else {
1844                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1845                            finderArgs = new Object[] { start, end, orderByComparator };
1846                    }
1847    
1848                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
1849                                    finderArgs, this);
1850    
1851                    if (list == null) {
1852                            StringBundler query = null;
1853                            String sql = null;
1854    
1855                            if (orderByComparator != null) {
1856                                    query = new StringBundler(2 +
1857                                                    (orderByComparator.getOrderByFields().length * 3));
1858    
1859                                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION);
1860    
1861                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1862                                            orderByComparator);
1863    
1864                                    sql = query.toString();
1865                            }
1866                            else {
1867                                    sql = _SQL_SELECT_RESOURCEBLOCKPERMISSION;
1868    
1869                                    if (pagination) {
1870                                            sql = sql.concat(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
1871                                    }
1872                            }
1873    
1874                            Session session = null;
1875    
1876                            try {
1877                                    session = openSession();
1878    
1879                                    Query q = session.createQuery(sql);
1880    
1881                                    if (!pagination) {
1882                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1883                                                            getDialect(), start, end, false);
1884    
1885                                            Collections.sort(list);
1886    
1887                                            list = new UnmodifiableList<ResourceBlockPermission>(list);
1888                                    }
1889                                    else {
1890                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1891                                                            getDialect(), start, end);
1892                                    }
1893    
1894                                    cacheResult(list);
1895    
1896                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1897                            }
1898                            catch (Exception e) {
1899                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1900    
1901                                    throw processException(e);
1902                            }
1903                            finally {
1904                                    closeSession(session);
1905                            }
1906                    }
1907    
1908                    return list;
1909            }
1910    
1911            /**
1912             * Removes all the resource block permissions from the database.
1913             *
1914             * @throws SystemException if a system exception occurred
1915             */
1916            @Override
1917            public void removeAll() throws SystemException {
1918                    for (ResourceBlockPermission resourceBlockPermission : findAll()) {
1919                            remove(resourceBlockPermission);
1920                    }
1921            }
1922    
1923            /**
1924             * Returns the number of resource block permissions.
1925             *
1926             * @return the number of resource block permissions
1927             * @throws SystemException if a system exception occurred
1928             */
1929            @Override
1930            public int countAll() throws SystemException {
1931                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1932                                    FINDER_ARGS_EMPTY, this);
1933    
1934                    if (count == null) {
1935                            Session session = null;
1936    
1937                            try {
1938                                    session = openSession();
1939    
1940                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCKPERMISSION);
1941    
1942                                    count = (Long)q.uniqueResult();
1943    
1944                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1945                                            FINDER_ARGS_EMPTY, count);
1946                            }
1947                            catch (Exception e) {
1948                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1949                                            FINDER_ARGS_EMPTY);
1950    
1951                                    throw processException(e);
1952                            }
1953                            finally {
1954                                    closeSession(session);
1955                            }
1956                    }
1957    
1958                    return count.intValue();
1959            }
1960    
1961            /**
1962             * Initializes the resource block permission persistence.
1963             */
1964            public void afterPropertiesSet() {
1965                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1966                                            com.liferay.portal.util.PropsUtil.get(
1967                                                    "value.object.listener.com.liferay.portal.model.ResourceBlockPermission")));
1968    
1969                    if (listenerClassNames.length > 0) {
1970                            try {
1971                                    List<ModelListener<ResourceBlockPermission>> listenersList = new ArrayList<ModelListener<ResourceBlockPermission>>();
1972    
1973                                    for (String listenerClassName : listenerClassNames) {
1974                                            listenersList.add((ModelListener<ResourceBlockPermission>)InstanceFactory.newInstance(
1975                                                            getClassLoader(), listenerClassName));
1976                                    }
1977    
1978                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1979                            }
1980                            catch (Exception e) {
1981                                    _log.error(e);
1982                            }
1983                    }
1984            }
1985    
1986            public void destroy() {
1987                    EntityCacheUtil.removeCache(ResourceBlockPermissionImpl.class.getName());
1988                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1989                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1990                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1991            }
1992    
1993            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission";
1994            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE ";
1995            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission";
1996            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission WHERE ";
1997            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlockPermission.";
1998            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlockPermission exists with the primary key ";
1999            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlockPermission exists with the key {";
2000            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2001            private static Log _log = LogFactoryUtil.getLog(ResourceBlockPermissionPersistenceImpl.class);
2002            private static ResourceBlockPermission _nullResourceBlockPermission = new ResourceBlockPermissionImpl() {
2003                            @Override
2004                            public Object clone() {
2005                                    return this;
2006                            }
2007    
2008                            @Override
2009                            public CacheModel<ResourceBlockPermission> toCacheModel() {
2010                                    return _nullResourceBlockPermissionCacheModel;
2011                            }
2012                    };
2013    
2014            private static CacheModel<ResourceBlockPermission> _nullResourceBlockPermissionCacheModel =
2015                    new CacheModel<ResourceBlockPermission>() {
2016                            @Override
2017                            public ResourceBlockPermission toEntityModel() {
2018                                    return _nullResourceBlockPermission;
2019                            }
2020                    };
2021    }