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