001    /**
002     * Copyright (c) 2000-present 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.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.exception.NoSuchResourceBlockPermissionException;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.model.CacheModel;
033    import com.liferay.portal.kernel.model.MVCCModel;
034    import com.liferay.portal.kernel.model.ResourceBlockPermission;
035    import com.liferay.portal.kernel.service.persistence.CompanyProvider;
036    import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
037    import com.liferay.portal.kernel.service.persistence.ResourceBlockPermissionPersistence;
038    import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.StringBundler;
041    import com.liferay.portal.kernel.util.StringPool;
042    import com.liferay.portal.model.impl.ResourceBlockPermissionImpl;
043    import com.liferay.portal.model.impl.ResourceBlockPermissionModelImpl;
044    
045    import java.io.Serializable;
046    
047    import java.util.Collections;
048    import java.util.HashMap;
049    import java.util.HashSet;
050    import java.util.Iterator;
051    import java.util.List;
052    import java.util.Map;
053    import java.util.Set;
054    
055    /**
056     * The persistence implementation for the resource block permission service.
057     *
058     * <p>
059     * Caching information and settings can be found in <code>portal.properties</code>
060     * </p>
061     *
062     * @author Brian Wing Shun Chan
063     * @see ResourceBlockPermissionPersistence
064     * @see com.liferay.portal.kernel.service.persistence.ResourceBlockPermissionUtil
065     * @generated
066     */
067    @ProviderType
068    public class ResourceBlockPermissionPersistenceImpl extends BasePersistenceImpl<ResourceBlockPermission>
069            implements ResourceBlockPermissionPersistence {
070            /*
071             * NOTE FOR DEVELOPERS:
072             *
073             * 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.
074             */
075            public static final String FINDER_CLASS_NAME_ENTITY = ResourceBlockPermissionImpl.class.getName();
076            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List1";
078            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079                    ".List2";
080            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
081                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
082                            ResourceBlockPermissionImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
085                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
086                            ResourceBlockPermissionImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
089                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID =
092                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
093                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
094                            ResourceBlockPermissionImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByResourceBlockId",
096                            new String[] {
097                                    Long.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID =
103                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
104                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
105                            ResourceBlockPermissionImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourceBlockId",
107                            new String[] { Long.class.getName() },
108                            ResourceBlockPermissionModelImpl.RESOURCEBLOCKID_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEBLOCKID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
110                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
112                            "countByResourceBlockId", new String[] { Long.class.getName() });
113    
114            /**
115             * Returns all the resource block permissions where resourceBlockId = &#63;.
116             *
117             * @param resourceBlockId the resource block ID
118             * @return the matching resource block permissions
119             */
120            @Override
121            public List<ResourceBlockPermission> findByResourceBlockId(
122                    long resourceBlockId) {
123                    return findByResourceBlockId(resourceBlockId, QueryUtil.ALL_POS,
124                            QueryUtil.ALL_POS, null);
125            }
126    
127            /**
128             * Returns a range of all the resource block permissions where resourceBlockId = &#63;.
129             *
130             * <p>
131             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
132             * </p>
133             *
134             * @param resourceBlockId the resource block ID
135             * @param start the lower bound of the range of resource block permissions
136             * @param end the upper bound of the range of resource block permissions (not inclusive)
137             * @return the range of matching resource block permissions
138             */
139            @Override
140            public List<ResourceBlockPermission> findByResourceBlockId(
141                    long resourceBlockId, int start, int end) {
142                    return findByResourceBlockId(resourceBlockId, start, end, null);
143            }
144    
145            /**
146             * Returns an ordered range of all the resource block permissions where resourceBlockId = &#63;.
147             *
148             * <p>
149             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
150             * </p>
151             *
152             * @param resourceBlockId the resource block ID
153             * @param start the lower bound of the range of resource block permissions
154             * @param end the upper bound of the range of resource block permissions (not inclusive)
155             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
156             * @return the ordered range of matching resource block permissions
157             */
158            @Override
159            public List<ResourceBlockPermission> findByResourceBlockId(
160                    long resourceBlockId, int start, int end,
161                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
162                    return findByResourceBlockId(resourceBlockId, start, end,
163                            orderByComparator, true);
164            }
165    
166            /**
167             * Returns an ordered range of all the resource block permissions where resourceBlockId = &#63;.
168             *
169             * <p>
170             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
171             * </p>
172             *
173             * @param resourceBlockId the resource block ID
174             * @param start the lower bound of the range of resource block permissions
175             * @param end the upper bound of the range of resource block permissions (not inclusive)
176             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
177             * @param retrieveFromCache whether to retrieve from the finder cache
178             * @return the ordered range of matching resource block permissions
179             */
180            @Override
181            public List<ResourceBlockPermission> findByResourceBlockId(
182                    long resourceBlockId, int start, int end,
183                    OrderByComparator<ResourceBlockPermission> orderByComparator,
184                    boolean retrieveFromCache) {
185                    boolean pagination = true;
186                    FinderPath finderPath = null;
187                    Object[] finderArgs = null;
188    
189                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
190                                    (orderByComparator == null)) {
191                            pagination = false;
192                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID;
193                            finderArgs = new Object[] { resourceBlockId };
194                    }
195                    else {
196                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEBLOCKID;
197                            finderArgs = new Object[] {
198                                            resourceBlockId,
199                                            
200                                            start, end, orderByComparator
201                                    };
202                    }
203    
204                    List<ResourceBlockPermission> list = null;
205    
206                    if (retrieveFromCache) {
207                            list = (List<ResourceBlockPermission>)finderCache.getResult(finderPath,
208                                            finderArgs, this);
209    
210                            if ((list != null) && !list.isEmpty()) {
211                                    for (ResourceBlockPermission resourceBlockPermission : list) {
212                                            if ((resourceBlockId != resourceBlockPermission.getResourceBlockId())) {
213                                                    list = null;
214    
215                                                    break;
216                                            }
217                                    }
218                            }
219                    }
220    
221                    if (list == null) {
222                            StringBundler query = null;
223    
224                            if (orderByComparator != null) {
225                                    query = new StringBundler(3 +
226                                                    (orderByComparator.getOrderByFields().length * 2));
227                            }
228                            else {
229                                    query = new StringBundler(3);
230                            }
231    
232                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
233    
234                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
235    
236                            if (orderByComparator != null) {
237                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
238                                            orderByComparator);
239                            }
240                            else
241                             if (pagination) {
242                                    query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
243                            }
244    
245                            String sql = query.toString();
246    
247                            Session session = null;
248    
249                            try {
250                                    session = openSession();
251    
252                                    Query q = session.createQuery(sql);
253    
254                                    QueryPos qPos = QueryPos.getInstance(q);
255    
256                                    qPos.add(resourceBlockId);
257    
258                                    if (!pagination) {
259                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
260                                                            getDialect(), start, end, false);
261    
262                                            Collections.sort(list);
263    
264                                            list = Collections.unmodifiableList(list);
265                                    }
266                                    else {
267                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
268                                                            getDialect(), start, end);
269                                    }
270    
271                                    cacheResult(list);
272    
273                                    finderCache.putResult(finderPath, finderArgs, list);
274                            }
275                            catch (Exception e) {
276                                    finderCache.removeResult(finderPath, finderArgs);
277    
278                                    throw processException(e);
279                            }
280                            finally {
281                                    closeSession(session);
282                            }
283                    }
284    
285                    return list;
286            }
287    
288            /**
289             * Returns the first resource block permission in the ordered set where resourceBlockId = &#63;.
290             *
291             * @param resourceBlockId the resource block ID
292             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
293             * @return the first matching resource block permission
294             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
295             */
296            @Override
297            public ResourceBlockPermission findByResourceBlockId_First(
298                    long resourceBlockId,
299                    OrderByComparator<ResourceBlockPermission> orderByComparator)
300                    throws NoSuchResourceBlockPermissionException {
301                    ResourceBlockPermission resourceBlockPermission = fetchByResourceBlockId_First(resourceBlockId,
302                                    orderByComparator);
303    
304                    if (resourceBlockPermission != null) {
305                            return resourceBlockPermission;
306                    }
307    
308                    StringBundler msg = new StringBundler(4);
309    
310                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
311    
312                    msg.append("resourceBlockId=");
313                    msg.append(resourceBlockId);
314    
315                    msg.append(StringPool.CLOSE_CURLY_BRACE);
316    
317                    throw new NoSuchResourceBlockPermissionException(msg.toString());
318            }
319    
320            /**
321             * Returns the first resource block permission in the ordered set where resourceBlockId = &#63;.
322             *
323             * @param resourceBlockId the resource block ID
324             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
325             * @return the first matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
326             */
327            @Override
328            public ResourceBlockPermission fetchByResourceBlockId_First(
329                    long resourceBlockId,
330                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
331                    List<ResourceBlockPermission> list = findByResourceBlockId(resourceBlockId,
332                                    0, 1, orderByComparator);
333    
334                    if (!list.isEmpty()) {
335                            return list.get(0);
336                    }
337    
338                    return null;
339            }
340    
341            /**
342             * Returns the last resource block permission in the ordered set where resourceBlockId = &#63;.
343             *
344             * @param resourceBlockId the resource block ID
345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
346             * @return the last matching resource block permission
347             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
348             */
349            @Override
350            public ResourceBlockPermission findByResourceBlockId_Last(
351                    long resourceBlockId,
352                    OrderByComparator<ResourceBlockPermission> orderByComparator)
353                    throws NoSuchResourceBlockPermissionException {
354                    ResourceBlockPermission resourceBlockPermission = fetchByResourceBlockId_Last(resourceBlockId,
355                                    orderByComparator);
356    
357                    if (resourceBlockPermission != null) {
358                            return resourceBlockPermission;
359                    }
360    
361                    StringBundler msg = new StringBundler(4);
362    
363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
364    
365                    msg.append("resourceBlockId=");
366                    msg.append(resourceBlockId);
367    
368                    msg.append(StringPool.CLOSE_CURLY_BRACE);
369    
370                    throw new NoSuchResourceBlockPermissionException(msg.toString());
371            }
372    
373            /**
374             * Returns the last resource block permission in the ordered set where resourceBlockId = &#63;.
375             *
376             * @param resourceBlockId the resource block ID
377             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
378             * @return the last matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
379             */
380            @Override
381            public ResourceBlockPermission fetchByResourceBlockId_Last(
382                    long resourceBlockId,
383                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
384                    int count = countByResourceBlockId(resourceBlockId);
385    
386                    if (count == 0) {
387                            return null;
388                    }
389    
390                    List<ResourceBlockPermission> list = findByResourceBlockId(resourceBlockId,
391                                    count - 1, count, orderByComparator);
392    
393                    if (!list.isEmpty()) {
394                            return list.get(0);
395                    }
396    
397                    return null;
398            }
399    
400            /**
401             * Returns the resource block permissions before and after the current resource block permission in the ordered set where resourceBlockId = &#63;.
402             *
403             * @param resourceBlockPermissionId the primary key of the current resource block permission
404             * @param resourceBlockId the resource block ID
405             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
406             * @return the previous, current, and next resource block permission
407             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
408             */
409            @Override
410            public ResourceBlockPermission[] findByResourceBlockId_PrevAndNext(
411                    long resourceBlockPermissionId, long resourceBlockId,
412                    OrderByComparator<ResourceBlockPermission> orderByComparator)
413                    throws NoSuchResourceBlockPermissionException {
414                    ResourceBlockPermission resourceBlockPermission = findByPrimaryKey(resourceBlockPermissionId);
415    
416                    Session session = null;
417    
418                    try {
419                            session = openSession();
420    
421                            ResourceBlockPermission[] array = new ResourceBlockPermissionImpl[3];
422    
423                            array[0] = getByResourceBlockId_PrevAndNext(session,
424                                            resourceBlockPermission, resourceBlockId,
425                                            orderByComparator, true);
426    
427                            array[1] = resourceBlockPermission;
428    
429                            array[2] = getByResourceBlockId_PrevAndNext(session,
430                                            resourceBlockPermission, resourceBlockId,
431                                            orderByComparator, false);
432    
433                            return array;
434                    }
435                    catch (Exception e) {
436                            throw processException(e);
437                    }
438                    finally {
439                            closeSession(session);
440                    }
441            }
442    
443            protected ResourceBlockPermission getByResourceBlockId_PrevAndNext(
444                    Session session, ResourceBlockPermission resourceBlockPermission,
445                    long resourceBlockId,
446                    OrderByComparator<ResourceBlockPermission> orderByComparator,
447                    boolean previous) {
448                    StringBundler query = null;
449    
450                    if (orderByComparator != null) {
451                            query = new StringBundler(4 +
452                                            (orderByComparator.getOrderByConditionFields().length * 3) +
453                                            (orderByComparator.getOrderByFields().length * 3));
454                    }
455                    else {
456                            query = new StringBundler(3);
457                    }
458    
459                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
460    
461                    query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
462    
463                    if (orderByComparator != null) {
464                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
465    
466                            if (orderByConditionFields.length > 0) {
467                                    query.append(WHERE_AND);
468                            }
469    
470                            for (int i = 0; i < orderByConditionFields.length; i++) {
471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
472                                    query.append(orderByConditionFields[i]);
473    
474                                    if ((i + 1) < orderByConditionFields.length) {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
477                                            }
478                                            else {
479                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
480                                            }
481                                    }
482                                    else {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(WHERE_GREATER_THAN);
485                                            }
486                                            else {
487                                                    query.append(WHERE_LESSER_THAN);
488                                            }
489                                    }
490                            }
491    
492                            query.append(ORDER_BY_CLAUSE);
493    
494                            String[] orderByFields = orderByComparator.getOrderByFields();
495    
496                            for (int i = 0; i < orderByFields.length; i++) {
497                                    query.append(_ORDER_BY_ENTITY_ALIAS);
498                                    query.append(orderByFields[i]);
499    
500                                    if ((i + 1) < orderByFields.length) {
501                                            if (orderByComparator.isAscending() ^ previous) {
502                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
503                                            }
504                                            else {
505                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
506                                            }
507                                    }
508                                    else {
509                                            if (orderByComparator.isAscending() ^ previous) {
510                                                    query.append(ORDER_BY_ASC);
511                                            }
512                                            else {
513                                                    query.append(ORDER_BY_DESC);
514                                            }
515                                    }
516                            }
517                    }
518                    else {
519                            query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
520                    }
521    
522                    String sql = query.toString();
523    
524                    Query q = session.createQuery(sql);
525    
526                    q.setFirstResult(0);
527                    q.setMaxResults(2);
528    
529                    QueryPos qPos = QueryPos.getInstance(q);
530    
531                    qPos.add(resourceBlockId);
532    
533                    if (orderByComparator != null) {
534                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlockPermission);
535    
536                            for (Object value : values) {
537                                    qPos.add(value);
538                            }
539                    }
540    
541                    List<ResourceBlockPermission> list = q.list();
542    
543                    if (list.size() == 2) {
544                            return list.get(1);
545                    }
546                    else {
547                            return null;
548                    }
549            }
550    
551            /**
552             * Removes all the resource block permissions where resourceBlockId = &#63; from the database.
553             *
554             * @param resourceBlockId the resource block ID
555             */
556            @Override
557            public void removeByResourceBlockId(long resourceBlockId) {
558                    for (ResourceBlockPermission resourceBlockPermission : findByResourceBlockId(
559                                    resourceBlockId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
560                            remove(resourceBlockPermission);
561                    }
562            }
563    
564            /**
565             * Returns the number of resource block permissions where resourceBlockId = &#63;.
566             *
567             * @param resourceBlockId the resource block ID
568             * @return the number of matching resource block permissions
569             */
570            @Override
571            public int countByResourceBlockId(long resourceBlockId) {
572                    FinderPath finderPath = FINDER_PATH_COUNT_BY_RESOURCEBLOCKID;
573    
574                    Object[] finderArgs = new Object[] { resourceBlockId };
575    
576                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
577    
578                    if (count == null) {
579                            StringBundler query = new StringBundler(2);
580    
581                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
582    
583                            query.append(_FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2);
584    
585                            String sql = query.toString();
586    
587                            Session session = null;
588    
589                            try {
590                                    session = openSession();
591    
592                                    Query q = session.createQuery(sql);
593    
594                                    QueryPos qPos = QueryPos.getInstance(q);
595    
596                                    qPos.add(resourceBlockId);
597    
598                                    count = (Long)q.uniqueResult();
599    
600                                    finderCache.putResult(finderPath, finderArgs, count);
601                            }
602                            catch (Exception e) {
603                                    finderCache.removeResult(finderPath, finderArgs);
604    
605                                    throw processException(e);
606                            }
607                            finally {
608                                    closeSession(session);
609                            }
610                    }
611    
612                    return count.intValue();
613            }
614    
615            private static final String _FINDER_COLUMN_RESOURCEBLOCKID_RESOURCEBLOCKID_2 =
616                    "resourceBlockPermission.resourceBlockId = ?";
617            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
618                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
619                            ResourceBlockPermissionImpl.class,
620                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
621                            new String[] {
622                                    Long.class.getName(),
623                                    
624                            Integer.class.getName(), Integer.class.getName(),
625                                    OrderByComparator.class.getName()
626                            });
627            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
628                    new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
629                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
630                            ResourceBlockPermissionImpl.class,
631                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
632                            new String[] { Long.class.getName() },
633                            ResourceBlockPermissionModelImpl.ROLEID_COLUMN_BITMASK);
634            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
635                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
636                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
637                            new String[] { Long.class.getName() });
638    
639            /**
640             * Returns all the resource block permissions where roleId = &#63;.
641             *
642             * @param roleId the role ID
643             * @return the matching resource block permissions
644             */
645            @Override
646            public List<ResourceBlockPermission> findByRoleId(long roleId) {
647                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
648            }
649    
650            /**
651             * Returns a range of all the resource block permissions where roleId = &#63;.
652             *
653             * <p>
654             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
655             * </p>
656             *
657             * @param roleId the role ID
658             * @param start the lower bound of the range of resource block permissions
659             * @param end the upper bound of the range of resource block permissions (not inclusive)
660             * @return the range of matching resource block permissions
661             */
662            @Override
663            public List<ResourceBlockPermission> findByRoleId(long roleId, int start,
664                    int end) {
665                    return findByRoleId(roleId, start, end, null);
666            }
667    
668            /**
669             * Returns an ordered range of all the resource block permissions where roleId = &#63;.
670             *
671             * <p>
672             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
673             * </p>
674             *
675             * @param roleId the role ID
676             * @param start the lower bound of the range of resource block permissions
677             * @param end the upper bound of the range of resource block permissions (not inclusive)
678             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
679             * @return the ordered range of matching resource block permissions
680             */
681            @Override
682            public List<ResourceBlockPermission> findByRoleId(long roleId, int start,
683                    int end, OrderByComparator<ResourceBlockPermission> orderByComparator) {
684                    return findByRoleId(roleId, start, end, orderByComparator, true);
685            }
686    
687            /**
688             * Returns an ordered range of all the resource block permissions where roleId = &#63;.
689             *
690             * <p>
691             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
692             * </p>
693             *
694             * @param roleId the role ID
695             * @param start the lower bound of the range of resource block permissions
696             * @param end the upper bound of the range of resource block permissions (not inclusive)
697             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
698             * @param retrieveFromCache whether to retrieve from the finder cache
699             * @return the ordered range of matching resource block permissions
700             */
701            @Override
702            public List<ResourceBlockPermission> findByRoleId(long roleId, int start,
703                    int end, OrderByComparator<ResourceBlockPermission> orderByComparator,
704                    boolean retrieveFromCache) {
705                    boolean pagination = true;
706                    FinderPath finderPath = null;
707                    Object[] finderArgs = null;
708    
709                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
710                                    (orderByComparator == null)) {
711                            pagination = false;
712                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
713                            finderArgs = new Object[] { roleId };
714                    }
715                    else {
716                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
717                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
718                    }
719    
720                    List<ResourceBlockPermission> list = null;
721    
722                    if (retrieveFromCache) {
723                            list = (List<ResourceBlockPermission>)finderCache.getResult(finderPath,
724                                            finderArgs, this);
725    
726                            if ((list != null) && !list.isEmpty()) {
727                                    for (ResourceBlockPermission resourceBlockPermission : list) {
728                                            if ((roleId != resourceBlockPermission.getRoleId())) {
729                                                    list = null;
730    
731                                                    break;
732                                            }
733                                    }
734                            }
735                    }
736    
737                    if (list == null) {
738                            StringBundler query = null;
739    
740                            if (orderByComparator != null) {
741                                    query = new StringBundler(3 +
742                                                    (orderByComparator.getOrderByFields().length * 2));
743                            }
744                            else {
745                                    query = new StringBundler(3);
746                            }
747    
748                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
749    
750                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
751    
752                            if (orderByComparator != null) {
753                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
754                                            orderByComparator);
755                            }
756                            else
757                             if (pagination) {
758                                    query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
759                            }
760    
761                            String sql = query.toString();
762    
763                            Session session = null;
764    
765                            try {
766                                    session = openSession();
767    
768                                    Query q = session.createQuery(sql);
769    
770                                    QueryPos qPos = QueryPos.getInstance(q);
771    
772                                    qPos.add(roleId);
773    
774                                    if (!pagination) {
775                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
776                                                            getDialect(), start, end, false);
777    
778                                            Collections.sort(list);
779    
780                                            list = Collections.unmodifiableList(list);
781                                    }
782                                    else {
783                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
784                                                            getDialect(), start, end);
785                                    }
786    
787                                    cacheResult(list);
788    
789                                    finderCache.putResult(finderPath, finderArgs, list);
790                            }
791                            catch (Exception e) {
792                                    finderCache.removeResult(finderPath, finderArgs);
793    
794                                    throw processException(e);
795                            }
796                            finally {
797                                    closeSession(session);
798                            }
799                    }
800    
801                    return list;
802            }
803    
804            /**
805             * Returns the first resource block permission in the ordered set where roleId = &#63;.
806             *
807             * @param roleId the role ID
808             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
809             * @return the first matching resource block permission
810             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
811             */
812            @Override
813            public ResourceBlockPermission findByRoleId_First(long roleId,
814                    OrderByComparator<ResourceBlockPermission> orderByComparator)
815                    throws NoSuchResourceBlockPermissionException {
816                    ResourceBlockPermission resourceBlockPermission = fetchByRoleId_First(roleId,
817                                    orderByComparator);
818    
819                    if (resourceBlockPermission != null) {
820                            return resourceBlockPermission;
821                    }
822    
823                    StringBundler msg = new StringBundler(4);
824    
825                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826    
827                    msg.append("roleId=");
828                    msg.append(roleId);
829    
830                    msg.append(StringPool.CLOSE_CURLY_BRACE);
831    
832                    throw new NoSuchResourceBlockPermissionException(msg.toString());
833            }
834    
835            /**
836             * Returns the first resource block permission in the ordered set where roleId = &#63;.
837             *
838             * @param roleId the role ID
839             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
840             * @return the first matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
841             */
842            @Override
843            public ResourceBlockPermission fetchByRoleId_First(long roleId,
844                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
845                    List<ResourceBlockPermission> list = findByRoleId(roleId, 0, 1,
846                                    orderByComparator);
847    
848                    if (!list.isEmpty()) {
849                            return list.get(0);
850                    }
851    
852                    return null;
853            }
854    
855            /**
856             * Returns the last resource block permission in the ordered set where roleId = &#63;.
857             *
858             * @param roleId the role ID
859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
860             * @return the last matching resource block permission
861             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
862             */
863            @Override
864            public ResourceBlockPermission findByRoleId_Last(long roleId,
865                    OrderByComparator<ResourceBlockPermission> orderByComparator)
866                    throws NoSuchResourceBlockPermissionException {
867                    ResourceBlockPermission resourceBlockPermission = fetchByRoleId_Last(roleId,
868                                    orderByComparator);
869    
870                    if (resourceBlockPermission != null) {
871                            return resourceBlockPermission;
872                    }
873    
874                    StringBundler msg = new StringBundler(4);
875    
876                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
877    
878                    msg.append("roleId=");
879                    msg.append(roleId);
880    
881                    msg.append(StringPool.CLOSE_CURLY_BRACE);
882    
883                    throw new NoSuchResourceBlockPermissionException(msg.toString());
884            }
885    
886            /**
887             * Returns the last resource block permission in the ordered set where roleId = &#63;.
888             *
889             * @param roleId the role ID
890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
891             * @return the last matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
892             */
893            @Override
894            public ResourceBlockPermission fetchByRoleId_Last(long roleId,
895                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
896                    int count = countByRoleId(roleId);
897    
898                    if (count == 0) {
899                            return null;
900                    }
901    
902                    List<ResourceBlockPermission> list = findByRoleId(roleId, count - 1,
903                                    count, orderByComparator);
904    
905                    if (!list.isEmpty()) {
906                            return list.get(0);
907                    }
908    
909                    return null;
910            }
911    
912            /**
913             * Returns the resource block permissions before and after the current resource block permission in the ordered set where roleId = &#63;.
914             *
915             * @param resourceBlockPermissionId the primary key of the current resource block permission
916             * @param roleId the role ID
917             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
918             * @return the previous, current, and next resource block permission
919             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
920             */
921            @Override
922            public ResourceBlockPermission[] findByRoleId_PrevAndNext(
923                    long resourceBlockPermissionId, long roleId,
924                    OrderByComparator<ResourceBlockPermission> orderByComparator)
925                    throws NoSuchResourceBlockPermissionException {
926                    ResourceBlockPermission resourceBlockPermission = findByPrimaryKey(resourceBlockPermissionId);
927    
928                    Session session = null;
929    
930                    try {
931                            session = openSession();
932    
933                            ResourceBlockPermission[] array = new ResourceBlockPermissionImpl[3];
934    
935                            array[0] = getByRoleId_PrevAndNext(session,
936                                            resourceBlockPermission, roleId, orderByComparator, true);
937    
938                            array[1] = resourceBlockPermission;
939    
940                            array[2] = getByRoleId_PrevAndNext(session,
941                                            resourceBlockPermission, roleId, orderByComparator, false);
942    
943                            return array;
944                    }
945                    catch (Exception e) {
946                            throw processException(e);
947                    }
948                    finally {
949                            closeSession(session);
950                    }
951            }
952    
953            protected ResourceBlockPermission getByRoleId_PrevAndNext(Session session,
954                    ResourceBlockPermission resourceBlockPermission, long roleId,
955                    OrderByComparator<ResourceBlockPermission> orderByComparator,
956                    boolean previous) {
957                    StringBundler query = null;
958    
959                    if (orderByComparator != null) {
960                            query = new StringBundler(4 +
961                                            (orderByComparator.getOrderByConditionFields().length * 3) +
962                                            (orderByComparator.getOrderByFields().length * 3));
963                    }
964                    else {
965                            query = new StringBundler(3);
966                    }
967    
968                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
969    
970                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
971    
972                    if (orderByComparator != null) {
973                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
974    
975                            if (orderByConditionFields.length > 0) {
976                                    query.append(WHERE_AND);
977                            }
978    
979                            for (int i = 0; i < orderByConditionFields.length; i++) {
980                                    query.append(_ORDER_BY_ENTITY_ALIAS);
981                                    query.append(orderByConditionFields[i]);
982    
983                                    if ((i + 1) < orderByConditionFields.length) {
984                                            if (orderByComparator.isAscending() ^ previous) {
985                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
986                                            }
987                                            else {
988                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
989                                            }
990                                    }
991                                    else {
992                                            if (orderByComparator.isAscending() ^ previous) {
993                                                    query.append(WHERE_GREATER_THAN);
994                                            }
995                                            else {
996                                                    query.append(WHERE_LESSER_THAN);
997                                            }
998                                    }
999                            }
1000    
1001                            query.append(ORDER_BY_CLAUSE);
1002    
1003                            String[] orderByFields = orderByComparator.getOrderByFields();
1004    
1005                            for (int i = 0; i < orderByFields.length; i++) {
1006                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1007                                    query.append(orderByFields[i]);
1008    
1009                                    if ((i + 1) < orderByFields.length) {
1010                                            if (orderByComparator.isAscending() ^ previous) {
1011                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1012                                            }
1013                                            else {
1014                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1015                                            }
1016                                    }
1017                                    else {
1018                                            if (orderByComparator.isAscending() ^ previous) {
1019                                                    query.append(ORDER_BY_ASC);
1020                                            }
1021                                            else {
1022                                                    query.append(ORDER_BY_DESC);
1023                                            }
1024                                    }
1025                            }
1026                    }
1027                    else {
1028                            query.append(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
1029                    }
1030    
1031                    String sql = query.toString();
1032    
1033                    Query q = session.createQuery(sql);
1034    
1035                    q.setFirstResult(0);
1036                    q.setMaxResults(2);
1037    
1038                    QueryPos qPos = QueryPos.getInstance(q);
1039    
1040                    qPos.add(roleId);
1041    
1042                    if (orderByComparator != null) {
1043                            Object[] values = orderByComparator.getOrderByConditionValues(resourceBlockPermission);
1044    
1045                            for (Object value : values) {
1046                                    qPos.add(value);
1047                            }
1048                    }
1049    
1050                    List<ResourceBlockPermission> list = q.list();
1051    
1052                    if (list.size() == 2) {
1053                            return list.get(1);
1054                    }
1055                    else {
1056                            return null;
1057                    }
1058            }
1059    
1060            /**
1061             * Removes all the resource block permissions where roleId = &#63; from the database.
1062             *
1063             * @param roleId the role ID
1064             */
1065            @Override
1066            public void removeByRoleId(long roleId) {
1067                    for (ResourceBlockPermission resourceBlockPermission : findByRoleId(
1068                                    roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1069                            remove(resourceBlockPermission);
1070                    }
1071            }
1072    
1073            /**
1074             * Returns the number of resource block permissions where roleId = &#63;.
1075             *
1076             * @param roleId the role ID
1077             * @return the number of matching resource block permissions
1078             */
1079            @Override
1080            public int countByRoleId(long roleId) {
1081                    FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1082    
1083                    Object[] finderArgs = new Object[] { roleId };
1084    
1085                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1086    
1087                    if (count == null) {
1088                            StringBundler query = new StringBundler(2);
1089    
1090                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1091    
1092                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1093    
1094                            String sql = query.toString();
1095    
1096                            Session session = null;
1097    
1098                            try {
1099                                    session = openSession();
1100    
1101                                    Query q = session.createQuery(sql);
1102    
1103                                    QueryPos qPos = QueryPos.getInstance(q);
1104    
1105                                    qPos.add(roleId);
1106    
1107                                    count = (Long)q.uniqueResult();
1108    
1109                                    finderCache.putResult(finderPath, finderArgs, count);
1110                            }
1111                            catch (Exception e) {
1112                                    finderCache.removeResult(finderPath, finderArgs);
1113    
1114                                    throw processException(e);
1115                            }
1116                            finally {
1117                                    closeSession(session);
1118                            }
1119                    }
1120    
1121                    return count.intValue();
1122            }
1123    
1124            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourceBlockPermission.roleId = ?";
1125            public static final FinderPath FINDER_PATH_FETCH_BY_R_R = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1126                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED,
1127                            ResourceBlockPermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
1128                            "fetchByR_R",
1129                            new String[] { Long.class.getName(), Long.class.getName() },
1130                            ResourceBlockPermissionModelImpl.RESOURCEBLOCKID_COLUMN_BITMASK |
1131                            ResourceBlockPermissionModelImpl.ROLEID_COLUMN_BITMASK);
1132            public static final FinderPath FINDER_PATH_COUNT_BY_R_R = new FinderPath(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1133                            ResourceBlockPermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1134                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByR_R",
1135                            new String[] { Long.class.getName(), Long.class.getName() });
1136    
1137            /**
1138             * Returns the resource block permission where resourceBlockId = &#63; and roleId = &#63; or throws a {@link NoSuchResourceBlockPermissionException} if it could not be found.
1139             *
1140             * @param resourceBlockId the resource block ID
1141             * @param roleId the role ID
1142             * @return the matching resource block permission
1143             * @throws NoSuchResourceBlockPermissionException if a matching resource block permission could not be found
1144             */
1145            @Override
1146            public ResourceBlockPermission findByR_R(long resourceBlockId, long roleId)
1147                    throws NoSuchResourceBlockPermissionException {
1148                    ResourceBlockPermission resourceBlockPermission = fetchByR_R(resourceBlockId,
1149                                    roleId);
1150    
1151                    if (resourceBlockPermission == null) {
1152                            StringBundler msg = new StringBundler(6);
1153    
1154                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1155    
1156                            msg.append("resourceBlockId=");
1157                            msg.append(resourceBlockId);
1158    
1159                            msg.append(", roleId=");
1160                            msg.append(roleId);
1161    
1162                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1163    
1164                            if (_log.isWarnEnabled()) {
1165                                    _log.warn(msg.toString());
1166                            }
1167    
1168                            throw new NoSuchResourceBlockPermissionException(msg.toString());
1169                    }
1170    
1171                    return resourceBlockPermission;
1172            }
1173    
1174            /**
1175             * 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.
1176             *
1177             * @param resourceBlockId the resource block ID
1178             * @param roleId the role ID
1179             * @return the matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
1180             */
1181            @Override
1182            public ResourceBlockPermission fetchByR_R(long resourceBlockId, long roleId) {
1183                    return fetchByR_R(resourceBlockId, roleId, true);
1184            }
1185    
1186            /**
1187             * 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.
1188             *
1189             * @param resourceBlockId the resource block ID
1190             * @param roleId the role ID
1191             * @param retrieveFromCache whether to retrieve from the finder cache
1192             * @return the matching resource block permission, or <code>null</code> if a matching resource block permission could not be found
1193             */
1194            @Override
1195            public ResourceBlockPermission fetchByR_R(long resourceBlockId,
1196                    long roleId, boolean retrieveFromCache) {
1197                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
1198    
1199                    Object result = null;
1200    
1201                    if (retrieveFromCache) {
1202                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_R_R,
1203                                            finderArgs, this);
1204                    }
1205    
1206                    if (result instanceof ResourceBlockPermission) {
1207                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)result;
1208    
1209                            if ((resourceBlockId != resourceBlockPermission.getResourceBlockId()) ||
1210                                            (roleId != resourceBlockPermission.getRoleId())) {
1211                                    result = null;
1212                            }
1213                    }
1214    
1215                    if (result == null) {
1216                            StringBundler query = new StringBundler(4);
1217    
1218                            query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE);
1219    
1220                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1221    
1222                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1223    
1224                            String sql = query.toString();
1225    
1226                            Session session = null;
1227    
1228                            try {
1229                                    session = openSession();
1230    
1231                                    Query q = session.createQuery(sql);
1232    
1233                                    QueryPos qPos = QueryPos.getInstance(q);
1234    
1235                                    qPos.add(resourceBlockId);
1236    
1237                                    qPos.add(roleId);
1238    
1239                                    List<ResourceBlockPermission> list = q.list();
1240    
1241                                    if (list.isEmpty()) {
1242                                            finderCache.putResult(FINDER_PATH_FETCH_BY_R_R, finderArgs,
1243                                                    list);
1244                                    }
1245                                    else {
1246                                            ResourceBlockPermission resourceBlockPermission = list.get(0);
1247    
1248                                            result = resourceBlockPermission;
1249    
1250                                            cacheResult(resourceBlockPermission);
1251    
1252                                            if ((resourceBlockPermission.getResourceBlockId() != resourceBlockId) ||
1253                                                            (resourceBlockPermission.getRoleId() != roleId)) {
1254                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_R,
1255                                                            finderArgs, resourceBlockPermission);
1256                                            }
1257                                    }
1258                            }
1259                            catch (Exception e) {
1260                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_R_R, finderArgs);
1261    
1262                                    throw processException(e);
1263                            }
1264                            finally {
1265                                    closeSession(session);
1266                            }
1267                    }
1268    
1269                    if (result instanceof List<?>) {
1270                            return null;
1271                    }
1272                    else {
1273                            return (ResourceBlockPermission)result;
1274                    }
1275            }
1276    
1277            /**
1278             * Removes the resource block permission where resourceBlockId = &#63; and roleId = &#63; from the database.
1279             *
1280             * @param resourceBlockId the resource block ID
1281             * @param roleId the role ID
1282             * @return the resource block permission that was removed
1283             */
1284            @Override
1285            public ResourceBlockPermission removeByR_R(long resourceBlockId, long roleId)
1286                    throws NoSuchResourceBlockPermissionException {
1287                    ResourceBlockPermission resourceBlockPermission = findByR_R(resourceBlockId,
1288                                    roleId);
1289    
1290                    return remove(resourceBlockPermission);
1291            }
1292    
1293            /**
1294             * Returns the number of resource block permissions where resourceBlockId = &#63; and roleId = &#63;.
1295             *
1296             * @param resourceBlockId the resource block ID
1297             * @param roleId the role ID
1298             * @return the number of matching resource block permissions
1299             */
1300            @Override
1301            public int countByR_R(long resourceBlockId, long roleId) {
1302                    FinderPath finderPath = FINDER_PATH_COUNT_BY_R_R;
1303    
1304                    Object[] finderArgs = new Object[] { resourceBlockId, roleId };
1305    
1306                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1307    
1308                    if (count == null) {
1309                            StringBundler query = new StringBundler(3);
1310    
1311                            query.append(_SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE);
1312    
1313                            query.append(_FINDER_COLUMN_R_R_RESOURCEBLOCKID_2);
1314    
1315                            query.append(_FINDER_COLUMN_R_R_ROLEID_2);
1316    
1317                            String sql = query.toString();
1318    
1319                            Session session = null;
1320    
1321                            try {
1322                                    session = openSession();
1323    
1324                                    Query q = session.createQuery(sql);
1325    
1326                                    QueryPos qPos = QueryPos.getInstance(q);
1327    
1328                                    qPos.add(resourceBlockId);
1329    
1330                                    qPos.add(roleId);
1331    
1332                                    count = (Long)q.uniqueResult();
1333    
1334                                    finderCache.putResult(finderPath, finderArgs, count);
1335                            }
1336                            catch (Exception e) {
1337                                    finderCache.removeResult(finderPath, finderArgs);
1338    
1339                                    throw processException(e);
1340                            }
1341                            finally {
1342                                    closeSession(session);
1343                            }
1344                    }
1345    
1346                    return count.intValue();
1347            }
1348    
1349            private static final String _FINDER_COLUMN_R_R_RESOURCEBLOCKID_2 = "resourceBlockPermission.resourceBlockId = ? AND ";
1350            private static final String _FINDER_COLUMN_R_R_ROLEID_2 = "resourceBlockPermission.roleId = ?";
1351    
1352            public ResourceBlockPermissionPersistenceImpl() {
1353                    setModelClass(ResourceBlockPermission.class);
1354            }
1355    
1356            /**
1357             * Caches the resource block permission in the entity cache if it is enabled.
1358             *
1359             * @param resourceBlockPermission the resource block permission
1360             */
1361            @Override
1362            public void cacheResult(ResourceBlockPermission resourceBlockPermission) {
1363                    entityCache.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1364                            ResourceBlockPermissionImpl.class,
1365                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission);
1366    
1367                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_R,
1368                            new Object[] {
1369                                    resourceBlockPermission.getResourceBlockId(),
1370                                    resourceBlockPermission.getRoleId()
1371                            }, resourceBlockPermission);
1372    
1373                    resourceBlockPermission.resetOriginalValues();
1374            }
1375    
1376            /**
1377             * Caches the resource block permissions in the entity cache if it is enabled.
1378             *
1379             * @param resourceBlockPermissions the resource block permissions
1380             */
1381            @Override
1382            public void cacheResult(
1383                    List<ResourceBlockPermission> resourceBlockPermissions) {
1384                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
1385                            if (entityCache.getResult(
1386                                                    ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1387                                                    ResourceBlockPermissionImpl.class,
1388                                                    resourceBlockPermission.getPrimaryKey()) == null) {
1389                                    cacheResult(resourceBlockPermission);
1390                            }
1391                            else {
1392                                    resourceBlockPermission.resetOriginalValues();
1393                            }
1394                    }
1395            }
1396    
1397            /**
1398             * Clears the cache for all resource block permissions.
1399             *
1400             * <p>
1401             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1402             * </p>
1403             */
1404            @Override
1405            public void clearCache() {
1406                    entityCache.clearCache(ResourceBlockPermissionImpl.class);
1407    
1408                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1409                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1410                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1411            }
1412    
1413            /**
1414             * Clears the cache for the resource block permission.
1415             *
1416             * <p>
1417             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1418             * </p>
1419             */
1420            @Override
1421            public void clearCache(ResourceBlockPermission resourceBlockPermission) {
1422                    entityCache.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1423                            ResourceBlockPermissionImpl.class,
1424                            resourceBlockPermission.getPrimaryKey());
1425    
1426                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1427                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1428    
1429                    clearUniqueFindersCache((ResourceBlockPermissionModelImpl)resourceBlockPermission);
1430            }
1431    
1432            @Override
1433            public void clearCache(
1434                    List<ResourceBlockPermission> resourceBlockPermissions) {
1435                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1436                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1437    
1438                    for (ResourceBlockPermission resourceBlockPermission : resourceBlockPermissions) {
1439                            entityCache.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1440                                    ResourceBlockPermissionImpl.class,
1441                                    resourceBlockPermission.getPrimaryKey());
1442    
1443                            clearUniqueFindersCache((ResourceBlockPermissionModelImpl)resourceBlockPermission);
1444                    }
1445            }
1446    
1447            protected void cacheUniqueFindersCache(
1448                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl,
1449                    boolean isNew) {
1450                    if (isNew) {
1451                            Object[] args = new Object[] {
1452                                            resourceBlockPermissionModelImpl.getResourceBlockId(),
1453                                            resourceBlockPermissionModelImpl.getRoleId()
1454                                    };
1455    
1456                            finderCache.putResult(FINDER_PATH_COUNT_BY_R_R, args,
1457                                    Long.valueOf(1));
1458                            finderCache.putResult(FINDER_PATH_FETCH_BY_R_R, args,
1459                                    resourceBlockPermissionModelImpl);
1460                    }
1461                    else {
1462                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1463                                            FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
1464                                    Object[] args = new Object[] {
1465                                                    resourceBlockPermissionModelImpl.getResourceBlockId(),
1466                                                    resourceBlockPermissionModelImpl.getRoleId()
1467                                            };
1468    
1469                                    finderCache.putResult(FINDER_PATH_COUNT_BY_R_R, args,
1470                                            Long.valueOf(1));
1471                                    finderCache.putResult(FINDER_PATH_FETCH_BY_R_R, args,
1472                                            resourceBlockPermissionModelImpl);
1473                            }
1474                    }
1475            }
1476    
1477            protected void clearUniqueFindersCache(
1478                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl) {
1479                    Object[] args = new Object[] {
1480                                    resourceBlockPermissionModelImpl.getResourceBlockId(),
1481                                    resourceBlockPermissionModelImpl.getRoleId()
1482                            };
1483    
1484                    finderCache.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
1485                    finderCache.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
1486    
1487                    if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1488                                    FINDER_PATH_FETCH_BY_R_R.getColumnBitmask()) != 0) {
1489                            args = new Object[] {
1490                                            resourceBlockPermissionModelImpl.getOriginalResourceBlockId(),
1491                                            resourceBlockPermissionModelImpl.getOriginalRoleId()
1492                                    };
1493    
1494                            finderCache.removeResult(FINDER_PATH_COUNT_BY_R_R, args);
1495                            finderCache.removeResult(FINDER_PATH_FETCH_BY_R_R, args);
1496                    }
1497            }
1498    
1499            /**
1500             * Creates a new resource block permission with the primary key. Does not add the resource block permission to the database.
1501             *
1502             * @param resourceBlockPermissionId the primary key for the new resource block permission
1503             * @return the new resource block permission
1504             */
1505            @Override
1506            public ResourceBlockPermission create(long resourceBlockPermissionId) {
1507                    ResourceBlockPermission resourceBlockPermission = new ResourceBlockPermissionImpl();
1508    
1509                    resourceBlockPermission.setNew(true);
1510                    resourceBlockPermission.setPrimaryKey(resourceBlockPermissionId);
1511    
1512                    resourceBlockPermission.setCompanyId(companyProvider.getCompanyId());
1513    
1514                    return resourceBlockPermission;
1515            }
1516    
1517            /**
1518             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
1519             *
1520             * @param resourceBlockPermissionId the primary key of the resource block permission
1521             * @return the resource block permission that was removed
1522             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1523             */
1524            @Override
1525            public ResourceBlockPermission remove(long resourceBlockPermissionId)
1526                    throws NoSuchResourceBlockPermissionException {
1527                    return remove((Serializable)resourceBlockPermissionId);
1528            }
1529    
1530            /**
1531             * Removes the resource block permission with the primary key from the database. Also notifies the appropriate model listeners.
1532             *
1533             * @param primaryKey the primary key of the resource block permission
1534             * @return the resource block permission that was removed
1535             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1536             */
1537            @Override
1538            public ResourceBlockPermission remove(Serializable primaryKey)
1539                    throws NoSuchResourceBlockPermissionException {
1540                    Session session = null;
1541    
1542                    try {
1543                            session = openSession();
1544    
1545                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1546                                            primaryKey);
1547    
1548                            if (resourceBlockPermission == null) {
1549                                    if (_log.isWarnEnabled()) {
1550                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1551                                    }
1552    
1553                                    throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1554                                            primaryKey);
1555                            }
1556    
1557                            return remove(resourceBlockPermission);
1558                    }
1559                    catch (NoSuchResourceBlockPermissionException nsee) {
1560                            throw nsee;
1561                    }
1562                    catch (Exception e) {
1563                            throw processException(e);
1564                    }
1565                    finally {
1566                            closeSession(session);
1567                    }
1568            }
1569    
1570            @Override
1571            protected ResourceBlockPermission removeImpl(
1572                    ResourceBlockPermission resourceBlockPermission) {
1573                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
1574    
1575                    Session session = null;
1576    
1577                    try {
1578                            session = openSession();
1579    
1580                            if (!session.contains(resourceBlockPermission)) {
1581                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1582                                                    resourceBlockPermission.getPrimaryKeyObj());
1583                            }
1584    
1585                            if (resourceBlockPermission != null) {
1586                                    session.delete(resourceBlockPermission);
1587                            }
1588                    }
1589                    catch (Exception e) {
1590                            throw processException(e);
1591                    }
1592                    finally {
1593                            closeSession(session);
1594                    }
1595    
1596                    if (resourceBlockPermission != null) {
1597                            clearCache(resourceBlockPermission);
1598                    }
1599    
1600                    return resourceBlockPermission;
1601            }
1602    
1603            @Override
1604            public ResourceBlockPermission updateImpl(
1605                    ResourceBlockPermission resourceBlockPermission) {
1606                    resourceBlockPermission = toUnwrappedModel(resourceBlockPermission);
1607    
1608                    boolean isNew = resourceBlockPermission.isNew();
1609    
1610                    ResourceBlockPermissionModelImpl resourceBlockPermissionModelImpl = (ResourceBlockPermissionModelImpl)resourceBlockPermission;
1611    
1612                    Session session = null;
1613    
1614                    try {
1615                            session = openSession();
1616    
1617                            if (resourceBlockPermission.isNew()) {
1618                                    session.save(resourceBlockPermission);
1619    
1620                                    resourceBlockPermission.setNew(false);
1621                            }
1622                            else {
1623                                    resourceBlockPermission = (ResourceBlockPermission)session.merge(resourceBlockPermission);
1624                            }
1625                    }
1626                    catch (Exception e) {
1627                            throw processException(e);
1628                    }
1629                    finally {
1630                            closeSession(session);
1631                    }
1632    
1633                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1634    
1635                    if (isNew || !ResourceBlockPermissionModelImpl.COLUMN_BITMASK_ENABLED) {
1636                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1637                    }
1638    
1639                    else {
1640                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1641                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID.getColumnBitmask()) != 0) {
1642                                    Object[] args = new Object[] {
1643                                                    resourceBlockPermissionModelImpl.getOriginalResourceBlockId()
1644                                            };
1645    
1646                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1647                                            args);
1648                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
1649                                            args);
1650    
1651                                    args = new Object[] {
1652                                                    resourceBlockPermissionModelImpl.getResourceBlockId()
1653                                            };
1654    
1655                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_RESOURCEBLOCKID,
1656                                            args);
1657                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEBLOCKID,
1658                                            args);
1659                            }
1660    
1661                            if ((resourceBlockPermissionModelImpl.getColumnBitmask() &
1662                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
1663                                    Object[] args = new Object[] {
1664                                                    resourceBlockPermissionModelImpl.getOriginalRoleId()
1665                                            };
1666    
1667                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1668                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1669                                            args);
1670    
1671                                    args = new Object[] { resourceBlockPermissionModelImpl.getRoleId() };
1672    
1673                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
1674                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
1675                                            args);
1676                            }
1677                    }
1678    
1679                    entityCache.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1680                            ResourceBlockPermissionImpl.class,
1681                            resourceBlockPermission.getPrimaryKey(), resourceBlockPermission,
1682                            false);
1683    
1684                    clearUniqueFindersCache(resourceBlockPermissionModelImpl);
1685                    cacheUniqueFindersCache(resourceBlockPermissionModelImpl, isNew);
1686    
1687                    resourceBlockPermission.resetOriginalValues();
1688    
1689                    return resourceBlockPermission;
1690            }
1691    
1692            protected ResourceBlockPermission toUnwrappedModel(
1693                    ResourceBlockPermission resourceBlockPermission) {
1694                    if (resourceBlockPermission instanceof ResourceBlockPermissionImpl) {
1695                            return resourceBlockPermission;
1696                    }
1697    
1698                    ResourceBlockPermissionImpl resourceBlockPermissionImpl = new ResourceBlockPermissionImpl();
1699    
1700                    resourceBlockPermissionImpl.setNew(resourceBlockPermission.isNew());
1701                    resourceBlockPermissionImpl.setPrimaryKey(resourceBlockPermission.getPrimaryKey());
1702    
1703                    resourceBlockPermissionImpl.setMvccVersion(resourceBlockPermission.getMvccVersion());
1704                    resourceBlockPermissionImpl.setResourceBlockPermissionId(resourceBlockPermission.getResourceBlockPermissionId());
1705                    resourceBlockPermissionImpl.setCompanyId(resourceBlockPermission.getCompanyId());
1706                    resourceBlockPermissionImpl.setResourceBlockId(resourceBlockPermission.getResourceBlockId());
1707                    resourceBlockPermissionImpl.setRoleId(resourceBlockPermission.getRoleId());
1708                    resourceBlockPermissionImpl.setActionIds(resourceBlockPermission.getActionIds());
1709    
1710                    return resourceBlockPermissionImpl;
1711            }
1712    
1713            /**
1714             * Returns the resource block permission with the primary key or throws a {@link com.liferay.portal.kernel.exception.NoSuchModelException} if it could not be found.
1715             *
1716             * @param primaryKey the primary key of the resource block permission
1717             * @return the resource block permission
1718             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1719             */
1720            @Override
1721            public ResourceBlockPermission findByPrimaryKey(Serializable primaryKey)
1722                    throws NoSuchResourceBlockPermissionException {
1723                    ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(primaryKey);
1724    
1725                    if (resourceBlockPermission == null) {
1726                            if (_log.isWarnEnabled()) {
1727                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1728                            }
1729    
1730                            throw new NoSuchResourceBlockPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1731                                    primaryKey);
1732                    }
1733    
1734                    return resourceBlockPermission;
1735            }
1736    
1737            /**
1738             * Returns the resource block permission with the primary key or throws a {@link NoSuchResourceBlockPermissionException} if it could not be found.
1739             *
1740             * @param resourceBlockPermissionId the primary key of the resource block permission
1741             * @return the resource block permission
1742             * @throws NoSuchResourceBlockPermissionException if a resource block permission with the primary key could not be found
1743             */
1744            @Override
1745            public ResourceBlockPermission findByPrimaryKey(
1746                    long resourceBlockPermissionId)
1747                    throws NoSuchResourceBlockPermissionException {
1748                    return findByPrimaryKey((Serializable)resourceBlockPermissionId);
1749            }
1750    
1751            /**
1752             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
1753             *
1754             * @param primaryKey the primary key of the resource block permission
1755             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
1756             */
1757            @Override
1758            public ResourceBlockPermission fetchByPrimaryKey(Serializable primaryKey) {
1759                    ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)entityCache.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1760                                    ResourceBlockPermissionImpl.class, primaryKey);
1761    
1762                    if (resourceBlockPermission == _nullResourceBlockPermission) {
1763                            return null;
1764                    }
1765    
1766                    if (resourceBlockPermission == null) {
1767                            Session session = null;
1768    
1769                            try {
1770                                    session = openSession();
1771    
1772                                    resourceBlockPermission = (ResourceBlockPermission)session.get(ResourceBlockPermissionImpl.class,
1773                                                    primaryKey);
1774    
1775                                    if (resourceBlockPermission != null) {
1776                                            cacheResult(resourceBlockPermission);
1777                                    }
1778                                    else {
1779                                            entityCache.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1780                                                    ResourceBlockPermissionImpl.class, primaryKey,
1781                                                    _nullResourceBlockPermission);
1782                                    }
1783                            }
1784                            catch (Exception e) {
1785                                    entityCache.removeResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1786                                            ResourceBlockPermissionImpl.class, primaryKey);
1787    
1788                                    throw processException(e);
1789                            }
1790                            finally {
1791                                    closeSession(session);
1792                            }
1793                    }
1794    
1795                    return resourceBlockPermission;
1796            }
1797    
1798            /**
1799             * Returns the resource block permission with the primary key or returns <code>null</code> if it could not be found.
1800             *
1801             * @param resourceBlockPermissionId the primary key of the resource block permission
1802             * @return the resource block permission, or <code>null</code> if a resource block permission with the primary key could not be found
1803             */
1804            @Override
1805            public ResourceBlockPermission fetchByPrimaryKey(
1806                    long resourceBlockPermissionId) {
1807                    return fetchByPrimaryKey((Serializable)resourceBlockPermissionId);
1808            }
1809    
1810            @Override
1811            public Map<Serializable, ResourceBlockPermission> fetchByPrimaryKeys(
1812                    Set<Serializable> primaryKeys) {
1813                    if (primaryKeys.isEmpty()) {
1814                            return Collections.emptyMap();
1815                    }
1816    
1817                    Map<Serializable, ResourceBlockPermission> map = new HashMap<Serializable, ResourceBlockPermission>();
1818    
1819                    if (primaryKeys.size() == 1) {
1820                            Iterator<Serializable> iterator = primaryKeys.iterator();
1821    
1822                            Serializable primaryKey = iterator.next();
1823    
1824                            ResourceBlockPermission resourceBlockPermission = fetchByPrimaryKey(primaryKey);
1825    
1826                            if (resourceBlockPermission != null) {
1827                                    map.put(primaryKey, resourceBlockPermission);
1828                            }
1829    
1830                            return map;
1831                    }
1832    
1833                    Set<Serializable> uncachedPrimaryKeys = null;
1834    
1835                    for (Serializable primaryKey : primaryKeys) {
1836                            ResourceBlockPermission resourceBlockPermission = (ResourceBlockPermission)entityCache.getResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1837                                            ResourceBlockPermissionImpl.class, primaryKey);
1838    
1839                            if (resourceBlockPermission == null) {
1840                                    if (uncachedPrimaryKeys == null) {
1841                                            uncachedPrimaryKeys = new HashSet<Serializable>();
1842                                    }
1843    
1844                                    uncachedPrimaryKeys.add(primaryKey);
1845                            }
1846                            else {
1847                                    map.put(primaryKey, resourceBlockPermission);
1848                            }
1849                    }
1850    
1851                    if (uncachedPrimaryKeys == null) {
1852                            return map;
1853                    }
1854    
1855                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1856                                    1);
1857    
1858                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE_PKS_IN);
1859    
1860                    for (Serializable primaryKey : uncachedPrimaryKeys) {
1861                            query.append(String.valueOf(primaryKey));
1862    
1863                            query.append(StringPool.COMMA);
1864                    }
1865    
1866                    query.setIndex(query.index() - 1);
1867    
1868                    query.append(StringPool.CLOSE_PARENTHESIS);
1869    
1870                    String sql = query.toString();
1871    
1872                    Session session = null;
1873    
1874                    try {
1875                            session = openSession();
1876    
1877                            Query q = session.createQuery(sql);
1878    
1879                            for (ResourceBlockPermission resourceBlockPermission : (List<ResourceBlockPermission>)q.list()) {
1880                                    map.put(resourceBlockPermission.getPrimaryKeyObj(),
1881                                            resourceBlockPermission);
1882    
1883                                    cacheResult(resourceBlockPermission);
1884    
1885                                    uncachedPrimaryKeys.remove(resourceBlockPermission.getPrimaryKeyObj());
1886                            }
1887    
1888                            for (Serializable primaryKey : uncachedPrimaryKeys) {
1889                                    entityCache.putResult(ResourceBlockPermissionModelImpl.ENTITY_CACHE_ENABLED,
1890                                            ResourceBlockPermissionImpl.class, primaryKey,
1891                                            _nullResourceBlockPermission);
1892                            }
1893                    }
1894                    catch (Exception e) {
1895                            throw processException(e);
1896                    }
1897                    finally {
1898                            closeSession(session);
1899                    }
1900    
1901                    return map;
1902            }
1903    
1904            /**
1905             * Returns all the resource block permissions.
1906             *
1907             * @return the resource block permissions
1908             */
1909            @Override
1910            public List<ResourceBlockPermission> findAll() {
1911                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1912            }
1913    
1914            /**
1915             * Returns a range of all the resource block permissions.
1916             *
1917             * <p>
1918             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1919             * </p>
1920             *
1921             * @param start the lower bound of the range of resource block permissions
1922             * @param end the upper bound of the range of resource block permissions (not inclusive)
1923             * @return the range of resource block permissions
1924             */
1925            @Override
1926            public List<ResourceBlockPermission> findAll(int start, int end) {
1927                    return findAll(start, end, null);
1928            }
1929    
1930            /**
1931             * Returns an ordered range of all the resource block permissions.
1932             *
1933             * <p>
1934             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1935             * </p>
1936             *
1937             * @param start the lower bound of the range of resource block permissions
1938             * @param end the upper bound of the range of resource block permissions (not inclusive)
1939             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1940             * @return the ordered range of resource block permissions
1941             */
1942            @Override
1943            public List<ResourceBlockPermission> findAll(int start, int end,
1944                    OrderByComparator<ResourceBlockPermission> orderByComparator) {
1945                    return findAll(start, end, orderByComparator, true);
1946            }
1947    
1948            /**
1949             * Returns an ordered range of all the resource block permissions.
1950             *
1951             * <p>
1952             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link 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.
1953             * </p>
1954             *
1955             * @param start the lower bound of the range of resource block permissions
1956             * @param end the upper bound of the range of resource block permissions (not inclusive)
1957             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1958             * @param retrieveFromCache whether to retrieve from the finder cache
1959             * @return the ordered range of resource block permissions
1960             */
1961            @Override
1962            public List<ResourceBlockPermission> findAll(int start, int end,
1963                    OrderByComparator<ResourceBlockPermission> orderByComparator,
1964                    boolean retrieveFromCache) {
1965                    boolean pagination = true;
1966                    FinderPath finderPath = null;
1967                    Object[] finderArgs = null;
1968    
1969                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1970                                    (orderByComparator == null)) {
1971                            pagination = false;
1972                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1973                            finderArgs = FINDER_ARGS_EMPTY;
1974                    }
1975                    else {
1976                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1977                            finderArgs = new Object[] { start, end, orderByComparator };
1978                    }
1979    
1980                    List<ResourceBlockPermission> list = null;
1981    
1982                    if (retrieveFromCache) {
1983                            list = (List<ResourceBlockPermission>)finderCache.getResult(finderPath,
1984                                            finderArgs, this);
1985                    }
1986    
1987                    if (list == null) {
1988                            StringBundler query = null;
1989                            String sql = null;
1990    
1991                            if (orderByComparator != null) {
1992                                    query = new StringBundler(2 +
1993                                                    (orderByComparator.getOrderByFields().length * 2));
1994    
1995                                    query.append(_SQL_SELECT_RESOURCEBLOCKPERMISSION);
1996    
1997                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1998                                            orderByComparator);
1999    
2000                                    sql = query.toString();
2001                            }
2002                            else {
2003                                    sql = _SQL_SELECT_RESOURCEBLOCKPERMISSION;
2004    
2005                                    if (pagination) {
2006                                            sql = sql.concat(ResourceBlockPermissionModelImpl.ORDER_BY_JPQL);
2007                                    }
2008                            }
2009    
2010                            Session session = null;
2011    
2012                            try {
2013                                    session = openSession();
2014    
2015                                    Query q = session.createQuery(sql);
2016    
2017                                    if (!pagination) {
2018                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
2019                                                            getDialect(), start, end, false);
2020    
2021                                            Collections.sort(list);
2022    
2023                                            list = Collections.unmodifiableList(list);
2024                                    }
2025                                    else {
2026                                            list = (List<ResourceBlockPermission>)QueryUtil.list(q,
2027                                                            getDialect(), start, end);
2028                                    }
2029    
2030                                    cacheResult(list);
2031    
2032                                    finderCache.putResult(finderPath, finderArgs, list);
2033                            }
2034                            catch (Exception e) {
2035                                    finderCache.removeResult(finderPath, finderArgs);
2036    
2037                                    throw processException(e);
2038                            }
2039                            finally {
2040                                    closeSession(session);
2041                            }
2042                    }
2043    
2044                    return list;
2045            }
2046    
2047            /**
2048             * Removes all the resource block permissions from the database.
2049             *
2050             */
2051            @Override
2052            public void removeAll() {
2053                    for (ResourceBlockPermission resourceBlockPermission : findAll()) {
2054                            remove(resourceBlockPermission);
2055                    }
2056            }
2057    
2058            /**
2059             * Returns the number of resource block permissions.
2060             *
2061             * @return the number of resource block permissions
2062             */
2063            @Override
2064            public int countAll() {
2065                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2066                                    FINDER_ARGS_EMPTY, this);
2067    
2068                    if (count == null) {
2069                            Session session = null;
2070    
2071                            try {
2072                                    session = openSession();
2073    
2074                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEBLOCKPERMISSION);
2075    
2076                                    count = (Long)q.uniqueResult();
2077    
2078                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2079                                            count);
2080                            }
2081                            catch (Exception e) {
2082                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2083                                            FINDER_ARGS_EMPTY);
2084    
2085                                    throw processException(e);
2086                            }
2087                            finally {
2088                                    closeSession(session);
2089                            }
2090                    }
2091    
2092                    return count.intValue();
2093            }
2094    
2095            @Override
2096            protected Map<String, Integer> getTableColumnsMap() {
2097                    return ResourceBlockPermissionModelImpl.TABLE_COLUMNS_MAP;
2098            }
2099    
2100            /**
2101             * Initializes the resource block permission persistence.
2102             */
2103            public void afterPropertiesSet() {
2104            }
2105    
2106            public void destroy() {
2107                    entityCache.removeCache(ResourceBlockPermissionImpl.class.getName());
2108                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2109                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2110                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2111            }
2112    
2113            @BeanReference(type = CompanyProviderWrapper.class)
2114            protected CompanyProvider companyProvider;
2115            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2116            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2117            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission";
2118            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE_PKS_IN =
2119                    "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE resourceBlockPermissionId IN (";
2120            private static final String _SQL_SELECT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT resourceBlockPermission FROM ResourceBlockPermission resourceBlockPermission WHERE ";
2121            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission";
2122            private static final String _SQL_COUNT_RESOURCEBLOCKPERMISSION_WHERE = "SELECT COUNT(resourceBlockPermission) FROM ResourceBlockPermission resourceBlockPermission WHERE ";
2123            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceBlockPermission.";
2124            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceBlockPermission exists with the primary key ";
2125            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceBlockPermission exists with the key {";
2126            private static final Log _log = LogFactoryUtil.getLog(ResourceBlockPermissionPersistenceImpl.class);
2127            private static final ResourceBlockPermission _nullResourceBlockPermission = new ResourceBlockPermissionImpl() {
2128                            @Override
2129                            public Object clone() {
2130                                    return this;
2131                            }
2132    
2133                            @Override
2134                            public CacheModel<ResourceBlockPermission> toCacheModel() {
2135                                    return _nullResourceBlockPermissionCacheModel;
2136                            }
2137                    };
2138    
2139            private static final CacheModel<ResourceBlockPermission> _nullResourceBlockPermissionCacheModel =
2140                    new NullCacheModel();
2141    
2142            private static class NullCacheModel implements CacheModel<ResourceBlockPermission>,
2143                    MVCCModel {
2144                    @Override
2145                    public long getMvccVersion() {
2146                            return -1;
2147                    }
2148    
2149                    @Override
2150                    public void setMvccVersion(long mvccVersion) {
2151                    }
2152    
2153                    @Override
2154                    public ResourceBlockPermission toEntityModel() {
2155                            return _nullResourceBlockPermission;
2156                    }
2157            }
2158    }