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