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