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