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