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