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