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