001    /**
002     * Copyright (c) 2000-2010 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.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.ResourcePermission;
040    import com.liferay.portal.model.impl.ResourcePermissionImpl;
041    import com.liferay.portal.model.impl.ResourcePermissionModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * @author    Brian Wing Shun Chan
052     * @see       ResourcePermissionPersistence
053     * @see       ResourcePermissionUtil
054     * @generated
055     */
056    public class ResourcePermissionPersistenceImpl extends BasePersistenceImpl<ResourcePermission>
057            implements ResourcePermissionPersistence {
058            public static final String FINDER_CLASS_NAME_ENTITY = ResourcePermissionImpl.class.getName();
059            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
060                    ".List";
061            public static final FinderPath FINDER_PATH_FIND_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
062                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
063                            FINDER_CLASS_NAME_LIST, "findByRoleId",
064                            new String[] {
065                                    Long.class.getName(),
066                                    
067                            "java.lang.Integer", "java.lang.Integer",
068                                    "com.liferay.portal.kernel.util.OrderByComparator"
069                            });
070            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
071                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
072                            FINDER_CLASS_NAME_LIST, "countByRoleId",
073                            new String[] { Long.class.getName() });
074            public static final FinderPath FINDER_PATH_FIND_BY_R_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
075                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "findByR_S",
077                            new String[] {
078                                    Long.class.getName(), Integer.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_R_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
084                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "countByR_S",
086                            new String[] { Long.class.getName(), Integer.class.getName() });
087            public static final FinderPath FINDER_PATH_FIND_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
088                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
089                            FINDER_CLASS_NAME_LIST, "findByC_N_S",
090                            new String[] {
091                                    Long.class.getName(), String.class.getName(),
092                                    Integer.class.getName(),
093                                    
094                            "java.lang.Integer", "java.lang.Integer",
095                                    "com.liferay.portal.kernel.util.OrderByComparator"
096                            });
097            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
098                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
099                            FINDER_CLASS_NAME_LIST, "countByC_N_S",
100                            new String[] {
101                                    Long.class.getName(), String.class.getName(),
102                                    Integer.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_FIND_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
105                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
106                            FINDER_CLASS_NAME_LIST, "findByC_N_S_P",
107                            new String[] {
108                                    Long.class.getName(), String.class.getName(),
109                                    Integer.class.getName(), String.class.getName(),
110                                    
111                            "java.lang.Integer", "java.lang.Integer",
112                                    "com.liferay.portal.kernel.util.OrderByComparator"
113                            });
114            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
115                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
116                            FINDER_CLASS_NAME_LIST, "countByC_N_S_P",
117                            new String[] {
118                                    Long.class.getName(), String.class.getName(),
119                                    Integer.class.getName(), String.class.getName()
120                            });
121            public static final FinderPath FINDER_PATH_FETCH_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
122                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
123                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N_S_P_R",
124                            new String[] {
125                                    Long.class.getName(), String.class.getName(),
126                                    Integer.class.getName(), String.class.getName(),
127                                    Long.class.getName()
128                            });
129            public static final FinderPath FINDER_PATH_COUNT_BY_C_N_S_P_R = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
130                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
131                            FINDER_CLASS_NAME_LIST, "countByC_N_S_P_R",
132                            new String[] {
133                                    Long.class.getName(), String.class.getName(),
134                                    Integer.class.getName(), String.class.getName(),
135                                    Long.class.getName()
136                            });
137            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
138                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
139                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
140            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
141                            ResourcePermissionModelImpl.FINDER_CACHE_ENABLED,
142                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
143    
144            public void cacheResult(ResourcePermission resourcePermission) {
145                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
146                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
147                            resourcePermission);
148    
149                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
150                            new Object[] {
151                                    new Long(resourcePermission.getCompanyId()),
152                                    
153                            resourcePermission.getName(),
154                                    new Integer(resourcePermission.getScope()),
155                                    
156                            resourcePermission.getPrimKey(),
157                                    new Long(resourcePermission.getRoleId())
158                            }, resourcePermission);
159            }
160    
161            public void cacheResult(List<ResourcePermission> resourcePermissions) {
162                    for (ResourcePermission resourcePermission : resourcePermissions) {
163                            if (EntityCacheUtil.getResult(
164                                                    ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
165                                                    ResourcePermissionImpl.class,
166                                                    resourcePermission.getPrimaryKey(), this) == null) {
167                                    cacheResult(resourcePermission);
168                            }
169                    }
170            }
171    
172            public void clearCache() {
173                    CacheRegistryUtil.clear(ResourcePermissionImpl.class.getName());
174                    EntityCacheUtil.clearCache(ResourcePermissionImpl.class.getName());
175                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
177            }
178    
179            public void clearCache(ResourcePermission resourcePermission) {
180                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
181                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
182    
183                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
184                            new Object[] {
185                                    new Long(resourcePermission.getCompanyId()),
186                                    
187                            resourcePermission.getName(),
188                                    new Integer(resourcePermission.getScope()),
189                                    
190                            resourcePermission.getPrimKey(),
191                                    new Long(resourcePermission.getRoleId())
192                            });
193            }
194    
195            public ResourcePermission create(long resourcePermissionId) {
196                    ResourcePermission resourcePermission = new ResourcePermissionImpl();
197    
198                    resourcePermission.setNew(true);
199                    resourcePermission.setPrimaryKey(resourcePermissionId);
200    
201                    return resourcePermission;
202            }
203    
204            public ResourcePermission remove(Serializable primaryKey)
205                    throws NoSuchModelException, SystemException {
206                    return remove(((Long)primaryKey).longValue());
207            }
208    
209            public ResourcePermission remove(long resourcePermissionId)
210                    throws NoSuchResourcePermissionException, SystemException {
211                    Session session = null;
212    
213                    try {
214                            session = openSession();
215    
216                            ResourcePermission resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
217                                            new Long(resourcePermissionId));
218    
219                            if (resourcePermission == null) {
220                                    if (_log.isWarnEnabled()) {
221                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
222                                                    resourcePermissionId);
223                                    }
224    
225                                    throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
226                                            resourcePermissionId);
227                            }
228    
229                            return remove(resourcePermission);
230                    }
231                    catch (NoSuchResourcePermissionException nsee) {
232                            throw nsee;
233                    }
234                    catch (Exception e) {
235                            throw processException(e);
236                    }
237                    finally {
238                            closeSession(session);
239                    }
240            }
241    
242            protected ResourcePermission removeImpl(
243                    ResourcePermission resourcePermission) throws SystemException {
244                    resourcePermission = toUnwrappedModel(resourcePermission);
245    
246                    Session session = null;
247    
248                    try {
249                            session = openSession();
250    
251                            if (resourcePermission.isCachedModel() ||
252                                            BatchSessionUtil.isEnabled()) {
253                                    Object staleObject = session.get(ResourcePermissionImpl.class,
254                                                    resourcePermission.getPrimaryKeyObj());
255    
256                                    if (staleObject != null) {
257                                            session.evict(staleObject);
258                                    }
259                            }
260    
261                            session.delete(resourcePermission);
262    
263                            session.flush();
264                    }
265                    catch (Exception e) {
266                            throw processException(e);
267                    }
268                    finally {
269                            closeSession(session);
270                    }
271    
272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273    
274                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
275    
276                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
277                            new Object[] {
278                                    new Long(resourcePermissionModelImpl.getOriginalCompanyId()),
279                                    
280                            resourcePermissionModelImpl.getOriginalName(),
281                                    new Integer(resourcePermissionModelImpl.getOriginalScope()),
282                                    
283                            resourcePermissionModelImpl.getOriginalPrimKey(),
284                                    new Long(resourcePermissionModelImpl.getOriginalRoleId())
285                            });
286    
287                    EntityCacheUtil.removeResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
288                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey());
289    
290                    return resourcePermission;
291            }
292    
293            public ResourcePermission updateImpl(
294                    com.liferay.portal.model.ResourcePermission resourcePermission,
295                    boolean merge) throws SystemException {
296                    resourcePermission = toUnwrappedModel(resourcePermission);
297    
298                    boolean isNew = resourcePermission.isNew();
299    
300                    ResourcePermissionModelImpl resourcePermissionModelImpl = (ResourcePermissionModelImpl)resourcePermission;
301    
302                    Session session = null;
303    
304                    try {
305                            session = openSession();
306    
307                            BatchSessionUtil.update(session, resourcePermission, merge);
308    
309                            resourcePermission.setNew(false);
310                    }
311                    catch (Exception e) {
312                            throw processException(e);
313                    }
314                    finally {
315                            closeSession(session);
316                    }
317    
318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
319    
320                    EntityCacheUtil.putResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
321                            ResourcePermissionImpl.class, resourcePermission.getPrimaryKey(),
322                            resourcePermission);
323    
324                    if (!isNew &&
325                                    ((resourcePermission.getCompanyId() != resourcePermissionModelImpl.getOriginalCompanyId()) ||
326                                    !Validator.equals(resourcePermission.getName(),
327                                            resourcePermissionModelImpl.getOriginalName()) ||
328                                    (resourcePermission.getScope() != resourcePermissionModelImpl.getOriginalScope()) ||
329                                    !Validator.equals(resourcePermission.getPrimKey(),
330                                            resourcePermissionModelImpl.getOriginalPrimKey()) ||
331                                    (resourcePermission.getRoleId() != resourcePermissionModelImpl.getOriginalRoleId()))) {
332                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
333                                    new Object[] {
334                                            new Long(resourcePermissionModelImpl.getOriginalCompanyId()),
335                                            
336                                    resourcePermissionModelImpl.getOriginalName(),
337                                            new Integer(resourcePermissionModelImpl.getOriginalScope()),
338                                            
339                                    resourcePermissionModelImpl.getOriginalPrimKey(),
340                                            new Long(resourcePermissionModelImpl.getOriginalRoleId())
341                                    });
342                    }
343    
344                    if (isNew ||
345                                    ((resourcePermission.getCompanyId() != resourcePermissionModelImpl.getOriginalCompanyId()) ||
346                                    !Validator.equals(resourcePermission.getName(),
347                                            resourcePermissionModelImpl.getOriginalName()) ||
348                                    (resourcePermission.getScope() != resourcePermissionModelImpl.getOriginalScope()) ||
349                                    !Validator.equals(resourcePermission.getPrimKey(),
350                                            resourcePermissionModelImpl.getOriginalPrimKey()) ||
351                                    (resourcePermission.getRoleId() != resourcePermissionModelImpl.getOriginalRoleId()))) {
352                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
353                                    new Object[] {
354                                            new Long(resourcePermission.getCompanyId()),
355                                            
356                                    resourcePermission.getName(),
357                                            new Integer(resourcePermission.getScope()),
358                                            
359                                    resourcePermission.getPrimKey(),
360                                            new Long(resourcePermission.getRoleId())
361                                    }, resourcePermission);
362                    }
363    
364                    return resourcePermission;
365            }
366    
367            protected ResourcePermission toUnwrappedModel(
368                    ResourcePermission resourcePermission) {
369                    if (resourcePermission instanceof ResourcePermissionImpl) {
370                            return resourcePermission;
371                    }
372    
373                    ResourcePermissionImpl resourcePermissionImpl = new ResourcePermissionImpl();
374    
375                    resourcePermissionImpl.setNew(resourcePermission.isNew());
376                    resourcePermissionImpl.setPrimaryKey(resourcePermission.getPrimaryKey());
377    
378                    resourcePermissionImpl.setResourcePermissionId(resourcePermission.getResourcePermissionId());
379                    resourcePermissionImpl.setCompanyId(resourcePermission.getCompanyId());
380                    resourcePermissionImpl.setName(resourcePermission.getName());
381                    resourcePermissionImpl.setScope(resourcePermission.getScope());
382                    resourcePermissionImpl.setPrimKey(resourcePermission.getPrimKey());
383                    resourcePermissionImpl.setRoleId(resourcePermission.getRoleId());
384                    resourcePermissionImpl.setActionIds(resourcePermission.getActionIds());
385    
386                    return resourcePermissionImpl;
387            }
388    
389            public ResourcePermission findByPrimaryKey(Serializable primaryKey)
390                    throws NoSuchModelException, SystemException {
391                    return findByPrimaryKey(((Long)primaryKey).longValue());
392            }
393    
394            public ResourcePermission findByPrimaryKey(long resourcePermissionId)
395                    throws NoSuchResourcePermissionException, SystemException {
396                    ResourcePermission resourcePermission = fetchByPrimaryKey(resourcePermissionId);
397    
398                    if (resourcePermission == null) {
399                            if (_log.isWarnEnabled()) {
400                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
401                                            resourcePermissionId);
402                            }
403    
404                            throw new NoSuchResourcePermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
405                                    resourcePermissionId);
406                    }
407    
408                    return resourcePermission;
409            }
410    
411            public ResourcePermission fetchByPrimaryKey(Serializable primaryKey)
412                    throws SystemException {
413                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
414            }
415    
416            public ResourcePermission fetchByPrimaryKey(long resourcePermissionId)
417                    throws SystemException {
418                    ResourcePermission resourcePermission = (ResourcePermission)EntityCacheUtil.getResult(ResourcePermissionModelImpl.ENTITY_CACHE_ENABLED,
419                                    ResourcePermissionImpl.class, resourcePermissionId, this);
420    
421                    if (resourcePermission == null) {
422                            Session session = null;
423    
424                            try {
425                                    session = openSession();
426    
427                                    resourcePermission = (ResourcePermission)session.get(ResourcePermissionImpl.class,
428                                                    new Long(resourcePermissionId));
429                            }
430                            catch (Exception e) {
431                                    throw processException(e);
432                            }
433                            finally {
434                                    if (resourcePermission != null) {
435                                            cacheResult(resourcePermission);
436                                    }
437    
438                                    closeSession(session);
439                            }
440                    }
441    
442                    return resourcePermission;
443            }
444    
445            public List<ResourcePermission> findByRoleId(long roleId)
446                    throws SystemException {
447                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
448            }
449    
450            public List<ResourcePermission> findByRoleId(long roleId, int start, int end)
451                    throws SystemException {
452                    return findByRoleId(roleId, start, end, null);
453            }
454    
455            public List<ResourcePermission> findByRoleId(long roleId, int start,
456                    int end, OrderByComparator orderByComparator) throws SystemException {
457                    Object[] finderArgs = new Object[] {
458                                    roleId,
459                                    
460                                    String.valueOf(start), String.valueOf(end),
461                                    String.valueOf(orderByComparator)
462                            };
463    
464                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_ROLEID,
465                                    finderArgs, this);
466    
467                    if (list == null) {
468                            Session session = null;
469    
470                            try {
471                                    session = openSession();
472    
473                                    StringBundler query = null;
474    
475                                    if (orderByComparator != null) {
476                                            query = new StringBundler(3 +
477                                                            (orderByComparator.getOrderByFields().length * 3));
478                                    }
479                                    else {
480                                            query = new StringBundler(2);
481                                    }
482    
483                                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
484    
485                                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
486    
487                                    if (orderByComparator != null) {
488                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
489                                                    orderByComparator);
490                                    }
491    
492                                    String sql = query.toString();
493    
494                                    Query q = session.createQuery(sql);
495    
496                                    QueryPos qPos = QueryPos.getInstance(q);
497    
498                                    qPos.add(roleId);
499    
500                                    list = (List<ResourcePermission>)QueryUtil.list(q,
501                                                    getDialect(), start, end);
502                            }
503                            catch (Exception e) {
504                                    throw processException(e);
505                            }
506                            finally {
507                                    if (list == null) {
508                                            list = new ArrayList<ResourcePermission>();
509                                    }
510    
511                                    cacheResult(list);
512    
513                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_ROLEID,
514                                            finderArgs, list);
515    
516                                    closeSession(session);
517                            }
518                    }
519    
520                    return list;
521            }
522    
523            public ResourcePermission findByRoleId_First(long roleId,
524                    OrderByComparator orderByComparator)
525                    throws NoSuchResourcePermissionException, SystemException {
526                    List<ResourcePermission> list = findByRoleId(roleId, 0, 1,
527                                    orderByComparator);
528    
529                    if (list.isEmpty()) {
530                            StringBundler msg = new StringBundler(4);
531    
532                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
533    
534                            msg.append("roleId=");
535                            msg.append(roleId);
536    
537                            msg.append(StringPool.CLOSE_CURLY_BRACE);
538    
539                            throw new NoSuchResourcePermissionException(msg.toString());
540                    }
541                    else {
542                            return list.get(0);
543                    }
544            }
545    
546            public ResourcePermission findByRoleId_Last(long roleId,
547                    OrderByComparator orderByComparator)
548                    throws NoSuchResourcePermissionException, SystemException {
549                    int count = countByRoleId(roleId);
550    
551                    List<ResourcePermission> list = findByRoleId(roleId, count - 1, count,
552                                    orderByComparator);
553    
554                    if (list.isEmpty()) {
555                            StringBundler msg = new StringBundler(4);
556    
557                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
558    
559                            msg.append("roleId=");
560                            msg.append(roleId);
561    
562                            msg.append(StringPool.CLOSE_CURLY_BRACE);
563    
564                            throw new NoSuchResourcePermissionException(msg.toString());
565                    }
566                    else {
567                            return list.get(0);
568                    }
569            }
570    
571            public ResourcePermission[] findByRoleId_PrevAndNext(
572                    long resourcePermissionId, long roleId,
573                    OrderByComparator orderByComparator)
574                    throws NoSuchResourcePermissionException, SystemException {
575                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
576    
577                    Session session = null;
578    
579                    try {
580                            session = openSession();
581    
582                            ResourcePermission[] array = new ResourcePermissionImpl[3];
583    
584                            array[0] = getByRoleId_PrevAndNext(session, resourcePermission,
585                                            roleId, orderByComparator, true);
586    
587                            array[1] = resourcePermission;
588    
589                            array[2] = getByRoleId_PrevAndNext(session, resourcePermission,
590                                            roleId, orderByComparator, false);
591    
592                            return array;
593                    }
594                    catch (Exception e) {
595                            throw processException(e);
596                    }
597                    finally {
598                            closeSession(session);
599                    }
600            }
601    
602            protected ResourcePermission getByRoleId_PrevAndNext(Session session,
603                    ResourcePermission resourcePermission, long roleId,
604                    OrderByComparator orderByComparator, boolean previous) {
605                    StringBundler query = null;
606    
607                    if (orderByComparator != null) {
608                            query = new StringBundler(6 +
609                                            (orderByComparator.getOrderByFields().length * 6));
610                    }
611                    else {
612                            query = new StringBundler(3);
613                    }
614    
615                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
616    
617                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
618    
619                    if (orderByComparator != null) {
620                            String[] orderByFields = orderByComparator.getOrderByFields();
621    
622                            if (orderByFields.length > 0) {
623                                    query.append(WHERE_AND);
624                            }
625    
626                            for (int i = 0; i < orderByFields.length; i++) {
627                                    query.append(_ORDER_BY_ENTITY_ALIAS);
628                                    query.append(orderByFields[i]);
629    
630                                    if ((i + 1) < orderByFields.length) {
631                                            if (orderByComparator.isAscending() ^ previous) {
632                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
633                                            }
634                                            else {
635                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
636                                            }
637                                    }
638                                    else {
639                                            if (orderByComparator.isAscending() ^ previous) {
640                                                    query.append(WHERE_GREATER_THAN);
641                                            }
642                                            else {
643                                                    query.append(WHERE_LESSER_THAN);
644                                            }
645                                    }
646                            }
647    
648                            query.append(ORDER_BY_CLAUSE);
649    
650                            for (int i = 0; i < orderByFields.length; i++) {
651                                    query.append(_ORDER_BY_ENTITY_ALIAS);
652                                    query.append(orderByFields[i]);
653    
654                                    if ((i + 1) < orderByFields.length) {
655                                            if (orderByComparator.isAscending() ^ previous) {
656                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
657                                            }
658                                            else {
659                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
660                                            }
661                                    }
662                                    else {
663                                            if (orderByComparator.isAscending() ^ previous) {
664                                                    query.append(ORDER_BY_ASC);
665                                            }
666                                            else {
667                                                    query.append(ORDER_BY_DESC);
668                                            }
669                                    }
670                            }
671                    }
672    
673                    String sql = query.toString();
674    
675                    Query q = session.createQuery(sql);
676    
677                    q.setFirstResult(0);
678                    q.setMaxResults(2);
679    
680                    QueryPos qPos = QueryPos.getInstance(q);
681    
682                    qPos.add(roleId);
683    
684                    if (orderByComparator != null) {
685                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
686    
687                            for (Object value : values) {
688                                    qPos.add(value);
689                            }
690                    }
691    
692                    List<ResourcePermission> list = q.list();
693    
694                    if (list.size() == 2) {
695                            return list.get(1);
696                    }
697                    else {
698                            return null;
699                    }
700            }
701    
702            public List<ResourcePermission> findByR_S(long roleId, int scope)
703                    throws SystemException {
704                    return findByR_S(roleId, scope, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
705                            null);
706            }
707    
708            public List<ResourcePermission> findByR_S(long roleId, int scope,
709                    int start, int end) throws SystemException {
710                    return findByR_S(roleId, scope, start, end, null);
711            }
712    
713            public List<ResourcePermission> findByR_S(long roleId, int scope,
714                    int start, int end, OrderByComparator orderByComparator)
715                    throws SystemException {
716                    Object[] finderArgs = new Object[] {
717                                    roleId, scope,
718                                    
719                                    String.valueOf(start), String.valueOf(end),
720                                    String.valueOf(orderByComparator)
721                            };
722    
723                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_R_S,
724                                    finderArgs, this);
725    
726                    if (list == null) {
727                            Session session = null;
728    
729                            try {
730                                    session = openSession();
731    
732                                    StringBundler query = null;
733    
734                                    if (orderByComparator != null) {
735                                            query = new StringBundler(4 +
736                                                            (orderByComparator.getOrderByFields().length * 3));
737                                    }
738                                    else {
739                                            query = new StringBundler(3);
740                                    }
741    
742                                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
743    
744                                    query.append(_FINDER_COLUMN_R_S_ROLEID_2);
745    
746                                    query.append(_FINDER_COLUMN_R_S_SCOPE_2);
747    
748                                    if (orderByComparator != null) {
749                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
750                                                    orderByComparator);
751                                    }
752    
753                                    String sql = query.toString();
754    
755                                    Query q = session.createQuery(sql);
756    
757                                    QueryPos qPos = QueryPos.getInstance(q);
758    
759                                    qPos.add(roleId);
760    
761                                    qPos.add(scope);
762    
763                                    list = (List<ResourcePermission>)QueryUtil.list(q,
764                                                    getDialect(), start, end);
765                            }
766                            catch (Exception e) {
767                                    throw processException(e);
768                            }
769                            finally {
770                                    if (list == null) {
771                                            list = new ArrayList<ResourcePermission>();
772                                    }
773    
774                                    cacheResult(list);
775    
776                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_R_S, finderArgs,
777                                            list);
778    
779                                    closeSession(session);
780                            }
781                    }
782    
783                    return list;
784            }
785    
786            public ResourcePermission findByR_S_First(long roleId, int scope,
787                    OrderByComparator orderByComparator)
788                    throws NoSuchResourcePermissionException, SystemException {
789                    List<ResourcePermission> list = findByR_S(roleId, scope, 0, 1,
790                                    orderByComparator);
791    
792                    if (list.isEmpty()) {
793                            StringBundler msg = new StringBundler(6);
794    
795                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
796    
797                            msg.append("roleId=");
798                            msg.append(roleId);
799    
800                            msg.append(", scope=");
801                            msg.append(scope);
802    
803                            msg.append(StringPool.CLOSE_CURLY_BRACE);
804    
805                            throw new NoSuchResourcePermissionException(msg.toString());
806                    }
807                    else {
808                            return list.get(0);
809                    }
810            }
811    
812            public ResourcePermission findByR_S_Last(long roleId, int scope,
813                    OrderByComparator orderByComparator)
814                    throws NoSuchResourcePermissionException, SystemException {
815                    int count = countByR_S(roleId, scope);
816    
817                    List<ResourcePermission> list = findByR_S(roleId, scope, count - 1,
818                                    count, orderByComparator);
819    
820                    if (list.isEmpty()) {
821                            StringBundler msg = new StringBundler(6);
822    
823                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824    
825                            msg.append("roleId=");
826                            msg.append(roleId);
827    
828                            msg.append(", scope=");
829                            msg.append(scope);
830    
831                            msg.append(StringPool.CLOSE_CURLY_BRACE);
832    
833                            throw new NoSuchResourcePermissionException(msg.toString());
834                    }
835                    else {
836                            return list.get(0);
837                    }
838            }
839    
840            public ResourcePermission[] findByR_S_PrevAndNext(
841                    long resourcePermissionId, long roleId, int scope,
842                    OrderByComparator orderByComparator)
843                    throws NoSuchResourcePermissionException, SystemException {
844                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
845    
846                    Session session = null;
847    
848                    try {
849                            session = openSession();
850    
851                            ResourcePermission[] array = new ResourcePermissionImpl[3];
852    
853                            array[0] = getByR_S_PrevAndNext(session, resourcePermission,
854                                            roleId, scope, orderByComparator, true);
855    
856                            array[1] = resourcePermission;
857    
858                            array[2] = getByR_S_PrevAndNext(session, resourcePermission,
859                                            roleId, scope, orderByComparator, false);
860    
861                            return array;
862                    }
863                    catch (Exception e) {
864                            throw processException(e);
865                    }
866                    finally {
867                            closeSession(session);
868                    }
869            }
870    
871            protected ResourcePermission getByR_S_PrevAndNext(Session session,
872                    ResourcePermission resourcePermission, long roleId, int scope,
873                    OrderByComparator orderByComparator, boolean previous) {
874                    StringBundler query = null;
875    
876                    if (orderByComparator != null) {
877                            query = new StringBundler(6 +
878                                            (orderByComparator.getOrderByFields().length * 6));
879                    }
880                    else {
881                            query = new StringBundler(3);
882                    }
883    
884                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
885    
886                    query.append(_FINDER_COLUMN_R_S_ROLEID_2);
887    
888                    query.append(_FINDER_COLUMN_R_S_SCOPE_2);
889    
890                    if (orderByComparator != null) {
891                            String[] orderByFields = orderByComparator.getOrderByFields();
892    
893                            if (orderByFields.length > 0) {
894                                    query.append(WHERE_AND);
895                            }
896    
897                            for (int i = 0; i < orderByFields.length; i++) {
898                                    query.append(_ORDER_BY_ENTITY_ALIAS);
899                                    query.append(orderByFields[i]);
900    
901                                    if ((i + 1) < orderByFields.length) {
902                                            if (orderByComparator.isAscending() ^ previous) {
903                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
904                                            }
905                                            else {
906                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
907                                            }
908                                    }
909                                    else {
910                                            if (orderByComparator.isAscending() ^ previous) {
911                                                    query.append(WHERE_GREATER_THAN);
912                                            }
913                                            else {
914                                                    query.append(WHERE_LESSER_THAN);
915                                            }
916                                    }
917                            }
918    
919                            query.append(ORDER_BY_CLAUSE);
920    
921                            for (int i = 0; i < orderByFields.length; i++) {
922                                    query.append(_ORDER_BY_ENTITY_ALIAS);
923                                    query.append(orderByFields[i]);
924    
925                                    if ((i + 1) < orderByFields.length) {
926                                            if (orderByComparator.isAscending() ^ previous) {
927                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
928                                            }
929                                            else {
930                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
931                                            }
932                                    }
933                                    else {
934                                            if (orderByComparator.isAscending() ^ previous) {
935                                                    query.append(ORDER_BY_ASC);
936                                            }
937                                            else {
938                                                    query.append(ORDER_BY_DESC);
939                                            }
940                                    }
941                            }
942                    }
943    
944                    String sql = query.toString();
945    
946                    Query q = session.createQuery(sql);
947    
948                    q.setFirstResult(0);
949                    q.setMaxResults(2);
950    
951                    QueryPos qPos = QueryPos.getInstance(q);
952    
953                    qPos.add(roleId);
954    
955                    qPos.add(scope);
956    
957                    if (orderByComparator != null) {
958                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
959    
960                            for (Object value : values) {
961                                    qPos.add(value);
962                            }
963                    }
964    
965                    List<ResourcePermission> list = q.list();
966    
967                    if (list.size() == 2) {
968                            return list.get(1);
969                    }
970                    else {
971                            return null;
972                    }
973            }
974    
975            public List<ResourcePermission> findByC_N_S(long companyId, String name,
976                    int scope) throws SystemException {
977                    return findByC_N_S(companyId, name, scope, QueryUtil.ALL_POS,
978                            QueryUtil.ALL_POS, null);
979            }
980    
981            public List<ResourcePermission> findByC_N_S(long companyId, String name,
982                    int scope, int start, int end) throws SystemException {
983                    return findByC_N_S(companyId, name, scope, start, end, null);
984            }
985    
986            public List<ResourcePermission> findByC_N_S(long companyId, String name,
987                    int scope, int start, int end, OrderByComparator orderByComparator)
988                    throws SystemException {
989                    Object[] finderArgs = new Object[] {
990                                    companyId, name, scope,
991                                    
992                                    String.valueOf(start), String.valueOf(end),
993                                    String.valueOf(orderByComparator)
994                            };
995    
996                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_N_S,
997                                    finderArgs, this);
998    
999                    if (list == null) {
1000                            Session session = null;
1001    
1002                            try {
1003                                    session = openSession();
1004    
1005                                    StringBundler query = null;
1006    
1007                                    if (orderByComparator != null) {
1008                                            query = new StringBundler(5 +
1009                                                            (orderByComparator.getOrderByFields().length * 3));
1010                                    }
1011                                    else {
1012                                            query = new StringBundler(4);
1013                                    }
1014    
1015                                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1016    
1017                                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1018    
1019                                    if (name == null) {
1020                                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1021                                    }
1022                                    else {
1023                                            if (name.equals(StringPool.BLANK)) {
1024                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1025                                            }
1026                                            else {
1027                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1028                                            }
1029                                    }
1030    
1031                                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1032    
1033                                    if (orderByComparator != null) {
1034                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1035                                                    orderByComparator);
1036                                    }
1037    
1038                                    String sql = query.toString();
1039    
1040                                    Query q = session.createQuery(sql);
1041    
1042                                    QueryPos qPos = QueryPos.getInstance(q);
1043    
1044                                    qPos.add(companyId);
1045    
1046                                    if (name != null) {
1047                                            qPos.add(name);
1048                                    }
1049    
1050                                    qPos.add(scope);
1051    
1052                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1053                                                    getDialect(), start, end);
1054                            }
1055                            catch (Exception e) {
1056                                    throw processException(e);
1057                            }
1058                            finally {
1059                                    if (list == null) {
1060                                            list = new ArrayList<ResourcePermission>();
1061                                    }
1062    
1063                                    cacheResult(list);
1064    
1065                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_N_S,
1066                                            finderArgs, list);
1067    
1068                                    closeSession(session);
1069                            }
1070                    }
1071    
1072                    return list;
1073            }
1074    
1075            public ResourcePermission findByC_N_S_First(long companyId, String name,
1076                    int scope, OrderByComparator orderByComparator)
1077                    throws NoSuchResourcePermissionException, SystemException {
1078                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope, 0,
1079                                    1, orderByComparator);
1080    
1081                    if (list.isEmpty()) {
1082                            StringBundler msg = new StringBundler(8);
1083    
1084                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1085    
1086                            msg.append("companyId=");
1087                            msg.append(companyId);
1088    
1089                            msg.append(", name=");
1090                            msg.append(name);
1091    
1092                            msg.append(", scope=");
1093                            msg.append(scope);
1094    
1095                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1096    
1097                            throw new NoSuchResourcePermissionException(msg.toString());
1098                    }
1099                    else {
1100                            return list.get(0);
1101                    }
1102            }
1103    
1104            public ResourcePermission findByC_N_S_Last(long companyId, String name,
1105                    int scope, OrderByComparator orderByComparator)
1106                    throws NoSuchResourcePermissionException, SystemException {
1107                    int count = countByC_N_S(companyId, name, scope);
1108    
1109                    List<ResourcePermission> list = findByC_N_S(companyId, name, scope,
1110                                    count - 1, count, orderByComparator);
1111    
1112                    if (list.isEmpty()) {
1113                            StringBundler msg = new StringBundler(8);
1114    
1115                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1116    
1117                            msg.append("companyId=");
1118                            msg.append(companyId);
1119    
1120                            msg.append(", name=");
1121                            msg.append(name);
1122    
1123                            msg.append(", scope=");
1124                            msg.append(scope);
1125    
1126                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1127    
1128                            throw new NoSuchResourcePermissionException(msg.toString());
1129                    }
1130                    else {
1131                            return list.get(0);
1132                    }
1133            }
1134    
1135            public ResourcePermission[] findByC_N_S_PrevAndNext(
1136                    long resourcePermissionId, long companyId, String name, int scope,
1137                    OrderByComparator orderByComparator)
1138                    throws NoSuchResourcePermissionException, SystemException {
1139                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1140    
1141                    Session session = null;
1142    
1143                    try {
1144                            session = openSession();
1145    
1146                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1147    
1148                            array[0] = getByC_N_S_PrevAndNext(session, resourcePermission,
1149                                            companyId, name, scope, orderByComparator, true);
1150    
1151                            array[1] = resourcePermission;
1152    
1153                            array[2] = getByC_N_S_PrevAndNext(session, resourcePermission,
1154                                            companyId, name, scope, orderByComparator, false);
1155    
1156                            return array;
1157                    }
1158                    catch (Exception e) {
1159                            throw processException(e);
1160                    }
1161                    finally {
1162                            closeSession(session);
1163                    }
1164            }
1165    
1166            protected ResourcePermission getByC_N_S_PrevAndNext(Session session,
1167                    ResourcePermission resourcePermission, long companyId, String name,
1168                    int scope, OrderByComparator orderByComparator, boolean previous) {
1169                    StringBundler query = null;
1170    
1171                    if (orderByComparator != null) {
1172                            query = new StringBundler(6 +
1173                                            (orderByComparator.getOrderByFields().length * 6));
1174                    }
1175                    else {
1176                            query = new StringBundler(3);
1177                    }
1178    
1179                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1180    
1181                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
1182    
1183                    if (name == null) {
1184                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
1185                    }
1186                    else {
1187                            if (name.equals(StringPool.BLANK)) {
1188                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
1189                            }
1190                            else {
1191                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
1192                            }
1193                    }
1194    
1195                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
1196    
1197                    if (orderByComparator != null) {
1198                            String[] orderByFields = orderByComparator.getOrderByFields();
1199    
1200                            if (orderByFields.length > 0) {
1201                                    query.append(WHERE_AND);
1202                            }
1203    
1204                            for (int i = 0; i < orderByFields.length; i++) {
1205                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1206                                    query.append(orderByFields[i]);
1207    
1208                                    if ((i + 1) < orderByFields.length) {
1209                                            if (orderByComparator.isAscending() ^ previous) {
1210                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1211                                            }
1212                                            else {
1213                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1214                                            }
1215                                    }
1216                                    else {
1217                                            if (orderByComparator.isAscending() ^ previous) {
1218                                                    query.append(WHERE_GREATER_THAN);
1219                                            }
1220                                            else {
1221                                                    query.append(WHERE_LESSER_THAN);
1222                                            }
1223                                    }
1224                            }
1225    
1226                            query.append(ORDER_BY_CLAUSE);
1227    
1228                            for (int i = 0; i < orderByFields.length; i++) {
1229                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1230                                    query.append(orderByFields[i]);
1231    
1232                                    if ((i + 1) < orderByFields.length) {
1233                                            if (orderByComparator.isAscending() ^ previous) {
1234                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1235                                            }
1236                                            else {
1237                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1238                                            }
1239                                    }
1240                                    else {
1241                                            if (orderByComparator.isAscending() ^ previous) {
1242                                                    query.append(ORDER_BY_ASC);
1243                                            }
1244                                            else {
1245                                                    query.append(ORDER_BY_DESC);
1246                                            }
1247                                    }
1248                            }
1249                    }
1250    
1251                    String sql = query.toString();
1252    
1253                    Query q = session.createQuery(sql);
1254    
1255                    q.setFirstResult(0);
1256                    q.setMaxResults(2);
1257    
1258                    QueryPos qPos = QueryPos.getInstance(q);
1259    
1260                    qPos.add(companyId);
1261    
1262                    if (name != null) {
1263                            qPos.add(name);
1264                    }
1265    
1266                    qPos.add(scope);
1267    
1268                    if (orderByComparator != null) {
1269                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
1270    
1271                            for (Object value : values) {
1272                                    qPos.add(value);
1273                            }
1274                    }
1275    
1276                    List<ResourcePermission> list = q.list();
1277    
1278                    if (list.size() == 2) {
1279                            return list.get(1);
1280                    }
1281                    else {
1282                            return null;
1283                    }
1284            }
1285    
1286            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1287                    int scope, String primKey) throws SystemException {
1288                    return findByC_N_S_P(companyId, name, scope, primKey,
1289                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1290            }
1291    
1292            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1293                    int scope, String primKey, int start, int end)
1294                    throws SystemException {
1295                    return findByC_N_S_P(companyId, name, scope, primKey, start, end, null);
1296            }
1297    
1298            public List<ResourcePermission> findByC_N_S_P(long companyId, String name,
1299                    int scope, String primKey, int start, int end,
1300                    OrderByComparator orderByComparator) throws SystemException {
1301                    Object[] finderArgs = new Object[] {
1302                                    companyId, name, scope, primKey,
1303                                    
1304                                    String.valueOf(start), String.valueOf(end),
1305                                    String.valueOf(orderByComparator)
1306                            };
1307    
1308                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_N_S_P,
1309                                    finderArgs, this);
1310    
1311                    if (list == null) {
1312                            Session session = null;
1313    
1314                            try {
1315                                    session = openSession();
1316    
1317                                    StringBundler query = null;
1318    
1319                                    if (orderByComparator != null) {
1320                                            query = new StringBundler(6 +
1321                                                            (orderByComparator.getOrderByFields().length * 3));
1322                                    }
1323                                    else {
1324                                            query = new StringBundler(5);
1325                                    }
1326    
1327                                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1328    
1329                                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
1330    
1331                                    if (name == null) {
1332                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
1333                                    }
1334                                    else {
1335                                            if (name.equals(StringPool.BLANK)) {
1336                                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
1337                                            }
1338                                            else {
1339                                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
1340                                            }
1341                                    }
1342    
1343                                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
1344    
1345                                    if (primKey == null) {
1346                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
1347                                    }
1348                                    else {
1349                                            if (primKey.equals(StringPool.BLANK)) {
1350                                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
1351                                            }
1352                                            else {
1353                                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
1354                                            }
1355                                    }
1356    
1357                                    if (orderByComparator != null) {
1358                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1359                                                    orderByComparator);
1360                                    }
1361    
1362                                    String sql = query.toString();
1363    
1364                                    Query q = session.createQuery(sql);
1365    
1366                                    QueryPos qPos = QueryPos.getInstance(q);
1367    
1368                                    qPos.add(companyId);
1369    
1370                                    if (name != null) {
1371                                            qPos.add(name);
1372                                    }
1373    
1374                                    qPos.add(scope);
1375    
1376                                    if (primKey != null) {
1377                                            qPos.add(primKey);
1378                                    }
1379    
1380                                    list = (List<ResourcePermission>)QueryUtil.list(q,
1381                                                    getDialect(), start, end);
1382                            }
1383                            catch (Exception e) {
1384                                    throw processException(e);
1385                            }
1386                            finally {
1387                                    if (list == null) {
1388                                            list = new ArrayList<ResourcePermission>();
1389                                    }
1390    
1391                                    cacheResult(list);
1392    
1393                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_N_S_P,
1394                                            finderArgs, list);
1395    
1396                                    closeSession(session);
1397                            }
1398                    }
1399    
1400                    return list;
1401            }
1402    
1403            public ResourcePermission findByC_N_S_P_First(long companyId, String name,
1404                    int scope, String primKey, OrderByComparator orderByComparator)
1405                    throws NoSuchResourcePermissionException, SystemException {
1406                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
1407                                    primKey, 0, 1, orderByComparator);
1408    
1409                    if (list.isEmpty()) {
1410                            StringBundler msg = new StringBundler(10);
1411    
1412                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1413    
1414                            msg.append("companyId=");
1415                            msg.append(companyId);
1416    
1417                            msg.append(", name=");
1418                            msg.append(name);
1419    
1420                            msg.append(", scope=");
1421                            msg.append(scope);
1422    
1423                            msg.append(", primKey=");
1424                            msg.append(primKey);
1425    
1426                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1427    
1428                            throw new NoSuchResourcePermissionException(msg.toString());
1429                    }
1430                    else {
1431                            return list.get(0);
1432                    }
1433            }
1434    
1435            public ResourcePermission findByC_N_S_P_Last(long companyId, String name,
1436                    int scope, String primKey, OrderByComparator orderByComparator)
1437                    throws NoSuchResourcePermissionException, SystemException {
1438                    int count = countByC_N_S_P(companyId, name, scope, primKey);
1439    
1440                    List<ResourcePermission> list = findByC_N_S_P(companyId, name, scope,
1441                                    primKey, count - 1, count, orderByComparator);
1442    
1443                    if (list.isEmpty()) {
1444                            StringBundler msg = new StringBundler(10);
1445    
1446                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1447    
1448                            msg.append("companyId=");
1449                            msg.append(companyId);
1450    
1451                            msg.append(", name=");
1452                            msg.append(name);
1453    
1454                            msg.append(", scope=");
1455                            msg.append(scope);
1456    
1457                            msg.append(", primKey=");
1458                            msg.append(primKey);
1459    
1460                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1461    
1462                            throw new NoSuchResourcePermissionException(msg.toString());
1463                    }
1464                    else {
1465                            return list.get(0);
1466                    }
1467            }
1468    
1469            public ResourcePermission[] findByC_N_S_P_PrevAndNext(
1470                    long resourcePermissionId, long companyId, String name, int scope,
1471                    String primKey, OrderByComparator orderByComparator)
1472                    throws NoSuchResourcePermissionException, SystemException {
1473                    ResourcePermission resourcePermission = findByPrimaryKey(resourcePermissionId);
1474    
1475                    Session session = null;
1476    
1477                    try {
1478                            session = openSession();
1479    
1480                            ResourcePermission[] array = new ResourcePermissionImpl[3];
1481    
1482                            array[0] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
1483                                            companyId, name, scope, primKey, orderByComparator, true);
1484    
1485                            array[1] = resourcePermission;
1486    
1487                            array[2] = getByC_N_S_P_PrevAndNext(session, resourcePermission,
1488                                            companyId, name, scope, primKey, orderByComparator, false);
1489    
1490                            return array;
1491                    }
1492                    catch (Exception e) {
1493                            throw processException(e);
1494                    }
1495                    finally {
1496                            closeSession(session);
1497                    }
1498            }
1499    
1500            protected ResourcePermission getByC_N_S_P_PrevAndNext(Session session,
1501                    ResourcePermission resourcePermission, long companyId, String name,
1502                    int scope, String primKey, OrderByComparator orderByComparator,
1503                    boolean previous) {
1504                    StringBundler query = null;
1505    
1506                    if (orderByComparator != null) {
1507                            query = new StringBundler(6 +
1508                                            (orderByComparator.getOrderByFields().length * 6));
1509                    }
1510                    else {
1511                            query = new StringBundler(3);
1512                    }
1513    
1514                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1515    
1516                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
1517    
1518                    if (name == null) {
1519                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
1520                    }
1521                    else {
1522                            if (name.equals(StringPool.BLANK)) {
1523                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
1524                            }
1525                            else {
1526                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
1527                            }
1528                    }
1529    
1530                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
1531    
1532                    if (primKey == null) {
1533                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
1534                    }
1535                    else {
1536                            if (primKey.equals(StringPool.BLANK)) {
1537                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
1538                            }
1539                            else {
1540                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
1541                            }
1542                    }
1543    
1544                    if (orderByComparator != null) {
1545                            String[] orderByFields = orderByComparator.getOrderByFields();
1546    
1547                            if (orderByFields.length > 0) {
1548                                    query.append(WHERE_AND);
1549                            }
1550    
1551                            for (int i = 0; i < orderByFields.length; i++) {
1552                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1553                                    query.append(orderByFields[i]);
1554    
1555                                    if ((i + 1) < orderByFields.length) {
1556                                            if (orderByComparator.isAscending() ^ previous) {
1557                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1558                                            }
1559                                            else {
1560                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1561                                            }
1562                                    }
1563                                    else {
1564                                            if (orderByComparator.isAscending() ^ previous) {
1565                                                    query.append(WHERE_GREATER_THAN);
1566                                            }
1567                                            else {
1568                                                    query.append(WHERE_LESSER_THAN);
1569                                            }
1570                                    }
1571                            }
1572    
1573                            query.append(ORDER_BY_CLAUSE);
1574    
1575                            for (int i = 0; i < orderByFields.length; i++) {
1576                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1577                                    query.append(orderByFields[i]);
1578    
1579                                    if ((i + 1) < orderByFields.length) {
1580                                            if (orderByComparator.isAscending() ^ previous) {
1581                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1582                                            }
1583                                            else {
1584                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1585                                            }
1586                                    }
1587                                    else {
1588                                            if (orderByComparator.isAscending() ^ previous) {
1589                                                    query.append(ORDER_BY_ASC);
1590                                            }
1591                                            else {
1592                                                    query.append(ORDER_BY_DESC);
1593                                            }
1594                                    }
1595                            }
1596                    }
1597    
1598                    String sql = query.toString();
1599    
1600                    Query q = session.createQuery(sql);
1601    
1602                    q.setFirstResult(0);
1603                    q.setMaxResults(2);
1604    
1605                    QueryPos qPos = QueryPos.getInstance(q);
1606    
1607                    qPos.add(companyId);
1608    
1609                    if (name != null) {
1610                            qPos.add(name);
1611                    }
1612    
1613                    qPos.add(scope);
1614    
1615                    if (primKey != null) {
1616                            qPos.add(primKey);
1617                    }
1618    
1619                    if (orderByComparator != null) {
1620                            Object[] values = orderByComparator.getOrderByValues(resourcePermission);
1621    
1622                            for (Object value : values) {
1623                                    qPos.add(value);
1624                            }
1625                    }
1626    
1627                    List<ResourcePermission> list = q.list();
1628    
1629                    if (list.size() == 2) {
1630                            return list.get(1);
1631                    }
1632                    else {
1633                            return null;
1634                    }
1635            }
1636    
1637            public ResourcePermission findByC_N_S_P_R(long companyId, String name,
1638                    int scope, String primKey, long roleId)
1639                    throws NoSuchResourcePermissionException, SystemException {
1640                    ResourcePermission resourcePermission = fetchByC_N_S_P_R(companyId,
1641                                    name, scope, primKey, roleId);
1642    
1643                    if (resourcePermission == null) {
1644                            StringBundler msg = new StringBundler(12);
1645    
1646                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1647    
1648                            msg.append("companyId=");
1649                            msg.append(companyId);
1650    
1651                            msg.append(", name=");
1652                            msg.append(name);
1653    
1654                            msg.append(", scope=");
1655                            msg.append(scope);
1656    
1657                            msg.append(", primKey=");
1658                            msg.append(primKey);
1659    
1660                            msg.append(", roleId=");
1661                            msg.append(roleId);
1662    
1663                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1664    
1665                            if (_log.isWarnEnabled()) {
1666                                    _log.warn(msg.toString());
1667                            }
1668    
1669                            throw new NoSuchResourcePermissionException(msg.toString());
1670                    }
1671    
1672                    return resourcePermission;
1673            }
1674    
1675            public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
1676                    int scope, String primKey, long roleId) throws SystemException {
1677                    return fetchByC_N_S_P_R(companyId, name, scope, primKey, roleId, true);
1678            }
1679    
1680            public ResourcePermission fetchByC_N_S_P_R(long companyId, String name,
1681                    int scope, String primKey, long roleId, boolean retrieveFromCache)
1682                    throws SystemException {
1683                    Object[] finderArgs = new Object[] {
1684                                    companyId, name, scope, primKey, roleId
1685                            };
1686    
1687                    Object result = null;
1688    
1689                    if (retrieveFromCache) {
1690                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1691                                            finderArgs, this);
1692                    }
1693    
1694                    if (result == null) {
1695                            Session session = null;
1696    
1697                            try {
1698                                    session = openSession();
1699    
1700                                    StringBundler query = new StringBundler(6);
1701    
1702                                    query.append(_SQL_SELECT_RESOURCEPERMISSION_WHERE);
1703    
1704                                    query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
1705    
1706                                    if (name == null) {
1707                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
1708                                    }
1709                                    else {
1710                                            if (name.equals(StringPool.BLANK)) {
1711                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
1712                                            }
1713                                            else {
1714                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
1715                                            }
1716                                    }
1717    
1718                                    query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
1719    
1720                                    if (primKey == null) {
1721                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
1722                                    }
1723                                    else {
1724                                            if (primKey.equals(StringPool.BLANK)) {
1725                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
1726                                            }
1727                                            else {
1728                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
1729                                            }
1730                                    }
1731    
1732                                    query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
1733    
1734                                    String sql = query.toString();
1735    
1736                                    Query q = session.createQuery(sql);
1737    
1738                                    QueryPos qPos = QueryPos.getInstance(q);
1739    
1740                                    qPos.add(companyId);
1741    
1742                                    if (name != null) {
1743                                            qPos.add(name);
1744                                    }
1745    
1746                                    qPos.add(scope);
1747    
1748                                    if (primKey != null) {
1749                                            qPos.add(primKey);
1750                                    }
1751    
1752                                    qPos.add(roleId);
1753    
1754                                    List<ResourcePermission> list = q.list();
1755    
1756                                    result = list;
1757    
1758                                    ResourcePermission resourcePermission = null;
1759    
1760                                    if (list.isEmpty()) {
1761                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1762                                                    finderArgs, list);
1763                                    }
1764                                    else {
1765                                            resourcePermission = list.get(0);
1766    
1767                                            cacheResult(resourcePermission);
1768    
1769                                            if ((resourcePermission.getCompanyId() != companyId) ||
1770                                                            (resourcePermission.getName() == null) ||
1771                                                            !resourcePermission.getName().equals(name) ||
1772                                                            (resourcePermission.getScope() != scope) ||
1773                                                            (resourcePermission.getPrimKey() == null) ||
1774                                                            !resourcePermission.getPrimKey().equals(primKey) ||
1775                                                            (resourcePermission.getRoleId() != roleId)) {
1776                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1777                                                            finderArgs, resourcePermission);
1778                                            }
1779                                    }
1780    
1781                                    return resourcePermission;
1782                            }
1783                            catch (Exception e) {
1784                                    throw processException(e);
1785                            }
1786                            finally {
1787                                    if (result == null) {
1788                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N_S_P_R,
1789                                                    finderArgs, new ArrayList<ResourcePermission>());
1790                                    }
1791    
1792                                    closeSession(session);
1793                            }
1794                    }
1795                    else {
1796                            if (result instanceof List<?>) {
1797                                    return null;
1798                            }
1799                            else {
1800                                    return (ResourcePermission)result;
1801                            }
1802                    }
1803            }
1804    
1805            public List<ResourcePermission> findAll() throws SystemException {
1806                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1807            }
1808    
1809            public List<ResourcePermission> findAll(int start, int end)
1810                    throws SystemException {
1811                    return findAll(start, end, null);
1812            }
1813    
1814            public List<ResourcePermission> findAll(int start, int end,
1815                    OrderByComparator orderByComparator) throws SystemException {
1816                    Object[] finderArgs = new Object[] {
1817                                    String.valueOf(start), String.valueOf(end),
1818                                    String.valueOf(orderByComparator)
1819                            };
1820    
1821                    List<ResourcePermission> list = (List<ResourcePermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1822                                    finderArgs, this);
1823    
1824                    if (list == null) {
1825                            Session session = null;
1826    
1827                            try {
1828                                    session = openSession();
1829    
1830                                    StringBundler query = null;
1831                                    String sql = null;
1832    
1833                                    if (orderByComparator != null) {
1834                                            query = new StringBundler(2 +
1835                                                            (orderByComparator.getOrderByFields().length * 3));
1836    
1837                                            query.append(_SQL_SELECT_RESOURCEPERMISSION);
1838    
1839                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1840                                                    orderByComparator);
1841    
1842                                            sql = query.toString();
1843                                    }
1844                                    else {
1845                                            sql = _SQL_SELECT_RESOURCEPERMISSION;
1846                                    }
1847    
1848                                    Query q = session.createQuery(sql);
1849    
1850                                    if (orderByComparator == null) {
1851                                            list = (List<ResourcePermission>)QueryUtil.list(q,
1852                                                            getDialect(), start, end, false);
1853    
1854                                            Collections.sort(list);
1855                                    }
1856                                    else {
1857                                            list = (List<ResourcePermission>)QueryUtil.list(q,
1858                                                            getDialect(), start, end);
1859                                    }
1860                            }
1861                            catch (Exception e) {
1862                                    throw processException(e);
1863                            }
1864                            finally {
1865                                    if (list == null) {
1866                                            list = new ArrayList<ResourcePermission>();
1867                                    }
1868    
1869                                    cacheResult(list);
1870    
1871                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1872    
1873                                    closeSession(session);
1874                            }
1875                    }
1876    
1877                    return list;
1878            }
1879    
1880            public void removeByRoleId(long roleId) throws SystemException {
1881                    for (ResourcePermission resourcePermission : findByRoleId(roleId)) {
1882                            remove(resourcePermission);
1883                    }
1884            }
1885    
1886            public void removeByR_S(long roleId, int scope) throws SystemException {
1887                    for (ResourcePermission resourcePermission : findByR_S(roleId, scope)) {
1888                            remove(resourcePermission);
1889                    }
1890            }
1891    
1892            public void removeByC_N_S(long companyId, String name, int scope)
1893                    throws SystemException {
1894                    for (ResourcePermission resourcePermission : findByC_N_S(companyId,
1895                                    name, scope)) {
1896                            remove(resourcePermission);
1897                    }
1898            }
1899    
1900            public void removeByC_N_S_P(long companyId, String name, int scope,
1901                    String primKey) throws SystemException {
1902                    for (ResourcePermission resourcePermission : findByC_N_S_P(companyId,
1903                                    name, scope, primKey)) {
1904                            remove(resourcePermission);
1905                    }
1906            }
1907    
1908            public void removeByC_N_S_P_R(long companyId, String name, int scope,
1909                    String primKey, long roleId)
1910                    throws NoSuchResourcePermissionException, SystemException {
1911                    ResourcePermission resourcePermission = findByC_N_S_P_R(companyId,
1912                                    name, scope, primKey, roleId);
1913    
1914                    remove(resourcePermission);
1915            }
1916    
1917            public void removeAll() throws SystemException {
1918                    for (ResourcePermission resourcePermission : findAll()) {
1919                            remove(resourcePermission);
1920                    }
1921            }
1922    
1923            public int countByRoleId(long roleId) throws SystemException {
1924                    Object[] finderArgs = new Object[] { roleId };
1925    
1926                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1927                                    finderArgs, this);
1928    
1929                    if (count == null) {
1930                            Session session = null;
1931    
1932                            try {
1933                                    session = openSession();
1934    
1935                                    StringBundler query = new StringBundler(2);
1936    
1937                                    query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
1938    
1939                                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1940    
1941                                    String sql = query.toString();
1942    
1943                                    Query q = session.createQuery(sql);
1944    
1945                                    QueryPos qPos = QueryPos.getInstance(q);
1946    
1947                                    qPos.add(roleId);
1948    
1949                                    count = (Long)q.uniqueResult();
1950                            }
1951                            catch (Exception e) {
1952                                    throw processException(e);
1953                            }
1954                            finally {
1955                                    if (count == null) {
1956                                            count = Long.valueOf(0);
1957                                    }
1958    
1959                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1960                                            finderArgs, count);
1961    
1962                                    closeSession(session);
1963                            }
1964                    }
1965    
1966                    return count.intValue();
1967            }
1968    
1969            public int countByR_S(long roleId, int scope) throws SystemException {
1970                    Object[] finderArgs = new Object[] { roleId, scope };
1971    
1972                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_R_S,
1973                                    finderArgs, this);
1974    
1975                    if (count == null) {
1976                            Session session = null;
1977    
1978                            try {
1979                                    session = openSession();
1980    
1981                                    StringBundler query = new StringBundler(3);
1982    
1983                                    query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
1984    
1985                                    query.append(_FINDER_COLUMN_R_S_ROLEID_2);
1986    
1987                                    query.append(_FINDER_COLUMN_R_S_SCOPE_2);
1988    
1989                                    String sql = query.toString();
1990    
1991                                    Query q = session.createQuery(sql);
1992    
1993                                    QueryPos qPos = QueryPos.getInstance(q);
1994    
1995                                    qPos.add(roleId);
1996    
1997                                    qPos.add(scope);
1998    
1999                                    count = (Long)q.uniqueResult();
2000                            }
2001                            catch (Exception e) {
2002                                    throw processException(e);
2003                            }
2004                            finally {
2005                                    if (count == null) {
2006                                            count = Long.valueOf(0);
2007                                    }
2008    
2009                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_R_S, finderArgs,
2010                                            count);
2011    
2012                                    closeSession(session);
2013                            }
2014                    }
2015    
2016                    return count.intValue();
2017            }
2018    
2019            public int countByC_N_S(long companyId, String name, int scope)
2020                    throws SystemException {
2021                    Object[] finderArgs = new Object[] { companyId, name, scope };
2022    
2023                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S,
2024                                    finderArgs, this);
2025    
2026                    if (count == null) {
2027                            Session session = null;
2028    
2029                            try {
2030                                    session = openSession();
2031    
2032                                    StringBundler query = new StringBundler(4);
2033    
2034                                    query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2035    
2036                                    query.append(_FINDER_COLUMN_C_N_S_COMPANYID_2);
2037    
2038                                    if (name == null) {
2039                                            query.append(_FINDER_COLUMN_C_N_S_NAME_1);
2040                                    }
2041                                    else {
2042                                            if (name.equals(StringPool.BLANK)) {
2043                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_3);
2044                                            }
2045                                            else {
2046                                                    query.append(_FINDER_COLUMN_C_N_S_NAME_2);
2047                                            }
2048                                    }
2049    
2050                                    query.append(_FINDER_COLUMN_C_N_S_SCOPE_2);
2051    
2052                                    String sql = query.toString();
2053    
2054                                    Query q = session.createQuery(sql);
2055    
2056                                    QueryPos qPos = QueryPos.getInstance(q);
2057    
2058                                    qPos.add(companyId);
2059    
2060                                    if (name != null) {
2061                                            qPos.add(name);
2062                                    }
2063    
2064                                    qPos.add(scope);
2065    
2066                                    count = (Long)q.uniqueResult();
2067                            }
2068                            catch (Exception e) {
2069                                    throw processException(e);
2070                            }
2071                            finally {
2072                                    if (count == null) {
2073                                            count = Long.valueOf(0);
2074                                    }
2075    
2076                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S,
2077                                            finderArgs, count);
2078    
2079                                    closeSession(session);
2080                            }
2081                    }
2082    
2083                    return count.intValue();
2084            }
2085    
2086            public int countByC_N_S_P(long companyId, String name, int scope,
2087                    String primKey) throws SystemException {
2088                    Object[] finderArgs = new Object[] { companyId, name, scope, primKey };
2089    
2090                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P,
2091                                    finderArgs, this);
2092    
2093                    if (count == null) {
2094                            Session session = null;
2095    
2096                            try {
2097                                    session = openSession();
2098    
2099                                    StringBundler query = new StringBundler(5);
2100    
2101                                    query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2102    
2103                                    query.append(_FINDER_COLUMN_C_N_S_P_COMPANYID_2);
2104    
2105                                    if (name == null) {
2106                                            query.append(_FINDER_COLUMN_C_N_S_P_NAME_1);
2107                                    }
2108                                    else {
2109                                            if (name.equals(StringPool.BLANK)) {
2110                                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_3);
2111                                            }
2112                                            else {
2113                                                    query.append(_FINDER_COLUMN_C_N_S_P_NAME_2);
2114                                            }
2115                                    }
2116    
2117                                    query.append(_FINDER_COLUMN_C_N_S_P_SCOPE_2);
2118    
2119                                    if (primKey == null) {
2120                                            query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_1);
2121                                    }
2122                                    else {
2123                                            if (primKey.equals(StringPool.BLANK)) {
2124                                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_3);
2125                                            }
2126                                            else {
2127                                                    query.append(_FINDER_COLUMN_C_N_S_P_PRIMKEY_2);
2128                                            }
2129                                    }
2130    
2131                                    String sql = query.toString();
2132    
2133                                    Query q = session.createQuery(sql);
2134    
2135                                    QueryPos qPos = QueryPos.getInstance(q);
2136    
2137                                    qPos.add(companyId);
2138    
2139                                    if (name != null) {
2140                                            qPos.add(name);
2141                                    }
2142    
2143                                    qPos.add(scope);
2144    
2145                                    if (primKey != null) {
2146                                            qPos.add(primKey);
2147                                    }
2148    
2149                                    count = (Long)q.uniqueResult();
2150                            }
2151                            catch (Exception e) {
2152                                    throw processException(e);
2153                            }
2154                            finally {
2155                                    if (count == null) {
2156                                            count = Long.valueOf(0);
2157                                    }
2158    
2159                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P,
2160                                            finderArgs, count);
2161    
2162                                    closeSession(session);
2163                            }
2164                    }
2165    
2166                    return count.intValue();
2167            }
2168    
2169            public int countByC_N_S_P_R(long companyId, String name, int scope,
2170                    String primKey, long roleId) throws SystemException {
2171                    Object[] finderArgs = new Object[] {
2172                                    companyId, name, scope, primKey, roleId
2173                            };
2174    
2175                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
2176                                    finderArgs, this);
2177    
2178                    if (count == null) {
2179                            Session session = null;
2180    
2181                            try {
2182                                    session = openSession();
2183    
2184                                    StringBundler query = new StringBundler(6);
2185    
2186                                    query.append(_SQL_COUNT_RESOURCEPERMISSION_WHERE);
2187    
2188                                    query.append(_FINDER_COLUMN_C_N_S_P_R_COMPANYID_2);
2189    
2190                                    if (name == null) {
2191                                            query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_1);
2192                                    }
2193                                    else {
2194                                            if (name.equals(StringPool.BLANK)) {
2195                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_3);
2196                                            }
2197                                            else {
2198                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_NAME_2);
2199                                            }
2200                                    }
2201    
2202                                    query.append(_FINDER_COLUMN_C_N_S_P_R_SCOPE_2);
2203    
2204                                    if (primKey == null) {
2205                                            query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1);
2206                                    }
2207                                    else {
2208                                            if (primKey.equals(StringPool.BLANK)) {
2209                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3);
2210                                            }
2211                                            else {
2212                                                    query.append(_FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2);
2213                                            }
2214                                    }
2215    
2216                                    query.append(_FINDER_COLUMN_C_N_S_P_R_ROLEID_2);
2217    
2218                                    String sql = query.toString();
2219    
2220                                    Query q = session.createQuery(sql);
2221    
2222                                    QueryPos qPos = QueryPos.getInstance(q);
2223    
2224                                    qPos.add(companyId);
2225    
2226                                    if (name != null) {
2227                                            qPos.add(name);
2228                                    }
2229    
2230                                    qPos.add(scope);
2231    
2232                                    if (primKey != null) {
2233                                            qPos.add(primKey);
2234                                    }
2235    
2236                                    qPos.add(roleId);
2237    
2238                                    count = (Long)q.uniqueResult();
2239                            }
2240                            catch (Exception e) {
2241                                    throw processException(e);
2242                            }
2243                            finally {
2244                                    if (count == null) {
2245                                            count = Long.valueOf(0);
2246                                    }
2247    
2248                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N_S_P_R,
2249                                            finderArgs, count);
2250    
2251                                    closeSession(session);
2252                            }
2253                    }
2254    
2255                    return count.intValue();
2256            }
2257    
2258            public int countAll() throws SystemException {
2259                    Object[] finderArgs = new Object[0];
2260    
2261                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2262                                    finderArgs, this);
2263    
2264                    if (count == null) {
2265                            Session session = null;
2266    
2267                            try {
2268                                    session = openSession();
2269    
2270                                    Query q = session.createQuery(_SQL_COUNT_RESOURCEPERMISSION);
2271    
2272                                    count = (Long)q.uniqueResult();
2273                            }
2274                            catch (Exception e) {
2275                                    throw processException(e);
2276                            }
2277                            finally {
2278                                    if (count == null) {
2279                                            count = Long.valueOf(0);
2280                                    }
2281    
2282                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2283                                            count);
2284    
2285                                    closeSession(session);
2286                            }
2287                    }
2288    
2289                    return count.intValue();
2290            }
2291    
2292            public void afterPropertiesSet() {
2293                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2294                                            com.liferay.portal.util.PropsUtil.get(
2295                                                    "value.object.listener.com.liferay.portal.model.ResourcePermission")));
2296    
2297                    if (listenerClassNames.length > 0) {
2298                            try {
2299                                    List<ModelListener<ResourcePermission>> listenersList = new ArrayList<ModelListener<ResourcePermission>>();
2300    
2301                                    for (String listenerClassName : listenerClassNames) {
2302                                            listenersList.add((ModelListener<ResourcePermission>)InstanceFactory.newInstance(
2303                                                            listenerClassName));
2304                                    }
2305    
2306                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2307                            }
2308                            catch (Exception e) {
2309                                    _log.error(e);
2310                            }
2311                    }
2312            }
2313    
2314            @BeanReference(type = AccountPersistence.class)
2315            protected AccountPersistence accountPersistence;
2316            @BeanReference(type = AddressPersistence.class)
2317            protected AddressPersistence addressPersistence;
2318            @BeanReference(type = BrowserTrackerPersistence.class)
2319            protected BrowserTrackerPersistence browserTrackerPersistence;
2320            @BeanReference(type = ClassNamePersistence.class)
2321            protected ClassNamePersistence classNamePersistence;
2322            @BeanReference(type = CompanyPersistence.class)
2323            protected CompanyPersistence companyPersistence;
2324            @BeanReference(type = ContactPersistence.class)
2325            protected ContactPersistence contactPersistence;
2326            @BeanReference(type = CountryPersistence.class)
2327            protected CountryPersistence countryPersistence;
2328            @BeanReference(type = EmailAddressPersistence.class)
2329            protected EmailAddressPersistence emailAddressPersistence;
2330            @BeanReference(type = GroupPersistence.class)
2331            protected GroupPersistence groupPersistence;
2332            @BeanReference(type = ImagePersistence.class)
2333            protected ImagePersistence imagePersistence;
2334            @BeanReference(type = LayoutPersistence.class)
2335            protected LayoutPersistence layoutPersistence;
2336            @BeanReference(type = LayoutPrototypePersistence.class)
2337            protected LayoutPrototypePersistence layoutPrototypePersistence;
2338            @BeanReference(type = LayoutSetPersistence.class)
2339            protected LayoutSetPersistence layoutSetPersistence;
2340            @BeanReference(type = LayoutSetPrototypePersistence.class)
2341            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2342            @BeanReference(type = ListTypePersistence.class)
2343            protected ListTypePersistence listTypePersistence;
2344            @BeanReference(type = LockPersistence.class)
2345            protected LockPersistence lockPersistence;
2346            @BeanReference(type = MembershipRequestPersistence.class)
2347            protected MembershipRequestPersistence membershipRequestPersistence;
2348            @BeanReference(type = OrganizationPersistence.class)
2349            protected OrganizationPersistence organizationPersistence;
2350            @BeanReference(type = OrgGroupPermissionPersistence.class)
2351            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2352            @BeanReference(type = OrgGroupRolePersistence.class)
2353            protected OrgGroupRolePersistence orgGroupRolePersistence;
2354            @BeanReference(type = OrgLaborPersistence.class)
2355            protected OrgLaborPersistence orgLaborPersistence;
2356            @BeanReference(type = PasswordPolicyPersistence.class)
2357            protected PasswordPolicyPersistence passwordPolicyPersistence;
2358            @BeanReference(type = PasswordPolicyRelPersistence.class)
2359            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2360            @BeanReference(type = PasswordTrackerPersistence.class)
2361            protected PasswordTrackerPersistence passwordTrackerPersistence;
2362            @BeanReference(type = PermissionPersistence.class)
2363            protected PermissionPersistence permissionPersistence;
2364            @BeanReference(type = PhonePersistence.class)
2365            protected PhonePersistence phonePersistence;
2366            @BeanReference(type = PluginSettingPersistence.class)
2367            protected PluginSettingPersistence pluginSettingPersistence;
2368            @BeanReference(type = PortletPersistence.class)
2369            protected PortletPersistence portletPersistence;
2370            @BeanReference(type = PortletItemPersistence.class)
2371            protected PortletItemPersistence portletItemPersistence;
2372            @BeanReference(type = PortletPreferencesPersistence.class)
2373            protected PortletPreferencesPersistence portletPreferencesPersistence;
2374            @BeanReference(type = RegionPersistence.class)
2375            protected RegionPersistence regionPersistence;
2376            @BeanReference(type = ReleasePersistence.class)
2377            protected ReleasePersistence releasePersistence;
2378            @BeanReference(type = ResourcePersistence.class)
2379            protected ResourcePersistence resourcePersistence;
2380            @BeanReference(type = ResourceActionPersistence.class)
2381            protected ResourceActionPersistence resourceActionPersistence;
2382            @BeanReference(type = ResourceCodePersistence.class)
2383            protected ResourceCodePersistence resourceCodePersistence;
2384            @BeanReference(type = ResourcePermissionPersistence.class)
2385            protected ResourcePermissionPersistence resourcePermissionPersistence;
2386            @BeanReference(type = RolePersistence.class)
2387            protected RolePersistence rolePersistence;
2388            @BeanReference(type = ServiceComponentPersistence.class)
2389            protected ServiceComponentPersistence serviceComponentPersistence;
2390            @BeanReference(type = ShardPersistence.class)
2391            protected ShardPersistence shardPersistence;
2392            @BeanReference(type = SubscriptionPersistence.class)
2393            protected SubscriptionPersistence subscriptionPersistence;
2394            @BeanReference(type = TicketPersistence.class)
2395            protected TicketPersistence ticketPersistence;
2396            @BeanReference(type = TeamPersistence.class)
2397            protected TeamPersistence teamPersistence;
2398            @BeanReference(type = UserPersistence.class)
2399            protected UserPersistence userPersistence;
2400            @BeanReference(type = UserGroupPersistence.class)
2401            protected UserGroupPersistence userGroupPersistence;
2402            @BeanReference(type = UserGroupGroupRolePersistence.class)
2403            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2404            @BeanReference(type = UserGroupRolePersistence.class)
2405            protected UserGroupRolePersistence userGroupRolePersistence;
2406            @BeanReference(type = UserIdMapperPersistence.class)
2407            protected UserIdMapperPersistence userIdMapperPersistence;
2408            @BeanReference(type = UserTrackerPersistence.class)
2409            protected UserTrackerPersistence userTrackerPersistence;
2410            @BeanReference(type = UserTrackerPathPersistence.class)
2411            protected UserTrackerPathPersistence userTrackerPathPersistence;
2412            @BeanReference(type = WebDAVPropsPersistence.class)
2413            protected WebDAVPropsPersistence webDAVPropsPersistence;
2414            @BeanReference(type = WebsitePersistence.class)
2415            protected WebsitePersistence websitePersistence;
2416            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2417            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2418            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2419            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2420            private static final String _SQL_SELECT_RESOURCEPERMISSION = "SELECT resourcePermission FROM ResourcePermission resourcePermission";
2421            private static final String _SQL_SELECT_RESOURCEPERMISSION_WHERE = "SELECT resourcePermission FROM ResourcePermission resourcePermission WHERE ";
2422            private static final String _SQL_COUNT_RESOURCEPERMISSION = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission";
2423            private static final String _SQL_COUNT_RESOURCEPERMISSION_WHERE = "SELECT COUNT(resourcePermission) FROM ResourcePermission resourcePermission WHERE ";
2424            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "resourcePermission.roleId = ?";
2425            private static final String _FINDER_COLUMN_R_S_ROLEID_2 = "resourcePermission.roleId = ? AND ";
2426            private static final String _FINDER_COLUMN_R_S_SCOPE_2 = "resourcePermission.scope = ?";
2427            private static final String _FINDER_COLUMN_C_N_S_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
2428            private static final String _FINDER_COLUMN_C_N_S_NAME_1 = "resourcePermission.name IS NULL AND ";
2429            private static final String _FINDER_COLUMN_C_N_S_NAME_2 = "resourcePermission.name = ? AND ";
2430            private static final String _FINDER_COLUMN_C_N_S_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
2431            private static final String _FINDER_COLUMN_C_N_S_SCOPE_2 = "resourcePermission.scope = ?";
2432            private static final String _FINDER_COLUMN_C_N_S_P_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
2433            private static final String _FINDER_COLUMN_C_N_S_P_NAME_1 = "resourcePermission.name IS NULL AND ";
2434            private static final String _FINDER_COLUMN_C_N_S_P_NAME_2 = "resourcePermission.name = ? AND ";
2435            private static final String _FINDER_COLUMN_C_N_S_P_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
2436            private static final String _FINDER_COLUMN_C_N_S_P_SCOPE_2 = "resourcePermission.scope = ? AND ";
2437            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_1 = "resourcePermission.primKey IS NULL";
2438            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_2 = "resourcePermission.primKey = ?";
2439            private static final String _FINDER_COLUMN_C_N_S_P_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?)";
2440            private static final String _FINDER_COLUMN_C_N_S_P_R_COMPANYID_2 = "resourcePermission.companyId = ? AND ";
2441            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_1 = "resourcePermission.name IS NULL AND ";
2442            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_2 = "resourcePermission.name = ? AND ";
2443            private static final String _FINDER_COLUMN_C_N_S_P_R_NAME_3 = "(resourcePermission.name IS NULL OR resourcePermission.name = ?) AND ";
2444            private static final String _FINDER_COLUMN_C_N_S_P_R_SCOPE_2 = "resourcePermission.scope = ? AND ";
2445            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_1 = "resourcePermission.primKey IS NULL AND ";
2446            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_2 = "resourcePermission.primKey = ? AND ";
2447            private static final String _FINDER_COLUMN_C_N_S_P_R_PRIMKEY_3 = "(resourcePermission.primKey IS NULL OR resourcePermission.primKey = ?) AND ";
2448            private static final String _FINDER_COLUMN_C_N_S_P_R_ROLEID_2 = "resourcePermission.roleId = ?";
2449            private static final String _ORDER_BY_ENTITY_ALIAS = "resourcePermission.";
2450            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ResourcePermission exists with the primary key ";
2451            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ResourcePermission exists with the key {";
2452            private static Log _log = LogFactoryUtil.getLog(ResourcePermissionPersistenceImpl.class);
2453    }