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