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