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