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