001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchResourcePermissionException;
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.ResourcePermission;
040    import com.liferay.portal.model.impl.ResourcePermissionImpl;
041    import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
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 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 ResourcePermissionPersistence
059     * @see ResourcePermissionUtil
060     * @generated
061     */
062    public class ResourcePermissionPersistenceImpl extends BasePersistenceImpl<ResourcePermission>
063            implements ResourcePermissionPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link ResourcePermissionUtil} to access the resource permission persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = ResourcePermissionImpl.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_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
075                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
076                            ResourcePermissionImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByScope",
078                            new String[] {
079                                    Integer.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_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
085                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
086                            ResourcePermissionImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByScope",
088                            new String[] { Integer.class.getName() },
089                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK);
090            public static final FinderPath FINDER_PATH_COUNT_BY_SCOPE = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
091                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByScope",
093                            new String[] { Integer.class.getName() });
094            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
095                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
096                            ResourcePermissionImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
098                            new String[] {
099                                    Long.class.getName(),
100                                    
101                            "java.lang.Integer", "java.lang.Integer",
102                                    "com.liferay.portal.kernel.util.OrderByComparator"
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
105                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
106                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
107                            ResourcePermissionImpl.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
109                            new String[] { Long.class.getName() },
110                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
111            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
112                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
113                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
114                            new String[] { Long.class.getName() });
115            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
116                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
117                            ResourcePermissionImpl.class,
118                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S",
119                            new String[] {
120                                    Long.class.getName(), String.class.getName(),
121                                    Integer.class.getName(),
122                                    
123                            "java.lang.Integer", "java.lang.Integer",
124                                    "com.liferay.portal.kernel.util.OrderByComparator"
125                            });
126            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
127                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
128                            ResourcePermissionImpl.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S",
130                            new String[] {
131                                    Long.class.getName(), String.class.getName(),
132                                    Integer.class.getName()
133                            },
134                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
135                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
136                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK);
137            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
138                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
139                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S",
140                            new String[] {
141                                    Long.class.getName(), String.class.getName(),
142                                    Integer.class.getName()
143                            });
144            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
145                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
146                            ResourcePermissionImpl.class,
147                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P",
148                            new String[] {
149                                    Long.class.getName(), String.class.getName(),
150                                    Integer.class.getName(), String.class.getName(),
151                                    
152                            "java.lang.Integer", "java.lang.Integer",
153                                    "com.liferay.portal.kernel.util.OrderByComparator"
154                            });
155            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P =
156                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
157                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
158                            ResourcePermissionImpl.class,
159                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P",
160                            new String[] {
161                                    Long.class.getName(), String.class.getName(),
162                                    Integer.class.getName(), String.class.getName()
163                            },
164                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
165                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
166                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
167                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK);
168            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
169                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
170                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P",
171                            new String[] {
172                                    Long.class.getName(), String.class.getName(),
173                                    Integer.class.getName(), String.class.getName()
174                            });
175            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_O = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
176                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
177                            ResourcePermissionImpl.class,
178                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_P_O",
179                            new String[] {
180                                    Long.class.getName(), String.class.getName(),
181                                    String.class.getName(), Long.class.getName(),
182                                    
183                            "java.lang.Integer", "java.lang.Integer",
184                                    "com.liferay.portal.kernel.util.OrderByComparator"
185                            });
186            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O =
187                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
188                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
189                            ResourcePermissionImpl.class,
190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_P_O",
191                            new String[] {
192                                    Long.class.getName(), String.class.getName(),
193                                    String.class.getName(), Long.class.getName()
194                            },
195                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
196                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
197                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
198                            ResourcePermissionModelImpl.OWNERID_COLUMN_BITMASK);
199            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_P_O = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
200                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
201                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_P_O",
202                            new String[] {
203                                    Long.class.getName(), String.class.getName(),
204                                    String.class.getName(), Long.class.getName()
205                            });
206            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R =
207                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
208                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
209                            ResourcePermissionImpl.class,
210                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P_R",
211                            new String[] {
212                                    Long.class.getName(), String.class.getName(),
213                                    Integer.class.getName(), String.class.getName(),
214                                    Long.class.getName(),
215                                    
216                            "java.lang.Integer", "java.lang.Integer",
217                                    "com.liferay.portal.kernel.util.OrderByComparator"
218                            });
219            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R =
220                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
221                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
222                            ResourcePermissionImpl.class,
223                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P_R",
224                            new String[] {
225                                    Long.class.getName(), String.class.getName(),
226                                    Integer.class.getName(), String.class.getName(),
227                                    Long.class.getName()
228                            },
229                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
230                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
231                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
232                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
233                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK);
234            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
235                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
236                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R",
237                            new String[] {
238                                    Long.class.getName(), String.class.getName(),
239                                    Integer.class.getName(), String.class.getName(),
240                                    Long.class.getName()
241                            });
242            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_R_A =
243                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
244                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
245                            ResourcePermissionImpl.class,
246                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_P_R_A",
247                            new String[] {
248                                    Long.class.getName(), String.class.getName(),
249                                    String.class.getName(), Long.class.getName(),
250                                    Long.class.getName(),
251                                    
252                            "java.lang.Integer", "java.lang.Integer",
253                                    "com.liferay.portal.kernel.util.OrderByComparator"
254                            });
255            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A =
256                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
257                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
258                            ResourcePermissionImpl.class,
259                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_P_R_A",
260                            new String[] {
261                                    Long.class.getName(), String.class.getName(),
262                                    String.class.getName(), Long.class.getName(),
263                                    Long.class.getName()
264                            },
265                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
266                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
267                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
268                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK |
269                            ResourcePermissionModelImpl.ACTIONIDS_COLUMN_BITMASK);
270            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_P_R_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
271                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
272                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_P_R_A",
273                            new String[] {
274                                    Long.class.getName(), String.class.getName(),
275                                    String.class.getName(), Long.class.getName(),
276                                    Long.class.getName()
277                            });
278            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A =
279                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
280                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
281                            ResourcePermissionImpl.class,
282                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_N_S_P_R_A",
283                            new String[] {
284                                    Long.class.getName(), String.class.getName(),
285                                    Integer.class.getName(), String.class.getName(),
286                                    Long.class.getName(), Long.class.getName(),
287                                    
288                            "java.lang.Integer", "java.lang.Integer",
289                                    "com.liferay.portal.kernel.util.OrderByComparator"
290                            });
291            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A =
292                    new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
293                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
294                            ResourcePermissionImpl.class,
295                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_N_S_P_R_A",
296                            new String[] {
297                                    Long.class.getName(), String.class.getName(),
298                                    Integer.class.getName(), String.class.getName(),
299                                    Long.class.getName(), Long.class.getName()
300                            },
301                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
302                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
303                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
304                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
305                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK |
306                            ResourcePermissionModelImpl.ACTIONIDS_COLUMN_BITMASK);
307            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
308                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
309                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R_A",
310                            new String[] {
311                                    Long.class.getName(), String.class.getName(),
312                                    Integer.class.getName(), String.class.getName(),
313                                    Long.class.getName(), Long.class.getName()
314                            });
315            public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
316                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
317                            ResourcePermissionImpl.class, FINDER_CLASS_NAME_ENTITY,
318                            "fetchByC_N_S_P_R_O_A",
319                            new String[] {
320                                    Long.class.getName(), String.class.getName(),
321                                    Integer.class.getName(), String.class.getName(),
322                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
323                            },
324                            ResourcePermissionModelImpl.COMPANYID_COLUMN_BITMASK |
325                            ResourcePermissionModelImpl.NAME_COLUMN_BITMASK |
326                            ResourcePermissionModelImpl.SCOPE_COLUMN_BITMASK |
327                            ResourcePermissionModelImpl.PRIMKEY_COLUMN_BITMASK |
328                            ResourcePermissionModelImpl.ROLEID_COLUMN_BITMASK |
329                            ResourcePermissionModelImpl.OWNERID_COLUMN_BITMASK |
330                            ResourcePermissionModelImpl.ACTIONIDS_COLUMN_BITMASK);
331            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
332                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
333                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N_S_P_R_O_A",
334                            new String[] {
335                                    Long.class.getName(), String.class.getName(),
336                                    Integer.class.getName(), String.class.getName(),
337                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
338                            });
339            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
340                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
341                            ResourcePermissionImpl.class,
342                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
343            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
344                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
345                            ResourcePermissionImpl.class,
346                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
347            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
348                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
349                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
350    
351            /**
352             * Caches the resource permission in the entity cache if it is enabled.
353             *
354             * @param resourcePermission the resource permission
355             */
356            public void cacheResult(ResourcePermission resourcePermission) {
357                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
358                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
359                            resourcePermission);
360    
361                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
362                            new Object[] {
363                                    Long.valueOf(resourcePermission.getCompanyId()),
364                                    
365                            resourcePermission.getName(),
366                                    Integer.valueOf(resourcePermission.getScope()),
367                                    
368                            resourcePermission.getPrimKey(),
369                                    Long.valueOf(resourcePermission.getRoleId()),
370                                    Long.valueOf(resourcePermission.getOwnerId()),
371                                    Long.valueOf(resourcePermission.getActionIds())
372                            }, resourcePermission);
373    
374                    resourcePermission.resetOriginalValues();
375            }
376    
377            /**
378             * Caches the resource permissions in the entity cache if it is enabled.
379             *
380             * @param resourcePermissions the resource permissions
381             */
382            public void cacheResult(List<ResourcePermission> resourcePermissions) {
383                    for (ResourcePermission resourcePermission : resourcePermissions) {
384                            if (EntityCacheUtil.getResult(
385                                                    ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
386                                                    ResourcePermissionImpl.class,
387                                                    resourcePermission.getPrimaryKey()) == null) {
388                                    cacheResult(resourcePermission);
389                            }
390                            else {
391                                    resourcePermission.resetOriginalValues();
392                            }
393                    }
394            }
395    
396            /**
397             * Clears the cache for all resource permissions.
398             *
399             * <p>
400             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
401             * </p>
402             */
403            @Override
404            public void clearCache() {
405                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
406                            CacheRegistryUtil.clear(ResourcePermissionImpl.class.getName());
407                    }
408    
409                    EntityCacheUtil.clearCache(ResourcePermissionImpl.class.getName());
410    
411                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
412                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
413                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
414            }
415    
416            /**
417             * Clears the cache for the resource permission.
418             *
419             * <p>
420             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
421             * </p>
422             */
423            @Override
424            public void clearCache(ResourcePermission resourcePermission) {
425                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
426                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
427    
428                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
429                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
430    
431                    clearUniqueFindersCache(resourcePermission);
432            }
433    
434            @Override
435            public void clearCache(List<ResourcePermission> resourcePermissions) {
436                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
437                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
438    
439                    for (ResourcePermission resourcePermission : resourcePermissions) {
440                            EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
441                                    ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
442    
443                            clearUniqueFindersCache(resourcePermission);
444                    }
445            }
446    
447            protected void clearUniqueFindersCache(
448                    ResourcePermission resourcePermission) {
449                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
450                            new Object[] {
451                                    Long.valueOf(resourcePermission.getCompanyId()),
452                                    
453                            resourcePermission.getName(),
454                                    Integer.valueOf(resourcePermission.getScope()),
455                                    
456                            resourcePermission.getPrimKey(),
457                                    Long.valueOf(resourcePermission.getRoleId()),
458                                    Long.valueOf(resourcePermission.getOwnerId()),
459                                    Long.valueOf(resourcePermission.getActionIds())
460                            });
461            }
462    
463            /**
464             * Creates a new resource permission with the primary key. Does not add the resource permission to the database.
465             *
466             * @param resourcePermissionId the primary key for the new resource permission
467             * @return the new resource permission
468             */
469            public ResourcePermission create(long resourcePermissionId) {
470                    ResourcePermission resourcePermission = new ResourcePermissionImpl();
471    
472                    resourcePermission.setNew(true);
473                    resourcePermission.setPrimaryKey(resourcePermissionId);
474    
475                    return resourcePermission;
476            }
477    
478            /**
479             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
480             *
481             * @param resourcePermissionId the primary key of the resource permission
482             * @return the resource permission that was removed
483             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
484             * @throws SystemException if a system exception occurred
485             */
486            public ResourcePermission remove(long resourcePermissionId)
487                    throws NoSuchResourcePermissionException, SystemException {
488                    return remove(Long.valueOf(resourcePermissionId));
489            }
490    
491            /**
492             * Removes the resource permission with the primary key from the database. Also notifies the appropriate model listeners.
493             *
494             * @param primaryKey the primary key of the resource permission
495             * @return the resource permission that was removed
496             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
497             * @throws SystemException if a system exception occurred
498             */
499            @Override
500            public ResourcePermission remove(Serializable primaryKey)
501                    throws NoSuchResourcePermissionException, SystemException {
502                    Session session = null;
503    
504                    try {
505                            session = openSession();
506    
507                            ResourcePermission resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
508                                            primaryKey);
509    
510                            if (resourcePermission == null) {
511                                    if (_log.isWarnEnabled()) {
512                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
513                                    }
514    
515                                    throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
516                                            primaryKey);
517                            }
518    
519                            return remove(resourcePermission);
520                    }
521                    catch (NoSuchResourcePermissionException nsee) {
522                            throw nsee;
523                    }
524                    catch (Exception e) {
525                            throw processException(e);
526                    }
527                    finally {
528                            closeSession(session);
529                    }
530            }
531    
532            @Override
533            protected ResourcePermission removeImpl(
534                    ResourcePermission resourcePermission) throws SystemException {
535                    resourcePermission = toUnwrappedModel(resourcePermission);
536    
537                    Session session = null;
538    
539                    try {
540                            session = openSession();
541    
542                            BatchSessionUtil.delete(session, resourcePermission);
543                    }
544                    catch (Exception e) {
545                            throw processException(e);
546                    }
547                    finally {
548                            closeSession(session);
549                    }
550    
551                    clearCache(resourcePermission);
552    
553                    return resourcePermission;
554            }
555    
556            @Override
557            public ResourcePermission updateImpl(
558                    com.liferay.portal.model.ResourcePermission resourcePermission,
559                    boolean merge) throws SystemException {
560                    resourcePermission = toUnwrappedModel(resourcePermission);
561    
562                    boolean isNew = resourcePermission.isNew();
563    
564                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
565    
566                    Session session = null;
567    
568                    try {
569                            session = openSession();
570    
571                            BatchSessionUtil.update(session, resourcePermission, merge);
572    
573                            resourcePermission.setNew(false);
574                    }
575                    catch (Exception e) {
576                            throw processException(e);
577                    }
578                    finally {
579                            closeSession(session);
580                    }
581    
582                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
583    
584                    if (isNew || !ResourcePermissionModelImpl.COLUMN_BITMASK_ENABLED) {
585                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
586                    }
587    
588                    else {
589                            if ((resourcePermissionModelImpl.getColumnBitmask() &
590                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE.getColumnBitmask()) != 0) {
591                                    Object[] args = new Object[] {
592                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope())
593                                            };
594    
595                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SCOPE, args);
596                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE,
597                                            args);
598    
599                                    args = new Object[] {
600                                                    Integer.valueOf(resourcePermissionModelImpl.getScope())
601                                            };
602    
603                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SCOPE, args);
604                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE,
605                                            args);
606                            }
607    
608                            if ((resourcePermissionModelImpl.getColumnBitmask() &
609                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
610                                    Object[] args = new Object[] {
611                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId())
612                                            };
613    
614                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
615                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
616                                            args);
617    
618                                    args = new Object[] {
619                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId())
620                                            };
621    
622                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
623                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
624                                            args);
625                            }
626    
627                            if ((resourcePermissionModelImpl.getColumnBitmask() &
628                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S.getColumnBitmask()) != 0) {
629                                    Object[] args = new Object[] {
630                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
631                                                    
632                                                    resourcePermissionModelImpl.getOriginalName(),
633                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope())
634                                            };
635    
636                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
637                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S,
638                                            args);
639    
640                                    args = new Object[] {
641                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
642                                                    
643                                                    resourcePermissionModelImpl.getName(),
644                                                    Integer.valueOf(resourcePermissionModelImpl.getScope())
645                                            };
646    
647                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S, args);
648                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S,
649                                            args);
650                            }
651    
652                            if ((resourcePermissionModelImpl.getColumnBitmask() &
653                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P.getColumnBitmask()) != 0) {
654                                    Object[] args = new Object[] {
655                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
656                                                    
657                                                    resourcePermissionModelImpl.getOriginalName(),
658                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
659                                                    
660                                                    resourcePermissionModelImpl.getOriginalPrimKey()
661                                            };
662    
663                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P, args);
664                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P,
665                                            args);
666    
667                                    args = new Object[] {
668                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
669                                                    
670                                                    resourcePermissionModelImpl.getName(),
671                                                    Integer.valueOf(resourcePermissionModelImpl.getScope()),
672                                                    
673                                                    resourcePermissionModelImpl.getPrimKey()
674                                            };
675    
676                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P, args);
677                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P,
678                                            args);
679                            }
680    
681                            if ((resourcePermissionModelImpl.getColumnBitmask() &
682                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O.getColumnBitmask()) != 0) {
683                                    Object[] args = new Object[] {
684                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
685                                                    
686                                                    resourcePermissionModelImpl.getOriginalName(),
687                                                    
688                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
689                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalOwnerId())
690                                            };
691    
692                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_O, args);
693                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O,
694                                            args);
695    
696                                    args = new Object[] {
697                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
698                                                    
699                                                    resourcePermissionModelImpl.getName(),
700                                                    
701                                                    resourcePermissionModelImpl.getPrimKey(),
702                                                    Long.valueOf(resourcePermissionModelImpl.getOwnerId())
703                                            };
704    
705                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_O, args);
706                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O,
707                                            args);
708                            }
709    
710                            if ((resourcePermissionModelImpl.getColumnBitmask() &
711                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R.getColumnBitmask()) != 0) {
712                                    Object[] args = new Object[] {
713                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
714                                                    
715                                                    resourcePermissionModelImpl.getOriginalName(),
716                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
717                                                    
718                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
719                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId())
720                                            };
721    
722                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
723                                            args);
724                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R,
725                                            args);
726    
727                                    args = new Object[] {
728                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
729                                                    
730                                                    resourcePermissionModelImpl.getName(),
731                                                    Integer.valueOf(resourcePermissionModelImpl.getScope()),
732                                                    
733                                                    resourcePermissionModelImpl.getPrimKey(),
734                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId())
735                                            };
736    
737                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
738                                            args);
739                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R,
740                                            args);
741                            }
742    
743                            if ((resourcePermissionModelImpl.getColumnBitmask() &
744                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A.getColumnBitmask()) != 0) {
745                                    Object[] args = new Object[] {
746                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
747                                                    
748                                                    resourcePermissionModelImpl.getOriginalName(),
749                                                    
750                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
751                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId()),
752                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalActionIds())
753                                            };
754    
755                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_R_A,
756                                            args);
757                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A,
758                                            args);
759    
760                                    args = new Object[] {
761                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
762                                                    
763                                                    resourcePermissionModelImpl.getName(),
764                                                    
765                                                    resourcePermissionModelImpl.getPrimKey(),
766                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId()),
767                                                    Long.valueOf(resourcePermissionModelImpl.getActionIds())
768                                            };
769    
770                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_P_R_A,
771                                            args);
772                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A,
773                                            args);
774                            }
775    
776                            if ((resourcePermissionModelImpl.getColumnBitmask() &
777                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A.getColumnBitmask()) != 0) {
778                                    Object[] args = new Object[] {
779                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
780                                                    
781                                                    resourcePermissionModelImpl.getOriginalName(),
782                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
783                                                    
784                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
785                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId()),
786                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalActionIds())
787                                            };
788    
789                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
790                                            args);
791                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A,
792                                            args);
793    
794                                    args = new Object[] {
795                                                    Long.valueOf(resourcePermissionModelImpl.getCompanyId()),
796                                                    
797                                                    resourcePermissionModelImpl.getName(),
798                                                    Integer.valueOf(resourcePermissionModelImpl.getScope()),
799                                                    
800                                                    resourcePermissionModelImpl.getPrimKey(),
801                                                    Long.valueOf(resourcePermissionModelImpl.getRoleId()),
802                                                    Long.valueOf(resourcePermissionModelImpl.getActionIds())
803                                            };
804    
805                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
806                                            args);
807                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A,
808                                            args);
809                            }
810                    }
811    
812                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
813                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
814                            resourcePermission);
815    
816                    if (isNew) {
817                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
818                                    new Object[] {
819                                            Long.valueOf(resourcePermission.getCompanyId()),
820                                            
821                                    resourcePermission.getName(),
822                                            Integer.valueOf(resourcePermission.getScope()),
823                                            
824                                    resourcePermission.getPrimKey(),
825                                            Long.valueOf(resourcePermission.getRoleId()),
826                                            Long.valueOf(resourcePermission.getOwnerId()),
827                                            Long.valueOf(resourcePermission.getActionIds())
828                                    }, resourcePermission);
829                    }
830                    else {
831                            if ((resourcePermissionModelImpl.getColumnBitmask() &
832                                            FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A.getColumnBitmask()) != 0) {
833                                    Object[] args = new Object[] {
834                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalCompanyId()),
835                                                    
836                                                    resourcePermissionModelImpl.getOriginalName(),
837                                                    Integer.valueOf(resourcePermissionModelImpl.getOriginalScope()),
838                                                    
839                                                    resourcePermissionModelImpl.getOriginalPrimKey(),
840                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalRoleId()),
841                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalOwnerId()),
842                                                    Long.valueOf(resourcePermissionModelImpl.getOriginalActionIds())
843                                            };
844    
845                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A,
846                                            args);
847                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
848                                            args);
849    
850                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
851                                            new Object[] {
852                                                    Long.valueOf(resourcePermission.getCompanyId()),
853                                                    
854                                            resourcePermission.getName(),
855                                                    Integer.valueOf(resourcePermission.getScope()),
856                                                    
857                                            resourcePermission.getPrimKey(),
858                                                    Long.valueOf(resourcePermission.getRoleId()),
859                                                    Long.valueOf(resourcePermission.getOwnerId()),
860                                                    Long.valueOf(resourcePermission.getActionIds())
861                                            }, resourcePermission);
862                            }
863                    }
864    
865                    return resourcePermission;
866            }
867    
868            protected ResourcePermission toUnwrappedModel(
869                    ResourcePermission resourcePermission) {
870                    if (resourcePermission instanceof ResourcePermissionImpl) {
871                            return resourcePermission;
872                    }
873    
874                    ResourcePermissionImpl resourcePermissionImpl = new ResourcePermissionImpl();
875    
876                    resourcePermissionImpl.setNew(resourcePermission.isNew());
877                    resourcePermissionImpl.setPrimaryKey(resourcePermission.getPrimaryKey());
878    
879                    resourcePermissionImpl.setResourcePermissionId(resourcePermission.getResourcePermissionId());
880                    resourcePermissionImpl.setCompanyId(resourcePermission.getCompanyId());
881                    resourcePermissionImpl.setName(resourcePermission.getName());
882                    resourcePermissionImpl.setScope(resourcePermission.getScope());
883                    resourcePermissionImpl.setPrimKey(resourcePermission.getPrimKey());
884                    resourcePermissionImpl.setRoleId(resourcePermission.getRoleId());
885                    resourcePermissionImpl.setOwnerId(resourcePermission.getOwnerId());
886                    resourcePermissionImpl.setActionIds(resourcePermission.getActionIds());
887    
888                    return resourcePermissionImpl;
889            }
890    
891            /**
892             * Returns the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
893             *
894             * @param primaryKey the primary key of the resource permission
895             * @return the resource permission
896             * @throws com.liferay.portal.NoSuchModelException if a resource permission with the primary key could not be found
897             * @throws SystemException if a system exception occurred
898             */
899            @Override
900            public ResourcePermission findByPrimaryKey(Serializable primaryKey)
901                    throws NoSuchModelException, SystemException {
902                    return findByPrimaryKey(((Long)primaryKey).longValue());
903            }
904    
905            /**
906             * Returns the resource permission with the primary key or throws a {@link com.liferay.portal.NoSuchResourcePermissionException} if it could not be found.
907             *
908             * @param resourcePermissionId the primary key of the resource permission
909             * @return the resource permission
910             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
911             * @throws SystemException if a system exception occurred
912             */
913            public ResourcePermission findByPrimaryKey(long resourcePermissionId)
914                    throws NoSuchResourcePermissionException, SystemException {
915                    ResourcePermission resourcePermission = fetchByPrimaryKey(resourcePermissionId);
916    
917                    if (resourcePermission == null) {
918                            if (_log.isWarnEnabled()) {
919                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
920                                            resourcePermissionId);
921                            }
922    
923                            throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
924                                    resourcePermissionId);
925                    }
926    
927                    return resourcePermission;
928            }
929    
930            /**
931             * Returns the resource permission with the primary key or returns <code>null</code> if it could not be found.
932             *
933             * @param primaryKey the primary key of the resource permission
934             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
935             * @throws SystemException if a system exception occurred
936             */
937            @Override
938            public ResourcePermission fetchByPrimaryKey(Serializable primaryKey)
939                    throws SystemException {
940                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
941            }
942    
943            /**
944             * Returns the resource permission with the primary key or returns <code>null</code> if it could not be found.
945             *
946             * @param resourcePermissionId the primary key of the resource permission
947             * @return the resource permission, or <code>null</code> if a resource permission with the primary key could not be found
948             * @throws SystemException if a system exception occurred
949             */
950            public ResourcePermission fetchByPrimaryKey(long resourcePermissionId)
951                    throws SystemException {
952                    ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
953                                    ResourcePermissionImpl.class, resourcePermissionId);
954    
955                    if (resourcePermission == _nullResourcePermission) {
956                            return null;
957                    }
958    
959                    if (resourcePermission == null) {
960                            Session session = null;
961    
962                            boolean hasException = false;
963    
964                            try {
965                                    session = openSession();
966    
967                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
968                                                    Long.valueOf(resourcePermissionId));
969                            }
970                            catch (Exception e) {
971                                    hasException = true;
972    
973                                    throw processException(e);
974                            }
975                            finally {
976                                    if (resourcePermission != null) {
977                                            cacheResult(resourcePermission);
978                                    }
979                                    else if (!hasException) {
980                                            EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
981                                                    ResourcePermissionImpl.class, resourcePermissionId,
982                                                    _nullResourcePermission);
983                                    }
984    
985                                    closeSession(session);
986                            }
987                    }
988    
989                    return resourcePermission;
990            }
991    
992            /**
993             * Returns all the resource permissions where scope = &#63;.
994             *
995             * @param scope the scope
996             * @return the matching resource permissions
997             * @throws SystemException if a system exception occurred
998             */
999            public List<ResourcePermission> findByScope(int scope)
1000                    throws SystemException {
1001                    return findByScope(scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1002            }
1003    
1004            /**
1005             * Returns a range of all the resource permissions where scope = &#63;.
1006             *
1007             * <p>
1008             * 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.
1009             * </p>
1010             *
1011             * @param scope the scope
1012             * @param start the lower bound of the range of resource permissions
1013             * @param end the upper bound of the range of resource permissions (not inclusive)
1014             * @return the range of matching resource permissions
1015             * @throws SystemException if a system exception occurred
1016             */
1017            public List<ResourcePermission> findByScope(int scope, int start, int end)
1018                    throws SystemException {
1019                    return findByScope(scope, start, end, null);
1020            }
1021    
1022            /**
1023             * Returns an ordered range of all the resource permissions where scope = &#63;.
1024             *
1025             * <p>
1026             * 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.
1027             * </p>
1028             *
1029             * @param scope the scope
1030             * @param start the lower bound of the range of resource permissions
1031             * @param end the upper bound of the range of resource permissions (not inclusive)
1032             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1033             * @return the ordered range of matching resource permissions
1034             * @throws SystemException if a system exception occurred
1035             */
1036            public List<ResourcePermission> findByScope(int scope, int start, int end,
1037                    OrderByComparator orderByComparator) throws SystemException {
1038                    FinderPath finderPath = null;
1039                    Object[] finderArgs = null;
1040    
1041                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1042                                    (orderByComparator == null)) {
1043                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE;
1044                            finderArgs = new Object[] { scope };
1045                    }
1046                    else {
1047                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE;
1048                            finderArgs = new Object[] { scope, start, end, orderByComparator };
1049                    }
1050    
1051                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1052                                    finderArgs, this);
1053    
1054                    if (list == null) {
1055                            StringBundler query = null;
1056    
1057                            if (orderByComparator != null) {
1058                                    query = new StringBundler(3 +
1059                                                    (orderByComparator.getOrderByFields().length * 3));
1060                            }
1061                            else {
1062                                    query = new StringBundler(2);
1063                            }
1064    
1065                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1066    
1067                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
1068    
1069                            if (orderByComparator != null) {
1070                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1071                                            orderByComparator);
1072                            }
1073    
1074                            String sql = query.toString();
1075    
1076                            Session session = null;
1077    
1078                            try {
1079                                    session = openSession();
1080    
1081                                    Query q = session.createQuery(sql);
1082    
1083                                    QueryPos qPos = QueryPos.getInstance(q);
1084    
1085                                    qPos.add(scope);
1086    
1087                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1088                                                    getDialect(), start, end);
1089                            }
1090                            catch (Exception e) {
1091                                    throw processException(e);
1092                            }
1093                            finally {
1094                                    if (list == null) {
1095                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1096                                    }
1097                                    else {
1098                                            cacheResult(list);
1099    
1100                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1101                                    }
1102    
1103                                    closeSession(session);
1104                            }
1105                    }
1106    
1107                    return list;
1108            }
1109    
1110            /**
1111             * Returns the first resource permission in the ordered set where scope = &#63;.
1112             *
1113             * <p>
1114             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1115             * </p>
1116             *
1117             * @param scope the scope
1118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1119             * @return the first matching resource permission
1120             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1121             * @throws SystemException if a system exception occurred
1122             */
1123            public ResourcePermission findByScope_First(int scope,
1124                    OrderByComparator orderByComparator)
1125                    throws NoSuchResourcePermissionException, SystemException {
1126                    List<ResourcePermission> list = findByScope(scope, 0, 1,
1127                                    orderByComparator);
1128    
1129                    if (list.isEmpty()) {
1130                            StringBundler msg = new StringBundler(4);
1131    
1132                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1133    
1134                            msg.append("scope=");
1135                            msg.append(scope);
1136    
1137                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1138    
1139                            throw new NoSuchResourcePermissionException(msg.toString());
1140                    }
1141                    else {
1142                            return list.get(0);
1143                    }
1144            }
1145    
1146            /**
1147             * Returns the last resource permission in the ordered set where scope = &#63;.
1148             *
1149             * <p>
1150             * 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.
1151             * </p>
1152             *
1153             * @param scope the scope
1154             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1155             * @return the last matching resource permission
1156             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1157             * @throws SystemException if a system exception occurred
1158             */
1159            public ResourcePermission findByScope_Last(int scope,
1160                    OrderByComparator orderByComparator)
1161                    throws NoSuchResourcePermissionException, SystemException {
1162                    int count = countByScope(scope);
1163    
1164                    List<ResourcePermission> list = findByScope(scope, count - 1, count,
1165                                    orderByComparator);
1166    
1167                    if (list.isEmpty()) {
1168                            StringBundler msg = new StringBundler(4);
1169    
1170                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1171    
1172                            msg.append("scope=");
1173                            msg.append(scope);
1174    
1175                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1176    
1177                            throw new NoSuchResourcePermissionException(msg.toString());
1178                    }
1179                    else {
1180                            return list.get(0);
1181                    }
1182            }
1183    
1184            /**
1185             * Returns the resource permissions before and after the current resource permission in the ordered set where scope = &#63;.
1186             *
1187             * <p>
1188             * 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.
1189             * </p>
1190             *
1191             * @param resourcePermissionId the primary key of the current resource permission
1192             * @param scope the scope
1193             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1194             * @return the previous, current, and next resource permission
1195             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1196             * @throws SystemException if a system exception occurred
1197             */
1198            public ResourcePermission[] findByScope_PrevAndNext(
1199                    long resourcePermissionId, int scope,
1200                    OrderByComparator orderByComparator)
1201                    throws NoSuchResourcePermissionException, SystemException {
1202                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1203    
1204                    Session session = null;
1205    
1206                    try {
1207                            session = openSession();
1208    
1209                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1210    
1211                            array[0] = getByScope_PrevAndNext(session, resourcePermission,
1212                                            scope, orderByComparator, true);
1213    
1214                            array[1] = resourcePermission;
1215    
1216                            array[2] = getByScope_PrevAndNext(session, resourcePermission,
1217                                            scope, orderByComparator, false);
1218    
1219                            return array;
1220                    }
1221                    catch (Exception e) {
1222                            throw processException(e);
1223                    }
1224                    finally {
1225                            closeSession(session);
1226                    }
1227            }
1228    
1229            protected ResourcePermission getByScope_PrevAndNext(Session session,
1230                    ResourcePermission resourcePermission, int scope,
1231                    OrderByComparator orderByComparator, boolean previous) {
1232                    StringBundler query = null;
1233    
1234                    if (orderByComparator != null) {
1235                            query = new StringBundler(6 +
1236                                            (orderByComparator.getOrderByFields().length * 6));
1237                    }
1238                    else {
1239                            query = new StringBundler(3);
1240                    }
1241    
1242                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1243    
1244                    query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
1245    
1246                    if (orderByComparator != null) {
1247                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1248    
1249                            if (orderByConditionFields.length > 0) {
1250                                    query.append(WHERE_AND);
1251                            }
1252    
1253                            for (int i = 0; i < orderByConditionFields.length; i++) {
1254                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1255                                    query.append(orderByConditionFields[i]);
1256    
1257                                    if ((i + 1) < orderByConditionFields.length) {
1258                                            if (orderByComparator.isAscending() ^ previous) {
1259                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1260                                            }
1261                                            else {
1262                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1263                                            }
1264                                    }
1265                                    else {
1266                                            if (orderByComparator.isAscending() ^ previous) {
1267                                                    query.append(WHERE_GREATER_THAN);
1268                                            }
1269                                            else {
1270                                                    query.append(WHERE_LESSER_THAN);
1271                                            }
1272                                    }
1273                            }
1274    
1275                            query.append(ORDER_BY_CLAUSE);
1276    
1277                            String[] orderByFields = orderByComparator.getOrderByFields();
1278    
1279                            for (int i = 0; i < orderByFields.length; i++) {
1280                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1281                                    query.append(orderByFields[i]);
1282    
1283                                    if ((i + 1) < orderByFields.length) {
1284                                            if (orderByComparator.isAscending() ^ previous) {
1285                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1286                                            }
1287                                            else {
1288                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1289                                            }
1290                                    }
1291                                    else {
1292                                            if (orderByComparator.isAscending() ^ previous) {
1293                                                    query.append(ORDER_BY_ASC);
1294                                            }
1295                                            else {
1296                                                    query.append(ORDER_BY_DESC);
1297                                            }
1298                                    }
1299                            }
1300                    }
1301    
1302                    String sql = query.toString();
1303    
1304                    Query q = session.createQuery(sql);
1305    
1306                    q.setFirstResult(0);
1307                    q.setMaxResults(2);
1308    
1309                    QueryPos qPos = QueryPos.getInstance(q);
1310    
1311                    qPos.add(scope);
1312    
1313                    if (orderByComparator != null) {
1314                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
1315    
1316                            for (Object value : values) {
1317                                    qPos.add(value);
1318                            }
1319                    }
1320    
1321                    List<ResourcePermission> list = q.list();
1322    
1323                    if (list.size() == 2) {
1324                            return list.get(1);
1325                    }
1326                    else {
1327                            return null;
1328                    }
1329            }
1330    
1331            /**
1332             * Returns all the resource permissions where scope = any &#63;.
1333             *
1334             * <p>
1335             * 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.
1336             * </p>
1337             *
1338             * @param scopes the scopes
1339             * @return the matching resource permissions
1340             * @throws SystemException if a system exception occurred
1341             */
1342            public List<ResourcePermission> findByScope(int[] scopes)
1343                    throws SystemException {
1344                    return findByScope(scopes, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1345            }
1346    
1347            /**
1348             * Returns a range of all the resource permissions where scope = any &#63;.
1349             *
1350             * <p>
1351             * 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.
1352             * </p>
1353             *
1354             * @param scopes the scopes
1355             * @param start the lower bound of the range of resource permissions
1356             * @param end the upper bound of the range of resource permissions (not inclusive)
1357             * @return the range of matching resource permissions
1358             * @throws SystemException if a system exception occurred
1359             */
1360            public List<ResourcePermission> findByScope(int[] scopes, int start, int end)
1361                    throws SystemException {
1362                    return findByScope(scopes, start, end, null);
1363            }
1364    
1365            /**
1366             * Returns an ordered range of all the resource permissions where scope = any &#63;.
1367             *
1368             * <p>
1369             * 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.
1370             * </p>
1371             *
1372             * @param scopes the scopes
1373             * @param start the lower bound of the range of resource permissions
1374             * @param end the upper bound of the range of resource permissions (not inclusive)
1375             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1376             * @return the ordered range of matching resource permissions
1377             * @throws SystemException if a system exception occurred
1378             */
1379            public List<ResourcePermission> findByScope(int[] scopes, int start,
1380                    int end, OrderByComparator orderByComparator) throws SystemException {
1381                    FinderPath finderPath = null;
1382                    Object[] finderArgs = null;
1383    
1384                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1385                                    (orderByComparator == null)) {
1386                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SCOPE;
1387                            finderArgs = new Object[] { StringUtil.merge(scopes) };
1388                    }
1389                    else {
1390                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SCOPE;
1391                            finderArgs = new Object[] {
1392                                            StringUtil.merge(scopes),
1393                                            
1394                                            start, end, orderByComparator
1395                                    };
1396                    }
1397    
1398                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1399                                    finderArgs, this);
1400    
1401                    if (list == null) {
1402                            StringBundler query = new StringBundler();
1403    
1404                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1405    
1406                            boolean conjunctionable = false;
1407    
1408                            if ((scopes == null) || (scopes.length > 0)) {
1409                                    if (conjunctionable) {
1410                                            query.append(WHERE_AND);
1411                                    }
1412    
1413                                    query.append(StringPool.OPEN_PARENTHESIS);
1414    
1415                                    for (int i = 0; i < scopes.length; i++) {
1416                                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_5);
1417    
1418                                            if ((i + 1) < scopes.length) {
1419                                                    query.append(WHERE_OR);
1420                                            }
1421                                    }
1422    
1423                                    query.append(StringPool.CLOSE_PARENTHESIS);
1424    
1425                                    conjunctionable = true;
1426                            }
1427    
1428                            if (orderByComparator != null) {
1429                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1430                                            orderByComparator);
1431                            }
1432    
1433                            String sql = query.toString();
1434    
1435                            Session session = null;
1436    
1437                            try {
1438                                    session = openSession();
1439    
1440                                    Query q = session.createQuery(sql);
1441    
1442                                    QueryPos qPos = QueryPos.getInstance(q);
1443    
1444                                    if (scopes != null) {
1445                                            qPos.add(scopes);
1446                                    }
1447    
1448                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1449                                                    getDialect(), start, end);
1450                            }
1451                            catch (Exception e) {
1452                                    throw processException(e);
1453                            }
1454                            finally {
1455                                    if (list == null) {
1456                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1457                                    }
1458                                    else {
1459                                            cacheResult(list);
1460    
1461                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1462                                    }
1463    
1464                                    closeSession(session);
1465                            }
1466                    }
1467    
1468                    return list;
1469            }
1470    
1471            /**
1472             * Returns all the resource permissions where roleId = &#63;.
1473             *
1474             * @param roleId the role ID
1475             * @return the matching resource permissions
1476             * @throws SystemException if a system exception occurred
1477             */
1478            public List<ResourcePermission> findByRoleId(long roleId)
1479                    throws SystemException {
1480                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1481            }
1482    
1483            /**
1484             * Returns a range of all the resource permissions where roleId = &#63;.
1485             *
1486             * <p>
1487             * 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.
1488             * </p>
1489             *
1490             * @param roleId the role ID
1491             * @param start the lower bound of the range of resource permissions
1492             * @param end the upper bound of the range of resource permissions (not inclusive)
1493             * @return the range of matching resource permissions
1494             * @throws SystemException if a system exception occurred
1495             */
1496            public List<ResourcePermission> findByRoleId(long roleId, int start, int end)
1497                    throws SystemException {
1498                    return findByRoleId(roleId, start, end, null);
1499            }
1500    
1501            /**
1502             * Returns an ordered range of all the resource permissions where roleId = &#63;.
1503             *
1504             * <p>
1505             * 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.
1506             * </p>
1507             *
1508             * @param roleId the role ID
1509             * @param start the lower bound of the range of resource permissions
1510             * @param end the upper bound of the range of resource permissions (not inclusive)
1511             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1512             * @return the ordered range of matching resource permissions
1513             * @throws SystemException if a system exception occurred
1514             */
1515            public List<ResourcePermission> findByRoleId(long roleId, int start,
1516                    int end, OrderByComparator orderByComparator) throws SystemException {
1517                    FinderPath finderPath = null;
1518                    Object[] finderArgs = null;
1519    
1520                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1521                                    (orderByComparator == null)) {
1522                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
1523                            finderArgs = new Object[] { roleId };
1524                    }
1525                    else {
1526                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
1527                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
1528                    }
1529    
1530                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1531                                    finderArgs, this);
1532    
1533                    if (list == null) {
1534                            StringBundler query = null;
1535    
1536                            if (orderByComparator != null) {
1537                                    query = new StringBundler(3 +
1538                                                    (orderByComparator.getOrderByFields().length * 3));
1539                            }
1540                            else {
1541                                    query = new StringBundler(2);
1542                            }
1543    
1544                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1545    
1546                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1547    
1548                            if (orderByComparator != null) {
1549                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1550                                            orderByComparator);
1551                            }
1552    
1553                            String sql = query.toString();
1554    
1555                            Session session = null;
1556    
1557                            try {
1558                                    session = openSession();
1559    
1560                                    Query q = session.createQuery(sql);
1561    
1562                                    QueryPos qPos = QueryPos.getInstance(q);
1563    
1564                                    qPos.add(roleId);
1565    
1566                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1567                                                    getDialect(), start, end);
1568                            }
1569                            catch (Exception e) {
1570                                    throw processException(e);
1571                            }
1572                            finally {
1573                                    if (list == null) {
1574                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1575                                    }
1576                                    else {
1577                                            cacheResult(list);
1578    
1579                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1580                                    }
1581    
1582                                    closeSession(session);
1583                            }
1584                    }
1585    
1586                    return list;
1587            }
1588    
1589            /**
1590             * Returns the first resource permission in the ordered set where roleId = &#63;.
1591             *
1592             * <p>
1593             * 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.
1594             * </p>
1595             *
1596             * @param roleId the role ID
1597             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1598             * @return the first matching resource permission
1599             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1600             * @throws SystemException if a system exception occurred
1601             */
1602            public ResourcePermission findByRoleId_First(long roleId,
1603                    OrderByComparator orderByComparator)
1604                    throws NoSuchResourcePermissionException, SystemException {
1605                    List<ResourcePermission> list = findByRoleId(roleId, 0, 1,
1606                                    orderByComparator);
1607    
1608                    if (list.isEmpty()) {
1609                            StringBundler msg = new StringBundler(4);
1610    
1611                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1612    
1613                            msg.append("roleId=");
1614                            msg.append(roleId);
1615    
1616                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1617    
1618                            throw new NoSuchResourcePermissionException(msg.toString());
1619                    }
1620                    else {
1621                            return list.get(0);
1622                    }
1623            }
1624    
1625            /**
1626             * Returns the last resource permission in the ordered set where roleId = &#63;.
1627             *
1628             * <p>
1629             * 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.
1630             * </p>
1631             *
1632             * @param roleId the role ID
1633             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1634             * @return the last matching resource permission
1635             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1636             * @throws SystemException if a system exception occurred
1637             */
1638            public ResourcePermission findByRoleId_Last(long roleId,
1639                    OrderByComparator orderByComparator)
1640                    throws NoSuchResourcePermissionException, SystemException {
1641                    int count = countByRoleId(roleId);
1642    
1643                    List<ResourcePermission> list = findByRoleId(roleId, count - 1, count,
1644                                    orderByComparator);
1645    
1646                    if (list.isEmpty()) {
1647                            StringBundler msg = new StringBundler(4);
1648    
1649                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1650    
1651                            msg.append("roleId=");
1652                            msg.append(roleId);
1653    
1654                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1655    
1656                            throw new NoSuchResourcePermissionException(msg.toString());
1657                    }
1658                    else {
1659                            return list.get(0);
1660                    }
1661            }
1662    
1663            /**
1664             * Returns the resource permissions before and after the current resource permission in the ordered set where roleId = &#63;.
1665             *
1666             * <p>
1667             * 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.
1668             * </p>
1669             *
1670             * @param resourcePermissionId the primary key of the current resource permission
1671             * @param roleId the role ID
1672             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1673             * @return the previous, current, and next resource permission
1674             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
1675             * @throws SystemException if a system exception occurred
1676             */
1677            public ResourcePermission[] findByRoleId_PrevAndNext(
1678                    long resourcePermissionId, long roleId,
1679                    OrderByComparator orderByComparator)
1680                    throws NoSuchResourcePermissionException, SystemException {
1681                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1682    
1683                    Session session = null;
1684    
1685                    try {
1686                            session = openSession();
1687    
1688                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1689    
1690                            array[0] = getByRoleId_PrevAndNext(session, resourcePermission,
1691                                            roleId, orderByComparator, true);
1692    
1693                            array[1] = resourcePermission;
1694    
1695                            array[2] = getByRoleId_PrevAndNext(session, resourcePermission,
1696                                            roleId, orderByComparator, false);
1697    
1698                            return array;
1699                    }
1700                    catch (Exception e) {
1701                            throw processException(e);
1702                    }
1703                    finally {
1704                            closeSession(session);
1705                    }
1706            }
1707    
1708            protected ResourcePermission getByRoleId_PrevAndNext(Session session,
1709                    ResourcePermission resourcePermission, long roleId,
1710                    OrderByComparator orderByComparator, boolean previous) {
1711                    StringBundler query = null;
1712    
1713                    if (orderByComparator != null) {
1714                            query = new StringBundler(6 +
1715                                            (orderByComparator.getOrderByFields().length * 6));
1716                    }
1717                    else {
1718                            query = new StringBundler(3);
1719                    }
1720    
1721                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1722    
1723                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1724    
1725                    if (orderByComparator != null) {
1726                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1727    
1728                            if (orderByConditionFields.length > 0) {
1729                                    query.append(WHERE_AND);
1730                            }
1731    
1732                            for (int i = 0; i < orderByConditionFields.length; i++) {
1733                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1734                                    query.append(orderByConditionFields[i]);
1735    
1736                                    if ((i + 1) < orderByConditionFields.length) {
1737                                            if (orderByComparator.isAscending() ^ previous) {
1738                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1739                                            }
1740                                            else {
1741                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1742                                            }
1743                                    }
1744                                    else {
1745                                            if (orderByComparator.isAscending() ^ previous) {
1746                                                    query.append(WHERE_GREATER_THAN);
1747                                            }
1748                                            else {
1749                                                    query.append(WHERE_LESSER_THAN);
1750                                            }
1751                                    }
1752                            }
1753    
1754                            query.append(ORDER_BY_CLAUSE);
1755    
1756                            String[] orderByFields = orderByComparator.getOrderByFields();
1757    
1758                            for (int i = 0; i < orderByFields.length; i++) {
1759                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1760                                    query.append(orderByFields[i]);
1761    
1762                                    if ((i + 1) < orderByFields.length) {
1763                                            if (orderByComparator.isAscending() ^ previous) {
1764                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1765                                            }
1766                                            else {
1767                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1768                                            }
1769                                    }
1770                                    else {
1771                                            if (orderByComparator.isAscending() ^ previous) {
1772                                                    query.append(ORDER_BY_ASC);
1773                                            }
1774                                            else {
1775                                                    query.append(ORDER_BY_DESC);
1776                                            }
1777                                    }
1778                            }
1779                    }
1780    
1781                    String sql = query.toString();
1782    
1783                    Query q = session.createQuery(sql);
1784    
1785                    q.setFirstResult(0);
1786                    q.setMaxResults(2);
1787    
1788                    QueryPos qPos = QueryPos.getInstance(q);
1789    
1790                    qPos.add(roleId);
1791    
1792                    if (orderByComparator != null) {
1793                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
1794    
1795                            for (Object value : values) {
1796                                    qPos.add(value);
1797                            }
1798                    }
1799    
1800                    List<ResourcePermission> list = q.list();
1801    
1802                    if (list.size() == 2) {
1803                            return list.get(1);
1804                    }
1805                    else {
1806                            return null;
1807                    }
1808            }
1809    
1810            /**
1811             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1812             *
1813             * @param companyId the company ID
1814             * @param name the name
1815             * @param scope the scope
1816             * @return the matching resource permissions
1817             * @throws SystemException if a system exception occurred
1818             */
1819            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1820                    int scope) throws SystemException {
1821                    return findByC_N_S(companyId, name, scope, QueryUtil.ALL_POS,
1822                            QueryUtil.ALL_POS, null);
1823            }
1824    
1825            /**
1826             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1827             *
1828             * <p>
1829             * 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.
1830             * </p>
1831             *
1832             * @param companyId the company ID
1833             * @param name the name
1834             * @param scope the scope
1835             * @param start the lower bound of the range of resource permissions
1836             * @param end the upper bound of the range of resource permissions (not inclusive)
1837             * @return the range of matching resource permissions
1838             * @throws SystemException if a system exception occurred
1839             */
1840            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1841                    int scope, int start, int end) throws SystemException {
1842                    return findByC_N_S(companyId, name, scope, start, end, null);
1843            }
1844    
1845            /**
1846             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
1847             *
1848             * <p>
1849             * 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.
1850             * </p>
1851             *
1852             * @param companyId the company ID
1853             * @param name the name
1854             * @param scope the scope
1855             * @param start the lower bound of the range of resource permissions
1856             * @param end the upper bound of the range of resource permissions (not inclusive)
1857             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1858             * @return the ordered range of matching resource permissions
1859             * @throws SystemException if a system exception occurred
1860             */
1861            public List<ResourcePermission> findByC_N_S(long companyId, String name,
1862                    int scope, int start, int end, OrderByComparator orderByComparator)
1863                    throws SystemException {
1864                    FinderPath finderPath = null;
1865                    Object[] finderArgs = null;
1866    
1867                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1868                                    (orderByComparator == null)) {
1869                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S;
1870                            finderArgs = new Object[] { companyId, name, scope };
1871                    }
1872                    else {
1873                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S;
1874                            finderArgs = new Object[] {
1875                                            companyId, name, scope,
1876                                            
1877                                            start, end, orderByComparator
1878                                    };
1879                    }
1880    
1881                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
1882                                    finderArgs, this);
1883    
1884                    if (list == null) {
1885                            StringBundler query = null;
1886    
1887                            if (orderByComparator != null) {
1888                                    query = new StringBundler(5 +
1889                                                    (orderByComparator.getOrderByFields().length * 3));
1890                            }
1891                            else {
1892                                    query = new StringBundler(4);
1893                            }
1894    
1895                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1896    
1897                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1898    
1899                            if (name == null) {
1900                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1901                            }
1902                            else {
1903                                    if (name.equals(StringPool.BLANK)) {
1904                                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1905                                    }
1906                                    else {
1907                                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1908                                    }
1909                            }
1910    
1911                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1912    
1913                            if (orderByComparator != null) {
1914                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1915                                            orderByComparator);
1916                            }
1917    
1918                            String sql = query.toString();
1919    
1920                            Session session = null;
1921    
1922                            try {
1923                                    session = openSession();
1924    
1925                                    Query q = session.createQuery(sql);
1926    
1927                                    QueryPos qPos = QueryPos.getInstance(q);
1928    
1929                                    qPos.add(companyId);
1930    
1931                                    if (name != null) {
1932                                            qPos.add(name);
1933                                    }
1934    
1935                                    qPos.add(scope);
1936    
1937                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1938                                                    getDialect(), start, end);
1939                            }
1940                            catch (Exception e) {
1941                                    throw processException(e);
1942                            }
1943                            finally {
1944                                    if (list == null) {
1945                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1946                                    }
1947                                    else {
1948                                            cacheResult(list);
1949    
1950                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1951                                    }
1952    
1953                                    closeSession(session);
1954                            }
1955                    }
1956    
1957                    return list;
1958            }
1959    
1960            /**
1961             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
1962             *
1963             * <p>
1964             * 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.
1965             * </p>
1966             *
1967             * @param companyId the company ID
1968             * @param name the name
1969             * @param scope the scope
1970             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1971             * @return the first matching resource permission
1972             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
1973             * @throws SystemException if a system exception occurred
1974             */
1975            public ResourcePermission findByC_N_S_First(long companyId, String name,
1976                    int scope, OrderByComparator orderByComparator)
1977                    throws NoSuchResourcePermissionException, SystemException {
1978                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope, 0,
1979                                    1, orderByComparator);
1980    
1981                    if (list.isEmpty()) {
1982                            StringBundler msg = new StringBundler(8);
1983    
1984                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1985    
1986                            msg.append("companyId=");
1987                            msg.append(companyId);
1988    
1989                            msg.append(", name=");
1990                            msg.append(name);
1991    
1992                            msg.append(", scope=");
1993                            msg.append(scope);
1994    
1995                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1996    
1997                            throw new NoSuchResourcePermissionException(msg.toString());
1998                    }
1999                    else {
2000                            return list.get(0);
2001                    }
2002            }
2003    
2004            /**
2005             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2006             *
2007             * <p>
2008             * 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.
2009             * </p>
2010             *
2011             * @param companyId the company ID
2012             * @param name the name
2013             * @param scope the scope
2014             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2015             * @return the last matching resource permission
2016             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2017             * @throws SystemException if a system exception occurred
2018             */
2019            public ResourcePermission findByC_N_S_Last(long companyId, String name,
2020                    int scope, OrderByComparator orderByComparator)
2021                    throws NoSuchResourcePermissionException, SystemException {
2022                    int count = countByC_N_S(companyId, name, scope);
2023    
2024                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope,
2025                                    count - 1, count, orderByComparator);
2026    
2027                    if (list.isEmpty()) {
2028                            StringBundler msg = new StringBundler(8);
2029    
2030                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2031    
2032                            msg.append("companyId=");
2033                            msg.append(companyId);
2034    
2035                            msg.append(", name=");
2036                            msg.append(name);
2037    
2038                            msg.append(", scope=");
2039                            msg.append(scope);
2040    
2041                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2042    
2043                            throw new NoSuchResourcePermissionException(msg.toString());
2044                    }
2045                    else {
2046                            return list.get(0);
2047                    }
2048            }
2049    
2050            /**
2051             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63;.
2052             *
2053             * <p>
2054             * 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.
2055             * </p>
2056             *
2057             * @param resourcePermissionId the primary key of the current resource permission
2058             * @param companyId the company ID
2059             * @param name the name
2060             * @param scope the scope
2061             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2062             * @return the previous, current, and next resource permission
2063             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2064             * @throws SystemException if a system exception occurred
2065             */
2066            public ResourcePermission[] findByC_N_S_PrevAndNext(
2067                    long resourcePermissionId, long companyId, String name, int scope,
2068                    OrderByComparator orderByComparator)
2069                    throws NoSuchResourcePermissionException, SystemException {
2070                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2071    
2072                    Session session = null;
2073    
2074                    try {
2075                            session = openSession();
2076    
2077                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2078    
2079                            array[0] = getByC_N_S_PrevAndNext(session, resourcePermission,
2080                                            companyId, name, scope, orderByComparator, true);
2081    
2082                            array[1] = resourcePermission;
2083    
2084                            array[2] = getByC_N_S_PrevAndNext(session, resourcePermission,
2085                                            companyId, name, scope, orderByComparator, false);
2086    
2087                            return array;
2088                    }
2089                    catch (Exception e) {
2090                            throw processException(e);
2091                    }
2092                    finally {
2093                            closeSession(session);
2094                    }
2095            }
2096    
2097            protected ResourcePermission getByC_N_S_PrevAndNext(Session session,
2098                    ResourcePermission resourcePermission, long companyId, String name,
2099                    int scope, OrderByComparator orderByComparator, boolean previous) {
2100                    StringBundler query = null;
2101    
2102                    if (orderByComparator != null) {
2103                            query = new StringBundler(6 +
2104                                            (orderByComparator.getOrderByFields().length * 6));
2105                    }
2106                    else {
2107                            query = new StringBundler(3);
2108                    }
2109    
2110                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2111    
2112                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2113    
2114                    if (name == null) {
2115                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2116                    }
2117                    else {
2118                            if (name.equals(StringPool.BLANK)) {
2119                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2120                            }
2121                            else {
2122                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2123                            }
2124                    }
2125    
2126                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2127    
2128                    if (orderByComparator != null) {
2129                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2130    
2131                            if (orderByConditionFields.length > 0) {
2132                                    query.append(WHERE_AND);
2133                            }
2134    
2135                            for (int i = 0; i < orderByConditionFields.length; i++) {
2136                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2137                                    query.append(orderByConditionFields[i]);
2138    
2139                                    if ((i + 1) < orderByConditionFields.length) {
2140                                            if (orderByComparator.isAscending() ^ previous) {
2141                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2142                                            }
2143                                            else {
2144                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2145                                            }
2146                                    }
2147                                    else {
2148                                            if (orderByComparator.isAscending() ^ previous) {
2149                                                    query.append(WHERE_GREATER_THAN);
2150                                            }
2151                                            else {
2152                                                    query.append(WHERE_LESSER_THAN);
2153                                            }
2154                                    }
2155                            }
2156    
2157                            query.append(ORDER_BY_CLAUSE);
2158    
2159                            String[] orderByFields = orderByComparator.getOrderByFields();
2160    
2161                            for (int i = 0; i < orderByFields.length; i++) {
2162                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2163                                    query.append(orderByFields[i]);
2164    
2165                                    if ((i + 1) < orderByFields.length) {
2166                                            if (orderByComparator.isAscending() ^ previous) {
2167                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2168                                            }
2169                                            else {
2170                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2171                                            }
2172                                    }
2173                                    else {
2174                                            if (orderByComparator.isAscending() ^ previous) {
2175                                                    query.append(ORDER_BY_ASC);
2176                                            }
2177                                            else {
2178                                                    query.append(ORDER_BY_DESC);
2179                                            }
2180                                    }
2181                            }
2182                    }
2183    
2184                    String sql = query.toString();
2185    
2186                    Query q = session.createQuery(sql);
2187    
2188                    q.setFirstResult(0);
2189                    q.setMaxResults(2);
2190    
2191                    QueryPos qPos = QueryPos.getInstance(q);
2192    
2193                    qPos.add(companyId);
2194    
2195                    if (name != null) {
2196                            qPos.add(name);
2197                    }
2198    
2199                    qPos.add(scope);
2200    
2201                    if (orderByComparator != null) {
2202                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
2203    
2204                            for (Object value : values) {
2205                                    qPos.add(value);
2206                            }
2207                    }
2208    
2209                    List<ResourcePermission> list = q.list();
2210    
2211                    if (list.size() == 2) {
2212                            return list.get(1);
2213                    }
2214                    else {
2215                            return null;
2216                    }
2217            }
2218    
2219            /**
2220             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2221             *
2222             * @param companyId the company ID
2223             * @param name the name
2224             * @param scope the scope
2225             * @param primKey the prim key
2226             * @return the matching resource permissions
2227             * @throws SystemException if a system exception occurred
2228             */
2229            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
2230                    int scope, String primKey) throws SystemException {
2231                    return findByC_N_S_P(companyId, name, scope, primKey,
2232                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2233            }
2234    
2235            /**
2236             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2237             *
2238             * <p>
2239             * 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.
2240             * </p>
2241             *
2242             * @param companyId the company ID
2243             * @param name the name
2244             * @param scope the scope
2245             * @param primKey the prim key
2246             * @param start the lower bound of the range of resource permissions
2247             * @param end the upper bound of the range of resource permissions (not inclusive)
2248             * @return the range of matching resource permissions
2249             * @throws SystemException if a system exception occurred
2250             */
2251            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
2252                    int scope, String primKey, int start, int end)
2253                    throws SystemException {
2254                    return findByC_N_S_P(companyId, name, scope, primKey, start, end, null);
2255            }
2256    
2257            /**
2258             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2259             *
2260             * <p>
2261             * 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.
2262             * </p>
2263             *
2264             * @param companyId the company ID
2265             * @param name the name
2266             * @param scope the scope
2267             * @param primKey the prim key
2268             * @param start the lower bound of the range of resource permissions
2269             * @param end the upper bound of the range of resource permissions (not inclusive)
2270             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2271             * @return the ordered range of matching resource permissions
2272             * @throws SystemException if a system exception occurred
2273             */
2274            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
2275                    int scope, String primKey, int start, int end,
2276                    OrderByComparator orderByComparator) throws SystemException {
2277                    FinderPath finderPath = null;
2278                    Object[] finderArgs = null;
2279    
2280                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2281                                    (orderByComparator == null)) {
2282                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P;
2283                            finderArgs = new Object[] { companyId, name, scope, primKey };
2284                    }
2285                    else {
2286                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P;
2287                            finderArgs = new Object[] {
2288                                            companyId, name, scope, primKey,
2289                                            
2290                                            start, end, orderByComparator
2291                                    };
2292                    }
2293    
2294                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
2295                                    finderArgs, this);
2296    
2297                    if (list == null) {
2298                            StringBundler query = null;
2299    
2300                            if (orderByComparator != null) {
2301                                    query = new StringBundler(6 +
2302                                                    (orderByComparator.getOrderByFields().length * 3));
2303                            }
2304                            else {
2305                                    query = new StringBundler(5);
2306                            }
2307    
2308                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2309    
2310                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
2311    
2312                            if (name == null) {
2313                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
2314                            }
2315                            else {
2316                                    if (name.equals(StringPool.BLANK)) {
2317                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
2318                                    }
2319                                    else {
2320                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
2321                                    }
2322                            }
2323    
2324                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
2325    
2326                            if (primKey == null) {
2327                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
2328                            }
2329                            else {
2330                                    if (primKey.equals(StringPool.BLANK)) {
2331                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
2332                                    }
2333                                    else {
2334                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
2335                                    }
2336                            }
2337    
2338                            if (orderByComparator != null) {
2339                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2340                                            orderByComparator);
2341                            }
2342    
2343                            String sql = query.toString();
2344    
2345                            Session session = null;
2346    
2347                            try {
2348                                    session = openSession();
2349    
2350                                    Query q = session.createQuery(sql);
2351    
2352                                    QueryPos qPos = QueryPos.getInstance(q);
2353    
2354                                    qPos.add(companyId);
2355    
2356                                    if (name != null) {
2357                                            qPos.add(name);
2358                                    }
2359    
2360                                    qPos.add(scope);
2361    
2362                                    if (primKey != null) {
2363                                            qPos.add(primKey);
2364                                    }
2365    
2366                                    list = (List<ResourcePermission>)QueryUtil.list(q,
2367                                                    getDialect(), start, end);
2368                            }
2369                            catch (Exception e) {
2370                                    throw processException(e);
2371                            }
2372                            finally {
2373                                    if (list == null) {
2374                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2375                                    }
2376                                    else {
2377                                            cacheResult(list);
2378    
2379                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2380                                    }
2381    
2382                                    closeSession(session);
2383                            }
2384                    }
2385    
2386                    return list;
2387            }
2388    
2389            /**
2390             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2391             *
2392             * <p>
2393             * 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.
2394             * </p>
2395             *
2396             * @param companyId the company ID
2397             * @param name the name
2398             * @param scope the scope
2399             * @param primKey the prim key
2400             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2401             * @return the first matching resource permission
2402             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2403             * @throws SystemException if a system exception occurred
2404             */
2405            public ResourcePermission findByC_N_S_P_First(long companyId, String name,
2406                    int scope, String primKey, OrderByComparator orderByComparator)
2407                    throws NoSuchResourcePermissionException, SystemException {
2408                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
2409                                    primKey, 0, 1, orderByComparator);
2410    
2411                    if (list.isEmpty()) {
2412                            StringBundler msg = new StringBundler(10);
2413    
2414                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2415    
2416                            msg.append("companyId=");
2417                            msg.append(companyId);
2418    
2419                            msg.append(", name=");
2420                            msg.append(name);
2421    
2422                            msg.append(", scope=");
2423                            msg.append(scope);
2424    
2425                            msg.append(", primKey=");
2426                            msg.append(primKey);
2427    
2428                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2429    
2430                            throw new NoSuchResourcePermissionException(msg.toString());
2431                    }
2432                    else {
2433                            return list.get(0);
2434                    }
2435            }
2436    
2437            /**
2438             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2439             *
2440             * <p>
2441             * 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.
2442             * </p>
2443             *
2444             * @param companyId the company ID
2445             * @param name the name
2446             * @param scope the scope
2447             * @param primKey the prim key
2448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2449             * @return the last matching resource permission
2450             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2451             * @throws SystemException if a system exception occurred
2452             */
2453            public ResourcePermission findByC_N_S_P_Last(long companyId, String name,
2454                    int scope, String primKey, OrderByComparator orderByComparator)
2455                    throws NoSuchResourcePermissionException, SystemException {
2456                    int count = countByC_N_S_P(companyId, name, scope, primKey);
2457    
2458                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
2459                                    primKey, count - 1, count, orderByComparator);
2460    
2461                    if (list.isEmpty()) {
2462                            StringBundler msg = new StringBundler(10);
2463    
2464                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2465    
2466                            msg.append("companyId=");
2467                            msg.append(companyId);
2468    
2469                            msg.append(", name=");
2470                            msg.append(name);
2471    
2472                            msg.append(", scope=");
2473                            msg.append(scope);
2474    
2475                            msg.append(", primKey=");
2476                            msg.append(primKey);
2477    
2478                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2479    
2480                            throw new NoSuchResourcePermissionException(msg.toString());
2481                    }
2482                    else {
2483                            return list.get(0);
2484                    }
2485            }
2486    
2487            /**
2488             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
2489             *
2490             * <p>
2491             * 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.
2492             * </p>
2493             *
2494             * @param resourcePermissionId the primary key of the current resource permission
2495             * @param companyId the company ID
2496             * @param name the name
2497             * @param scope the scope
2498             * @param primKey the prim key
2499             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2500             * @return the previous, current, and next resource permission
2501             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2502             * @throws SystemException if a system exception occurred
2503             */
2504            public ResourcePermission[] findByC_N_S_P_PrevAndNext(
2505                    long resourcePermissionId, long companyId, String name, int scope,
2506                    String primKey, OrderByComparator orderByComparator)
2507                    throws NoSuchResourcePermissionException, SystemException {
2508                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2509    
2510                    Session session = null;
2511    
2512                    try {
2513                            session = openSession();
2514    
2515                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2516    
2517                            array[0] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
2518                                            companyId, name, scope, primKey, orderByComparator, true);
2519    
2520                            array[1] = resourcePermission;
2521    
2522                            array[2] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
2523                                            companyId, name, scope, primKey, orderByComparator, false);
2524    
2525                            return array;
2526                    }
2527                    catch (Exception e) {
2528                            throw processException(e);
2529                    }
2530                    finally {
2531                            closeSession(session);
2532                    }
2533            }
2534    
2535            protected ResourcePermission getByC_N_S_P_PrevAndNext(Session session,
2536                    ResourcePermission resourcePermission, long companyId, String name,
2537                    int scope, String primKey, OrderByComparator orderByComparator,
2538                    boolean previous) {
2539                    StringBundler query = null;
2540    
2541                    if (orderByComparator != null) {
2542                            query = new StringBundler(6 +
2543                                            (orderByComparator.getOrderByFields().length * 6));
2544                    }
2545                    else {
2546                            query = new StringBundler(3);
2547                    }
2548    
2549                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2550    
2551                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
2552    
2553                    if (name == null) {
2554                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
2555                    }
2556                    else {
2557                            if (name.equals(StringPool.BLANK)) {
2558                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
2559                            }
2560                            else {
2561                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
2562                            }
2563                    }
2564    
2565                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
2566    
2567                    if (primKey == null) {
2568                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
2569                    }
2570                    else {
2571                            if (primKey.equals(StringPool.BLANK)) {
2572                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
2573                            }
2574                            else {
2575                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
2576                            }
2577                    }
2578    
2579                    if (orderByComparator != null) {
2580                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2581    
2582                            if (orderByConditionFields.length > 0) {
2583                                    query.append(WHERE_AND);
2584                            }
2585    
2586                            for (int i = 0; i < orderByConditionFields.length; i++) {
2587                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2588                                    query.append(orderByConditionFields[i]);
2589    
2590                                    if ((i + 1) < orderByConditionFields.length) {
2591                                            if (orderByComparator.isAscending() ^ previous) {
2592                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2593                                            }
2594                                            else {
2595                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2596                                            }
2597                                    }
2598                                    else {
2599                                            if (orderByComparator.isAscending() ^ previous) {
2600                                                    query.append(WHERE_GREATER_THAN);
2601                                            }
2602                                            else {
2603                                                    query.append(WHERE_LESSER_THAN);
2604                                            }
2605                                    }
2606                            }
2607    
2608                            query.append(ORDER_BY_CLAUSE);
2609    
2610                            String[] orderByFields = orderByComparator.getOrderByFields();
2611    
2612                            for (int i = 0; i < orderByFields.length; i++) {
2613                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2614                                    query.append(orderByFields[i]);
2615    
2616                                    if ((i + 1) < orderByFields.length) {
2617                                            if (orderByComparator.isAscending() ^ previous) {
2618                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2619                                            }
2620                                            else {
2621                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2622                                            }
2623                                    }
2624                                    else {
2625                                            if (orderByComparator.isAscending() ^ previous) {
2626                                                    query.append(ORDER_BY_ASC);
2627                                            }
2628                                            else {
2629                                                    query.append(ORDER_BY_DESC);
2630                                            }
2631                                    }
2632                            }
2633                    }
2634    
2635                    String sql = query.toString();
2636    
2637                    Query q = session.createQuery(sql);
2638    
2639                    q.setFirstResult(0);
2640                    q.setMaxResults(2);
2641    
2642                    QueryPos qPos = QueryPos.getInstance(q);
2643    
2644                    qPos.add(companyId);
2645    
2646                    if (name != null) {
2647                            qPos.add(name);
2648                    }
2649    
2650                    qPos.add(scope);
2651    
2652                    if (primKey != null) {
2653                            qPos.add(primKey);
2654                    }
2655    
2656                    if (orderByComparator != null) {
2657                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
2658    
2659                            for (Object value : values) {
2660                                    qPos.add(value);
2661                            }
2662                    }
2663    
2664                    List<ResourcePermission> list = q.list();
2665    
2666                    if (list.size() == 2) {
2667                            return list.get(1);
2668                    }
2669                    else {
2670                            return null;
2671                    }
2672            }
2673    
2674            /**
2675             * Returns all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
2676             *
2677             * @param companyId the company ID
2678             * @param name the name
2679             * @param primKey the prim key
2680             * @param ownerId the owner ID
2681             * @return the matching resource permissions
2682             * @throws SystemException if a system exception occurred
2683             */
2684            public List<ResourcePermission> findByC_N_P_O(long companyId, String name,
2685                    String primKey, long ownerId) throws SystemException {
2686                    return findByC_N_P_O(companyId, name, primKey, ownerId,
2687                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2688            }
2689    
2690            /**
2691             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
2692             *
2693             * <p>
2694             * 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.
2695             * </p>
2696             *
2697             * @param companyId the company ID
2698             * @param name the name
2699             * @param primKey the prim key
2700             * @param ownerId the owner ID
2701             * @param start the lower bound of the range of resource permissions
2702             * @param end the upper bound of the range of resource permissions (not inclusive)
2703             * @return the range of matching resource permissions
2704             * @throws SystemException if a system exception occurred
2705             */
2706            public List<ResourcePermission> findByC_N_P_O(long companyId, String name,
2707                    String primKey, long ownerId, int start, int end)
2708                    throws SystemException {
2709                    return findByC_N_P_O(companyId, name, primKey, ownerId, start, end, null);
2710            }
2711    
2712            /**
2713             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
2714             *
2715             * <p>
2716             * 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.
2717             * </p>
2718             *
2719             * @param companyId the company ID
2720             * @param name the name
2721             * @param primKey the prim key
2722             * @param ownerId the owner ID
2723             * @param start the lower bound of the range of resource permissions
2724             * @param end the upper bound of the range of resource permissions (not inclusive)
2725             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2726             * @return the ordered range of matching resource permissions
2727             * @throws SystemException if a system exception occurred
2728             */
2729            public List<ResourcePermission> findByC_N_P_O(long companyId, String name,
2730                    String primKey, long ownerId, int start, int end,
2731                    OrderByComparator orderByComparator) throws SystemException {
2732                    FinderPath finderPath = null;
2733                    Object[] finderArgs = null;
2734    
2735                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2736                                    (orderByComparator == null)) {
2737                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_O;
2738                            finderArgs = new Object[] { companyId, name, primKey, ownerId };
2739                    }
2740                    else {
2741                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_O;
2742                            finderArgs = new Object[] {
2743                                            companyId, name, primKey, ownerId,
2744                                            
2745                                            start, end, orderByComparator
2746                                    };
2747                    }
2748    
2749                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
2750                                    finderArgs, this);
2751    
2752                    if (list == null) {
2753                            StringBundler query = null;
2754    
2755                            if (orderByComparator != null) {
2756                                    query = new StringBundler(6 +
2757                                                    (orderByComparator.getOrderByFields().length * 3));
2758                            }
2759                            else {
2760                                    query = new StringBundler(5);
2761                            }
2762    
2763                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
2764    
2765                            query.append(_FINDER_COLUMN_C_N_P_O_COMPANYID_2);
2766    
2767                            if (name == null) {
2768                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_1);
2769                            }
2770                            else {
2771                                    if (name.equals(StringPool.BLANK)) {
2772                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_3);
2773                                    }
2774                                    else {
2775                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_2);
2776                                    }
2777                            }
2778    
2779                            if (primKey == null) {
2780                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_1);
2781                            }
2782                            else {
2783                                    if (primKey.equals(StringPool.BLANK)) {
2784                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_3);
2785                                    }
2786                                    else {
2787                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_2);
2788                                    }
2789                            }
2790    
2791                            query.append(_FINDER_COLUMN_C_N_P_O_OWNERID_2);
2792    
2793                            if (orderByComparator != null) {
2794                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2795                                            orderByComparator);
2796                            }
2797    
2798                            String sql = query.toString();
2799    
2800                            Session session = null;
2801    
2802                            try {
2803                                    session = openSession();
2804    
2805                                    Query q = session.createQuery(sql);
2806    
2807                                    QueryPos qPos = QueryPos.getInstance(q);
2808    
2809                                    qPos.add(companyId);
2810    
2811                                    if (name != null) {
2812                                            qPos.add(name);
2813                                    }
2814    
2815                                    if (primKey != null) {
2816                                            qPos.add(primKey);
2817                                    }
2818    
2819                                    qPos.add(ownerId);
2820    
2821                                    list = (List<ResourcePermission>)QueryUtil.list(q,
2822                                                    getDialect(), start, end);
2823                            }
2824                            catch (Exception e) {
2825                                    throw processException(e);
2826                            }
2827                            finally {
2828                                    if (list == null) {
2829                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2830                                    }
2831                                    else {
2832                                            cacheResult(list);
2833    
2834                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2835                                    }
2836    
2837                                    closeSession(session);
2838                            }
2839                    }
2840    
2841                    return list;
2842            }
2843    
2844            /**
2845             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
2846             *
2847             * <p>
2848             * 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.
2849             * </p>
2850             *
2851             * @param companyId the company ID
2852             * @param name the name
2853             * @param primKey the prim key
2854             * @param ownerId the owner ID
2855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2856             * @return the first matching resource permission
2857             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2858             * @throws SystemException if a system exception occurred
2859             */
2860            public ResourcePermission findByC_N_P_O_First(long companyId, String name,
2861                    String primKey, long ownerId, OrderByComparator orderByComparator)
2862                    throws NoSuchResourcePermissionException, SystemException {
2863                    List<ResourcePermission> list = findByC_N_P_O(companyId, name, primKey,
2864                                    ownerId, 0, 1, orderByComparator);
2865    
2866                    if (list.isEmpty()) {
2867                            StringBundler msg = new StringBundler(10);
2868    
2869                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2870    
2871                            msg.append("companyId=");
2872                            msg.append(companyId);
2873    
2874                            msg.append(", name=");
2875                            msg.append(name);
2876    
2877                            msg.append(", primKey=");
2878                            msg.append(primKey);
2879    
2880                            msg.append(", ownerId=");
2881                            msg.append(ownerId);
2882    
2883                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2884    
2885                            throw new NoSuchResourcePermissionException(msg.toString());
2886                    }
2887                    else {
2888                            return list.get(0);
2889                    }
2890            }
2891    
2892            /**
2893             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
2894             *
2895             * <p>
2896             * 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.
2897             * </p>
2898             *
2899             * @param companyId the company ID
2900             * @param name the name
2901             * @param primKey the prim key
2902             * @param ownerId the owner ID
2903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2904             * @return the last matching resource permission
2905             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
2906             * @throws SystemException if a system exception occurred
2907             */
2908            public ResourcePermission findByC_N_P_O_Last(long companyId, String name,
2909                    String primKey, long ownerId, OrderByComparator orderByComparator)
2910                    throws NoSuchResourcePermissionException, SystemException {
2911                    int count = countByC_N_P_O(companyId, name, primKey, ownerId);
2912    
2913                    List<ResourcePermission> list = findByC_N_P_O(companyId, name, primKey,
2914                                    ownerId, count - 1, count, orderByComparator);
2915    
2916                    if (list.isEmpty()) {
2917                            StringBundler msg = new StringBundler(10);
2918    
2919                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2920    
2921                            msg.append("companyId=");
2922                            msg.append(companyId);
2923    
2924                            msg.append(", name=");
2925                            msg.append(name);
2926    
2927                            msg.append(", primKey=");
2928                            msg.append(primKey);
2929    
2930                            msg.append(", ownerId=");
2931                            msg.append(ownerId);
2932    
2933                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2934    
2935                            throw new NoSuchResourcePermissionException(msg.toString());
2936                    }
2937                    else {
2938                            return list.get(0);
2939                    }
2940            }
2941    
2942            /**
2943             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
2944             *
2945             * <p>
2946             * 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.
2947             * </p>
2948             *
2949             * @param resourcePermissionId the primary key of the current resource permission
2950             * @param companyId the company ID
2951             * @param name the name
2952             * @param primKey the prim key
2953             * @param ownerId the owner ID
2954             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2955             * @return the previous, current, and next resource permission
2956             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
2957             * @throws SystemException if a system exception occurred
2958             */
2959            public ResourcePermission[] findByC_N_P_O_PrevAndNext(
2960                    long resourcePermissionId, long companyId, String name, String primKey,
2961                    long ownerId, OrderByComparator orderByComparator)
2962                    throws NoSuchResourcePermissionException, SystemException {
2963                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
2964    
2965                    Session session = null;
2966    
2967                    try {
2968                            session = openSession();
2969    
2970                            ResourcePermission[] array = new ResourcePermissionImpl[3];
2971    
2972                            array[0] = getByC_N_P_O_PrevAndNext(session, resourcePermission,
2973                                            companyId, name, primKey, ownerId, orderByComparator, true);
2974    
2975                            array[1] = resourcePermission;
2976    
2977                            array[2] = getByC_N_P_O_PrevAndNext(session, resourcePermission,
2978                                            companyId, name, primKey, ownerId, orderByComparator, false);
2979    
2980                            return array;
2981                    }
2982                    catch (Exception e) {
2983                            throw processException(e);
2984                    }
2985                    finally {
2986                            closeSession(session);
2987                    }
2988            }
2989    
2990            protected ResourcePermission getByC_N_P_O_PrevAndNext(Session session,
2991                    ResourcePermission resourcePermission, long companyId, String name,
2992                    String primKey, long ownerId, OrderByComparator orderByComparator,
2993                    boolean previous) {
2994                    StringBundler query = null;
2995    
2996                    if (orderByComparator != null) {
2997                            query = new StringBundler(6 +
2998                                            (orderByComparator.getOrderByFields().length * 6));
2999                    }
3000                    else {
3001                            query = new StringBundler(3);
3002                    }
3003    
3004                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3005    
3006                    query.append(_FINDER_COLUMN_C_N_P_O_COMPANYID_2);
3007    
3008                    if (name == null) {
3009                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_1);
3010                    }
3011                    else {
3012                            if (name.equals(StringPool.BLANK)) {
3013                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_3);
3014                            }
3015                            else {
3016                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_2);
3017                            }
3018                    }
3019    
3020                    if (primKey == null) {
3021                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_1);
3022                    }
3023                    else {
3024                            if (primKey.equals(StringPool.BLANK)) {
3025                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_3);
3026                            }
3027                            else {
3028                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_2);
3029                            }
3030                    }
3031    
3032                    query.append(_FINDER_COLUMN_C_N_P_O_OWNERID_2);
3033    
3034                    if (orderByComparator != null) {
3035                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3036    
3037                            if (orderByConditionFields.length > 0) {
3038                                    query.append(WHERE_AND);
3039                            }
3040    
3041                            for (int i = 0; i < orderByConditionFields.length; i++) {
3042                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3043                                    query.append(orderByConditionFields[i]);
3044    
3045                                    if ((i + 1) < orderByConditionFields.length) {
3046                                            if (orderByComparator.isAscending() ^ previous) {
3047                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3048                                            }
3049                                            else {
3050                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3051                                            }
3052                                    }
3053                                    else {
3054                                            if (orderByComparator.isAscending() ^ previous) {
3055                                                    query.append(WHERE_GREATER_THAN);
3056                                            }
3057                                            else {
3058                                                    query.append(WHERE_LESSER_THAN);
3059                                            }
3060                                    }
3061                            }
3062    
3063                            query.append(ORDER_BY_CLAUSE);
3064    
3065                            String[] orderByFields = orderByComparator.getOrderByFields();
3066    
3067                            for (int i = 0; i < orderByFields.length; i++) {
3068                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3069                                    query.append(orderByFields[i]);
3070    
3071                                    if ((i + 1) < orderByFields.length) {
3072                                            if (orderByComparator.isAscending() ^ previous) {
3073                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3074                                            }
3075                                            else {
3076                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3077                                            }
3078                                    }
3079                                    else {
3080                                            if (orderByComparator.isAscending() ^ previous) {
3081                                                    query.append(ORDER_BY_ASC);
3082                                            }
3083                                            else {
3084                                                    query.append(ORDER_BY_DESC);
3085                                            }
3086                                    }
3087                            }
3088                    }
3089    
3090                    String sql = query.toString();
3091    
3092                    Query q = session.createQuery(sql);
3093    
3094                    q.setFirstResult(0);
3095                    q.setMaxResults(2);
3096    
3097                    QueryPos qPos = QueryPos.getInstance(q);
3098    
3099                    qPos.add(companyId);
3100    
3101                    if (name != null) {
3102                            qPos.add(name);
3103                    }
3104    
3105                    if (primKey != null) {
3106                            qPos.add(primKey);
3107                    }
3108    
3109                    qPos.add(ownerId);
3110    
3111                    if (orderByComparator != null) {
3112                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
3113    
3114                            for (Object value : values) {
3115                                    qPos.add(value);
3116                            }
3117                    }
3118    
3119                    List<ResourcePermission> list = q.list();
3120    
3121                    if (list.size() == 2) {
3122                            return list.get(1);
3123                    }
3124                    else {
3125                            return null;
3126                    }
3127            }
3128    
3129            /**
3130             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3131             *
3132             * @param companyId the company ID
3133             * @param name the name
3134             * @param scope the scope
3135             * @param primKey the prim key
3136             * @param roleId the role ID
3137             * @return the matching resource permissions
3138             * @throws SystemException if a system exception occurred
3139             */
3140            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3141                    String name, int scope, String primKey, long roleId)
3142                    throws SystemException {
3143                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleId,
3144                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3145            }
3146    
3147            /**
3148             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3149             *
3150             * <p>
3151             * 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.
3152             * </p>
3153             *
3154             * @param companyId the company ID
3155             * @param name the name
3156             * @param scope the scope
3157             * @param primKey the prim key
3158             * @param roleId the role ID
3159             * @param start the lower bound of the range of resource permissions
3160             * @param end the upper bound of the range of resource permissions (not inclusive)
3161             * @return the range of matching resource permissions
3162             * @throws SystemException if a system exception occurred
3163             */
3164            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3165                    String name, int scope, String primKey, long roleId, int start, int end)
3166                    throws SystemException {
3167                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleId, start,
3168                            end, null);
3169            }
3170    
3171            /**
3172             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3173             *
3174             * <p>
3175             * 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.
3176             * </p>
3177             *
3178             * @param companyId the company ID
3179             * @param name the name
3180             * @param scope the scope
3181             * @param primKey the prim key
3182             * @param roleId the role ID
3183             * @param start the lower bound of the range of resource permissions
3184             * @param end the upper bound of the range of resource permissions (not inclusive)
3185             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3186             * @return the ordered range of matching resource permissions
3187             * @throws SystemException if a system exception occurred
3188             */
3189            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3190                    String name, int scope, String primKey, long roleId, int start,
3191                    int end, OrderByComparator orderByComparator) throws SystemException {
3192                    FinderPath finderPath = null;
3193                    Object[] finderArgs = null;
3194    
3195                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3196                                    (orderByComparator == null)) {
3197                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R;
3198                            finderArgs = new Object[] { companyId, name, scope, primKey, roleId };
3199                    }
3200                    else {
3201                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R;
3202                            finderArgs = new Object[] {
3203                                            companyId, name, scope, primKey, roleId,
3204                                            
3205                                            start, end, orderByComparator
3206                                    };
3207                    }
3208    
3209                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
3210                                    finderArgs, this);
3211    
3212                    if (list == null) {
3213                            StringBundler query = null;
3214    
3215                            if (orderByComparator != null) {
3216                                    query = new StringBundler(7 +
3217                                                    (orderByComparator.getOrderByFields().length * 3));
3218                            }
3219                            else {
3220                                    query = new StringBundler(6);
3221                            }
3222    
3223                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3224    
3225                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
3226    
3227                            if (name == null) {
3228                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
3229                            }
3230                            else {
3231                                    if (name.equals(StringPool.BLANK)) {
3232                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
3233                                    }
3234                                    else {
3235                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
3236                                    }
3237                            }
3238    
3239                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
3240    
3241                            if (primKey == null) {
3242                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
3243                            }
3244                            else {
3245                                    if (primKey.equals(StringPool.BLANK)) {
3246                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
3247                                    }
3248                                    else {
3249                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
3250                                    }
3251                            }
3252    
3253                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
3254    
3255                            if (orderByComparator != null) {
3256                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3257                                            orderByComparator);
3258                            }
3259    
3260                            String sql = query.toString();
3261    
3262                            Session session = null;
3263    
3264                            try {
3265                                    session = openSession();
3266    
3267                                    Query q = session.createQuery(sql);
3268    
3269                                    QueryPos qPos = QueryPos.getInstance(q);
3270    
3271                                    qPos.add(companyId);
3272    
3273                                    if (name != null) {
3274                                            qPos.add(name);
3275                                    }
3276    
3277                                    qPos.add(scope);
3278    
3279                                    if (primKey != null) {
3280                                            qPos.add(primKey);
3281                                    }
3282    
3283                                    qPos.add(roleId);
3284    
3285                                    list = (List<ResourcePermission>)QueryUtil.list(q,
3286                                                    getDialect(), start, end);
3287                            }
3288                            catch (Exception e) {
3289                                    throw processException(e);
3290                            }
3291                            finally {
3292                                    if (list == null) {
3293                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3294                                    }
3295                                    else {
3296                                            cacheResult(list);
3297    
3298                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3299                                    }
3300    
3301                                    closeSession(session);
3302                            }
3303                    }
3304    
3305                    return list;
3306            }
3307    
3308            /**
3309             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3310             *
3311             * <p>
3312             * 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.
3313             * </p>
3314             *
3315             * @param companyId the company ID
3316             * @param name the name
3317             * @param scope the scope
3318             * @param primKey the prim key
3319             * @param roleId the role ID
3320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3321             * @return the first matching resource permission
3322             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
3323             * @throws SystemException if a system exception occurred
3324             */
3325            public ResourcePermission findByC_N_S_P_R_First(long companyId,
3326                    String name, int scope, String primKey, long roleId,
3327                    OrderByComparator orderByComparator)
3328                    throws NoSuchResourcePermissionException, SystemException {
3329                    List<ResourcePermission> list = findByC_N_S_P_R(companyId, name, scope,
3330                                    primKey, roleId, 0, 1, orderByComparator);
3331    
3332                    if (list.isEmpty()) {
3333                            StringBundler msg = new StringBundler(12);
3334    
3335                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3336    
3337                            msg.append("companyId=");
3338                            msg.append(companyId);
3339    
3340                            msg.append(", name=");
3341                            msg.append(name);
3342    
3343                            msg.append(", scope=");
3344                            msg.append(scope);
3345    
3346                            msg.append(", primKey=");
3347                            msg.append(primKey);
3348    
3349                            msg.append(", roleId=");
3350                            msg.append(roleId);
3351    
3352                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3353    
3354                            throw new NoSuchResourcePermissionException(msg.toString());
3355                    }
3356                    else {
3357                            return list.get(0);
3358                    }
3359            }
3360    
3361            /**
3362             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3363             *
3364             * <p>
3365             * 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.
3366             * </p>
3367             *
3368             * @param companyId the company ID
3369             * @param name the name
3370             * @param scope the scope
3371             * @param primKey the prim key
3372             * @param roleId the role ID
3373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3374             * @return the last matching resource permission
3375             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
3376             * @throws SystemException if a system exception occurred
3377             */
3378            public ResourcePermission findByC_N_S_P_R_Last(long companyId, String name,
3379                    int scope, String primKey, long roleId,
3380                    OrderByComparator orderByComparator)
3381                    throws NoSuchResourcePermissionException, SystemException {
3382                    int count = countByC_N_S_P_R(companyId, name, scope, primKey, roleId);
3383    
3384                    List<ResourcePermission> list = findByC_N_S_P_R(companyId, name, scope,
3385                                    primKey, roleId, count - 1, count, orderByComparator);
3386    
3387                    if (list.isEmpty()) {
3388                            StringBundler msg = new StringBundler(12);
3389    
3390                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3391    
3392                            msg.append("companyId=");
3393                            msg.append(companyId);
3394    
3395                            msg.append(", name=");
3396                            msg.append(name);
3397    
3398                            msg.append(", scope=");
3399                            msg.append(scope);
3400    
3401                            msg.append(", primKey=");
3402                            msg.append(primKey);
3403    
3404                            msg.append(", roleId=");
3405                            msg.append(roleId);
3406    
3407                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3408    
3409                            throw new NoSuchResourcePermissionException(msg.toString());
3410                    }
3411                    else {
3412                            return list.get(0);
3413                    }
3414            }
3415    
3416            /**
3417             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
3418             *
3419             * <p>
3420             * 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.
3421             * </p>
3422             *
3423             * @param resourcePermissionId the primary key of the current resource permission
3424             * @param companyId the company ID
3425             * @param name the name
3426             * @param scope the scope
3427             * @param primKey the prim key
3428             * @param roleId the role ID
3429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3430             * @return the previous, current, and next resource permission
3431             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
3432             * @throws SystemException if a system exception occurred
3433             */
3434            public ResourcePermission[] findByC_N_S_P_R_PrevAndNext(
3435                    long resourcePermissionId, long companyId, String name, int scope,
3436                    String primKey, long roleId, OrderByComparator orderByComparator)
3437                    throws NoSuchResourcePermissionException, SystemException {
3438                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
3439    
3440                    Session session = null;
3441    
3442                    try {
3443                            session = openSession();
3444    
3445                            ResourcePermission[] array = new ResourcePermissionImpl[3];
3446    
3447                            array[0] = getByC_N_S_P_R_PrevAndNext(session, resourcePermission,
3448                                            companyId, name, scope, primKey, roleId, orderByComparator,
3449                                            true);
3450    
3451                            array[1] = resourcePermission;
3452    
3453                            array[2] = getByC_N_S_P_R_PrevAndNext(session, resourcePermission,
3454                                            companyId, name, scope, primKey, roleId, orderByComparator,
3455                                            false);
3456    
3457                            return array;
3458                    }
3459                    catch (Exception e) {
3460                            throw processException(e);
3461                    }
3462                    finally {
3463                            closeSession(session);
3464                    }
3465            }
3466    
3467            protected ResourcePermission getByC_N_S_P_R_PrevAndNext(Session session,
3468                    ResourcePermission resourcePermission, long companyId, String name,
3469                    int scope, String primKey, long roleId,
3470                    OrderByComparator orderByComparator, boolean previous) {
3471                    StringBundler query = null;
3472    
3473                    if (orderByComparator != null) {
3474                            query = new StringBundler(6 +
3475                                            (orderByComparator.getOrderByFields().length * 6));
3476                    }
3477                    else {
3478                            query = new StringBundler(3);
3479                    }
3480    
3481                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3482    
3483                    query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
3484    
3485                    if (name == null) {
3486                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
3487                    }
3488                    else {
3489                            if (name.equals(StringPool.BLANK)) {
3490                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
3491                            }
3492                            else {
3493                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
3494                            }
3495                    }
3496    
3497                    query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
3498    
3499                    if (primKey == null) {
3500                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
3501                    }
3502                    else {
3503                            if (primKey.equals(StringPool.BLANK)) {
3504                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
3505                            }
3506                            else {
3507                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
3508                            }
3509                    }
3510    
3511                    query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
3512    
3513                    if (orderByComparator != null) {
3514                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3515    
3516                            if (orderByConditionFields.length > 0) {
3517                                    query.append(WHERE_AND);
3518                            }
3519    
3520                            for (int i = 0; i < orderByConditionFields.length; i++) {
3521                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3522                                    query.append(orderByConditionFields[i]);
3523    
3524                                    if ((i + 1) < orderByConditionFields.length) {
3525                                            if (orderByComparator.isAscending() ^ previous) {
3526                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3527                                            }
3528                                            else {
3529                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3530                                            }
3531                                    }
3532                                    else {
3533                                            if (orderByComparator.isAscending() ^ previous) {
3534                                                    query.append(WHERE_GREATER_THAN);
3535                                            }
3536                                            else {
3537                                                    query.append(WHERE_LESSER_THAN);
3538                                            }
3539                                    }
3540                            }
3541    
3542                            query.append(ORDER_BY_CLAUSE);
3543    
3544                            String[] orderByFields = orderByComparator.getOrderByFields();
3545    
3546                            for (int i = 0; i < orderByFields.length; i++) {
3547                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3548                                    query.append(orderByFields[i]);
3549    
3550                                    if ((i + 1) < orderByFields.length) {
3551                                            if (orderByComparator.isAscending() ^ previous) {
3552                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3553                                            }
3554                                            else {
3555                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3556                                            }
3557                                    }
3558                                    else {
3559                                            if (orderByComparator.isAscending() ^ previous) {
3560                                                    query.append(ORDER_BY_ASC);
3561                                            }
3562                                            else {
3563                                                    query.append(ORDER_BY_DESC);
3564                                            }
3565                                    }
3566                            }
3567                    }
3568    
3569                    String sql = query.toString();
3570    
3571                    Query q = session.createQuery(sql);
3572    
3573                    q.setFirstResult(0);
3574                    q.setMaxResults(2);
3575    
3576                    QueryPos qPos = QueryPos.getInstance(q);
3577    
3578                    qPos.add(companyId);
3579    
3580                    if (name != null) {
3581                            qPos.add(name);
3582                    }
3583    
3584                    qPos.add(scope);
3585    
3586                    if (primKey != null) {
3587                            qPos.add(primKey);
3588                    }
3589    
3590                    qPos.add(roleId);
3591    
3592                    if (orderByComparator != null) {
3593                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
3594    
3595                            for (Object value : values) {
3596                                    qPos.add(value);
3597                            }
3598                    }
3599    
3600                    List<ResourcePermission> list = q.list();
3601    
3602                    if (list.size() == 2) {
3603                            return list.get(1);
3604                    }
3605                    else {
3606                            return null;
3607                    }
3608            }
3609    
3610            /**
3611             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
3612             *
3613             * <p>
3614             * 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.
3615             * </p>
3616             *
3617             * @param companyId the company ID
3618             * @param name the name
3619             * @param scope the scope
3620             * @param primKey the prim key
3621             * @param roleIds the role IDs
3622             * @return the matching resource permissions
3623             * @throws SystemException if a system exception occurred
3624             */
3625            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3626                    String name, int scope, String primKey, long[] roleIds)
3627                    throws SystemException {
3628                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds,
3629                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3630            }
3631    
3632            /**
3633             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
3634             *
3635             * <p>
3636             * 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.
3637             * </p>
3638             *
3639             * @param companyId the company ID
3640             * @param name the name
3641             * @param scope the scope
3642             * @param primKey the prim key
3643             * @param roleIds the role IDs
3644             * @param start the lower bound of the range of resource permissions
3645             * @param end the upper bound of the range of resource permissions (not inclusive)
3646             * @return the range of matching resource permissions
3647             * @throws SystemException if a system exception occurred
3648             */
3649            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3650                    String name, int scope, String primKey, long[] roleIds, int start,
3651                    int end) throws SystemException {
3652                    return findByC_N_S_P_R(companyId, name, scope, primKey, roleIds, start,
3653                            end, null);
3654            }
3655    
3656            /**
3657             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
3658             *
3659             * <p>
3660             * 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.
3661             * </p>
3662             *
3663             * @param companyId the company ID
3664             * @param name the name
3665             * @param scope the scope
3666             * @param primKey the prim key
3667             * @param roleIds the role IDs
3668             * @param start the lower bound of the range of resource permissions
3669             * @param end the upper bound of the range of resource permissions (not inclusive)
3670             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3671             * @return the ordered range of matching resource permissions
3672             * @throws SystemException if a system exception occurred
3673             */
3674            public List<ResourcePermission> findByC_N_S_P_R(long companyId,
3675                    String name, int scope, String primKey, long[] roleIds, int start,
3676                    int end, OrderByComparator orderByComparator) throws SystemException {
3677                    FinderPath finderPath = null;
3678                    Object[] finderArgs = null;
3679    
3680                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3681                                    (orderByComparator == null)) {
3682                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R;
3683                            finderArgs = new Object[] {
3684                                            companyId, name, scope, primKey, StringUtil.merge(roleIds)
3685                                    };
3686                    }
3687                    else {
3688                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R;
3689                            finderArgs = new Object[] {
3690                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
3691                                            
3692                                            start, end, orderByComparator
3693                                    };
3694                    }
3695    
3696                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
3697                                    finderArgs, this);
3698    
3699                    if (list == null) {
3700                            StringBundler query = new StringBundler();
3701    
3702                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3703    
3704                            boolean conjunctionable = false;
3705    
3706                            if (conjunctionable) {
3707                                    query.append(WHERE_AND);
3708                            }
3709    
3710                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_5);
3711    
3712                            conjunctionable = true;
3713    
3714                            if (conjunctionable) {
3715                                    query.append(WHERE_AND);
3716                            }
3717    
3718                            if (name == null) {
3719                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_4);
3720                            }
3721                            else {
3722                                    if (name.equals(StringPool.BLANK)) {
3723                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_6);
3724                                    }
3725                                    else {
3726                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_5);
3727                                    }
3728                            }
3729    
3730                            conjunctionable = true;
3731    
3732                            if (conjunctionable) {
3733                                    query.append(WHERE_AND);
3734                            }
3735    
3736                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_5);
3737    
3738                            conjunctionable = true;
3739    
3740                            if (conjunctionable) {
3741                                    query.append(WHERE_AND);
3742                            }
3743    
3744                            if (primKey == null) {
3745                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_4);
3746                            }
3747                            else {
3748                                    if (primKey.equals(StringPool.BLANK)) {
3749                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_6);
3750                                    }
3751                                    else {
3752                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_5);
3753                                    }
3754                            }
3755    
3756                            conjunctionable = true;
3757    
3758                            if ((roleIds == null) || (roleIds.length > 0)) {
3759                                    if (conjunctionable) {
3760                                            query.append(WHERE_AND);
3761                                    }
3762    
3763                                    query.append(StringPool.OPEN_PARENTHESIS);
3764    
3765                                    for (int i = 0; i < roleIds.length; i++) {
3766                                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_5);
3767    
3768                                            if ((i + 1) < roleIds.length) {
3769                                                    query.append(WHERE_OR);
3770                                            }
3771                                    }
3772    
3773                                    query.append(StringPool.CLOSE_PARENTHESIS);
3774    
3775                                    conjunctionable = true;
3776                            }
3777    
3778                            if (orderByComparator != null) {
3779                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3780                                            orderByComparator);
3781                            }
3782    
3783                            String sql = query.toString();
3784    
3785                            Session session = null;
3786    
3787                            try {
3788                                    session = openSession();
3789    
3790                                    Query q = session.createQuery(sql);
3791    
3792                                    QueryPos qPos = QueryPos.getInstance(q);
3793    
3794                                    qPos.add(companyId);
3795    
3796                                    if (name != null) {
3797                                            qPos.add(name);
3798                                    }
3799    
3800                                    qPos.add(scope);
3801    
3802                                    if (primKey != null) {
3803                                            qPos.add(primKey);
3804                                    }
3805    
3806                                    if (roleIds != null) {
3807                                            qPos.add(roleIds);
3808                                    }
3809    
3810                                    list = (List<ResourcePermission>)QueryUtil.list(q,
3811                                                    getDialect(), start, end);
3812                            }
3813                            catch (Exception e) {
3814                                    throw processException(e);
3815                            }
3816                            finally {
3817                                    if (list == null) {
3818                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3819                                    }
3820                                    else {
3821                                            cacheResult(list);
3822    
3823                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3824                                    }
3825    
3826                                    closeSession(session);
3827                            }
3828                    }
3829    
3830                    return list;
3831            }
3832    
3833            /**
3834             * Returns all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
3835             *
3836             * @param companyId the company ID
3837             * @param name the name
3838             * @param primKey the prim key
3839             * @param roleId the role ID
3840             * @param actionIds the action IDs
3841             * @return the matching resource permissions
3842             * @throws SystemException if a system exception occurred
3843             */
3844            public List<ResourcePermission> findByC_N_P_R_A(long companyId,
3845                    String name, String primKey, long roleId, long actionIds)
3846                    throws SystemException {
3847                    return findByC_N_P_R_A(companyId, name, primKey, roleId, actionIds,
3848                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3849            }
3850    
3851            /**
3852             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
3853             *
3854             * <p>
3855             * 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.
3856             * </p>
3857             *
3858             * @param companyId the company ID
3859             * @param name the name
3860             * @param primKey the prim key
3861             * @param roleId the role ID
3862             * @param actionIds the action IDs
3863             * @param start the lower bound of the range of resource permissions
3864             * @param end the upper bound of the range of resource permissions (not inclusive)
3865             * @return the range of matching resource permissions
3866             * @throws SystemException if a system exception occurred
3867             */
3868            public List<ResourcePermission> findByC_N_P_R_A(long companyId,
3869                    String name, String primKey, long roleId, long actionIds, int start,
3870                    int end) throws SystemException {
3871                    return findByC_N_P_R_A(companyId, name, primKey, roleId, actionIds,
3872                            start, end, null);
3873            }
3874    
3875            /**
3876             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
3877             *
3878             * <p>
3879             * 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.
3880             * </p>
3881             *
3882             * @param companyId the company ID
3883             * @param name the name
3884             * @param primKey the prim key
3885             * @param roleId the role ID
3886             * @param actionIds the action IDs
3887             * @param start the lower bound of the range of resource permissions
3888             * @param end the upper bound of the range of resource permissions (not inclusive)
3889             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3890             * @return the ordered range of matching resource permissions
3891             * @throws SystemException if a system exception occurred
3892             */
3893            public List<ResourcePermission> findByC_N_P_R_A(long companyId,
3894                    String name, String primKey, long roleId, long actionIds, int start,
3895                    int end, OrderByComparator orderByComparator) throws SystemException {
3896                    FinderPath finderPath = null;
3897                    Object[] finderArgs = null;
3898    
3899                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3900                                    (orderByComparator == null)) {
3901                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_P_R_A;
3902                            finderArgs = new Object[] {
3903                                            companyId, name, primKey, roleId, actionIds
3904                                    };
3905                    }
3906                    else {
3907                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_P_R_A;
3908                            finderArgs = new Object[] {
3909                                            companyId, name, primKey, roleId, actionIds,
3910                                            
3911                                            start, end, orderByComparator
3912                                    };
3913                    }
3914    
3915                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
3916                                    finderArgs, this);
3917    
3918                    if (list == null) {
3919                            StringBundler query = null;
3920    
3921                            if (orderByComparator != null) {
3922                                    query = new StringBundler(7 +
3923                                                    (orderByComparator.getOrderByFields().length * 3));
3924                            }
3925                            else {
3926                                    query = new StringBundler(6);
3927                            }
3928    
3929                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
3930    
3931                            query.append(_FINDER_COLUMN_C_N_P_R_A_COMPANYID_2);
3932    
3933                            if (name == null) {
3934                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_1);
3935                            }
3936                            else {
3937                                    if (name.equals(StringPool.BLANK)) {
3938                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_3);
3939                                    }
3940                                    else {
3941                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_2);
3942                                    }
3943                            }
3944    
3945                            if (primKey == null) {
3946                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1);
3947                            }
3948                            else {
3949                                    if (primKey.equals(StringPool.BLANK)) {
3950                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3);
3951                                    }
3952                                    else {
3953                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2);
3954                                    }
3955                            }
3956    
3957                            query.append(_FINDER_COLUMN_C_N_P_R_A_ROLEID_2);
3958    
3959                            query.append(_FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2);
3960    
3961                            if (orderByComparator != null) {
3962                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3963                                            orderByComparator);
3964                            }
3965    
3966                            String sql = query.toString();
3967    
3968                            Session session = null;
3969    
3970                            try {
3971                                    session = openSession();
3972    
3973                                    Query q = session.createQuery(sql);
3974    
3975                                    QueryPos qPos = QueryPos.getInstance(q);
3976    
3977                                    qPos.add(companyId);
3978    
3979                                    if (name != null) {
3980                                            qPos.add(name);
3981                                    }
3982    
3983                                    if (primKey != null) {
3984                                            qPos.add(primKey);
3985                                    }
3986    
3987                                    qPos.add(roleId);
3988    
3989                                    qPos.add(actionIds);
3990    
3991                                    list = (List<ResourcePermission>)QueryUtil.list(q,
3992                                                    getDialect(), start, end);
3993                            }
3994                            catch (Exception e) {
3995                                    throw processException(e);
3996                            }
3997                            finally {
3998                                    if (list == null) {
3999                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4000                                    }
4001                                    else {
4002                                            cacheResult(list);
4003    
4004                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4005                                    }
4006    
4007                                    closeSession(session);
4008                            }
4009                    }
4010    
4011                    return list;
4012            }
4013    
4014            /**
4015             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4016             *
4017             * <p>
4018             * 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.
4019             * </p>
4020             *
4021             * @param companyId the company ID
4022             * @param name the name
4023             * @param primKey the prim key
4024             * @param roleId the role ID
4025             * @param actionIds the action IDs
4026             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4027             * @return the first matching resource permission
4028             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
4029             * @throws SystemException if a system exception occurred
4030             */
4031            public ResourcePermission findByC_N_P_R_A_First(long companyId,
4032                    String name, String primKey, long roleId, long actionIds,
4033                    OrderByComparator orderByComparator)
4034                    throws NoSuchResourcePermissionException, SystemException {
4035                    List<ResourcePermission> list = findByC_N_P_R_A(companyId, name,
4036                                    primKey, roleId, actionIds, 0, 1, orderByComparator);
4037    
4038                    if (list.isEmpty()) {
4039                            StringBundler msg = new StringBundler(12);
4040    
4041                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4042    
4043                            msg.append("companyId=");
4044                            msg.append(companyId);
4045    
4046                            msg.append(", name=");
4047                            msg.append(name);
4048    
4049                            msg.append(", primKey=");
4050                            msg.append(primKey);
4051    
4052                            msg.append(", roleId=");
4053                            msg.append(roleId);
4054    
4055                            msg.append(", actionIds=");
4056                            msg.append(actionIds);
4057    
4058                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4059    
4060                            throw new NoSuchResourcePermissionException(msg.toString());
4061                    }
4062                    else {
4063                            return list.get(0);
4064                    }
4065            }
4066    
4067            /**
4068             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4069             *
4070             * <p>
4071             * 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.
4072             * </p>
4073             *
4074             * @param companyId the company ID
4075             * @param name the name
4076             * @param primKey the prim key
4077             * @param roleId the role ID
4078             * @param actionIds the action IDs
4079             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4080             * @return the last matching resource permission
4081             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
4082             * @throws SystemException if a system exception occurred
4083             */
4084            public ResourcePermission findByC_N_P_R_A_Last(long companyId, String name,
4085                    String primKey, long roleId, long actionIds,
4086                    OrderByComparator orderByComparator)
4087                    throws NoSuchResourcePermissionException, SystemException {
4088                    int count = countByC_N_P_R_A(companyId, name, primKey, roleId, actionIds);
4089    
4090                    List<ResourcePermission> list = findByC_N_P_R_A(companyId, name,
4091                                    primKey, roleId, actionIds, count - 1, count, orderByComparator);
4092    
4093                    if (list.isEmpty()) {
4094                            StringBundler msg = new StringBundler(12);
4095    
4096                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4097    
4098                            msg.append("companyId=");
4099                            msg.append(companyId);
4100    
4101                            msg.append(", name=");
4102                            msg.append(name);
4103    
4104                            msg.append(", primKey=");
4105                            msg.append(primKey);
4106    
4107                            msg.append(", roleId=");
4108                            msg.append(roleId);
4109    
4110                            msg.append(", actionIds=");
4111                            msg.append(actionIds);
4112    
4113                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4114    
4115                            throw new NoSuchResourcePermissionException(msg.toString());
4116                    }
4117                    else {
4118                            return list.get(0);
4119                    }
4120            }
4121    
4122            /**
4123             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4124             *
4125             * <p>
4126             * 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.
4127             * </p>
4128             *
4129             * @param resourcePermissionId the primary key of the current resource permission
4130             * @param companyId the company ID
4131             * @param name the name
4132             * @param primKey the prim key
4133             * @param roleId the role ID
4134             * @param actionIds the action IDs
4135             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4136             * @return the previous, current, and next resource permission
4137             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4138             * @throws SystemException if a system exception occurred
4139             */
4140            public ResourcePermission[] findByC_N_P_R_A_PrevAndNext(
4141                    long resourcePermissionId, long companyId, String name, String primKey,
4142                    long roleId, long actionIds, OrderByComparator orderByComparator)
4143                    throws NoSuchResourcePermissionException, SystemException {
4144                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
4145    
4146                    Session session = null;
4147    
4148                    try {
4149                            session = openSession();
4150    
4151                            ResourcePermission[] array = new ResourcePermissionImpl[3];
4152    
4153                            array[0] = getByC_N_P_R_A_PrevAndNext(session, resourcePermission,
4154                                            companyId, name, primKey, roleId, actionIds,
4155                                            orderByComparator, true);
4156    
4157                            array[1] = resourcePermission;
4158    
4159                            array[2] = getByC_N_P_R_A_PrevAndNext(session, resourcePermission,
4160                                            companyId, name, primKey, roleId, actionIds,
4161                                            orderByComparator, false);
4162    
4163                            return array;
4164                    }
4165                    catch (Exception e) {
4166                            throw processException(e);
4167                    }
4168                    finally {
4169                            closeSession(session);
4170                    }
4171            }
4172    
4173            protected ResourcePermission getByC_N_P_R_A_PrevAndNext(Session session,
4174                    ResourcePermission resourcePermission, long companyId, String name,
4175                    String primKey, long roleId, long actionIds,
4176                    OrderByComparator orderByComparator, boolean previous) {
4177                    StringBundler query = null;
4178    
4179                    if (orderByComparator != null) {
4180                            query = new StringBundler(6 +
4181                                            (orderByComparator.getOrderByFields().length * 6));
4182                    }
4183                    else {
4184                            query = new StringBundler(3);
4185                    }
4186    
4187                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4188    
4189                    query.append(_FINDER_COLUMN_C_N_P_R_A_COMPANYID_2);
4190    
4191                    if (name == null) {
4192                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_1);
4193                    }
4194                    else {
4195                            if (name.equals(StringPool.BLANK)) {
4196                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_3);
4197                            }
4198                            else {
4199                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_2);
4200                            }
4201                    }
4202    
4203                    if (primKey == null) {
4204                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1);
4205                    }
4206                    else {
4207                            if (primKey.equals(StringPool.BLANK)) {
4208                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3);
4209                            }
4210                            else {
4211                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2);
4212                            }
4213                    }
4214    
4215                    query.append(_FINDER_COLUMN_C_N_P_R_A_ROLEID_2);
4216    
4217                    query.append(_FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2);
4218    
4219                    if (orderByComparator != null) {
4220                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4221    
4222                            if (orderByConditionFields.length > 0) {
4223                                    query.append(WHERE_AND);
4224                            }
4225    
4226                            for (int i = 0; i < orderByConditionFields.length; i++) {
4227                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4228                                    query.append(orderByConditionFields[i]);
4229    
4230                                    if ((i + 1) < orderByConditionFields.length) {
4231                                            if (orderByComparator.isAscending() ^ previous) {
4232                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4233                                            }
4234                                            else {
4235                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4236                                            }
4237                                    }
4238                                    else {
4239                                            if (orderByComparator.isAscending() ^ previous) {
4240                                                    query.append(WHERE_GREATER_THAN);
4241                                            }
4242                                            else {
4243                                                    query.append(WHERE_LESSER_THAN);
4244                                            }
4245                                    }
4246                            }
4247    
4248                            query.append(ORDER_BY_CLAUSE);
4249    
4250                            String[] orderByFields = orderByComparator.getOrderByFields();
4251    
4252                            for (int i = 0; i < orderByFields.length; i++) {
4253                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4254                                    query.append(orderByFields[i]);
4255    
4256                                    if ((i + 1) < orderByFields.length) {
4257                                            if (orderByComparator.isAscending() ^ previous) {
4258                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4259                                            }
4260                                            else {
4261                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4262                                            }
4263                                    }
4264                                    else {
4265                                            if (orderByComparator.isAscending() ^ previous) {
4266                                                    query.append(ORDER_BY_ASC);
4267                                            }
4268                                            else {
4269                                                    query.append(ORDER_BY_DESC);
4270                                            }
4271                                    }
4272                            }
4273                    }
4274    
4275                    String sql = query.toString();
4276    
4277                    Query q = session.createQuery(sql);
4278    
4279                    q.setFirstResult(0);
4280                    q.setMaxResults(2);
4281    
4282                    QueryPos qPos = QueryPos.getInstance(q);
4283    
4284                    qPos.add(companyId);
4285    
4286                    if (name != null) {
4287                            qPos.add(name);
4288                    }
4289    
4290                    if (primKey != null) {
4291                            qPos.add(primKey);
4292                    }
4293    
4294                    qPos.add(roleId);
4295    
4296                    qPos.add(actionIds);
4297    
4298                    if (orderByComparator != null) {
4299                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
4300    
4301                            for (Object value : values) {
4302                                    qPos.add(value);
4303                            }
4304                    }
4305    
4306                    List<ResourcePermission> list = q.list();
4307    
4308                    if (list.size() == 2) {
4309                            return list.get(1);
4310                    }
4311                    else {
4312                            return null;
4313                    }
4314            }
4315    
4316            /**
4317             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4318             *
4319             * @param companyId the company ID
4320             * @param name the name
4321             * @param scope the scope
4322             * @param primKey the prim key
4323             * @param roleId the role ID
4324             * @param actionIds the action IDs
4325             * @return the matching resource permissions
4326             * @throws SystemException if a system exception occurred
4327             */
4328            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
4329                    String name, int scope, String primKey, long roleId, long actionIds)
4330                    throws SystemException {
4331                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleId,
4332                            actionIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4333            }
4334    
4335            /**
4336             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4337             *
4338             * <p>
4339             * 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.
4340             * </p>
4341             *
4342             * @param companyId the company ID
4343             * @param name the name
4344             * @param scope the scope
4345             * @param primKey the prim key
4346             * @param roleId the role ID
4347             * @param actionIds the action IDs
4348             * @param start the lower bound of the range of resource permissions
4349             * @param end the upper bound of the range of resource permissions (not inclusive)
4350             * @return the range of matching resource permissions
4351             * @throws SystemException if a system exception occurred
4352             */
4353            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
4354                    String name, int scope, String primKey, long roleId, long actionIds,
4355                    int start, int end) throws SystemException {
4356                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleId,
4357                            actionIds, start, end, null);
4358            }
4359    
4360            /**
4361             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4362             *
4363             * <p>
4364             * 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.
4365             * </p>
4366             *
4367             * @param companyId the company ID
4368             * @param name the name
4369             * @param scope the scope
4370             * @param primKey the prim key
4371             * @param roleId the role ID
4372             * @param actionIds the action IDs
4373             * @param start the lower bound of the range of resource permissions
4374             * @param end the upper bound of the range of resource permissions (not inclusive)
4375             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4376             * @return the ordered range of matching resource permissions
4377             * @throws SystemException if a system exception occurred
4378             */
4379            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
4380                    String name, int scope, String primKey, long roleId, long actionIds,
4381                    int start, int end, OrderByComparator orderByComparator)
4382                    throws SystemException {
4383                    FinderPath finderPath = null;
4384                    Object[] finderArgs = null;
4385    
4386                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4387                                    (orderByComparator == null)) {
4388                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A;
4389                            finderArgs = new Object[] {
4390                                            companyId, name, scope, primKey, roleId, actionIds
4391                                    };
4392                    }
4393                    else {
4394                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A;
4395                            finderArgs = new Object[] {
4396                                            companyId, name, scope, primKey, roleId, actionIds,
4397                                            
4398                                            start, end, orderByComparator
4399                                    };
4400                    }
4401    
4402                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
4403                                    finderArgs, this);
4404    
4405                    if (list == null) {
4406                            StringBundler query = null;
4407    
4408                            if (orderByComparator != null) {
4409                                    query = new StringBundler(8 +
4410                                                    (orderByComparator.getOrderByFields().length * 3));
4411                            }
4412                            else {
4413                                    query = new StringBundler(7);
4414                            }
4415    
4416                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4417    
4418                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2);
4419    
4420                            if (name == null) {
4421                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1);
4422                            }
4423                            else {
4424                                    if (name.equals(StringPool.BLANK)) {
4425                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3);
4426                                    }
4427                                    else {
4428                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2);
4429                                    }
4430                            }
4431    
4432                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2);
4433    
4434                            if (primKey == null) {
4435                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1);
4436                            }
4437                            else {
4438                                    if (primKey.equals(StringPool.BLANK)) {
4439                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3);
4440                                    }
4441                                    else {
4442                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2);
4443                                    }
4444                            }
4445    
4446                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2);
4447    
4448                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2);
4449    
4450                            if (orderByComparator != null) {
4451                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4452                                            orderByComparator);
4453                            }
4454    
4455                            String sql = query.toString();
4456    
4457                            Session session = null;
4458    
4459                            try {
4460                                    session = openSession();
4461    
4462                                    Query q = session.createQuery(sql);
4463    
4464                                    QueryPos qPos = QueryPos.getInstance(q);
4465    
4466                                    qPos.add(companyId);
4467    
4468                                    if (name != null) {
4469                                            qPos.add(name);
4470                                    }
4471    
4472                                    qPos.add(scope);
4473    
4474                                    if (primKey != null) {
4475                                            qPos.add(primKey);
4476                                    }
4477    
4478                                    qPos.add(roleId);
4479    
4480                                    qPos.add(actionIds);
4481    
4482                                    list = (List<ResourcePermission>)QueryUtil.list(q,
4483                                                    getDialect(), start, end);
4484                            }
4485                            catch (Exception e) {
4486                                    throw processException(e);
4487                            }
4488                            finally {
4489                                    if (list == null) {
4490                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4491                                    }
4492                                    else {
4493                                            cacheResult(list);
4494    
4495                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4496                                    }
4497    
4498                                    closeSession(session);
4499                            }
4500                    }
4501    
4502                    return list;
4503            }
4504    
4505            /**
4506             * Returns the first resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4507             *
4508             * <p>
4509             * 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.
4510             * </p>
4511             *
4512             * @param companyId the company ID
4513             * @param name the name
4514             * @param scope the scope
4515             * @param primKey the prim key
4516             * @param roleId the role ID
4517             * @param actionIds the action IDs
4518             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4519             * @return the first matching resource permission
4520             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
4521             * @throws SystemException if a system exception occurred
4522             */
4523            public ResourcePermission findByC_N_S_P_R_A_First(long companyId,
4524                    String name, int scope, String primKey, long roleId, long actionIds,
4525                    OrderByComparator orderByComparator)
4526                    throws NoSuchResourcePermissionException, SystemException {
4527                    List<ResourcePermission> list = findByC_N_S_P_R_A(companyId, name,
4528                                    scope, primKey, roleId, actionIds, 0, 1, orderByComparator);
4529    
4530                    if (list.isEmpty()) {
4531                            StringBundler msg = new StringBundler(14);
4532    
4533                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4534    
4535                            msg.append("companyId=");
4536                            msg.append(companyId);
4537    
4538                            msg.append(", name=");
4539                            msg.append(name);
4540    
4541                            msg.append(", scope=");
4542                            msg.append(scope);
4543    
4544                            msg.append(", primKey=");
4545                            msg.append(primKey);
4546    
4547                            msg.append(", roleId=");
4548                            msg.append(roleId);
4549    
4550                            msg.append(", actionIds=");
4551                            msg.append(actionIds);
4552    
4553                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4554    
4555                            throw new NoSuchResourcePermissionException(msg.toString());
4556                    }
4557                    else {
4558                            return list.get(0);
4559                    }
4560            }
4561    
4562            /**
4563             * Returns the last resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4564             *
4565             * <p>
4566             * 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.
4567             * </p>
4568             *
4569             * @param companyId the company ID
4570             * @param name the name
4571             * @param scope the scope
4572             * @param primKey the prim key
4573             * @param roleId the role ID
4574             * @param actionIds the action IDs
4575             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4576             * @return the last matching resource permission
4577             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
4578             * @throws SystemException if a system exception occurred
4579             */
4580            public ResourcePermission findByC_N_S_P_R_A_Last(long companyId,
4581                    String name, int scope, String primKey, long roleId, long actionIds,
4582                    OrderByComparator orderByComparator)
4583                    throws NoSuchResourcePermissionException, SystemException {
4584                    int count = countByC_N_S_P_R_A(companyId, name, scope, primKey, roleId,
4585                                    actionIds);
4586    
4587                    List<ResourcePermission> list = findByC_N_S_P_R_A(companyId, name,
4588                                    scope, primKey, roleId, actionIds, count - 1, count,
4589                                    orderByComparator);
4590    
4591                    if (list.isEmpty()) {
4592                            StringBundler msg = new StringBundler(14);
4593    
4594                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4595    
4596                            msg.append("companyId=");
4597                            msg.append(companyId);
4598    
4599                            msg.append(", name=");
4600                            msg.append(name);
4601    
4602                            msg.append(", scope=");
4603                            msg.append(scope);
4604    
4605                            msg.append(", primKey=");
4606                            msg.append(primKey);
4607    
4608                            msg.append(", roleId=");
4609                            msg.append(roleId);
4610    
4611                            msg.append(", actionIds=");
4612                            msg.append(actionIds);
4613    
4614                            msg.append(StringPool.CLOSE_CURLY_BRACE);
4615    
4616                            throw new NoSuchResourcePermissionException(msg.toString());
4617                    }
4618                    else {
4619                            return list.get(0);
4620                    }
4621            }
4622    
4623            /**
4624             * Returns the resource permissions before and after the current resource permission in the ordered set where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
4625             *
4626             * <p>
4627             * 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.
4628             * </p>
4629             *
4630             * @param resourcePermissionId the primary key of the current resource permission
4631             * @param companyId the company ID
4632             * @param name the name
4633             * @param scope the scope
4634             * @param primKey the prim key
4635             * @param roleId the role ID
4636             * @param actionIds the action IDs
4637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4638             * @return the previous, current, and next resource permission
4639             * @throws com.liferay.portal.NoSuchResourcePermissionException if a resource permission with the primary key could not be found
4640             * @throws SystemException if a system exception occurred
4641             */
4642            public ResourcePermission[] findByC_N_S_P_R_A_PrevAndNext(
4643                    long resourcePermissionId, long companyId, String name, int scope,
4644                    String primKey, long roleId, long actionIds,
4645                    OrderByComparator orderByComparator)
4646                    throws NoSuchResourcePermissionException, SystemException {
4647                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
4648    
4649                    Session session = null;
4650    
4651                    try {
4652                            session = openSession();
4653    
4654                            ResourcePermission[] array = new ResourcePermissionImpl[3];
4655    
4656                            array[0] = getByC_N_S_P_R_A_PrevAndNext(session,
4657                                            resourcePermission, companyId, name, scope, primKey,
4658                                            roleId, actionIds, orderByComparator, true);
4659    
4660                            array[1] = resourcePermission;
4661    
4662                            array[2] = getByC_N_S_P_R_A_PrevAndNext(session,
4663                                            resourcePermission, companyId, name, scope, primKey,
4664                                            roleId, actionIds, orderByComparator, false);
4665    
4666                            return array;
4667                    }
4668                    catch (Exception e) {
4669                            throw processException(e);
4670                    }
4671                    finally {
4672                            closeSession(session);
4673                    }
4674            }
4675    
4676            protected ResourcePermission getByC_N_S_P_R_A_PrevAndNext(Session session,
4677                    ResourcePermission resourcePermission, long companyId, String name,
4678                    int scope, String primKey, long roleId, long actionIds,
4679                    OrderByComparator orderByComparator, boolean previous) {
4680                    StringBundler query = null;
4681    
4682                    if (orderByComparator != null) {
4683                            query = new StringBundler(6 +
4684                                            (orderByComparator.getOrderByFields().length * 6));
4685                    }
4686                    else {
4687                            query = new StringBundler(3);
4688                    }
4689    
4690                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4691    
4692                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2);
4693    
4694                    if (name == null) {
4695                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1);
4696                    }
4697                    else {
4698                            if (name.equals(StringPool.BLANK)) {
4699                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3);
4700                            }
4701                            else {
4702                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2);
4703                            }
4704                    }
4705    
4706                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2);
4707    
4708                    if (primKey == null) {
4709                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1);
4710                    }
4711                    else {
4712                            if (primKey.equals(StringPool.BLANK)) {
4713                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3);
4714                            }
4715                            else {
4716                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2);
4717                            }
4718                    }
4719    
4720                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2);
4721    
4722                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2);
4723    
4724                    if (orderByComparator != null) {
4725                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4726    
4727                            if (orderByConditionFields.length > 0) {
4728                                    query.append(WHERE_AND);
4729                            }
4730    
4731                            for (int i = 0; i < orderByConditionFields.length; i++) {
4732                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4733                                    query.append(orderByConditionFields[i]);
4734    
4735                                    if ((i + 1) < orderByConditionFields.length) {
4736                                            if (orderByComparator.isAscending() ^ previous) {
4737                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4738                                            }
4739                                            else {
4740                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4741                                            }
4742                                    }
4743                                    else {
4744                                            if (orderByComparator.isAscending() ^ previous) {
4745                                                    query.append(WHERE_GREATER_THAN);
4746                                            }
4747                                            else {
4748                                                    query.append(WHERE_LESSER_THAN);
4749                                            }
4750                                    }
4751                            }
4752    
4753                            query.append(ORDER_BY_CLAUSE);
4754    
4755                            String[] orderByFields = orderByComparator.getOrderByFields();
4756    
4757                            for (int i = 0; i < orderByFields.length; i++) {
4758                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4759                                    query.append(orderByFields[i]);
4760    
4761                                    if ((i + 1) < orderByFields.length) {
4762                                            if (orderByComparator.isAscending() ^ previous) {
4763                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4764                                            }
4765                                            else {
4766                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4767                                            }
4768                                    }
4769                                    else {
4770                                            if (orderByComparator.isAscending() ^ previous) {
4771                                                    query.append(ORDER_BY_ASC);
4772                                            }
4773                                            else {
4774                                                    query.append(ORDER_BY_DESC);
4775                                            }
4776                                    }
4777                            }
4778                    }
4779    
4780                    String sql = query.toString();
4781    
4782                    Query q = session.createQuery(sql);
4783    
4784                    q.setFirstResult(0);
4785                    q.setMaxResults(2);
4786    
4787                    QueryPos qPos = QueryPos.getInstance(q);
4788    
4789                    qPos.add(companyId);
4790    
4791                    if (name != null) {
4792                            qPos.add(name);
4793                    }
4794    
4795                    qPos.add(scope);
4796    
4797                    if (primKey != null) {
4798                            qPos.add(primKey);
4799                    }
4800    
4801                    qPos.add(roleId);
4802    
4803                    qPos.add(actionIds);
4804    
4805                    if (orderByComparator != null) {
4806                            Object[] values = orderByComparator.getOrderByConditionValues(resourcePermission);
4807    
4808                            for (Object value : values) {
4809                                    qPos.add(value);
4810                            }
4811                    }
4812    
4813                    List<ResourcePermission> list = q.list();
4814    
4815                    if (list.size() == 2) {
4816                            return list.get(1);
4817                    }
4818                    else {
4819                            return null;
4820                    }
4821            }
4822    
4823            /**
4824             * Returns all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
4825             *
4826             * <p>
4827             * 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.
4828             * </p>
4829             *
4830             * @param companyId the company ID
4831             * @param name the name
4832             * @param scope the scope
4833             * @param primKey the prim key
4834             * @param roleIds the role IDs
4835             * @param actionIds the action IDs
4836             * @return the matching resource permissions
4837             * @throws SystemException if a system exception occurred
4838             */
4839            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
4840                    String name, int scope, String primKey, long[] roleIds, long actionIds)
4841                    throws SystemException {
4842                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleIds,
4843                            actionIds, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4844            }
4845    
4846            /**
4847             * Returns a range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
4848             *
4849             * <p>
4850             * 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.
4851             * </p>
4852             *
4853             * @param companyId the company ID
4854             * @param name the name
4855             * @param scope the scope
4856             * @param primKey the prim key
4857             * @param roleIds the role IDs
4858             * @param actionIds the action IDs
4859             * @param start the lower bound of the range of resource permissions
4860             * @param end the upper bound of the range of resource permissions (not inclusive)
4861             * @return the range of matching resource permissions
4862             * @throws SystemException if a system exception occurred
4863             */
4864            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
4865                    String name, int scope, String primKey, long[] roleIds, long actionIds,
4866                    int start, int end) throws SystemException {
4867                    return findByC_N_S_P_R_A(companyId, name, scope, primKey, roleIds,
4868                            actionIds, start, end, null);
4869            }
4870    
4871            /**
4872             * Returns an ordered range of all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
4873             *
4874             * <p>
4875             * 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.
4876             * </p>
4877             *
4878             * @param companyId the company ID
4879             * @param name the name
4880             * @param scope the scope
4881             * @param primKey the prim key
4882             * @param roleIds the role IDs
4883             * @param actionIds the action IDs
4884             * @param start the lower bound of the range of resource permissions
4885             * @param end the upper bound of the range of resource permissions (not inclusive)
4886             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4887             * @return the ordered range of matching resource permissions
4888             * @throws SystemException if a system exception occurred
4889             */
4890            public List<ResourcePermission> findByC_N_S_P_R_A(long companyId,
4891                    String name, int scope, String primKey, long[] roleIds, long actionIds,
4892                    int start, int end, OrderByComparator orderByComparator)
4893                    throws SystemException {
4894                    FinderPath finderPath = null;
4895                    Object[] finderArgs = null;
4896    
4897                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4898                                    (orderByComparator == null)) {
4899                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_N_S_P_R_A;
4900                            finderArgs = new Object[] {
4901                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
4902                                            actionIds
4903                                    };
4904                    }
4905                    else {
4906                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_N_S_P_R_A;
4907                            finderArgs = new Object[] {
4908                                            companyId, name, scope, primKey, StringUtil.merge(roleIds),
4909                                            actionIds,
4910                                            
4911                                            start, end, orderByComparator
4912                                    };
4913                    }
4914    
4915                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
4916                                    finderArgs, this);
4917    
4918                    if (list == null) {
4919                            StringBundler query = new StringBundler();
4920    
4921                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
4922    
4923                            boolean conjunctionable = false;
4924    
4925                            if (conjunctionable) {
4926                                    query.append(WHERE_AND);
4927                            }
4928    
4929                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_5);
4930    
4931                            conjunctionable = true;
4932    
4933                            if (conjunctionable) {
4934                                    query.append(WHERE_AND);
4935                            }
4936    
4937                            if (name == null) {
4938                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_4);
4939                            }
4940                            else {
4941                                    if (name.equals(StringPool.BLANK)) {
4942                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_6);
4943                                    }
4944                                    else {
4945                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_5);
4946                                    }
4947                            }
4948    
4949                            conjunctionable = true;
4950    
4951                            if (conjunctionable) {
4952                                    query.append(WHERE_AND);
4953                            }
4954    
4955                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_5);
4956    
4957                            conjunctionable = true;
4958    
4959                            if (conjunctionable) {
4960                                    query.append(WHERE_AND);
4961                            }
4962    
4963                            if (primKey == null) {
4964                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_4);
4965                            }
4966                            else {
4967                                    if (primKey.equals(StringPool.BLANK)) {
4968                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_6);
4969                                    }
4970                                    else {
4971                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_5);
4972                                    }
4973                            }
4974    
4975                            conjunctionable = true;
4976    
4977                            if ((roleIds == null) || (roleIds.length > 0)) {
4978                                    if (conjunctionable) {
4979                                            query.append(WHERE_AND);
4980                                    }
4981    
4982                                    query.append(StringPool.OPEN_PARENTHESIS);
4983    
4984                                    for (int i = 0; i < roleIds.length; i++) {
4985                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_5);
4986    
4987                                            if ((i + 1) < roleIds.length) {
4988                                                    query.append(WHERE_OR);
4989                                            }
4990                                    }
4991    
4992                                    query.append(StringPool.CLOSE_PARENTHESIS);
4993    
4994                                    conjunctionable = true;
4995                            }
4996    
4997                            if (conjunctionable) {
4998                                    query.append(WHERE_AND);
4999                            }
5000    
5001                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_5);
5002    
5003                            conjunctionable = true;
5004    
5005                            if (orderByComparator != null) {
5006                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5007                                            orderByComparator);
5008                            }
5009    
5010                            String sql = query.toString();
5011    
5012                            Session session = null;
5013    
5014                            try {
5015                                    session = openSession();
5016    
5017                                    Query q = session.createQuery(sql);
5018    
5019                                    QueryPos qPos = QueryPos.getInstance(q);
5020    
5021                                    qPos.add(companyId);
5022    
5023                                    if (name != null) {
5024                                            qPos.add(name);
5025                                    }
5026    
5027                                    qPos.add(scope);
5028    
5029                                    if (primKey != null) {
5030                                            qPos.add(primKey);
5031                                    }
5032    
5033                                    if (roleIds != null) {
5034                                            qPos.add(roleIds);
5035                                    }
5036    
5037                                    qPos.add(actionIds);
5038    
5039                                    list = (List<ResourcePermission>)QueryUtil.list(q,
5040                                                    getDialect(), start, end);
5041                            }
5042                            catch (Exception e) {
5043                                    throw processException(e);
5044                            }
5045                            finally {
5046                                    if (list == null) {
5047                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5048                                    }
5049                                    else {
5050                                            cacheResult(list);
5051    
5052                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5053                                    }
5054    
5055                                    closeSession(session);
5056                            }
5057                    }
5058    
5059                    return list;
5060            }
5061    
5062            /**
5063             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; or throws a {@link com.liferay.portal.NoSuchResourcePermissionException} if it could not be found.
5064             *
5065             * @param companyId the company ID
5066             * @param name the name
5067             * @param scope the scope
5068             * @param primKey the prim key
5069             * @param roleId the role ID
5070             * @param ownerId the owner ID
5071             * @param actionIds the action IDs
5072             * @return the matching resource permission
5073             * @throws com.liferay.portal.NoSuchResourcePermissionException if a matching resource permission could not be found
5074             * @throws SystemException if a system exception occurred
5075             */
5076            public ResourcePermission findByC_N_S_P_R_O_A(long companyId, String name,
5077                    int scope, String primKey, long roleId, long ownerId, long actionIds)
5078                    throws NoSuchResourcePermissionException, SystemException {
5079                    ResourcePermission resourcePermission = fetchByC_N_S_P_R_O_A(companyId,
5080                                    name, scope, primKey, roleId, ownerId, actionIds);
5081    
5082                    if (resourcePermission == null) {
5083                            StringBundler msg = new StringBundler(16);
5084    
5085                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5086    
5087                            msg.append("companyId=");
5088                            msg.append(companyId);
5089    
5090                            msg.append(", name=");
5091                            msg.append(name);
5092    
5093                            msg.append(", scope=");
5094                            msg.append(scope);
5095    
5096                            msg.append(", primKey=");
5097                            msg.append(primKey);
5098    
5099                            msg.append(", roleId=");
5100                            msg.append(roleId);
5101    
5102                            msg.append(", ownerId=");
5103                            msg.append(ownerId);
5104    
5105                            msg.append(", actionIds=");
5106                            msg.append(actionIds);
5107    
5108                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5109    
5110                            if (_log.isWarnEnabled()) {
5111                                    _log.warn(msg.toString());
5112                            }
5113    
5114                            throw new NoSuchResourcePermissionException(msg.toString());
5115                    }
5116    
5117                    return resourcePermission;
5118            }
5119    
5120            /**
5121             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5122             *
5123             * @param companyId the company ID
5124             * @param name the name
5125             * @param scope the scope
5126             * @param primKey the prim key
5127             * @param roleId the role ID
5128             * @param ownerId the owner ID
5129             * @param actionIds the action IDs
5130             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
5131             * @throws SystemException if a system exception occurred
5132             */
5133            public ResourcePermission fetchByC_N_S_P_R_O_A(long companyId, String name,
5134                    int scope, String primKey, long roleId, long ownerId, long actionIds)
5135                    throws SystemException {
5136                    return fetchByC_N_S_P_R_O_A(companyId, name, scope, primKey, roleId,
5137                            ownerId, actionIds, true);
5138            }
5139    
5140            /**
5141             * Returns the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
5142             *
5143             * @param companyId the company ID
5144             * @param name the name
5145             * @param scope the scope
5146             * @param primKey the prim key
5147             * @param roleId the role ID
5148             * @param ownerId the owner ID
5149             * @param actionIds the action IDs
5150             * @param retrieveFromCache whether to use the finder cache
5151             * @return the matching resource permission, or <code>null</code> if a matching resource permission could not be found
5152             * @throws SystemException if a system exception occurred
5153             */
5154            public ResourcePermission fetchByC_N_S_P_R_O_A(long companyId, String name,
5155                    int scope, String primKey, long roleId, long ownerId, long actionIds,
5156                    boolean retrieveFromCache) throws SystemException {
5157                    Object[] finderArgs = new Object[] {
5158                                    companyId, name, scope, primKey, roleId, ownerId, actionIds
5159                            };
5160    
5161                    Object result = null;
5162    
5163                    if (retrieveFromCache) {
5164                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
5165                                            finderArgs, this);
5166                    }
5167    
5168                    if (result == null) {
5169                            StringBundler query = new StringBundler(8);
5170    
5171                            query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
5172    
5173                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_COMPANYID_2);
5174    
5175                            if (name == null) {
5176                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_1);
5177                            }
5178                            else {
5179                                    if (name.equals(StringPool.BLANK)) {
5180                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_3);
5181                                    }
5182                                    else {
5183                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_2);
5184                                    }
5185                            }
5186    
5187                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_SCOPE_2);
5188    
5189                            if (primKey == null) {
5190                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_1);
5191                            }
5192                            else {
5193                                    if (primKey.equals(StringPool.BLANK)) {
5194                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_3);
5195                                    }
5196                                    else {
5197                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_2);
5198                                    }
5199                            }
5200    
5201                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ROLEID_2);
5202    
5203                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_OWNERID_2);
5204    
5205                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ACTIONIDS_2);
5206    
5207                            String sql = query.toString();
5208    
5209                            Session session = null;
5210    
5211                            try {
5212                                    session = openSession();
5213    
5214                                    Query q = session.createQuery(sql);
5215    
5216                                    QueryPos qPos = QueryPos.getInstance(q);
5217    
5218                                    qPos.add(companyId);
5219    
5220                                    if (name != null) {
5221                                            qPos.add(name);
5222                                    }
5223    
5224                                    qPos.add(scope);
5225    
5226                                    if (primKey != null) {
5227                                            qPos.add(primKey);
5228                                    }
5229    
5230                                    qPos.add(roleId);
5231    
5232                                    qPos.add(ownerId);
5233    
5234                                    qPos.add(actionIds);
5235    
5236                                    List<ResourcePermission> list = q.list();
5237    
5238                                    result = list;
5239    
5240                                    ResourcePermission resourcePermission = null;
5241    
5242                                    if (list.isEmpty()) {
5243                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
5244                                                    finderArgs, list);
5245                                    }
5246                                    else {
5247                                            resourcePermission = list.get(0);
5248    
5249                                            cacheResult(resourcePermission);
5250    
5251                                            if ((resourcePermission.getCompanyId() != companyId) ||
5252                                                            (resourcePermission.getName() == null) ||
5253                                                            !resourcePermission.getName().equals(name) ||
5254                                                            (resourcePermission.getScope() != scope) ||
5255                                                            (resourcePermission.getPrimKey() == null) ||
5256                                                            !resourcePermission.getPrimKey().equals(primKey) ||
5257                                                            (resourcePermission.getRoleId() != roleId) ||
5258                                                            (resourcePermission.getOwnerId() != ownerId) ||
5259                                                            (resourcePermission.getActionIds() != actionIds)) {
5260                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
5261                                                            finderArgs, resourcePermission);
5262                                            }
5263                                    }
5264    
5265                                    return resourcePermission;
5266                            }
5267                            catch (Exception e) {
5268                                    throw processException(e);
5269                            }
5270                            finally {
5271                                    if (result == null) {
5272                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R_O_A,
5273                                                    finderArgs);
5274                                    }
5275    
5276                                    closeSession(session);
5277                            }
5278                    }
5279                    else {
5280                            if (result instanceof List<?>) {
5281                                    return null;
5282                            }
5283                            else {
5284                                    return (ResourcePermission)result;
5285                            }
5286                    }
5287            }
5288    
5289            /**
5290             * Returns all the resource permissions.
5291             *
5292             * @return the resource permissions
5293             * @throws SystemException if a system exception occurred
5294             */
5295            public List<ResourcePermission> findAll() throws SystemException {
5296                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5297            }
5298    
5299            /**
5300             * Returns a range of all the resource permissions.
5301             *
5302             * <p>
5303             * 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.
5304             * </p>
5305             *
5306             * @param start the lower bound of the range of resource permissions
5307             * @param end the upper bound of the range of resource permissions (not inclusive)
5308             * @return the range of resource permissions
5309             * @throws SystemException if a system exception occurred
5310             */
5311            public List<ResourcePermission> findAll(int start, int end)
5312                    throws SystemException {
5313                    return findAll(start, end, null);
5314            }
5315    
5316            /**
5317             * Returns an ordered range of all the resource permissions.
5318             *
5319             * <p>
5320             * 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.
5321             * </p>
5322             *
5323             * @param start the lower bound of the range of resource permissions
5324             * @param end the upper bound of the range of resource permissions (not inclusive)
5325             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5326             * @return the ordered range of resource permissions
5327             * @throws SystemException if a system exception occurred
5328             */
5329            public List<ResourcePermission> findAll(int start, int end,
5330                    OrderByComparator orderByComparator) throws SystemException {
5331                    FinderPath finderPath = null;
5332                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
5333    
5334                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5335                                    (orderByComparator == null)) {
5336                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
5337                            finderArgs = FINDER_ARGS_EMPTY;
5338                    }
5339                    else {
5340                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
5341                            finderArgs = new Object[] { start, end, orderByComparator };
5342                    }
5343    
5344                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(finderPath,
5345                                    finderArgs, this);
5346    
5347                    if (list == null) {
5348                            StringBundler query = null;
5349                            String sql = null;
5350    
5351                            if (orderByComparator != null) {
5352                                    query = new StringBundler(2 +
5353                                                    (orderByComparator.getOrderByFields().length * 3));
5354    
5355                                    query.append(_SQL_SELECT_RESOURCEPERMISSION);
5356    
5357                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5358                                            orderByComparator);
5359    
5360                                    sql = query.toString();
5361                            }
5362                            else {
5363                                    sql = _SQL_SELECT_RESOURCEPERMISSION;
5364                            }
5365    
5366                            Session session = null;
5367    
5368                            try {
5369                                    session = openSession();
5370    
5371                                    Query q = session.createQuery(sql);
5372    
5373                                    if (orderByComparator == null) {
5374                                            list = (List<ResourcePermission>)QueryUtil.list(q,
5375                                                            getDialect(), start, end, false);
5376    
5377                                            Collections.sort(list);
5378                                    }
5379                                    else {
5380                                            list = (List<ResourcePermission>)QueryUtil.list(q,
5381                                                            getDialect(), start, end);
5382                                    }
5383                            }
5384                            catch (Exception e) {
5385                                    throw processException(e);
5386                            }
5387                            finally {
5388                                    if (list == null) {
5389                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5390                                    }
5391                                    else {
5392                                            cacheResult(list);
5393    
5394                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5395                                    }
5396    
5397                                    closeSession(session);
5398                            }
5399                    }
5400    
5401                    return list;
5402            }
5403    
5404            /**
5405             * Removes all the resource permissions where scope = &#63; from the database.
5406             *
5407             * @param scope the scope
5408             * @throws SystemException if a system exception occurred
5409             */
5410            public void removeByScope(int scope) throws SystemException {
5411                    for (ResourcePermission resourcePermission : findByScope(scope)) {
5412                            remove(resourcePermission);
5413                    }
5414            }
5415    
5416            /**
5417             * Removes all the resource permissions where roleId = &#63; from the database.
5418             *
5419             * @param roleId the role ID
5420             * @throws SystemException if a system exception occurred
5421             */
5422            public void removeByRoleId(long roleId) throws SystemException {
5423                    for (ResourcePermission resourcePermission : findByRoleId(roleId)) {
5424                            remove(resourcePermission);
5425                    }
5426            }
5427    
5428            /**
5429             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; from the database.
5430             *
5431             * @param companyId the company ID
5432             * @param name the name
5433             * @param scope the scope
5434             * @throws SystemException if a system exception occurred
5435             */
5436            public void removeByC_N_S(long companyId, String name, int scope)
5437                    throws SystemException {
5438                    for (ResourcePermission resourcePermission : findByC_N_S(companyId,
5439                                    name, scope)) {
5440                            remove(resourcePermission);
5441                    }
5442            }
5443    
5444            /**
5445             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; from the database.
5446             *
5447             * @param companyId the company ID
5448             * @param name the name
5449             * @param scope the scope
5450             * @param primKey the prim key
5451             * @throws SystemException if a system exception occurred
5452             */
5453            public void removeByC_N_S_P(long companyId, String name, int scope,
5454                    String primKey) throws SystemException {
5455                    for (ResourcePermission resourcePermission : findByC_N_S_P(companyId,
5456                                    name, scope, primKey)) {
5457                            remove(resourcePermission);
5458                    }
5459            }
5460    
5461            /**
5462             * Removes all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63; from the database.
5463             *
5464             * @param companyId the company ID
5465             * @param name the name
5466             * @param primKey the prim key
5467             * @param ownerId the owner ID
5468             * @throws SystemException if a system exception occurred
5469             */
5470            public void removeByC_N_P_O(long companyId, String name, String primKey,
5471                    long ownerId) throws SystemException {
5472                    for (ResourcePermission resourcePermission : findByC_N_P_O(companyId,
5473                                    name, primKey, ownerId)) {
5474                            remove(resourcePermission);
5475                    }
5476            }
5477    
5478            /**
5479             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; from the database.
5480             *
5481             * @param companyId the company ID
5482             * @param name the name
5483             * @param scope the scope
5484             * @param primKey the prim key
5485             * @param roleId the role ID
5486             * @throws SystemException if a system exception occurred
5487             */
5488            public void removeByC_N_S_P_R(long companyId, String name, int scope,
5489                    String primKey, long roleId) throws SystemException {
5490                    for (ResourcePermission resourcePermission : findByC_N_S_P_R(
5491                                    companyId, name, scope, primKey, roleId)) {
5492                            remove(resourcePermission);
5493                    }
5494            }
5495    
5496            /**
5497             * Removes all the resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63; from the database.
5498             *
5499             * @param companyId the company ID
5500             * @param name the name
5501             * @param primKey the prim key
5502             * @param roleId the role ID
5503             * @param actionIds the action IDs
5504             * @throws SystemException if a system exception occurred
5505             */
5506            public void removeByC_N_P_R_A(long companyId, String name, String primKey,
5507                    long roleId, long actionIds) throws SystemException {
5508                    for (ResourcePermission resourcePermission : findByC_N_P_R_A(
5509                                    companyId, name, primKey, roleId, actionIds)) {
5510                            remove(resourcePermission);
5511                    }
5512            }
5513    
5514            /**
5515             * Removes all the resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63; from the database.
5516             *
5517             * @param companyId the company ID
5518             * @param name the name
5519             * @param scope the scope
5520             * @param primKey the prim key
5521             * @param roleId the role ID
5522             * @param actionIds the action IDs
5523             * @throws SystemException if a system exception occurred
5524             */
5525            public void removeByC_N_S_P_R_A(long companyId, String name, int scope,
5526                    String primKey, long roleId, long actionIds) throws SystemException {
5527                    for (ResourcePermission resourcePermission : findByC_N_S_P_R_A(
5528                                    companyId, name, scope, primKey, roleId, actionIds)) {
5529                            remove(resourcePermission);
5530                    }
5531            }
5532    
5533            /**
5534             * Removes the resource permission where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63; from the database.
5535             *
5536             * @param companyId the company ID
5537             * @param name the name
5538             * @param scope the scope
5539             * @param primKey the prim key
5540             * @param roleId the role ID
5541             * @param ownerId the owner ID
5542             * @param actionIds the action IDs
5543             * @throws SystemException if a system exception occurred
5544             */
5545            public void removeByC_N_S_P_R_O_A(long companyId, String name, int scope,
5546                    String primKey, long roleId, long ownerId, long actionIds)
5547                    throws NoSuchResourcePermissionException, SystemException {
5548                    ResourcePermission resourcePermission = findByC_N_S_P_R_O_A(companyId,
5549                                    name, scope, primKey, roleId, ownerId, actionIds);
5550    
5551                    remove(resourcePermission);
5552            }
5553    
5554            /**
5555             * Removes all the resource permissions from the database.
5556             *
5557             * @throws SystemException if a system exception occurred
5558             */
5559            public void removeAll() throws SystemException {
5560                    for (ResourcePermission resourcePermission : findAll()) {
5561                            remove(resourcePermission);
5562                    }
5563            }
5564    
5565            /**
5566             * Returns the number of resource permissions where scope = &#63;.
5567             *
5568             * @param scope the scope
5569             * @return the number of matching resource permissions
5570             * @throws SystemException if a system exception occurred
5571             */
5572            public int countByScope(int scope) throws SystemException {
5573                    Object[] finderArgs = new Object[] { scope };
5574    
5575                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SCOPE,
5576                                    finderArgs, this);
5577    
5578                    if (count == null) {
5579                            StringBundler query = new StringBundler(2);
5580    
5581                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5582    
5583                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_2);
5584    
5585                            String sql = query.toString();
5586    
5587                            Session session = null;
5588    
5589                            try {
5590                                    session = openSession();
5591    
5592                                    Query q = session.createQuery(sql);
5593    
5594                                    QueryPos qPos = QueryPos.getInstance(q);
5595    
5596                                    qPos.add(scope);
5597    
5598                                    count = (Long)q.uniqueResult();
5599                            }
5600                            catch (Exception e) {
5601                                    throw processException(e);
5602                            }
5603                            finally {
5604                                    if (count == null) {
5605                                            count = Long.valueOf(0);
5606                                    }
5607    
5608                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SCOPE,
5609                                            finderArgs, count);
5610    
5611                                    closeSession(session);
5612                            }
5613                    }
5614    
5615                    return count.intValue();
5616            }
5617    
5618            /**
5619             * Returns the number of resource permissions where scope = any &#63;.
5620             *
5621             * @param scopes the scopes
5622             * @return the number of matching resource permissions
5623             * @throws SystemException if a system exception occurred
5624             */
5625            public int countByScope(int[] scopes) throws SystemException {
5626                    Object[] finderArgs = new Object[] { StringUtil.merge(scopes) };
5627    
5628                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SCOPE,
5629                                    finderArgs, this);
5630    
5631                    if (count == null) {
5632                            StringBundler query = new StringBundler();
5633    
5634                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5635    
5636                            boolean conjunctionable = false;
5637    
5638                            if ((scopes == null) || (scopes.length > 0)) {
5639                                    if (conjunctionable) {
5640                                            query.append(WHERE_AND);
5641                                    }
5642    
5643                                    query.append(StringPool.OPEN_PARENTHESIS);
5644    
5645                                    for (int i = 0; i < scopes.length; i++) {
5646                                            query.append(_FINDER_COLUMN_SCOPE_SCOPE_5);
5647    
5648                                            if ((i + 1) < scopes.length) {
5649                                                    query.append(WHERE_OR);
5650                                            }
5651                                    }
5652    
5653                                    query.append(StringPool.CLOSE_PARENTHESIS);
5654    
5655                                    conjunctionable = true;
5656                            }
5657    
5658                            String sql = query.toString();
5659    
5660                            Session session = null;
5661    
5662                            try {
5663                                    session = openSession();
5664    
5665                                    Query q = session.createQuery(sql);
5666    
5667                                    QueryPos qPos = QueryPos.getInstance(q);
5668    
5669                                    if (scopes != null) {
5670                                            qPos.add(scopes);
5671                                    }
5672    
5673                                    count = (Long)q.uniqueResult();
5674                            }
5675                            catch (Exception e) {
5676                                    throw processException(e);
5677                            }
5678                            finally {
5679                                    if (count == null) {
5680                                            count = Long.valueOf(0);
5681                                    }
5682    
5683                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SCOPE,
5684                                            finderArgs, count);
5685    
5686                                    closeSession(session);
5687                            }
5688                    }
5689    
5690                    return count.intValue();
5691            }
5692    
5693            /**
5694             * Returns the number of resource permissions where roleId = &#63;.
5695             *
5696             * @param roleId the role ID
5697             * @return the number of matching resource permissions
5698             * @throws SystemException if a system exception occurred
5699             */
5700            public int countByRoleId(long roleId) throws SystemException {
5701                    Object[] finderArgs = new Object[] { roleId };
5702    
5703                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
5704                                    finderArgs, this);
5705    
5706                    if (count == null) {
5707                            StringBundler query = new StringBundler(2);
5708    
5709                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5710    
5711                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
5712    
5713                            String sql = query.toString();
5714    
5715                            Session session = null;
5716    
5717                            try {
5718                                    session = openSession();
5719    
5720                                    Query q = session.createQuery(sql);
5721    
5722                                    QueryPos qPos = QueryPos.getInstance(q);
5723    
5724                                    qPos.add(roleId);
5725    
5726                                    count = (Long)q.uniqueResult();
5727                            }
5728                            catch (Exception e) {
5729                                    throw processException(e);
5730                            }
5731                            finally {
5732                                    if (count == null) {
5733                                            count = Long.valueOf(0);
5734                                    }
5735    
5736                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
5737                                            finderArgs, count);
5738    
5739                                    closeSession(session);
5740                            }
5741                    }
5742    
5743                    return count.intValue();
5744            }
5745    
5746            /**
5747             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63;.
5748             *
5749             * @param companyId the company ID
5750             * @param name the name
5751             * @param scope the scope
5752             * @return the number of matching resource permissions
5753             * @throws SystemException if a system exception occurred
5754             */
5755            public int countByC_N_S(long companyId, String name, int scope)
5756                    throws SystemException {
5757                    Object[] finderArgs = new Object[] { companyId, name, scope };
5758    
5759                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
5760                                    finderArgs, this);
5761    
5762                    if (count == null) {
5763                            StringBundler query = new StringBundler(4);
5764    
5765                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5766    
5767                            query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
5768    
5769                            if (name == null) {
5770                                    query.append(_FINDER_COLUMN_C_N_S_NAME_1);
5771                            }
5772                            else {
5773                                    if (name.equals(StringPool.BLANK)) {
5774                                            query.append(_FINDER_COLUMN_C_N_S_NAME_3);
5775                                    }
5776                                    else {
5777                                            query.append(_FINDER_COLUMN_C_N_S_NAME_2);
5778                                    }
5779                            }
5780    
5781                            query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
5782    
5783                            String sql = query.toString();
5784    
5785                            Session session = null;
5786    
5787                            try {
5788                                    session = openSession();
5789    
5790                                    Query q = session.createQuery(sql);
5791    
5792                                    QueryPos qPos = QueryPos.getInstance(q);
5793    
5794                                    qPos.add(companyId);
5795    
5796                                    if (name != null) {
5797                                            qPos.add(name);
5798                                    }
5799    
5800                                    qPos.add(scope);
5801    
5802                                    count = (Long)q.uniqueResult();
5803                            }
5804                            catch (Exception e) {
5805                                    throw processException(e);
5806                            }
5807                            finally {
5808                                    if (count == null) {
5809                                            count = Long.valueOf(0);
5810                                    }
5811    
5812                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
5813                                            finderArgs, count);
5814    
5815                                    closeSession(session);
5816                            }
5817                    }
5818    
5819                    return count.intValue();
5820            }
5821    
5822            /**
5823             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63;.
5824             *
5825             * @param companyId the company ID
5826             * @param name the name
5827             * @param scope the scope
5828             * @param primKey the prim key
5829             * @return the number of matching resource permissions
5830             * @throws SystemException if a system exception occurred
5831             */
5832            public int countByC_N_S_P(long companyId, String name, int scope,
5833                    String primKey) throws SystemException {
5834                    Object[] finderArgs = new Object[] { companyId, name, scope, primKey };
5835    
5836                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P,
5837                                    finderArgs, this);
5838    
5839                    if (count == null) {
5840                            StringBundler query = new StringBundler(5);
5841    
5842                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5843    
5844                            query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
5845    
5846                            if (name == null) {
5847                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
5848                            }
5849                            else {
5850                                    if (name.equals(StringPool.BLANK)) {
5851                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
5852                                    }
5853                                    else {
5854                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
5855                                    }
5856                            }
5857    
5858                            query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
5859    
5860                            if (primKey == null) {
5861                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
5862                            }
5863                            else {
5864                                    if (primKey.equals(StringPool.BLANK)) {
5865                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
5866                                    }
5867                                    else {
5868                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
5869                                    }
5870                            }
5871    
5872                            String sql = query.toString();
5873    
5874                            Session session = null;
5875    
5876                            try {
5877                                    session = openSession();
5878    
5879                                    Query q = session.createQuery(sql);
5880    
5881                                    QueryPos qPos = QueryPos.getInstance(q);
5882    
5883                                    qPos.add(companyId);
5884    
5885                                    if (name != null) {
5886                                            qPos.add(name);
5887                                    }
5888    
5889                                    qPos.add(scope);
5890    
5891                                    if (primKey != null) {
5892                                            qPos.add(primKey);
5893                                    }
5894    
5895                                    count = (Long)q.uniqueResult();
5896                            }
5897                            catch (Exception e) {
5898                                    throw processException(e);
5899                            }
5900                            finally {
5901                                    if (count == null) {
5902                                            count = Long.valueOf(0);
5903                                    }
5904    
5905                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P,
5906                                            finderArgs, count);
5907    
5908                                    closeSession(session);
5909                            }
5910                    }
5911    
5912                    return count.intValue();
5913            }
5914    
5915            /**
5916             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and ownerId = &#63;.
5917             *
5918             * @param companyId the company ID
5919             * @param name the name
5920             * @param primKey the prim key
5921             * @param ownerId the owner ID
5922             * @return the number of matching resource permissions
5923             * @throws SystemException if a system exception occurred
5924             */
5925            public int countByC_N_P_O(long companyId, String name, String primKey,
5926                    long ownerId) throws SystemException {
5927                    Object[] finderArgs = new Object[] { companyId, name, primKey, ownerId };
5928    
5929                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_P_O,
5930                                    finderArgs, this);
5931    
5932                    if (count == null) {
5933                            StringBundler query = new StringBundler(5);
5934    
5935                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
5936    
5937                            query.append(_FINDER_COLUMN_C_N_P_O_COMPANYID_2);
5938    
5939                            if (name == null) {
5940                                    query.append(_FINDER_COLUMN_C_N_P_O_NAME_1);
5941                            }
5942                            else {
5943                                    if (name.equals(StringPool.BLANK)) {
5944                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_3);
5945                                    }
5946                                    else {
5947                                            query.append(_FINDER_COLUMN_C_N_P_O_NAME_2);
5948                                    }
5949                            }
5950    
5951                            if (primKey == null) {
5952                                    query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_1);
5953                            }
5954                            else {
5955                                    if (primKey.equals(StringPool.BLANK)) {
5956                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_3);
5957                                    }
5958                                    else {
5959                                            query.append(_FINDER_COLUMN_C_N_P_O_PRIMKEY_2);
5960                                    }
5961                            }
5962    
5963                            query.append(_FINDER_COLUMN_C_N_P_O_OWNERID_2);
5964    
5965                            String sql = query.toString();
5966    
5967                            Session session = null;
5968    
5969                            try {
5970                                    session = openSession();
5971    
5972                                    Query q = session.createQuery(sql);
5973    
5974                                    QueryPos qPos = QueryPos.getInstance(q);
5975    
5976                                    qPos.add(companyId);
5977    
5978                                    if (name != null) {
5979                                            qPos.add(name);
5980                                    }
5981    
5982                                    if (primKey != null) {
5983                                            qPos.add(primKey);
5984                                    }
5985    
5986                                    qPos.add(ownerId);
5987    
5988                                    count = (Long)q.uniqueResult();
5989                            }
5990                            catch (Exception e) {
5991                                    throw processException(e);
5992                            }
5993                            finally {
5994                                    if (count == null) {
5995                                            count = Long.valueOf(0);
5996                                    }
5997    
5998                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_P_O,
5999                                            finderArgs, count);
6000    
6001                                    closeSession(session);
6002                            }
6003                    }
6004    
6005                    return count.intValue();
6006            }
6007    
6008            /**
6009             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63;.
6010             *
6011             * @param companyId the company ID
6012             * @param name the name
6013             * @param scope the scope
6014             * @param primKey the prim key
6015             * @param roleId the role ID
6016             * @return the number of matching resource permissions
6017             * @throws SystemException if a system exception occurred
6018             */
6019            public int countByC_N_S_P_R(long companyId, String name, int scope,
6020                    String primKey, long roleId) throws SystemException {
6021                    Object[] finderArgs = new Object[] {
6022                                    companyId, name, scope, primKey, roleId
6023                            };
6024    
6025                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
6026                                    finderArgs, this);
6027    
6028                    if (count == null) {
6029                            StringBundler query = new StringBundler(6);
6030    
6031                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6032    
6033                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
6034    
6035                            if (name == null) {
6036                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
6037                            }
6038                            else {
6039                                    if (name.equals(StringPool.BLANK)) {
6040                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
6041                                    }
6042                                    else {
6043                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
6044                                    }
6045                            }
6046    
6047                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
6048    
6049                            if (primKey == null) {
6050                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
6051                            }
6052                            else {
6053                                    if (primKey.equals(StringPool.BLANK)) {
6054                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
6055                                    }
6056                                    else {
6057                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
6058                                    }
6059                            }
6060    
6061                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
6062    
6063                            String sql = query.toString();
6064    
6065                            Session session = null;
6066    
6067                            try {
6068                                    session = openSession();
6069    
6070                                    Query q = session.createQuery(sql);
6071    
6072                                    QueryPos qPos = QueryPos.getInstance(q);
6073    
6074                                    qPos.add(companyId);
6075    
6076                                    if (name != null) {
6077                                            qPos.add(name);
6078                                    }
6079    
6080                                    qPos.add(scope);
6081    
6082                                    if (primKey != null) {
6083                                            qPos.add(primKey);
6084                                    }
6085    
6086                                    qPos.add(roleId);
6087    
6088                                    count = (Long)q.uniqueResult();
6089                            }
6090                            catch (Exception e) {
6091                                    throw processException(e);
6092                            }
6093                            finally {
6094                                    if (count == null) {
6095                                            count = Long.valueOf(0);
6096                                    }
6097    
6098                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
6099                                            finderArgs, count);
6100    
6101                                    closeSession(session);
6102                            }
6103                    }
6104    
6105                    return count.intValue();
6106            }
6107    
6108            /**
6109             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63;.
6110             *
6111             * @param companyId the company ID
6112             * @param name the name
6113             * @param scope the scope
6114             * @param primKey the prim key
6115             * @param roleIds the role IDs
6116             * @return the number of matching resource permissions
6117             * @throws SystemException if a system exception occurred
6118             */
6119            public int countByC_N_S_P_R(long companyId, String name, int scope,
6120                    String primKey, long[] roleIds) throws SystemException {
6121                    Object[] finderArgs = new Object[] {
6122                                    companyId, name, scope, primKey, StringUtil.merge(roleIds)
6123                            };
6124    
6125                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
6126                                    finderArgs, this);
6127    
6128                    if (count == null) {
6129                            StringBundler query = new StringBundler();
6130    
6131                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6132    
6133                            boolean conjunctionable = false;
6134    
6135                            if (conjunctionable) {
6136                                    query.append(WHERE_AND);
6137                            }
6138    
6139                            query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_5);
6140    
6141                            conjunctionable = true;
6142    
6143                            if (conjunctionable) {
6144                                    query.append(WHERE_AND);
6145                            }
6146    
6147                            if (name == null) {
6148                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_4);
6149                            }
6150                            else {
6151                                    if (name.equals(StringPool.BLANK)) {
6152                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_6);
6153                                    }
6154                                    else {
6155                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_5);
6156                                    }
6157                            }
6158    
6159                            conjunctionable = true;
6160    
6161                            if (conjunctionable) {
6162                                    query.append(WHERE_AND);
6163                            }
6164    
6165                            query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_5);
6166    
6167                            conjunctionable = true;
6168    
6169                            if (conjunctionable) {
6170                                    query.append(WHERE_AND);
6171                            }
6172    
6173                            if (primKey == null) {
6174                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_4);
6175                            }
6176                            else {
6177                                    if (primKey.equals(StringPool.BLANK)) {
6178                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_6);
6179                                    }
6180                                    else {
6181                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_5);
6182                                    }
6183                            }
6184    
6185                            conjunctionable = true;
6186    
6187                            if ((roleIds == null) || (roleIds.length > 0)) {
6188                                    if (conjunctionable) {
6189                                            query.append(WHERE_AND);
6190                                    }
6191    
6192                                    query.append(StringPool.OPEN_PARENTHESIS);
6193    
6194                                    for (int i = 0; i < roleIds.length; i++) {
6195                                            query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_5);
6196    
6197                                            if ((i + 1) < roleIds.length) {
6198                                                    query.append(WHERE_OR);
6199                                            }
6200                                    }
6201    
6202                                    query.append(StringPool.CLOSE_PARENTHESIS);
6203    
6204                                    conjunctionable = true;
6205                            }
6206    
6207                            String sql = query.toString();
6208    
6209                            Session session = null;
6210    
6211                            try {
6212                                    session = openSession();
6213    
6214                                    Query q = session.createQuery(sql);
6215    
6216                                    QueryPos qPos = QueryPos.getInstance(q);
6217    
6218                                    qPos.add(companyId);
6219    
6220                                    if (name != null) {
6221                                            qPos.add(name);
6222                                    }
6223    
6224                                    qPos.add(scope);
6225    
6226                                    if (primKey != null) {
6227                                            qPos.add(primKey);
6228                                    }
6229    
6230                                    if (roleIds != null) {
6231                                            qPos.add(roleIds);
6232                                    }
6233    
6234                                    count = (Long)q.uniqueResult();
6235                            }
6236                            catch (Exception e) {
6237                                    throw processException(e);
6238                            }
6239                            finally {
6240                                    if (count == null) {
6241                                            count = Long.valueOf(0);
6242                                    }
6243    
6244                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
6245                                            finderArgs, count);
6246    
6247                                    closeSession(session);
6248                            }
6249                    }
6250    
6251                    return count.intValue();
6252            }
6253    
6254            /**
6255             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6256             *
6257             * @param companyId the company ID
6258             * @param name the name
6259             * @param primKey the prim key
6260             * @param roleId the role ID
6261             * @param actionIds the action IDs
6262             * @return the number of matching resource permissions
6263             * @throws SystemException if a system exception occurred
6264             */
6265            public int countByC_N_P_R_A(long companyId, String name, String primKey,
6266                    long roleId, long actionIds) throws SystemException {
6267                    Object[] finderArgs = new Object[] {
6268                                    companyId, name, primKey, roleId, actionIds
6269                            };
6270    
6271                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_P_R_A,
6272                                    finderArgs, this);
6273    
6274                    if (count == null) {
6275                            StringBundler query = new StringBundler(6);
6276    
6277                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6278    
6279                            query.append(_FINDER_COLUMN_C_N_P_R_A_COMPANYID_2);
6280    
6281                            if (name == null) {
6282                                    query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_1);
6283                            }
6284                            else {
6285                                    if (name.equals(StringPool.BLANK)) {
6286                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_3);
6287                                    }
6288                                    else {
6289                                            query.append(_FINDER_COLUMN_C_N_P_R_A_NAME_2);
6290                                    }
6291                            }
6292    
6293                            if (primKey == null) {
6294                                    query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1);
6295                            }
6296                            else {
6297                                    if (primKey.equals(StringPool.BLANK)) {
6298                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3);
6299                                    }
6300                                    else {
6301                                            query.append(_FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2);
6302                                    }
6303                            }
6304    
6305                            query.append(_FINDER_COLUMN_C_N_P_R_A_ROLEID_2);
6306    
6307                            query.append(_FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2);
6308    
6309                            String sql = query.toString();
6310    
6311                            Session session = null;
6312    
6313                            try {
6314                                    session = openSession();
6315    
6316                                    Query q = session.createQuery(sql);
6317    
6318                                    QueryPos qPos = QueryPos.getInstance(q);
6319    
6320                                    qPos.add(companyId);
6321    
6322                                    if (name != null) {
6323                                            qPos.add(name);
6324                                    }
6325    
6326                                    if (primKey != null) {
6327                                            qPos.add(primKey);
6328                                    }
6329    
6330                                    qPos.add(roleId);
6331    
6332                                    qPos.add(actionIds);
6333    
6334                                    count = (Long)q.uniqueResult();
6335                            }
6336                            catch (Exception e) {
6337                                    throw processException(e);
6338                            }
6339                            finally {
6340                                    if (count == null) {
6341                                            count = Long.valueOf(0);
6342                                    }
6343    
6344                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_P_R_A,
6345                                            finderArgs, count);
6346    
6347                                    closeSession(session);
6348                            }
6349                    }
6350    
6351                    return count.intValue();
6352            }
6353    
6354            /**
6355             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and actionIds = &#63;.
6356             *
6357             * @param companyId the company ID
6358             * @param name the name
6359             * @param scope the scope
6360             * @param primKey the prim key
6361             * @param roleId the role ID
6362             * @param actionIds the action IDs
6363             * @return the number of matching resource permissions
6364             * @throws SystemException if a system exception occurred
6365             */
6366            public int countByC_N_S_P_R_A(long companyId, String name, int scope,
6367                    String primKey, long roleId, long actionIds) throws SystemException {
6368                    Object[] finderArgs = new Object[] {
6369                                    companyId, name, scope, primKey, roleId, actionIds
6370                            };
6371    
6372                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
6373                                    finderArgs, this);
6374    
6375                    if (count == null) {
6376                            StringBundler query = new StringBundler(7);
6377    
6378                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6379    
6380                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2);
6381    
6382                            if (name == null) {
6383                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1);
6384                            }
6385                            else {
6386                                    if (name.equals(StringPool.BLANK)) {
6387                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3);
6388                                    }
6389                                    else {
6390                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2);
6391                                    }
6392                            }
6393    
6394                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2);
6395    
6396                            if (primKey == null) {
6397                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1);
6398                            }
6399                            else {
6400                                    if (primKey.equals(StringPool.BLANK)) {
6401                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3);
6402                                    }
6403                                    else {
6404                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2);
6405                                    }
6406                            }
6407    
6408                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2);
6409    
6410                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2);
6411    
6412                            String sql = query.toString();
6413    
6414                            Session session = null;
6415    
6416                            try {
6417                                    session = openSession();
6418    
6419                                    Query q = session.createQuery(sql);
6420    
6421                                    QueryPos qPos = QueryPos.getInstance(q);
6422    
6423                                    qPos.add(companyId);
6424    
6425                                    if (name != null) {
6426                                            qPos.add(name);
6427                                    }
6428    
6429                                    qPos.add(scope);
6430    
6431                                    if (primKey != null) {
6432                                            qPos.add(primKey);
6433                                    }
6434    
6435                                    qPos.add(roleId);
6436    
6437                                    qPos.add(actionIds);
6438    
6439                                    count = (Long)q.uniqueResult();
6440                            }
6441                            catch (Exception e) {
6442                                    throw processException(e);
6443                            }
6444                            finally {
6445                                    if (count == null) {
6446                                            count = Long.valueOf(0);
6447                                    }
6448    
6449                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
6450                                            finderArgs, count);
6451    
6452                                    closeSession(session);
6453                            }
6454                    }
6455    
6456                    return count.intValue();
6457            }
6458    
6459            /**
6460             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = any &#63; and actionIds = &#63;.
6461             *
6462             * @param companyId the company ID
6463             * @param name the name
6464             * @param scope the scope
6465             * @param primKey the prim key
6466             * @param roleIds the role IDs
6467             * @param actionIds the action IDs
6468             * @return the number of matching resource permissions
6469             * @throws SystemException if a system exception occurred
6470             */
6471            public int countByC_N_S_P_R_A(long companyId, String name, int scope,
6472                    String primKey, long[] roleIds, long actionIds)
6473                    throws SystemException {
6474                    Object[] finderArgs = new Object[] {
6475                                    companyId, name, scope, primKey, StringUtil.merge(roleIds),
6476                                    actionIds
6477                            };
6478    
6479                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
6480                                    finderArgs, this);
6481    
6482                    if (count == null) {
6483                            StringBundler query = new StringBundler();
6484    
6485                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6486    
6487                            boolean conjunctionable = false;
6488    
6489                            if (conjunctionable) {
6490                                    query.append(WHERE_AND);
6491                            }
6492    
6493                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_5);
6494    
6495                            conjunctionable = true;
6496    
6497                            if (conjunctionable) {
6498                                    query.append(WHERE_AND);
6499                            }
6500    
6501                            if (name == null) {
6502                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_4);
6503                            }
6504                            else {
6505                                    if (name.equals(StringPool.BLANK)) {
6506                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_6);
6507                                    }
6508                                    else {
6509                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_NAME_5);
6510                                    }
6511                            }
6512    
6513                            conjunctionable = true;
6514    
6515                            if (conjunctionable) {
6516                                    query.append(WHERE_AND);
6517                            }
6518    
6519                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_5);
6520    
6521                            conjunctionable = true;
6522    
6523                            if (conjunctionable) {
6524                                    query.append(WHERE_AND);
6525                            }
6526    
6527                            if (primKey == null) {
6528                                    query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_4);
6529                            }
6530                            else {
6531                                    if (primKey.equals(StringPool.BLANK)) {
6532                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_6);
6533                                    }
6534                                    else {
6535                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_5);
6536                                    }
6537                            }
6538    
6539                            conjunctionable = true;
6540    
6541                            if ((roleIds == null) || (roleIds.length > 0)) {
6542                                    if (conjunctionable) {
6543                                            query.append(WHERE_AND);
6544                                    }
6545    
6546                                    query.append(StringPool.OPEN_PARENTHESIS);
6547    
6548                                    for (int i = 0; i < roleIds.length; i++) {
6549                                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_5);
6550    
6551                                            if ((i + 1) < roleIds.length) {
6552                                                    query.append(WHERE_OR);
6553                                            }
6554                                    }
6555    
6556                                    query.append(StringPool.CLOSE_PARENTHESIS);
6557    
6558                                    conjunctionable = true;
6559                            }
6560    
6561                            if (conjunctionable) {
6562                                    query.append(WHERE_AND);
6563                            }
6564    
6565                            query.append(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_5);
6566    
6567                            conjunctionable = true;
6568    
6569                            String sql = query.toString();
6570    
6571                            Session session = null;
6572    
6573                            try {
6574                                    session = openSession();
6575    
6576                                    Query q = session.createQuery(sql);
6577    
6578                                    QueryPos qPos = QueryPos.getInstance(q);
6579    
6580                                    qPos.add(companyId);
6581    
6582                                    if (name != null) {
6583                                            qPos.add(name);
6584                                    }
6585    
6586                                    qPos.add(scope);
6587    
6588                                    if (primKey != null) {
6589                                            qPos.add(primKey);
6590                                    }
6591    
6592                                    if (roleIds != null) {
6593                                            qPos.add(roleIds);
6594                                    }
6595    
6596                                    qPos.add(actionIds);
6597    
6598                                    count = (Long)q.uniqueResult();
6599                            }
6600                            catch (Exception e) {
6601                                    throw processException(e);
6602                            }
6603                            finally {
6604                                    if (count == null) {
6605                                            count = Long.valueOf(0);
6606                                    }
6607    
6608                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_A,
6609                                            finderArgs, count);
6610    
6611                                    closeSession(session);
6612                            }
6613                    }
6614    
6615                    return count.intValue();
6616            }
6617    
6618            /**
6619             * Returns the number of resource permissions where companyId = &#63; and name = &#63; and scope = &#63; and primKey = &#63; and roleId = &#63; and ownerId = &#63; and actionIds = &#63;.
6620             *
6621             * @param companyId the company ID
6622             * @param name the name
6623             * @param scope the scope
6624             * @param primKey the prim key
6625             * @param roleId the role ID
6626             * @param ownerId the owner ID
6627             * @param actionIds the action IDs
6628             * @return the number of matching resource permissions
6629             * @throws SystemException if a system exception occurred
6630             */
6631            public int countByC_N_S_P_R_O_A(long companyId, String name, int scope,
6632                    String primKey, long roleId, long ownerId, long actionIds)
6633                    throws SystemException {
6634                    Object[] finderArgs = new Object[] {
6635                                    companyId, name, scope, primKey, roleId, ownerId, actionIds
6636                            };
6637    
6638                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A,
6639                                    finderArgs, this);
6640    
6641                    if (count == null) {
6642                            StringBundler query = new StringBundler(8);
6643    
6644                            query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
6645    
6646                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_COMPANYID_2);
6647    
6648                            if (name == null) {
6649                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_1);
6650                            }
6651                            else {
6652                                    if (name.equals(StringPool.BLANK)) {
6653                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_3);
6654                                    }
6655                                    else {
6656                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_NAME_2);
6657                                    }
6658                            }
6659    
6660                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_SCOPE_2);
6661    
6662                            if (primKey == null) {
6663                                    query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_1);
6664                            }
6665                            else {
6666                                    if (primKey.equals(StringPool.BLANK)) {
6667                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_3);
6668                                    }
6669                                    else {
6670                                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_2);
6671                                    }
6672                            }
6673    
6674                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ROLEID_2);
6675    
6676                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_OWNERID_2);
6677    
6678                            query.append(_FINDER_COLUMN_C_N_S_P_R_O_A_ACTIONIDS_2);
6679    
6680                            String sql = query.toString();
6681    
6682                            Session session = null;
6683    
6684                            try {
6685                                    session = openSession();
6686    
6687                                    Query q = session.createQuery(sql);
6688    
6689                                    QueryPos qPos = QueryPos.getInstance(q);
6690    
6691                                    qPos.add(companyId);
6692    
6693                                    if (name != null) {
6694                                            qPos.add(name);
6695                                    }
6696    
6697                                    qPos.add(scope);
6698    
6699                                    if (primKey != null) {
6700                                            qPos.add(primKey);
6701                                    }
6702    
6703                                    qPos.add(roleId);
6704    
6705                                    qPos.add(ownerId);
6706    
6707                                    qPos.add(actionIds);
6708    
6709                                    count = (Long)q.uniqueResult();
6710                            }
6711                            catch (Exception e) {
6712                                    throw processException(e);
6713                            }
6714                            finally {
6715                                    if (count == null) {
6716                                            count = Long.valueOf(0);
6717                                    }
6718    
6719                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R_O_A,
6720                                            finderArgs, count);
6721    
6722                                    closeSession(session);
6723                            }
6724                    }
6725    
6726                    return count.intValue();
6727            }
6728    
6729            /**
6730             * Returns the number of resource permissions.
6731             *
6732             * @return the number of resource permissions
6733             * @throws SystemException if a system exception occurred
6734             */
6735            public int countAll() throws SystemException {
6736                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
6737                                    FINDER_ARGS_EMPTY, this);
6738    
6739                    if (count == null) {
6740                            Session session = null;
6741    
6742                            try {
6743                                    session = openSession();
6744    
6745                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEPERMISSION);
6746    
6747                                    count = (Long)q.uniqueResult();
6748                            }
6749                            catch (Exception e) {
6750                                    throw processException(e);
6751                            }
6752                            finally {
6753                                    if (count == null) {
6754                                            count = Long.valueOf(0);
6755                                    }
6756    
6757                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
6758                                            FINDER_ARGS_EMPTY, count);
6759    
6760                                    closeSession(session);
6761                            }
6762                    }
6763    
6764                    return count.intValue();
6765            }
6766    
6767            /**
6768             * Initializes the resource permission persistence.
6769             */
6770            public void afterPropertiesSet() {
6771                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
6772                                            com.liferay.portal.util.PropsUtil.get(
6773                                                    "value.object.listener.com.liferay.portal.model.ResourcePermission")));
6774    
6775                    if (listenerClassNames.length > 0) {
6776                            try {
6777                                    List<ModelListener<ResourcePermission>> listenersList = new ArrayList<ModelListener<ResourcePermission>>();
6778    
6779                                    for (String listenerClassName : listenerClassNames) {
6780                                            listenersList.add((ModelListener<ResourcePermission>)InstanceFactory.newInstance(
6781                                                            listenerClassName));
6782                                    }
6783    
6784                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
6785                            }
6786                            catch (Exception e) {
6787                                    _log.error(e);
6788                            }
6789                    }
6790            }
6791    
6792            public void destroy() {
6793                    EntityCacheUtil.removeCache(ResourcePermissionImpl.class.getName());
6794                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
6795                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
6796            }
6797    
6798            @BeanReference(type = AccountPersistence.class)
6799            protected AccountPersistence accountPersistence;
6800            @BeanReference(type = AddressPersistence.class)
6801            protected AddressPersistence addressPersistence;
6802            @BeanReference(type = BrowserTrackerPersistence.class)
6803            protected BrowserTrackerPersistence browserTrackerPersistence;
6804            @BeanReference(type = ClassNamePersistence.class)
6805            protected ClassNamePersistence classNamePersistence;
6806            @BeanReference(type = ClusterGroupPersistence.class)
6807            protected ClusterGroupPersistence clusterGroupPersistence;
6808            @BeanReference(type = CompanyPersistence.class)
6809            protected CompanyPersistence companyPersistence;
6810            @BeanReference(type = ContactPersistence.class)
6811            protected ContactPersistence contactPersistence;
6812            @BeanReference(type = CountryPersistence.class)
6813            protected CountryPersistence countryPersistence;
6814            @BeanReference(type = EmailAddressPersistence.class)
6815            protected EmailAddressPersistence emailAddressPersistence;
6816            @BeanReference(type = GroupPersistence.class)
6817            protected GroupPersistence groupPersistence;
6818            @BeanReference(type = ImagePersistence.class)
6819            protected ImagePersistence imagePersistence;
6820            @BeanReference(type = LayoutPersistence.class)
6821            protected LayoutPersistence layoutPersistence;
6822            @BeanReference(type = LayoutBranchPersistence.class)
6823            protected LayoutBranchPersistence layoutBranchPersistence;
6824            @BeanReference(type = LayoutPrototypePersistence.class)
6825            protected LayoutPrototypePersistence layoutPrototypePersistence;
6826            @BeanReference(type = LayoutRevisionPersistence.class)
6827            protected LayoutRevisionPersistence layoutRevisionPersistence;
6828            @BeanReference(type = LayoutSetPersistence.class)
6829            protected LayoutSetPersistence layoutSetPersistence;
6830            @BeanReference(type = LayoutSetBranchPersistence.class)
6831            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
6832            @BeanReference(type = LayoutSetPrototypePersistence.class)
6833            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
6834            @BeanReference(type = ListTypePersistence.class)
6835            protected ListTypePersistence listTypePersistence;
6836            @BeanReference(type = LockPersistence.class)
6837            protected LockPersistence lockPersistence;
6838            @BeanReference(type = MembershipRequestPersistence.class)
6839            protected MembershipRequestPersistence membershipRequestPersistence;
6840            @BeanReference(type = OrganizationPersistence.class)
6841            protected OrganizationPersistence organizationPersistence;
6842            @BeanReference(type = OrgGroupPermissionPersistence.class)
6843            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
6844            @BeanReference(type = OrgGroupRolePersistence.class)
6845            protected OrgGroupRolePersistence orgGroupRolePersistence;
6846            @BeanReference(type = OrgLaborPersistence.class)
6847            protected OrgLaborPersistence orgLaborPersistence;
6848            @BeanReference(type = PasswordPolicyPersistence.class)
6849            protected PasswordPolicyPersistence passwordPolicyPersistence;
6850            @BeanReference(type = PasswordPolicyRelPersistence.class)
6851            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
6852            @BeanReference(type = PasswordTrackerPersistence.class)
6853            protected PasswordTrackerPersistence passwordTrackerPersistence;
6854            @BeanReference(type = PermissionPersistence.class)
6855            protected PermissionPersistence permissionPersistence;
6856            @BeanReference(type = PhonePersistence.class)
6857            protected PhonePersistence phonePersistence;
6858            @BeanReference(type = PluginSettingPersistence.class)
6859            protected PluginSettingPersistence pluginSettingPersistence;
6860            @BeanReference(type = PortalPreferencesPersistence.class)
6861            protected PortalPreferencesPersistence portalPreferencesPersistence;
6862            @BeanReference(type = PortletPersistence.class)
6863            protected PortletPersistence portletPersistence;
6864            @BeanReference(type = PortletItemPersistence.class)
6865            protected PortletItemPersistence portletItemPersistence;
6866            @BeanReference(type = PortletPreferencesPersistence.class)
6867            protected PortletPreferencesPersistence portletPreferencesPersistence;
6868            @BeanReference(type = RegionPersistence.class)
6869            protected RegionPersistence regionPersistence;
6870            @BeanReference(type = ReleasePersistence.class)
6871            protected ReleasePersistence releasePersistence;
6872            @BeanReference(type = RepositoryPersistence.class)
6873            protected RepositoryPersistence repositoryPersistence;
6874            @BeanReference(type = RepositoryEntryPersistence.class)
6875            protected RepositoryEntryPersistence repositoryEntryPersistence;
6876            @BeanReference(type = ResourcePersistence.class)
6877            protected ResourcePersistence resourcePersistence;
6878            @BeanReference(type = ResourceActionPersistence.class)
6879            protected ResourceActionPersistence resourceActionPersistence;
6880            @BeanReference(type = ResourceBlockPersistence.class)
6881            protected ResourceBlockPersistence resourceBlockPersistence;
6882            @BeanReference(type = ResourceBlockPermissionPersistence.class)
6883            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
6884            @BeanReference(type = ResourceCodePersistence.class)
6885            protected ResourceCodePersistence resourceCodePersistence;
6886            @BeanReference(type = ResourcePermissionPersistence.class)
6887            protected ResourcePermissionPersistence resourcePermissionPersistence;
6888            @BeanReference(type = ResourceTypePermissionPersistence.class)
6889            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
6890            @BeanReference(type = RolePersistence.class)
6891            protected RolePersistence rolePersistence;
6892            @BeanReference(type = ServiceComponentPersistence.class)
6893            protected ServiceComponentPersistence serviceComponentPersistence;
6894            @BeanReference(type = ShardPersistence.class)
6895            protected ShardPersistence shardPersistence;
6896            @BeanReference(type = SubscriptionPersistence.class)
6897            protected SubscriptionPersistence subscriptionPersistence;
6898            @BeanReference(type = TeamPersistence.class)
6899            protected TeamPersistence teamPersistence;
6900            @BeanReference(type = TicketPersistence.class)
6901            protected TicketPersistence ticketPersistence;
6902            @BeanReference(type = UserPersistence.class)
6903            protected UserPersistence userPersistence;
6904            @BeanReference(type = UserGroupPersistence.class)
6905            protected UserGroupPersistence userGroupPersistence;
6906            @BeanReference(type = UserGroupGroupRolePersistence.class)
6907            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
6908            @BeanReference(type = UserGroupRolePersistence.class)
6909            protected UserGroupRolePersistence userGroupRolePersistence;
6910            @BeanReference(type = UserIdMapperPersistence.class)
6911            protected UserIdMapperPersistence userIdMapperPersistence;
6912            @BeanReference(type = UserNotificationEventPersistence.class)
6913            protected UserNotificationEventPersistence userNotificationEventPersistence;
6914            @BeanReference(type = UserTrackerPersistence.class)
6915            protected UserTrackerPersistence userTrackerPersistence;
6916            @BeanReference(type = UserTrackerPathPersistence.class)
6917            protected UserTrackerPathPersistence userTrackerPathPersistence;
6918            @BeanReference(type = VirtualHostPersistence.class)
6919            protected VirtualHostPersistence virtualHostPersistence;
6920            @BeanReference(type = WebDAVPropsPersistence.class)
6921            protected WebDAVPropsPersistence webDAVPropsPersistence;
6922            @BeanReference(type = WebsitePersistence.class)
6923            protected WebsitePersistence websitePersistence;
6924            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
6925            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
6926            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
6927            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
6928            private static final String _SQL_SELECT_RESOURCEPERMISSION = "SELECT resourcePermission FROM ResourcePermission resourcePermission";
6929            private static final String _SQL_SELECT_RESOURCEPERMISSION_WHERE = "SELECT resourcePermission FROM ResourcePermission resourcePermission WHERE ";
6930            private static final String _SQL_COUNT_RESOURCEPERMISSION = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission";
6931            private static final String _SQL_COUNT_RESOURCEPERMISSION_WHERE = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission WHERE ";
6932            private static final String _FINDER_COLUMN_SCOPE_SCOPE_2 = "resourcePermission.scope = ?";
6933            private static final String _FINDER_COLUMN_SCOPE_SCOPE_5 = "(" +
6934                    _removeConjunction(_FINDER_COLUMN_SCOPE_SCOPE_2) + ")";
6935            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourcePermission.roleId = ?";
6936            private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6937            private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourcePermission.name IS NULL AND ";
6938            private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourcePermission.name = ? AND ";
6939            private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6940            private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourcePermission.scope = ?";
6941            private static final String _FINDER_COLUMN_C_N_S_P_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6942            private static final String _FINDER_COLUMN_C_N_S_P_NAME_1 = "resourcePermission.name IS NULL AND ";
6943            private static final String _FINDER_COLUMN_C_N_S_P_NAME_2 = "resourcePermission.name = ? AND ";
6944            private static final String _FINDER_COLUMN_C_N_S_P_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6945            private static final String _FINDER_COLUMN_C_N_S_P_SCOPE_2 = "resourcePermission.scope = ? AND ";
6946            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_1 = "resourcePermission.primKey IS NULL";
6947            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_2 = "resourcePermission.primKey = ?";
6948            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?)";
6949            private static final String _FINDER_COLUMN_C_N_P_O_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6950            private static final String _FINDER_COLUMN_C_N_P_O_NAME_1 = "resourcePermission.name IS NULL AND ";
6951            private static final String _FINDER_COLUMN_C_N_P_O_NAME_2 = "resourcePermission.name = ? AND ";
6952            private static final String _FINDER_COLUMN_C_N_P_O_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6953            private static final String _FINDER_COLUMN_C_N_P_O_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
6954            private static final String _FINDER_COLUMN_C_N_P_O_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
6955            private static final String _FINDER_COLUMN_C_N_P_O_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
6956            private static final String _FINDER_COLUMN_C_N_P_O_OWNERID_2 = "resourcePermission.ownerId = ?";
6957            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6958            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_5 = "(" +
6959                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2) + ")";
6960            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_1 = "resourcePermission.name IS NULL AND ";
6961            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_2 = "resourcePermission.name = ? AND ";
6962            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6963            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_4 = "(" +
6964                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_NAME_1) + ")";
6965            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_5 = "(" +
6966                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_NAME_2) + ")";
6967            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_6 = "(" +
6968                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_NAME_3) + ")";
6969            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_2 = "resourcePermission.scope = ? AND ";
6970            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_5 = "(" +
6971                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2) + ")";
6972            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
6973            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
6974            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
6975            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_4 = "(" +
6976                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1) + ")";
6977            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_5 = "(" +
6978                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2) + ")";
6979            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_6 = "(" +
6980                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3) + ")";
6981            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_2 = "resourcePermission.roleId = ?";
6982            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_5 = "(" +
6983                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2) + ")";
6984            private static final String _FINDER_COLUMN_C_N_P_R_A_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6985            private static final String _FINDER_COLUMN_C_N_P_R_A_NAME_1 = "resourcePermission.name IS NULL AND ";
6986            private static final String _FINDER_COLUMN_C_N_P_R_A_NAME_2 = "resourcePermission.name = ? AND ";
6987            private static final String _FINDER_COLUMN_C_N_P_R_A_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6988            private static final String _FINDER_COLUMN_C_N_P_R_A_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
6989            private static final String _FINDER_COLUMN_C_N_P_R_A_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
6990            private static final String _FINDER_COLUMN_C_N_P_R_A_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
6991            private static final String _FINDER_COLUMN_C_N_P_R_A_ROLEID_2 = "resourcePermission.roleId = ? AND ";
6992            private static final String _FINDER_COLUMN_C_N_P_R_A_ACTIONIDS_2 = "resourcePermission.actionIds = ?";
6993            private static final String _FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
6994            private static final String _FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_5 = "(" +
6995                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_COMPANYID_2) + ")";
6996            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_1 = "resourcePermission.name IS NULL AND ";
6997            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_2 = "resourcePermission.name = ? AND ";
6998            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
6999            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_4 = "(" +
7000                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_NAME_1) + ")";
7001            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_5 = "(" +
7002                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_NAME_2) + ")";
7003            private static final String _FINDER_COLUMN_C_N_S_P_R_A_NAME_6 = "(" +
7004                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_NAME_3) + ")";
7005            private static final String _FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2 = "resourcePermission.scope = ? AND ";
7006            private static final String _FINDER_COLUMN_C_N_S_P_R_A_SCOPE_5 = "(" +
7007                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_SCOPE_2) + ")";
7008            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
7009            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
7010            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
7011            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_4 = "(" +
7012                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_1) + ")";
7013            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_5 = "(" +
7014                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_2) + ")";
7015            private static final String _FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_6 = "(" +
7016                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_PRIMKEY_3) + ")";
7017            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2 = "resourcePermission.roleId = ? AND ";
7018            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ROLEID_5 = "(" +
7019                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_ROLEID_2) + ")";
7020            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2 = "resourcePermission.actionIds = ?";
7021            private static final String _FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_5 = "(" +
7022                    _removeConjunction(_FINDER_COLUMN_C_N_S_P_R_A_ACTIONIDS_2) + ")";
7023            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
7024            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_NAME_1 = "resourcePermission.name IS NULL AND ";
7025            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_NAME_2 = "resourcePermission.name = ? AND ";
7026            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
7027            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_SCOPE_2 = "resourcePermission.scope = ? AND ";
7028            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
7029            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
7030            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
7031            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_ROLEID_2 = "resourcePermission.roleId = ? AND ";
7032            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_OWNERID_2 = "resourcePermission.ownerId = ? AND ";
7033            private static final String _FINDER_COLUMN_C_N_S_P_R_O_A_ACTIONIDS_2 = "resourcePermission.actionIds = ?";
7034    
7035            private static String _removeConjunction(String sql) {
7036                    int pos = sql.indexOf(" AND ");
7037    
7038                    if (pos != -1) {
7039                            sql = sql.substring(0, pos);
7040                    }
7041    
7042                    return sql;
7043            }
7044    
7045            private static final String _ORDER_BY_ENTITY_ALIAS = "resourcePermission.";
7046            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourcePermission exists with the primary key ";
7047            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourcePermission exists with the key {";
7048            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7049            private static Log _log = LogFactoryUtil.getLog(ResourcePermissionPersistenceImpl.class);
7050            private static ResourcePermission _nullResourcePermission = new ResourcePermissionImpl() {
7051                            @Override
7052                            public Object clone() {
7053                                    return this;
7054                            }
7055    
7056                            @Override
7057                            public CacheModel<ResourcePermission> toCacheModel() {
7058                                    return _nullResourcePermissionCacheModel;
7059                            }
7060                    };
7061    
7062            private static CacheModel<ResourcePermission> _nullResourcePermissionCacheModel =
7063                    new CacheModel<ResourcePermission>() {
7064                            public ResourcePermission toEntityModel() {
7065                                    return _nullResourcePermission;
7066                            }
7067                    };
7068    }