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