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