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