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.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.ResourceTypePermission;
040    import com.liferay.portal.model.impl.ResourceTypePermissionImpl;
041    import com.liferay.portal.model.impl.ResourceTypePermissionModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the resource type permission service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see ResourceTypePermissionPersistence
059     * @see ResourceTypePermissionUtil
060     * @generated
061     */
062    public class ResourceTypePermissionPersistenceImpl extends BasePersistenceImpl<ResourceTypePermission>
063            implements ResourceTypePermissionPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link ResourceTypePermissionUtil} to access the resource type permission persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ResourceTypePermissionImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
075                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
076                            ResourceTypePermissionImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
078                            new String[] {
079                                    Long.class.getName(),
080                                    
081                            "java.lang.Integer", "java.lang.Integer",
082                                    "com.liferay.portal.kernel.util.OrderByComparator"
083                            });
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
085                    new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
086                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
087                            ResourceTypePermissionImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
089                            new String[] { Long.class.getName() },
090                            ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
091            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
092                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
094                            new String[] { Long.class.getName() });
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
096                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
097                            ResourceTypePermissionImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_R",
099                            new String[] {
100                                    Long.class.getName(), String.class.getName(),
101                                    Long.class.getName(),
102                                    
103                            "java.lang.Integer", "java.lang.Integer",
104                                    "com.liferay.portal.kernel.util.OrderByComparator"
105                            });
106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
107                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
108                            ResourceTypePermissionImpl.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_R",
110                            new String[] {
111                                    Long.class.getName(), String.class.getName(),
112                                    Long.class.getName()
113                            },
114                            ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
115                            ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
116                            ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
117            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
118                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
119                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_R",
120                            new String[] {
121                                    Long.class.getName(), String.class.getName(),
122                                    Long.class.getName()
123                            });
124            public static final FinderPath FINDER_PATH_FETCH_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
125                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
126                            ResourceTypePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
127                            "fetchByC_G_N_R",
128                            new String[] {
129                                    Long.class.getName(), Long.class.getName(),
130                                    String.class.getName(), Long.class.getName()
131                            },
132                            ResourceTypePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
133                            ResourceTypePermissionModelImpl.GROUPID_COLUMN_BITMASK |
134                            ResourceTypePermissionModelImpl.NAME_COLUMN_BITMASK |
135                            ResourceTypePermissionModelImpl.ROLEID_COLUMN_BITMASK);
136            public static final FinderPath FINDER_PATH_COUNT_BY_C_G_N_R = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
137                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
138                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_G_N_R",
139                            new String[] {
140                                    Long.class.getName(), Long.class.getName(),
141                                    String.class.getName(), Long.class.getName()
142                            });
143            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
144                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
145                            ResourceTypePermissionImpl.class,
146                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
147            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
148                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED,
149                            ResourceTypePermissionImpl.class,
150                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
151            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
152                            ResourceTypePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
153                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
154    
155            /**
156             * Caches the resource type permission in the entity cache if it is enabled.
157             *
158             * @param resourceTypePermission the resource type permission
159             */
160            public void cacheResult(ResourceTypePermission resourceTypePermission) {
161                    EntityCacheUtil.putResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
162                            ResourceTypePermissionImpl.class,
163                            resourceTypePermission.getPrimaryKey(), resourceTypePermission);
164    
165                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
166                            new Object[] {
167                                    Long.valueOf(resourceTypePermission.getCompanyId()),
168                                    Long.valueOf(resourceTypePermission.getGroupId()),
169                                    
170                            resourceTypePermission.getName(),
171                                    Long.valueOf(resourceTypePermission.getRoleId())
172                            }, resourceTypePermission);
173    
174                    resourceTypePermission.resetOriginalValues();
175            }
176    
177            /**
178             * Caches the resource type permissions in the entity cache if it is enabled.
179             *
180             * @param resourceTypePermissions the resource type permissions
181             */
182            public void cacheResult(
183                    List<ResourceTypePermission> resourceTypePermissions) {
184                    for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
185                            if (EntityCacheUtil.getResult(
186                                                    ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
187                                                    ResourceTypePermissionImpl.class,
188                                                    resourceTypePermission.getPrimaryKey()) == null) {
189                                    cacheResult(resourceTypePermission);
190                            }
191                            else {
192                                    resourceTypePermission.resetOriginalValues();
193                            }
194                    }
195            }
196    
197            /**
198             * Clears the cache for all resource type permissions.
199             *
200             * <p>
201             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
202             * </p>
203             */
204            @Override
205            public void clearCache() {
206                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
207                            CacheRegistryUtil.clear(ResourceTypePermissionImpl.class.getName());
208                    }
209    
210                    EntityCacheUtil.clearCache(ResourceTypePermissionImpl.class.getName());
211    
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
214                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
215            }
216    
217            /**
218             * Clears the cache for the resource type permission.
219             *
220             * <p>
221             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
222             * </p>
223             */
224            @Override
225            public void clearCache(ResourceTypePermission resourceTypePermission) {
226                    EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
227                            ResourceTypePermissionImpl.class,
228                            resourceTypePermission.getPrimaryKey());
229    
230                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
231                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
232    
233                    clearUniqueFindersCache(resourceTypePermission);
234            }
235    
236            @Override
237            public void clearCache(List<ResourceTypePermission> resourceTypePermissions) {
238                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
239                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
240    
241                    for (ResourceTypePermission resourceTypePermission : resourceTypePermissions) {
242                            EntityCacheUtil.removeResult(ResourceTypePermissionModelImpl.ENTITY_CACHE_ENABLED,
243                                    ResourceTypePermissionImpl.class,
244                                    resourceTypePermission.getPrimaryKey());
245    
246                            clearUniqueFindersCache(resourceTypePermission);
247                    }
248            }
249    
250            protected void clearUniqueFindersCache(
251                    ResourceTypePermission resourceTypePermission) {
252                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R,
253                            new Object[] {
254                                    Long.valueOf(resourceTypePermission.getCompanyId()),
255                                    Long.valueOf(resourceTypePermission.getGroupId()),
256                                    
257                            resourceTypePermission.getName(),
258                                    Long.valueOf(resourceTypePermission.getRoleId())
259                            });
260            }
261    
262            /**
263             * Creates a new resource type permission with the primary key. Does not add the resource type permission to the database.
264             *
265             * @param resourceTypePermissionId the primary key for the new resource type permission
266             * @return the new resource type permission
267             */
268            public ResourceTypePermission create(long resourceTypePermissionId) {
269                    ResourceTypePermission resourceTypePermission = new ResourceTypePermissionImpl();
270    
271                    resourceTypePermission.setNew(true);
272                    resourceTypePermission.setPrimaryKey(resourceTypePermissionId);
273    
274                    return resourceTypePermission;
275            }
276    
277            /**
278             * Removes the resource type permission with the primary key from the database. Also notifies the appropriate model listeners.
279             *
280             * @param resourceTypePermissionId the primary key of the resource type permission
281             * @return the resource type permission that was removed
282             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a resource type permission with the primary key could not be found
283             * @throws SystemException if a system exception occurred
284             */
285            public ResourceTypePermission remove(long resourceTypePermissionId)
286                    throws NoSuchResourceTypePermissionException, SystemException {
287                    return remove(Long.valueOf(resourceTypePermissionId));
288            }
289    
290            /**
291             * Removes the resource type permission with the primary key from the database. Also notifies the appropriate model listeners.
292             *
293             * @param primaryKey the primary key of the resource type permission
294             * @return the resource type permission that was removed
295             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a resource type permission with the primary key could not be found
296             * @throws SystemException if a system exception occurred
297             */
298            @Override
299            public ResourceTypePermission remove(Serializable primaryKey)
300                    throws NoSuchResourceTypePermissionException, SystemException {
301                    Session session = null;
302    
303                    try {
304                            session = openSession();
305    
306                            ResourceTypePermission resourceTypePermission = (ResourceTypePermission)session.get(ResourceTypePermissionImpl.class,
307                                            primaryKey);
308    
309                            if (resourceTypePermission == null) {
310                                    if (_log.isWarnEnabled()) {
311                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
312                                    }
313    
314                                    throw new NoSuchResourceTypePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
315                                            primaryKey);
316                            }
317    
318                            return remove(resourceTypePermission);
319                    }
320                    catch (NoSuchResourceTypePermissionException nsee) {
321                            throw nsee;
322                    }
323                    catch (Exception e) {
324                            throw processException(e);
325                    }
326                    finally {
327                            closeSession(session);
328                    }
329            }
330    
331            @Override
332            protected ResourceTypePermission removeImpl(
333                    ResourceTypePermission resourceTypePermission)
334                    throws SystemException {
335                    resourceTypePermission = toUnwrappedModel(resourceTypePermission);
336    
337                    Session session = null;
338    
339                    try {
340                            session = openSession();
341    
342                            BatchSessionUtil.delete(session, resourceTypePermission);
343                    }
344                    catch (Exception e) {
345                            throw processException(e);
346                    }
347                    finally {
348                            closeSession(session);
349                    }
350    
351                    clearCache(resourceTypePermission);
352    
353                    return resourceTypePermission;
354            }
355    
356            @Override
357            public ResourceTypePermission updateImpl(
358                    com.liferay.portal.model.ResourceTypePermission resourceTypePermission,
359                    boolean merge) throws SystemException {
360                    resourceTypePermission = toUnwrappedModel(resourceTypePermission);
361    
362                    boolean isNew = resourceTypePermission.isNew();
363    
364                    ResourceTypePermissionModelImpl resourceTypePermissionModelImpl = (ResourceTypePermissionModelImpl)resourceTypePermission;
365    
366                    Session session = null;
367    
368                    try {
369                            session = openSession();
370    
371                            BatchSessionUtil.update(session, resourceTypePermission, merge);
372    
373                            resourceTypePermission.setNew(false);
374                    }
375                    catch (Exception e) {
376                            throw processException(e);
377                    }
378                    finally {
379                            closeSession(session);
380                    }
381    
382                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
383    
384                    if (isNew || !ResourceTypePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
385                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
386                    }
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) {
662                            StringBundler query = null;
663    
664                            if (orderByComparator != null) {
665                                    query = new StringBundler(3 +
666                                                    (orderByComparator.getOrderByFields().length * 3));
667                            }
668                            else {
669                                    query = new StringBundler(2);
670                            }
671    
672                            query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
673    
674                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
675    
676                            if (orderByComparator != null) {
677                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
678                                            orderByComparator);
679                            }
680    
681                            String sql = query.toString();
682    
683                            Session session = null;
684    
685                            try {
686                                    session = openSession();
687    
688                                    Query q = session.createQuery(sql);
689    
690                                    QueryPos qPos = QueryPos.getInstance(q);
691    
692                                    qPos.add(roleId);
693    
694                                    list = (List<ResourceTypePermission>)QueryUtil.list(q,
695                                                    getDialect(), start, end);
696                            }
697                            catch (Exception e) {
698                                    throw processException(e);
699                            }
700                            finally {
701                                    if (list == null) {
702                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
703                                    }
704                                    else {
705                                            cacheResult(list);
706    
707                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
708                                    }
709    
710                                    closeSession(session);
711                            }
712                    }
713    
714                    return list;
715            }
716    
717            /**
718             * Returns the first resource type permission in the ordered set where roleId = &#63;.
719             *
720             * <p>
721             * 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.
722             * </p>
723             *
724             * @param roleId the role ID
725             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
726             * @return the first matching resource type permission
727             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a matching resource type permission could not be found
728             * @throws SystemException if a system exception occurred
729             */
730            public ResourceTypePermission findByRoleId_First(long roleId,
731                    OrderByComparator orderByComparator)
732                    throws NoSuchResourceTypePermissionException, SystemException {
733                    List<ResourceTypePermission> list = findByRoleId(roleId, 0, 1,
734                                    orderByComparator);
735    
736                    if (list.isEmpty()) {
737                            StringBundler msg = new StringBundler(4);
738    
739                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
740    
741                            msg.append("roleId=");
742                            msg.append(roleId);
743    
744                            msg.append(StringPool.CLOSE_CURLY_BRACE);
745    
746                            throw new NoSuchResourceTypePermissionException(msg.toString());
747                    }
748                    else {
749                            return list.get(0);
750                    }
751            }
752    
753            /**
754             * Returns the last resource type permission in the ordered set where roleId = &#63;.
755             *
756             * <p>
757             * 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.
758             * </p>
759             *
760             * @param roleId the role ID
761             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
762             * @return the last matching resource type permission
763             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a matching resource type permission could not be found
764             * @throws SystemException if a system exception occurred
765             */
766            public ResourceTypePermission findByRoleId_Last(long roleId,
767                    OrderByComparator orderByComparator)
768                    throws NoSuchResourceTypePermissionException, SystemException {
769                    int count = countByRoleId(roleId);
770    
771                    List<ResourceTypePermission> list = findByRoleId(roleId, count - 1,
772                                    count, orderByComparator);
773    
774                    if (list.isEmpty()) {
775                            StringBundler msg = new StringBundler(4);
776    
777                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
778    
779                            msg.append("roleId=");
780                            msg.append(roleId);
781    
782                            msg.append(StringPool.CLOSE_CURLY_BRACE);
783    
784                            throw new NoSuchResourceTypePermissionException(msg.toString());
785                    }
786                    else {
787                            return list.get(0);
788                    }
789            }
790    
791            /**
792             * Returns the resource type permissions before and after the current resource type permission in the ordered set where roleId = &#63;.
793             *
794             * <p>
795             * 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.
796             * </p>
797             *
798             * @param resourceTypePermissionId the primary key of the current resource type permission
799             * @param roleId the role ID
800             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
801             * @return the previous, current, and next resource type permission
802             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a resource type permission with the primary key could not be found
803             * @throws SystemException if a system exception occurred
804             */
805            public ResourceTypePermission[] findByRoleId_PrevAndNext(
806                    long resourceTypePermissionId, long roleId,
807                    OrderByComparator orderByComparator)
808                    throws NoSuchResourceTypePermissionException, SystemException {
809                    ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
810    
811                    Session session = null;
812    
813                    try {
814                            session = openSession();
815    
816                            ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
817    
818                            array[0] = getByRoleId_PrevAndNext(session, resourceTypePermission,
819                                            roleId, orderByComparator, true);
820    
821                            array[1] = resourceTypePermission;
822    
823                            array[2] = getByRoleId_PrevAndNext(session, resourceTypePermission,
824                                            roleId, orderByComparator, false);
825    
826                            return array;
827                    }
828                    catch (Exception e) {
829                            throw processException(e);
830                    }
831                    finally {
832                            closeSession(session);
833                    }
834            }
835    
836            protected ResourceTypePermission getByRoleId_PrevAndNext(Session session,
837                    ResourceTypePermission resourceTypePermission, long roleId,
838                    OrderByComparator orderByComparator, boolean previous) {
839                    StringBundler query = null;
840    
841                    if (orderByComparator != null) {
842                            query = new StringBundler(6 +
843                                            (orderByComparator.getOrderByFields().length * 6));
844                    }
845                    else {
846                            query = new StringBundler(3);
847                    }
848    
849                    query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
850    
851                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
852    
853                    if (orderByComparator != null) {
854                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
855    
856                            if (orderByConditionFields.length > 0) {
857                                    query.append(WHERE_AND);
858                            }
859    
860                            for (int i = 0; i < orderByConditionFields.length; i++) {
861                                    query.append(_ORDER_BY_ENTITY_ALIAS);
862                                    query.append(orderByConditionFields[i]);
863    
864                                    if ((i + 1) < orderByConditionFields.length) {
865                                            if (orderByComparator.isAscending() ^ previous) {
866                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
867                                            }
868                                            else {
869                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
870                                            }
871                                    }
872                                    else {
873                                            if (orderByComparator.isAscending() ^ previous) {
874                                                    query.append(WHERE_GREATER_THAN);
875                                            }
876                                            else {
877                                                    query.append(WHERE_LESSER_THAN);
878                                            }
879                                    }
880                            }
881    
882                            query.append(ORDER_BY_CLAUSE);
883    
884                            String[] orderByFields = orderByComparator.getOrderByFields();
885    
886                            for (int i = 0; i < orderByFields.length; i++) {
887                                    query.append(_ORDER_BY_ENTITY_ALIAS);
888                                    query.append(orderByFields[i]);
889    
890                                    if ((i + 1) < orderByFields.length) {
891                                            if (orderByComparator.isAscending() ^ previous) {
892                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
893                                            }
894                                            else {
895                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
896                                            }
897                                    }
898                                    else {
899                                            if (orderByComparator.isAscending() ^ previous) {
900                                                    query.append(ORDER_BY_ASC);
901                                            }
902                                            else {
903                                                    query.append(ORDER_BY_DESC);
904                                            }
905                                    }
906                            }
907                    }
908    
909                    String sql = query.toString();
910    
911                    Query q = session.createQuery(sql);
912    
913                    q.setFirstResult(0);
914                    q.setMaxResults(2);
915    
916                    QueryPos qPos = QueryPos.getInstance(q);
917    
918                    qPos.add(roleId);
919    
920                    if (orderByComparator != null) {
921                            Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
922    
923                            for (Object value : values) {
924                                    qPos.add(value);
925                            }
926                    }
927    
928                    List<ResourceTypePermission> list = q.list();
929    
930                    if (list.size() == 2) {
931                            return list.get(1);
932                    }
933                    else {
934                            return null;
935                    }
936            }
937    
938            /**
939             * Returns all the resource type permissions where companyId = &#63; and name = &#63; and roleId = &#63;.
940             *
941             * @param companyId the company ID
942             * @param name the name
943             * @param roleId the role ID
944             * @return the matching resource type permissions
945             * @throws SystemException if a system exception occurred
946             */
947            public List<ResourceTypePermission> findByC_N_R(long companyId,
948                    String name, long roleId) throws SystemException {
949                    return findByC_N_R(companyId, name, roleId, QueryUtil.ALL_POS,
950                            QueryUtil.ALL_POS, null);
951            }
952    
953            /**
954             * Returns a range of all the resource type permissions where companyId = &#63; and name = &#63; and roleId = &#63;.
955             *
956             * <p>
957             * 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.
958             * </p>
959             *
960             * @param companyId the company ID
961             * @param name the name
962             * @param roleId the role ID
963             * @param start the lower bound of the range of resource type permissions
964             * @param end the upper bound of the range of resource type permissions (not inclusive)
965             * @return the range of matching resource type permissions
966             * @throws SystemException if a system exception occurred
967             */
968            public List<ResourceTypePermission> findByC_N_R(long companyId,
969                    String name, long roleId, int start, int end) throws SystemException {
970                    return findByC_N_R(companyId, name, roleId, start, end, null);
971            }
972    
973            /**
974             * Returns an ordered range of all the resource type permissions where companyId = &#63; and name = &#63; and roleId = &#63;.
975             *
976             * <p>
977             * 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.
978             * </p>
979             *
980             * @param companyId the company ID
981             * @param name the name
982             * @param roleId the role ID
983             * @param start the lower bound of the range of resource type permissions
984             * @param end the upper bound of the range of resource type permissions (not inclusive)
985             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
986             * @return the ordered range of matching resource type permissions
987             * @throws SystemException if a system exception occurred
988             */
989            public List<ResourceTypePermission> findByC_N_R(long companyId,
990                    String name, long roleId, int start, int end,
991                    OrderByComparator orderByComparator) throws SystemException {
992                    FinderPath finderPath = null;
993                    Object[] finderArgs = null;
994    
995                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
996                                    (orderByComparator == null)) {
997                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_R;
998                            finderArgs = new Object[] { companyId, name, roleId };
999                    }
1000                    else {
1001                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_R;
1002                            finderArgs = new Object[] {
1003                                            companyId, name, roleId,
1004                                            
1005                                            start, end, orderByComparator
1006                                    };
1007                    }
1008    
1009                    List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
1010                                    finderArgs, this);
1011    
1012                    if (list == null) {
1013                            StringBundler query = null;
1014    
1015                            if (orderByComparator != null) {
1016                                    query = new StringBundler(5 +
1017                                                    (orderByComparator.getOrderByFields().length * 3));
1018                            }
1019                            else {
1020                                    query = new StringBundler(4);
1021                            }
1022    
1023                            query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
1024    
1025                            query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
1026    
1027                            if (name == null) {
1028                                    query.append(_FINDER_COLUMN_C_N_R_NAME_1);
1029                            }
1030                            else {
1031                                    if (name.equals(StringPool.BLANK)) {
1032                                            query.append(_FINDER_COLUMN_C_N_R_NAME_3);
1033                                    }
1034                                    else {
1035                                            query.append(_FINDER_COLUMN_C_N_R_NAME_2);
1036                                    }
1037                            }
1038    
1039                            query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
1040    
1041                            if (orderByComparator != null) {
1042                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1043                                            orderByComparator);
1044                            }
1045    
1046                            String sql = query.toString();
1047    
1048                            Session session = null;
1049    
1050                            try {
1051                                    session = openSession();
1052    
1053                                    Query q = session.createQuery(sql);
1054    
1055                                    QueryPos qPos = QueryPos.getInstance(q);
1056    
1057                                    qPos.add(companyId);
1058    
1059                                    if (name != null) {
1060                                            qPos.add(name);
1061                                    }
1062    
1063                                    qPos.add(roleId);
1064    
1065                                    list = (List<ResourceTypePermission>)QueryUtil.list(q,
1066                                                    getDialect(), start, end);
1067                            }
1068                            catch (Exception e) {
1069                                    throw processException(e);
1070                            }
1071                            finally {
1072                                    if (list == null) {
1073                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1074                                    }
1075                                    else {
1076                                            cacheResult(list);
1077    
1078                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1079                                    }
1080    
1081                                    closeSession(session);
1082                            }
1083                    }
1084    
1085                    return list;
1086            }
1087    
1088            /**
1089             * Returns the first resource type permission in the ordered set where companyId = &#63; and name = &#63; and roleId = &#63;.
1090             *
1091             * <p>
1092             * 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.
1093             * </p>
1094             *
1095             * @param companyId the company ID
1096             * @param name the name
1097             * @param roleId the role ID
1098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1099             * @return the first matching resource type permission
1100             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a matching resource type permission could not be found
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public ResourceTypePermission findByC_N_R_First(long companyId,
1104                    String name, long roleId, OrderByComparator orderByComparator)
1105                    throws NoSuchResourceTypePermissionException, SystemException {
1106                    List<ResourceTypePermission> list = findByC_N_R(companyId, name,
1107                                    roleId, 0, 1, orderByComparator);
1108    
1109                    if (list.isEmpty()) {
1110                            StringBundler msg = new StringBundler(8);
1111    
1112                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1113    
1114                            msg.append("companyId=");
1115                            msg.append(companyId);
1116    
1117                            msg.append(", name=");
1118                            msg.append(name);
1119    
1120                            msg.append(", roleId=");
1121                            msg.append(roleId);
1122    
1123                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1124    
1125                            throw new NoSuchResourceTypePermissionException(msg.toString());
1126                    }
1127                    else {
1128                            return list.get(0);
1129                    }
1130            }
1131    
1132            /**
1133             * Returns the last resource type permission in the ordered set where companyId = &#63; and name = &#63; and roleId = &#63;.
1134             *
1135             * <p>
1136             * 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.
1137             * </p>
1138             *
1139             * @param companyId the company ID
1140             * @param name the name
1141             * @param roleId the role ID
1142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1143             * @return the last matching resource type permission
1144             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a matching resource type permission could not be found
1145             * @throws SystemException if a system exception occurred
1146             */
1147            public ResourceTypePermission findByC_N_R_Last(long companyId, String name,
1148                    long roleId, OrderByComparator orderByComparator)
1149                    throws NoSuchResourceTypePermissionException, SystemException {
1150                    int count = countByC_N_R(companyId, name, roleId);
1151    
1152                    List<ResourceTypePermission> list = findByC_N_R(companyId, name,
1153                                    roleId, count - 1, count, orderByComparator);
1154    
1155                    if (list.isEmpty()) {
1156                            StringBundler msg = new StringBundler(8);
1157    
1158                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1159    
1160                            msg.append("companyId=");
1161                            msg.append(companyId);
1162    
1163                            msg.append(", name=");
1164                            msg.append(name);
1165    
1166                            msg.append(", roleId=");
1167                            msg.append(roleId);
1168    
1169                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1170    
1171                            throw new NoSuchResourceTypePermissionException(msg.toString());
1172                    }
1173                    else {
1174                            return list.get(0);
1175                    }
1176            }
1177    
1178            /**
1179             * 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;.
1180             *
1181             * <p>
1182             * 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.
1183             * </p>
1184             *
1185             * @param resourceTypePermissionId the primary key of the current resource type permission
1186             * @param companyId the company ID
1187             * @param name the name
1188             * @param roleId the role ID
1189             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1190             * @return the previous, current, and next resource type permission
1191             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a resource type permission with the primary key could not be found
1192             * @throws SystemException if a system exception occurred
1193             */
1194            public ResourceTypePermission[] findByC_N_R_PrevAndNext(
1195                    long resourceTypePermissionId, long companyId, String name,
1196                    long roleId, OrderByComparator orderByComparator)
1197                    throws NoSuchResourceTypePermissionException, SystemException {
1198                    ResourceTypePermission resourceTypePermission = findByPrimaryKey(resourceTypePermissionId);
1199    
1200                    Session session = null;
1201    
1202                    try {
1203                            session = openSession();
1204    
1205                            ResourceTypePermission[] array = new ResourceTypePermissionImpl[3];
1206    
1207                            array[0] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
1208                                            companyId, name, roleId, orderByComparator, true);
1209    
1210                            array[1] = resourceTypePermission;
1211    
1212                            array[2] = getByC_N_R_PrevAndNext(session, resourceTypePermission,
1213                                            companyId, name, roleId, orderByComparator, false);
1214    
1215                            return array;
1216                    }
1217                    catch (Exception e) {
1218                            throw processException(e);
1219                    }
1220                    finally {
1221                            closeSession(session);
1222                    }
1223            }
1224    
1225            protected ResourceTypePermission getByC_N_R_PrevAndNext(Session session,
1226                    ResourceTypePermission resourceTypePermission, long companyId,
1227                    String name, long roleId, OrderByComparator orderByComparator,
1228                    boolean previous) {
1229                    StringBundler query = null;
1230    
1231                    if (orderByComparator != null) {
1232                            query = new StringBundler(6 +
1233                                            (orderByComparator.getOrderByFields().length * 6));
1234                    }
1235                    else {
1236                            query = new StringBundler(3);
1237                    }
1238    
1239                    query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
1240    
1241                    query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
1242    
1243                    if (name == null) {
1244                            query.append(_FINDER_COLUMN_C_N_R_NAME_1);
1245                    }
1246                    else {
1247                            if (name.equals(StringPool.BLANK)) {
1248                                    query.append(_FINDER_COLUMN_C_N_R_NAME_3);
1249                            }
1250                            else {
1251                                    query.append(_FINDER_COLUMN_C_N_R_NAME_2);
1252                            }
1253                    }
1254    
1255                    query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
1256    
1257                    if (orderByComparator != null) {
1258                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1259    
1260                            if (orderByConditionFields.length > 0) {
1261                                    query.append(WHERE_AND);
1262                            }
1263    
1264                            for (int i = 0; i < orderByConditionFields.length; i++) {
1265                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1266                                    query.append(orderByConditionFields[i]);
1267    
1268                                    if ((i + 1) < orderByConditionFields.length) {
1269                                            if (orderByComparator.isAscending() ^ previous) {
1270                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1271                                            }
1272                                            else {
1273                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1274                                            }
1275                                    }
1276                                    else {
1277                                            if (orderByComparator.isAscending() ^ previous) {
1278                                                    query.append(WHERE_GREATER_THAN);
1279                                            }
1280                                            else {
1281                                                    query.append(WHERE_LESSER_THAN);
1282                                            }
1283                                    }
1284                            }
1285    
1286                            query.append(ORDER_BY_CLAUSE);
1287    
1288                            String[] orderByFields = orderByComparator.getOrderByFields();
1289    
1290                            for (int i = 0; i < orderByFields.length; i++) {
1291                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1292                                    query.append(orderByFields[i]);
1293    
1294                                    if ((i + 1) < orderByFields.length) {
1295                                            if (orderByComparator.isAscending() ^ previous) {
1296                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1297                                            }
1298                                            else {
1299                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1300                                            }
1301                                    }
1302                                    else {
1303                                            if (orderByComparator.isAscending() ^ previous) {
1304                                                    query.append(ORDER_BY_ASC);
1305                                            }
1306                                            else {
1307                                                    query.append(ORDER_BY_DESC);
1308                                            }
1309                                    }
1310                            }
1311                    }
1312    
1313                    String sql = query.toString();
1314    
1315                    Query q = session.createQuery(sql);
1316    
1317                    q.setFirstResult(0);
1318                    q.setMaxResults(2);
1319    
1320                    QueryPos qPos = QueryPos.getInstance(q);
1321    
1322                    qPos.add(companyId);
1323    
1324                    if (name != null) {
1325                            qPos.add(name);
1326                    }
1327    
1328                    qPos.add(roleId);
1329    
1330                    if (orderByComparator != null) {
1331                            Object[] values = orderByComparator.getOrderByConditionValues(resourceTypePermission);
1332    
1333                            for (Object value : values) {
1334                                    qPos.add(value);
1335                            }
1336                    }
1337    
1338                    List<ResourceTypePermission> list = q.list();
1339    
1340                    if (list.size() == 2) {
1341                            return list.get(1);
1342                    }
1343                    else {
1344                            return null;
1345                    }
1346            }
1347    
1348            /**
1349             * 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.
1350             *
1351             * @param companyId the company ID
1352             * @param groupId the group ID
1353             * @param name the name
1354             * @param roleId the role ID
1355             * @return the matching resource type permission
1356             * @throws com.liferay.portal.NoSuchResourceTypePermissionException if a matching resource type permission could not be found
1357             * @throws SystemException if a system exception occurred
1358             */
1359            public ResourceTypePermission findByC_G_N_R(long companyId, long groupId,
1360                    String name, long roleId)
1361                    throws NoSuchResourceTypePermissionException, SystemException {
1362                    ResourceTypePermission resourceTypePermission = fetchByC_G_N_R(companyId,
1363                                    groupId, name, roleId);
1364    
1365                    if (resourceTypePermission == null) {
1366                            StringBundler msg = new StringBundler(10);
1367    
1368                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1369    
1370                            msg.append("companyId=");
1371                            msg.append(companyId);
1372    
1373                            msg.append(", groupId=");
1374                            msg.append(groupId);
1375    
1376                            msg.append(", name=");
1377                            msg.append(name);
1378    
1379                            msg.append(", roleId=");
1380                            msg.append(roleId);
1381    
1382                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1383    
1384                            if (_log.isWarnEnabled()) {
1385                                    _log.warn(msg.toString());
1386                            }
1387    
1388                            throw new NoSuchResourceTypePermissionException(msg.toString());
1389                    }
1390    
1391                    return resourceTypePermission;
1392            }
1393    
1394            /**
1395             * 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.
1396             *
1397             * @param companyId the company ID
1398             * @param groupId the group ID
1399             * @param name the name
1400             * @param roleId the role ID
1401             * @return the matching resource type permission, or <code>null</code> if a matching resource type permission could not be found
1402             * @throws SystemException if a system exception occurred
1403             */
1404            public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1405                    String name, long roleId) throws SystemException {
1406                    return fetchByC_G_N_R(companyId, groupId, name, roleId, true);
1407            }
1408    
1409            /**
1410             * 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.
1411             *
1412             * @param companyId the company ID
1413             * @param groupId the group ID
1414             * @param name the name
1415             * @param roleId the role ID
1416             * @param retrieveFromCache whether to use the finder cache
1417             * @return the matching resource type permission, or <code>null</code> if a matching resource type permission could not be found
1418             * @throws SystemException if a system exception occurred
1419             */
1420            public ResourceTypePermission fetchByC_G_N_R(long companyId, long groupId,
1421                    String name, long roleId, boolean retrieveFromCache)
1422                    throws SystemException {
1423                    Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1424    
1425                    Object result = null;
1426    
1427                    if (retrieveFromCache) {
1428                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1429                                            finderArgs, this);
1430                    }
1431    
1432                    if (result == null) {
1433                            StringBundler query = new StringBundler(5);
1434    
1435                            query.append(_SQL_SELECT_RESOURCETYPEPERMISSION_WHERE);
1436    
1437                            query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1438    
1439                            query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1440    
1441                            if (name == null) {
1442                                    query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1443                            }
1444                            else {
1445                                    if (name.equals(StringPool.BLANK)) {
1446                                            query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1447                                    }
1448                                    else {
1449                                            query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1450                                    }
1451                            }
1452    
1453                            query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1454    
1455                            String sql = query.toString();
1456    
1457                            Session session = null;
1458    
1459                            try {
1460                                    session = openSession();
1461    
1462                                    Query q = session.createQuery(sql);
1463    
1464                                    QueryPos qPos = QueryPos.getInstance(q);
1465    
1466                                    qPos.add(companyId);
1467    
1468                                    qPos.add(groupId);
1469    
1470                                    if (name != null) {
1471                                            qPos.add(name);
1472                                    }
1473    
1474                                    qPos.add(roleId);
1475    
1476                                    List<ResourceTypePermission> list = q.list();
1477    
1478                                    result = list;
1479    
1480                                    ResourceTypePermission resourceTypePermission = null;
1481    
1482                                    if (list.isEmpty()) {
1483                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1484                                                    finderArgs, list);
1485                                    }
1486                                    else {
1487                                            resourceTypePermission = list.get(0);
1488    
1489                                            cacheResult(resourceTypePermission);
1490    
1491                                            if ((resourceTypePermission.getCompanyId() != companyId) ||
1492                                                            (resourceTypePermission.getGroupId() != groupId) ||
1493                                                            (resourceTypePermission.getName() == null) ||
1494                                                            !resourceTypePermission.getName().equals(name) ||
1495                                                            (resourceTypePermission.getRoleId() != roleId)) {
1496                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1497                                                            finderArgs, resourceTypePermission);
1498                                            }
1499                                    }
1500    
1501                                    return resourceTypePermission;
1502                            }
1503                            catch (Exception e) {
1504                                    throw processException(e);
1505                            }
1506                            finally {
1507                                    if (result == null) {
1508                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_G_N_R,
1509                                                    finderArgs);
1510                                    }
1511    
1512                                    closeSession(session);
1513                            }
1514                    }
1515                    else {
1516                            if (result instanceof List<?>) {
1517                                    return null;
1518                            }
1519                            else {
1520                                    return (ResourceTypePermission)result;
1521                            }
1522                    }
1523            }
1524    
1525            /**
1526             * Returns all the resource type permissions.
1527             *
1528             * @return the resource type permissions
1529             * @throws SystemException if a system exception occurred
1530             */
1531            public List<ResourceTypePermission> findAll() throws SystemException {
1532                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1533            }
1534    
1535            /**
1536             * Returns a range of all the resource type permissions.
1537             *
1538             * <p>
1539             * 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.
1540             * </p>
1541             *
1542             * @param start the lower bound of the range of resource type permissions
1543             * @param end the upper bound of the range of resource type permissions (not inclusive)
1544             * @return the range of resource type permissions
1545             * @throws SystemException if a system exception occurred
1546             */
1547            public List<ResourceTypePermission> findAll(int start, int end)
1548                    throws SystemException {
1549                    return findAll(start, end, null);
1550            }
1551    
1552            /**
1553             * Returns an ordered range of all the resource type permissions.
1554             *
1555             * <p>
1556             * 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.
1557             * </p>
1558             *
1559             * @param start the lower bound of the range of resource type permissions
1560             * @param end the upper bound of the range of resource type permissions (not inclusive)
1561             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1562             * @return the ordered range of resource type permissions
1563             * @throws SystemException if a system exception occurred
1564             */
1565            public List<ResourceTypePermission> findAll(int start, int end,
1566                    OrderByComparator orderByComparator) throws SystemException {
1567                    FinderPath finderPath = null;
1568                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1569    
1570                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1571                                    (orderByComparator == null)) {
1572                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1573                            finderArgs = FINDER_ARGS_EMPTY;
1574                    }
1575                    else {
1576                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1577                            finderArgs = new Object[] { start, end, orderByComparator };
1578                    }
1579    
1580                    List<ResourceTypePermission> list = (List<ResourceTypePermission>)FinderCacheUtil.getResult(finderPath,
1581                                    finderArgs, this);
1582    
1583                    if (list == null) {
1584                            StringBundler query = null;
1585                            String sql = null;
1586    
1587                            if (orderByComparator != null) {
1588                                    query = new StringBundler(2 +
1589                                                    (orderByComparator.getOrderByFields().length * 3));
1590    
1591                                    query.append(_SQL_SELECT_RESOURCETYPEPERMISSION);
1592    
1593                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1594                                            orderByComparator);
1595    
1596                                    sql = query.toString();
1597                            }
1598                            else {
1599                                    sql = _SQL_SELECT_RESOURCETYPEPERMISSION;
1600                            }
1601    
1602                            Session session = null;
1603    
1604                            try {
1605                                    session = openSession();
1606    
1607                                    Query q = session.createQuery(sql);
1608    
1609                                    if (orderByComparator == null) {
1610                                            list = (List<ResourceTypePermission>)QueryUtil.list(q,
1611                                                            getDialect(), start, end, false);
1612    
1613                                            Collections.sort(list);
1614                                    }
1615                                    else {
1616                                            list = (List<ResourceTypePermission>)QueryUtil.list(q,
1617                                                            getDialect(), start, end);
1618                                    }
1619                            }
1620                            catch (Exception e) {
1621                                    throw processException(e);
1622                            }
1623                            finally {
1624                                    if (list == null) {
1625                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1626                                    }
1627                                    else {
1628                                            cacheResult(list);
1629    
1630                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1631                                    }
1632    
1633                                    closeSession(session);
1634                            }
1635                    }
1636    
1637                    return list;
1638            }
1639    
1640            /**
1641             * Removes all the resource type permissions where roleId = &#63; from the database.
1642             *
1643             * @param roleId the role ID
1644             * @throws SystemException if a system exception occurred
1645             */
1646            public void removeByRoleId(long roleId) throws SystemException {
1647                    for (ResourceTypePermission resourceTypePermission : findByRoleId(
1648                                    roleId)) {
1649                            remove(resourceTypePermission);
1650                    }
1651            }
1652    
1653            /**
1654             * Removes all the resource type permissions where companyId = &#63; and name = &#63; and roleId = &#63; from the database.
1655             *
1656             * @param companyId the company ID
1657             * @param name the name
1658             * @param roleId the role ID
1659             * @throws SystemException if a system exception occurred
1660             */
1661            public void removeByC_N_R(long companyId, String name, long roleId)
1662                    throws SystemException {
1663                    for (ResourceTypePermission resourceTypePermission : findByC_N_R(
1664                                    companyId, name, roleId)) {
1665                            remove(resourceTypePermission);
1666                    }
1667            }
1668    
1669            /**
1670             * Removes the resource type permission where companyId = &#63; and groupId = &#63; and name = &#63; and roleId = &#63; from the database.
1671             *
1672             * @param companyId the company ID
1673             * @param groupId the group ID
1674             * @param name the name
1675             * @param roleId the role ID
1676             * @throws SystemException if a system exception occurred
1677             */
1678            public void removeByC_G_N_R(long companyId, long groupId, String name,
1679                    long roleId)
1680                    throws NoSuchResourceTypePermissionException, SystemException {
1681                    ResourceTypePermission resourceTypePermission = findByC_G_N_R(companyId,
1682                                    groupId, name, roleId);
1683    
1684                    remove(resourceTypePermission);
1685            }
1686    
1687            /**
1688             * Removes all the resource type permissions from the database.
1689             *
1690             * @throws SystemException if a system exception occurred
1691             */
1692            public void removeAll() throws SystemException {
1693                    for (ResourceTypePermission resourceTypePermission : findAll()) {
1694                            remove(resourceTypePermission);
1695                    }
1696            }
1697    
1698            /**
1699             * Returns the number of resource type permissions where roleId = &#63;.
1700             *
1701             * @param roleId the role ID
1702             * @return the number of matching resource type permissions
1703             * @throws SystemException if a system exception occurred
1704             */
1705            public int countByRoleId(long roleId) throws SystemException {
1706                    Object[] finderArgs = new Object[] { roleId };
1707    
1708                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1709                                    finderArgs, this);
1710    
1711                    if (count == null) {
1712                            StringBundler query = new StringBundler(2);
1713    
1714                            query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1715    
1716                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1717    
1718                            String sql = query.toString();
1719    
1720                            Session session = null;
1721    
1722                            try {
1723                                    session = openSession();
1724    
1725                                    Query q = session.createQuery(sql);
1726    
1727                                    QueryPos qPos = QueryPos.getInstance(q);
1728    
1729                                    qPos.add(roleId);
1730    
1731                                    count = (Long)q.uniqueResult();
1732                            }
1733                            catch (Exception e) {
1734                                    throw processException(e);
1735                            }
1736                            finally {
1737                                    if (count == null) {
1738                                            count = Long.valueOf(0);
1739                                    }
1740    
1741                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1742                                            finderArgs, count);
1743    
1744                                    closeSession(session);
1745                            }
1746                    }
1747    
1748                    return count.intValue();
1749            }
1750    
1751            /**
1752             * Returns the number of resource type permissions where companyId = &#63; and name = &#63; and roleId = &#63;.
1753             *
1754             * @param companyId the company ID
1755             * @param name the name
1756             * @param roleId the role ID
1757             * @return the number of matching resource type permissions
1758             * @throws SystemException if a system exception occurred
1759             */
1760            public int countByC_N_R(long companyId, String name, long roleId)
1761                    throws SystemException {
1762                    Object[] finderArgs = new Object[] { companyId, name, roleId };
1763    
1764                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_R,
1765                                    finderArgs, this);
1766    
1767                    if (count == null) {
1768                            StringBundler query = new StringBundler(4);
1769    
1770                            query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1771    
1772                            query.append(_FINDER_COLUMN_C_N_R_COMPANYID_2);
1773    
1774                            if (name == null) {
1775                                    query.append(_FINDER_COLUMN_C_N_R_NAME_1);
1776                            }
1777                            else {
1778                                    if (name.equals(StringPool.BLANK)) {
1779                                            query.append(_FINDER_COLUMN_C_N_R_NAME_3);
1780                                    }
1781                                    else {
1782                                            query.append(_FINDER_COLUMN_C_N_R_NAME_2);
1783                                    }
1784                            }
1785    
1786                            query.append(_FINDER_COLUMN_C_N_R_ROLEID_2);
1787    
1788                            String sql = query.toString();
1789    
1790                            Session session = null;
1791    
1792                            try {
1793                                    session = openSession();
1794    
1795                                    Query q = session.createQuery(sql);
1796    
1797                                    QueryPos qPos = QueryPos.getInstance(q);
1798    
1799                                    qPos.add(companyId);
1800    
1801                                    if (name != null) {
1802                                            qPos.add(name);
1803                                    }
1804    
1805                                    qPos.add(roleId);
1806    
1807                                    count = (Long)q.uniqueResult();
1808                            }
1809                            catch (Exception e) {
1810                                    throw processException(e);
1811                            }
1812                            finally {
1813                                    if (count == null) {
1814                                            count = Long.valueOf(0);
1815                                    }
1816    
1817                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_R,
1818                                            finderArgs, count);
1819    
1820                                    closeSession(session);
1821                            }
1822                    }
1823    
1824                    return count.intValue();
1825            }
1826    
1827            /**
1828             * Returns the number of resource type permissions where companyId = &#63; and groupId = &#63; and name = &#63; and roleId = &#63;.
1829             *
1830             * @param companyId the company ID
1831             * @param groupId the group ID
1832             * @param name the name
1833             * @param roleId the role ID
1834             * @return the number of matching resource type permissions
1835             * @throws SystemException if a system exception occurred
1836             */
1837            public int countByC_G_N_R(long companyId, long groupId, String name,
1838                    long roleId) throws SystemException {
1839                    Object[] finderArgs = new Object[] { companyId, groupId, name, roleId };
1840    
1841                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_G_N_R,
1842                                    finderArgs, this);
1843    
1844                    if (count == null) {
1845                            StringBundler query = new StringBundler(5);
1846    
1847                            query.append(_SQL_COUNT_RESOURCETYPEPERMISSION_WHERE);
1848    
1849                            query.append(_FINDER_COLUMN_C_G_N_R_COMPANYID_2);
1850    
1851                            query.append(_FINDER_COLUMN_C_G_N_R_GROUPID_2);
1852    
1853                            if (name == null) {
1854                                    query.append(_FINDER_COLUMN_C_G_N_R_NAME_1);
1855                            }
1856                            else {
1857                                    if (name.equals(StringPool.BLANK)) {
1858                                            query.append(_FINDER_COLUMN_C_G_N_R_NAME_3);
1859                                    }
1860                                    else {
1861                                            query.append(_FINDER_COLUMN_C_G_N_R_NAME_2);
1862                                    }
1863                            }
1864    
1865                            query.append(_FINDER_COLUMN_C_G_N_R_ROLEID_2);
1866    
1867                            String sql = query.toString();
1868    
1869                            Session session = null;
1870    
1871                            try {
1872                                    session = openSession();
1873    
1874                                    Query q = session.createQuery(sql);
1875    
1876                                    QueryPos qPos = QueryPos.getInstance(q);
1877    
1878                                    qPos.add(companyId);
1879    
1880                                    qPos.add(groupId);
1881    
1882                                    if (name != null) {
1883                                            qPos.add(name);
1884                                    }
1885    
1886                                    qPos.add(roleId);
1887    
1888                                    count = (Long)q.uniqueResult();
1889                            }
1890                            catch (Exception e) {
1891                                    throw processException(e);
1892                            }
1893                            finally {
1894                                    if (count == null) {
1895                                            count = Long.valueOf(0);
1896                                    }
1897    
1898                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_G_N_R,
1899                                            finderArgs, count);
1900    
1901                                    closeSession(session);
1902                            }
1903                    }
1904    
1905                    return count.intValue();
1906            }
1907    
1908            /**
1909             * Returns the number of resource type permissions.
1910             *
1911             * @return the number of resource type permissions
1912             * @throws SystemException if a system exception occurred
1913             */
1914            public int countAll() throws SystemException {
1915                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1916                                    FINDER_ARGS_EMPTY, this);
1917    
1918                    if (count == null) {
1919                            Session session = null;
1920    
1921                            try {
1922                                    session = openSession();
1923    
1924                                    Query q = session.createQuery(_SQL_COUNT_RESOURCETYPEPERMISSION);
1925    
1926                                    count = (Long)q.uniqueResult();
1927                            }
1928                            catch (Exception e) {
1929                                    throw processException(e);
1930                            }
1931                            finally {
1932                                    if (count == null) {
1933                                            count = Long.valueOf(0);
1934                                    }
1935    
1936                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1937                                            FINDER_ARGS_EMPTY, count);
1938    
1939                                    closeSession(session);
1940                            }
1941                    }
1942    
1943                    return count.intValue();
1944            }
1945    
1946            /**
1947             * Initializes the resource type permission persistence.
1948             */
1949            public void afterPropertiesSet() {
1950                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1951                                            com.liferay.portal.util.PropsUtil.get(
1952                                                    "value.object.listener.com.liferay.portal.model.ResourceTypePermission")));
1953    
1954                    if (listenerClassNames.length > 0) {
1955                            try {
1956                                    List<ModelListener<ResourceTypePermission>> listenersList = new ArrayList<ModelListener<ResourceTypePermission>>();
1957    
1958                                    for (String listenerClassName : listenerClassNames) {
1959                                            listenersList.add((ModelListener<ResourceTypePermission>)InstanceFactory.newInstance(
1960                                                            listenerClassName));
1961                                    }
1962    
1963                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1964                            }
1965                            catch (Exception e) {
1966                                    _log.error(e);
1967                            }
1968                    }
1969            }
1970    
1971            public void destroy() {
1972                    EntityCacheUtil.removeCache(ResourceTypePermissionImpl.class.getName());
1973                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1974                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1975            }
1976    
1977            @BeanReference(type = AccountPersistence.class)
1978            protected AccountPersistence accountPersistence;
1979            @BeanReference(type = AddressPersistence.class)
1980            protected AddressPersistence addressPersistence;
1981            @BeanReference(type = BrowserTrackerPersistence.class)
1982            protected BrowserTrackerPersistence browserTrackerPersistence;
1983            @BeanReference(type = ClassNamePersistence.class)
1984            protected ClassNamePersistence classNamePersistence;
1985            @BeanReference(type = ClusterGroupPersistence.class)
1986            protected ClusterGroupPersistence clusterGroupPersistence;
1987            @BeanReference(type = CompanyPersistence.class)
1988            protected CompanyPersistence companyPersistence;
1989            @BeanReference(type = ContactPersistence.class)
1990            protected ContactPersistence contactPersistence;
1991            @BeanReference(type = CountryPersistence.class)
1992            protected CountryPersistence countryPersistence;
1993            @BeanReference(type = EmailAddressPersistence.class)
1994            protected EmailAddressPersistence emailAddressPersistence;
1995            @BeanReference(type = GroupPersistence.class)
1996            protected GroupPersistence groupPersistence;
1997            @BeanReference(type = ImagePersistence.class)
1998            protected ImagePersistence imagePersistence;
1999            @BeanReference(type = LayoutPersistence.class)
2000            protected LayoutPersistence layoutPersistence;
2001            @BeanReference(type = LayoutBranchPersistence.class)
2002            protected LayoutBranchPersistence layoutBranchPersistence;
2003            @BeanReference(type = LayoutPrototypePersistence.class)
2004            protected LayoutPrototypePersistence layoutPrototypePersistence;
2005            @BeanReference(type = LayoutRevisionPersistence.class)
2006            protected LayoutRevisionPersistence layoutRevisionPersistence;
2007            @BeanReference(type = LayoutSetPersistence.class)
2008            protected LayoutSetPersistence layoutSetPersistence;
2009            @BeanReference(type = LayoutSetBranchPersistence.class)
2010            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2011            @BeanReference(type = LayoutSetPrototypePersistence.class)
2012            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2013            @BeanReference(type = ListTypePersistence.class)
2014            protected ListTypePersistence listTypePersistence;
2015            @BeanReference(type = LockPersistence.class)
2016            protected LockPersistence lockPersistence;
2017            @BeanReference(type = MembershipRequestPersistence.class)
2018            protected MembershipRequestPersistence membershipRequestPersistence;
2019            @BeanReference(type = OrganizationPersistence.class)
2020            protected OrganizationPersistence organizationPersistence;
2021            @BeanReference(type = OrgGroupPermissionPersistence.class)
2022            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2023            @BeanReference(type = OrgGroupRolePersistence.class)
2024            protected OrgGroupRolePersistence orgGroupRolePersistence;
2025            @BeanReference(type = OrgLaborPersistence.class)
2026            protected OrgLaborPersistence orgLaborPersistence;
2027            @BeanReference(type = PasswordPolicyPersistence.class)
2028            protected PasswordPolicyPersistence passwordPolicyPersistence;
2029            @BeanReference(type = PasswordPolicyRelPersistence.class)
2030            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2031            @BeanReference(type = PasswordTrackerPersistence.class)
2032            protected PasswordTrackerPersistence passwordTrackerPersistence;
2033            @BeanReference(type = PermissionPersistence.class)
2034            protected PermissionPersistence permissionPersistence;
2035            @BeanReference(type = PhonePersistence.class)
2036            protected PhonePersistence phonePersistence;
2037            @BeanReference(type = PluginSettingPersistence.class)
2038            protected PluginSettingPersistence pluginSettingPersistence;
2039            @BeanReference(type = PortalPreferencesPersistence.class)
2040            protected PortalPreferencesPersistence portalPreferencesPersistence;
2041            @BeanReference(type = PortletPersistence.class)
2042            protected PortletPersistence portletPersistence;
2043            @BeanReference(type = PortletItemPersistence.class)
2044            protected PortletItemPersistence portletItemPersistence;
2045            @BeanReference(type = PortletPreferencesPersistence.class)
2046            protected PortletPreferencesPersistence portletPreferencesPersistence;
2047            @BeanReference(type = RegionPersistence.class)
2048            protected RegionPersistence regionPersistence;
2049            @BeanReference(type = ReleasePersistence.class)
2050            protected ReleasePersistence releasePersistence;
2051            @BeanReference(type = RepositoryPersistence.class)
2052            protected RepositoryPersistence repositoryPersistence;
2053            @BeanReference(type = RepositoryEntryPersistence.class)
2054            protected RepositoryEntryPersistence repositoryEntryPersistence;
2055            @BeanReference(type = ResourcePersistence.class)
2056            protected ResourcePersistence resourcePersistence;
2057            @BeanReference(type = ResourceActionPersistence.class)
2058            protected ResourceActionPersistence resourceActionPersistence;
2059            @BeanReference(type = ResourceBlockPersistence.class)
2060            protected ResourceBlockPersistence resourceBlockPersistence;
2061            @BeanReference(type = ResourceBlockPermissionPersistence.class)
2062            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2063            @BeanReference(type = ResourceCodePersistence.class)
2064            protected ResourceCodePersistence resourceCodePersistence;
2065            @BeanReference(type = ResourcePermissionPersistence.class)
2066            protected ResourcePermissionPersistence resourcePermissionPersistence;
2067            @BeanReference(type = ResourceTypePermissionPersistence.class)
2068            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2069            @BeanReference(type = RolePersistence.class)
2070            protected RolePersistence rolePersistence;
2071            @BeanReference(type = ServiceComponentPersistence.class)
2072            protected ServiceComponentPersistence serviceComponentPersistence;
2073            @BeanReference(type = ShardPersistence.class)
2074            protected ShardPersistence shardPersistence;
2075            @BeanReference(type = SubscriptionPersistence.class)
2076            protected SubscriptionPersistence subscriptionPersistence;
2077            @BeanReference(type = TeamPersistence.class)
2078            protected TeamPersistence teamPersistence;
2079            @BeanReference(type = TicketPersistence.class)
2080            protected TicketPersistence ticketPersistence;
2081            @BeanReference(type = UserPersistence.class)
2082            protected UserPersistence userPersistence;
2083            @BeanReference(type = UserGroupPersistence.class)
2084            protected UserGroupPersistence userGroupPersistence;
2085            @BeanReference(type = UserGroupGroupRolePersistence.class)
2086            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2087            @BeanReference(type = UserGroupRolePersistence.class)
2088            protected UserGroupRolePersistence userGroupRolePersistence;
2089            @BeanReference(type = UserIdMapperPersistence.class)
2090            protected UserIdMapperPersistence userIdMapperPersistence;
2091            @BeanReference(type = UserNotificationEventPersistence.class)
2092            protected UserNotificationEventPersistence userNotificationEventPersistence;
2093            @BeanReference(type = UserTrackerPersistence.class)
2094            protected UserTrackerPersistence userTrackerPersistence;
2095            @BeanReference(type = UserTrackerPathPersistence.class)
2096            protected UserTrackerPathPersistence userTrackerPathPersistence;
2097            @BeanReference(type = VirtualHostPersistence.class)
2098            protected VirtualHostPersistence virtualHostPersistence;
2099            @BeanReference(type = WebDAVPropsPersistence.class)
2100            protected WebDAVPropsPersistence webDAVPropsPersistence;
2101            @BeanReference(type = WebsitePersistence.class)
2102            protected WebsitePersistence websitePersistence;
2103            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2104            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2105            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2106            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2107            private static final String _SQL_SELECT_RESOURCETYPEPERMISSION = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission";
2108            private static final String _SQL_SELECT_RESOURCETYPEPERMISSION_WHERE = "SELECT resourceTypePermission FROM ResourceTypePermission resourceTypePermission WHERE ";
2109            private static final String _SQL_COUNT_RESOURCETYPEPERMISSION = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission";
2110            private static final String _SQL_COUNT_RESOURCETYPEPERMISSION_WHERE = "SELECT COUNT(resourceTypePermission) FROM ResourceTypePermission resourceTypePermission WHERE ";
2111            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourceTypePermission.roleId = ?";
2112            private static final String _FINDER_COLUMN_C_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
2113            private static final String _FINDER_COLUMN_C_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
2114            private static final String _FINDER_COLUMN_C_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
2115            private static final String _FINDER_COLUMN_C_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = ?) AND ";
2116            private static final String _FINDER_COLUMN_C_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
2117            private static final String _FINDER_COLUMN_C_G_N_R_COMPANYID_2 = "resourceTypePermission.companyId = ? AND ";
2118            private static final String _FINDER_COLUMN_C_G_N_R_GROUPID_2 = "resourceTypePermission.groupId = ? AND ";
2119            private static final String _FINDER_COLUMN_C_G_N_R_NAME_1 = "resourceTypePermission.name IS NULL AND ";
2120            private static final String _FINDER_COLUMN_C_G_N_R_NAME_2 = "resourceTypePermission.name = ? AND ";
2121            private static final String _FINDER_COLUMN_C_G_N_R_NAME_3 = "(resourceTypePermission.name IS NULL OR resourceTypePermission.name = ?) AND ";
2122            private static final String _FINDER_COLUMN_C_G_N_R_ROLEID_2 = "resourceTypePermission.roleId = ?";
2123            private static final String _ORDER_BY_ENTITY_ALIAS = "resourceTypePermission.";
2124            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourceTypePermission exists with the primary key ";
2125            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourceTypePermission exists with the key {";
2126            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2127            private static Log _log = LogFactoryUtil.getLog(ResourceTypePermissionPersistenceImpl.class);
2128            private static ResourceTypePermission _nullResourceTypePermission = new ResourceTypePermissionImpl() {
2129                            @Override
2130                            public Object clone() {
2131                                    return this;
2132                            }
2133    
2134                            @Override
2135                            public CacheModel<ResourceTypePermission> toCacheModel() {
2136                                    return _nullResourceTypePermissionCacheModel;
2137                            }
2138                    };
2139    
2140            private static CacheModel<ResourceTypePermission> _nullResourceTypePermissionCacheModel =
2141                    new CacheModel<ResourceTypePermission>() {
2142                            public ResourceTypePermission toEntityModel() {
2143                                    return _nullResourceTypePermission;
2144                            }
2145                    };
2146    }