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