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_WITH_PAGINATION, "findAll", new String[0]);
111            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
112                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
113                            ResourceBlockPermissionImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
116                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
118    
119            /**
120             * Caches the resource block permission in the entity cache if it is enabled.
121             *
122             * @param resourceBlockPermission the resource block permission
123             */
124            public void cacheResult(ResourceBlockPermission resourceBlockPermission) {
125                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
126                            ResourceBlockPermissionImpl.class,
127                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
128    
129                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
130                            new Object[] {
131                                    Long.valueOf(resourceBlockPermission.getResourceBlockId()),
132                                    Long.valueOf(resourceBlockPermission.getRoleId())
133                            }, resourceBlockPermission);
134    
135                    resourceBlockPermission.resetOriginalValues();
136            }
137    
138            /**
139             * Caches the resource block permissions in the entity cache if it is enabled.
140             *
141             * @param resourceBlockPermissions the resource block permissions
142             */
143            public void cacheResult(
144                    List<ResourceBlockPermission> resourceBlockPermissions) {
145                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
146                            if (EntityCacheUtil.getResult(
147                                                    ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
148                                                    ResourceBlockPermissionImpl.class,
149                                                    resourceBlockPermission.getPrimaryKey()) == null) {
150                                    cacheResult(resourceBlockPermission);
151                            }
152                            else {
153                                    resourceBlockPermission.resetOriginalValues();
154                            }
155                    }
156            }
157    
158            /**
159             * Clears the cache for all resource block permissions.
160             *
161             * <p>
162             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
163             * </p>
164             */
165            @Override
166            public void clearCache() {
167                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
168                            CacheRegistryUtil.clear(ResourceBlockPermissionImpl.class.getName());
169                    }
170    
171                    EntityCacheUtil.clearCache(ResourceBlockPermissionImpl.class.getName());
172    
173                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
174                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
175                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
176            }
177    
178            /**
179             * Clears the cache for the resource block permission.
180             *
181             * <p>
182             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
183             * </p>
184             */
185            @Override
186            public void clearCache(ResourceBlockPermission resourceBlockPermission) {
187                    EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
188                            ResourceBlockPermissionImpl.class,
189                            resourceBlockPermission.getPrimaryKey());
190    
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193    
194                    clearUniqueFindersCache(resourceBlockPermission);
195            }
196    
197            @Override
198            public void clearCache(
199                    List<ResourceBlockPermission> resourceBlockPermissions) {
200                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
201                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
202    
203                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
204                            EntityCacheUtil.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
205                                    ResourceBlockPermissionImpl.class,
206                                    resourceBlockPermission.getPrimaryKey());
207    
208                            clearUniqueFindersCache(resourceBlockPermission);
209                    }
210            }
211    
212            protected void 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                    else {
347                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
348                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID.getColumnBitmask()) != 0) {
349                                    Object[] args = new Object[] {
350                                                    Long.valueOf(resourceBlockPermissionModelImpl.getOriginalResourceBlockId())
351                                            };
352    
353                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
354                                            args);
355                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
356                                            args);
357    
358                                    args = new Object[] {
359                                                    Long.valueOf(resourceBlockPermissionModelImpl.getResourceBlockId())
360                                            };
361    
362                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
363                                            args);
364                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
365                                            args);
366                            }
367                    }
368    
369                    EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
370                            ResourceBlockPermissionImpl.class,
371                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
372    
373                    if (isNew) {
374                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
375                                    new Object[] {
376                                            Long.valueOf(resourceBlockPermission.getResourceBlockId()),
377                                            Long.valueOf(resourceBlockPermission.getRoleId())
378                                    }, resourceBlockPermission);
379                    }
380                    else {
381                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
382                                            FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
383                                    Object[] args = new Object[] {
384                                                    Long.valueOf(resourceBlockPermissionModelImpl.getOriginalResourceBlockId()),
385                                                    Long.valueOf(resourceBlockPermissionModelImpl.getOriginalRoleId())
386                                            };
387    
388                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
389                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
390    
391                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
392                                            new Object[] {
393                                                    Long.valueOf(
394                                                            resourceBlockPermission.getResourceBlockId()),
395                                                    Long.valueOf(resourceBlockPermission.getRoleId())
396                                            }, resourceBlockPermission);
397                            }
398                    }
399    
400                    return resourceBlockPermission;
401            }
402    
403            protected ResourceBlockPermission toUnwrappedModel(
404                    ResourceBlockPermission resourceBlockPermission) {
405                    if (resourceBlockPermission instanceof ResourceBlockPermissionImpl) {
406                            return resourceBlockPermission;
407                    }
408    
409                    ResourceBlockPermissionImpl resourceBlockPermissionImpl = new ResourceBlockPermissionImpl();
410    
411                    resourceBlockPermissionImpl.setNew(resourceBlockPermission.isNew());
412                    resourceBlockPermissionImpl.setPrimaryKey(resourceBlockPermission.getPrimaryKey());
413    
414                    resourceBlockPermissionImpl.setResourceBlockPermissionId(resourceBlockPermission.getResourceBlockPermissionId());
415                    resourceBlockPermissionImpl.setResourceBlockId(resourceBlockPermission.getResourceBlockId());
416                    resourceBlockPermissionImpl.setRoleId(resourceBlockPermission.getRoleId());
417                    resourceBlockPermissionImpl.setActionIds(resourceBlockPermission.getActionIds());
418    
419                    return resourceBlockPermissionImpl;
420            }
421    
422            /**
423             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
424             *
425             * @param primaryKey the primary key of the resource block permission
426             * @return the resource block permission
427             * @throws com.liferay.portal.NoSuchModelException if a resource block permission with the primary key could not be found
428             * @throws SystemException if a system exception occurred
429             */
430            @Override
431            public ResourceBlockPermission findByPrimaryKey(Serializable primaryKey)
432                    throws NoSuchModelException, SystemException {
433                    return findByPrimaryKey(((Long)primaryKey).longValue());
434            }
435    
436            /**
437             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.NoSuchResourceBlockPermissionException} if it could not be found.
438             *
439             * @param resourceBlockPermissionId the primary key of the resource block permission
440             * @return the resource block permission
441             * @throws com.liferay.portal.NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
442             * @throws SystemException if a system exception occurred
443             */
444            public ResourceBlockPermission findByPrimaryKey(
445                    long resourceBlockPermissionId)
446                    throws NoSuchResourceBlockPermissionException, SystemException {
447                    ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(resourceBlockPermissionId);
448    
449                    if (resourceBlockPermission == null) {
450                            if (_log.isWarnEnabled()) {
451                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
452                                            resourceBlockPermissionId);
453                            }
454    
455                            throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
456                                    resourceBlockPermissionId);
457                    }
458    
459                    return resourceBlockPermission;
460            }
461    
462            /**
463             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
464             *
465             * @param primaryKey the primary key of the resource block permission
466             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
467             * @throws SystemException if a system exception occurred
468             */
469            @Override
470            public ResourceBlockPermission fetchByPrimaryKey(Serializable primaryKey)
471                    throws SystemException {
472                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
473            }
474    
475            /**
476             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
477             *
478             * @param resourceBlockPermissionId the primary key of the resource block permission
479             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
480             * @throws SystemException if a system exception occurred
481             */
482            public ResourceBlockPermission fetchByPrimaryKey(
483                    long resourceBlockPermissionId) throws SystemException {
484                    ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)EntityCacheUtil.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
485                                    ResourceBlockPermissionImpl.class, resourceBlockPermissionId);
486    
487                    if (resourceBlockPermission == _nullResourceBlockPermission) {
488                            return null;
489                    }
490    
491                    if (resourceBlockPermission == null) {
492                            Session session = null;
493    
494                            boolean hasException = false;
495    
496                            try {
497                                    session = openSession();
498    
499                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
500                                                    Long.valueOf(resourceBlockPermissionId));
501                            }
502                            catch (Exception e) {
503                                    hasException = true;
504    
505                                    throw processException(e);
506                            }
507                            finally {
508                                    if (resourceBlockPermission != null) {
509                                            cacheResult(resourceBlockPermission);
510                                    }
511                                    else if (!hasException) {
512                                            EntityCacheUtil.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
513                                                    ResourceBlockPermissionImpl.class,
514                                                    resourceBlockPermissionId, _nullResourceBlockPermission);
515                                    }
516    
517                                    closeSession(session);
518                            }
519                    }
520    
521                    return resourceBlockPermission;
522            }
523    
524            /**
525             * Returns all the resource block permissions where resourceBlockId = &#63;.
526             *
527             * @param resourceBlockId the resource block ID
528             * @return the matching resource block permissions
529             * @throws SystemException if a system exception occurred
530             */
531            public List<ResourceBlockPermission> findByResourceBlockId(
532                    long resourceBlockId) throws SystemException {
533                    return findByResourceBlockId(resourceBlockId, QueryUtil.ALL_POS,
534                            QueryUtil.ALL_POS, null);
535            }
536    
537            /**
538             * Returns a range of all the resource block permissions where resourceBlockId = &#63;.
539             *
540             * <p>
541             * 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.
542             * </p>
543             *
544             * @param resourceBlockId the resource block ID
545             * @param start the lower bound of the range of resource block permissions
546             * @param end the upper bound of the range of resource block permissions (not inclusive)
547             * @return the range of matching resource block permissions
548             * @throws SystemException if a system exception occurred
549             */
550            public List<ResourceBlockPermission> findByResourceBlockId(
551                    long resourceBlockId, int start, int end) throws SystemException {
552                    return findByResourceBlockId(resourceBlockId, start, end, null);
553            }
554    
555            /**
556             * Returns an ordered range of all the resource block permissions where resourceBlockId = &#63;.
557             *
558             * <p>
559             * 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.
560             * </p>
561             *
562             * @param resourceBlockId the resource block ID
563             * @param start the lower bound of the range of resource block permissions
564             * @param end the upper bound of the range of resource block permissions (not inclusive)
565             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
566             * @return the ordered range of matching resource block permissions
567             * @throws SystemException if a system exception occurred
568             */
569            public List<ResourceBlockPermission> findByResourceBlockId(
570                    long resourceBlockId, int start, int end,
571                    OrderByComparator orderByComparator) throws SystemException {
572                    FinderPath finderPath = null;
573                    Object[] finderArgs = null;
574    
575                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
576                                    (orderByComparator == null)) {
577                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID;
578                            finderArgs = new Object[] { resourceBlockId };
579                    }
580                    else {
581                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID;
582                            finderArgs = new Object[] {
583                                            resourceBlockId,
584                                            
585                                            start, end, orderByComparator
586                                    };
587                    }
588    
589                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
590                                    finderArgs, this);
591    
592                    if ((list != null) && !list.isEmpty()) {
593                            for (ResourceBlockPermission resourceBlockPermission : list) {
594                                    if ((resourceBlockId != resourceBlockPermission.getResourceBlockId())) {
595                                            list = null;
596    
597                                            break;
598                                    }
599                            }
600                    }
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 instanceof ResourceBlockPermission) {
953                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)result;
954    
955                            if ((resourceBlockId != resourceBlockPermission.getResourceBlockId()) ||
956                                            (roleId != resourceBlockPermission.getRoleId())) {
957                                    result = null;
958                            }
959                    }
960    
961                    if (result == null) {
962                            StringBundler query = new StringBundler(3);
963    
964                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
965    
966                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
967    
968                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
969    
970                            String sql = query.toString();
971    
972                            Session session = null;
973    
974                            try {
975                                    session = openSession();
976    
977                                    Query q = session.createQuery(sql);
978    
979                                    QueryPos qPos = QueryPos.getInstance(q);
980    
981                                    qPos.add(resourceBlockId);
982    
983                                    qPos.add(roleId);
984    
985                                    List<ResourceBlockPermission> list = q.list();
986    
987                                    result = list;
988    
989                                    ResourceBlockPermission resourceBlockPermission = null;
990    
991                                    if (list.isEmpty()) {
992                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
993                                                    finderArgs, list);
994                                    }
995                                    else {
996                                            resourceBlockPermission = list.get(0);
997    
998                                            cacheResult(resourceBlockPermission);
999    
1000                                            if ((resourceBlockPermission.getResourceBlockId() != resourceBlockId) ||
1001                                                            (resourceBlockPermission.getRoleId() != roleId)) {
1002                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_R_R,
1003                                                            finderArgs, resourceBlockPermission);
1004                                            }
1005                                    }
1006    
1007                                    return resourceBlockPermission;
1008                            }
1009                            catch (Exception e) {
1010                                    throw processException(e);
1011                            }
1012                            finally {
1013                                    if (result == null) {
1014                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_R_R,
1015                                                    finderArgs);
1016                                    }
1017    
1018                                    closeSession(session);
1019                            }
1020                    }
1021                    else {
1022                            if (result instanceof List<?>) {
1023                                    return null;
1024                            }
1025                            else {
1026                                    return (ResourceBlockPermission)result;
1027                            }
1028                    }
1029            }
1030    
1031            /**
1032             * Returns all the resource block permissions.
1033             *
1034             * @return the resource block permissions
1035             * @throws SystemException if a system exception occurred
1036             */
1037            public List<ResourceBlockPermission> findAll() throws SystemException {
1038                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1039            }
1040    
1041            /**
1042             * Returns a range of all the resource block permissions.
1043             *
1044             * <p>
1045             * 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.
1046             * </p>
1047             *
1048             * @param start the lower bound of the range of resource block permissions
1049             * @param end the upper bound of the range of resource block permissions (not inclusive)
1050             * @return the range of resource block permissions
1051             * @throws SystemException if a system exception occurred
1052             */
1053            public List<ResourceBlockPermission> findAll(int start, int end)
1054                    throws SystemException {
1055                    return findAll(start, end, null);
1056            }
1057    
1058            /**
1059             * Returns an ordered range of all the resource block permissions.
1060             *
1061             * <p>
1062             * 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.
1063             * </p>
1064             *
1065             * @param start the lower bound of the range of resource block permissions
1066             * @param end the upper bound of the range of resource block permissions (not inclusive)
1067             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1068             * @return the ordered range of resource block permissions
1069             * @throws SystemException if a system exception occurred
1070             */
1071            public List<ResourceBlockPermission> findAll(int start, int end,
1072                    OrderByComparator orderByComparator) throws SystemException {
1073                    FinderPath finderPath = null;
1074                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1075    
1076                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1077                                    (orderByComparator == null)) {
1078                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1079                            finderArgs = FINDER_ARGS_EMPTY;
1080                    }
1081                    else {
1082                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1083                            finderArgs = new Object[] { start, end, orderByComparator };
1084                    }
1085    
1086                    List<ResourceBlockPermission> list = (List<ResourceBlockPermission>)FinderCacheUtil.getResult(finderPath,
1087                                    finderArgs, this);
1088    
1089                    if (list == null) {
1090                            StringBundler query = null;
1091                            String sql = null;
1092    
1093                            if (orderByComparator != null) {
1094                                    query = new StringBundler(2 +
1095                                                    (orderByComparator.getOrderByFields().length * 3));
1096    
1097                                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION);
1098    
1099                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1100                                            orderByComparator);
1101    
1102                                    sql = query.toString();
1103                            }
1104                            else {
1105                                    sql = _SQL_SELECT_RESOURCEBLOCKPERMISSION;
1106                            }
1107    
1108                            Session session = null;
1109    
1110                            try {
1111                                    session = openSession();
1112    
1113                                    Query q = session.createQuery(sql);
1114    
1115                                    if (orderByComparator == null) {
1116                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1117                                                            getDialect(), start, end, false);
1118    
1119                                            Collections.sort(list);
1120                                    }
1121                                    else {
1122                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
1123                                                            getDialect(), start, end);
1124                                    }
1125                            }
1126                            catch (Exception e) {
1127                                    throw processException(e);
1128                            }
1129                            finally {
1130                                    if (list == null) {
1131                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1132                                    }
1133                                    else {
1134                                            cacheResult(list);
1135    
1136                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1137                                    }
1138    
1139                                    closeSession(session);
1140                            }
1141                    }
1142    
1143                    return list;
1144            }
1145    
1146            /**
1147             * Removes all the resource block permissions where resourceBlockId = &#63; from the database.
1148             *
1149             * @param resourceBlockId the resource block ID
1150             * @throws SystemException if a system exception occurred
1151             */
1152            public void removeByResourceBlockId(long resourceBlockId)
1153                    throws SystemException {
1154                    for (ResourceBlockPermission resourceBlockPermission : findByResourceBlockId(
1155                                    resourceBlockId)) {
1156                            remove(resourceBlockPermission);
1157                    }
1158            }
1159    
1160            /**
1161             * Removes the resource block permission where resourceBlockId = &#63; and roleId = &#63; from the database.
1162             *
1163             * @param resourceBlockId the resource block ID
1164             * @param roleId the role ID
1165             * @throws SystemException if a system exception occurred
1166             */
1167            public void removeByR_R(long resourceBlockId, long roleId)
1168                    throws NoSuchResourceBlockPermissionException, SystemException {
1169                    ResourceBlockPermission resourceBlockPermission = findByR_R(resourceBlockId,
1170                                    roleId);
1171    
1172                    remove(resourceBlockPermission);
1173            }
1174    
1175            /**
1176             * Removes all the resource block permissions from the database.
1177             *
1178             * @throws SystemException if a system exception occurred
1179             */
1180            public void removeAll() throws SystemException {
1181                    for (ResourceBlockPermission resourceBlockPermission : findAll()) {
1182                            remove(resourceBlockPermission);
1183                    }
1184            }
1185    
1186            /**
1187             * Returns the number of resource block permissions where resourceBlockId = &#63;.
1188             *
1189             * @param resourceBlockId the resource block ID
1190             * @return the number of matching resource block permissions
1191             * @throws SystemException if a system exception occurred
1192             */
1193            public int countByResourceBlockId(long resourceBlockId)
1194                    throws SystemException {
1195                    Object[] finderArgs = new Object[] { resourceBlockId };
1196    
1197                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1198                                    finderArgs, this);
1199    
1200                    if (count == null) {
1201                            StringBundler query = new StringBundler(2);
1202    
1203                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1204    
1205                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
1206    
1207                            String sql = query.toString();
1208    
1209                            Session session = null;
1210    
1211                            try {
1212                                    session = openSession();
1213    
1214                                    Query q = session.createQuery(sql);
1215    
1216                                    QueryPos qPos = QueryPos.getInstance(q);
1217    
1218                                    qPos.add(resourceBlockId);
1219    
1220                                    count = (Long)q.uniqueResult();
1221                            }
1222                            catch (Exception e) {
1223                                    throw processException(e);
1224                            }
1225                            finally {
1226                                    if (count == null) {
1227                                            count = Long.valueOf(0);
1228                                    }
1229    
1230                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1231                                            finderArgs, count);
1232    
1233                                    closeSession(session);
1234                            }
1235                    }
1236    
1237                    return count.intValue();
1238            }
1239    
1240            /**
1241             * Returns the number of resource block permissions where resourceBlockId = &#63; and roleId = &#63;.
1242             *
1243             * @param resourceBlockId the resource block ID
1244             * @param roleId the role ID
1245             * @return the number of matching resource block permissions
1246             * @throws SystemException if a system exception occurred
1247             */
1248            public int countByR_R(long resourceBlockId, long roleId)
1249                    throws SystemException {
1250                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
1251    
1252                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_R,
1253                                    finderArgs, this);
1254    
1255                    if (count == null) {
1256                            StringBundler query = new StringBundler(3);
1257    
1258                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1259    
1260                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1261    
1262                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1263    
1264                            String sql = query.toString();
1265    
1266                            Session session = null;
1267    
1268                            try {
1269                                    session = openSession();
1270    
1271                                    Query q = session.createQuery(sql);
1272    
1273                                    QueryPos qPos = QueryPos.getInstance(q);
1274    
1275                                    qPos.add(resourceBlockId);
1276    
1277                                    qPos.add(roleId);
1278    
1279                                    count = (Long)q.uniqueResult();
1280                            }
1281                            catch (Exception e) {
1282                                    throw processException(e);
1283                            }
1284                            finally {
1285                                    if (count == null) {
1286                                            count = Long.valueOf(0);
1287                                    }
1288    
1289                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_R, finderArgs,
1290                                            count);
1291    
1292                                    closeSession(session);
1293                            }
1294                    }
1295    
1296                    return count.intValue();
1297            }
1298    
1299            /**
1300             * Returns the number of resource block permissions.
1301             *
1302             * @return the number of resource block permissions
1303             * @throws SystemException if a system exception occurred
1304             */
1305            public int countAll() throws SystemException {
1306                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1307                                    FINDER_ARGS_EMPTY, this);
1308    
1309                    if (count == null) {
1310                            Session session = null;
1311    
1312                            try {
1313                                    session = openSession();
1314    
1315                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCKPERMISSION);
1316    
1317                                    count = (Long)q.uniqueResult();
1318                            }
1319                            catch (Exception e) {
1320                                    throw processException(e);
1321                            }
1322                            finally {
1323                                    if (count == null) {
1324                                            count = Long.valueOf(0);
1325                                    }
1326    
1327                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1328                                            FINDER_ARGS_EMPTY, count);
1329    
1330                                    closeSession(session);
1331                            }
1332                    }
1333    
1334                    return count.intValue();
1335            }
1336    
1337            /**
1338             * Initializes the resource block permission persistence.
1339             */
1340            public void afterPropertiesSet() {
1341                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1342                                            com.liferay.portal.util.PropsUtil.get(
1343                                                    "value.object.listener.com.liferay.portal.model.ResourceBlockPermission")));
1344    
1345                    if (listenerClassNames.length > 0) {
1346                            try {
1347                                    List<ModelListener<ResourceBlockPermission>> listenersList = new ArrayList<ModelListener<ResourceBlockPermission>>();
1348    
1349                                    for (String listenerClassName : listenerClassNames) {
1350                                            listenersList.add((ModelListener<ResourceBlockPermission>)InstanceFactory.newInstance(
1351                                                            listenerClassName));
1352                                    }
1353    
1354                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1355                            }
1356                            catch (Exception e) {
1357                                    _log.error(e);
1358                            }
1359                    }
1360            }
1361    
1362            public void destroy() {
1363                    EntityCacheUtil.removeCache(ResourceBlockPermissionImpl.class.getName());
1364                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1365                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1366            }
1367    
1368            @BeanReference(type = AccountPersistence.class)
1369            protected AccountPersistence accountPersistence;
1370            @BeanReference(type = AddressPersistence.class)
1371            protected AddressPersistence addressPersistence;
1372            @BeanReference(type = BrowserTrackerPersistence.class)
1373            protected BrowserTrackerPersistence browserTrackerPersistence;
1374            @BeanReference(type = ClassNamePersistence.class)
1375            protected ClassNamePersistence classNamePersistence;
1376            @BeanReference(type = ClusterGroupPersistence.class)
1377            protected ClusterGroupPersistence clusterGroupPersistence;
1378            @BeanReference(type = CompanyPersistence.class)
1379            protected CompanyPersistence companyPersistence;
1380            @BeanReference(type = ContactPersistence.class)
1381            protected ContactPersistence contactPersistence;
1382            @BeanReference(type = CountryPersistence.class)
1383            protected CountryPersistence countryPersistence;
1384            @BeanReference(type = EmailAddressPersistence.class)
1385            protected EmailAddressPersistence emailAddressPersistence;
1386            @BeanReference(type = GroupPersistence.class)
1387            protected GroupPersistence groupPersistence;
1388            @BeanReference(type = ImagePersistence.class)
1389            protected ImagePersistence imagePersistence;
1390            @BeanReference(type = LayoutPersistence.class)
1391            protected LayoutPersistence layoutPersistence;
1392            @BeanReference(type = LayoutBranchPersistence.class)
1393            protected LayoutBranchPersistence layoutBranchPersistence;
1394            @BeanReference(type = LayoutPrototypePersistence.class)
1395            protected LayoutPrototypePersistence layoutPrototypePersistence;
1396            @BeanReference(type = LayoutRevisionPersistence.class)
1397            protected LayoutRevisionPersistence layoutRevisionPersistence;
1398            @BeanReference(type = LayoutSetPersistence.class)
1399            protected LayoutSetPersistence layoutSetPersistence;
1400            @BeanReference(type = LayoutSetBranchPersistence.class)
1401            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1402            @BeanReference(type = LayoutSetPrototypePersistence.class)
1403            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1404            @BeanReference(type = ListTypePersistence.class)
1405            protected ListTypePersistence listTypePersistence;
1406            @BeanReference(type = LockPersistence.class)
1407            protected LockPersistence lockPersistence;
1408            @BeanReference(type = MembershipRequestPersistence.class)
1409            protected MembershipRequestPersistence membershipRequestPersistence;
1410            @BeanReference(type = OrganizationPersistence.class)
1411            protected OrganizationPersistence organizationPersistence;
1412            @BeanReference(type = OrgGroupPermissionPersistence.class)
1413            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1414            @BeanReference(type = OrgGroupRolePersistence.class)
1415            protected OrgGroupRolePersistence orgGroupRolePersistence;
1416            @BeanReference(type = OrgLaborPersistence.class)
1417            protected OrgLaborPersistence orgLaborPersistence;
1418            @BeanReference(type = PasswordPolicyPersistence.class)
1419            protected PasswordPolicyPersistence passwordPolicyPersistence;
1420            @BeanReference(type = PasswordPolicyRelPersistence.class)
1421            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1422            @BeanReference(type = PasswordTrackerPersistence.class)
1423            protected PasswordTrackerPersistence passwordTrackerPersistence;
1424            @BeanReference(type = PermissionPersistence.class)
1425            protected PermissionPersistence permissionPersistence;
1426            @BeanReference(type = PhonePersistence.class)
1427            protected PhonePersistence phonePersistence;
1428            @BeanReference(type = PluginSettingPersistence.class)
1429            protected PluginSettingPersistence pluginSettingPersistence;
1430            @BeanReference(type = PortalPreferencesPersistence.class)
1431            protected PortalPreferencesPersistence portalPreferencesPersistence;
1432            @BeanReference(type = PortletPersistence.class)
1433            protected PortletPersistence portletPersistence;
1434            @BeanReference(type = PortletItemPersistence.class)
1435            protected PortletItemPersistence portletItemPersistence;
1436            @BeanReference(type = PortletPreferencesPersistence.class)
1437            protected PortletPreferencesPersistence portletPreferencesPersistence;
1438            @BeanReference(type = RegionPersistence.class)
1439            protected RegionPersistence regionPersistence;
1440            @BeanReference(type = ReleasePersistence.class)
1441            protected ReleasePersistence releasePersistence;
1442            @BeanReference(type = RepositoryPersistence.class)
1443            protected RepositoryPersistence repositoryPersistence;
1444            @BeanReference(type = RepositoryEntryPersistence.class)
1445            protected RepositoryEntryPersistence repositoryEntryPersistence;
1446            @BeanReference(type = ResourcePersistence.class)
1447            protected ResourcePersistence resourcePersistence;
1448            @BeanReference(type = ResourceActionPersistence.class)
1449            protected ResourceActionPersistence resourceActionPersistence;
1450            @BeanReference(type = ResourceBlockPersistence.class)
1451            protected ResourceBlockPersistence resourceBlockPersistence;
1452            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1453            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1454            @BeanReference(type = ResourceCodePersistence.class)
1455            protected ResourceCodePersistence resourceCodePersistence;
1456            @BeanReference(type = ResourcePermissionPersistence.class)
1457            protected ResourcePermissionPersistence resourcePermissionPersistence;
1458            @BeanReference(type = ResourceTypePermissionPersistence.class)
1459            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1460            @BeanReference(type = RolePersistence.class)
1461            protected RolePersistence rolePersistence;
1462            @BeanReference(type = ServiceComponentPersistence.class)
1463            protected ServiceComponentPersistence serviceComponentPersistence;
1464            @BeanReference(type = ShardPersistence.class)
1465            protected ShardPersistence shardPersistence;
1466            @BeanReference(type = SubscriptionPersistence.class)
1467            protected SubscriptionPersistence subscriptionPersistence;
1468            @BeanReference(type = TeamPersistence.class)
1469            protected TeamPersistence teamPersistence;
1470            @BeanReference(type = TicketPersistence.class)
1471            protected TicketPersistence ticketPersistence;
1472            @BeanReference(type = UserPersistence.class)
1473            protected UserPersistence userPersistence;
1474            @BeanReference(type = UserGroupPersistence.class)
1475            protected UserGroupPersistence userGroupPersistence;
1476            @BeanReference(type = UserGroupGroupRolePersistence.class)
1477            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1478            @BeanReference(type = UserGroupRolePersistence.class)
1479            protected UserGroupRolePersistence userGroupRolePersistence;
1480            @BeanReference(type = UserIdMapperPersistence.class)
1481            protected UserIdMapperPersistence userIdMapperPersistence;
1482            @BeanReference(type = UserNotificationEventPersistence.class)
1483            protected UserNotificationEventPersistence userNotificationEventPersistence;
1484            @BeanReference(type = UserTrackerPersistence.class)
1485            protected UserTrackerPersistence userTrackerPersistence;
1486            @BeanReference(type = UserTrackerPathPersistence.class)
1487            protected UserTrackerPathPersistence userTrackerPathPersistence;
1488            @BeanReference(type = VirtualHostPersistence.class)
1489            protected VirtualHostPersistence virtualHostPersistence;
1490            @BeanReference(type = WebDAVPropsPersistence.class)
1491            protected WebDAVPropsPersistence webDAVPropsPersistence;
1492            @BeanReference(type = WebsitePersistence.class)
1493            protected WebsitePersistence websitePersistence;
1494            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1495            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1496            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1497            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1498            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission";
1499            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE ";
1500            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission";
1501            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission WHERE ";
1502            private static final String _FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2 =
1503                    "resourceBlockPermission.resourceBlockId = ?";
1504            private static final String _FINDER_COLUMN_R_R_RESOURCEBLOCKID_2 = "resourceBlockPermission.resourceBlockId = ? AND ";
1505            private static final String _FINDER_COLUMN_R_R_ROLEID_2 = "resourceBlockPermission.roleId = ?";
1506            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlockPermission.";
1507            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlockPermission exists with the primary key ";
1508            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlockPermission exists with the key {";
1509            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1510            private static Log _log = LogFactoryUtil.getLog(ResourceBlockPermissionPersistenceImpl.class);
1511            private static ResourceBlockPermission _nullResourceBlockPermission = new ResourceBlockPermissionImpl() {
1512                            @Override
1513                            public Object clone() {
1514                                    return this;
1515                            }
1516    
1517                            @Override
1518                            public CacheModel<ResourceBlockPermission> toCacheModel() {
1519                                    return _nullResourceBlockPermissionCacheModel;
1520                            }
1521                    };
1522    
1523            private static CacheModel<ResourceBlockPermission> _nullResourceBlockPermissionCacheModel =
1524                    new CacheModel<ResourceBlockPermission>() {
1525                            public ResourceBlockPermission toEntityModel() {
1526                                    return _nullResourceBlockPermission;
1527                            }
1528                    };
1529    }