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