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