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