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