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