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