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