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