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