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.NoSuchModelException;
018    import com.liferay.portal.NoSuchResourceBlockPermissionException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.ResourceBlockPermission;
040    import com.liferay.portal.model.impl.ResourceBlockPermissionImpl;
041    import com.liferay.portal.model.impl.ResourceBlockPermissionModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the resource block permission service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ResourceBlockPermissionPersistence
059     * @see ResourceBlockPermissionUtil
060     * @generated
061     */
062    public class ResourceBlockPermissionPersistenceImpl extends BasePersistenceImpl<ResourceBlockPermission>
063            implements ResourceBlockPermissionPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * 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.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockPermissionImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID =
075                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
076                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
077                            ResourceBlockPermissionImpl.class,
078                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByResourceBlockId",
079                            new String[] {
080                                    Long.class.getName(),
081                                    
082                            "java.lang.Integer", "java.lang.Integer",
083                                    "com.liferay.portal.kernel.util.OrderByComparator"
084                            });
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID =
086                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
087                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
088                            ResourceBlockPermissionImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourceBlockId",
090                            new String[] { Long.class.getName() },
091                            ResourceBlockPermissionModelImpl.RESOURCEBLOCKID_COLUMN_BITMASK);
092            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEBLOCKID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
093                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
095                            "countByResourceBlockId", new String[] { Long.class.getName() });
096            public static final FinderPath FINDER_PATH_FETCH_BY_R_R = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
097                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
098                            ResourceBlockPermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
099                            "fetchByR_R",
100                            new String[] { Long.class.getName(), Long.class.getName() },
101                            ResourceBlockPermissionModelImpl.RESOURCEBLOCKID_COLUMN_BITMASK |
102                            ResourceBlockPermissionModelImpl.ROLEID_COLUMN_BITMASK);
103            public static final FinderPath FINDER_PATH_COUNT_BY_R_R = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
104                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_R",
106                            new String[] { Long.class.getName(), Long.class.getName() });
107            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
108                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
109                            ResourceBlockPermissionImpl.class,
110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
111            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
112                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
113                            ResourceBlockPermissionImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
116                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
118    
119            /**
120             * Caches the resource block permission in the entity cache if it is enabled.
121             *
122             * @param resourceBlockPermission the resource block permission
123             */
124            public void cacheResult(ResourceBlockPermission resourceBlockPermission) {
125                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
126                            ResourceBlockPermissionImpl.class,
127                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
128    
129                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
130                            new Object[] {
131                                    Long.valueOf(resourceBlockPermission.getResourceBlockId()),
132                                    Long.valueOf(resourceBlockPermission.getRoleId())
133                            }, resourceBlockPermission);
134    
135                    resourceBlockPermission.resetOriginalValues();
136            }
137    
138            /**
139             * Caches the resource block permissions in the entity cache if it is enabled.
140             *
141             * @param resourceBlockPermissions the resource block permissions
142             */
143            public void cacheResult(
144                    List<ResourceBlockPermission> resourceBlockPermissions) {
145                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
146                            if (EntityCacheUtil.getResult(
147                                                    ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
148                                                    ResourceBlockPermissionImpl.class,
149                                                    resourceBlockPermission.getPrimaryKey()) == null) {
150                                    cacheResult(resourceBlockPermission);
151                            }
152                            else {
153                                    resourceBlockPermission.resetOriginalValues();
154                            }
155                    }
156            }
157    
158            /**
159             * Clears the cache for all resource block permissions.
160             *
161             * <p>
162             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
163             * </p>
164             */
165            @Override
166            public void clearCache() {
167                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
168                            CacheRegistryUtil.clear(ResourceBlockPermissionImpl.class.getName());
169                    }
170    
171                    EntityCacheUtil.clearCache(ResourceBlockPermissionImpl.class.getName());
172    
173                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
174                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
175                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
176            }
177    
178            /**
179             * Clears the cache for the resource block permission.
180             *
181             * <p>
182             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
183             * </p>
184             */
185            @Override
186            public void clearCache(ResourceBlockPermission resourceBlockPermission) {
187                    EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
188                            ResourceBlockPermissionImpl.class,
189                            resourceBlockPermission.getPrimaryKey());
190    
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193    
194                    clearUniqueFindersCache(resourceBlockPermission);
195            }
196    
197            @Override
198            public void clearCache(
199                    List<ResourceBlockPermission> resourceBlockPermissions) {
200                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
201                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
202    
203                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
204                            EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
205                                    ResourceBlockPermissionImpl.class,
206                                    resourceBlockPermission.getPrimaryKey());
207    
208                            clearUniqueFindersCache(resourceBlockPermission);
209                    }
210            }
211    
212            protected void cacheUniqueFindersCache(
213                    ResourceBlockPermission resourceBlockPermission) {
214                    if (resourceBlockPermission.isNew()) {
215                            Object[] args = new Object[] {
216                                            Long.valueOf(resourceBlockPermission.getResourceBlockId()),
217                                            Long.valueOf(resourceBlockPermission.getRoleId())
218                                    };
219    
220                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, args,
221                                    Long.valueOf(1));
222                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R, args,
223                                    resourceBlockPermission);
224                    }
225                    else {
226                            ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
227    
228                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
229                                            FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
230                                    Object[] args = new Object[] {
231                                                    Long.valueOf(resourceBlockPermission.getResourceBlockId()),
232                                                    Long.valueOf(resourceBlockPermission.getRoleId())
233                                            };
234    
235                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, args,
236                                            Long.valueOf(1));
237                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R, args,
238                                            resourceBlockPermission);
239                            }
240                    }
241            }
242    
243            protected void clearUniqueFindersCache(
244                    ResourceBlockPermission resourceBlockPermission) {
245                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
246    
247                    Object[] args = new Object[] {
248                                    Long.valueOf(resourceBlockPermission.getResourceBlockId()),
249                                    Long.valueOf(resourceBlockPermission.getRoleId())
250                            };
251    
252                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
253                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
254    
255                    if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
256                                    FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
257                            args = new Object[] {
258                                            Long.valueOf(resourceBlockPermissionModelImpl.getOriginalResourceBlockId()),
259                                            Long.valueOf(resourceBlockPermissionModelImpl.getOriginalRoleId())
260                                    };
261    
262                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
263                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
264                    }
265            }
266    
267            /**
268             * Creates a new resource block permission with the primary key. Does not add the resource block permission to the database.
269             *
270             * @param resourceBlockPermissionId the primary key for the new resource block permission
271             * @return the new resource block permission
272             */
273            public ResourceBlockPermission create(long resourceBlockPermissionId) {
274                    ResourceBlockPermission resourceBlockPermission = new ResourceBlockPermissionImpl();
275    
276                    resourceBlockPermission.setNew(true);
277                    resourceBlockPermission.setPrimaryKey(resourceBlockPermissionId);
278    
279                    return resourceBlockPermission;
280            }
281    
282            /**
283             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
284             *
285             * @param resourceBlockPermissionId the primary key of the resource block permission
286             * @return the resource block permission that was removed
287             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
288             * @throws SystemException if a system exception occurred
289             */
290            public ResourceBlockPermission remove(long resourceBlockPermissionId)
291                    throws NoSuchResourceBlockPermissionException, SystemException {
292                    return remove(Long.valueOf(resourceBlockPermissionId));
293            }
294    
295            /**
296             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
297             *
298             * @param primaryKey the primary key of the resource block permission
299             * @return the resource block permission that was removed
300             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            @Override
304            public ResourceBlockPermission remove(Serializable primaryKey)
305                    throws NoSuchResourceBlockPermissionException, SystemException {
306                    Session session = null;
307    
308                    try {
309                            session = openSession();
310    
311                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
312                                            primaryKey);
313    
314                            if (resourceBlockPermission == null) {
315                                    if (_log.isWarnEnabled()) {
316                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
317                                    }
318    
319                                    throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
320                                            primaryKey);
321                            }
322    
323                            return remove(resourceBlockPermission);
324                    }
325                    catch (NoSuchResourceBlockPermissionException nsee) {
326                            throw nsee;
327                    }
328                    catch (Exception e) {
329                            throw processException(e);
330                    }
331                    finally {
332                            closeSession(session);
333                    }
334            }
335    
336            @Override
337            protected ResourceBlockPermission removeImpl(
338                    ResourceBlockPermission resourceBlockPermission)
339                    throws SystemException {
340                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
341    
342                    Session session = null;
343    
344                    try {
345                            session = openSession();
346    
347                            BatchSessionUtil.delete(session, resourceBlockPermission);
348                    }
349                    catch (Exception e) {
350                            throw processException(e);
351                    }
352                    finally {
353                            closeSession(session);
354                    }
355    
356                    clearCache(resourceBlockPermission);
357    
358                    return resourceBlockPermission;
359            }
360    
361            @Override
362            public ResourceBlockPermission updateImpl(
363                    com.liferay.portal.model.ResourceBlockPermission resourceBlockPermission,
364                    boolean merge) throws SystemException {
365                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
366    
367                    boolean isNew = resourceBlockPermission.isNew();
368    
369                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
370    
371                    Session session = null;
372    
373                    try {
374                            session = openSession();
375    
376                            BatchSessionUtil.update(session, resourceBlockPermission, merge);
377    
378                            resourceBlockPermission.setNew(false);
379                    }
380                    catch (Exception e) {
381                            throw processException(e);
382                    }
383                    finally {
384                            closeSession(session);
385                    }
386    
387                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
388    
389                    if (isNew || !ResourceBlockPermissionModelImpl.COLUMN_BITMASK_ENABLED) {
390                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
391                    }
392    
393                    else {
394                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
395                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID.getColumnBitmask()) != 0) {
396                                    Object[] args = new Object[] {
397                                                    Long.valueOf(resourceBlockPermissionModelImpl.getOriginalResourceBlockId())
398                                            };
399    
400                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
401                                            args);
402                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
403                                            args);
404    
405                                    args = new Object[] {
406                                                    Long.valueOf(resourceBlockPermissionModelImpl.getResourceBlockId())
407                                            };
408    
409                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
410                                            args);
411                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
412                                            args);
413                            }
414                    }
415    
416                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
417                            ResourceBlockPermissionImpl.class,
418                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
419    
420                    clearUniqueFindersCache(resourceBlockPermission);
421                    cacheUniqueFindersCache(resourceBlockPermission);
422    
423                    return resourceBlockPermission;
424            }
425    
426            protected ResourceBlockPermission toUnwrappedModel(
427                    ResourceBlockPermission resourceBlockPermission) {
428                    if (resourceBlockPermission instanceof ResourceBlockPermissionImpl) {
429                            return resourceBlockPermission;
430                    }
431    
432                    ResourceBlockPermissionImpl resourceBlockPermissionImpl = new ResourceBlockPermissionImpl();
433    
434                    resourceBlockPermissionImpl.setNew(resourceBlockPermission.isNew());
435                    resourceBlockPermissionImpl.setPrimaryKey(resourceBlockPermission.getPrimaryKey());
436    
437                    resourceBlockPermissionImpl.setResourceBlockPermissionId(resourceBlockPermission.getResourceBlockPermissionId());
438                    resourceBlockPermissionImpl.setResourceBlockId(resourceBlockPermission.getResourceBlockId());
439                    resourceBlockPermissionImpl.setRoleId(resourceBlockPermission.getRoleId());
440                    resourceBlockPermissionImpl.setActionIds(resourceBlockPermission.getActionIds());
441    
442                    return resourceBlockPermissionImpl;
443            }
444    
445            /**
446             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
447             *
448             * @param primaryKey the primary key of the resource block permission
449             * @return the resource block permission
450             * @throws com.liferay.portal.NoSuchModelException if a resource block permission with the primary key could not be found
451             * @throws SystemException if a system exception occurred
452             */
453            @Override
454            public ResourceBlockPermission findByPrimaryKey(Serializable primaryKey)
455                    throws NoSuchModelException, SystemException {
456                    return findByPrimaryKey(((Long)primaryKey).longValue());
457            }
458    
459            /**
460             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchResourceBlockPermissionException} if it could not be found.
461             *
462             * @param resourceBlockPermissionId the primary key of the resource block permission
463             * @return the resource block permission
464             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
465             * @throws SystemException if a system exception occurred
466             */
467            public ResourceBlockPermission findByPrimaryKey(
468                    long resourceBlockPermissionId)
469                    throws NoSuchResourceBlockPermissionException, SystemException {
470                    ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(resourceBlockPermissionId);
471    
472                    if (resourceBlockPermission == null) {
473                            if (_log.isWarnEnabled()) {
474                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
475                                            resourceBlockPermissionId);
476                            }
477    
478                            throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
479                                    resourceBlockPermissionId);
480                    }
481    
482                    return resourceBlockPermission;
483            }
484    
485            /**
486             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
487             *
488             * @param primaryKey the primary key of the resource block permission
489             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
490             * @throws SystemException if a system exception occurred
491             */
492            @Override
493            public ResourceBlockPermission fetchByPrimaryKey(Serializable primaryKey)
494                    throws SystemException {
495                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
496            }
497    
498            /**
499             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
500             *
501             * @param resourceBlockPermissionId the primary key of the resource block permission
502             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
503             * @throws SystemException if a system exception occurred
504             */
505            public ResourceBlockPermission fetchByPrimaryKey(
506                    long resourceBlockPermissionId) throws SystemException {
507                    ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)EntityCacheUtil.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
508                                    ResourceBlockPermissionImpl.class, resourceBlockPermissionId);
509    
510                    if (resourceBlockPermission == _nullResourceBlockPermission) {
511                            return null;
512                    }
513    
514                    if (resourceBlockPermission == null) {
515                            Session session = null;
516    
517                            boolean hasException = false;
518    
519                            try {
520                                    session = openSession();
521    
522                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
523                                                    Long.valueOf(resourceBlockPermissionId));
524                            }
525                            catch (Exception e) {
526                                    hasException = true;
527    
528                                    throw processException(e);
529                            }
530                            finally {
531                                    if (resourceBlockPermission != null) {
532                                            cacheResult(resourceBlockPermission);
533                                    }
534                                    else if (!hasException) {
535                                            EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
536                                                    ResourceBlockPermissionImpl.class,
537                                                    resourceBlockPermissionId, _nullResourceBlockPermission);
538                                    }
539    
540                                    closeSession(session);
541                            }
542                    }
543    
544                    return resourceBlockPermission;
545            }
546    
547            /**
548             * Returns all the resource block permissions where resourceBlockId = &#63;.
549             *
550             * @param resourceBlockId the resource block ID
551             * @return the matching resource block permissions
552             * @throws SystemException if a system exception occurred
553             */
554            public List<ResourceBlockPermission> findByResourceBlockId(
555                    long resourceBlockId) throws SystemException {
556                    return findByResourceBlockId(resourceBlockId, QueryUtil.ALL_POS,
557                            QueryUtil.ALL_POS, null);
558            }
559    
560            /**
561             * Returns a range of all the resource block permissions where resourceBlockId = &#63;.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param resourceBlockId the resource block ID
568             * @param start the lower bound of the range of resource block permissions
569             * @param end the upper bound of the range of resource block permissions (not inclusive)
570             * @return the range of matching resource block permissions
571             * @throws SystemException if a system exception occurred
572             */
573            public List<ResourceBlockPermission> findByResourceBlockId(
574                    long resourceBlockId, int start, int end) throws SystemException {
575                    return findByResourceBlockId(resourceBlockId, start, end, null);
576            }
577    
578            /**
579             * Returns an ordered range of all the resource block permissions where resourceBlockId = &#63;.
580             *
581             * <p>
582             * 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.
583             * </p>
584             *
585             * @param resourceBlockId the resource block ID
586             * @param start the lower bound of the range of resource block permissions
587             * @param end the upper bound of the range of resource block permissions (not inclusive)
588             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
589             * @return the ordered range of matching resource block permissions
590             * @throws SystemException if a system exception occurred
591             */
592            public List<ResourceBlockPermission> findByResourceBlockId(
593                    long resourceBlockId, int start, int end,
594                    OrderByComparator orderByComparator) throws SystemException {
595                    FinderPath finderPath = null;
596                    Object[] finderArgs = null;
597    
598                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
599                                    (orderByComparator == null)) {
600                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID;
601                            finderArgs = new Object[] { resourceBlockId };
602                    }
603                    else {
604                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID;
605                            finderArgs = new Object[] {
606                                            resourceBlockId,
607                                            
608                                            start, end, orderByComparator
609                                    };
610                    }
611    
612                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
613                                    finderArgs, this);
614    
615                    if ((list != null) && !list.isEmpty()) {
616                            for (ResourceBlockPermission resourceBlockPermission : list) {
617                                    if ((resourceBlockId != resourceBlockPermission.getResourceBlockId())) {
618                                            list = null;
619    
620                                            break;
621                                    }
622                            }
623                    }
624    
625                    if (list == null) {
626                            StringBundler query = null;
627    
628                            if (orderByComparator != null) {
629                                    query = new StringBundler(3 +
630                                                    (orderByComparator.getOrderByFields().length * 3));
631                            }
632                            else {
633                                    query = new StringBundler(2);
634                            }
635    
636                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
637    
638                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
639    
640                            if (orderByComparator != null) {
641                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
642                                            orderByComparator);
643                            }
644    
645                            String sql = query.toString();
646    
647                            Session session = null;
648    
649                            try {
650                                    session = openSession();
651    
652                                    Query q = session.createQuery(sql);
653    
654                                    QueryPos qPos = QueryPos.getInstance(q);
655    
656                                    qPos.add(resourceBlockId);
657    
658                                    list = (List<ResourceBlockPermission>)QueryUtil.list(q,
659                                                    getDialect(), start, end);
660                            }
661                            catch (Exception e) {
662                                    throw processException(e);
663                            }
664                            finally {
665                                    if (list == null) {
666                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
667                                    }
668                                    else {
669                                            cacheResult(list);
670    
671                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
672                                    }
673    
674                                    closeSession(session);
675                            }
676                    }
677    
678                    return list;
679            }
680    
681            /**
682             * Returns the first resource block permission in the ordered set where resourceBlockId = &#63;.
683             *
684             * @param resourceBlockId the resource block ID
685             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
686             * @return the first matching resource block permission
687             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
688             * @throws SystemException if a system exception occurred
689             */
690            public ResourceBlockPermission findByResourceBlockId_First(
691                    long resourceBlockId, OrderByComparator orderByComparator)
692                    throws NoSuchResourceBlockPermissionException, SystemException {
693                    ResourceBlockPermission resourceBlockPermission = fetchByResourceBlockId_First(resourceBlockId,
694                                    orderByComparator);
695    
696                    if (resourceBlockPermission != null) {
697                            return resourceBlockPermission;
698                    }
699    
700                    StringBundler msg = new StringBundler(4);
701    
702                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
703    
704                    msg.append("resourceBlockId=");
705                    msg.append(resourceBlockId);
706    
707                    msg.append(StringPool.CLOSE_CURLY_BRACE);
708    
709                    throw new NoSuchResourceBlockPermissionException(msg.toString());
710            }
711    
712            /**
713             * Returns the first resource block permission in the ordered set where resourceBlockId = &#63;.
714             *
715             * @param resourceBlockId the resource block ID
716             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
717             * @return the first matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
718             * @throws SystemException if a system exception occurred
719             */
720            public ResourceBlockPermission fetchByResourceBlockId_First(
721                    long resourceBlockId, OrderByComparator orderByComparator)
722                    throws SystemException {
723                    List<ResourceBlockPermission> list = findByResourceBlockId(resourceBlockId,
724                                    0, 1, orderByComparator);
725    
726                    if (!list.isEmpty()) {
727                            return list.get(0);
728                    }
729    
730                    return null;
731            }
732    
733            /**
734             * Returns the last resource block permission in the ordered set where resourceBlockId = &#63;.
735             *
736             * @param resourceBlockId the resource block ID
737             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
738             * @return the last matching resource block permission
739             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
740             * @throws SystemException if a system exception occurred
741             */
742            public ResourceBlockPermission findByResourceBlockId_Last(
743                    long resourceBlockId, OrderByComparator orderByComparator)
744                    throws NoSuchResourceBlockPermissionException, SystemException {
745                    ResourceBlockPermission resourceBlockPermission = fetchByResourceBlockId_Last(resourceBlockId,
746                                    orderByComparator);
747    
748                    if (resourceBlockPermission != null) {
749                            return resourceBlockPermission;
750                    }
751    
752                    StringBundler msg = new StringBundler(4);
753    
754                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
755    
756                    msg.append("resourceBlockId=");
757                    msg.append(resourceBlockId);
758    
759                    msg.append(StringPool.CLOSE_CURLY_BRACE);
760    
761                    throw new NoSuchResourceBlockPermissionException(msg.toString());
762            }
763    
764            /**
765             * Returns the last resource block permission in the ordered set where resourceBlockId = &#63;.
766             *
767             * @param resourceBlockId the resource block ID
768             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
769             * @return the last matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
770             * @throws SystemException if a system exception occurred
771             */
772            public ResourceBlockPermission fetchByResourceBlockId_Last(
773                    long resourceBlockId, OrderByComparator orderByComparator)
774                    throws SystemException {
775                    int count = countByResourceBlockId(resourceBlockId);
776    
777                    List<ResourceBlockPermission> list = findByResourceBlockId(resourceBlockId,
778                                    count - 1, count, orderByComparator);
779    
780                    if (!list.isEmpty()) {
781                            return list.get(0);
782                    }
783    
784                    return null;
785            }
786    
787            /**
788             * Returns the resource block permissions before and after the current resource block permission in the ordered set where resourceBlockId = &#63;.
789             *
790             * @param resourceBlockPermissionId the primary key of the current resource block permission
791             * @param resourceBlockId the resource block ID
792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
793             * @return the previous, current, and next resource block permission
794             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
795             * @throws SystemException if a system exception occurred
796             */
797            public ResourceBlockPermission[] findByResourceBlockId_PrevAndNext(
798                    long resourceBlockPermissionId, long resourceBlockId,
799                    OrderByComparator orderByComparator)
800                    throws NoSuchResourceBlockPermissionException, SystemException {
801                    ResourceBlockPermission resourceBlockPermission = findByPrimaryKey(resourceBlockPermissionId);
802    
803                    Session session = null;
804    
805                    try {
806                            session = openSession();
807    
808                            ResourceBlockPermission[] array = new ResourceBlockPermissionImpl[3];
809    
810                            array[0] = getByResourceBlockId_PrevAndNext(session,
811                                            resourceBlockPermission, resourceBlockId,
812                                            orderByComparator, true);
813    
814                            array[1] = resourceBlockPermission;
815    
816                            array[2] = getByResourceBlockId_PrevAndNext(session,
817                                            resourceBlockPermission, resourceBlockId,
818                                            orderByComparator, false);
819    
820                            return array;
821                    }
822                    catch (Exception e) {
823                            throw processException(e);
824                    }
825                    finally {
826                            closeSession(session);
827                    }
828            }
829    
830            protected ResourceBlockPermission getByResourceBlockId_PrevAndNext(
831                    Session session, ResourceBlockPermission resourceBlockPermission,
832                    long resourceBlockId, OrderByComparator orderByComparator,
833                    boolean previous) {
834                    StringBundler query = null;
835    
836                    if (orderByComparator != null) {
837                            query = new StringBundler(6 +
838                                            (orderByComparator.getOrderByFields().length * 6));
839                    }
840                    else {
841                            query = new StringBundler(3);
842                    }
843    
844                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
845    
846                    query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
847    
848                    if (orderByComparator != null) {
849                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
850    
851                            if (orderByConditionFields.length > 0) {
852                                    query.append(WHERE_AND);
853                            }
854    
855                            for (int i = 0; i < orderByConditionFields.length; i++) {
856                                    query.append(_ORDER_BY_ENTITY_ALIAS);
857                                    query.append(orderByConditionFields[i]);
858    
859                                    if ((i + 1) < orderByConditionFields.length) {
860                                            if (orderByComparator.isAscending() ^ previous) {
861                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
862                                            }
863                                            else {
864                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
865                                            }
866                                    }
867                                    else {
868                                            if (orderByComparator.isAscending() ^ previous) {
869                                                    query.append(WHERE_GREATER_THAN);
870                                            }
871                                            else {
872                                                    query.append(WHERE_LESSER_THAN);
873                                            }
874                                    }
875                            }
876    
877                            query.append(ORDER_BY_CLAUSE);
878    
879                            String[] orderByFields = orderByComparator.getOrderByFields();
880    
881                            for (int i = 0; i < orderByFields.length; i++) {
882                                    query.append(_ORDER_BY_ENTITY_ALIAS);
883                                    query.append(orderByFields[i]);
884    
885                                    if ((i + 1) < orderByFields.length) {
886                                            if (orderByComparator.isAscending() ^ previous) {
887                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
888                                            }
889                                            else {
890                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
891                                            }
892                                    }
893                                    else {
894                                            if (orderByComparator.isAscending() ^ previous) {
895                                                    query.append(ORDER_BY_ASC);
896                                            }
897                                            else {
898                                                    query.append(ORDER_BY_DESC);
899                                            }
900                                    }
901                            }
902                    }
903    
904                    String sql = query.toString();
905    
906                    Query q = session.createQuery(sql);
907    
908                    q.setFirstResult(0);
909                    q.setMaxResults(2);
910    
911                    QueryPos qPos = QueryPos.getInstance(q);
912    
913                    qPos.add(resourceBlockId);
914    
915                    if (orderByComparator != null) {
916                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlockPermission);
917    
918                            for (Object value : values) {
919                                    qPos.add(value);
920                            }
921                    }
922    
923                    List<ResourceBlockPermission> list = q.list();
924    
925                    if (list.size() == 2) {
926                            return list.get(1);
927                    }
928                    else {
929                            return null;
930                    }
931            }
932    
933            /**
934             * 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.
935             *
936             * @param resourceBlockId the resource block ID
937             * @param roleId the role ID
938             * @return the matching resource block permission
939             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
940             * @throws SystemException if a system exception occurred
941             */
942            public ResourceBlockPermission findByR_R(long resourceBlockId, long roleId)
943                    throws NoSuchResourceBlockPermissionException, SystemException {
944                    ResourceBlockPermission resourceBlockPermission = fetchByR_R(resourceBlockId,
945                                    roleId);
946    
947                    if (resourceBlockPermission == null) {
948                            StringBundler msg = new StringBundler(6);
949    
950                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
951    
952                            msg.append("resourceBlockId=");
953                            msg.append(resourceBlockId);
954    
955                            msg.append(", roleId=");
956                            msg.append(roleId);
957    
958                            msg.append(StringPool.CLOSE_CURLY_BRACE);
959    
960                            if (_log.isWarnEnabled()) {
961                                    _log.warn(msg.toString());
962                            }
963    
964                            throw new NoSuchResourceBlockPermissionException(msg.toString());
965                    }
966    
967                    return resourceBlockPermission;
968            }
969    
970            /**
971             * 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.
972             *
973             * @param resourceBlockId the resource block ID
974             * @param roleId the role ID
975             * @return the matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
976             * @throws SystemException if a system exception occurred
977             */
978            public ResourceBlockPermission fetchByR_R(long resourceBlockId, long roleId)
979                    throws SystemException {
980                    return fetchByR_R(resourceBlockId, roleId, true);
981            }
982    
983            /**
984             * 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.
985             *
986             * @param resourceBlockId the resource block ID
987             * @param roleId the role ID
988             * @param retrieveFromCache whether to use the finder cache
989             * @return the matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
990             * @throws SystemException if a system exception occurred
991             */
992            public ResourceBlockPermission fetchByR_R(long resourceBlockId,
993                    long roleId, boolean retrieveFromCache) throws SystemException {
994                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
995    
996                    Object result = null;
997    
998                    if (retrieveFromCache) {
999                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_R_R,
1000                                            finderArgs, this);
1001                    }
1002    
1003                    if (result instanceof ResourceBlockPermission) {
1004                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)result;
1005    
1006                            if ((resourceBlockId != resourceBlockPermission.getResourceBlockId()) ||
1007                                            (roleId != resourceBlockPermission.getRoleId())) {
1008                                    result = null;
1009                            }
1010                    }
1011    
1012                    if (result == null) {
1013                            StringBundler query = new StringBundler(3);
1014    
1015                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
1016    
1017                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1018    
1019                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1020    
1021                            String sql = query.toString();
1022    
1023                            Session session = null;
1024    
1025                            try {
1026                                    session = openSession();
1027    
1028                                    Query q = session.createQuery(sql);
1029    
1030                                    QueryPos qPos = QueryPos.getInstance(q);
1031    
1032                                    qPos.add(resourceBlockId);
1033    
1034                                    qPos.add(roleId);
1035    
1036                                    List<ResourceBlockPermission> list = q.list();
1037    
1038                                    result = list;
1039    
1040                                    ResourceBlockPermission resourceBlockPermission = null;
1041    
1042                                    if (list.isEmpty()) {
1043                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1044                                                    finderArgs, list);
1045                                    }
1046                                    else {
1047                                            resourceBlockPermission = list.get(0);
1048    
1049                                            cacheResult(resourceBlockPermission);
1050    
1051                                            if ((resourceBlockPermission.getResourceBlockId() != resourceBlockId) ||
1052                                                            (resourceBlockPermission.getRoleId() != roleId)) {
1053                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1054                                                            finderArgs, resourceBlockPermission);
1055                                            }
1056                                    }
1057    
1058                                    return resourceBlockPermission;
1059                            }
1060                            catch (Exception e) {
1061                                    throw processException(e);
1062                            }
1063                            finally {
1064                                    if (result == null) {
1065                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R,
1066                                                    finderArgs);
1067                                    }
1068    
1069                                    closeSession(session);
1070                            }
1071                    }
1072                    else {
1073                            if (result instanceof List<?>) {
1074                                    return null;
1075                            }
1076                            else {
1077                                    return (ResourceBlockPermission)result;
1078                            }
1079                    }
1080            }
1081    
1082            /**
1083             * Returns all the resource block permissions.
1084             *
1085             * @return the resource block permissions
1086             * @throws SystemException if a system exception occurred
1087             */
1088            public List<ResourceBlockPermission> findAll() throws SystemException {
1089                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1090            }
1091    
1092            /**
1093             * Returns a range of all the resource block permissions.
1094             *
1095             * <p>
1096             * 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.
1097             * </p>
1098             *
1099             * @param start the lower bound of the range of resource block permissions
1100             * @param end the upper bound of the range of resource block permissions (not inclusive)
1101             * @return the range of resource block permissions
1102             * @throws SystemException if a system exception occurred
1103             */
1104            public List<ResourceBlockPermission> findAll(int start, int end)
1105                    throws SystemException {
1106                    return findAll(start, end, null);
1107            }
1108    
1109            /**
1110             * Returns an ordered range of all the resource block permissions.
1111             *
1112             * <p>
1113             * 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.
1114             * </p>
1115             *
1116             * @param start the lower bound of the range of resource block permissions
1117             * @param end the upper bound of the range of resource block permissions (not inclusive)
1118             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1119             * @return the ordered range of resource block permissions
1120             * @throws SystemException if a system exception occurred
1121             */
1122            public List<ResourceBlockPermission> findAll(int start, int end,
1123                    OrderByComparator orderByComparator) throws SystemException {
1124                    FinderPath finderPath = null;
1125                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1126    
1127                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1128                                    (orderByComparator == null)) {
1129                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1130                            finderArgs = FINDER_ARGS_EMPTY;
1131                    }
1132                    else {
1133                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1134                            finderArgs = new Object[] { start, end, orderByComparator };
1135                    }
1136    
1137                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
1138                                    finderArgs, this);
1139    
1140                    if (list == null) {
1141                            StringBundler query = null;
1142                            String sql = null;
1143    
1144                            if (orderByComparator != null) {
1145                                    query = new StringBundler(2 +
1146                                                    (orderByComparator.getOrderByFields().length * 3));
1147    
1148                                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION);
1149    
1150                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1151                                            orderByComparator);
1152    
1153                                    sql = query.toString();
1154                            }
1155                            else {
1156                                    sql = _SQL_SELECT_RESOURCEBLOCKPERMISSION;
1157                            }
1158    
1159                            Session session = null;
1160    
1161                            try {
1162                                    session = openSession();
1163    
1164                                    Query q = session.createQuery(sql);
1165    
1166                                    if (orderByComparator == null) {
1167                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1168                                                            getDialect(), start, end, false);
1169    
1170                                            Collections.sort(list);
1171                                    }
1172                                    else {
1173                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1174                                                            getDialect(), start, end);
1175                                    }
1176                            }
1177                            catch (Exception e) {
1178                                    throw processException(e);
1179                            }
1180                            finally {
1181                                    if (list == null) {
1182                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1183                                    }
1184                                    else {
1185                                            cacheResult(list);
1186    
1187                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1188                                    }
1189    
1190                                    closeSession(session);
1191                            }
1192                    }
1193    
1194                    return list;
1195            }
1196    
1197            /**
1198             * Removes all the resource block permissions where resourceBlockId = &#63; from the database.
1199             *
1200             * @param resourceBlockId the resource block ID
1201             * @throws SystemException if a system exception occurred
1202             */
1203            public void removeByResourceBlockId(long resourceBlockId)
1204                    throws SystemException {
1205                    for (ResourceBlockPermission resourceBlockPermission : findByResourceBlockId(
1206                                    resourceBlockId)) {
1207                            remove(resourceBlockPermission);
1208                    }
1209            }
1210    
1211            /**
1212             * Removes the resource block permission where resourceBlockId = &#63; and roleId = &#63; from the database.
1213             *
1214             * @param resourceBlockId the resource block ID
1215             * @param roleId the role ID
1216             * @return the resource block permission that was removed
1217             * @throws SystemException if a system exception occurred
1218             */
1219            public ResourceBlockPermission removeByR_R(long resourceBlockId, long roleId)
1220                    throws NoSuchResourceBlockPermissionException, SystemException {
1221                    ResourceBlockPermission resourceBlockPermission = findByR_R(resourceBlockId,
1222                                    roleId);
1223    
1224                    return remove(resourceBlockPermission);
1225            }
1226    
1227            /**
1228             * Removes all the resource block permissions from the database.
1229             *
1230             * @throws SystemException if a system exception occurred
1231             */
1232            public void removeAll() throws SystemException {
1233                    for (ResourceBlockPermission resourceBlockPermission : findAll()) {
1234                            remove(resourceBlockPermission);
1235                    }
1236            }
1237    
1238            /**
1239             * Returns the number of resource block permissions where resourceBlockId = &#63;.
1240             *
1241             * @param resourceBlockId the resource block ID
1242             * @return the number of matching resource block permissions
1243             * @throws SystemException if a system exception occurred
1244             */
1245            public int countByResourceBlockId(long resourceBlockId)
1246                    throws SystemException {
1247                    Object[] finderArgs = new Object[] { resourceBlockId };
1248    
1249                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1250                                    finderArgs, this);
1251    
1252                    if (count == null) {
1253                            StringBundler query = new StringBundler(2);
1254    
1255                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1256    
1257                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
1258    
1259                            String sql = query.toString();
1260    
1261                            Session session = null;
1262    
1263                            try {
1264                                    session = openSession();
1265    
1266                                    Query q = session.createQuery(sql);
1267    
1268                                    QueryPos qPos = QueryPos.getInstance(q);
1269    
1270                                    qPos.add(resourceBlockId);
1271    
1272                                    count = (Long)q.uniqueResult();
1273                            }
1274                            catch (Exception e) {
1275                                    throw processException(e);
1276                            }
1277                            finally {
1278                                    if (count == null) {
1279                                            count = Long.valueOf(0);
1280                                    }
1281    
1282                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1283                                            finderArgs, count);
1284    
1285                                    closeSession(session);
1286                            }
1287                    }
1288    
1289                    return count.intValue();
1290            }
1291    
1292            /**
1293             * Returns the number of resource block permissions where resourceBlockId = &#63; and roleId = &#63;.
1294             *
1295             * @param resourceBlockId the resource block ID
1296             * @param roleId the role ID
1297             * @return the number of matching resource block permissions
1298             * @throws SystemException if a system exception occurred
1299             */
1300            public int countByR_R(long resourceBlockId, long roleId)
1301                    throws SystemException {
1302                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
1303    
1304                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_R,
1305                                    finderArgs, this);
1306    
1307                    if (count == null) {
1308                            StringBundler query = new StringBundler(3);
1309    
1310                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1311    
1312                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1313    
1314                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1315    
1316                            String sql = query.toString();
1317    
1318                            Session session = null;
1319    
1320                            try {
1321                                    session = openSession();
1322    
1323                                    Query q = session.createQuery(sql);
1324    
1325                                    QueryPos qPos = QueryPos.getInstance(q);
1326    
1327                                    qPos.add(resourceBlockId);
1328    
1329                                    qPos.add(roleId);
1330    
1331                                    count = (Long)q.uniqueResult();
1332                            }
1333                            catch (Exception e) {
1334                                    throw processException(e);
1335                            }
1336                            finally {
1337                                    if (count == null) {
1338                                            count = Long.valueOf(0);
1339                                    }
1340    
1341                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, finderArgs,
1342                                            count);
1343    
1344                                    closeSession(session);
1345                            }
1346                    }
1347    
1348                    return count.intValue();
1349            }
1350    
1351            /**
1352             * Returns the number of resource block permissions.
1353             *
1354             * @return the number of resource block permissions
1355             * @throws SystemException if a system exception occurred
1356             */
1357            public int countAll() throws SystemException {
1358                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1359                                    FINDER_ARGS_EMPTY, this);
1360    
1361                    if (count == null) {
1362                            Session session = null;
1363    
1364                            try {
1365                                    session = openSession();
1366    
1367                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCKPERMISSION);
1368    
1369                                    count = (Long)q.uniqueResult();
1370                            }
1371                            catch (Exception e) {
1372                                    throw processException(e);
1373                            }
1374                            finally {
1375                                    if (count == null) {
1376                                            count = Long.valueOf(0);
1377                                    }
1378    
1379                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1380                                            FINDER_ARGS_EMPTY, count);
1381    
1382                                    closeSession(session);
1383                            }
1384                    }
1385    
1386                    return count.intValue();
1387            }
1388    
1389            /**
1390             * Initializes the resource block permission persistence.
1391             */
1392            public void afterPropertiesSet() {
1393                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1394                                            com.liferay.portal.util.PropsUtil.get(
1395                                                    "value.object.listener.com.liferay.portal.model.ResourceBlockPermission")));
1396    
1397                    if (listenerClassNames.length > 0) {
1398                            try {
1399                                    List<ModelListener<ResourceBlockPermission>> listenersList = new ArrayList<ModelListener<ResourceBlockPermission>>();
1400    
1401                                    for (String listenerClassName : listenerClassNames) {
1402                                            Class<?> clazz = getClass();
1403    
1404                                            listenersList.add((ModelListener<ResourceBlockPermission>)InstanceFactory.newInstance(
1405                                                            clazz.getClassLoader(), listenerClassName));
1406                                    }
1407    
1408                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1409                            }
1410                            catch (Exception e) {
1411                                    _log.error(e);
1412                            }
1413                    }
1414            }
1415    
1416            public void destroy() {
1417                    EntityCacheUtil.removeCache(ResourceBlockPermissionImpl.class.getName());
1418                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1419                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1420            }
1421    
1422            @BeanReference(type = AccountPersistence.class)
1423            protected AccountPersistence accountPersistence;
1424            @BeanReference(type = AddressPersistence.class)
1425            protected AddressPersistence addressPersistence;
1426            @BeanReference(type = BrowserTrackerPersistence.class)
1427            protected BrowserTrackerPersistence browserTrackerPersistence;
1428            @BeanReference(type = ClassNamePersistence.class)
1429            protected ClassNamePersistence classNamePersistence;
1430            @BeanReference(type = ClusterGroupPersistence.class)
1431            protected ClusterGroupPersistence clusterGroupPersistence;
1432            @BeanReference(type = CompanyPersistence.class)
1433            protected CompanyPersistence companyPersistence;
1434            @BeanReference(type = ContactPersistence.class)
1435            protected ContactPersistence contactPersistence;
1436            @BeanReference(type = CountryPersistence.class)
1437            protected CountryPersistence countryPersistence;
1438            @BeanReference(type = EmailAddressPersistence.class)
1439            protected EmailAddressPersistence emailAddressPersistence;
1440            @BeanReference(type = GroupPersistence.class)
1441            protected GroupPersistence groupPersistence;
1442            @BeanReference(type = ImagePersistence.class)
1443            protected ImagePersistence imagePersistence;
1444            @BeanReference(type = LayoutPersistence.class)
1445            protected LayoutPersistence layoutPersistence;
1446            @BeanReference(type = LayoutBranchPersistence.class)
1447            protected LayoutBranchPersistence layoutBranchPersistence;
1448            @BeanReference(type = LayoutPrototypePersistence.class)
1449            protected LayoutPrototypePersistence layoutPrototypePersistence;
1450            @BeanReference(type = LayoutRevisionPersistence.class)
1451            protected LayoutRevisionPersistence layoutRevisionPersistence;
1452            @BeanReference(type = LayoutSetPersistence.class)
1453            protected LayoutSetPersistence layoutSetPersistence;
1454            @BeanReference(type = LayoutSetBranchPersistence.class)
1455            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1456            @BeanReference(type = LayoutSetPrototypePersistence.class)
1457            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1458            @BeanReference(type = ListTypePersistence.class)
1459            protected ListTypePersistence listTypePersistence;
1460            @BeanReference(type = LockPersistence.class)
1461            protected LockPersistence lockPersistence;
1462            @BeanReference(type = MembershipRequestPersistence.class)
1463            protected MembershipRequestPersistence membershipRequestPersistence;
1464            @BeanReference(type = OrganizationPersistence.class)
1465            protected OrganizationPersistence organizationPersistence;
1466            @BeanReference(type = OrgGroupPermissionPersistence.class)
1467            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1468            @BeanReference(type = OrgGroupRolePersistence.class)
1469            protected OrgGroupRolePersistence orgGroupRolePersistence;
1470            @BeanReference(type = OrgLaborPersistence.class)
1471            protected OrgLaborPersistence orgLaborPersistence;
1472            @BeanReference(type = PasswordPolicyPersistence.class)
1473            protected PasswordPolicyPersistence passwordPolicyPersistence;
1474            @BeanReference(type = PasswordPolicyRelPersistence.class)
1475            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1476            @BeanReference(type = PasswordTrackerPersistence.class)
1477            protected PasswordTrackerPersistence passwordTrackerPersistence;
1478            @BeanReference(type = PermissionPersistence.class)
1479            protected PermissionPersistence permissionPersistence;
1480            @BeanReference(type = PhonePersistence.class)
1481            protected PhonePersistence phonePersistence;
1482            @BeanReference(type = PluginSettingPersistence.class)
1483            protected PluginSettingPersistence pluginSettingPersistence;
1484            @BeanReference(type = PortalPreferencesPersistence.class)
1485            protected PortalPreferencesPersistence portalPreferencesPersistence;
1486            @BeanReference(type = PortletPersistence.class)
1487            protected PortletPersistence portletPersistence;
1488            @BeanReference(type = PortletItemPersistence.class)
1489            protected PortletItemPersistence portletItemPersistence;
1490            @BeanReference(type = PortletPreferencesPersistence.class)
1491            protected PortletPreferencesPersistence portletPreferencesPersistence;
1492            @BeanReference(type = RegionPersistence.class)
1493            protected RegionPersistence regionPersistence;
1494            @BeanReference(type = ReleasePersistence.class)
1495            protected ReleasePersistence releasePersistence;
1496            @BeanReference(type = RepositoryPersistence.class)
1497            protected RepositoryPersistence repositoryPersistence;
1498            @BeanReference(type = RepositoryEntryPersistence.class)
1499            protected RepositoryEntryPersistence repositoryEntryPersistence;
1500            @BeanReference(type = ResourcePersistence.class)
1501            protected ResourcePersistence resourcePersistence;
1502            @BeanReference(type = ResourceActionPersistence.class)
1503            protected ResourceActionPersistence resourceActionPersistence;
1504            @BeanReference(type = ResourceBlockPersistence.class)
1505            protected ResourceBlockPersistence resourceBlockPersistence;
1506            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1507            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1508            @BeanReference(type = ResourceCodePersistence.class)
1509            protected ResourceCodePersistence resourceCodePersistence;
1510            @BeanReference(type = ResourcePermissionPersistence.class)
1511            protected ResourcePermissionPersistence resourcePermissionPersistence;
1512            @BeanReference(type = ResourceTypePermissionPersistence.class)
1513            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1514            @BeanReference(type = RolePersistence.class)
1515            protected RolePersistence rolePersistence;
1516            @BeanReference(type = ServiceComponentPersistence.class)
1517            protected ServiceComponentPersistence serviceComponentPersistence;
1518            @BeanReference(type = ShardPersistence.class)
1519            protected ShardPersistence shardPersistence;
1520            @BeanReference(type = SubscriptionPersistence.class)
1521            protected SubscriptionPersistence subscriptionPersistence;
1522            @BeanReference(type = TeamPersistence.class)
1523            protected TeamPersistence teamPersistence;
1524            @BeanReference(type = TicketPersistence.class)
1525            protected TicketPersistence ticketPersistence;
1526            @BeanReference(type = UserPersistence.class)
1527            protected UserPersistence userPersistence;
1528            @BeanReference(type = UserGroupPersistence.class)
1529            protected UserGroupPersistence userGroupPersistence;
1530            @BeanReference(type = UserGroupGroupRolePersistence.class)
1531            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1532            @BeanReference(type = UserGroupRolePersistence.class)
1533            protected UserGroupRolePersistence userGroupRolePersistence;
1534            @BeanReference(type = UserIdMapperPersistence.class)
1535            protected UserIdMapperPersistence userIdMapperPersistence;
1536            @BeanReference(type = UserNotificationEventPersistence.class)
1537            protected UserNotificationEventPersistence userNotificationEventPersistence;
1538            @BeanReference(type = UserTrackerPersistence.class)
1539            protected UserTrackerPersistence userTrackerPersistence;
1540            @BeanReference(type = UserTrackerPathPersistence.class)
1541            protected UserTrackerPathPersistence userTrackerPathPersistence;
1542            @BeanReference(type = VirtualHostPersistence.class)
1543            protected VirtualHostPersistence virtualHostPersistence;
1544            @BeanReference(type = WebDAVPropsPersistence.class)
1545            protected WebDAVPropsPersistence webDAVPropsPersistence;
1546            @BeanReference(type = WebsitePersistence.class)
1547            protected WebsitePersistence websitePersistence;
1548            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1549            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1550            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1551            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1552            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission";
1553            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE ";
1554            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission";
1555            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission WHERE ";
1556            private static final String _FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2 =
1557                    "resourceBlockPermission.resourceBlockId = ?";
1558            private static final String _FINDER_COLUMN_R_R_RESOURCEBLOCKID_2 = "resourceBlockPermission.resourceBlockId = ? AND ";
1559            private static final String _FINDER_COLUMN_R_R_ROLEID_2 = "resourceBlockPermission.roleId = ?";
1560            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlockPermission.";
1561            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlockPermission exists with the primary key ";
1562            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlockPermission exists with the key {";
1563            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1564            private static Log _log = LogFactoryUtil.getLog(ResourceBlockPermissionPersistenceImpl.class);
1565            private static ResourceBlockPermission _nullResourceBlockPermission = new ResourceBlockPermissionImpl() {
1566                            @Override
1567                            public Object clone() {
1568                                    return this;
1569                            }
1570    
1571                            @Override
1572                            public CacheModel<ResourceBlockPermission> toCacheModel() {
1573                                    return _nullResourceBlockPermissionCacheModel;
1574                            }
1575                    };
1576    
1577            private static CacheModel<ResourceBlockPermission> _nullResourceBlockPermissionCacheModel =
1578                    new CacheModel<ResourceBlockPermission>() {
1579                            public ResourceBlockPermission toEntityModel() {
1580                                    return _nullResourceBlockPermission;
1581                            }
1582                    };
1583    }