001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchRoleException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.ArrayUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.InstanceFactory;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.SetUtil;
036    import com.liferay.portal.kernel.util.StringBundler;
037    import com.liferay.portal.kernel.util.StringPool;
038    import com.liferay.portal.kernel.util.StringUtil;
039    import com.liferay.portal.kernel.util.UnmodifiableList;
040    import com.liferay.portal.kernel.util.Validator;
041    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
042    import com.liferay.portal.model.CacheModel;
043    import com.liferay.portal.model.ModelListener;
044    import com.liferay.portal.model.Role;
045    import com.liferay.portal.model.impl.RoleImpl;
046    import com.liferay.portal.model.impl.RoleModelImpl;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049    import com.liferay.portal.service.persistence.impl.TableMapper;
050    import com.liferay.portal.service.persistence.impl.TableMapperFactory;
051    
052    import java.io.Serializable;
053    
054    import java.util.ArrayList;
055    import java.util.Collections;
056    import java.util.HashSet;
057    import java.util.List;
058    import java.util.Set;
059    
060    /**
061     * The persistence implementation for the role service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see RolePersistence
069     * @see RoleUtil
070     * @generated
071     */
072    public class RolePersistenceImpl extends BasePersistenceImpl<Role>
073            implements RolePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * 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.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
085                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
088                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
091                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
094                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
103                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105                            new String[] { String.class.getName() },
106                            RoleModelImpl.UUID_COLUMN_BITMASK |
107                            RoleModelImpl.NAME_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
109                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the roles where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching roles
118             * @throws SystemException if a system exception occurred
119             */
120            @Override
121            public List<Role> findByUuid(String uuid) throws SystemException {
122                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123            }
124    
125            /**
126             * Returns a range of all the roles where uuid = &#63;.
127             *
128             * <p>
129             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
130             * </p>
131             *
132             * @param uuid the uuid
133             * @param start the lower bound of the range of roles
134             * @param end the upper bound of the range of roles (not inclusive)
135             * @return the range of matching roles
136             * @throws SystemException if a system exception occurred
137             */
138            @Override
139            public List<Role> findByUuid(String uuid, int start, int end)
140                    throws SystemException {
141                    return findByUuid(uuid, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the roles where uuid = &#63;.
146             *
147             * <p>
148             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
149             * </p>
150             *
151             * @param uuid the uuid
152             * @param start the lower bound of the range of roles
153             * @param end the upper bound of the range of roles (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching roles
156             * @throws SystemException if a system exception occurred
157             */
158            @Override
159            public List<Role> findByUuid(String uuid, int start, int end,
160                    OrderByComparator orderByComparator) throws SystemException {
161                    boolean pagination = true;
162                    FinderPath finderPath = null;
163                    Object[] finderArgs = null;
164    
165                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166                                    (orderByComparator == null)) {
167                            pagination = false;
168                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
169                            finderArgs = new Object[] { uuid };
170                    }
171                    else {
172                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
173                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
174                    }
175    
176                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
177                                    finderArgs, this);
178    
179                    if ((list != null) && !list.isEmpty()) {
180                            for (Role role : list) {
181                                    if (!Validator.equals(uuid, role.getUuid())) {
182                                            list = null;
183    
184                                            break;
185                                    }
186                            }
187                    }
188    
189                    if (list == null) {
190                            StringBundler query = null;
191    
192                            if (orderByComparator != null) {
193                                    query = new StringBundler(3 +
194                                                    (orderByComparator.getOrderByFields().length * 3));
195                            }
196                            else {
197                                    query = new StringBundler(3);
198                            }
199    
200                            query.append(_SQL_SELECT_ROLE_WHERE);
201    
202                            boolean bindUuid = false;
203    
204                            if (uuid == null) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
206                            }
207                            else if (uuid.equals(StringPool.BLANK)) {
208                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
209                            }
210                            else {
211                                    bindUuid = true;
212    
213                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
214                            }
215    
216                            if (orderByComparator != null) {
217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218                                            orderByComparator);
219                            }
220                            else
221                             if (pagination) {
222                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
223                            }
224    
225                            String sql = query.toString();
226    
227                            Session session = null;
228    
229                            try {
230                                    session = openSession();
231    
232                                    Query q = session.createQuery(sql);
233    
234                                    QueryPos qPos = QueryPos.getInstance(q);
235    
236                                    if (bindUuid) {
237                                            qPos.add(uuid);
238                                    }
239    
240                                    if (!pagination) {
241                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
242                                                            end, false);
243    
244                                            Collections.sort(list);
245    
246                                            list = new UnmodifiableList<Role>(list);
247                                    }
248                                    else {
249                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
250                                                            end);
251                                    }
252    
253                                    cacheResult(list);
254    
255                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
256                            }
257                            catch (Exception e) {
258                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
259    
260                                    throw processException(e);
261                            }
262                            finally {
263                                    closeSession(session);
264                            }
265                    }
266    
267                    return list;
268            }
269    
270            /**
271             * Returns the first role in the ordered set where uuid = &#63;.
272             *
273             * @param uuid the uuid
274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
275             * @return the first matching role
276             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
277             * @throws SystemException if a system exception occurred
278             */
279            @Override
280            public Role findByUuid_First(String uuid,
281                    OrderByComparator orderByComparator)
282                    throws NoSuchRoleException, SystemException {
283                    Role role = fetchByUuid_First(uuid, orderByComparator);
284    
285                    if (role != null) {
286                            return role;
287                    }
288    
289                    StringBundler msg = new StringBundler(4);
290    
291                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292    
293                    msg.append("uuid=");
294                    msg.append(uuid);
295    
296                    msg.append(StringPool.CLOSE_CURLY_BRACE);
297    
298                    throw new NoSuchRoleException(msg.toString());
299            }
300    
301            /**
302             * Returns the first role in the ordered set where uuid = &#63;.
303             *
304             * @param uuid the uuid
305             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
306             * @return the first matching role, or <code>null</code> if a matching role could not be found
307             * @throws SystemException if a system exception occurred
308             */
309            @Override
310            public Role fetchByUuid_First(String uuid,
311                    OrderByComparator orderByComparator) throws SystemException {
312                    List<Role> list = findByUuid(uuid, 0, 1, orderByComparator);
313    
314                    if (!list.isEmpty()) {
315                            return list.get(0);
316                    }
317    
318                    return null;
319            }
320    
321            /**
322             * Returns the last role in the ordered set where uuid = &#63;.
323             *
324             * @param uuid the uuid
325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
326             * @return the last matching role
327             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
328             * @throws SystemException if a system exception occurred
329             */
330            @Override
331            public Role findByUuid_Last(String uuid, OrderByComparator orderByComparator)
332                    throws NoSuchRoleException, SystemException {
333                    Role role = fetchByUuid_Last(uuid, orderByComparator);
334    
335                    if (role != null) {
336                            return role;
337                    }
338    
339                    StringBundler msg = new StringBundler(4);
340    
341                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
342    
343                    msg.append("uuid=");
344                    msg.append(uuid);
345    
346                    msg.append(StringPool.CLOSE_CURLY_BRACE);
347    
348                    throw new NoSuchRoleException(msg.toString());
349            }
350    
351            /**
352             * Returns the last role in the ordered set where uuid = &#63;.
353             *
354             * @param uuid the uuid
355             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
356             * @return the last matching role, or <code>null</code> if a matching role could not be found
357             * @throws SystemException if a system exception occurred
358             */
359            @Override
360            public Role fetchByUuid_Last(String uuid,
361                    OrderByComparator orderByComparator) throws SystemException {
362                    int count = countByUuid(uuid);
363    
364                    if (count == 0) {
365                            return null;
366                    }
367    
368                    List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator);
369    
370                    if (!list.isEmpty()) {
371                            return list.get(0);
372                    }
373    
374                    return null;
375            }
376    
377            /**
378             * Returns the roles before and after the current role in the ordered set where uuid = &#63;.
379             *
380             * @param roleId the primary key of the current role
381             * @param uuid the uuid
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the previous, current, and next role
384             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
385             * @throws SystemException if a system exception occurred
386             */
387            @Override
388            public Role[] findByUuid_PrevAndNext(long roleId, String uuid,
389                    OrderByComparator orderByComparator)
390                    throws NoSuchRoleException, SystemException {
391                    Role role = findByPrimaryKey(roleId);
392    
393                    Session session = null;
394    
395                    try {
396                            session = openSession();
397    
398                            Role[] array = new RoleImpl[3];
399    
400                            array[0] = getByUuid_PrevAndNext(session, role, uuid,
401                                            orderByComparator, true);
402    
403                            array[1] = role;
404    
405                            array[2] = getByUuid_PrevAndNext(session, role, uuid,
406                                            orderByComparator, false);
407    
408                            return array;
409                    }
410                    catch (Exception e) {
411                            throw processException(e);
412                    }
413                    finally {
414                            closeSession(session);
415                    }
416            }
417    
418            protected Role getByUuid_PrevAndNext(Session session, Role role,
419                    String uuid, OrderByComparator orderByComparator, boolean previous) {
420                    StringBundler query = null;
421    
422                    if (orderByComparator != null) {
423                            query = new StringBundler(6 +
424                                            (orderByComparator.getOrderByFields().length * 6));
425                    }
426                    else {
427                            query = new StringBundler(3);
428                    }
429    
430                    query.append(_SQL_SELECT_ROLE_WHERE);
431    
432                    boolean bindUuid = false;
433    
434                    if (uuid == null) {
435                            query.append(_FINDER_COLUMN_UUID_UUID_1);
436                    }
437                    else if (uuid.equals(StringPool.BLANK)) {
438                            query.append(_FINDER_COLUMN_UUID_UUID_3);
439                    }
440                    else {
441                            bindUuid = true;
442    
443                            query.append(_FINDER_COLUMN_UUID_UUID_2);
444                    }
445    
446                    if (orderByComparator != null) {
447                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
448    
449                            if (orderByConditionFields.length > 0) {
450                                    query.append(WHERE_AND);
451                            }
452    
453                            for (int i = 0; i < orderByConditionFields.length; i++) {
454                                    query.append(_ORDER_BY_ENTITY_ALIAS);
455                                    query.append(orderByConditionFields[i]);
456    
457                                    if ((i + 1) < orderByConditionFields.length) {
458                                            if (orderByComparator.isAscending() ^ previous) {
459                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
460                                            }
461                                            else {
462                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
463                                            }
464                                    }
465                                    else {
466                                            if (orderByComparator.isAscending() ^ previous) {
467                                                    query.append(WHERE_GREATER_THAN);
468                                            }
469                                            else {
470                                                    query.append(WHERE_LESSER_THAN);
471                                            }
472                                    }
473                            }
474    
475                            query.append(ORDER_BY_CLAUSE);
476    
477                            String[] orderByFields = orderByComparator.getOrderByFields();
478    
479                            for (int i = 0; i < orderByFields.length; i++) {
480                                    query.append(_ORDER_BY_ENTITY_ALIAS);
481                                    query.append(orderByFields[i]);
482    
483                                    if ((i + 1) < orderByFields.length) {
484                                            if (orderByComparator.isAscending() ^ previous) {
485                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
486                                            }
487                                            else {
488                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
489                                            }
490                                    }
491                                    else {
492                                            if (orderByComparator.isAscending() ^ previous) {
493                                                    query.append(ORDER_BY_ASC);
494                                            }
495                                            else {
496                                                    query.append(ORDER_BY_DESC);
497                                            }
498                                    }
499                            }
500                    }
501                    else {
502                            query.append(RoleModelImpl.ORDER_BY_JPQL);
503                    }
504    
505                    String sql = query.toString();
506    
507                    Query q = session.createQuery(sql);
508    
509                    q.setFirstResult(0);
510                    q.setMaxResults(2);
511    
512                    QueryPos qPos = QueryPos.getInstance(q);
513    
514                    if (bindUuid) {
515                            qPos.add(uuid);
516                    }
517    
518                    if (orderByComparator != null) {
519                            Object[] values = orderByComparator.getOrderByConditionValues(role);
520    
521                            for (Object value : values) {
522                                    qPos.add(value);
523                            }
524                    }
525    
526                    List<Role> list = q.list();
527    
528                    if (list.size() == 2) {
529                            return list.get(1);
530                    }
531                    else {
532                            return null;
533                    }
534            }
535    
536            /**
537             * Returns all the roles that the user has permission to view where uuid = &#63;.
538             *
539             * @param uuid the uuid
540             * @return the matching roles that the user has permission to view
541             * @throws SystemException if a system exception occurred
542             */
543            @Override
544            public List<Role> filterFindByUuid(String uuid) throws SystemException {
545                    return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
546            }
547    
548            /**
549             * Returns a range of all the roles that the user has permission to view where uuid = &#63;.
550             *
551             * <p>
552             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
553             * </p>
554             *
555             * @param uuid the uuid
556             * @param start the lower bound of the range of roles
557             * @param end the upper bound of the range of roles (not inclusive)
558             * @return the range of matching roles that the user has permission to view
559             * @throws SystemException if a system exception occurred
560             */
561            @Override
562            public List<Role> filterFindByUuid(String uuid, int start, int end)
563                    throws SystemException {
564                    return filterFindByUuid(uuid, start, end, null);
565            }
566    
567            /**
568             * Returns an ordered range of all the roles that the user has permissions to view where uuid = &#63;.
569             *
570             * <p>
571             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
572             * </p>
573             *
574             * @param uuid the uuid
575             * @param start the lower bound of the range of roles
576             * @param end the upper bound of the range of roles (not inclusive)
577             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
578             * @return the ordered range of matching roles that the user has permission to view
579             * @throws SystemException if a system exception occurred
580             */
581            @Override
582            public List<Role> filterFindByUuid(String uuid, int start, int end,
583                    OrderByComparator orderByComparator) throws SystemException {
584                    if (!InlineSQLHelperUtil.isEnabled()) {
585                            return findByUuid(uuid, start, end, orderByComparator);
586                    }
587    
588                    StringBundler query = null;
589    
590                    if (orderByComparator != null) {
591                            query = new StringBundler(3 +
592                                            (orderByComparator.getOrderByFields().length * 3));
593                    }
594                    else {
595                            query = new StringBundler(3);
596                    }
597    
598                    if (getDB().isSupportsInlineDistinct()) {
599                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
600                    }
601                    else {
602                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
603                    }
604    
605                    boolean bindUuid = false;
606    
607                    if (uuid == null) {
608                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
609                    }
610                    else if (uuid.equals(StringPool.BLANK)) {
611                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
612                    }
613                    else {
614                            bindUuid = true;
615    
616                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
617                    }
618    
619                    if (!getDB().isSupportsInlineDistinct()) {
620                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
621                    }
622    
623                    if (orderByComparator != null) {
624                            if (getDB().isSupportsInlineDistinct()) {
625                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
626                                            orderByComparator, true);
627                            }
628                            else {
629                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
630                                            orderByComparator, true);
631                            }
632                    }
633                    else {
634                            if (getDB().isSupportsInlineDistinct()) {
635                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
636                            }
637                            else {
638                                    query.append(RoleModelImpl.ORDER_BY_SQL);
639                            }
640                    }
641    
642                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
643                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
644    
645                    Session session = null;
646    
647                    try {
648                            session = openSession();
649    
650                            SQLQuery q = session.createSQLQuery(sql);
651    
652                            if (getDB().isSupportsInlineDistinct()) {
653                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
654                            }
655                            else {
656                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
657                            }
658    
659                            QueryPos qPos = QueryPos.getInstance(q);
660    
661                            if (bindUuid) {
662                                    qPos.add(uuid);
663                            }
664    
665                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
666                    }
667                    catch (Exception e) {
668                            throw processException(e);
669                    }
670                    finally {
671                            closeSession(session);
672                    }
673            }
674    
675            /**
676             * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where uuid = &#63;.
677             *
678             * @param roleId the primary key of the current role
679             * @param uuid the uuid
680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
681             * @return the previous, current, and next role
682             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
683             * @throws SystemException if a system exception occurred
684             */
685            @Override
686            public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid,
687                    OrderByComparator orderByComparator)
688                    throws NoSuchRoleException, SystemException {
689                    if (!InlineSQLHelperUtil.isEnabled()) {
690                            return findByUuid_PrevAndNext(roleId, uuid, orderByComparator);
691                    }
692    
693                    Role role = findByPrimaryKey(roleId);
694    
695                    Session session = null;
696    
697                    try {
698                            session = openSession();
699    
700                            Role[] array = new RoleImpl[3];
701    
702                            array[0] = filterGetByUuid_PrevAndNext(session, role, uuid,
703                                            orderByComparator, true);
704    
705                            array[1] = role;
706    
707                            array[2] = filterGetByUuid_PrevAndNext(session, role, uuid,
708                                            orderByComparator, false);
709    
710                            return array;
711                    }
712                    catch (Exception e) {
713                            throw processException(e);
714                    }
715                    finally {
716                            closeSession(session);
717                    }
718            }
719    
720            protected Role filterGetByUuid_PrevAndNext(Session session, Role role,
721                    String uuid, OrderByComparator orderByComparator, boolean previous) {
722                    StringBundler query = null;
723    
724                    if (orderByComparator != null) {
725                            query = new StringBundler(6 +
726                                            (orderByComparator.getOrderByFields().length * 6));
727                    }
728                    else {
729                            query = new StringBundler(3);
730                    }
731    
732                    if (getDB().isSupportsInlineDistinct()) {
733                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
734                    }
735                    else {
736                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
737                    }
738    
739                    boolean bindUuid = false;
740    
741                    if (uuid == null) {
742                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
743                    }
744                    else if (uuid.equals(StringPool.BLANK)) {
745                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
746                    }
747                    else {
748                            bindUuid = true;
749    
750                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
751                    }
752    
753                    if (!getDB().isSupportsInlineDistinct()) {
754                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
755                    }
756    
757                    if (orderByComparator != null) {
758                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
759    
760                            if (orderByConditionFields.length > 0) {
761                                    query.append(WHERE_AND);
762                            }
763    
764                            for (int i = 0; i < orderByConditionFields.length; i++) {
765                                    if (getDB().isSupportsInlineDistinct()) {
766                                            query.append(_ORDER_BY_ENTITY_ALIAS);
767                                    }
768                                    else {
769                                            query.append(_ORDER_BY_ENTITY_TABLE);
770                                    }
771    
772                                    query.append(orderByConditionFields[i]);
773    
774                                    if ((i + 1) < orderByConditionFields.length) {
775                                            if (orderByComparator.isAscending() ^ previous) {
776                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
777                                            }
778                                            else {
779                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
780                                            }
781                                    }
782                                    else {
783                                            if (orderByComparator.isAscending() ^ previous) {
784                                                    query.append(WHERE_GREATER_THAN);
785                                            }
786                                            else {
787                                                    query.append(WHERE_LESSER_THAN);
788                                            }
789                                    }
790                            }
791    
792                            query.append(ORDER_BY_CLAUSE);
793    
794                            String[] orderByFields = orderByComparator.getOrderByFields();
795    
796                            for (int i = 0; i < orderByFields.length; i++) {
797                                    if (getDB().isSupportsInlineDistinct()) {
798                                            query.append(_ORDER_BY_ENTITY_ALIAS);
799                                    }
800                                    else {
801                                            query.append(_ORDER_BY_ENTITY_TABLE);
802                                    }
803    
804                                    query.append(orderByFields[i]);
805    
806                                    if ((i + 1) < orderByFields.length) {
807                                            if (orderByComparator.isAscending() ^ previous) {
808                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
809                                            }
810                                            else {
811                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
812                                            }
813                                    }
814                                    else {
815                                            if (orderByComparator.isAscending() ^ previous) {
816                                                    query.append(ORDER_BY_ASC);
817                                            }
818                                            else {
819                                                    query.append(ORDER_BY_DESC);
820                                            }
821                                    }
822                            }
823                    }
824                    else {
825                            if (getDB().isSupportsInlineDistinct()) {
826                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
827                            }
828                            else {
829                                    query.append(RoleModelImpl.ORDER_BY_SQL);
830                            }
831                    }
832    
833                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
834                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
835    
836                    SQLQuery q = session.createSQLQuery(sql);
837    
838                    q.setFirstResult(0);
839                    q.setMaxResults(2);
840    
841                    if (getDB().isSupportsInlineDistinct()) {
842                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
843                    }
844                    else {
845                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
846                    }
847    
848                    QueryPos qPos = QueryPos.getInstance(q);
849    
850                    if (bindUuid) {
851                            qPos.add(uuid);
852                    }
853    
854                    if (orderByComparator != null) {
855                            Object[] values = orderByComparator.getOrderByConditionValues(role);
856    
857                            for (Object value : values) {
858                                    qPos.add(value);
859                            }
860                    }
861    
862                    List<Role> list = q.list();
863    
864                    if (list.size() == 2) {
865                            return list.get(1);
866                    }
867                    else {
868                            return null;
869                    }
870            }
871    
872            /**
873             * Removes all the roles where uuid = &#63; from the database.
874             *
875             * @param uuid the uuid
876             * @throws SystemException if a system exception occurred
877             */
878            @Override
879            public void removeByUuid(String uuid) throws SystemException {
880                    for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
881                                    null)) {
882                            remove(role);
883                    }
884            }
885    
886            /**
887             * Returns the number of roles where uuid = &#63;.
888             *
889             * @param uuid the uuid
890             * @return the number of matching roles
891             * @throws SystemException if a system exception occurred
892             */
893            @Override
894            public int countByUuid(String uuid) throws SystemException {
895                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
896    
897                    Object[] finderArgs = new Object[] { uuid };
898    
899                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
900                                    this);
901    
902                    if (count == null) {
903                            StringBundler query = new StringBundler(2);
904    
905                            query.append(_SQL_COUNT_ROLE_WHERE);
906    
907                            boolean bindUuid = false;
908    
909                            if (uuid == null) {
910                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
911                            }
912                            else if (uuid.equals(StringPool.BLANK)) {
913                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
914                            }
915                            else {
916                                    bindUuid = true;
917    
918                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
919                            }
920    
921                            String sql = query.toString();
922    
923                            Session session = null;
924    
925                            try {
926                                    session = openSession();
927    
928                                    Query q = session.createQuery(sql);
929    
930                                    QueryPos qPos = QueryPos.getInstance(q);
931    
932                                    if (bindUuid) {
933                                            qPos.add(uuid);
934                                    }
935    
936                                    count = (Long)q.uniqueResult();
937    
938                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
939                            }
940                            catch (Exception e) {
941                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
942    
943                                    throw processException(e);
944                            }
945                            finally {
946                                    closeSession(session);
947                            }
948                    }
949    
950                    return count.intValue();
951            }
952    
953            /**
954             * Returns the number of roles that the user has permission to view where uuid = &#63;.
955             *
956             * @param uuid the uuid
957             * @return the number of matching roles that the user has permission to view
958             * @throws SystemException if a system exception occurred
959             */
960            @Override
961            public int filterCountByUuid(String uuid) throws SystemException {
962                    if (!InlineSQLHelperUtil.isEnabled()) {
963                            return countByUuid(uuid);
964                    }
965    
966                    StringBundler query = new StringBundler(2);
967    
968                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
969    
970                    boolean bindUuid = false;
971    
972                    if (uuid == null) {
973                            query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
974                    }
975                    else if (uuid.equals(StringPool.BLANK)) {
976                            query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
977                    }
978                    else {
979                            bindUuid = true;
980    
981                            query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
982                    }
983    
984                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
985                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
986    
987                    Session session = null;
988    
989                    try {
990                            session = openSession();
991    
992                            SQLQuery q = session.createSQLQuery(sql);
993    
994                            q.addScalar(COUNT_COLUMN_NAME,
995                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
996    
997                            QueryPos qPos = QueryPos.getInstance(q);
998    
999                            if (bindUuid) {
1000                                    qPos.add(uuid);
1001                            }
1002    
1003                            Long count = (Long)q.uniqueResult();
1004    
1005                            return count.intValue();
1006                    }
1007                    catch (Exception e) {
1008                            throw processException(e);
1009                    }
1010                    finally {
1011                            closeSession(session);
1012                    }
1013            }
1014    
1015            private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL";
1016            private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?";
1017            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')";
1018            private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL";
1019            private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?";
1020            private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')";
1021            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1022                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1023                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1024                            new String[] {
1025                                    String.class.getName(), Long.class.getName(),
1026                                    
1027                            Integer.class.getName(), Integer.class.getName(),
1028                                    OrderByComparator.class.getName()
1029                            });
1030            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1031                    new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1032                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1033                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1034                            new String[] { String.class.getName(), Long.class.getName() },
1035                            RoleModelImpl.UUID_COLUMN_BITMASK |
1036                            RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1037                            RoleModelImpl.NAME_COLUMN_BITMASK);
1038            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1039                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1040                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1041                            new String[] { String.class.getName(), Long.class.getName() });
1042    
1043            /**
1044             * Returns all the roles where uuid = &#63; and companyId = &#63;.
1045             *
1046             * @param uuid the uuid
1047             * @param companyId the company ID
1048             * @return the matching roles
1049             * @throws SystemException if a system exception occurred
1050             */
1051            @Override
1052            public List<Role> findByUuid_C(String uuid, long companyId)
1053                    throws SystemException {
1054                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1055                            QueryUtil.ALL_POS, null);
1056            }
1057    
1058            /**
1059             * Returns a range of all the roles where uuid = &#63; and companyId = &#63;.
1060             *
1061             * <p>
1062             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1063             * </p>
1064             *
1065             * @param uuid the uuid
1066             * @param companyId the company ID
1067             * @param start the lower bound of the range of roles
1068             * @param end the upper bound of the range of roles (not inclusive)
1069             * @return the range of matching roles
1070             * @throws SystemException if a system exception occurred
1071             */
1072            @Override
1073            public List<Role> findByUuid_C(String uuid, long companyId, int start,
1074                    int end) throws SystemException {
1075                    return findByUuid_C(uuid, companyId, start, end, null);
1076            }
1077    
1078            /**
1079             * Returns an ordered range of all the roles where uuid = &#63; and companyId = &#63;.
1080             *
1081             * <p>
1082             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1083             * </p>
1084             *
1085             * @param uuid the uuid
1086             * @param companyId the company ID
1087             * @param start the lower bound of the range of roles
1088             * @param end the upper bound of the range of roles (not inclusive)
1089             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1090             * @return the ordered range of matching roles
1091             * @throws SystemException if a system exception occurred
1092             */
1093            @Override
1094            public List<Role> findByUuid_C(String uuid, long companyId, int start,
1095                    int end, OrderByComparator orderByComparator) throws SystemException {
1096                    boolean pagination = true;
1097                    FinderPath finderPath = null;
1098                    Object[] finderArgs = null;
1099    
1100                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1101                                    (orderByComparator == null)) {
1102                            pagination = false;
1103                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1104                            finderArgs = new Object[] { uuid, companyId };
1105                    }
1106                    else {
1107                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1108                            finderArgs = new Object[] {
1109                                            uuid, companyId,
1110                                            
1111                                            start, end, orderByComparator
1112                                    };
1113                    }
1114    
1115                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1116                                    finderArgs, this);
1117    
1118                    if ((list != null) && !list.isEmpty()) {
1119                            for (Role role : list) {
1120                                    if (!Validator.equals(uuid, role.getUuid()) ||
1121                                                    (companyId != role.getCompanyId())) {
1122                                            list = null;
1123    
1124                                            break;
1125                                    }
1126                            }
1127                    }
1128    
1129                    if (list == null) {
1130                            StringBundler query = null;
1131    
1132                            if (orderByComparator != null) {
1133                                    query = new StringBundler(4 +
1134                                                    (orderByComparator.getOrderByFields().length * 3));
1135                            }
1136                            else {
1137                                    query = new StringBundler(4);
1138                            }
1139    
1140                            query.append(_SQL_SELECT_ROLE_WHERE);
1141    
1142                            boolean bindUuid = false;
1143    
1144                            if (uuid == null) {
1145                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1146                            }
1147                            else if (uuid.equals(StringPool.BLANK)) {
1148                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1149                            }
1150                            else {
1151                                    bindUuid = true;
1152    
1153                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1154                            }
1155    
1156                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1157    
1158                            if (orderByComparator != null) {
1159                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1160                                            orderByComparator);
1161                            }
1162                            else
1163                             if (pagination) {
1164                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
1165                            }
1166    
1167                            String sql = query.toString();
1168    
1169                            Session session = null;
1170    
1171                            try {
1172                                    session = openSession();
1173    
1174                                    Query q = session.createQuery(sql);
1175    
1176                                    QueryPos qPos = QueryPos.getInstance(q);
1177    
1178                                    if (bindUuid) {
1179                                            qPos.add(uuid);
1180                                    }
1181    
1182                                    qPos.add(companyId);
1183    
1184                                    if (!pagination) {
1185                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1186                                                            end, false);
1187    
1188                                            Collections.sort(list);
1189    
1190                                            list = new UnmodifiableList<Role>(list);
1191                                    }
1192                                    else {
1193                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1194                                                            end);
1195                                    }
1196    
1197                                    cacheResult(list);
1198    
1199                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1200                            }
1201                            catch (Exception e) {
1202                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1203    
1204                                    throw processException(e);
1205                            }
1206                            finally {
1207                                    closeSession(session);
1208                            }
1209                    }
1210    
1211                    return list;
1212            }
1213    
1214            /**
1215             * Returns the first role in the ordered set where uuid = &#63; and companyId = &#63;.
1216             *
1217             * @param uuid the uuid
1218             * @param companyId the company ID
1219             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1220             * @return the first matching role
1221             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1222             * @throws SystemException if a system exception occurred
1223             */
1224            @Override
1225            public Role findByUuid_C_First(String uuid, long companyId,
1226                    OrderByComparator orderByComparator)
1227                    throws NoSuchRoleException, SystemException {
1228                    Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1229    
1230                    if (role != null) {
1231                            return role;
1232                    }
1233    
1234                    StringBundler msg = new StringBundler(6);
1235    
1236                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1237    
1238                    msg.append("uuid=");
1239                    msg.append(uuid);
1240    
1241                    msg.append(", companyId=");
1242                    msg.append(companyId);
1243    
1244                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1245    
1246                    throw new NoSuchRoleException(msg.toString());
1247            }
1248    
1249            /**
1250             * Returns the first role in the ordered set where uuid = &#63; and companyId = &#63;.
1251             *
1252             * @param uuid the uuid
1253             * @param companyId the company ID
1254             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1255             * @return the first matching role, or <code>null</code> if a matching role could not be found
1256             * @throws SystemException if a system exception occurred
1257             */
1258            @Override
1259            public Role fetchByUuid_C_First(String uuid, long companyId,
1260                    OrderByComparator orderByComparator) throws SystemException {
1261                    List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1262    
1263                    if (!list.isEmpty()) {
1264                            return list.get(0);
1265                    }
1266    
1267                    return null;
1268            }
1269    
1270            /**
1271             * Returns the last role in the ordered set where uuid = &#63; and companyId = &#63;.
1272             *
1273             * @param uuid the uuid
1274             * @param companyId the company ID
1275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1276             * @return the last matching role
1277             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1278             * @throws SystemException if a system exception occurred
1279             */
1280            @Override
1281            public Role findByUuid_C_Last(String uuid, long companyId,
1282                    OrderByComparator orderByComparator)
1283                    throws NoSuchRoleException, SystemException {
1284                    Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1285    
1286                    if (role != null) {
1287                            return role;
1288                    }
1289    
1290                    StringBundler msg = new StringBundler(6);
1291    
1292                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1293    
1294                    msg.append("uuid=");
1295                    msg.append(uuid);
1296    
1297                    msg.append(", companyId=");
1298                    msg.append(companyId);
1299    
1300                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1301    
1302                    throw new NoSuchRoleException(msg.toString());
1303            }
1304    
1305            /**
1306             * Returns the last role in the ordered set where uuid = &#63; and companyId = &#63;.
1307             *
1308             * @param uuid the uuid
1309             * @param companyId the company ID
1310             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1311             * @return the last matching role, or <code>null</code> if a matching role could not be found
1312             * @throws SystemException if a system exception occurred
1313             */
1314            @Override
1315            public Role fetchByUuid_C_Last(String uuid, long companyId,
1316                    OrderByComparator orderByComparator) throws SystemException {
1317                    int count = countByUuid_C(uuid, companyId);
1318    
1319                    if (count == 0) {
1320                            return null;
1321                    }
1322    
1323                    List<Role> list = findByUuid_C(uuid, companyId, count - 1, count,
1324                                    orderByComparator);
1325    
1326                    if (!list.isEmpty()) {
1327                            return list.get(0);
1328                    }
1329    
1330                    return null;
1331            }
1332    
1333            /**
1334             * Returns the roles before and after the current role in the ordered set where uuid = &#63; and companyId = &#63;.
1335             *
1336             * @param roleId the primary key of the current role
1337             * @param uuid the uuid
1338             * @param companyId the company ID
1339             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1340             * @return the previous, current, and next role
1341             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
1342             * @throws SystemException if a system exception occurred
1343             */
1344            @Override
1345            public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid,
1346                    long companyId, OrderByComparator orderByComparator)
1347                    throws NoSuchRoleException, SystemException {
1348                    Role role = findByPrimaryKey(roleId);
1349    
1350                    Session session = null;
1351    
1352                    try {
1353                            session = openSession();
1354    
1355                            Role[] array = new RoleImpl[3];
1356    
1357                            array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1358                                            orderByComparator, true);
1359    
1360                            array[1] = role;
1361    
1362                            array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1363                                            orderByComparator, false);
1364    
1365                            return array;
1366                    }
1367                    catch (Exception e) {
1368                            throw processException(e);
1369                    }
1370                    finally {
1371                            closeSession(session);
1372                    }
1373            }
1374    
1375            protected Role getByUuid_C_PrevAndNext(Session session, Role role,
1376                    String uuid, long companyId, OrderByComparator orderByComparator,
1377                    boolean previous) {
1378                    StringBundler query = null;
1379    
1380                    if (orderByComparator != null) {
1381                            query = new StringBundler(6 +
1382                                            (orderByComparator.getOrderByFields().length * 6));
1383                    }
1384                    else {
1385                            query = new StringBundler(3);
1386                    }
1387    
1388                    query.append(_SQL_SELECT_ROLE_WHERE);
1389    
1390                    boolean bindUuid = false;
1391    
1392                    if (uuid == null) {
1393                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1394                    }
1395                    else if (uuid.equals(StringPool.BLANK)) {
1396                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1397                    }
1398                    else {
1399                            bindUuid = true;
1400    
1401                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1402                    }
1403    
1404                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1405    
1406                    if (orderByComparator != null) {
1407                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1408    
1409                            if (orderByConditionFields.length > 0) {
1410                                    query.append(WHERE_AND);
1411                            }
1412    
1413                            for (int i = 0; i < orderByConditionFields.length; i++) {
1414                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1415                                    query.append(orderByConditionFields[i]);
1416    
1417                                    if ((i + 1) < orderByConditionFields.length) {
1418                                            if (orderByComparator.isAscending() ^ previous) {
1419                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1420                                            }
1421                                            else {
1422                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1423                                            }
1424                                    }
1425                                    else {
1426                                            if (orderByComparator.isAscending() ^ previous) {
1427                                                    query.append(WHERE_GREATER_THAN);
1428                                            }
1429                                            else {
1430                                                    query.append(WHERE_LESSER_THAN);
1431                                            }
1432                                    }
1433                            }
1434    
1435                            query.append(ORDER_BY_CLAUSE);
1436    
1437                            String[] orderByFields = orderByComparator.getOrderByFields();
1438    
1439                            for (int i = 0; i < orderByFields.length; i++) {
1440                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1441                                    query.append(orderByFields[i]);
1442    
1443                                    if ((i + 1) < orderByFields.length) {
1444                                            if (orderByComparator.isAscending() ^ previous) {
1445                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1446                                            }
1447                                            else {
1448                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1449                                            }
1450                                    }
1451                                    else {
1452                                            if (orderByComparator.isAscending() ^ previous) {
1453                                                    query.append(ORDER_BY_ASC);
1454                                            }
1455                                            else {
1456                                                    query.append(ORDER_BY_DESC);
1457                                            }
1458                                    }
1459                            }
1460                    }
1461                    else {
1462                            query.append(RoleModelImpl.ORDER_BY_JPQL);
1463                    }
1464    
1465                    String sql = query.toString();
1466    
1467                    Query q = session.createQuery(sql);
1468    
1469                    q.setFirstResult(0);
1470                    q.setMaxResults(2);
1471    
1472                    QueryPos qPos = QueryPos.getInstance(q);
1473    
1474                    if (bindUuid) {
1475                            qPos.add(uuid);
1476                    }
1477    
1478                    qPos.add(companyId);
1479    
1480                    if (orderByComparator != null) {
1481                            Object[] values = orderByComparator.getOrderByConditionValues(role);
1482    
1483                            for (Object value : values) {
1484                                    qPos.add(value);
1485                            }
1486                    }
1487    
1488                    List<Role> list = q.list();
1489    
1490                    if (list.size() == 2) {
1491                            return list.get(1);
1492                    }
1493                    else {
1494                            return null;
1495                    }
1496            }
1497    
1498            /**
1499             * Returns all the roles that the user has permission to view where uuid = &#63; and companyId = &#63;.
1500             *
1501             * @param uuid the uuid
1502             * @param companyId the company ID
1503             * @return the matching roles that the user has permission to view
1504             * @throws SystemException if a system exception occurred
1505             */
1506            @Override
1507            public List<Role> filterFindByUuid_C(String uuid, long companyId)
1508                    throws SystemException {
1509                    return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1510                            QueryUtil.ALL_POS, null);
1511            }
1512    
1513            /**
1514             * Returns a range of all the roles that the user has permission to view where uuid = &#63; and companyId = &#63;.
1515             *
1516             * <p>
1517             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1518             * </p>
1519             *
1520             * @param uuid the uuid
1521             * @param companyId the company ID
1522             * @param start the lower bound of the range of roles
1523             * @param end the upper bound of the range of roles (not inclusive)
1524             * @return the range of matching roles that the user has permission to view
1525             * @throws SystemException if a system exception occurred
1526             */
1527            @Override
1528            public List<Role> filterFindByUuid_C(String uuid, long companyId,
1529                    int start, int end) throws SystemException {
1530                    return filterFindByUuid_C(uuid, companyId, start, end, null);
1531            }
1532    
1533            /**
1534             * Returns an ordered range of all the roles that the user has permissions to view where uuid = &#63; and companyId = &#63;.
1535             *
1536             * <p>
1537             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1538             * </p>
1539             *
1540             * @param uuid the uuid
1541             * @param companyId the company ID
1542             * @param start the lower bound of the range of roles
1543             * @param end the upper bound of the range of roles (not inclusive)
1544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1545             * @return the ordered range of matching roles that the user has permission to view
1546             * @throws SystemException if a system exception occurred
1547             */
1548            @Override
1549            public List<Role> filterFindByUuid_C(String uuid, long companyId,
1550                    int start, int end, OrderByComparator orderByComparator)
1551                    throws SystemException {
1552                    if (!InlineSQLHelperUtil.isEnabled()) {
1553                            return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1554                    }
1555    
1556                    StringBundler query = null;
1557    
1558                    if (orderByComparator != null) {
1559                            query = new StringBundler(4 +
1560                                            (orderByComparator.getOrderByFields().length * 3));
1561                    }
1562                    else {
1563                            query = new StringBundler(4);
1564                    }
1565    
1566                    if (getDB().isSupportsInlineDistinct()) {
1567                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1568                    }
1569                    else {
1570                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1571                    }
1572    
1573                    boolean bindUuid = false;
1574    
1575                    if (uuid == null) {
1576                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1577                    }
1578                    else if (uuid.equals(StringPool.BLANK)) {
1579                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1580                    }
1581                    else {
1582                            bindUuid = true;
1583    
1584                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1585                    }
1586    
1587                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1588    
1589                    if (!getDB().isSupportsInlineDistinct()) {
1590                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1591                    }
1592    
1593                    if (orderByComparator != null) {
1594                            if (getDB().isSupportsInlineDistinct()) {
1595                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1596                                            orderByComparator, true);
1597                            }
1598                            else {
1599                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1600                                            orderByComparator, true);
1601                            }
1602                    }
1603                    else {
1604                            if (getDB().isSupportsInlineDistinct()) {
1605                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
1606                            }
1607                            else {
1608                                    query.append(RoleModelImpl.ORDER_BY_SQL);
1609                            }
1610                    }
1611    
1612                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1613                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1614    
1615                    Session session = null;
1616    
1617                    try {
1618                            session = openSession();
1619    
1620                            SQLQuery q = session.createSQLQuery(sql);
1621    
1622                            if (getDB().isSupportsInlineDistinct()) {
1623                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1624                            }
1625                            else {
1626                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1627                            }
1628    
1629                            QueryPos qPos = QueryPos.getInstance(q);
1630    
1631                            if (bindUuid) {
1632                                    qPos.add(uuid);
1633                            }
1634    
1635                            qPos.add(companyId);
1636    
1637                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1638                    }
1639                    catch (Exception e) {
1640                            throw processException(e);
1641                    }
1642                    finally {
1643                            closeSession(session);
1644                    }
1645            }
1646    
1647            /**
1648             * Returns the roles before and after the current role in the ordered set of roles that the user has permission to view where uuid = &#63; and companyId = &#63;.
1649             *
1650             * @param roleId the primary key of the current role
1651             * @param uuid the uuid
1652             * @param companyId the company ID
1653             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1654             * @return the previous, current, and next role
1655             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
1656             * @throws SystemException if a system exception occurred
1657             */
1658            @Override
1659            public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid,
1660                    long companyId, OrderByComparator orderByComparator)
1661                    throws NoSuchRoleException, SystemException {
1662                    if (!InlineSQLHelperUtil.isEnabled()) {
1663                            return findByUuid_C_PrevAndNext(roleId, uuid, companyId,
1664                                    orderByComparator);
1665                    }
1666    
1667                    Role role = findByPrimaryKey(roleId);
1668    
1669                    Session session = null;
1670    
1671                    try {
1672                            session = openSession();
1673    
1674                            Role[] array = new RoleImpl[3];
1675    
1676                            array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1677                                            companyId, orderByComparator, true);
1678    
1679                            array[1] = role;
1680    
1681                            array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1682                                            companyId, orderByComparator, false);
1683    
1684                            return array;
1685                    }
1686                    catch (Exception e) {
1687                            throw processException(e);
1688                    }
1689                    finally {
1690                            closeSession(session);
1691                    }
1692            }
1693    
1694            protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role,
1695                    String uuid, long companyId, OrderByComparator orderByComparator,
1696                    boolean previous) {
1697                    StringBundler query = null;
1698    
1699                    if (orderByComparator != null) {
1700                            query = new StringBundler(6 +
1701                                            (orderByComparator.getOrderByFields().length * 6));
1702                    }
1703                    else {
1704                            query = new StringBundler(3);
1705                    }
1706    
1707                    if (getDB().isSupportsInlineDistinct()) {
1708                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1709                    }
1710                    else {
1711                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1712                    }
1713    
1714                    boolean bindUuid = false;
1715    
1716                    if (uuid == null) {
1717                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1718                    }
1719                    else if (uuid.equals(StringPool.BLANK)) {
1720                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1721                    }
1722                    else {
1723                            bindUuid = true;
1724    
1725                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1726                    }
1727    
1728                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1729    
1730                    if (!getDB().isSupportsInlineDistinct()) {
1731                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1732                    }
1733    
1734                    if (orderByComparator != null) {
1735                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1736    
1737                            if (orderByConditionFields.length > 0) {
1738                                    query.append(WHERE_AND);
1739                            }
1740    
1741                            for (int i = 0; i < orderByConditionFields.length; i++) {
1742                                    if (getDB().isSupportsInlineDistinct()) {
1743                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1744                                    }
1745                                    else {
1746                                            query.append(_ORDER_BY_ENTITY_TABLE);
1747                                    }
1748    
1749                                    query.append(orderByConditionFields[i]);
1750    
1751                                    if ((i + 1) < orderByConditionFields.length) {
1752                                            if (orderByComparator.isAscending() ^ previous) {
1753                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1754                                            }
1755                                            else {
1756                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1757                                            }
1758                                    }
1759                                    else {
1760                                            if (orderByComparator.isAscending() ^ previous) {
1761                                                    query.append(WHERE_GREATER_THAN);
1762                                            }
1763                                            else {
1764                                                    query.append(WHERE_LESSER_THAN);
1765                                            }
1766                                    }
1767                            }
1768    
1769                            query.append(ORDER_BY_CLAUSE);
1770    
1771                            String[] orderByFields = orderByComparator.getOrderByFields();
1772    
1773                            for (int i = 0; i < orderByFields.length; i++) {
1774                                    if (getDB().isSupportsInlineDistinct()) {
1775                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1776                                    }
1777                                    else {
1778                                            query.append(_ORDER_BY_ENTITY_TABLE);
1779                                    }
1780    
1781                                    query.append(orderByFields[i]);
1782    
1783                                    if ((i + 1) < orderByFields.length) {
1784                                            if (orderByComparator.isAscending() ^ previous) {
1785                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1786                                            }
1787                                            else {
1788                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1789                                            }
1790                                    }
1791                                    else {
1792                                            if (orderByComparator.isAscending() ^ previous) {
1793                                                    query.append(ORDER_BY_ASC);
1794                                            }
1795                                            else {
1796                                                    query.append(ORDER_BY_DESC);
1797                                            }
1798                                    }
1799                            }
1800                    }
1801                    else {
1802                            if (getDB().isSupportsInlineDistinct()) {
1803                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
1804                            }
1805                            else {
1806                                    query.append(RoleModelImpl.ORDER_BY_SQL);
1807                            }
1808                    }
1809    
1810                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1811                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1812    
1813                    SQLQuery q = session.createSQLQuery(sql);
1814    
1815                    q.setFirstResult(0);
1816                    q.setMaxResults(2);
1817    
1818                    if (getDB().isSupportsInlineDistinct()) {
1819                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1820                    }
1821                    else {
1822                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1823                    }
1824    
1825                    QueryPos qPos = QueryPos.getInstance(q);
1826    
1827                    if (bindUuid) {
1828                            qPos.add(uuid);
1829                    }
1830    
1831                    qPos.add(companyId);
1832    
1833                    if (orderByComparator != null) {
1834                            Object[] values = orderByComparator.getOrderByConditionValues(role);
1835    
1836                            for (Object value : values) {
1837                                    qPos.add(value);
1838                            }
1839                    }
1840    
1841                    List<Role> list = q.list();
1842    
1843                    if (list.size() == 2) {
1844                            return list.get(1);
1845                    }
1846                    else {
1847                            return null;
1848                    }
1849            }
1850    
1851            /**
1852             * Removes all the roles where uuid = &#63; and companyId = &#63; from the database.
1853             *
1854             * @param uuid the uuid
1855             * @param companyId the company ID
1856             * @throws SystemException if a system exception occurred
1857             */
1858            @Override
1859            public void removeByUuid_C(String uuid, long companyId)
1860                    throws SystemException {
1861                    for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1862                                    QueryUtil.ALL_POS, null)) {
1863                            remove(role);
1864                    }
1865            }
1866    
1867            /**
1868             * Returns the number of roles where uuid = &#63; and companyId = &#63;.
1869             *
1870             * @param uuid the uuid
1871             * @param companyId the company ID
1872             * @return the number of matching roles
1873             * @throws SystemException if a system exception occurred
1874             */
1875            @Override
1876            public int countByUuid_C(String uuid, long companyId)
1877                    throws SystemException {
1878                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1879    
1880                    Object[] finderArgs = new Object[] { uuid, companyId };
1881    
1882                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1883                                    this);
1884    
1885                    if (count == null) {
1886                            StringBundler query = new StringBundler(3);
1887    
1888                            query.append(_SQL_COUNT_ROLE_WHERE);
1889    
1890                            boolean bindUuid = false;
1891    
1892                            if (uuid == null) {
1893                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1894                            }
1895                            else if (uuid.equals(StringPool.BLANK)) {
1896                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1897                            }
1898                            else {
1899                                    bindUuid = true;
1900    
1901                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1902                            }
1903    
1904                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1905    
1906                            String sql = query.toString();
1907    
1908                            Session session = null;
1909    
1910                            try {
1911                                    session = openSession();
1912    
1913                                    Query q = session.createQuery(sql);
1914    
1915                                    QueryPos qPos = QueryPos.getInstance(q);
1916    
1917                                    if (bindUuid) {
1918                                            qPos.add(uuid);
1919                                    }
1920    
1921                                    qPos.add(companyId);
1922    
1923                                    count = (Long)q.uniqueResult();
1924    
1925                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1926                            }
1927                            catch (Exception e) {
1928                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1929    
1930                                    throw processException(e);
1931                            }
1932                            finally {
1933                                    closeSession(session);
1934                            }
1935                    }
1936    
1937                    return count.intValue();
1938            }
1939    
1940            /**
1941             * Returns the number of roles that the user has permission to view where uuid = &#63; and companyId = &#63;.
1942             *
1943             * @param uuid the uuid
1944             * @param companyId the company ID
1945             * @return the number of matching roles that the user has permission to view
1946             * @throws SystemException if a system exception occurred
1947             */
1948            @Override
1949            public int filterCountByUuid_C(String uuid, long companyId)
1950                    throws SystemException {
1951                    if (!InlineSQLHelperUtil.isEnabled()) {
1952                            return countByUuid_C(uuid, companyId);
1953                    }
1954    
1955                    StringBundler query = new StringBundler(3);
1956    
1957                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1958    
1959                    boolean bindUuid = false;
1960    
1961                    if (uuid == null) {
1962                            query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1963                    }
1964                    else if (uuid.equals(StringPool.BLANK)) {
1965                            query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1966                    }
1967                    else {
1968                            bindUuid = true;
1969    
1970                            query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1971                    }
1972    
1973                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1974    
1975                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1976                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1977    
1978                    Session session = null;
1979    
1980                    try {
1981                            session = openSession();
1982    
1983                            SQLQuery q = session.createSQLQuery(sql);
1984    
1985                            q.addScalar(COUNT_COLUMN_NAME,
1986                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1987    
1988                            QueryPos qPos = QueryPos.getInstance(q);
1989    
1990                            if (bindUuid) {
1991                                    qPos.add(uuid);
1992                            }
1993    
1994                            qPos.add(companyId);
1995    
1996                            Long count = (Long)q.uniqueResult();
1997    
1998                            return count.intValue();
1999                    }
2000                    catch (Exception e) {
2001                            throw processException(e);
2002                    }
2003                    finally {
2004                            closeSession(session);
2005                    }
2006            }
2007    
2008            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND ";
2009            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND ";
2010            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND ";
2011            private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND ";
2012            private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND ";
2013            private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND ";
2014            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?";
2015            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2016                    new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2017                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2018                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2019                            new String[] {
2020                                    Long.class.getName(),
2021                                    
2022                            Integer.class.getName(), Integer.class.getName(),
2023                                    OrderByComparator.class.getName()
2024                            });
2025            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2026                    new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2027                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2028                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2029                            new String[] { Long.class.getName() },
2030                            RoleModelImpl.COMPANYID_COLUMN_BITMASK |
2031                            RoleModelImpl.NAME_COLUMN_BITMASK);
2032            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2033                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2034                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2035                            new String[] { Long.class.getName() });
2036    
2037            /**
2038             * Returns all the roles where companyId = &#63;.
2039             *
2040             * @param companyId the company ID
2041             * @return the matching roles
2042             * @throws SystemException if a system exception occurred
2043             */
2044            @Override
2045            public List<Role> findByCompanyId(long companyId) throws SystemException {
2046                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2047                            null);
2048            }
2049    
2050            /**
2051             * Returns a range of all the roles where companyId = &#63;.
2052             *
2053             * <p>
2054             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2055             * </p>
2056             *
2057             * @param companyId the company ID
2058             * @param start the lower bound of the range of roles
2059             * @param end the upper bound of the range of roles (not inclusive)
2060             * @return the range of matching roles
2061             * @throws SystemException if a system exception occurred
2062             */
2063            @Override
2064            public List<Role> findByCompanyId(long companyId, int start, int end)
2065                    throws SystemException {
2066                    return findByCompanyId(companyId, start, end, null);
2067            }
2068    
2069            /**
2070             * Returns an ordered range of all the roles where companyId = &#63;.
2071             *
2072             * <p>
2073             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2074             * </p>
2075             *
2076             * @param companyId the company ID
2077             * @param start the lower bound of the range of roles
2078             * @param end the upper bound of the range of roles (not inclusive)
2079             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2080             * @return the ordered range of matching roles
2081             * @throws SystemException if a system exception occurred
2082             */
2083            @Override
2084            public List<Role> findByCompanyId(long companyId, int start, int end,
2085                    OrderByComparator orderByComparator) throws SystemException {
2086                    boolean pagination = true;
2087                    FinderPath finderPath = null;
2088                    Object[] finderArgs = null;
2089    
2090                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2091                                    (orderByComparator == null)) {
2092                            pagination = false;
2093                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2094                            finderArgs = new Object[] { companyId };
2095                    }
2096                    else {
2097                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2098                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2099                    }
2100    
2101                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2102                                    finderArgs, this);
2103    
2104                    if ((list != null) && !list.isEmpty()) {
2105                            for (Role role : list) {
2106                                    if ((companyId != role.getCompanyId())) {
2107                                            list = null;
2108    
2109                                            break;
2110                                    }
2111                            }
2112                    }
2113    
2114                    if (list == null) {
2115                            StringBundler query = null;
2116    
2117                            if (orderByComparator != null) {
2118                                    query = new StringBundler(3 +
2119                                                    (orderByComparator.getOrderByFields().length * 3));
2120                            }
2121                            else {
2122                                    query = new StringBundler(3);
2123                            }
2124    
2125                            query.append(_SQL_SELECT_ROLE_WHERE);
2126    
2127                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2128    
2129                            if (orderByComparator != null) {
2130                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2131                                            orderByComparator);
2132                            }
2133                            else
2134                             if (pagination) {
2135                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
2136                            }
2137    
2138                            String sql = query.toString();
2139    
2140                            Session session = null;
2141    
2142                            try {
2143                                    session = openSession();
2144    
2145                                    Query q = session.createQuery(sql);
2146    
2147                                    QueryPos qPos = QueryPos.getInstance(q);
2148    
2149                                    qPos.add(companyId);
2150    
2151                                    if (!pagination) {
2152                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2153                                                            end, false);
2154    
2155                                            Collections.sort(list);
2156    
2157                                            list = new UnmodifiableList<Role>(list);
2158                                    }
2159                                    else {
2160                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2161                                                            end);
2162                                    }
2163    
2164                                    cacheResult(list);
2165    
2166                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2167                            }
2168                            catch (Exception e) {
2169                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2170    
2171                                    throw processException(e);
2172                            }
2173                            finally {
2174                                    closeSession(session);
2175                            }
2176                    }
2177    
2178                    return list;
2179            }
2180    
2181            /**
2182             * Returns the first role in the ordered set where companyId = &#63;.
2183             *
2184             * @param companyId the company ID
2185             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2186             * @return the first matching role
2187             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
2188             * @throws SystemException if a system exception occurred
2189             */
2190            @Override
2191            public Role findByCompanyId_First(long companyId,
2192                    OrderByComparator orderByComparator)
2193                    throws NoSuchRoleException, SystemException {
2194                    Role role = fetchByCompanyId_First(companyId, orderByComparator);
2195    
2196                    if (role != null) {
2197                            return role;
2198                    }
2199    
2200                    StringBundler msg = new StringBundler(4);
2201    
2202                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2203    
2204                    msg.append("companyId=");
2205                    msg.append(companyId);
2206    
2207                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2208    
2209                    throw new NoSuchRoleException(msg.toString());
2210            }
2211    
2212            /**
2213             * Returns the first role in the ordered set where companyId = &#63;.
2214             *
2215             * @param companyId the company ID
2216             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2217             * @return the first matching role, or <code>null</code> if a matching role could not be found
2218             * @throws SystemException if a system exception occurred
2219             */
2220            @Override
2221            public Role fetchByCompanyId_First(long companyId,
2222                    OrderByComparator orderByComparator) throws SystemException {
2223                    List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2224    
2225                    if (!list.isEmpty()) {
2226                            return list.get(0);
2227                    }
2228    
2229                    return null;
2230            }
2231    
2232            /**
2233             * Returns the last role in the ordered set where companyId = &#63;.
2234             *
2235             * @param companyId the company ID
2236             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2237             * @return the last matching role
2238             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
2239             * @throws SystemException if a system exception occurred
2240             */
2241            @Override
2242            public Role findByCompanyId_Last(long companyId,
2243                    OrderByComparator orderByComparator)
2244                    throws NoSuchRoleException, SystemException {
2245                    Role role = fetchByCompanyId_Last(companyId, orderByComparator);
2246    
2247                    if (role != null) {
2248                            return role;
2249                    }
2250    
2251                    StringBundler msg = new StringBundler(4);
2252    
2253                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2254    
2255                    msg.append("companyId=");
2256                    msg.append(companyId);
2257    
2258                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2259    
2260                    throw new NoSuchRoleException(msg.toString());
2261            }
2262    
2263            /**
2264             * Returns the last role in the ordered set where companyId = &#63;.
2265             *
2266             * @param companyId the company ID
2267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2268             * @return the last matching role, or <code>null</code> if a matching role could not be found
2269             * @throws SystemException if a system exception occurred
2270             */
2271            @Override
2272            public Role fetchByCompanyId_Last(long companyId,
2273                    OrderByComparator orderByComparator) throws SystemException {
2274                    int count = countByCompanyId(companyId);
2275    
2276                    if (count == 0) {
2277                            return null;
2278                    }
2279    
2280                    List<Role> list = findByCompanyId(companyId, count - 1, count,
2281                                    orderByComparator);
2282    
2283                    if (!list.isEmpty()) {
2284                            return list.get(0);
2285                    }
2286    
2287                    return null;
2288            }
2289    
2290            /**
2291             * Returns the roles before and after the current role in the ordered set where companyId = &#63;.
2292             *
2293             * @param roleId the primary key of the current role
2294             * @param companyId the company ID
2295             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2296             * @return the previous, current, and next role
2297             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
2298             * @throws SystemException if a system exception occurred
2299             */
2300            @Override
2301            public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
2302                    OrderByComparator orderByComparator)
2303                    throws NoSuchRoleException, SystemException {
2304                    Role role = findByPrimaryKey(roleId);
2305    
2306                    Session session = null;
2307    
2308                    try {
2309                            session = openSession();
2310    
2311                            Role[] array = new RoleImpl[3];
2312    
2313                            array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
2314                                            orderByComparator, true);
2315    
2316                            array[1] = role;
2317    
2318                            array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
2319                                            orderByComparator, false);
2320    
2321                            return array;
2322                    }
2323                    catch (Exception e) {
2324                            throw processException(e);
2325                    }
2326                    finally {
2327                            closeSession(session);
2328                    }
2329            }
2330    
2331            protected Role getByCompanyId_PrevAndNext(Session session, Role role,
2332                    long companyId, OrderByComparator orderByComparator, boolean previous) {
2333                    StringBundler query = null;
2334    
2335                    if (orderByComparator != null) {
2336                            query = new StringBundler(6 +
2337                                            (orderByComparator.getOrderByFields().length * 6));
2338                    }
2339                    else {
2340                            query = new StringBundler(3);
2341                    }
2342    
2343                    query.append(_SQL_SELECT_ROLE_WHERE);
2344    
2345                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2346    
2347                    if (orderByComparator != null) {
2348                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2349    
2350                            if (orderByConditionFields.length > 0) {
2351                                    query.append(WHERE_AND);
2352                            }
2353    
2354                            for (int i = 0; i < orderByConditionFields.length; i++) {
2355                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2356                                    query.append(orderByConditionFields[i]);
2357    
2358                                    if ((i + 1) < orderByConditionFields.length) {
2359                                            if (orderByComparator.isAscending() ^ previous) {
2360                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2361                                            }
2362                                            else {
2363                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2364                                            }
2365                                    }
2366                                    else {
2367                                            if (orderByComparator.isAscending() ^ previous) {
2368                                                    query.append(WHERE_GREATER_THAN);
2369                                            }
2370                                            else {
2371                                                    query.append(WHERE_LESSER_THAN);
2372                                            }
2373                                    }
2374                            }
2375    
2376                            query.append(ORDER_BY_CLAUSE);
2377    
2378                            String[] orderByFields = orderByComparator.getOrderByFields();
2379    
2380                            for (int i = 0; i < orderByFields.length; i++) {
2381                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2382                                    query.append(orderByFields[i]);
2383    
2384                                    if ((i + 1) < orderByFields.length) {
2385                                            if (orderByComparator.isAscending() ^ previous) {
2386                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2387                                            }
2388                                            else {
2389                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2390                                            }
2391                                    }
2392                                    else {
2393                                            if (orderByComparator.isAscending() ^ previous) {
2394                                                    query.append(ORDER_BY_ASC);
2395                                            }
2396                                            else {
2397                                                    query.append(ORDER_BY_DESC);
2398                                            }
2399                                    }
2400                            }
2401                    }
2402                    else {
2403                            query.append(RoleModelImpl.ORDER_BY_JPQL);
2404                    }
2405    
2406                    String sql = query.toString();
2407    
2408                    Query q = session.createQuery(sql);
2409    
2410                    q.setFirstResult(0);
2411                    q.setMaxResults(2);
2412    
2413                    QueryPos qPos = QueryPos.getInstance(q);
2414    
2415                    qPos.add(companyId);
2416    
2417                    if (orderByComparator != null) {
2418                            Object[] values = orderByComparator.getOrderByConditionValues(role);
2419    
2420                            for (Object value : values) {
2421                                    qPos.add(value);
2422                            }
2423                    }
2424    
2425                    List<Role> list = q.list();
2426    
2427                    if (list.size() == 2) {
2428                            return list.get(1);
2429                    }
2430                    else {
2431                            return null;
2432                    }
2433            }
2434    
2435            /**
2436             * Returns all the roles that the user has permission to view where companyId = &#63;.
2437             *
2438             * @param companyId the company ID
2439             * @return the matching roles that the user has permission to view
2440             * @throws SystemException if a system exception occurred
2441             */
2442            @Override
2443            public List<Role> filterFindByCompanyId(long companyId)
2444                    throws SystemException {
2445                    return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2446                            QueryUtil.ALL_POS, null);
2447            }
2448    
2449            /**
2450             * Returns a range of all the roles that the user has permission to view where companyId = &#63;.
2451             *
2452             * <p>
2453             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2454             * </p>
2455             *
2456             * @param companyId the company ID
2457             * @param start the lower bound of the range of roles
2458             * @param end the upper bound of the range of roles (not inclusive)
2459             * @return the range of matching roles that the user has permission to view
2460             * @throws SystemException if a system exception occurred
2461             */
2462            @Override
2463            public List<Role> filterFindByCompanyId(long companyId, int start, int end)
2464                    throws SystemException {
2465                    return filterFindByCompanyId(companyId, start, end, null);
2466            }
2467    
2468            /**
2469             * Returns an ordered range of all the roles that the user has permissions to view where companyId = &#63;.
2470             *
2471             * <p>
2472             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2473             * </p>
2474             *
2475             * @param companyId the company ID
2476             * @param start the lower bound of the range of roles
2477             * @param end the upper bound of the range of roles (not inclusive)
2478             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2479             * @return the ordered range of matching roles that the user has permission to view
2480             * @throws SystemException if a system exception occurred
2481             */
2482            @Override
2483            public List<Role> filterFindByCompanyId(long companyId, int start, int end,
2484                    OrderByComparator orderByComparator) throws SystemException {
2485                    if (!InlineSQLHelperUtil.isEnabled()) {
2486                            return findByCompanyId(companyId, start, end, orderByComparator);
2487                    }
2488    
2489                    StringBundler query = null;
2490    
2491                    if (orderByComparator != null) {
2492                            query = new StringBundler(3 +
2493                                            (orderByComparator.getOrderByFields().length * 3));
2494                    }
2495                    else {
2496                            query = new StringBundler(3);
2497                    }
2498    
2499                    if (getDB().isSupportsInlineDistinct()) {
2500                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2501                    }
2502                    else {
2503                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2504                    }
2505    
2506                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2507    
2508                    if (!getDB().isSupportsInlineDistinct()) {
2509                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2510                    }
2511    
2512                    if (orderByComparator != null) {
2513                            if (getDB().isSupportsInlineDistinct()) {
2514                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2515                                            orderByComparator, true);
2516                            }
2517                            else {
2518                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2519                                            orderByComparator, true);
2520                            }
2521                    }
2522                    else {
2523                            if (getDB().isSupportsInlineDistinct()) {
2524                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
2525                            }
2526                            else {
2527                                    query.append(RoleModelImpl.ORDER_BY_SQL);
2528                            }
2529                    }
2530    
2531                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2532                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2533    
2534                    Session session = null;
2535    
2536                    try {
2537                            session = openSession();
2538    
2539                            SQLQuery q = session.createSQLQuery(sql);
2540    
2541                            if (getDB().isSupportsInlineDistinct()) {
2542                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2543                            }
2544                            else {
2545                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2546                            }
2547    
2548                            QueryPos qPos = QueryPos.getInstance(q);
2549    
2550                            qPos.add(companyId);
2551    
2552                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2553                    }
2554                    catch (Exception e) {
2555                            throw processException(e);
2556                    }
2557                    finally {
2558                            closeSession(session);
2559                    }
2560            }
2561    
2562            /**
2563             * 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;.
2564             *
2565             * @param roleId the primary key of the current role
2566             * @param companyId the company ID
2567             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2568             * @return the previous, current, and next role
2569             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
2570             * @throws SystemException if a system exception occurred
2571             */
2572            @Override
2573            public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
2574                    long companyId, OrderByComparator orderByComparator)
2575                    throws NoSuchRoleException, SystemException {
2576                    if (!InlineSQLHelperUtil.isEnabled()) {
2577                            return findByCompanyId_PrevAndNext(roleId, companyId,
2578                                    orderByComparator);
2579                    }
2580    
2581                    Role role = findByPrimaryKey(roleId);
2582    
2583                    Session session = null;
2584    
2585                    try {
2586                            session = openSession();
2587    
2588                            Role[] array = new RoleImpl[3];
2589    
2590                            array[0] = filterGetByCompanyId_PrevAndNext(session, role,
2591                                            companyId, orderByComparator, true);
2592    
2593                            array[1] = role;
2594    
2595                            array[2] = filterGetByCompanyId_PrevAndNext(session, role,
2596                                            companyId, orderByComparator, false);
2597    
2598                            return array;
2599                    }
2600                    catch (Exception e) {
2601                            throw processException(e);
2602                    }
2603                    finally {
2604                            closeSession(session);
2605                    }
2606            }
2607    
2608            protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
2609                    long companyId, OrderByComparator orderByComparator, boolean previous) {
2610                    StringBundler query = null;
2611    
2612                    if (orderByComparator != null) {
2613                            query = new StringBundler(6 +
2614                                            (orderByComparator.getOrderByFields().length * 6));
2615                    }
2616                    else {
2617                            query = new StringBundler(3);
2618                    }
2619    
2620                    if (getDB().isSupportsInlineDistinct()) {
2621                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2622                    }
2623                    else {
2624                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2625                    }
2626    
2627                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2628    
2629                    if (!getDB().isSupportsInlineDistinct()) {
2630                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2631                    }
2632    
2633                    if (orderByComparator != null) {
2634                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2635    
2636                            if (orderByConditionFields.length > 0) {
2637                                    query.append(WHERE_AND);
2638                            }
2639    
2640                            for (int i = 0; i < orderByConditionFields.length; i++) {
2641                                    if (getDB().isSupportsInlineDistinct()) {
2642                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2643                                    }
2644                                    else {
2645                                            query.append(_ORDER_BY_ENTITY_TABLE);
2646                                    }
2647    
2648                                    query.append(orderByConditionFields[i]);
2649    
2650                                    if ((i + 1) < orderByConditionFields.length) {
2651                                            if (orderByComparator.isAscending() ^ previous) {
2652                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2653                                            }
2654                                            else {
2655                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2656                                            }
2657                                    }
2658                                    else {
2659                                            if (orderByComparator.isAscending() ^ previous) {
2660                                                    query.append(WHERE_GREATER_THAN);
2661                                            }
2662                                            else {
2663                                                    query.append(WHERE_LESSER_THAN);
2664                                            }
2665                                    }
2666                            }
2667    
2668                            query.append(ORDER_BY_CLAUSE);
2669    
2670                            String[] orderByFields = orderByComparator.getOrderByFields();
2671    
2672                            for (int i = 0; i < orderByFields.length; i++) {
2673                                    if (getDB().isSupportsInlineDistinct()) {
2674                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2675                                    }
2676                                    else {
2677                                            query.append(_ORDER_BY_ENTITY_TABLE);
2678                                    }
2679    
2680                                    query.append(orderByFields[i]);
2681    
2682                                    if ((i + 1) < orderByFields.length) {
2683                                            if (orderByComparator.isAscending() ^ previous) {
2684                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2685                                            }
2686                                            else {
2687                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2688                                            }
2689                                    }
2690                                    else {
2691                                            if (orderByComparator.isAscending() ^ previous) {
2692                                                    query.append(ORDER_BY_ASC);
2693                                            }
2694                                            else {
2695                                                    query.append(ORDER_BY_DESC);
2696                                            }
2697                                    }
2698                            }
2699                    }
2700                    else {
2701                            if (getDB().isSupportsInlineDistinct()) {
2702                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
2703                            }
2704                            else {
2705                                    query.append(RoleModelImpl.ORDER_BY_SQL);
2706                            }
2707                    }
2708    
2709                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2710                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2711    
2712                    SQLQuery q = session.createSQLQuery(sql);
2713    
2714                    q.setFirstResult(0);
2715                    q.setMaxResults(2);
2716    
2717                    if (getDB().isSupportsInlineDistinct()) {
2718                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2719                    }
2720                    else {
2721                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2722                    }
2723    
2724                    QueryPos qPos = QueryPos.getInstance(q);
2725    
2726                    qPos.add(companyId);
2727    
2728                    if (orderByComparator != null) {
2729                            Object[] values = orderByComparator.getOrderByConditionValues(role);
2730    
2731                            for (Object value : values) {
2732                                    qPos.add(value);
2733                            }
2734                    }
2735    
2736                    List<Role> list = q.list();
2737    
2738                    if (list.size() == 2) {
2739                            return list.get(1);
2740                    }
2741                    else {
2742                            return null;
2743                    }
2744            }
2745    
2746            /**
2747             * Removes all the roles where companyId = &#63; from the database.
2748             *
2749             * @param companyId the company ID
2750             * @throws SystemException if a system exception occurred
2751             */
2752            @Override
2753            public void removeByCompanyId(long companyId) throws SystemException {
2754                    for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
2755                                    QueryUtil.ALL_POS, null)) {
2756                            remove(role);
2757                    }
2758            }
2759    
2760            /**
2761             * Returns the number of roles where companyId = &#63;.
2762             *
2763             * @param companyId the company ID
2764             * @return the number of matching roles
2765             * @throws SystemException if a system exception occurred
2766             */
2767            @Override
2768            public int countByCompanyId(long companyId) throws SystemException {
2769                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2770    
2771                    Object[] finderArgs = new Object[] { companyId };
2772    
2773                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2774                                    this);
2775    
2776                    if (count == null) {
2777                            StringBundler query = new StringBundler(2);
2778    
2779                            query.append(_SQL_COUNT_ROLE_WHERE);
2780    
2781                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2782    
2783                            String sql = query.toString();
2784    
2785                            Session session = null;
2786    
2787                            try {
2788                                    session = openSession();
2789    
2790                                    Query q = session.createQuery(sql);
2791    
2792                                    QueryPos qPos = QueryPos.getInstance(q);
2793    
2794                                    qPos.add(companyId);
2795    
2796                                    count = (Long)q.uniqueResult();
2797    
2798                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2799                            }
2800                            catch (Exception e) {
2801                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2802    
2803                                    throw processException(e);
2804                            }
2805                            finally {
2806                                    closeSession(session);
2807                            }
2808                    }
2809    
2810                    return count.intValue();
2811            }
2812    
2813            /**
2814             * Returns the number of roles that the user has permission to view where companyId = &#63;.
2815             *
2816             * @param companyId the company ID
2817             * @return the number of matching roles that the user has permission to view
2818             * @throws SystemException if a system exception occurred
2819             */
2820            @Override
2821            public int filterCountByCompanyId(long companyId) throws SystemException {
2822                    if (!InlineSQLHelperUtil.isEnabled()) {
2823                            return countByCompanyId(companyId);
2824                    }
2825    
2826                    StringBundler query = new StringBundler(2);
2827    
2828                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2829    
2830                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2831    
2832                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2833                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2834    
2835                    Session session = null;
2836    
2837                    try {
2838                            session = openSession();
2839    
2840                            SQLQuery q = session.createSQLQuery(sql);
2841    
2842                            q.addScalar(COUNT_COLUMN_NAME,
2843                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2844    
2845                            QueryPos qPos = QueryPos.getInstance(q);
2846    
2847                            qPos.add(companyId);
2848    
2849                            Long count = (Long)q.uniqueResult();
2850    
2851                            return count.intValue();
2852                    }
2853                    catch (Exception e) {
2854                            throw processException(e);
2855                    }
2856                    finally {
2857                            closeSession(session);
2858                    }
2859            }
2860    
2861            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
2862            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2863                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2864                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
2865                            new String[] {
2866                                    String.class.getName(),
2867                                    
2868                            Integer.class.getName(), Integer.class.getName(),
2869                                    OrderByComparator.class.getName()
2870                            });
2871            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2872                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2873                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
2874                            new String[] { String.class.getName() },
2875                            RoleModelImpl.NAME_COLUMN_BITMASK);
2876            public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2877                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2878                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
2879                            new String[] { String.class.getName() });
2880    
2881            /**
2882             * Returns all the roles where name = &#63;.
2883             *
2884             * @param name the name
2885             * @return the matching roles
2886             * @throws SystemException if a system exception occurred
2887             */
2888            @Override
2889            public List<Role> findByName(String name) throws SystemException {
2890                    return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2891            }
2892    
2893            /**
2894             * Returns a range of all the roles where name = &#63;.
2895             *
2896             * <p>
2897             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2898             * </p>
2899             *
2900             * @param name the name
2901             * @param start the lower bound of the range of roles
2902             * @param end the upper bound of the range of roles (not inclusive)
2903             * @return the range of matching roles
2904             * @throws SystemException if a system exception occurred
2905             */
2906            @Override
2907            public List<Role> findByName(String name, int start, int end)
2908                    throws SystemException {
2909                    return findByName(name, start, end, null);
2910            }
2911    
2912            /**
2913             * Returns an ordered range of all the roles where name = &#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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2917             * </p>
2918             *
2919             * @param name the name
2920             * @param start the lower bound of the range of roles
2921             * @param end the upper bound of the range of roles (not inclusive)
2922             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2923             * @return the ordered range of matching roles
2924             * @throws SystemException if a system exception occurred
2925             */
2926            @Override
2927            public List<Role> findByName(String name, int start, int end,
2928                    OrderByComparator orderByComparator) throws SystemException {
2929                    boolean pagination = true;
2930                    FinderPath finderPath = null;
2931                    Object[] finderArgs = null;
2932    
2933                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2934                                    (orderByComparator == null)) {
2935                            pagination = false;
2936                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
2937                            finderArgs = new Object[] { name };
2938                    }
2939                    else {
2940                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
2941                            finderArgs = new Object[] { name, start, end, orderByComparator };
2942                    }
2943    
2944                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2945                                    finderArgs, this);
2946    
2947                    if ((list != null) && !list.isEmpty()) {
2948                            for (Role role : list) {
2949                                    if (!Validator.equals(name, role.getName())) {
2950                                            list = null;
2951    
2952                                            break;
2953                                    }
2954                            }
2955                    }
2956    
2957                    if (list == null) {
2958                            StringBundler query = null;
2959    
2960                            if (orderByComparator != null) {
2961                                    query = new StringBundler(3 +
2962                                                    (orderByComparator.getOrderByFields().length * 3));
2963                            }
2964                            else {
2965                                    query = new StringBundler(3);
2966                            }
2967    
2968                            query.append(_SQL_SELECT_ROLE_WHERE);
2969    
2970                            boolean bindName = false;
2971    
2972                            if (name == null) {
2973                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
2974                            }
2975                            else if (name.equals(StringPool.BLANK)) {
2976                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
2977                            }
2978                            else {
2979                                    bindName = true;
2980    
2981                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
2982                            }
2983    
2984                            if (orderByComparator != null) {
2985                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2986                                            orderByComparator);
2987                            }
2988                            else
2989                             if (pagination) {
2990                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
2991                            }
2992    
2993                            String sql = query.toString();
2994    
2995                            Session session = null;
2996    
2997                            try {
2998                                    session = openSession();
2999    
3000                                    Query q = session.createQuery(sql);
3001    
3002                                    QueryPos qPos = QueryPos.getInstance(q);
3003    
3004                                    if (bindName) {
3005                                            qPos.add(name);
3006                                    }
3007    
3008                                    if (!pagination) {
3009                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3010                                                            end, false);
3011    
3012                                            Collections.sort(list);
3013    
3014                                            list = new UnmodifiableList<Role>(list);
3015                                    }
3016                                    else {
3017                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3018                                                            end);
3019                                    }
3020    
3021                                    cacheResult(list);
3022    
3023                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3024                            }
3025                            catch (Exception e) {
3026                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3027    
3028                                    throw processException(e);
3029                            }
3030                            finally {
3031                                    closeSession(session);
3032                            }
3033                    }
3034    
3035                    return list;
3036            }
3037    
3038            /**
3039             * Returns the first role in the ordered set where name = &#63;.
3040             *
3041             * @param name the name
3042             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3043             * @return the first matching role
3044             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
3045             * @throws SystemException if a system exception occurred
3046             */
3047            @Override
3048            public Role findByName_First(String name,
3049                    OrderByComparator orderByComparator)
3050                    throws NoSuchRoleException, SystemException {
3051                    Role role = fetchByName_First(name, orderByComparator);
3052    
3053                    if (role != null) {
3054                            return role;
3055                    }
3056    
3057                    StringBundler msg = new StringBundler(4);
3058    
3059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3060    
3061                    msg.append("name=");
3062                    msg.append(name);
3063    
3064                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3065    
3066                    throw new NoSuchRoleException(msg.toString());
3067            }
3068    
3069            /**
3070             * Returns the first role in the ordered set where name = &#63;.
3071             *
3072             * @param name the name
3073             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3074             * @return the first matching role, or <code>null</code> if a matching role could not be found
3075             * @throws SystemException if a system exception occurred
3076             */
3077            @Override
3078            public Role fetchByName_First(String name,
3079                    OrderByComparator orderByComparator) throws SystemException {
3080                    List<Role> list = findByName(name, 0, 1, orderByComparator);
3081    
3082                    if (!list.isEmpty()) {
3083                            return list.get(0);
3084                    }
3085    
3086                    return null;
3087            }
3088    
3089            /**
3090             * Returns the last role in the ordered set where name = &#63;.
3091             *
3092             * @param name the name
3093             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3094             * @return the last matching role
3095             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
3096             * @throws SystemException if a system exception occurred
3097             */
3098            @Override
3099            public Role findByName_Last(String name, OrderByComparator orderByComparator)
3100                    throws NoSuchRoleException, SystemException {
3101                    Role role = fetchByName_Last(name, orderByComparator);
3102    
3103                    if (role != null) {
3104                            return role;
3105                    }
3106    
3107                    StringBundler msg = new StringBundler(4);
3108    
3109                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3110    
3111                    msg.append("name=");
3112                    msg.append(name);
3113    
3114                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3115    
3116                    throw new NoSuchRoleException(msg.toString());
3117            }
3118    
3119            /**
3120             * Returns the last role in the ordered set where name = &#63;.
3121             *
3122             * @param name the name
3123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3124             * @return the last matching role, or <code>null</code> if a matching role could not be found
3125             * @throws SystemException if a system exception occurred
3126             */
3127            @Override
3128            public Role fetchByName_Last(String name,
3129                    OrderByComparator orderByComparator) throws SystemException {
3130                    int count = countByName(name);
3131    
3132                    if (count == 0) {
3133                            return null;
3134                    }
3135    
3136                    List<Role> list = findByName(name, count - 1, count, orderByComparator);
3137    
3138                    if (!list.isEmpty()) {
3139                            return list.get(0);
3140                    }
3141    
3142                    return null;
3143            }
3144    
3145            /**
3146             * Returns the roles before and after the current role in the ordered set where name = &#63;.
3147             *
3148             * @param roleId the primary key of the current role
3149             * @param name the name
3150             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3151             * @return the previous, current, and next role
3152             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
3153             * @throws SystemException if a system exception occurred
3154             */
3155            @Override
3156            public Role[] findByName_PrevAndNext(long roleId, String name,
3157                    OrderByComparator orderByComparator)
3158                    throws NoSuchRoleException, SystemException {
3159                    Role role = findByPrimaryKey(roleId);
3160    
3161                    Session session = null;
3162    
3163                    try {
3164                            session = openSession();
3165    
3166                            Role[] array = new RoleImpl[3];
3167    
3168                            array[0] = getByName_PrevAndNext(session, role, name,
3169                                            orderByComparator, true);
3170    
3171                            array[1] = role;
3172    
3173                            array[2] = getByName_PrevAndNext(session, role, name,
3174                                            orderByComparator, false);
3175    
3176                            return array;
3177                    }
3178                    catch (Exception e) {
3179                            throw processException(e);
3180                    }
3181                    finally {
3182                            closeSession(session);
3183                    }
3184            }
3185    
3186            protected Role getByName_PrevAndNext(Session session, Role role,
3187                    String name, OrderByComparator orderByComparator, boolean previous) {
3188                    StringBundler query = null;
3189    
3190                    if (orderByComparator != null) {
3191                            query = new StringBundler(6 +
3192                                            (orderByComparator.getOrderByFields().length * 6));
3193                    }
3194                    else {
3195                            query = new StringBundler(3);
3196                    }
3197    
3198                    query.append(_SQL_SELECT_ROLE_WHERE);
3199    
3200                    boolean bindName = false;
3201    
3202                    if (name == null) {
3203                            query.append(_FINDER_COLUMN_NAME_NAME_1);
3204                    }
3205                    else if (name.equals(StringPool.BLANK)) {
3206                            query.append(_FINDER_COLUMN_NAME_NAME_3);
3207                    }
3208                    else {
3209                            bindName = true;
3210    
3211                            query.append(_FINDER_COLUMN_NAME_NAME_2);
3212                    }
3213    
3214                    if (orderByComparator != null) {
3215                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3216    
3217                            if (orderByConditionFields.length > 0) {
3218                                    query.append(WHERE_AND);
3219                            }
3220    
3221                            for (int i = 0; i < orderByConditionFields.length; i++) {
3222                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3223                                    query.append(orderByConditionFields[i]);
3224    
3225                                    if ((i + 1) < orderByConditionFields.length) {
3226                                            if (orderByComparator.isAscending() ^ previous) {
3227                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3228                                            }
3229                                            else {
3230                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3231                                            }
3232                                    }
3233                                    else {
3234                                            if (orderByComparator.isAscending() ^ previous) {
3235                                                    query.append(WHERE_GREATER_THAN);
3236                                            }
3237                                            else {
3238                                                    query.append(WHERE_LESSER_THAN);
3239                                            }
3240                                    }
3241                            }
3242    
3243                            query.append(ORDER_BY_CLAUSE);
3244    
3245                            String[] orderByFields = orderByComparator.getOrderByFields();
3246    
3247                            for (int i = 0; i < orderByFields.length; i++) {
3248                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3249                                    query.append(orderByFields[i]);
3250    
3251                                    if ((i + 1) < orderByFields.length) {
3252                                            if (orderByComparator.isAscending() ^ previous) {
3253                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3254                                            }
3255                                            else {
3256                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3257                                            }
3258                                    }
3259                                    else {
3260                                            if (orderByComparator.isAscending() ^ previous) {
3261                                                    query.append(ORDER_BY_ASC);
3262                                            }
3263                                            else {
3264                                                    query.append(ORDER_BY_DESC);
3265                                            }
3266                                    }
3267                            }
3268                    }
3269                    else {
3270                            query.append(RoleModelImpl.ORDER_BY_JPQL);
3271                    }
3272    
3273                    String sql = query.toString();
3274    
3275                    Query q = session.createQuery(sql);
3276    
3277                    q.setFirstResult(0);
3278                    q.setMaxResults(2);
3279    
3280                    QueryPos qPos = QueryPos.getInstance(q);
3281    
3282                    if (bindName) {
3283                            qPos.add(name);
3284                    }
3285    
3286                    if (orderByComparator != null) {
3287                            Object[] values = orderByComparator.getOrderByConditionValues(role);
3288    
3289                            for (Object value : values) {
3290                                    qPos.add(value);
3291                            }
3292                    }
3293    
3294                    List<Role> list = q.list();
3295    
3296                    if (list.size() == 2) {
3297                            return list.get(1);
3298                    }
3299                    else {
3300                            return null;
3301                    }
3302            }
3303    
3304            /**
3305             * Returns all the roles that the user has permission to view where name = &#63;.
3306             *
3307             * @param name the name
3308             * @return the matching roles that the user has permission to view
3309             * @throws SystemException if a system exception occurred
3310             */
3311            @Override
3312            public List<Role> filterFindByName(String name) throws SystemException {
3313                    return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3314            }
3315    
3316            /**
3317             * Returns a range of all the roles that the user has permission to view where name = &#63;.
3318             *
3319             * <p>
3320             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3321             * </p>
3322             *
3323             * @param name the name
3324             * @param start the lower bound of the range of roles
3325             * @param end the upper bound of the range of roles (not inclusive)
3326             * @return the range of matching roles that the user has permission to view
3327             * @throws SystemException if a system exception occurred
3328             */
3329            @Override
3330            public List<Role> filterFindByName(String name, int start, int end)
3331                    throws SystemException {
3332                    return filterFindByName(name, start, end, null);
3333            }
3334    
3335            /**
3336             * Returns an ordered range of all the roles that the user has permissions to view where name = &#63;.
3337             *
3338             * <p>
3339             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3340             * </p>
3341             *
3342             * @param name the name
3343             * @param start the lower bound of the range of roles
3344             * @param end the upper bound of the range of roles (not inclusive)
3345             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3346             * @return the ordered range of matching roles that the user has permission to view
3347             * @throws SystemException if a system exception occurred
3348             */
3349            @Override
3350            public List<Role> filterFindByName(String name, int start, int end,
3351                    OrderByComparator orderByComparator) throws SystemException {
3352                    if (!InlineSQLHelperUtil.isEnabled()) {
3353                            return findByName(name, start, end, orderByComparator);
3354                    }
3355    
3356                    StringBundler query = null;
3357    
3358                    if (orderByComparator != null) {
3359                            query = new StringBundler(3 +
3360                                            (orderByComparator.getOrderByFields().length * 3));
3361                    }
3362                    else {
3363                            query = new StringBundler(3);
3364                    }
3365    
3366                    if (getDB().isSupportsInlineDistinct()) {
3367                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3368                    }
3369                    else {
3370                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3371                    }
3372    
3373                    boolean bindName = false;
3374    
3375                    if (name == null) {
3376                            query.append(_FINDER_COLUMN_NAME_NAME_1);
3377                    }
3378                    else if (name.equals(StringPool.BLANK)) {
3379                            query.append(_FINDER_COLUMN_NAME_NAME_3);
3380                    }
3381                    else {
3382                            bindName = true;
3383    
3384                            query.append(_FINDER_COLUMN_NAME_NAME_2);
3385                    }
3386    
3387                    if (!getDB().isSupportsInlineDistinct()) {
3388                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3389                    }
3390    
3391                    if (orderByComparator != null) {
3392                            if (getDB().isSupportsInlineDistinct()) {
3393                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3394                                            orderByComparator, true);
3395                            }
3396                            else {
3397                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3398                                            orderByComparator, true);
3399                            }
3400                    }
3401                    else {
3402                            if (getDB().isSupportsInlineDistinct()) {
3403                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
3404                            }
3405                            else {
3406                                    query.append(RoleModelImpl.ORDER_BY_SQL);
3407                            }
3408                    }
3409    
3410                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3411                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3412    
3413                    Session session = null;
3414    
3415                    try {
3416                            session = openSession();
3417    
3418                            SQLQuery q = session.createSQLQuery(sql);
3419    
3420                            if (getDB().isSupportsInlineDistinct()) {
3421                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3422                            }
3423                            else {
3424                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3425                            }
3426    
3427                            QueryPos qPos = QueryPos.getInstance(q);
3428    
3429                            if (bindName) {
3430                                    qPos.add(name);
3431                            }
3432    
3433                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3434                    }
3435                    catch (Exception e) {
3436                            throw processException(e);
3437                    }
3438                    finally {
3439                            closeSession(session);
3440                    }
3441            }
3442    
3443            /**
3444             * 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;.
3445             *
3446             * @param roleId the primary key of the current role
3447             * @param name the name
3448             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3449             * @return the previous, current, and next role
3450             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
3451             * @throws SystemException if a system exception occurred
3452             */
3453            @Override
3454            public Role[] filterFindByName_PrevAndNext(long roleId, String name,
3455                    OrderByComparator orderByComparator)
3456                    throws NoSuchRoleException, SystemException {
3457                    if (!InlineSQLHelperUtil.isEnabled()) {
3458                            return findByName_PrevAndNext(roleId, name, orderByComparator);
3459                    }
3460    
3461                    Role role = findByPrimaryKey(roleId);
3462    
3463                    Session session = null;
3464    
3465                    try {
3466                            session = openSession();
3467    
3468                            Role[] array = new RoleImpl[3];
3469    
3470                            array[0] = filterGetByName_PrevAndNext(session, role, name,
3471                                            orderByComparator, true);
3472    
3473                            array[1] = role;
3474    
3475                            array[2] = filterGetByName_PrevAndNext(session, role, name,
3476                                            orderByComparator, false);
3477    
3478                            return array;
3479                    }
3480                    catch (Exception e) {
3481                            throw processException(e);
3482                    }
3483                    finally {
3484                            closeSession(session);
3485                    }
3486            }
3487    
3488            protected Role filterGetByName_PrevAndNext(Session session, Role role,
3489                    String name, OrderByComparator orderByComparator, boolean previous) {
3490                    StringBundler query = null;
3491    
3492                    if (orderByComparator != null) {
3493                            query = new StringBundler(6 +
3494                                            (orderByComparator.getOrderByFields().length * 6));
3495                    }
3496                    else {
3497                            query = new StringBundler(3);
3498                    }
3499    
3500                    if (getDB().isSupportsInlineDistinct()) {
3501                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3502                    }
3503                    else {
3504                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3505                    }
3506    
3507                    boolean bindName = false;
3508    
3509                    if (name == null) {
3510                            query.append(_FINDER_COLUMN_NAME_NAME_1);
3511                    }
3512                    else if (name.equals(StringPool.BLANK)) {
3513                            query.append(_FINDER_COLUMN_NAME_NAME_3);
3514                    }
3515                    else {
3516                            bindName = true;
3517    
3518                            query.append(_FINDER_COLUMN_NAME_NAME_2);
3519                    }
3520    
3521                    if (!getDB().isSupportsInlineDistinct()) {
3522                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3523                    }
3524    
3525                    if (orderByComparator != null) {
3526                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3527    
3528                            if (orderByConditionFields.length > 0) {
3529                                    query.append(WHERE_AND);
3530                            }
3531    
3532                            for (int i = 0; i < orderByConditionFields.length; i++) {
3533                                    if (getDB().isSupportsInlineDistinct()) {
3534                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3535                                    }
3536                                    else {
3537                                            query.append(_ORDER_BY_ENTITY_TABLE);
3538                                    }
3539    
3540                                    query.append(orderByConditionFields[i]);
3541    
3542                                    if ((i + 1) < orderByConditionFields.length) {
3543                                            if (orderByComparator.isAscending() ^ previous) {
3544                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3545                                            }
3546                                            else {
3547                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3548                                            }
3549                                    }
3550                                    else {
3551                                            if (orderByComparator.isAscending() ^ previous) {
3552                                                    query.append(WHERE_GREATER_THAN);
3553                                            }
3554                                            else {
3555                                                    query.append(WHERE_LESSER_THAN);
3556                                            }
3557                                    }
3558                            }
3559    
3560                            query.append(ORDER_BY_CLAUSE);
3561    
3562                            String[] orderByFields = orderByComparator.getOrderByFields();
3563    
3564                            for (int i = 0; i < orderByFields.length; i++) {
3565                                    if (getDB().isSupportsInlineDistinct()) {
3566                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3567                                    }
3568                                    else {
3569                                            query.append(_ORDER_BY_ENTITY_TABLE);
3570                                    }
3571    
3572                                    query.append(orderByFields[i]);
3573    
3574                                    if ((i + 1) < orderByFields.length) {
3575                                            if (orderByComparator.isAscending() ^ previous) {
3576                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3577                                            }
3578                                            else {
3579                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3580                                            }
3581                                    }
3582                                    else {
3583                                            if (orderByComparator.isAscending() ^ previous) {
3584                                                    query.append(ORDER_BY_ASC);
3585                                            }
3586                                            else {
3587                                                    query.append(ORDER_BY_DESC);
3588                                            }
3589                                    }
3590                            }
3591                    }
3592                    else {
3593                            if (getDB().isSupportsInlineDistinct()) {
3594                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
3595                            }
3596                            else {
3597                                    query.append(RoleModelImpl.ORDER_BY_SQL);
3598                            }
3599                    }
3600    
3601                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3602                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3603    
3604                    SQLQuery q = session.createSQLQuery(sql);
3605    
3606                    q.setFirstResult(0);
3607                    q.setMaxResults(2);
3608    
3609                    if (getDB().isSupportsInlineDistinct()) {
3610                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3611                    }
3612                    else {
3613                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3614                    }
3615    
3616                    QueryPos qPos = QueryPos.getInstance(q);
3617    
3618                    if (bindName) {
3619                            qPos.add(name);
3620                    }
3621    
3622                    if (orderByComparator != null) {
3623                            Object[] values = orderByComparator.getOrderByConditionValues(role);
3624    
3625                            for (Object value : values) {
3626                                    qPos.add(value);
3627                            }
3628                    }
3629    
3630                    List<Role> list = q.list();
3631    
3632                    if (list.size() == 2) {
3633                            return list.get(1);
3634                    }
3635                    else {
3636                            return null;
3637                    }
3638            }
3639    
3640            /**
3641             * Removes all the roles where name = &#63; from the database.
3642             *
3643             * @param name the name
3644             * @throws SystemException if a system exception occurred
3645             */
3646            @Override
3647            public void removeByName(String name) throws SystemException {
3648                    for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3649                                    null)) {
3650                            remove(role);
3651                    }
3652            }
3653    
3654            /**
3655             * Returns the number of roles where name = &#63;.
3656             *
3657             * @param name the name
3658             * @return the number of matching roles
3659             * @throws SystemException if a system exception occurred
3660             */
3661            @Override
3662            public int countByName(String name) throws SystemException {
3663                    FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
3664    
3665                    Object[] finderArgs = new Object[] { name };
3666    
3667                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3668                                    this);
3669    
3670                    if (count == null) {
3671                            StringBundler query = new StringBundler(2);
3672    
3673                            query.append(_SQL_COUNT_ROLE_WHERE);
3674    
3675                            boolean bindName = false;
3676    
3677                            if (name == null) {
3678                                    query.append(_FINDER_COLUMN_NAME_NAME_1);
3679                            }
3680                            else if (name.equals(StringPool.BLANK)) {
3681                                    query.append(_FINDER_COLUMN_NAME_NAME_3);
3682                            }
3683                            else {
3684                                    bindName = true;
3685    
3686                                    query.append(_FINDER_COLUMN_NAME_NAME_2);
3687                            }
3688    
3689                            String sql = query.toString();
3690    
3691                            Session session = null;
3692    
3693                            try {
3694                                    session = openSession();
3695    
3696                                    Query q = session.createQuery(sql);
3697    
3698                                    QueryPos qPos = QueryPos.getInstance(q);
3699    
3700                                    if (bindName) {
3701                                            qPos.add(name);
3702                                    }
3703    
3704                                    count = (Long)q.uniqueResult();
3705    
3706                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3707                            }
3708                            catch (Exception e) {
3709                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3710    
3711                                    throw processException(e);
3712                            }
3713                            finally {
3714                                    closeSession(session);
3715                            }
3716                    }
3717    
3718                    return count.intValue();
3719            }
3720    
3721            /**
3722             * Returns the number of roles that the user has permission to view where name = &#63;.
3723             *
3724             * @param name the name
3725             * @return the number of matching roles that the user has permission to view
3726             * @throws SystemException if a system exception occurred
3727             */
3728            @Override
3729            public int filterCountByName(String name) throws SystemException {
3730                    if (!InlineSQLHelperUtil.isEnabled()) {
3731                            return countByName(name);
3732                    }
3733    
3734                    StringBundler query = new StringBundler(2);
3735    
3736                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3737    
3738                    boolean bindName = false;
3739    
3740                    if (name == null) {
3741                            query.append(_FINDER_COLUMN_NAME_NAME_1);
3742                    }
3743                    else if (name.equals(StringPool.BLANK)) {
3744                            query.append(_FINDER_COLUMN_NAME_NAME_3);
3745                    }
3746                    else {
3747                            bindName = true;
3748    
3749                            query.append(_FINDER_COLUMN_NAME_NAME_2);
3750                    }
3751    
3752                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3753                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3754    
3755                    Session session = null;
3756    
3757                    try {
3758                            session = openSession();
3759    
3760                            SQLQuery q = session.createSQLQuery(sql);
3761    
3762                            q.addScalar(COUNT_COLUMN_NAME,
3763                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3764    
3765                            QueryPos qPos = QueryPos.getInstance(q);
3766    
3767                            if (bindName) {
3768                                    qPos.add(name);
3769                            }
3770    
3771                            Long count = (Long)q.uniqueResult();
3772    
3773                            return count.intValue();
3774                    }
3775                    catch (Exception e) {
3776                            throw processException(e);
3777                    }
3778                    finally {
3779                            closeSession(session);
3780                    }
3781            }
3782    
3783            private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
3784            private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
3785            private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')";
3786            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3787                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3788                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3789                            new String[] {
3790                                    Integer.class.getName(),
3791                                    
3792                            Integer.class.getName(), Integer.class.getName(),
3793                                    OrderByComparator.class.getName()
3794                            });
3795            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3796                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3797                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3798                            new String[] { Integer.class.getName() },
3799                            RoleModelImpl.TYPE_COLUMN_BITMASK |
3800                            RoleModelImpl.NAME_COLUMN_BITMASK);
3801            public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3802                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3803                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3804                            new String[] { Integer.class.getName() });
3805    
3806            /**
3807             * Returns all the roles where type = &#63;.
3808             *
3809             * @param type the type
3810             * @return the matching roles
3811             * @throws SystemException if a system exception occurred
3812             */
3813            @Override
3814            public List<Role> findByType(int type) throws SystemException {
3815                    return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3816            }
3817    
3818            /**
3819             * Returns a range of all the roles where type = &#63;.
3820             *
3821             * <p>
3822             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3823             * </p>
3824             *
3825             * @param type the type
3826             * @param start the lower bound of the range of roles
3827             * @param end the upper bound of the range of roles (not inclusive)
3828             * @return the range of matching roles
3829             * @throws SystemException if a system exception occurred
3830             */
3831            @Override
3832            public List<Role> findByType(int type, int start, int end)
3833                    throws SystemException {
3834                    return findByType(type, start, end, null);
3835            }
3836    
3837            /**
3838             * Returns an ordered range of all the roles where type = &#63;.
3839             *
3840             * <p>
3841             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3842             * </p>
3843             *
3844             * @param type the type
3845             * @param start the lower bound of the range of roles
3846             * @param end the upper bound of the range of roles (not inclusive)
3847             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3848             * @return the ordered range of matching roles
3849             * @throws SystemException if a system exception occurred
3850             */
3851            @Override
3852            public List<Role> findByType(int type, int start, int end,
3853                    OrderByComparator orderByComparator) throws SystemException {
3854                    boolean pagination = true;
3855                    FinderPath finderPath = null;
3856                    Object[] finderArgs = null;
3857    
3858                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3859                                    (orderByComparator == null)) {
3860                            pagination = false;
3861                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3862                            finderArgs = new Object[] { type };
3863                    }
3864                    else {
3865                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3866                            finderArgs = new Object[] { type, start, end, orderByComparator };
3867                    }
3868    
3869                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
3870                                    finderArgs, this);
3871    
3872                    if ((list != null) && !list.isEmpty()) {
3873                            for (Role role : list) {
3874                                    if ((type != role.getType())) {
3875                                            list = null;
3876    
3877                                            break;
3878                                    }
3879                            }
3880                    }
3881    
3882                    if (list == null) {
3883                            StringBundler query = null;
3884    
3885                            if (orderByComparator != null) {
3886                                    query = new StringBundler(3 +
3887                                                    (orderByComparator.getOrderByFields().length * 3));
3888                            }
3889                            else {
3890                                    query = new StringBundler(3);
3891                            }
3892    
3893                            query.append(_SQL_SELECT_ROLE_WHERE);
3894    
3895                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3896    
3897                            if (orderByComparator != null) {
3898                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3899                                            orderByComparator);
3900                            }
3901                            else
3902                             if (pagination) {
3903                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
3904                            }
3905    
3906                            String sql = query.toString();
3907    
3908                            Session session = null;
3909    
3910                            try {
3911                                    session = openSession();
3912    
3913                                    Query q = session.createQuery(sql);
3914    
3915                                    QueryPos qPos = QueryPos.getInstance(q);
3916    
3917                                    qPos.add(type);
3918    
3919                                    if (!pagination) {
3920                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3921                                                            end, false);
3922    
3923                                            Collections.sort(list);
3924    
3925                                            list = new UnmodifiableList<Role>(list);
3926                                    }
3927                                    else {
3928                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3929                                                            end);
3930                                    }
3931    
3932                                    cacheResult(list);
3933    
3934                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3935                            }
3936                            catch (Exception e) {
3937                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3938    
3939                                    throw processException(e);
3940                            }
3941                            finally {
3942                                    closeSession(session);
3943                            }
3944                    }
3945    
3946                    return list;
3947            }
3948    
3949            /**
3950             * Returns the first role in the ordered set where type = &#63;.
3951             *
3952             * @param type the type
3953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3954             * @return the first matching role
3955             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
3956             * @throws SystemException if a system exception occurred
3957             */
3958            @Override
3959            public Role findByType_First(int type, OrderByComparator orderByComparator)
3960                    throws NoSuchRoleException, SystemException {
3961                    Role role = fetchByType_First(type, orderByComparator);
3962    
3963                    if (role != null) {
3964                            return role;
3965                    }
3966    
3967                    StringBundler msg = new StringBundler(4);
3968    
3969                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3970    
3971                    msg.append("type=");
3972                    msg.append(type);
3973    
3974                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3975    
3976                    throw new NoSuchRoleException(msg.toString());
3977            }
3978    
3979            /**
3980             * Returns the first role in the ordered set where type = &#63;.
3981             *
3982             * @param type the type
3983             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3984             * @return the first matching role, or <code>null</code> if a matching role could not be found
3985             * @throws SystemException if a system exception occurred
3986             */
3987            @Override
3988            public Role fetchByType_First(int type, OrderByComparator orderByComparator)
3989                    throws SystemException {
3990                    List<Role> list = findByType(type, 0, 1, orderByComparator);
3991    
3992                    if (!list.isEmpty()) {
3993                            return list.get(0);
3994                    }
3995    
3996                    return null;
3997            }
3998    
3999            /**
4000             * Returns the last role in the ordered set where type = &#63;.
4001             *
4002             * @param type the type
4003             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4004             * @return the last matching role
4005             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
4006             * @throws SystemException if a system exception occurred
4007             */
4008            @Override
4009            public Role findByType_Last(int type, OrderByComparator orderByComparator)
4010                    throws NoSuchRoleException, SystemException {
4011                    Role role = fetchByType_Last(type, orderByComparator);
4012    
4013                    if (role != null) {
4014                            return role;
4015                    }
4016    
4017                    StringBundler msg = new StringBundler(4);
4018    
4019                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4020    
4021                    msg.append("type=");
4022                    msg.append(type);
4023    
4024                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4025    
4026                    throw new NoSuchRoleException(msg.toString());
4027            }
4028    
4029            /**
4030             * Returns the last role in the ordered set where type = &#63;.
4031             *
4032             * @param type the type
4033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4034             * @return the last matching role, or <code>null</code> if a matching role could not be found
4035             * @throws SystemException if a system exception occurred
4036             */
4037            @Override
4038            public Role fetchByType_Last(int type, OrderByComparator orderByComparator)
4039                    throws SystemException {
4040                    int count = countByType(type);
4041    
4042                    if (count == 0) {
4043                            return null;
4044                    }
4045    
4046                    List<Role> list = findByType(type, count - 1, count, orderByComparator);
4047    
4048                    if (!list.isEmpty()) {
4049                            return list.get(0);
4050                    }
4051    
4052                    return null;
4053            }
4054    
4055            /**
4056             * Returns the roles before and after the current role in the ordered set where type = &#63;.
4057             *
4058             * @param roleId the primary key of the current role
4059             * @param type the type
4060             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4061             * @return the previous, current, and next role
4062             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
4063             * @throws SystemException if a system exception occurred
4064             */
4065            @Override
4066            public Role[] findByType_PrevAndNext(long roleId, int type,
4067                    OrderByComparator orderByComparator)
4068                    throws NoSuchRoleException, SystemException {
4069                    Role role = findByPrimaryKey(roleId);
4070    
4071                    Session session = null;
4072    
4073                    try {
4074                            session = openSession();
4075    
4076                            Role[] array = new RoleImpl[3];
4077    
4078                            array[0] = getByType_PrevAndNext(session, role, type,
4079                                            orderByComparator, true);
4080    
4081                            array[1] = role;
4082    
4083                            array[2] = getByType_PrevAndNext(session, role, type,
4084                                            orderByComparator, false);
4085    
4086                            return array;
4087                    }
4088                    catch (Exception e) {
4089                            throw processException(e);
4090                    }
4091                    finally {
4092                            closeSession(session);
4093                    }
4094            }
4095    
4096            protected Role getByType_PrevAndNext(Session session, Role role, int type,
4097                    OrderByComparator orderByComparator, boolean previous) {
4098                    StringBundler query = null;
4099    
4100                    if (orderByComparator != null) {
4101                            query = new StringBundler(6 +
4102                                            (orderByComparator.getOrderByFields().length * 6));
4103                    }
4104                    else {
4105                            query = new StringBundler(3);
4106                    }
4107    
4108                    query.append(_SQL_SELECT_ROLE_WHERE);
4109    
4110                    query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4111    
4112                    if (orderByComparator != null) {
4113                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4114    
4115                            if (orderByConditionFields.length > 0) {
4116                                    query.append(WHERE_AND);
4117                            }
4118    
4119                            for (int i = 0; i < orderByConditionFields.length; i++) {
4120                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4121                                    query.append(orderByConditionFields[i]);
4122    
4123                                    if ((i + 1) < orderByConditionFields.length) {
4124                                            if (orderByComparator.isAscending() ^ previous) {
4125                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4126                                            }
4127                                            else {
4128                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4129                                            }
4130                                    }
4131                                    else {
4132                                            if (orderByComparator.isAscending() ^ previous) {
4133                                                    query.append(WHERE_GREATER_THAN);
4134                                            }
4135                                            else {
4136                                                    query.append(WHERE_LESSER_THAN);
4137                                            }
4138                                    }
4139                            }
4140    
4141                            query.append(ORDER_BY_CLAUSE);
4142    
4143                            String[] orderByFields = orderByComparator.getOrderByFields();
4144    
4145                            for (int i = 0; i < orderByFields.length; i++) {
4146                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4147                                    query.append(orderByFields[i]);
4148    
4149                                    if ((i + 1) < orderByFields.length) {
4150                                            if (orderByComparator.isAscending() ^ previous) {
4151                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4152                                            }
4153                                            else {
4154                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4155                                            }
4156                                    }
4157                                    else {
4158                                            if (orderByComparator.isAscending() ^ previous) {
4159                                                    query.append(ORDER_BY_ASC);
4160                                            }
4161                                            else {
4162                                                    query.append(ORDER_BY_DESC);
4163                                            }
4164                                    }
4165                            }
4166                    }
4167                    else {
4168                            query.append(RoleModelImpl.ORDER_BY_JPQL);
4169                    }
4170    
4171                    String sql = query.toString();
4172    
4173                    Query q = session.createQuery(sql);
4174    
4175                    q.setFirstResult(0);
4176                    q.setMaxResults(2);
4177    
4178                    QueryPos qPos = QueryPos.getInstance(q);
4179    
4180                    qPos.add(type);
4181    
4182                    if (orderByComparator != null) {
4183                            Object[] values = orderByComparator.getOrderByConditionValues(role);
4184    
4185                            for (Object value : values) {
4186                                    qPos.add(value);
4187                            }
4188                    }
4189    
4190                    List<Role> list = q.list();
4191    
4192                    if (list.size() == 2) {
4193                            return list.get(1);
4194                    }
4195                    else {
4196                            return null;
4197                    }
4198            }
4199    
4200            /**
4201             * Returns all the roles that the user has permission to view where type = &#63;.
4202             *
4203             * @param type the type
4204             * @return the matching roles that the user has permission to view
4205             * @throws SystemException if a system exception occurred
4206             */
4207            @Override
4208            public List<Role> filterFindByType(int type) throws SystemException {
4209                    return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4210            }
4211    
4212            /**
4213             * Returns a range of all the roles that the user has permission to view where type = &#63;.
4214             *
4215             * <p>
4216             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4217             * </p>
4218             *
4219             * @param type the type
4220             * @param start the lower bound of the range of roles
4221             * @param end the upper bound of the range of roles (not inclusive)
4222             * @return the range of matching roles that the user has permission to view
4223             * @throws SystemException if a system exception occurred
4224             */
4225            @Override
4226            public List<Role> filterFindByType(int type, int start, int end)
4227                    throws SystemException {
4228                    return filterFindByType(type, start, end, null);
4229            }
4230    
4231            /**
4232             * Returns an ordered range of all the roles that the user has permissions to view where type = &#63;.
4233             *
4234             * <p>
4235             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4236             * </p>
4237             *
4238             * @param type the type
4239             * @param start the lower bound of the range of roles
4240             * @param end the upper bound of the range of roles (not inclusive)
4241             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4242             * @return the ordered range of matching roles that the user has permission to view
4243             * @throws SystemException if a system exception occurred
4244             */
4245            @Override
4246            public List<Role> filterFindByType(int type, int start, int end,
4247                    OrderByComparator orderByComparator) throws SystemException {
4248                    if (!InlineSQLHelperUtil.isEnabled()) {
4249                            return findByType(type, start, end, orderByComparator);
4250                    }
4251    
4252                    StringBundler query = null;
4253    
4254                    if (orderByComparator != null) {
4255                            query = new StringBundler(3 +
4256                                            (orderByComparator.getOrderByFields().length * 3));
4257                    }
4258                    else {
4259                            query = new StringBundler(3);
4260                    }
4261    
4262                    if (getDB().isSupportsInlineDistinct()) {
4263                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4264                    }
4265                    else {
4266                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4267                    }
4268    
4269                    query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4270    
4271                    if (!getDB().isSupportsInlineDistinct()) {
4272                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4273                    }
4274    
4275                    if (orderByComparator != null) {
4276                            if (getDB().isSupportsInlineDistinct()) {
4277                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4278                                            orderByComparator, true);
4279                            }
4280                            else {
4281                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4282                                            orderByComparator, true);
4283                            }
4284                    }
4285                    else {
4286                            if (getDB().isSupportsInlineDistinct()) {
4287                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
4288                            }
4289                            else {
4290                                    query.append(RoleModelImpl.ORDER_BY_SQL);
4291                            }
4292                    }
4293    
4294                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4295                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4296    
4297                    Session session = null;
4298    
4299                    try {
4300                            session = openSession();
4301    
4302                            SQLQuery q = session.createSQLQuery(sql);
4303    
4304                            if (getDB().isSupportsInlineDistinct()) {
4305                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4306                            }
4307                            else {
4308                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4309                            }
4310    
4311                            QueryPos qPos = QueryPos.getInstance(q);
4312    
4313                            qPos.add(type);
4314    
4315                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
4316                    }
4317                    catch (Exception e) {
4318                            throw processException(e);
4319                    }
4320                    finally {
4321                            closeSession(session);
4322                    }
4323            }
4324    
4325            /**
4326             * 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;.
4327             *
4328             * @param roleId the primary key of the current role
4329             * @param type the type
4330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4331             * @return the previous, current, and next role
4332             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
4333             * @throws SystemException if a system exception occurred
4334             */
4335            @Override
4336            public Role[] filterFindByType_PrevAndNext(long roleId, int type,
4337                    OrderByComparator orderByComparator)
4338                    throws NoSuchRoleException, SystemException {
4339                    if (!InlineSQLHelperUtil.isEnabled()) {
4340                            return findByType_PrevAndNext(roleId, type, orderByComparator);
4341                    }
4342    
4343                    Role role = findByPrimaryKey(roleId);
4344    
4345                    Session session = null;
4346    
4347                    try {
4348                            session = openSession();
4349    
4350                            Role[] array = new RoleImpl[3];
4351    
4352                            array[0] = filterGetByType_PrevAndNext(session, role, type,
4353                                            orderByComparator, true);
4354    
4355                            array[1] = role;
4356    
4357                            array[2] = filterGetByType_PrevAndNext(session, role, type,
4358                                            orderByComparator, false);
4359    
4360                            return array;
4361                    }
4362                    catch (Exception e) {
4363                            throw processException(e);
4364                    }
4365                    finally {
4366                            closeSession(session);
4367                    }
4368            }
4369    
4370            protected Role filterGetByType_PrevAndNext(Session session, Role role,
4371                    int type, OrderByComparator orderByComparator, boolean previous) {
4372                    StringBundler query = null;
4373    
4374                    if (orderByComparator != null) {
4375                            query = new StringBundler(6 +
4376                                            (orderByComparator.getOrderByFields().length * 6));
4377                    }
4378                    else {
4379                            query = new StringBundler(3);
4380                    }
4381    
4382                    if (getDB().isSupportsInlineDistinct()) {
4383                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4384                    }
4385                    else {
4386                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4387                    }
4388    
4389                    query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4390    
4391                    if (!getDB().isSupportsInlineDistinct()) {
4392                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4393                    }
4394    
4395                    if (orderByComparator != null) {
4396                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4397    
4398                            if (orderByConditionFields.length > 0) {
4399                                    query.append(WHERE_AND);
4400                            }
4401    
4402                            for (int i = 0; i < orderByConditionFields.length; i++) {
4403                                    if (getDB().isSupportsInlineDistinct()) {
4404                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4405                                    }
4406                                    else {
4407                                            query.append(_ORDER_BY_ENTITY_TABLE);
4408                                    }
4409    
4410                                    query.append(orderByConditionFields[i]);
4411    
4412                                    if ((i + 1) < orderByConditionFields.length) {
4413                                            if (orderByComparator.isAscending() ^ previous) {
4414                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4415                                            }
4416                                            else {
4417                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4418                                            }
4419                                    }
4420                                    else {
4421                                            if (orderByComparator.isAscending() ^ previous) {
4422                                                    query.append(WHERE_GREATER_THAN);
4423                                            }
4424                                            else {
4425                                                    query.append(WHERE_LESSER_THAN);
4426                                            }
4427                                    }
4428                            }
4429    
4430                            query.append(ORDER_BY_CLAUSE);
4431    
4432                            String[] orderByFields = orderByComparator.getOrderByFields();
4433    
4434                            for (int i = 0; i < orderByFields.length; i++) {
4435                                    if (getDB().isSupportsInlineDistinct()) {
4436                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4437                                    }
4438                                    else {
4439                                            query.append(_ORDER_BY_ENTITY_TABLE);
4440                                    }
4441    
4442                                    query.append(orderByFields[i]);
4443    
4444                                    if ((i + 1) < orderByFields.length) {
4445                                            if (orderByComparator.isAscending() ^ previous) {
4446                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4447                                            }
4448                                            else {
4449                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4450                                            }
4451                                    }
4452                                    else {
4453                                            if (orderByComparator.isAscending() ^ previous) {
4454                                                    query.append(ORDER_BY_ASC);
4455                                            }
4456                                            else {
4457                                                    query.append(ORDER_BY_DESC);
4458                                            }
4459                                    }
4460                            }
4461                    }
4462                    else {
4463                            if (getDB().isSupportsInlineDistinct()) {
4464                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
4465                            }
4466                            else {
4467                                    query.append(RoleModelImpl.ORDER_BY_SQL);
4468                            }
4469                    }
4470    
4471                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4472                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4473    
4474                    SQLQuery q = session.createSQLQuery(sql);
4475    
4476                    q.setFirstResult(0);
4477                    q.setMaxResults(2);
4478    
4479                    if (getDB().isSupportsInlineDistinct()) {
4480                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4481                    }
4482                    else {
4483                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4484                    }
4485    
4486                    QueryPos qPos = QueryPos.getInstance(q);
4487    
4488                    qPos.add(type);
4489    
4490                    if (orderByComparator != null) {
4491                            Object[] values = orderByComparator.getOrderByConditionValues(role);
4492    
4493                            for (Object value : values) {
4494                                    qPos.add(value);
4495                            }
4496                    }
4497    
4498                    List<Role> list = q.list();
4499    
4500                    if (list.size() == 2) {
4501                            return list.get(1);
4502                    }
4503                    else {
4504                            return null;
4505                    }
4506            }
4507    
4508            /**
4509             * Removes all the roles where type = &#63; from the database.
4510             *
4511             * @param type the type
4512             * @throws SystemException if a system exception occurred
4513             */
4514            @Override
4515            public void removeByType(int type) throws SystemException {
4516                    for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4517                                    null)) {
4518                            remove(role);
4519                    }
4520            }
4521    
4522            /**
4523             * Returns the number of roles where type = &#63;.
4524             *
4525             * @param type the type
4526             * @return the number of matching roles
4527             * @throws SystemException if a system exception occurred
4528             */
4529            @Override
4530            public int countByType(int type) throws SystemException {
4531                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
4532    
4533                    Object[] finderArgs = new Object[] { type };
4534    
4535                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4536                                    this);
4537    
4538                    if (count == null) {
4539                            StringBundler query = new StringBundler(2);
4540    
4541                            query.append(_SQL_COUNT_ROLE_WHERE);
4542    
4543                            query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4544    
4545                            String sql = query.toString();
4546    
4547                            Session session = null;
4548    
4549                            try {
4550                                    session = openSession();
4551    
4552                                    Query q = session.createQuery(sql);
4553    
4554                                    QueryPos qPos = QueryPos.getInstance(q);
4555    
4556                                    qPos.add(type);
4557    
4558                                    count = (Long)q.uniqueResult();
4559    
4560                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4561                            }
4562                            catch (Exception e) {
4563                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4564    
4565                                    throw processException(e);
4566                            }
4567                            finally {
4568                                    closeSession(session);
4569                            }
4570                    }
4571    
4572                    return count.intValue();
4573            }
4574    
4575            /**
4576             * Returns the number of roles that the user has permission to view where type = &#63;.
4577             *
4578             * @param type the type
4579             * @return the number of matching roles that the user has permission to view
4580             * @throws SystemException if a system exception occurred
4581             */
4582            @Override
4583            public int filterCountByType(int type) throws SystemException {
4584                    if (!InlineSQLHelperUtil.isEnabled()) {
4585                            return countByType(type);
4586                    }
4587    
4588                    StringBundler query = new StringBundler(2);
4589    
4590                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4591    
4592                    query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4593    
4594                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4595                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4596    
4597                    Session session = null;
4598    
4599                    try {
4600                            session = openSession();
4601    
4602                            SQLQuery q = session.createSQLQuery(sql);
4603    
4604                            q.addScalar(COUNT_COLUMN_NAME,
4605                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4606    
4607                            QueryPos qPos = QueryPos.getInstance(q);
4608    
4609                            qPos.add(type);
4610    
4611                            Long count = (Long)q.uniqueResult();
4612    
4613                            return count.intValue();
4614                    }
4615                    catch (Exception e) {
4616                            throw processException(e);
4617                    }
4618                    finally {
4619                            closeSession(session);
4620                    }
4621            }
4622    
4623            private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?";
4624            private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?";
4625            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4626                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4627                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
4628                            new String[] {
4629                                    String.class.getName(),
4630                                    
4631                            Integer.class.getName(), Integer.class.getName(),
4632                                    OrderByComparator.class.getName()
4633                            });
4634            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
4635                    new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4636                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4637                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
4638                            new String[] { String.class.getName() },
4639                            RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
4640                            RoleModelImpl.NAME_COLUMN_BITMASK);
4641            public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4642                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4643                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
4644                            new String[] { String.class.getName() });
4645    
4646            /**
4647             * Returns all the roles where subtype = &#63;.
4648             *
4649             * @param subtype the subtype
4650             * @return the matching roles
4651             * @throws SystemException if a system exception occurred
4652             */
4653            @Override
4654            public List<Role> findBySubtype(String subtype) throws SystemException {
4655                    return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4656            }
4657    
4658            /**
4659             * Returns a range of all the roles where subtype = &#63;.
4660             *
4661             * <p>
4662             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4663             * </p>
4664             *
4665             * @param subtype the subtype
4666             * @param start the lower bound of the range of roles
4667             * @param end the upper bound of the range of roles (not inclusive)
4668             * @return the range of matching roles
4669             * @throws SystemException if a system exception occurred
4670             */
4671            @Override
4672            public List<Role> findBySubtype(String subtype, int start, int end)
4673                    throws SystemException {
4674                    return findBySubtype(subtype, start, end, null);
4675            }
4676    
4677            /**
4678             * Returns an ordered range of all the roles where subtype = &#63;.
4679             *
4680             * <p>
4681             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4682             * </p>
4683             *
4684             * @param subtype the subtype
4685             * @param start the lower bound of the range of roles
4686             * @param end the upper bound of the range of roles (not inclusive)
4687             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4688             * @return the ordered range of matching roles
4689             * @throws SystemException if a system exception occurred
4690             */
4691            @Override
4692            public List<Role> findBySubtype(String subtype, int start, int end,
4693                    OrderByComparator orderByComparator) throws SystemException {
4694                    boolean pagination = true;
4695                    FinderPath finderPath = null;
4696                    Object[] finderArgs = null;
4697    
4698                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4699                                    (orderByComparator == null)) {
4700                            pagination = false;
4701                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
4702                            finderArgs = new Object[] { subtype };
4703                    }
4704                    else {
4705                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
4706                            finderArgs = new Object[] { subtype, start, end, orderByComparator };
4707                    }
4708    
4709                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
4710                                    finderArgs, this);
4711    
4712                    if ((list != null) && !list.isEmpty()) {
4713                            for (Role role : list) {
4714                                    if (!Validator.equals(subtype, role.getSubtype())) {
4715                                            list = null;
4716    
4717                                            break;
4718                                    }
4719                            }
4720                    }
4721    
4722                    if (list == null) {
4723                            StringBundler query = null;
4724    
4725                            if (orderByComparator != null) {
4726                                    query = new StringBundler(3 +
4727                                                    (orderByComparator.getOrderByFields().length * 3));
4728                            }
4729                            else {
4730                                    query = new StringBundler(3);
4731                            }
4732    
4733                            query.append(_SQL_SELECT_ROLE_WHERE);
4734    
4735                            boolean bindSubtype = false;
4736    
4737                            if (subtype == null) {
4738                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4739                            }
4740                            else if (subtype.equals(StringPool.BLANK)) {
4741                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4742                            }
4743                            else {
4744                                    bindSubtype = true;
4745    
4746                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4747                            }
4748    
4749                            if (orderByComparator != null) {
4750                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4751                                            orderByComparator);
4752                            }
4753                            else
4754                             if (pagination) {
4755                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
4756                            }
4757    
4758                            String sql = query.toString();
4759    
4760                            Session session = null;
4761    
4762                            try {
4763                                    session = openSession();
4764    
4765                                    Query q = session.createQuery(sql);
4766    
4767                                    QueryPos qPos = QueryPos.getInstance(q);
4768    
4769                                    if (bindSubtype) {
4770                                            qPos.add(subtype);
4771                                    }
4772    
4773                                    if (!pagination) {
4774                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4775                                                            end, false);
4776    
4777                                            Collections.sort(list);
4778    
4779                                            list = new UnmodifiableList<Role>(list);
4780                                    }
4781                                    else {
4782                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4783                                                            end);
4784                                    }
4785    
4786                                    cacheResult(list);
4787    
4788                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4789                            }
4790                            catch (Exception e) {
4791                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4792    
4793                                    throw processException(e);
4794                            }
4795                            finally {
4796                                    closeSession(session);
4797                            }
4798                    }
4799    
4800                    return list;
4801            }
4802    
4803            /**
4804             * Returns the first role in the ordered set where subtype = &#63;.
4805             *
4806             * @param subtype the subtype
4807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4808             * @return the first matching role
4809             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
4810             * @throws SystemException if a system exception occurred
4811             */
4812            @Override
4813            public Role findBySubtype_First(String subtype,
4814                    OrderByComparator orderByComparator)
4815                    throws NoSuchRoleException, SystemException {
4816                    Role role = fetchBySubtype_First(subtype, orderByComparator);
4817    
4818                    if (role != null) {
4819                            return role;
4820                    }
4821    
4822                    StringBundler msg = new StringBundler(4);
4823    
4824                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4825    
4826                    msg.append("subtype=");
4827                    msg.append(subtype);
4828    
4829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4830    
4831                    throw new NoSuchRoleException(msg.toString());
4832            }
4833    
4834            /**
4835             * Returns the first role in the ordered set where subtype = &#63;.
4836             *
4837             * @param subtype the subtype
4838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4839             * @return the first matching role, or <code>null</code> if a matching role could not be found
4840             * @throws SystemException if a system exception occurred
4841             */
4842            @Override
4843            public Role fetchBySubtype_First(String subtype,
4844                    OrderByComparator orderByComparator) throws SystemException {
4845                    List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
4846    
4847                    if (!list.isEmpty()) {
4848                            return list.get(0);
4849                    }
4850    
4851                    return null;
4852            }
4853    
4854            /**
4855             * Returns the last role in the ordered set where subtype = &#63;.
4856             *
4857             * @param subtype the subtype
4858             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4859             * @return the last matching role
4860             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
4861             * @throws SystemException if a system exception occurred
4862             */
4863            @Override
4864            public Role findBySubtype_Last(String subtype,
4865                    OrderByComparator orderByComparator)
4866                    throws NoSuchRoleException, SystemException {
4867                    Role role = fetchBySubtype_Last(subtype, orderByComparator);
4868    
4869                    if (role != null) {
4870                            return role;
4871                    }
4872    
4873                    StringBundler msg = new StringBundler(4);
4874    
4875                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4876    
4877                    msg.append("subtype=");
4878                    msg.append(subtype);
4879    
4880                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4881    
4882                    throw new NoSuchRoleException(msg.toString());
4883            }
4884    
4885            /**
4886             * Returns the last role in the ordered set where subtype = &#63;.
4887             *
4888             * @param subtype the subtype
4889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4890             * @return the last matching role, or <code>null</code> if a matching role could not be found
4891             * @throws SystemException if a system exception occurred
4892             */
4893            @Override
4894            public Role fetchBySubtype_Last(String subtype,
4895                    OrderByComparator orderByComparator) throws SystemException {
4896                    int count = countBySubtype(subtype);
4897    
4898                    if (count == 0) {
4899                            return null;
4900                    }
4901    
4902                    List<Role> list = findBySubtype(subtype, count - 1, count,
4903                                    orderByComparator);
4904    
4905                    if (!list.isEmpty()) {
4906                            return list.get(0);
4907                    }
4908    
4909                    return null;
4910            }
4911    
4912            /**
4913             * Returns the roles before and after the current role in the ordered set where subtype = &#63;.
4914             *
4915             * @param roleId the primary key of the current role
4916             * @param subtype the subtype
4917             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4918             * @return the previous, current, and next role
4919             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
4920             * @throws SystemException if a system exception occurred
4921             */
4922            @Override
4923            public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
4924                    OrderByComparator orderByComparator)
4925                    throws NoSuchRoleException, SystemException {
4926                    Role role = findByPrimaryKey(roleId);
4927    
4928                    Session session = null;
4929    
4930                    try {
4931                            session = openSession();
4932    
4933                            Role[] array = new RoleImpl[3];
4934    
4935                            array[0] = getBySubtype_PrevAndNext(session, role, subtype,
4936                                            orderByComparator, true);
4937    
4938                            array[1] = role;
4939    
4940                            array[2] = getBySubtype_PrevAndNext(session, role, subtype,
4941                                            orderByComparator, false);
4942    
4943                            return array;
4944                    }
4945                    catch (Exception e) {
4946                            throw processException(e);
4947                    }
4948                    finally {
4949                            closeSession(session);
4950                    }
4951            }
4952    
4953            protected Role getBySubtype_PrevAndNext(Session session, Role role,
4954                    String subtype, OrderByComparator orderByComparator, boolean previous) {
4955                    StringBundler query = null;
4956    
4957                    if (orderByComparator != null) {
4958                            query = new StringBundler(6 +
4959                                            (orderByComparator.getOrderByFields().length * 6));
4960                    }
4961                    else {
4962                            query = new StringBundler(3);
4963                    }
4964    
4965                    query.append(_SQL_SELECT_ROLE_WHERE);
4966    
4967                    boolean bindSubtype = false;
4968    
4969                    if (subtype == null) {
4970                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4971                    }
4972                    else if (subtype.equals(StringPool.BLANK)) {
4973                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4974                    }
4975                    else {
4976                            bindSubtype = true;
4977    
4978                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4979                    }
4980    
4981                    if (orderByComparator != null) {
4982                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4983    
4984                            if (orderByConditionFields.length > 0) {
4985                                    query.append(WHERE_AND);
4986                            }
4987    
4988                            for (int i = 0; i < orderByConditionFields.length; i++) {
4989                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4990                                    query.append(orderByConditionFields[i]);
4991    
4992                                    if ((i + 1) < orderByConditionFields.length) {
4993                                            if (orderByComparator.isAscending() ^ previous) {
4994                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4995                                            }
4996                                            else {
4997                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4998                                            }
4999                                    }
5000                                    else {
5001                                            if (orderByComparator.isAscending() ^ previous) {
5002                                                    query.append(WHERE_GREATER_THAN);
5003                                            }
5004                                            else {
5005                                                    query.append(WHERE_LESSER_THAN);
5006                                            }
5007                                    }
5008                            }
5009    
5010                            query.append(ORDER_BY_CLAUSE);
5011    
5012                            String[] orderByFields = orderByComparator.getOrderByFields();
5013    
5014                            for (int i = 0; i < orderByFields.length; i++) {
5015                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5016                                    query.append(orderByFields[i]);
5017    
5018                                    if ((i + 1) < orderByFields.length) {
5019                                            if (orderByComparator.isAscending() ^ previous) {
5020                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5021                                            }
5022                                            else {
5023                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5024                                            }
5025                                    }
5026                                    else {
5027                                            if (orderByComparator.isAscending() ^ previous) {
5028                                                    query.append(ORDER_BY_ASC);
5029                                            }
5030                                            else {
5031                                                    query.append(ORDER_BY_DESC);
5032                                            }
5033                                    }
5034                            }
5035                    }
5036                    else {
5037                            query.append(RoleModelImpl.ORDER_BY_JPQL);
5038                    }
5039    
5040                    String sql = query.toString();
5041    
5042                    Query q = session.createQuery(sql);
5043    
5044                    q.setFirstResult(0);
5045                    q.setMaxResults(2);
5046    
5047                    QueryPos qPos = QueryPos.getInstance(q);
5048    
5049                    if (bindSubtype) {
5050                            qPos.add(subtype);
5051                    }
5052    
5053                    if (orderByComparator != null) {
5054                            Object[] values = orderByComparator.getOrderByConditionValues(role);
5055    
5056                            for (Object value : values) {
5057                                    qPos.add(value);
5058                            }
5059                    }
5060    
5061                    List<Role> list = q.list();
5062    
5063                    if (list.size() == 2) {
5064                            return list.get(1);
5065                    }
5066                    else {
5067                            return null;
5068                    }
5069            }
5070    
5071            /**
5072             * Returns all the roles that the user has permission to view where subtype = &#63;.
5073             *
5074             * @param subtype the subtype
5075             * @return the matching roles that the user has permission to view
5076             * @throws SystemException if a system exception occurred
5077             */
5078            @Override
5079            public List<Role> filterFindBySubtype(String subtype)
5080                    throws SystemException {
5081                    return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
5082                            QueryUtil.ALL_POS, null);
5083            }
5084    
5085            /**
5086             * Returns a range of all the roles that the user has permission to view where subtype = &#63;.
5087             *
5088             * <p>
5089             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5090             * </p>
5091             *
5092             * @param subtype the subtype
5093             * @param start the lower bound of the range of roles
5094             * @param end the upper bound of the range of roles (not inclusive)
5095             * @return the range of matching roles that the user has permission to view
5096             * @throws SystemException if a system exception occurred
5097             */
5098            @Override
5099            public List<Role> filterFindBySubtype(String subtype, int start, int end)
5100                    throws SystemException {
5101                    return filterFindBySubtype(subtype, start, end, null);
5102            }
5103    
5104            /**
5105             * Returns an ordered range of all the roles that the user has permissions to view where subtype = &#63;.
5106             *
5107             * <p>
5108             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5109             * </p>
5110             *
5111             * @param subtype the subtype
5112             * @param start the lower bound of the range of roles
5113             * @param end the upper bound of the range of roles (not inclusive)
5114             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5115             * @return the ordered range of matching roles that the user has permission to view
5116             * @throws SystemException if a system exception occurred
5117             */
5118            @Override
5119            public List<Role> filterFindBySubtype(String subtype, int start, int end,
5120                    OrderByComparator orderByComparator) throws SystemException {
5121                    if (!InlineSQLHelperUtil.isEnabled()) {
5122                            return findBySubtype(subtype, start, end, orderByComparator);
5123                    }
5124    
5125                    StringBundler query = null;
5126    
5127                    if (orderByComparator != null) {
5128                            query = new StringBundler(3 +
5129                                            (orderByComparator.getOrderByFields().length * 3));
5130                    }
5131                    else {
5132                            query = new StringBundler(3);
5133                    }
5134    
5135                    if (getDB().isSupportsInlineDistinct()) {
5136                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5137                    }
5138                    else {
5139                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5140                    }
5141    
5142                    boolean bindSubtype = false;
5143    
5144                    if (subtype == null) {
5145                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5146                    }
5147                    else if (subtype.equals(StringPool.BLANK)) {
5148                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5149                    }
5150                    else {
5151                            bindSubtype = true;
5152    
5153                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5154                    }
5155    
5156                    if (!getDB().isSupportsInlineDistinct()) {
5157                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5158                    }
5159    
5160                    if (orderByComparator != null) {
5161                            if (getDB().isSupportsInlineDistinct()) {
5162                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5163                                            orderByComparator, true);
5164                            }
5165                            else {
5166                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5167                                            orderByComparator, true);
5168                            }
5169                    }
5170                    else {
5171                            if (getDB().isSupportsInlineDistinct()) {
5172                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
5173                            }
5174                            else {
5175                                    query.append(RoleModelImpl.ORDER_BY_SQL);
5176                            }
5177                    }
5178    
5179                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5180                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5181    
5182                    Session session = null;
5183    
5184                    try {
5185                            session = openSession();
5186    
5187                            SQLQuery q = session.createSQLQuery(sql);
5188    
5189                            if (getDB().isSupportsInlineDistinct()) {
5190                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5191                            }
5192                            else {
5193                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5194                            }
5195    
5196                            QueryPos qPos = QueryPos.getInstance(q);
5197    
5198                            if (bindSubtype) {
5199                                    qPos.add(subtype);
5200                            }
5201    
5202                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
5203                    }
5204                    catch (Exception e) {
5205                            throw processException(e);
5206                    }
5207                    finally {
5208                            closeSession(session);
5209                    }
5210            }
5211    
5212            /**
5213             * 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;.
5214             *
5215             * @param roleId the primary key of the current role
5216             * @param subtype the subtype
5217             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5218             * @return the previous, current, and next role
5219             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
5220             * @throws SystemException if a system exception occurred
5221             */
5222            @Override
5223            public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
5224                    OrderByComparator orderByComparator)
5225                    throws NoSuchRoleException, SystemException {
5226                    if (!InlineSQLHelperUtil.isEnabled()) {
5227                            return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
5228                    }
5229    
5230                    Role role = findByPrimaryKey(roleId);
5231    
5232                    Session session = null;
5233    
5234                    try {
5235                            session = openSession();
5236    
5237                            Role[] array = new RoleImpl[3];
5238    
5239                            array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5240                                            orderByComparator, true);
5241    
5242                            array[1] = role;
5243    
5244                            array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5245                                            orderByComparator, false);
5246    
5247                            return array;
5248                    }
5249                    catch (Exception e) {
5250                            throw processException(e);
5251                    }
5252                    finally {
5253                            closeSession(session);
5254                    }
5255            }
5256    
5257            protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
5258                    String subtype, OrderByComparator orderByComparator, boolean previous) {
5259                    StringBundler query = null;
5260    
5261                    if (orderByComparator != null) {
5262                            query = new StringBundler(6 +
5263                                            (orderByComparator.getOrderByFields().length * 6));
5264                    }
5265                    else {
5266                            query = new StringBundler(3);
5267                    }
5268    
5269                    if (getDB().isSupportsInlineDistinct()) {
5270                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5271                    }
5272                    else {
5273                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5274                    }
5275    
5276                    boolean bindSubtype = false;
5277    
5278                    if (subtype == null) {
5279                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5280                    }
5281                    else if (subtype.equals(StringPool.BLANK)) {
5282                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5283                    }
5284                    else {
5285                            bindSubtype = true;
5286    
5287                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5288                    }
5289    
5290                    if (!getDB().isSupportsInlineDistinct()) {
5291                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5292                    }
5293    
5294                    if (orderByComparator != null) {
5295                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5296    
5297                            if (orderByConditionFields.length > 0) {
5298                                    query.append(WHERE_AND);
5299                            }
5300    
5301                            for (int i = 0; i < orderByConditionFields.length; i++) {
5302                                    if (getDB().isSupportsInlineDistinct()) {
5303                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5304                                    }
5305                                    else {
5306                                            query.append(_ORDER_BY_ENTITY_TABLE);
5307                                    }
5308    
5309                                    query.append(orderByConditionFields[i]);
5310    
5311                                    if ((i + 1) < orderByConditionFields.length) {
5312                                            if (orderByComparator.isAscending() ^ previous) {
5313                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5314                                            }
5315                                            else {
5316                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5317                                            }
5318                                    }
5319                                    else {
5320                                            if (orderByComparator.isAscending() ^ previous) {
5321                                                    query.append(WHERE_GREATER_THAN);
5322                                            }
5323                                            else {
5324                                                    query.append(WHERE_LESSER_THAN);
5325                                            }
5326                                    }
5327                            }
5328    
5329                            query.append(ORDER_BY_CLAUSE);
5330    
5331                            String[] orderByFields = orderByComparator.getOrderByFields();
5332    
5333                            for (int i = 0; i < orderByFields.length; i++) {
5334                                    if (getDB().isSupportsInlineDistinct()) {
5335                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5336                                    }
5337                                    else {
5338                                            query.append(_ORDER_BY_ENTITY_TABLE);
5339                                    }
5340    
5341                                    query.append(orderByFields[i]);
5342    
5343                                    if ((i + 1) < orderByFields.length) {
5344                                            if (orderByComparator.isAscending() ^ previous) {
5345                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5346                                            }
5347                                            else {
5348                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5349                                            }
5350                                    }
5351                                    else {
5352                                            if (orderByComparator.isAscending() ^ previous) {
5353                                                    query.append(ORDER_BY_ASC);
5354                                            }
5355                                            else {
5356                                                    query.append(ORDER_BY_DESC);
5357                                            }
5358                                    }
5359                            }
5360                    }
5361                    else {
5362                            if (getDB().isSupportsInlineDistinct()) {
5363                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
5364                            }
5365                            else {
5366                                    query.append(RoleModelImpl.ORDER_BY_SQL);
5367                            }
5368                    }
5369    
5370                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5371                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5372    
5373                    SQLQuery q = session.createSQLQuery(sql);
5374    
5375                    q.setFirstResult(0);
5376                    q.setMaxResults(2);
5377    
5378                    if (getDB().isSupportsInlineDistinct()) {
5379                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5380                    }
5381                    else {
5382                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5383                    }
5384    
5385                    QueryPos qPos = QueryPos.getInstance(q);
5386    
5387                    if (bindSubtype) {
5388                            qPos.add(subtype);
5389                    }
5390    
5391                    if (orderByComparator != null) {
5392                            Object[] values = orderByComparator.getOrderByConditionValues(role);
5393    
5394                            for (Object value : values) {
5395                                    qPos.add(value);
5396                            }
5397                    }
5398    
5399                    List<Role> list = q.list();
5400    
5401                    if (list.size() == 2) {
5402                            return list.get(1);
5403                    }
5404                    else {
5405                            return null;
5406                    }
5407            }
5408    
5409            /**
5410             * Removes all the roles where subtype = &#63; from the database.
5411             *
5412             * @param subtype the subtype
5413             * @throws SystemException if a system exception occurred
5414             */
5415            @Override
5416            public void removeBySubtype(String subtype) throws SystemException {
5417                    for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
5418                                    QueryUtil.ALL_POS, null)) {
5419                            remove(role);
5420                    }
5421            }
5422    
5423            /**
5424             * Returns the number of roles where subtype = &#63;.
5425             *
5426             * @param subtype the subtype
5427             * @return the number of matching roles
5428             * @throws SystemException if a system exception occurred
5429             */
5430            @Override
5431            public int countBySubtype(String subtype) throws SystemException {
5432                    FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
5433    
5434                    Object[] finderArgs = new Object[] { subtype };
5435    
5436                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5437                                    this);
5438    
5439                    if (count == null) {
5440                            StringBundler query = new StringBundler(2);
5441    
5442                            query.append(_SQL_COUNT_ROLE_WHERE);
5443    
5444                            boolean bindSubtype = false;
5445    
5446                            if (subtype == null) {
5447                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5448                            }
5449                            else if (subtype.equals(StringPool.BLANK)) {
5450                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5451                            }
5452                            else {
5453                                    bindSubtype = true;
5454    
5455                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5456                            }
5457    
5458                            String sql = query.toString();
5459    
5460                            Session session = null;
5461    
5462                            try {
5463                                    session = openSession();
5464    
5465                                    Query q = session.createQuery(sql);
5466    
5467                                    QueryPos qPos = QueryPos.getInstance(q);
5468    
5469                                    if (bindSubtype) {
5470                                            qPos.add(subtype);
5471                                    }
5472    
5473                                    count = (Long)q.uniqueResult();
5474    
5475                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5476                            }
5477                            catch (Exception e) {
5478                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5479    
5480                                    throw processException(e);
5481                            }
5482                            finally {
5483                                    closeSession(session);
5484                            }
5485                    }
5486    
5487                    return count.intValue();
5488            }
5489    
5490            /**
5491             * Returns the number of roles that the user has permission to view where subtype = &#63;.
5492             *
5493             * @param subtype the subtype
5494             * @return the number of matching roles that the user has permission to view
5495             * @throws SystemException if a system exception occurred
5496             */
5497            @Override
5498            public int filterCountBySubtype(String subtype) throws SystemException {
5499                    if (!InlineSQLHelperUtil.isEnabled()) {
5500                            return countBySubtype(subtype);
5501                    }
5502    
5503                    StringBundler query = new StringBundler(2);
5504    
5505                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
5506    
5507                    boolean bindSubtype = false;
5508    
5509                    if (subtype == null) {
5510                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5511                    }
5512                    else if (subtype.equals(StringPool.BLANK)) {
5513                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5514                    }
5515                    else {
5516                            bindSubtype = true;
5517    
5518                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5519                    }
5520    
5521                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5522                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5523    
5524                    Session session = null;
5525    
5526                    try {
5527                            session = openSession();
5528    
5529                            SQLQuery q = session.createSQLQuery(sql);
5530    
5531                            q.addScalar(COUNT_COLUMN_NAME,
5532                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5533    
5534                            QueryPos qPos = QueryPos.getInstance(q);
5535    
5536                            if (bindSubtype) {
5537                                    qPos.add(subtype);
5538                            }
5539    
5540                            Long count = (Long)q.uniqueResult();
5541    
5542                            return count.intValue();
5543                    }
5544                    catch (Exception e) {
5545                            throw processException(e);
5546                    }
5547                    finally {
5548                            closeSession(session);
5549                    }
5550            }
5551    
5552            private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5553            private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5554            private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
5555            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5556                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5557                            FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5558                            new String[] { Long.class.getName(), String.class.getName() },
5559                            RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5560                            RoleModelImpl.NAME_COLUMN_BITMASK);
5561            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5562                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5563                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5564                            new String[] { Long.class.getName(), String.class.getName() });
5565    
5566            /**
5567             * Returns the role where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchRoleException} if it could not be found.
5568             *
5569             * @param companyId the company ID
5570             * @param name the name
5571             * @return the matching role
5572             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
5573             * @throws SystemException if a system exception occurred
5574             */
5575            @Override
5576            public Role findByC_N(long companyId, String name)
5577                    throws NoSuchRoleException, SystemException {
5578                    Role role = fetchByC_N(companyId, name);
5579    
5580                    if (role == null) {
5581                            StringBundler msg = new StringBundler(6);
5582    
5583                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5584    
5585                            msg.append("companyId=");
5586                            msg.append(companyId);
5587    
5588                            msg.append(", name=");
5589                            msg.append(name);
5590    
5591                            msg.append(StringPool.CLOSE_CURLY_BRACE);
5592    
5593                            if (_log.isWarnEnabled()) {
5594                                    _log.warn(msg.toString());
5595                            }
5596    
5597                            throw new NoSuchRoleException(msg.toString());
5598                    }
5599    
5600                    return role;
5601            }
5602    
5603            /**
5604             * Returns the role where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
5605             *
5606             * @param companyId the company ID
5607             * @param name the name
5608             * @return the matching role, or <code>null</code> if a matching role could not be found
5609             * @throws SystemException if a system exception occurred
5610             */
5611            @Override
5612            public Role fetchByC_N(long companyId, String name)
5613                    throws SystemException {
5614                    return fetchByC_N(companyId, name, true);
5615            }
5616    
5617            /**
5618             * 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.
5619             *
5620             * @param companyId the company ID
5621             * @param name the name
5622             * @param retrieveFromCache whether to use the finder cache
5623             * @return the matching role, or <code>null</code> if a matching role could not be found
5624             * @throws SystemException if a system exception occurred
5625             */
5626            @Override
5627            public Role fetchByC_N(long companyId, String name,
5628                    boolean retrieveFromCache) throws SystemException {
5629                    Object[] finderArgs = new Object[] { companyId, name };
5630    
5631                    Object result = null;
5632    
5633                    if (retrieveFromCache) {
5634                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5635                                            finderArgs, this);
5636                    }
5637    
5638                    if (result instanceof Role) {
5639                            Role role = (Role)result;
5640    
5641                            if ((companyId != role.getCompanyId()) ||
5642                                            !Validator.equals(name, role.getName())) {
5643                                    result = null;
5644                            }
5645                    }
5646    
5647                    if (result == null) {
5648                            StringBundler query = new StringBundler(4);
5649    
5650                            query.append(_SQL_SELECT_ROLE_WHERE);
5651    
5652                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5653    
5654                            boolean bindName = false;
5655    
5656                            if (name == null) {
5657                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
5658                            }
5659                            else if (name.equals(StringPool.BLANK)) {
5660                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
5661                            }
5662                            else {
5663                                    bindName = true;
5664    
5665                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
5666                            }
5667    
5668                            String sql = query.toString();
5669    
5670                            Session session = null;
5671    
5672                            try {
5673                                    session = openSession();
5674    
5675                                    Query q = session.createQuery(sql);
5676    
5677                                    QueryPos qPos = QueryPos.getInstance(q);
5678    
5679                                    qPos.add(companyId);
5680    
5681                                    if (bindName) {
5682                                            qPos.add(name.toLowerCase());
5683                                    }
5684    
5685                                    List<Role> list = q.list();
5686    
5687                                    if (list.isEmpty()) {
5688                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5689                                                    finderArgs, list);
5690                                    }
5691                                    else {
5692                                            Role role = list.get(0);
5693    
5694                                            result = role;
5695    
5696                                            cacheResult(role);
5697    
5698                                            if ((role.getCompanyId() != companyId) ||
5699                                                            (role.getName() == null) ||
5700                                                            !role.getName().equals(name)) {
5701                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5702                                                            finderArgs, role);
5703                                            }
5704                                    }
5705                            }
5706                            catch (Exception e) {
5707                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5708                                            finderArgs);
5709    
5710                                    throw processException(e);
5711                            }
5712                            finally {
5713                                    closeSession(session);
5714                            }
5715                    }
5716    
5717                    if (result instanceof List<?>) {
5718                            return null;
5719                    }
5720                    else {
5721                            return (Role)result;
5722                    }
5723            }
5724    
5725            /**
5726             * Removes the role where companyId = &#63; and name = &#63; from the database.
5727             *
5728             * @param companyId the company ID
5729             * @param name the name
5730             * @return the role that was removed
5731             * @throws SystemException if a system exception occurred
5732             */
5733            @Override
5734            public Role removeByC_N(long companyId, String name)
5735                    throws NoSuchRoleException, SystemException {
5736                    Role role = findByC_N(companyId, name);
5737    
5738                    return remove(role);
5739            }
5740    
5741            /**
5742             * Returns the number of roles where companyId = &#63; and name = &#63;.
5743             *
5744             * @param companyId the company ID
5745             * @param name the name
5746             * @return the number of matching roles
5747             * @throws SystemException if a system exception occurred
5748             */
5749            @Override
5750            public int countByC_N(long companyId, String name)
5751                    throws SystemException {
5752                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5753    
5754                    Object[] finderArgs = new Object[] { companyId, name };
5755    
5756                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5757                                    this);
5758    
5759                    if (count == null) {
5760                            StringBundler query = new StringBundler(3);
5761    
5762                            query.append(_SQL_COUNT_ROLE_WHERE);
5763    
5764                            query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5765    
5766                            boolean bindName = false;
5767    
5768                            if (name == null) {
5769                                    query.append(_FINDER_COLUMN_C_N_NAME_1);
5770                            }
5771                            else if (name.equals(StringPool.BLANK)) {
5772                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
5773                            }
5774                            else {
5775                                    bindName = true;
5776    
5777                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
5778                            }
5779    
5780                            String sql = query.toString();
5781    
5782                            Session session = null;
5783    
5784                            try {
5785                                    session = openSession();
5786    
5787                                    Query q = session.createQuery(sql);
5788    
5789                                    QueryPos qPos = QueryPos.getInstance(q);
5790    
5791                                    qPos.add(companyId);
5792    
5793                                    if (bindName) {
5794                                            qPos.add(name.toLowerCase());
5795                                    }
5796    
5797                                    count = (Long)q.uniqueResult();
5798    
5799                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5800                            }
5801                            catch (Exception e) {
5802                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5803    
5804                                    throw processException(e);
5805                            }
5806                            finally {
5807                                    closeSession(session);
5808                            }
5809                    }
5810    
5811                    return count.intValue();
5812            }
5813    
5814            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5815            private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5816            private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?";
5817            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')";
5818            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5819                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5820                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
5821                            new String[] {
5822                                    Long.class.getName(), Integer.class.getName(),
5823                                    
5824                            Integer.class.getName(), Integer.class.getName(),
5825                                    OrderByComparator.class.getName()
5826                            });
5827            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5828                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5829                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
5830                            new String[] { Long.class.getName(), Integer.class.getName() },
5831                            RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5832                            RoleModelImpl.TYPE_COLUMN_BITMASK |
5833                            RoleModelImpl.NAME_COLUMN_BITMASK);
5834            public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5835                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5836                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
5837                            new String[] { Long.class.getName(), Integer.class.getName() });
5838            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5839                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5840                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
5841                            new String[] { Long.class.getName(), Integer.class.getName() });
5842    
5843            /**
5844             * Returns all the roles where companyId = &#63; and type = &#63;.
5845             *
5846             * @param companyId the company ID
5847             * @param type the type
5848             * @return the matching roles
5849             * @throws SystemException if a system exception occurred
5850             */
5851            @Override
5852            public List<Role> findByC_T(long companyId, int type)
5853                    throws SystemException {
5854                    return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5855                            null);
5856            }
5857    
5858            /**
5859             * Returns a range of all the roles where companyId = &#63; and type = &#63;.
5860             *
5861             * <p>
5862             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5863             * </p>
5864             *
5865             * @param companyId the company ID
5866             * @param type the type
5867             * @param start the lower bound of the range of roles
5868             * @param end the upper bound of the range of roles (not inclusive)
5869             * @return the range of matching roles
5870             * @throws SystemException if a system exception occurred
5871             */
5872            @Override
5873            public List<Role> findByC_T(long companyId, int type, int start, int end)
5874                    throws SystemException {
5875                    return findByC_T(companyId, type, start, end, null);
5876            }
5877    
5878            /**
5879             * Returns an ordered range of all the roles where companyId = &#63; and type = &#63;.
5880             *
5881             * <p>
5882             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5883             * </p>
5884             *
5885             * @param companyId the company ID
5886             * @param type the type
5887             * @param start the lower bound of the range of roles
5888             * @param end the upper bound of the range of roles (not inclusive)
5889             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5890             * @return the ordered range of matching roles
5891             * @throws SystemException if a system exception occurred
5892             */
5893            @Override
5894            public List<Role> findByC_T(long companyId, int type, int start, int end,
5895                    OrderByComparator orderByComparator) throws SystemException {
5896                    boolean pagination = true;
5897                    FinderPath finderPath = null;
5898                    Object[] finderArgs = null;
5899    
5900                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5901                                    (orderByComparator == null)) {
5902                            pagination = false;
5903                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
5904                            finderArgs = new Object[] { companyId, type };
5905                    }
5906                    else {
5907                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
5908                            finderArgs = new Object[] {
5909                                            companyId, type,
5910                                            
5911                                            start, end, orderByComparator
5912                                    };
5913                    }
5914    
5915                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
5916                                    finderArgs, this);
5917    
5918                    if ((list != null) && !list.isEmpty()) {
5919                            for (Role role : list) {
5920                                    if ((companyId != role.getCompanyId()) ||
5921                                                    (type != role.getType())) {
5922                                            list = null;
5923    
5924                                            break;
5925                                    }
5926                            }
5927                    }
5928    
5929                    if (list == null) {
5930                            StringBundler query = null;
5931    
5932                            if (orderByComparator != null) {
5933                                    query = new StringBundler(4 +
5934                                                    (orderByComparator.getOrderByFields().length * 3));
5935                            }
5936                            else {
5937                                    query = new StringBundler(4);
5938                            }
5939    
5940                            query.append(_SQL_SELECT_ROLE_WHERE);
5941    
5942                            query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5943    
5944                            query.append(_FINDER_COLUMN_C_T_TYPE_2);
5945    
5946                            if (orderByComparator != null) {
5947                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5948                                            orderByComparator);
5949                            }
5950                            else
5951                             if (pagination) {
5952                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
5953                            }
5954    
5955                            String sql = query.toString();
5956    
5957                            Session session = null;
5958    
5959                            try {
5960                                    session = openSession();
5961    
5962                                    Query q = session.createQuery(sql);
5963    
5964                                    QueryPos qPos = QueryPos.getInstance(q);
5965    
5966                                    qPos.add(companyId);
5967    
5968                                    qPos.add(type);
5969    
5970                                    if (!pagination) {
5971                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5972                                                            end, false);
5973    
5974                                            Collections.sort(list);
5975    
5976                                            list = new UnmodifiableList<Role>(list);
5977                                    }
5978                                    else {
5979                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5980                                                            end);
5981                                    }
5982    
5983                                    cacheResult(list);
5984    
5985                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5986                            }
5987                            catch (Exception e) {
5988                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5989    
5990                                    throw processException(e);
5991                            }
5992                            finally {
5993                                    closeSession(session);
5994                            }
5995                    }
5996    
5997                    return list;
5998            }
5999    
6000            /**
6001             * Returns the first role in the ordered set where companyId = &#63; and type = &#63;.
6002             *
6003             * @param companyId the company ID
6004             * @param type the type
6005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6006             * @return the first matching role
6007             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
6008             * @throws SystemException if a system exception occurred
6009             */
6010            @Override
6011            public Role findByC_T_First(long companyId, int type,
6012                    OrderByComparator orderByComparator)
6013                    throws NoSuchRoleException, SystemException {
6014                    Role role = fetchByC_T_First(companyId, type, orderByComparator);
6015    
6016                    if (role != null) {
6017                            return role;
6018                    }
6019    
6020                    StringBundler msg = new StringBundler(6);
6021    
6022                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6023    
6024                    msg.append("companyId=");
6025                    msg.append(companyId);
6026    
6027                    msg.append(", type=");
6028                    msg.append(type);
6029    
6030                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6031    
6032                    throw new NoSuchRoleException(msg.toString());
6033            }
6034    
6035            /**
6036             * Returns the first role in the ordered set where companyId = &#63; and type = &#63;.
6037             *
6038             * @param companyId the company ID
6039             * @param type the type
6040             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6041             * @return the first matching role, or <code>null</code> if a matching role could not be found
6042             * @throws SystemException if a system exception occurred
6043             */
6044            @Override
6045            public Role fetchByC_T_First(long companyId, int type,
6046                    OrderByComparator orderByComparator) throws SystemException {
6047                    List<Role> list = findByC_T(companyId, type, 0, 1, orderByComparator);
6048    
6049                    if (!list.isEmpty()) {
6050                            return list.get(0);
6051                    }
6052    
6053                    return null;
6054            }
6055    
6056            /**
6057             * Returns the last role in the ordered set where companyId = &#63; and type = &#63;.
6058             *
6059             * @param companyId the company ID
6060             * @param type the type
6061             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6062             * @return the last matching role
6063             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
6064             * @throws SystemException if a system exception occurred
6065             */
6066            @Override
6067            public Role findByC_T_Last(long companyId, int type,
6068                    OrderByComparator orderByComparator)
6069                    throws NoSuchRoleException, SystemException {
6070                    Role role = fetchByC_T_Last(companyId, type, orderByComparator);
6071    
6072                    if (role != null) {
6073                            return role;
6074                    }
6075    
6076                    StringBundler msg = new StringBundler(6);
6077    
6078                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6079    
6080                    msg.append("companyId=");
6081                    msg.append(companyId);
6082    
6083                    msg.append(", type=");
6084                    msg.append(type);
6085    
6086                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6087    
6088                    throw new NoSuchRoleException(msg.toString());
6089            }
6090    
6091            /**
6092             * Returns the last role in the ordered set where companyId = &#63; and type = &#63;.
6093             *
6094             * @param companyId the company ID
6095             * @param type the type
6096             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6097             * @return the last matching role, or <code>null</code> if a matching role could not be found
6098             * @throws SystemException if a system exception occurred
6099             */
6100            @Override
6101            public Role fetchByC_T_Last(long companyId, int type,
6102                    OrderByComparator orderByComparator) throws SystemException {
6103                    int count = countByC_T(companyId, type);
6104    
6105                    if (count == 0) {
6106                            return null;
6107                    }
6108    
6109                    List<Role> list = findByC_T(companyId, type, count - 1, count,
6110                                    orderByComparator);
6111    
6112                    if (!list.isEmpty()) {
6113                            return list.get(0);
6114                    }
6115    
6116                    return null;
6117            }
6118    
6119            /**
6120             * Returns the roles before and after the current role in the ordered set where companyId = &#63; and type = &#63;.
6121             *
6122             * @param roleId the primary key of the current role
6123             * @param companyId the company ID
6124             * @param type the type
6125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6126             * @return the previous, current, and next role
6127             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
6128             * @throws SystemException if a system exception occurred
6129             */
6130            @Override
6131            public Role[] findByC_T_PrevAndNext(long roleId, long companyId, int type,
6132                    OrderByComparator orderByComparator)
6133                    throws NoSuchRoleException, SystemException {
6134                    Role role = findByPrimaryKey(roleId);
6135    
6136                    Session session = null;
6137    
6138                    try {
6139                            session = openSession();
6140    
6141                            Role[] array = new RoleImpl[3];
6142    
6143                            array[0] = getByC_T_PrevAndNext(session, role, companyId, type,
6144                                            orderByComparator, true);
6145    
6146                            array[1] = role;
6147    
6148                            array[2] = getByC_T_PrevAndNext(session, role, companyId, type,
6149                                            orderByComparator, false);
6150    
6151                            return array;
6152                    }
6153                    catch (Exception e) {
6154                            throw processException(e);
6155                    }
6156                    finally {
6157                            closeSession(session);
6158                    }
6159            }
6160    
6161            protected Role getByC_T_PrevAndNext(Session session, Role role,
6162                    long companyId, int type, OrderByComparator orderByComparator,
6163                    boolean previous) {
6164                    StringBundler query = null;
6165    
6166                    if (orderByComparator != null) {
6167                            query = new StringBundler(6 +
6168                                            (orderByComparator.getOrderByFields().length * 6));
6169                    }
6170                    else {
6171                            query = new StringBundler(3);
6172                    }
6173    
6174                    query.append(_SQL_SELECT_ROLE_WHERE);
6175    
6176                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6177    
6178                    query.append(_FINDER_COLUMN_C_T_TYPE_2);
6179    
6180                    if (orderByComparator != null) {
6181                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6182    
6183                            if (orderByConditionFields.length > 0) {
6184                                    query.append(WHERE_AND);
6185                            }
6186    
6187                            for (int i = 0; i < orderByConditionFields.length; i++) {
6188                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6189                                    query.append(orderByConditionFields[i]);
6190    
6191                                    if ((i + 1) < orderByConditionFields.length) {
6192                                            if (orderByComparator.isAscending() ^ previous) {
6193                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6194                                            }
6195                                            else {
6196                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6197                                            }
6198                                    }
6199                                    else {
6200                                            if (orderByComparator.isAscending() ^ previous) {
6201                                                    query.append(WHERE_GREATER_THAN);
6202                                            }
6203                                            else {
6204                                                    query.append(WHERE_LESSER_THAN);
6205                                            }
6206                                    }
6207                            }
6208    
6209                            query.append(ORDER_BY_CLAUSE);
6210    
6211                            String[] orderByFields = orderByComparator.getOrderByFields();
6212    
6213                            for (int i = 0; i < orderByFields.length; i++) {
6214                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6215                                    query.append(orderByFields[i]);
6216    
6217                                    if ((i + 1) < orderByFields.length) {
6218                                            if (orderByComparator.isAscending() ^ previous) {
6219                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6220                                            }
6221                                            else {
6222                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6223                                            }
6224                                    }
6225                                    else {
6226                                            if (orderByComparator.isAscending() ^ previous) {
6227                                                    query.append(ORDER_BY_ASC);
6228                                            }
6229                                            else {
6230                                                    query.append(ORDER_BY_DESC);
6231                                            }
6232                                    }
6233                            }
6234                    }
6235                    else {
6236                            query.append(RoleModelImpl.ORDER_BY_JPQL);
6237                    }
6238    
6239                    String sql = query.toString();
6240    
6241                    Query q = session.createQuery(sql);
6242    
6243                    q.setFirstResult(0);
6244                    q.setMaxResults(2);
6245    
6246                    QueryPos qPos = QueryPos.getInstance(q);
6247    
6248                    qPos.add(companyId);
6249    
6250                    qPos.add(type);
6251    
6252                    if (orderByComparator != null) {
6253                            Object[] values = orderByComparator.getOrderByConditionValues(role);
6254    
6255                            for (Object value : values) {
6256                                    qPos.add(value);
6257                            }
6258                    }
6259    
6260                    List<Role> list = q.list();
6261    
6262                    if (list.size() == 2) {
6263                            return list.get(1);
6264                    }
6265                    else {
6266                            return null;
6267                    }
6268            }
6269    
6270            /**
6271             * Returns all the roles that the user has permission to view where companyId = &#63; and type = &#63;.
6272             *
6273             * @param companyId the company ID
6274             * @param type the type
6275             * @return the matching roles that the user has permission to view
6276             * @throws SystemException if a system exception occurred
6277             */
6278            @Override
6279            public List<Role> filterFindByC_T(long companyId, int type)
6280                    throws SystemException {
6281                    return filterFindByC_T(companyId, type, QueryUtil.ALL_POS,
6282                            QueryUtil.ALL_POS, null);
6283            }
6284    
6285            /**
6286             * Returns a range of all the roles that the user has permission to view where companyId = &#63; and type = &#63;.
6287             *
6288             * <p>
6289             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6290             * </p>
6291             *
6292             * @param companyId the company ID
6293             * @param type the type
6294             * @param start the lower bound of the range of roles
6295             * @param end the upper bound of the range of roles (not inclusive)
6296             * @return the range of matching roles that the user has permission to view
6297             * @throws SystemException if a system exception occurred
6298             */
6299            @Override
6300            public List<Role> filterFindByC_T(long companyId, int type, int start,
6301                    int end) throws SystemException {
6302                    return filterFindByC_T(companyId, type, start, end, null);
6303            }
6304    
6305            /**
6306             * Returns an ordered range of all the roles that the user has permissions to view where companyId = &#63; and type = &#63;.
6307             *
6308             * <p>
6309             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6310             * </p>
6311             *
6312             * @param companyId the company ID
6313             * @param type the type
6314             * @param start the lower bound of the range of roles
6315             * @param end the upper bound of the range of roles (not inclusive)
6316             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6317             * @return the ordered range of matching roles that the user has permission to view
6318             * @throws SystemException if a system exception occurred
6319             */
6320            @Override
6321            public List<Role> filterFindByC_T(long companyId, int type, int start,
6322                    int end, OrderByComparator orderByComparator) throws SystemException {
6323                    if (!InlineSQLHelperUtil.isEnabled()) {
6324                            return findByC_T(companyId, type, start, end, orderByComparator);
6325                    }
6326    
6327                    StringBundler query = null;
6328    
6329                    if (orderByComparator != null) {
6330                            query = new StringBundler(4 +
6331                                            (orderByComparator.getOrderByFields().length * 3));
6332                    }
6333                    else {
6334                            query = new StringBundler(4);
6335                    }
6336    
6337                    if (getDB().isSupportsInlineDistinct()) {
6338                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6339                    }
6340                    else {
6341                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6342                    }
6343    
6344                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6345    
6346                    query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6347    
6348                    if (!getDB().isSupportsInlineDistinct()) {
6349                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6350                    }
6351    
6352                    if (orderByComparator != null) {
6353                            if (getDB().isSupportsInlineDistinct()) {
6354                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6355                                            orderByComparator, true);
6356                            }
6357                            else {
6358                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6359                                            orderByComparator, true);
6360                            }
6361                    }
6362                    else {
6363                            if (getDB().isSupportsInlineDistinct()) {
6364                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
6365                            }
6366                            else {
6367                                    query.append(RoleModelImpl.ORDER_BY_SQL);
6368                            }
6369                    }
6370    
6371                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6372                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6373    
6374                    Session session = null;
6375    
6376                    try {
6377                            session = openSession();
6378    
6379                            SQLQuery q = session.createSQLQuery(sql);
6380    
6381                            if (getDB().isSupportsInlineDistinct()) {
6382                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6383                            }
6384                            else {
6385                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6386                            }
6387    
6388                            QueryPos qPos = QueryPos.getInstance(q);
6389    
6390                            qPos.add(companyId);
6391    
6392                            qPos.add(type);
6393    
6394                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6395                    }
6396                    catch (Exception e) {
6397                            throw processException(e);
6398                    }
6399                    finally {
6400                            closeSession(session);
6401                    }
6402            }
6403    
6404            /**
6405             * 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; and type = &#63;.
6406             *
6407             * @param roleId the primary key of the current role
6408             * @param companyId the company ID
6409             * @param type the type
6410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6411             * @return the previous, current, and next role
6412             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
6413             * @throws SystemException if a system exception occurred
6414             */
6415            @Override
6416            public Role[] filterFindByC_T_PrevAndNext(long roleId, long companyId,
6417                    int type, OrderByComparator orderByComparator)
6418                    throws NoSuchRoleException, SystemException {
6419                    if (!InlineSQLHelperUtil.isEnabled()) {
6420                            return findByC_T_PrevAndNext(roleId, companyId, type,
6421                                    orderByComparator);
6422                    }
6423    
6424                    Role role = findByPrimaryKey(roleId);
6425    
6426                    Session session = null;
6427    
6428                    try {
6429                            session = openSession();
6430    
6431                            Role[] array = new RoleImpl[3];
6432    
6433                            array[0] = filterGetByC_T_PrevAndNext(session, role, companyId,
6434                                            type, orderByComparator, true);
6435    
6436                            array[1] = role;
6437    
6438                            array[2] = filterGetByC_T_PrevAndNext(session, role, companyId,
6439                                            type, orderByComparator, false);
6440    
6441                            return array;
6442                    }
6443                    catch (Exception e) {
6444                            throw processException(e);
6445                    }
6446                    finally {
6447                            closeSession(session);
6448                    }
6449            }
6450    
6451            protected Role filterGetByC_T_PrevAndNext(Session session, Role role,
6452                    long companyId, int type, OrderByComparator orderByComparator,
6453                    boolean previous) {
6454                    StringBundler query = null;
6455    
6456                    if (orderByComparator != null) {
6457                            query = new StringBundler(6 +
6458                                            (orderByComparator.getOrderByFields().length * 6));
6459                    }
6460                    else {
6461                            query = new StringBundler(3);
6462                    }
6463    
6464                    if (getDB().isSupportsInlineDistinct()) {
6465                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6466                    }
6467                    else {
6468                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6469                    }
6470    
6471                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6472    
6473                    query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6474    
6475                    if (!getDB().isSupportsInlineDistinct()) {
6476                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6477                    }
6478    
6479                    if (orderByComparator != null) {
6480                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6481    
6482                            if (orderByConditionFields.length > 0) {
6483                                    query.append(WHERE_AND);
6484                            }
6485    
6486                            for (int i = 0; i < orderByConditionFields.length; i++) {
6487                                    if (getDB().isSupportsInlineDistinct()) {
6488                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6489                                    }
6490                                    else {
6491                                            query.append(_ORDER_BY_ENTITY_TABLE);
6492                                    }
6493    
6494                                    query.append(orderByConditionFields[i]);
6495    
6496                                    if ((i + 1) < orderByConditionFields.length) {
6497                                            if (orderByComparator.isAscending() ^ previous) {
6498                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6499                                            }
6500                                            else {
6501                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6502                                            }
6503                                    }
6504                                    else {
6505                                            if (orderByComparator.isAscending() ^ previous) {
6506                                                    query.append(WHERE_GREATER_THAN);
6507                                            }
6508                                            else {
6509                                                    query.append(WHERE_LESSER_THAN);
6510                                            }
6511                                    }
6512                            }
6513    
6514                            query.append(ORDER_BY_CLAUSE);
6515    
6516                            String[] orderByFields = orderByComparator.getOrderByFields();
6517    
6518                            for (int i = 0; i < orderByFields.length; i++) {
6519                                    if (getDB().isSupportsInlineDistinct()) {
6520                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6521                                    }
6522                                    else {
6523                                            query.append(_ORDER_BY_ENTITY_TABLE);
6524                                    }
6525    
6526                                    query.append(orderByFields[i]);
6527    
6528                                    if ((i + 1) < orderByFields.length) {
6529                                            if (orderByComparator.isAscending() ^ previous) {
6530                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6531                                            }
6532                                            else {
6533                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6534                                            }
6535                                    }
6536                                    else {
6537                                            if (orderByComparator.isAscending() ^ previous) {
6538                                                    query.append(ORDER_BY_ASC);
6539                                            }
6540                                            else {
6541                                                    query.append(ORDER_BY_DESC);
6542                                            }
6543                                    }
6544                            }
6545                    }
6546                    else {
6547                            if (getDB().isSupportsInlineDistinct()) {
6548                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
6549                            }
6550                            else {
6551                                    query.append(RoleModelImpl.ORDER_BY_SQL);
6552                            }
6553                    }
6554    
6555                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6556                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6557    
6558                    SQLQuery q = session.createSQLQuery(sql);
6559    
6560                    q.setFirstResult(0);
6561                    q.setMaxResults(2);
6562    
6563                    if (getDB().isSupportsInlineDistinct()) {
6564                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6565                    }
6566                    else {
6567                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6568                    }
6569    
6570                    QueryPos qPos = QueryPos.getInstance(q);
6571    
6572                    qPos.add(companyId);
6573    
6574                    qPos.add(type);
6575    
6576                    if (orderByComparator != null) {
6577                            Object[] values = orderByComparator.getOrderByConditionValues(role);
6578    
6579                            for (Object value : values) {
6580                                    qPos.add(value);
6581                            }
6582                    }
6583    
6584                    List<Role> list = q.list();
6585    
6586                    if (list.size() == 2) {
6587                            return list.get(1);
6588                    }
6589                    else {
6590                            return null;
6591                    }
6592            }
6593    
6594            /**
6595             * Returns all the roles that the user has permission to view where companyId = &#63; and type = any &#63;.
6596             *
6597             * @param companyId the company ID
6598             * @param types the types
6599             * @return the matching roles that the user has permission to view
6600             * @throws SystemException if a system exception occurred
6601             */
6602            @Override
6603            public List<Role> filterFindByC_T(long companyId, int[] types)
6604                    throws SystemException {
6605                    return filterFindByC_T(companyId, types, QueryUtil.ALL_POS,
6606                            QueryUtil.ALL_POS, null);
6607            }
6608    
6609            /**
6610             * Returns a range of all the roles that the user has permission to view where companyId = &#63; and type = any &#63;.
6611             *
6612             * <p>
6613             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6614             * </p>
6615             *
6616             * @param companyId the company ID
6617             * @param types the types
6618             * @param start the lower bound of the range of roles
6619             * @param end the upper bound of the range of roles (not inclusive)
6620             * @return the range of matching roles that the user has permission to view
6621             * @throws SystemException if a system exception occurred
6622             */
6623            @Override
6624            public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6625                    int end) throws SystemException {
6626                    return filterFindByC_T(companyId, types, start, end, null);
6627            }
6628    
6629            /**
6630             * Returns an ordered range of all the roles that the user has permission to view where companyId = &#63; and type = any &#63;.
6631             *
6632             * <p>
6633             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6634             * </p>
6635             *
6636             * @param companyId the company ID
6637             * @param types the types
6638             * @param start the lower bound of the range of roles
6639             * @param end the upper bound of the range of roles (not inclusive)
6640             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6641             * @return the ordered range of matching roles that the user has permission to view
6642             * @throws SystemException if a system exception occurred
6643             */
6644            @Override
6645            public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6646                    int end, OrderByComparator orderByComparator) throws SystemException {
6647                    if (!InlineSQLHelperUtil.isEnabled()) {
6648                            return findByC_T(companyId, types, start, end, orderByComparator);
6649                    }
6650    
6651                    StringBundler query = new StringBundler();
6652    
6653                    if (getDB().isSupportsInlineDistinct()) {
6654                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6655                    }
6656                    else {
6657                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6658                    }
6659    
6660                    boolean conjunctionable = false;
6661    
6662                    if (conjunctionable) {
6663                            query.append(WHERE_AND);
6664                    }
6665    
6666                    query.append(_FINDER_COLUMN_C_T_COMPANYID_5);
6667    
6668                    conjunctionable = true;
6669    
6670                    if ((types == null) || (types.length > 0)) {
6671                            if (conjunctionable) {
6672                                    query.append(WHERE_AND);
6673                            }
6674    
6675                            query.append(StringPool.OPEN_PARENTHESIS);
6676    
6677                            for (int i = 0; i < types.length; i++) {
6678                                    query.append(_FINDER_COLUMN_C_T_TYPE_5_SQL);
6679    
6680                                    if ((i + 1) < types.length) {
6681                                            query.append(WHERE_OR);
6682                                    }
6683                            }
6684    
6685                            query.append(StringPool.CLOSE_PARENTHESIS);
6686    
6687                            conjunctionable = true;
6688                    }
6689    
6690                    if (!getDB().isSupportsInlineDistinct()) {
6691                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6692                    }
6693    
6694                    if (orderByComparator != null) {
6695                            if (getDB().isSupportsInlineDistinct()) {
6696                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6697                                            orderByComparator, true);
6698                            }
6699                            else {
6700                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6701                                            orderByComparator, true);
6702                            }
6703                    }
6704                    else {
6705                            if (getDB().isSupportsInlineDistinct()) {
6706                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
6707                            }
6708                            else {
6709                                    query.append(RoleModelImpl.ORDER_BY_SQL);
6710                            }
6711                    }
6712    
6713                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6714                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6715    
6716                    Session session = null;
6717    
6718                    try {
6719                            session = openSession();
6720    
6721                            SQLQuery q = session.createSQLQuery(sql);
6722    
6723                            if (getDB().isSupportsInlineDistinct()) {
6724                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6725                            }
6726                            else {
6727                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6728                            }
6729    
6730                            QueryPos qPos = QueryPos.getInstance(q);
6731    
6732                            qPos.add(companyId);
6733    
6734                            if (types != null) {
6735                                    qPos.add(types);
6736                            }
6737    
6738                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6739                    }
6740                    catch (Exception e) {
6741                            throw processException(e);
6742                    }
6743                    finally {
6744                            closeSession(session);
6745                    }
6746            }
6747    
6748            /**
6749             * Returns all the roles where companyId = &#63; and type = any &#63;.
6750             *
6751             * <p>
6752             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6753             * </p>
6754             *
6755             * @param companyId the company ID
6756             * @param types the types
6757             * @return the matching roles
6758             * @throws SystemException if a system exception occurred
6759             */
6760            @Override
6761            public List<Role> findByC_T(long companyId, int[] types)
6762                    throws SystemException {
6763                    return findByC_T(companyId, types, QueryUtil.ALL_POS,
6764                            QueryUtil.ALL_POS, null);
6765            }
6766    
6767            /**
6768             * Returns a range of all the roles where companyId = &#63; and type = any &#63;.
6769             *
6770             * <p>
6771             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6772             * </p>
6773             *
6774             * @param companyId the company ID
6775             * @param types the types
6776             * @param start the lower bound of the range of roles
6777             * @param end the upper bound of the range of roles (not inclusive)
6778             * @return the range of matching roles
6779             * @throws SystemException if a system exception occurred
6780             */
6781            @Override
6782            public List<Role> findByC_T(long companyId, int[] types, int start, int end)
6783                    throws SystemException {
6784                    return findByC_T(companyId, types, start, end, null);
6785            }
6786    
6787            /**
6788             * Returns an ordered range of all the roles where companyId = &#63; and type = any &#63;.
6789             *
6790             * <p>
6791             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6792             * </p>
6793             *
6794             * @param companyId the company ID
6795             * @param types the types
6796             * @param start the lower bound of the range of roles
6797             * @param end the upper bound of the range of roles (not inclusive)
6798             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6799             * @return the ordered range of matching roles
6800             * @throws SystemException if a system exception occurred
6801             */
6802            @Override
6803            public List<Role> findByC_T(long companyId, int[] types, int start,
6804                    int end, OrderByComparator orderByComparator) throws SystemException {
6805                    if ((types != null) && (types.length == 1)) {
6806                            return findByC_T(companyId, types[0], start, end, orderByComparator);
6807                    }
6808    
6809                    boolean pagination = true;
6810                    Object[] finderArgs = null;
6811    
6812                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6813                                    (orderByComparator == null)) {
6814                            pagination = false;
6815                            finderArgs = new Object[] { companyId, StringUtil.merge(types) };
6816                    }
6817                    else {
6818                            finderArgs = new Object[] {
6819                                            companyId, StringUtil.merge(types),
6820                                            
6821                                            start, end, orderByComparator
6822                                    };
6823                    }
6824    
6825                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6826                                    finderArgs, this);
6827    
6828                    if ((list != null) && !list.isEmpty()) {
6829                            for (Role role : list) {
6830                                    if ((companyId != role.getCompanyId()) ||
6831                                                    !ArrayUtil.contains(types, role.getType())) {
6832                                            list = null;
6833    
6834                                            break;
6835                                    }
6836                            }
6837                    }
6838    
6839                    if (list == null) {
6840                            StringBundler query = new StringBundler();
6841    
6842                            query.append(_SQL_SELECT_ROLE_WHERE);
6843    
6844                            boolean conjunctionable = false;
6845    
6846                            if (conjunctionable) {
6847                                    query.append(WHERE_AND);
6848                            }
6849    
6850                            query.append(_FINDER_COLUMN_C_T_COMPANYID_5);
6851    
6852                            conjunctionable = true;
6853    
6854                            if ((types == null) || (types.length > 0)) {
6855                                    if (conjunctionable) {
6856                                            query.append(WHERE_AND);
6857                                    }
6858    
6859                                    query.append(StringPool.OPEN_PARENTHESIS);
6860    
6861                                    for (int i = 0; i < types.length; i++) {
6862                                            query.append(_FINDER_COLUMN_C_T_TYPE_5);
6863    
6864                                            if ((i + 1) < types.length) {
6865                                                    query.append(WHERE_OR);
6866                                            }
6867                                    }
6868    
6869                                    query.append(StringPool.CLOSE_PARENTHESIS);
6870    
6871                                    conjunctionable = true;
6872                            }
6873    
6874                            if (orderByComparator != null) {
6875                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6876                                            orderByComparator);
6877                            }
6878                            else
6879                             if (pagination) {
6880                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
6881                            }
6882    
6883                            String sql = query.toString();
6884    
6885                            Session session = null;
6886    
6887                            try {
6888                                    session = openSession();
6889    
6890                                    Query q = session.createQuery(sql);
6891    
6892                                    QueryPos qPos = QueryPos.getInstance(q);
6893    
6894                                    qPos.add(companyId);
6895    
6896                                    if (types != null) {
6897                                            qPos.add(types);
6898                                    }
6899    
6900                                    if (!pagination) {
6901                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6902                                                            end, false);
6903    
6904                                            Collections.sort(list);
6905    
6906                                            list = new UnmodifiableList<Role>(list);
6907                                    }
6908                                    else {
6909                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6910                                                            end);
6911                                    }
6912    
6913                                    cacheResult(list);
6914    
6915                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6916                                            finderArgs, list);
6917                            }
6918                            catch (Exception e) {
6919                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6920                                            finderArgs);
6921    
6922                                    throw processException(e);
6923                            }
6924                            finally {
6925                                    closeSession(session);
6926                            }
6927                    }
6928    
6929                    return list;
6930            }
6931    
6932            /**
6933             * Removes all the roles where companyId = &#63; and type = &#63; from the database.
6934             *
6935             * @param companyId the company ID
6936             * @param type the type
6937             * @throws SystemException if a system exception occurred
6938             */
6939            @Override
6940            public void removeByC_T(long companyId, int type) throws SystemException {
6941                    for (Role role : findByC_T(companyId, type, QueryUtil.ALL_POS,
6942                                    QueryUtil.ALL_POS, null)) {
6943                            remove(role);
6944                    }
6945            }
6946    
6947            /**
6948             * Returns the number of roles where companyId = &#63; and type = &#63;.
6949             *
6950             * @param companyId the company ID
6951             * @param type the type
6952             * @return the number of matching roles
6953             * @throws SystemException if a system exception occurred
6954             */
6955            @Override
6956            public int countByC_T(long companyId, int type) throws SystemException {
6957                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
6958    
6959                    Object[] finderArgs = new Object[] { companyId, type };
6960    
6961                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6962                                    this);
6963    
6964                    if (count == null) {
6965                            StringBundler query = new StringBundler(3);
6966    
6967                            query.append(_SQL_COUNT_ROLE_WHERE);
6968    
6969                            query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6970    
6971                            query.append(_FINDER_COLUMN_C_T_TYPE_2);
6972    
6973                            String sql = query.toString();
6974    
6975                            Session session = null;
6976    
6977                            try {
6978                                    session = openSession();
6979    
6980                                    Query q = session.createQuery(sql);
6981    
6982                                    QueryPos qPos = QueryPos.getInstance(q);
6983    
6984                                    qPos.add(companyId);
6985    
6986                                    qPos.add(type);
6987    
6988                                    count = (Long)q.uniqueResult();
6989    
6990                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6991                            }
6992                            catch (Exception e) {
6993                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6994    
6995                                    throw processException(e);
6996                            }
6997                            finally {
6998                                    closeSession(session);
6999                            }
7000                    }
7001    
7002                    return count.intValue();
7003            }
7004    
7005            /**
7006             * Returns the number of roles where companyId = &#63; and type = any &#63;.
7007             *
7008             * @param companyId the company ID
7009             * @param types the types
7010             * @return the number of matching roles
7011             * @throws SystemException if a system exception occurred
7012             */
7013            @Override
7014            public int countByC_T(long companyId, int[] types)
7015                    throws SystemException {
7016                    Object[] finderArgs = new Object[] { companyId, StringUtil.merge(types) };
7017    
7018                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7019                                    finderArgs, this);
7020    
7021                    if (count == null) {
7022                            StringBundler query = new StringBundler();
7023    
7024                            query.append(_SQL_COUNT_ROLE_WHERE);
7025    
7026                            boolean conjunctionable = false;
7027    
7028                            if (conjunctionable) {
7029                                    query.append(WHERE_AND);
7030                            }
7031    
7032                            query.append(_FINDER_COLUMN_C_T_COMPANYID_5);
7033    
7034                            conjunctionable = true;
7035    
7036                            if ((types == null) || (types.length > 0)) {
7037                                    if (conjunctionable) {
7038                                            query.append(WHERE_AND);
7039                                    }
7040    
7041                                    query.append(StringPool.OPEN_PARENTHESIS);
7042    
7043                                    for (int i = 0; i < types.length; i++) {
7044                                            query.append(_FINDER_COLUMN_C_T_TYPE_5);
7045    
7046                                            if ((i + 1) < types.length) {
7047                                                    query.append(WHERE_OR);
7048                                            }
7049                                    }
7050    
7051                                    query.append(StringPool.CLOSE_PARENTHESIS);
7052    
7053                                    conjunctionable = true;
7054                            }
7055    
7056                            String sql = query.toString();
7057    
7058                            Session session = null;
7059    
7060                            try {
7061                                    session = openSession();
7062    
7063                                    Query q = session.createQuery(sql);
7064    
7065                                    QueryPos qPos = QueryPos.getInstance(q);
7066    
7067                                    qPos.add(companyId);
7068    
7069                                    if (types != null) {
7070                                            qPos.add(types);
7071                                    }
7072    
7073                                    count = (Long)q.uniqueResult();
7074    
7075                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7076                                            finderArgs, count);
7077                            }
7078                            catch (Exception e) {
7079                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7080                                            finderArgs);
7081    
7082                                    throw processException(e);
7083                            }
7084                            finally {
7085                                    closeSession(session);
7086                            }
7087                    }
7088    
7089                    return count.intValue();
7090            }
7091    
7092            /**
7093             * Returns the number of roles that the user has permission to view where companyId = &#63; and type = &#63;.
7094             *
7095             * @param companyId the company ID
7096             * @param type the type
7097             * @return the number of matching roles that the user has permission to view
7098             * @throws SystemException if a system exception occurred
7099             */
7100            @Override
7101            public int filterCountByC_T(long companyId, int type)
7102                    throws SystemException {
7103                    if (!InlineSQLHelperUtil.isEnabled()) {
7104                            return countByC_T(companyId, type);
7105                    }
7106    
7107                    StringBundler query = new StringBundler(3);
7108    
7109                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7110    
7111                    query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7112    
7113                    query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
7114    
7115                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7116                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7117    
7118                    Session session = null;
7119    
7120                    try {
7121                            session = openSession();
7122    
7123                            SQLQuery q = session.createSQLQuery(sql);
7124    
7125                            q.addScalar(COUNT_COLUMN_NAME,
7126                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7127    
7128                            QueryPos qPos = QueryPos.getInstance(q);
7129    
7130                            qPos.add(companyId);
7131    
7132                            qPos.add(type);
7133    
7134                            Long count = (Long)q.uniqueResult();
7135    
7136                            return count.intValue();
7137                    }
7138                    catch (Exception e) {
7139                            throw processException(e);
7140                    }
7141                    finally {
7142                            closeSession(session);
7143                    }
7144            }
7145    
7146            /**
7147             * Returns the number of roles that the user has permission to view where companyId = &#63; and type = any &#63;.
7148             *
7149             * @param companyId the company ID
7150             * @param types the types
7151             * @return the number of matching roles that the user has permission to view
7152             * @throws SystemException if a system exception occurred
7153             */
7154            @Override
7155            public int filterCountByC_T(long companyId, int[] types)
7156                    throws SystemException {
7157                    if (!InlineSQLHelperUtil.isEnabled()) {
7158                            return countByC_T(companyId, types);
7159                    }
7160    
7161                    StringBundler query = new StringBundler();
7162    
7163                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7164    
7165                    boolean conjunctionable = false;
7166    
7167                    if (conjunctionable) {
7168                            query.append(WHERE_AND);
7169                    }
7170    
7171                    query.append(_FINDER_COLUMN_C_T_COMPANYID_5);
7172    
7173                    conjunctionable = true;
7174    
7175                    if ((types == null) || (types.length > 0)) {
7176                            if (conjunctionable) {
7177                                    query.append(WHERE_AND);
7178                            }
7179    
7180                            query.append(StringPool.OPEN_PARENTHESIS);
7181    
7182                            for (int i = 0; i < types.length; i++) {
7183                                    query.append(_FINDER_COLUMN_C_T_TYPE_5_SQL);
7184    
7185                                    if ((i + 1) < types.length) {
7186                                            query.append(WHERE_OR);
7187                                    }
7188                            }
7189    
7190                            query.append(StringPool.CLOSE_PARENTHESIS);
7191    
7192                            conjunctionable = true;
7193                    }
7194    
7195                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7196                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7197    
7198                    Session session = null;
7199    
7200                    try {
7201                            session = openSession();
7202    
7203                            SQLQuery q = session.createSQLQuery(sql);
7204    
7205                            q.addScalar(COUNT_COLUMN_NAME,
7206                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7207    
7208                            QueryPos qPos = QueryPos.getInstance(q);
7209    
7210                            qPos.add(companyId);
7211    
7212                            if (types != null) {
7213                                    qPos.add(types);
7214                            }
7215    
7216                            Long count = (Long)q.uniqueResult();
7217    
7218                            return count.intValue();
7219                    }
7220                    catch (Exception e) {
7221                            throw processException(e);
7222                    }
7223                    finally {
7224                            closeSession(session);
7225                    }
7226            }
7227    
7228            private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "role.companyId = ? AND ";
7229            private static final String _FINDER_COLUMN_C_T_COMPANYID_5 = "(" +
7230                    removeConjunction(_FINDER_COLUMN_C_T_COMPANYID_2) + ")";
7231            private static final String _FINDER_COLUMN_C_T_TYPE_2 = "role.type = ?";
7232            private static final String _FINDER_COLUMN_C_T_TYPE_5 = "(" +
7233                    removeConjunction(_FINDER_COLUMN_C_T_TYPE_2) + ")";
7234            private static final String _FINDER_COLUMN_C_T_TYPE_2_SQL = "role.type_ = ?";
7235            private static final String _FINDER_COLUMN_C_T_TYPE_5_SQL = "(" +
7236                    removeConjunction(_FINDER_COLUMN_C_T_TYPE_2) + ")";
7237            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7238                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7239                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
7240                            new String[] {
7241                                    Integer.class.getName(), String.class.getName(),
7242                                    
7243                            Integer.class.getName(), Integer.class.getName(),
7244                                    OrderByComparator.class.getName()
7245                            });
7246            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7247                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7248                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
7249                            new String[] { Integer.class.getName(), String.class.getName() },
7250                            RoleModelImpl.TYPE_COLUMN_BITMASK |
7251                            RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
7252                            RoleModelImpl.NAME_COLUMN_BITMASK);
7253            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7254                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7255                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
7256                            new String[] { Integer.class.getName(), String.class.getName() });
7257    
7258            /**
7259             * Returns all the roles where type = &#63; and subtype = &#63;.
7260             *
7261             * @param type the type
7262             * @param subtype the subtype
7263             * @return the matching roles
7264             * @throws SystemException if a system exception occurred
7265             */
7266            @Override
7267            public List<Role> findByT_S(int type, String subtype)
7268                    throws SystemException {
7269                    return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7270                            null);
7271            }
7272    
7273            /**
7274             * Returns a range of all the roles where type = &#63; and subtype = &#63;.
7275             *
7276             * <p>
7277             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7278             * </p>
7279             *
7280             * @param type the type
7281             * @param subtype the subtype
7282             * @param start the lower bound of the range of roles
7283             * @param end the upper bound of the range of roles (not inclusive)
7284             * @return the range of matching roles
7285             * @throws SystemException if a system exception occurred
7286             */
7287            @Override
7288            public List<Role> findByT_S(int type, String subtype, int start, int end)
7289                    throws SystemException {
7290                    return findByT_S(type, subtype, start, end, null);
7291            }
7292    
7293            /**
7294             * Returns an ordered range of all the roles where type = &#63; and subtype = &#63;.
7295             *
7296             * <p>
7297             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7298             * </p>
7299             *
7300             * @param type the type
7301             * @param subtype the subtype
7302             * @param start the lower bound of the range of roles
7303             * @param end the upper bound of the range of roles (not inclusive)
7304             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7305             * @return the ordered range of matching roles
7306             * @throws SystemException if a system exception occurred
7307             */
7308            @Override
7309            public List<Role> findByT_S(int type, String subtype, int start, int end,
7310                    OrderByComparator orderByComparator) throws SystemException {
7311                    boolean pagination = true;
7312                    FinderPath finderPath = null;
7313                    Object[] finderArgs = null;
7314    
7315                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7316                                    (orderByComparator == null)) {
7317                            pagination = false;
7318                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
7319                            finderArgs = new Object[] { type, subtype };
7320                    }
7321                    else {
7322                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
7323                            finderArgs = new Object[] {
7324                                            type, subtype,
7325                                            
7326                                            start, end, orderByComparator
7327                                    };
7328                    }
7329    
7330                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
7331                                    finderArgs, this);
7332    
7333                    if ((list != null) && !list.isEmpty()) {
7334                            for (Role role : list) {
7335                                    if ((type != role.getType()) ||
7336                                                    !Validator.equals(subtype, role.getSubtype())) {
7337                                            list = null;
7338    
7339                                            break;
7340                                    }
7341                            }
7342                    }
7343    
7344                    if (list == null) {
7345                            StringBundler query = null;
7346    
7347                            if (orderByComparator != null) {
7348                                    query = new StringBundler(4 +
7349                                                    (orderByComparator.getOrderByFields().length * 3));
7350                            }
7351                            else {
7352                                    query = new StringBundler(4);
7353                            }
7354    
7355                            query.append(_SQL_SELECT_ROLE_WHERE);
7356    
7357                            query.append(_FINDER_COLUMN_T_S_TYPE_2);
7358    
7359                            boolean bindSubtype = false;
7360    
7361                            if (subtype == null) {
7362                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7363                            }
7364                            else if (subtype.equals(StringPool.BLANK)) {
7365                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7366                            }
7367                            else {
7368                                    bindSubtype = true;
7369    
7370                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7371                            }
7372    
7373                            if (orderByComparator != null) {
7374                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7375                                            orderByComparator);
7376                            }
7377                            else
7378                             if (pagination) {
7379                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
7380                            }
7381    
7382                            String sql = query.toString();
7383    
7384                            Session session = null;
7385    
7386                            try {
7387                                    session = openSession();
7388    
7389                                    Query q = session.createQuery(sql);
7390    
7391                                    QueryPos qPos = QueryPos.getInstance(q);
7392    
7393                                    qPos.add(type);
7394    
7395                                    if (bindSubtype) {
7396                                            qPos.add(subtype);
7397                                    }
7398    
7399                                    if (!pagination) {
7400                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7401                                                            end, false);
7402    
7403                                            Collections.sort(list);
7404    
7405                                            list = new UnmodifiableList<Role>(list);
7406                                    }
7407                                    else {
7408                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7409                                                            end);
7410                                    }
7411    
7412                                    cacheResult(list);
7413    
7414                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7415                            }
7416                            catch (Exception e) {
7417                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7418    
7419                                    throw processException(e);
7420                            }
7421                            finally {
7422                                    closeSession(session);
7423                            }
7424                    }
7425    
7426                    return list;
7427            }
7428    
7429            /**
7430             * Returns the first role in the ordered set where type = &#63; and subtype = &#63;.
7431             *
7432             * @param type the type
7433             * @param subtype the subtype
7434             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7435             * @return the first matching role
7436             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
7437             * @throws SystemException if a system exception occurred
7438             */
7439            @Override
7440            public Role findByT_S_First(int type, String subtype,
7441                    OrderByComparator orderByComparator)
7442                    throws NoSuchRoleException, SystemException {
7443                    Role role = fetchByT_S_First(type, subtype, orderByComparator);
7444    
7445                    if (role != null) {
7446                            return role;
7447                    }
7448    
7449                    StringBundler msg = new StringBundler(6);
7450    
7451                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7452    
7453                    msg.append("type=");
7454                    msg.append(type);
7455    
7456                    msg.append(", subtype=");
7457                    msg.append(subtype);
7458    
7459                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7460    
7461                    throw new NoSuchRoleException(msg.toString());
7462            }
7463    
7464            /**
7465             * Returns the first role in the ordered set where type = &#63; and subtype = &#63;.
7466             *
7467             * @param type the type
7468             * @param subtype the subtype
7469             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7470             * @return the first matching role, or <code>null</code> if a matching role could not be found
7471             * @throws SystemException if a system exception occurred
7472             */
7473            @Override
7474            public Role fetchByT_S_First(int type, String subtype,
7475                    OrderByComparator orderByComparator) throws SystemException {
7476                    List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
7477    
7478                    if (!list.isEmpty()) {
7479                            return list.get(0);
7480                    }
7481    
7482                    return null;
7483            }
7484    
7485            /**
7486             * Returns the last role in the ordered set where type = &#63; and subtype = &#63;.
7487             *
7488             * @param type the type
7489             * @param subtype the subtype
7490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7491             * @return the last matching role
7492             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
7493             * @throws SystemException if a system exception occurred
7494             */
7495            @Override
7496            public Role findByT_S_Last(int type, String subtype,
7497                    OrderByComparator orderByComparator)
7498                    throws NoSuchRoleException, SystemException {
7499                    Role role = fetchByT_S_Last(type, subtype, orderByComparator);
7500    
7501                    if (role != null) {
7502                            return role;
7503                    }
7504    
7505                    StringBundler msg = new StringBundler(6);
7506    
7507                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7508    
7509                    msg.append("type=");
7510                    msg.append(type);
7511    
7512                    msg.append(", subtype=");
7513                    msg.append(subtype);
7514    
7515                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7516    
7517                    throw new NoSuchRoleException(msg.toString());
7518            }
7519    
7520            /**
7521             * Returns the last role in the ordered set where type = &#63; and subtype = &#63;.
7522             *
7523             * @param type the type
7524             * @param subtype the subtype
7525             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7526             * @return the last matching role, or <code>null</code> if a matching role could not be found
7527             * @throws SystemException if a system exception occurred
7528             */
7529            @Override
7530            public Role fetchByT_S_Last(int type, String subtype,
7531                    OrderByComparator orderByComparator) throws SystemException {
7532                    int count = countByT_S(type, subtype);
7533    
7534                    if (count == 0) {
7535                            return null;
7536                    }
7537    
7538                    List<Role> list = findByT_S(type, subtype, count - 1, count,
7539                                    orderByComparator);
7540    
7541                    if (!list.isEmpty()) {
7542                            return list.get(0);
7543                    }
7544    
7545                    return null;
7546            }
7547    
7548            /**
7549             * Returns the roles before and after the current role in the ordered set where type = &#63; and subtype = &#63;.
7550             *
7551             * @param roleId the primary key of the current role
7552             * @param type the type
7553             * @param subtype the subtype
7554             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7555             * @return the previous, current, and next role
7556             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
7557             * @throws SystemException if a system exception occurred
7558             */
7559            @Override
7560            public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
7561                    OrderByComparator orderByComparator)
7562                    throws NoSuchRoleException, SystemException {
7563                    Role role = findByPrimaryKey(roleId);
7564    
7565                    Session session = null;
7566    
7567                    try {
7568                            session = openSession();
7569    
7570                            Role[] array = new RoleImpl[3];
7571    
7572                            array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
7573                                            orderByComparator, true);
7574    
7575                            array[1] = role;
7576    
7577                            array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
7578                                            orderByComparator, false);
7579    
7580                            return array;
7581                    }
7582                    catch (Exception e) {
7583                            throw processException(e);
7584                    }
7585                    finally {
7586                            closeSession(session);
7587                    }
7588            }
7589    
7590            protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
7591                    String subtype, OrderByComparator orderByComparator, boolean previous) {
7592                    StringBundler query = null;
7593    
7594                    if (orderByComparator != null) {
7595                            query = new StringBundler(6 +
7596                                            (orderByComparator.getOrderByFields().length * 6));
7597                    }
7598                    else {
7599                            query = new StringBundler(3);
7600                    }
7601    
7602                    query.append(_SQL_SELECT_ROLE_WHERE);
7603    
7604                    query.append(_FINDER_COLUMN_T_S_TYPE_2);
7605    
7606                    boolean bindSubtype = false;
7607    
7608                    if (subtype == null) {
7609                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7610                    }
7611                    else if (subtype.equals(StringPool.BLANK)) {
7612                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7613                    }
7614                    else {
7615                            bindSubtype = true;
7616    
7617                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7618                    }
7619    
7620                    if (orderByComparator != null) {
7621                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7622    
7623                            if (orderByConditionFields.length > 0) {
7624                                    query.append(WHERE_AND);
7625                            }
7626    
7627                            for (int i = 0; i < orderByConditionFields.length; i++) {
7628                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7629                                    query.append(orderByConditionFields[i]);
7630    
7631                                    if ((i + 1) < orderByConditionFields.length) {
7632                                            if (orderByComparator.isAscending() ^ previous) {
7633                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7634                                            }
7635                                            else {
7636                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7637                                            }
7638                                    }
7639                                    else {
7640                                            if (orderByComparator.isAscending() ^ previous) {
7641                                                    query.append(WHERE_GREATER_THAN);
7642                                            }
7643                                            else {
7644                                                    query.append(WHERE_LESSER_THAN);
7645                                            }
7646                                    }
7647                            }
7648    
7649                            query.append(ORDER_BY_CLAUSE);
7650    
7651                            String[] orderByFields = orderByComparator.getOrderByFields();
7652    
7653                            for (int i = 0; i < orderByFields.length; i++) {
7654                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7655                                    query.append(orderByFields[i]);
7656    
7657                                    if ((i + 1) < orderByFields.length) {
7658                                            if (orderByComparator.isAscending() ^ previous) {
7659                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7660                                            }
7661                                            else {
7662                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7663                                            }
7664                                    }
7665                                    else {
7666                                            if (orderByComparator.isAscending() ^ previous) {
7667                                                    query.append(ORDER_BY_ASC);
7668                                            }
7669                                            else {
7670                                                    query.append(ORDER_BY_DESC);
7671                                            }
7672                                    }
7673                            }
7674                    }
7675                    else {
7676                            query.append(RoleModelImpl.ORDER_BY_JPQL);
7677                    }
7678    
7679                    String sql = query.toString();
7680    
7681                    Query q = session.createQuery(sql);
7682    
7683                    q.setFirstResult(0);
7684                    q.setMaxResults(2);
7685    
7686                    QueryPos qPos = QueryPos.getInstance(q);
7687    
7688                    qPos.add(type);
7689    
7690                    if (bindSubtype) {
7691                            qPos.add(subtype);
7692                    }
7693    
7694                    if (orderByComparator != null) {
7695                            Object[] values = orderByComparator.getOrderByConditionValues(role);
7696    
7697                            for (Object value : values) {
7698                                    qPos.add(value);
7699                            }
7700                    }
7701    
7702                    List<Role> list = q.list();
7703    
7704                    if (list.size() == 2) {
7705                            return list.get(1);
7706                    }
7707                    else {
7708                            return null;
7709                    }
7710            }
7711    
7712            /**
7713             * Returns all the roles that the user has permission to view where type = &#63; and subtype = &#63;.
7714             *
7715             * @param type the type
7716             * @param subtype the subtype
7717             * @return the matching roles that the user has permission to view
7718             * @throws SystemException if a system exception occurred
7719             */
7720            @Override
7721            public List<Role> filterFindByT_S(int type, String subtype)
7722                    throws SystemException {
7723                    return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
7724                            QueryUtil.ALL_POS, null);
7725            }
7726    
7727            /**
7728             * Returns a range of all the roles that the user has permission to view where type = &#63; and subtype = &#63;.
7729             *
7730             * <p>
7731             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7732             * </p>
7733             *
7734             * @param type the type
7735             * @param subtype the subtype
7736             * @param start the lower bound of the range of roles
7737             * @param end the upper bound of the range of roles (not inclusive)
7738             * @return the range of matching roles that the user has permission to view
7739             * @throws SystemException if a system exception occurred
7740             */
7741            @Override
7742            public List<Role> filterFindByT_S(int type, String subtype, int start,
7743                    int end) throws SystemException {
7744                    return filterFindByT_S(type, subtype, start, end, null);
7745            }
7746    
7747            /**
7748             * Returns an ordered range of all the roles that the user has permissions to view where type = &#63; and subtype = &#63;.
7749             *
7750             * <p>
7751             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7752             * </p>
7753             *
7754             * @param type the type
7755             * @param subtype the subtype
7756             * @param start the lower bound of the range of roles
7757             * @param end the upper bound of the range of roles (not inclusive)
7758             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7759             * @return the ordered range of matching roles that the user has permission to view
7760             * @throws SystemException if a system exception occurred
7761             */
7762            @Override
7763            public List<Role> filterFindByT_S(int type, String subtype, int start,
7764                    int end, OrderByComparator orderByComparator) throws SystemException {
7765                    if (!InlineSQLHelperUtil.isEnabled()) {
7766                            return findByT_S(type, subtype, start, end, orderByComparator);
7767                    }
7768    
7769                    StringBundler query = null;
7770    
7771                    if (orderByComparator != null) {
7772                            query = new StringBundler(4 +
7773                                            (orderByComparator.getOrderByFields().length * 3));
7774                    }
7775                    else {
7776                            query = new StringBundler(4);
7777                    }
7778    
7779                    if (getDB().isSupportsInlineDistinct()) {
7780                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7781                    }
7782                    else {
7783                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7784                    }
7785    
7786                    query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7787    
7788                    boolean bindSubtype = false;
7789    
7790                    if (subtype == null) {
7791                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7792                    }
7793                    else if (subtype.equals(StringPool.BLANK)) {
7794                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7795                    }
7796                    else {
7797                            bindSubtype = true;
7798    
7799                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7800                    }
7801    
7802                    if (!getDB().isSupportsInlineDistinct()) {
7803                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7804                    }
7805    
7806                    if (orderByComparator != null) {
7807                            if (getDB().isSupportsInlineDistinct()) {
7808                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7809                                            orderByComparator, true);
7810                            }
7811                            else {
7812                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7813                                            orderByComparator, true);
7814                            }
7815                    }
7816                    else {
7817                            if (getDB().isSupportsInlineDistinct()) {
7818                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
7819                            }
7820                            else {
7821                                    query.append(RoleModelImpl.ORDER_BY_SQL);
7822                            }
7823                    }
7824    
7825                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7826                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7827    
7828                    Session session = null;
7829    
7830                    try {
7831                            session = openSession();
7832    
7833                            SQLQuery q = session.createSQLQuery(sql);
7834    
7835                            if (getDB().isSupportsInlineDistinct()) {
7836                                    q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
7837                            }
7838                            else {
7839                                    q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
7840                            }
7841    
7842                            QueryPos qPos = QueryPos.getInstance(q);
7843    
7844                            qPos.add(type);
7845    
7846                            if (bindSubtype) {
7847                                    qPos.add(subtype);
7848                            }
7849    
7850                            return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
7851                    }
7852                    catch (Exception e) {
7853                            throw processException(e);
7854                    }
7855                    finally {
7856                            closeSession(session);
7857                    }
7858            }
7859    
7860            /**
7861             * 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;.
7862             *
7863             * @param roleId the primary key of the current role
7864             * @param type the type
7865             * @param subtype the subtype
7866             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7867             * @return the previous, current, and next role
7868             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
7869             * @throws SystemException if a system exception occurred
7870             */
7871            @Override
7872            public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
7873                    String subtype, OrderByComparator orderByComparator)
7874                    throws NoSuchRoleException, SystemException {
7875                    if (!InlineSQLHelperUtil.isEnabled()) {
7876                            return findByT_S_PrevAndNext(roleId, type, subtype,
7877                                    orderByComparator);
7878                    }
7879    
7880                    Role role = findByPrimaryKey(roleId);
7881    
7882                    Session session = null;
7883    
7884                    try {
7885                            session = openSession();
7886    
7887                            Role[] array = new RoleImpl[3];
7888    
7889                            array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7890                                            orderByComparator, true);
7891    
7892                            array[1] = role;
7893    
7894                            array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7895                                            orderByComparator, false);
7896    
7897                            return array;
7898                    }
7899                    catch (Exception e) {
7900                            throw processException(e);
7901                    }
7902                    finally {
7903                            closeSession(session);
7904                    }
7905            }
7906    
7907            protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
7908                    int type, String subtype, OrderByComparator orderByComparator,
7909                    boolean previous) {
7910                    StringBundler query = null;
7911    
7912                    if (orderByComparator != null) {
7913                            query = new StringBundler(6 +
7914                                            (orderByComparator.getOrderByFields().length * 6));
7915                    }
7916                    else {
7917                            query = new StringBundler(3);
7918                    }
7919    
7920                    if (getDB().isSupportsInlineDistinct()) {
7921                            query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7922                    }
7923                    else {
7924                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7925                    }
7926    
7927                    query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7928    
7929                    boolean bindSubtype = false;
7930    
7931                    if (subtype == null) {
7932                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7933                    }
7934                    else if (subtype.equals(StringPool.BLANK)) {
7935                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7936                    }
7937                    else {
7938                            bindSubtype = true;
7939    
7940                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7941                    }
7942    
7943                    if (!getDB().isSupportsInlineDistinct()) {
7944                            query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7945                    }
7946    
7947                    if (orderByComparator != null) {
7948                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7949    
7950                            if (orderByConditionFields.length > 0) {
7951                                    query.append(WHERE_AND);
7952                            }
7953    
7954                            for (int i = 0; i < orderByConditionFields.length; i++) {
7955                                    if (getDB().isSupportsInlineDistinct()) {
7956                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7957                                    }
7958                                    else {
7959                                            query.append(_ORDER_BY_ENTITY_TABLE);
7960                                    }
7961    
7962                                    query.append(orderByConditionFields[i]);
7963    
7964                                    if ((i + 1) < orderByConditionFields.length) {
7965                                            if (orderByComparator.isAscending() ^ previous) {
7966                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7967                                            }
7968                                            else {
7969                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7970                                            }
7971                                    }
7972                                    else {
7973                                            if (orderByComparator.isAscending() ^ previous) {
7974                                                    query.append(WHERE_GREATER_THAN);
7975                                            }
7976                                            else {
7977                                                    query.append(WHERE_LESSER_THAN);
7978                                            }
7979                                    }
7980                            }
7981    
7982                            query.append(ORDER_BY_CLAUSE);
7983    
7984                            String[] orderByFields = orderByComparator.getOrderByFields();
7985    
7986                            for (int i = 0; i < orderByFields.length; i++) {
7987                                    if (getDB().isSupportsInlineDistinct()) {
7988                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7989                                    }
7990                                    else {
7991                                            query.append(_ORDER_BY_ENTITY_TABLE);
7992                                    }
7993    
7994                                    query.append(orderByFields[i]);
7995    
7996                                    if ((i + 1) < orderByFields.length) {
7997                                            if (orderByComparator.isAscending() ^ previous) {
7998                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7999                                            }
8000                                            else {
8001                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8002                                            }
8003                                    }
8004                                    else {
8005                                            if (orderByComparator.isAscending() ^ previous) {
8006                                                    query.append(ORDER_BY_ASC);
8007                                            }
8008                                            else {
8009                                                    query.append(ORDER_BY_DESC);
8010                                            }
8011                                    }
8012                            }
8013                    }
8014                    else {
8015                            if (getDB().isSupportsInlineDistinct()) {
8016                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
8017                            }
8018                            else {
8019                                    query.append(RoleModelImpl.ORDER_BY_SQL);
8020                            }
8021                    }
8022    
8023                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8024                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
8025    
8026                    SQLQuery q = session.createSQLQuery(sql);
8027    
8028                    q.setFirstResult(0);
8029                    q.setMaxResults(2);
8030    
8031                    if (getDB().isSupportsInlineDistinct()) {
8032                            q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
8033                    }
8034                    else {
8035                            q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
8036                    }
8037    
8038                    QueryPos qPos = QueryPos.getInstance(q);
8039    
8040                    qPos.add(type);
8041    
8042                    if (bindSubtype) {
8043                            qPos.add(subtype);
8044                    }
8045    
8046                    if (orderByComparator != null) {
8047                            Object[] values = orderByComparator.getOrderByConditionValues(role);
8048    
8049                            for (Object value : values) {
8050                                    qPos.add(value);
8051                            }
8052                    }
8053    
8054                    List<Role> list = q.list();
8055    
8056                    if (list.size() == 2) {
8057                            return list.get(1);
8058                    }
8059                    else {
8060                            return null;
8061                    }
8062            }
8063    
8064            /**
8065             * Removes all the roles where type = &#63; and subtype = &#63; from the database.
8066             *
8067             * @param type the type
8068             * @param subtype the subtype
8069             * @throws SystemException if a system exception occurred
8070             */
8071            @Override
8072            public void removeByT_S(int type, String subtype) throws SystemException {
8073                    for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
8074                                    QueryUtil.ALL_POS, null)) {
8075                            remove(role);
8076                    }
8077            }
8078    
8079            /**
8080             * Returns the number of roles where type = &#63; and subtype = &#63;.
8081             *
8082             * @param type the type
8083             * @param subtype the subtype
8084             * @return the number of matching roles
8085             * @throws SystemException if a system exception occurred
8086             */
8087            @Override
8088            public int countByT_S(int type, String subtype) throws SystemException {
8089                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
8090    
8091                    Object[] finderArgs = new Object[] { type, subtype };
8092    
8093                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8094                                    this);
8095    
8096                    if (count == null) {
8097                            StringBundler query = new StringBundler(3);
8098    
8099                            query.append(_SQL_COUNT_ROLE_WHERE);
8100    
8101                            query.append(_FINDER_COLUMN_T_S_TYPE_2);
8102    
8103                            boolean bindSubtype = false;
8104    
8105                            if (subtype == null) {
8106                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
8107                            }
8108                            else if (subtype.equals(StringPool.BLANK)) {
8109                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
8110                            }
8111                            else {
8112                                    bindSubtype = true;
8113    
8114                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
8115                            }
8116    
8117                            String sql = query.toString();
8118    
8119                            Session session = null;
8120    
8121                            try {
8122                                    session = openSession();
8123    
8124                                    Query q = session.createQuery(sql);
8125    
8126                                    QueryPos qPos = QueryPos.getInstance(q);
8127    
8128                                    qPos.add(type);
8129    
8130                                    if (bindSubtype) {
8131                                            qPos.add(subtype);
8132                                    }
8133    
8134                                    count = (Long)q.uniqueResult();
8135    
8136                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8137                            }
8138                            catch (Exception e) {
8139                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8140    
8141                                    throw processException(e);
8142                            }
8143                            finally {
8144                                    closeSession(session);
8145                            }
8146                    }
8147    
8148                    return count.intValue();
8149            }
8150    
8151            /**
8152             * Returns the number of roles that the user has permission to view where type = &#63; and subtype = &#63;.
8153             *
8154             * @param type the type
8155             * @param subtype the subtype
8156             * @return the number of matching roles that the user has permission to view
8157             * @throws SystemException if a system exception occurred
8158             */
8159            @Override
8160            public int filterCountByT_S(int type, String subtype)
8161                    throws SystemException {
8162                    if (!InlineSQLHelperUtil.isEnabled()) {
8163                            return countByT_S(type, subtype);
8164                    }
8165    
8166                    StringBundler query = new StringBundler(3);
8167    
8168                    query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
8169    
8170                    query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
8171    
8172                    boolean bindSubtype = false;
8173    
8174                    if (subtype == null) {
8175                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
8176                    }
8177                    else if (subtype.equals(StringPool.BLANK)) {
8178                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
8179                    }
8180                    else {
8181                            bindSubtype = true;
8182    
8183                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
8184                    }
8185    
8186                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8187                                    Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
8188    
8189                    Session session = null;
8190    
8191                    try {
8192                            session = openSession();
8193    
8194                            SQLQuery q = session.createSQLQuery(sql);
8195    
8196                            q.addScalar(COUNT_COLUMN_NAME,
8197                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8198    
8199                            QueryPos qPos = QueryPos.getInstance(q);
8200    
8201                            qPos.add(type);
8202    
8203                            if (bindSubtype) {
8204                                    qPos.add(subtype);
8205                            }
8206    
8207                            Long count = (Long)q.uniqueResult();
8208    
8209                            return count.intValue();
8210                    }
8211                    catch (Exception e) {
8212                            throw processException(e);
8213                    }
8214                    finally {
8215                            closeSession(session);
8216                    }
8217            }
8218    
8219            private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
8220            private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND ";
8221            private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
8222            private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
8223            private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
8224            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8225                            RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
8226                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
8227                            new String[] {
8228                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
8229                            },
8230                            RoleModelImpl.COMPANYID_COLUMN_BITMASK |
8231                            RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8232                            RoleModelImpl.CLASSPK_COLUMN_BITMASK);
8233            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8234                            RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8235                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
8236                            new String[] {
8237                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
8238                            });
8239    
8240            /**
8241             * 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.
8242             *
8243             * @param companyId the company ID
8244             * @param classNameId the class name ID
8245             * @param classPK the class p k
8246             * @return the matching role
8247             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
8248             * @throws SystemException if a system exception occurred
8249             */
8250            @Override
8251            public Role findByC_C_C(long companyId, long classNameId, long classPK)
8252                    throws NoSuchRoleException, SystemException {
8253                    Role role = fetchByC_C_C(companyId, classNameId, classPK);
8254    
8255                    if (role == null) {
8256                            StringBundler msg = new StringBundler(8);
8257    
8258                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8259    
8260                            msg.append("companyId=");
8261                            msg.append(companyId);
8262    
8263                            msg.append(", classNameId=");
8264                            msg.append(classNameId);
8265    
8266                            msg.append(", classPK=");
8267                            msg.append(classPK);
8268    
8269                            msg.append(StringPool.CLOSE_CURLY_BRACE);
8270    
8271                            if (_log.isWarnEnabled()) {
8272                                    _log.warn(msg.toString());
8273                            }
8274    
8275                            throw new NoSuchRoleException(msg.toString());
8276                    }
8277    
8278                    return role;
8279            }
8280    
8281            /**
8282             * 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.
8283             *
8284             * @param companyId the company ID
8285             * @param classNameId the class name ID
8286             * @param classPK the class p k
8287             * @return the matching role, or <code>null</code> if a matching role could not be found
8288             * @throws SystemException if a system exception occurred
8289             */
8290            @Override
8291            public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
8292                    throws SystemException {
8293                    return fetchByC_C_C(companyId, classNameId, classPK, true);
8294            }
8295    
8296            /**
8297             * 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.
8298             *
8299             * @param companyId the company ID
8300             * @param classNameId the class name ID
8301             * @param classPK the class p k
8302             * @param retrieveFromCache whether to use the finder cache
8303             * @return the matching role, or <code>null</code> if a matching role could not be found
8304             * @throws SystemException if a system exception occurred
8305             */
8306            @Override
8307            public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
8308                    boolean retrieveFromCache) throws SystemException {
8309                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8310    
8311                    Object result = null;
8312    
8313                    if (retrieveFromCache) {
8314                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
8315                                            finderArgs, this);
8316                    }
8317    
8318                    if (result instanceof Role) {
8319                            Role role = (Role)result;
8320    
8321                            if ((companyId != role.getCompanyId()) ||
8322                                            (classNameId != role.getClassNameId()) ||
8323                                            (classPK != role.getClassPK())) {
8324                                    result = null;
8325                            }
8326                    }
8327    
8328                    if (result == null) {
8329                            StringBundler query = new StringBundler(5);
8330    
8331                            query.append(_SQL_SELECT_ROLE_WHERE);
8332    
8333                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8334    
8335                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8336    
8337                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8338    
8339                            String sql = query.toString();
8340    
8341                            Session session = null;
8342    
8343                            try {
8344                                    session = openSession();
8345    
8346                                    Query q = session.createQuery(sql);
8347    
8348                                    QueryPos qPos = QueryPos.getInstance(q);
8349    
8350                                    qPos.add(companyId);
8351    
8352                                    qPos.add(classNameId);
8353    
8354                                    qPos.add(classPK);
8355    
8356                                    List<Role> list = q.list();
8357    
8358                                    if (list.isEmpty()) {
8359                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8360                                                    finderArgs, list);
8361                                    }
8362                                    else {
8363                                            Role role = list.get(0);
8364    
8365                                            result = role;
8366    
8367                                            cacheResult(role);
8368    
8369                                            if ((role.getCompanyId() != companyId) ||
8370                                                            (role.getClassNameId() != classNameId) ||
8371                                                            (role.getClassPK() != classPK)) {
8372                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8373                                                            finderArgs, role);
8374                                            }
8375                                    }
8376                            }
8377                            catch (Exception e) {
8378                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
8379                                            finderArgs);
8380    
8381                                    throw processException(e);
8382                            }
8383                            finally {
8384                                    closeSession(session);
8385                            }
8386                    }
8387    
8388                    if (result instanceof List<?>) {
8389                            return null;
8390                    }
8391                    else {
8392                            return (Role)result;
8393                    }
8394            }
8395    
8396            /**
8397             * Removes the role where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
8398             *
8399             * @param companyId the company ID
8400             * @param classNameId the class name ID
8401             * @param classPK the class p k
8402             * @return the role that was removed
8403             * @throws SystemException if a system exception occurred
8404             */
8405            @Override
8406            public Role removeByC_C_C(long companyId, long classNameId, long classPK)
8407                    throws NoSuchRoleException, SystemException {
8408                    Role role = findByC_C_C(companyId, classNameId, classPK);
8409    
8410                    return remove(role);
8411            }
8412    
8413            /**
8414             * Returns the number of roles where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
8415             *
8416             * @param companyId the company ID
8417             * @param classNameId the class name ID
8418             * @param classPK the class p k
8419             * @return the number of matching roles
8420             * @throws SystemException if a system exception occurred
8421             */
8422            @Override
8423            public int countByC_C_C(long companyId, long classNameId, long classPK)
8424                    throws SystemException {
8425                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
8426    
8427                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8428    
8429                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8430                                    this);
8431    
8432                    if (count == null) {
8433                            StringBundler query = new StringBundler(4);
8434    
8435                            query.append(_SQL_COUNT_ROLE_WHERE);
8436    
8437                            query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8438    
8439                            query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8440    
8441                            query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8442    
8443                            String sql = query.toString();
8444    
8445                            Session session = null;
8446    
8447                            try {
8448                                    session = openSession();
8449    
8450                                    Query q = session.createQuery(sql);
8451    
8452                                    QueryPos qPos = QueryPos.getInstance(q);
8453    
8454                                    qPos.add(companyId);
8455    
8456                                    qPos.add(classNameId);
8457    
8458                                    qPos.add(classPK);
8459    
8460                                    count = (Long)q.uniqueResult();
8461    
8462                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8463                            }
8464                            catch (Exception e) {
8465                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8466    
8467                                    throw processException(e);
8468                            }
8469                            finally {
8470                                    closeSession(session);
8471                            }
8472                    }
8473    
8474                    return count.intValue();
8475            }
8476    
8477            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
8478            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
8479            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
8480    
8481            public RolePersistenceImpl() {
8482                    setModelClass(Role.class);
8483            }
8484    
8485            /**
8486             * Caches the role in the entity cache if it is enabled.
8487             *
8488             * @param role the role
8489             */
8490            @Override
8491            public void cacheResult(Role role) {
8492                    EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8493                            RoleImpl.class, role.getPrimaryKey(), role);
8494    
8495                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
8496                            new Object[] { role.getCompanyId(), role.getName() }, role);
8497    
8498                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8499                            new Object[] {
8500                                    role.getCompanyId(), role.getClassNameId(), role.getClassPK()
8501                            }, role);
8502    
8503                    role.resetOriginalValues();
8504            }
8505    
8506            /**
8507             * Caches the roles in the entity cache if it is enabled.
8508             *
8509             * @param roles the roles
8510             */
8511            @Override
8512            public void cacheResult(List<Role> roles) {
8513                    for (Role role : roles) {
8514                            if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8515                                                    RoleImpl.class, role.getPrimaryKey()) == null) {
8516                                    cacheResult(role);
8517                            }
8518                            else {
8519                                    role.resetOriginalValues();
8520                            }
8521                    }
8522            }
8523    
8524            /**
8525             * Clears the cache for all roles.
8526             *
8527             * <p>
8528             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8529             * </p>
8530             */
8531            @Override
8532            public void clearCache() {
8533                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
8534                            CacheRegistryUtil.clear(RoleImpl.class.getName());
8535                    }
8536    
8537                    EntityCacheUtil.clearCache(RoleImpl.class.getName());
8538    
8539                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8540                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8541                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8542            }
8543    
8544            /**
8545             * Clears the cache for the role.
8546             *
8547             * <p>
8548             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
8549             * </p>
8550             */
8551            @Override
8552            public void clearCache(Role role) {
8553                    EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8554                            RoleImpl.class, role.getPrimaryKey());
8555    
8556                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8557                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8558    
8559                    clearUniqueFindersCache(role);
8560            }
8561    
8562            @Override
8563            public void clearCache(List<Role> roles) {
8564                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8565                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8566    
8567                    for (Role role : roles) {
8568                            EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8569                                    RoleImpl.class, role.getPrimaryKey());
8570    
8571                            clearUniqueFindersCache(role);
8572                    }
8573            }
8574    
8575            protected void cacheUniqueFindersCache(Role role) {
8576                    if (role.isNew()) {
8577                            Object[] args = new Object[] { role.getCompanyId(), role.getName() };
8578    
8579                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8580                                    Long.valueOf(1));
8581                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
8582    
8583                            args = new Object[] {
8584                                            role.getCompanyId(), role.getClassNameId(),
8585                                            role.getClassPK()
8586                                    };
8587    
8588                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8589                                    Long.valueOf(1));
8590                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
8591                    }
8592                    else {
8593                            RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8594    
8595                            if ((roleModelImpl.getColumnBitmask() &
8596                                            FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8597                                    Object[] args = new Object[] { role.getCompanyId(), role.getName() };
8598    
8599                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8600                                            Long.valueOf(1));
8601                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
8602                            }
8603    
8604                            if ((roleModelImpl.getColumnBitmask() &
8605                                            FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8606                                    Object[] args = new Object[] {
8607                                                    role.getCompanyId(), role.getClassNameId(),
8608                                                    role.getClassPK()
8609                                            };
8610    
8611                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8612                                            Long.valueOf(1));
8613                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
8614                            }
8615                    }
8616            }
8617    
8618            protected void clearUniqueFindersCache(Role role) {
8619                    RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8620    
8621                    Object[] args = new Object[] { role.getCompanyId(), role.getName() };
8622    
8623                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8624                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8625    
8626                    if ((roleModelImpl.getColumnBitmask() &
8627                                    FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8628                            args = new Object[] {
8629                                            roleModelImpl.getOriginalCompanyId(),
8630                                            roleModelImpl.getOriginalName()
8631                                    };
8632    
8633                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8634                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8635                    }
8636    
8637                    args = new Object[] {
8638                                    role.getCompanyId(), role.getClassNameId(), role.getClassPK()
8639                            };
8640    
8641                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8642                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8643    
8644                    if ((roleModelImpl.getColumnBitmask() &
8645                                    FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8646                            args = new Object[] {
8647                                            roleModelImpl.getOriginalCompanyId(),
8648                                            roleModelImpl.getOriginalClassNameId(),
8649                                            roleModelImpl.getOriginalClassPK()
8650                                    };
8651    
8652                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8653                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8654                    }
8655            }
8656    
8657            /**
8658             * Creates a new role with the primary key. Does not add the role to the database.
8659             *
8660             * @param roleId the primary key for the new role
8661             * @return the new role
8662             */
8663            @Override
8664            public Role create(long roleId) {
8665                    Role role = new RoleImpl();
8666    
8667                    role.setNew(true);
8668                    role.setPrimaryKey(roleId);
8669    
8670                    String uuid = PortalUUIDUtil.generate();
8671    
8672                    role.setUuid(uuid);
8673    
8674                    return role;
8675            }
8676    
8677            /**
8678             * Removes the role with the primary key from the database. Also notifies the appropriate model listeners.
8679             *
8680             * @param roleId the primary key of the role
8681             * @return the role that was removed
8682             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
8683             * @throws SystemException if a system exception occurred
8684             */
8685            @Override
8686            public Role remove(long roleId) throws NoSuchRoleException, SystemException {
8687                    return remove((Serializable)roleId);
8688            }
8689    
8690            /**
8691             * Removes the role with the primary key from the database. Also notifies the appropriate model listeners.
8692             *
8693             * @param primaryKey the primary key of the role
8694             * @return the role that was removed
8695             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
8696             * @throws SystemException if a system exception occurred
8697             */
8698            @Override
8699            public Role remove(Serializable primaryKey)
8700                    throws NoSuchRoleException, SystemException {
8701                    Session session = null;
8702    
8703                    try {
8704                            session = openSession();
8705    
8706                            Role role = (Role)session.get(RoleImpl.class, primaryKey);
8707    
8708                            if (role == null) {
8709                                    if (_log.isWarnEnabled()) {
8710                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8711                                    }
8712    
8713                                    throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8714                                            primaryKey);
8715                            }
8716    
8717                            return remove(role);
8718                    }
8719                    catch (NoSuchRoleException nsee) {
8720                            throw nsee;
8721                    }
8722                    catch (Exception e) {
8723                            throw processException(e);
8724                    }
8725                    finally {
8726                            closeSession(session);
8727                    }
8728            }
8729    
8730            @Override
8731            protected Role removeImpl(Role role) throws SystemException {
8732                    role = toUnwrappedModel(role);
8733    
8734                    roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8735    
8736                    roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8737    
8738                    Session session = null;
8739    
8740                    try {
8741                            session = openSession();
8742    
8743                            if (!session.contains(role)) {
8744                                    role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
8745                            }
8746    
8747                            if (role != null) {
8748                                    session.delete(role);
8749                            }
8750                    }
8751                    catch (Exception e) {
8752                            throw processException(e);
8753                    }
8754                    finally {
8755                            closeSession(session);
8756                    }
8757    
8758                    if (role != null) {
8759                            clearCache(role);
8760                    }
8761    
8762                    return role;
8763            }
8764    
8765            @Override
8766            public Role updateImpl(com.liferay.portal.model.Role role)
8767                    throws SystemException {
8768                    role = toUnwrappedModel(role);
8769    
8770                    boolean isNew = role.isNew();
8771    
8772                    RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8773    
8774                    if (Validator.isNull(role.getUuid())) {
8775                            String uuid = PortalUUIDUtil.generate();
8776    
8777                            role.setUuid(uuid);
8778                    }
8779    
8780                    Session session = null;
8781    
8782                    try {
8783                            session = openSession();
8784    
8785                            if (role.isNew()) {
8786                                    session.save(role);
8787    
8788                                    role.setNew(false);
8789                            }
8790                            else {
8791                                    session.merge(role);
8792                            }
8793                    }
8794                    catch (Exception e) {
8795                            throw processException(e);
8796                    }
8797                    finally {
8798                            closeSession(session);
8799                    }
8800    
8801                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8802    
8803                    if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
8804                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8805                    }
8806    
8807                    else {
8808                            if ((roleModelImpl.getColumnBitmask() &
8809                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8810                                    Object[] args = new Object[] { roleModelImpl.getOriginalUuid() };
8811    
8812                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8813                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8814                                            args);
8815    
8816                                    args = new Object[] { roleModelImpl.getUuid() };
8817    
8818                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8819                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8820                                            args);
8821                            }
8822    
8823                            if ((roleModelImpl.getColumnBitmask() &
8824                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8825                                    Object[] args = new Object[] {
8826                                                    roleModelImpl.getOriginalUuid(),
8827                                                    roleModelImpl.getOriginalCompanyId()
8828                                            };
8829    
8830                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8831                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8832                                            args);
8833    
8834                                    args = new Object[] {
8835                                                    roleModelImpl.getUuid(), roleModelImpl.getCompanyId()
8836                                            };
8837    
8838                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8839                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8840                                            args);
8841                            }
8842    
8843                            if ((roleModelImpl.getColumnBitmask() &
8844                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8845                                    Object[] args = new Object[] {
8846                                                    roleModelImpl.getOriginalCompanyId()
8847                                            };
8848    
8849                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8850                                            args);
8851                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8852                                            args);
8853    
8854                                    args = new Object[] { roleModelImpl.getCompanyId() };
8855    
8856                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8857                                            args);
8858                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8859                                            args);
8860                            }
8861    
8862                            if ((roleModelImpl.getColumnBitmask() &
8863                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
8864                                    Object[] args = new Object[] { roleModelImpl.getOriginalName() };
8865    
8866                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8867                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8868                                            args);
8869    
8870                                    args = new Object[] { roleModelImpl.getName() };
8871    
8872                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8873                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8874                                            args);
8875                            }
8876    
8877                            if ((roleModelImpl.getColumnBitmask() &
8878                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
8879                                    Object[] args = new Object[] { roleModelImpl.getOriginalType() };
8880    
8881                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8882                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8883                                            args);
8884    
8885                                    args = new Object[] { roleModelImpl.getType() };
8886    
8887                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8888                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8889                                            args);
8890                            }
8891    
8892                            if ((roleModelImpl.getColumnBitmask() &
8893                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
8894                                    Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
8895    
8896                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8897                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8898                                            args);
8899    
8900                                    args = new Object[] { roleModelImpl.getSubtype() };
8901    
8902                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8903                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8904                                            args);
8905                            }
8906    
8907                            if ((roleModelImpl.getColumnBitmask() &
8908                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
8909                                    Object[] args = new Object[] {
8910                                                    roleModelImpl.getOriginalCompanyId(),
8911                                                    roleModelImpl.getOriginalType()
8912                                            };
8913    
8914                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8915                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8916                                            args);
8917    
8918                                    args = new Object[] {
8919                                                    roleModelImpl.getCompanyId(), roleModelImpl.getType()
8920                                            };
8921    
8922                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8923                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8924                                            args);
8925                            }
8926    
8927                            if ((roleModelImpl.getColumnBitmask() &
8928                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
8929                                    Object[] args = new Object[] {
8930                                                    roleModelImpl.getOriginalType(),
8931                                                    roleModelImpl.getOriginalSubtype()
8932                                            };
8933    
8934                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8935                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8936                                            args);
8937    
8938                                    args = new Object[] {
8939                                                    roleModelImpl.getType(), roleModelImpl.getSubtype()
8940                                            };
8941    
8942                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8943                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8944                                            args);
8945                            }
8946                    }
8947    
8948                    EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8949                            RoleImpl.class, role.getPrimaryKey(), role);
8950    
8951                    clearUniqueFindersCache(role);
8952                    cacheUniqueFindersCache(role);
8953    
8954                    return role;
8955            }
8956    
8957            protected Role toUnwrappedModel(Role role) {
8958                    if (role instanceof RoleImpl) {
8959                            return role;
8960                    }
8961    
8962                    RoleImpl roleImpl = new RoleImpl();
8963    
8964                    roleImpl.setNew(role.isNew());
8965                    roleImpl.setPrimaryKey(role.getPrimaryKey());
8966    
8967                    roleImpl.setUuid(role.getUuid());
8968                    roleImpl.setRoleId(role.getRoleId());
8969                    roleImpl.setCompanyId(role.getCompanyId());
8970                    roleImpl.setUserId(role.getUserId());
8971                    roleImpl.setUserName(role.getUserName());
8972                    roleImpl.setCreateDate(role.getCreateDate());
8973                    roleImpl.setModifiedDate(role.getModifiedDate());
8974                    roleImpl.setClassNameId(role.getClassNameId());
8975                    roleImpl.setClassPK(role.getClassPK());
8976                    roleImpl.setName(role.getName());
8977                    roleImpl.setTitle(role.getTitle());
8978                    roleImpl.setDescription(role.getDescription());
8979                    roleImpl.setType(role.getType());
8980                    roleImpl.setSubtype(role.getSubtype());
8981    
8982                    return roleImpl;
8983            }
8984    
8985            /**
8986             * Returns the role with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
8987             *
8988             * @param primaryKey the primary key of the role
8989             * @return the role
8990             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
8991             * @throws SystemException if a system exception occurred
8992             */
8993            @Override
8994            public Role findByPrimaryKey(Serializable primaryKey)
8995                    throws NoSuchRoleException, SystemException {
8996                    Role role = fetchByPrimaryKey(primaryKey);
8997    
8998                    if (role == null) {
8999                            if (_log.isWarnEnabled()) {
9000                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9001                            }
9002    
9003                            throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9004                                    primaryKey);
9005                    }
9006    
9007                    return role;
9008            }
9009    
9010            /**
9011             * Returns the role with the primary key or throws a {@link com.liferay.portal.NoSuchRoleException} if it could not be found.
9012             *
9013             * @param roleId the primary key of the role
9014             * @return the role
9015             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
9016             * @throws SystemException if a system exception occurred
9017             */
9018            @Override
9019            public Role findByPrimaryKey(long roleId)
9020                    throws NoSuchRoleException, SystemException {
9021                    return findByPrimaryKey((Serializable)roleId);
9022            }
9023    
9024            /**
9025             * Returns the role with the primary key or returns <code>null</code> if it could not be found.
9026             *
9027             * @param primaryKey the primary key of the role
9028             * @return the role, or <code>null</code> if a role with the primary key could not be found
9029             * @throws SystemException if a system exception occurred
9030             */
9031            @Override
9032            public Role fetchByPrimaryKey(Serializable primaryKey)
9033                    throws SystemException {
9034                    Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9035                                    RoleImpl.class, primaryKey);
9036    
9037                    if (role == _nullRole) {
9038                            return null;
9039                    }
9040    
9041                    if (role == null) {
9042                            Session session = null;
9043    
9044                            try {
9045                                    session = openSession();
9046    
9047                                    role = (Role)session.get(RoleImpl.class, primaryKey);
9048    
9049                                    if (role != null) {
9050                                            cacheResult(role);
9051                                    }
9052                                    else {
9053                                            EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9054                                                    RoleImpl.class, primaryKey, _nullRole);
9055                                    }
9056                            }
9057                            catch (Exception e) {
9058                                    EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9059                                            RoleImpl.class, primaryKey);
9060    
9061                                    throw processException(e);
9062                            }
9063                            finally {
9064                                    closeSession(session);
9065                            }
9066                    }
9067    
9068                    return role;
9069            }
9070    
9071            /**
9072             * Returns the role with the primary key or returns <code>null</code> if it could not be found.
9073             *
9074             * @param roleId the primary key of the role
9075             * @return the role, or <code>null</code> if a role with the primary key could not be found
9076             * @throws SystemException if a system exception occurred
9077             */
9078            @Override
9079            public Role fetchByPrimaryKey(long roleId) throws SystemException {
9080                    return fetchByPrimaryKey((Serializable)roleId);
9081            }
9082    
9083            /**
9084             * Returns all the roles.
9085             *
9086             * @return the roles
9087             * @throws SystemException if a system exception occurred
9088             */
9089            @Override
9090            public List<Role> findAll() throws SystemException {
9091                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9092            }
9093    
9094            /**
9095             * Returns a range of all the roles.
9096             *
9097             * <p>
9098             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9099             * </p>
9100             *
9101             * @param start the lower bound of the range of roles
9102             * @param end the upper bound of the range of roles (not inclusive)
9103             * @return the range of roles
9104             * @throws SystemException if a system exception occurred
9105             */
9106            @Override
9107            public List<Role> findAll(int start, int end) throws SystemException {
9108                    return findAll(start, end, null);
9109            }
9110    
9111            /**
9112             * Returns an ordered range of all the roles.
9113             *
9114             * <p>
9115             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9116             * </p>
9117             *
9118             * @param start the lower bound of the range of roles
9119             * @param end the upper bound of the range of roles (not inclusive)
9120             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9121             * @return the ordered range of roles
9122             * @throws SystemException if a system exception occurred
9123             */
9124            @Override
9125            public List<Role> findAll(int start, int end,
9126                    OrderByComparator orderByComparator) throws SystemException {
9127                    boolean pagination = true;
9128                    FinderPath finderPath = null;
9129                    Object[] finderArgs = null;
9130    
9131                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9132                                    (orderByComparator == null)) {
9133                            pagination = false;
9134                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9135                            finderArgs = FINDER_ARGS_EMPTY;
9136                    }
9137                    else {
9138                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9139                            finderArgs = new Object[] { start, end, orderByComparator };
9140                    }
9141    
9142                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
9143                                    finderArgs, this);
9144    
9145                    if (list == null) {
9146                            StringBundler query = null;
9147                            String sql = null;
9148    
9149                            if (orderByComparator != null) {
9150                                    query = new StringBundler(2 +
9151                                                    (orderByComparator.getOrderByFields().length * 3));
9152    
9153                                    query.append(_SQL_SELECT_ROLE);
9154    
9155                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9156                                            orderByComparator);
9157    
9158                                    sql = query.toString();
9159                            }
9160                            else {
9161                                    sql = _SQL_SELECT_ROLE;
9162    
9163                                    if (pagination) {
9164                                            sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
9165                                    }
9166                            }
9167    
9168                            Session session = null;
9169    
9170                            try {
9171                                    session = openSession();
9172    
9173                                    Query q = session.createQuery(sql);
9174    
9175                                    if (!pagination) {
9176                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9177                                                            end, false);
9178    
9179                                            Collections.sort(list);
9180    
9181                                            list = new UnmodifiableList<Role>(list);
9182                                    }
9183                                    else {
9184                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9185                                                            end);
9186                                    }
9187    
9188                                    cacheResult(list);
9189    
9190                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9191                            }
9192                            catch (Exception e) {
9193                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9194    
9195                                    throw processException(e);
9196                            }
9197                            finally {
9198                                    closeSession(session);
9199                            }
9200                    }
9201    
9202                    return list;
9203            }
9204    
9205            /**
9206             * Removes all the roles from the database.
9207             *
9208             * @throws SystemException if a system exception occurred
9209             */
9210            @Override
9211            public void removeAll() throws SystemException {
9212                    for (Role role : findAll()) {
9213                            remove(role);
9214                    }
9215            }
9216    
9217            /**
9218             * Returns the number of roles.
9219             *
9220             * @return the number of roles
9221             * @throws SystemException if a system exception occurred
9222             */
9223            @Override
9224            public int countAll() throws SystemException {
9225                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9226                                    FINDER_ARGS_EMPTY, this);
9227    
9228                    if (count == null) {
9229                            Session session = null;
9230    
9231                            try {
9232                                    session = openSession();
9233    
9234                                    Query q = session.createQuery(_SQL_COUNT_ROLE);
9235    
9236                                    count = (Long)q.uniqueResult();
9237    
9238                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9239                                            FINDER_ARGS_EMPTY, count);
9240                            }
9241                            catch (Exception e) {
9242                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
9243                                            FINDER_ARGS_EMPTY);
9244    
9245                                    throw processException(e);
9246                            }
9247                            finally {
9248                                    closeSession(session);
9249                            }
9250                    }
9251    
9252                    return count.intValue();
9253            }
9254    
9255            /**
9256             * Returns all the groups associated with the role.
9257             *
9258             * @param pk the primary key of the role
9259             * @return the groups associated with the role
9260             * @throws SystemException if a system exception occurred
9261             */
9262            @Override
9263            public List<com.liferay.portal.model.Group> getGroups(long pk)
9264                    throws SystemException {
9265                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9266            }
9267    
9268            /**
9269             * Returns a range of all the groups associated with the role.
9270             *
9271             * <p>
9272             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9273             * </p>
9274             *
9275             * @param pk the primary key of the role
9276             * @param start the lower bound of the range of roles
9277             * @param end the upper bound of the range of roles (not inclusive)
9278             * @return the range of groups associated with the role
9279             * @throws SystemException if a system exception occurred
9280             */
9281            @Override
9282            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
9283                    int end) throws SystemException {
9284                    return getGroups(pk, start, end, null);
9285            }
9286    
9287            /**
9288             * Returns an ordered range of all the groups associated with the role.
9289             *
9290             * <p>
9291             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9292             * </p>
9293             *
9294             * @param pk the primary key of the role
9295             * @param start the lower bound of the range of roles
9296             * @param end the upper bound of the range of roles (not inclusive)
9297             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9298             * @return the ordered range of groups associated with the role
9299             * @throws SystemException if a system exception occurred
9300             */
9301            @Override
9302            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
9303                    int end, OrderByComparator orderByComparator) throws SystemException {
9304                    return roleToGroupTableMapper.getRightBaseModels(pk, start, end,
9305                            orderByComparator);
9306            }
9307    
9308            /**
9309             * Returns the number of groups associated with the role.
9310             *
9311             * @param pk the primary key of the role
9312             * @return the number of groups associated with the role
9313             * @throws SystemException if a system exception occurred
9314             */
9315            @Override
9316            public int getGroupsSize(long pk) throws SystemException {
9317                    long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9318    
9319                    return pks.length;
9320            }
9321    
9322            /**
9323             * Returns <code>true</code> if the group is associated with the role.
9324             *
9325             * @param pk the primary key of the role
9326             * @param groupPK the primary key of the group
9327             * @return <code>true</code> if the group is associated with the role; <code>false</code> otherwise
9328             * @throws SystemException if a system exception occurred
9329             */
9330            @Override
9331            public boolean containsGroup(long pk, long groupPK)
9332                    throws SystemException {
9333                    return roleToGroupTableMapper.containsTableMapping(pk, groupPK);
9334            }
9335    
9336            /**
9337             * Returns <code>true</code> if the role has any groups associated with it.
9338             *
9339             * @param pk the primary key of the role to check for associations with groups
9340             * @return <code>true</code> if the role has any groups associated with it; <code>false</code> otherwise
9341             * @throws SystemException if a system exception occurred
9342             */
9343            @Override
9344            public boolean containsGroups(long pk) throws SystemException {
9345                    if (getGroupsSize(pk) > 0) {
9346                            return true;
9347                    }
9348                    else {
9349                            return false;
9350                    }
9351            }
9352    
9353            /**
9354             * Adds an association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9355             *
9356             * @param pk the primary key of the role
9357             * @param groupPK the primary key of the group
9358             * @throws SystemException if a system exception occurred
9359             */
9360            @Override
9361            public void addGroup(long pk, long groupPK) throws SystemException {
9362                    roleToGroupTableMapper.addTableMapping(pk, groupPK);
9363            }
9364    
9365            /**
9366             * Adds an association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9367             *
9368             * @param pk the primary key of the role
9369             * @param group the group
9370             * @throws SystemException if a system exception occurred
9371             */
9372            @Override
9373            public void addGroup(long pk, com.liferay.portal.model.Group group)
9374                    throws SystemException {
9375                    roleToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
9376            }
9377    
9378            /**
9379             * Adds an association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9380             *
9381             * @param pk the primary key of the role
9382             * @param groupPKs the primary keys of the groups
9383             * @throws SystemException if a system exception occurred
9384             */
9385            @Override
9386            public void addGroups(long pk, long[] groupPKs) throws SystemException {
9387                    for (long groupPK : groupPKs) {
9388                            roleToGroupTableMapper.addTableMapping(pk, groupPK);
9389                    }
9390            }
9391    
9392            /**
9393             * Adds an association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9394             *
9395             * @param pk the primary key of the role
9396             * @param groups the groups
9397             * @throws SystemException if a system exception occurred
9398             */
9399            @Override
9400            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
9401                    throws SystemException {
9402                    for (com.liferay.portal.model.Group group : groups) {
9403                            roleToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
9404                    }
9405            }
9406    
9407            /**
9408             * Clears all associations between the role and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9409             *
9410             * @param pk the primary key of the role to clear the associated groups from
9411             * @throws SystemException if a system exception occurred
9412             */
9413            @Override
9414            public void clearGroups(long pk) throws SystemException {
9415                    roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9416            }
9417    
9418            /**
9419             * Removes the association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9420             *
9421             * @param pk the primary key of the role
9422             * @param groupPK the primary key of the group
9423             * @throws SystemException if a system exception occurred
9424             */
9425            @Override
9426            public void removeGroup(long pk, long groupPK) throws SystemException {
9427                    roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9428            }
9429    
9430            /**
9431             * Removes the association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9432             *
9433             * @param pk the primary key of the role
9434             * @param group the group
9435             * @throws SystemException if a system exception occurred
9436             */
9437            @Override
9438            public void removeGroup(long pk, com.liferay.portal.model.Group group)
9439                    throws SystemException {
9440                    roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9441            }
9442    
9443            /**
9444             * Removes the association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9445             *
9446             * @param pk the primary key of the role
9447             * @param groupPKs the primary keys of the groups
9448             * @throws SystemException if a system exception occurred
9449             */
9450            @Override
9451            public void removeGroups(long pk, long[] groupPKs)
9452                    throws SystemException {
9453                    for (long groupPK : groupPKs) {
9454                            roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9455                    }
9456            }
9457    
9458            /**
9459             * Removes the association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9460             *
9461             * @param pk the primary key of the role
9462             * @param groups the groups
9463             * @throws SystemException if a system exception occurred
9464             */
9465            @Override
9466            public void removeGroups(long pk,
9467                    List<com.liferay.portal.model.Group> groups) throws SystemException {
9468                    for (com.liferay.portal.model.Group group : groups) {
9469                            roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9470                    }
9471            }
9472    
9473            /**
9474             * 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.
9475             *
9476             * @param pk the primary key of the role
9477             * @param groupPKs the primary keys of the groups to be associated with the role
9478             * @throws SystemException if a system exception occurred
9479             */
9480            @Override
9481            public void setGroups(long pk, long[] groupPKs) throws SystemException {
9482                    Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
9483                    Set<Long> oldGroupPKsSet = SetUtil.fromArray(roleToGroupTableMapper.getRightPrimaryKeys(
9484                                            pk));
9485    
9486                    Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
9487    
9488                    removeGroupPKsSet.removeAll(newGroupPKsSet);
9489    
9490                    for (long removeGroupPK : removeGroupPKsSet) {
9491                            roleToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
9492                    }
9493    
9494                    newGroupPKsSet.removeAll(oldGroupPKsSet);
9495    
9496                    for (long newGroupPK : newGroupPKsSet) {
9497                            roleToGroupTableMapper.addTableMapping(pk, newGroupPK);
9498                    }
9499            }
9500    
9501            /**
9502             * 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.
9503             *
9504             * @param pk the primary key of the role
9505             * @param groups the groups to be associated with the role
9506             * @throws SystemException if a system exception occurred
9507             */
9508            @Override
9509            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
9510                    throws SystemException {
9511                    try {
9512                            long[] groupPKs = new long[groups.size()];
9513    
9514                            for (int i = 0; i < groups.size(); i++) {
9515                                    com.liferay.portal.model.Group group = groups.get(i);
9516    
9517                                    groupPKs[i] = group.getPrimaryKey();
9518                            }
9519    
9520                            setGroups(pk, groupPKs);
9521                    }
9522                    catch (Exception e) {
9523                            throw processException(e);
9524                    }
9525                    finally {
9526                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
9527                    }
9528            }
9529    
9530            /**
9531             * Returns all the users associated with the role.
9532             *
9533             * @param pk the primary key of the role
9534             * @return the users associated with the role
9535             * @throws SystemException if a system exception occurred
9536             */
9537            @Override
9538            public List<com.liferay.portal.model.User> getUsers(long pk)
9539                    throws SystemException {
9540                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9541            }
9542    
9543            /**
9544             * Returns a range of all the users associated with the role.
9545             *
9546             * <p>
9547             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9548             * </p>
9549             *
9550             * @param pk the primary key of the role
9551             * @param start the lower bound of the range of roles
9552             * @param end the upper bound of the range of roles (not inclusive)
9553             * @return the range of users associated with the role
9554             * @throws SystemException if a system exception occurred
9555             */
9556            @Override
9557            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9558                    int end) throws SystemException {
9559                    return getUsers(pk, start, end, null);
9560            }
9561    
9562            /**
9563             * Returns an ordered range of all the users associated with the role.
9564             *
9565             * <p>
9566             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.RoleModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9567             * </p>
9568             *
9569             * @param pk the primary key of the role
9570             * @param start the lower bound of the range of roles
9571             * @param end the upper bound of the range of roles (not inclusive)
9572             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9573             * @return the ordered range of users associated with the role
9574             * @throws SystemException if a system exception occurred
9575             */
9576            @Override
9577            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9578                    int end, OrderByComparator orderByComparator) throws SystemException {
9579                    return roleToUserTableMapper.getRightBaseModels(pk, start, end,
9580                            orderByComparator);
9581            }
9582    
9583            /**
9584             * Returns the number of users associated with the role.
9585             *
9586             * @param pk the primary key of the role
9587             * @return the number of users associated with the role
9588             * @throws SystemException if a system exception occurred
9589             */
9590            @Override
9591            public int getUsersSize(long pk) throws SystemException {
9592                    long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9593    
9594                    return pks.length;
9595            }
9596    
9597            /**
9598             * Returns <code>true</code> if the user is associated with the role.
9599             *
9600             * @param pk the primary key of the role
9601             * @param userPK the primary key of the user
9602             * @return <code>true</code> if the user is associated with the role; <code>false</code> otherwise
9603             * @throws SystemException if a system exception occurred
9604             */
9605            @Override
9606            public boolean containsUser(long pk, long userPK) throws SystemException {
9607                    return roleToUserTableMapper.containsTableMapping(pk, userPK);
9608            }
9609    
9610            /**
9611             * Returns <code>true</code> if the role has any users associated with it.
9612             *
9613             * @param pk the primary key of the role to check for associations with users
9614             * @return <code>true</code> if the role has any users associated with it; <code>false</code> otherwise
9615             * @throws SystemException if a system exception occurred
9616             */
9617            @Override
9618            public boolean containsUsers(long pk) throws SystemException {
9619                    if (getUsersSize(pk) > 0) {
9620                            return true;
9621                    }
9622                    else {
9623                            return false;
9624                    }
9625            }
9626    
9627            /**
9628             * Adds an association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9629             *
9630             * @param pk the primary key of the role
9631             * @param userPK the primary key of the user
9632             * @throws SystemException if a system exception occurred
9633             */
9634            @Override
9635            public void addUser(long pk, long userPK) throws SystemException {
9636                    roleToUserTableMapper.addTableMapping(pk, userPK);
9637            }
9638    
9639            /**
9640             * Adds an association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9641             *
9642             * @param pk the primary key of the role
9643             * @param user the user
9644             * @throws SystemException if a system exception occurred
9645             */
9646            @Override
9647            public void addUser(long pk, com.liferay.portal.model.User user)
9648                    throws SystemException {
9649                    roleToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
9650            }
9651    
9652            /**
9653             * Adds an association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9654             *
9655             * @param pk the primary key of the role
9656             * @param userPKs the primary keys of the users
9657             * @throws SystemException if a system exception occurred
9658             */
9659            @Override
9660            public void addUsers(long pk, long[] userPKs) throws SystemException {
9661                    for (long userPK : userPKs) {
9662                            roleToUserTableMapper.addTableMapping(pk, userPK);
9663                    }
9664            }
9665    
9666            /**
9667             * Adds an association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9668             *
9669             * @param pk the primary key of the role
9670             * @param users the users
9671             * @throws SystemException if a system exception occurred
9672             */
9673            @Override
9674            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
9675                    throws SystemException {
9676                    for (com.liferay.portal.model.User user : users) {
9677                            roleToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
9678                    }
9679            }
9680    
9681            /**
9682             * Clears all associations between the role and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9683             *
9684             * @param pk the primary key of the role to clear the associated users from
9685             * @throws SystemException if a system exception occurred
9686             */
9687            @Override
9688            public void clearUsers(long pk) throws SystemException {
9689                    roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9690            }
9691    
9692            /**
9693             * Removes the association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9694             *
9695             * @param pk the primary key of the role
9696             * @param userPK the primary key of the user
9697             * @throws SystemException if a system exception occurred
9698             */
9699            @Override
9700            public void removeUser(long pk, long userPK) throws SystemException {
9701                    roleToUserTableMapper.deleteTableMapping(pk, userPK);
9702            }
9703    
9704            /**
9705             * Removes the association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9706             *
9707             * @param pk the primary key of the role
9708             * @param user the user
9709             * @throws SystemException if a system exception occurred
9710             */
9711            @Override
9712            public void removeUser(long pk, com.liferay.portal.model.User user)
9713                    throws SystemException {
9714                    roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9715            }
9716    
9717            /**
9718             * Removes the association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9719             *
9720             * @param pk the primary key of the role
9721             * @param userPKs the primary keys of the users
9722             * @throws SystemException if a system exception occurred
9723             */
9724            @Override
9725            public void removeUsers(long pk, long[] userPKs) throws SystemException {
9726                    for (long userPK : userPKs) {
9727                            roleToUserTableMapper.deleteTableMapping(pk, userPK);
9728                    }
9729            }
9730    
9731            /**
9732             * Removes the association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
9733             *
9734             * @param pk the primary key of the role
9735             * @param users the users
9736             * @throws SystemException if a system exception occurred
9737             */
9738            @Override
9739            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
9740                    throws SystemException {
9741                    for (com.liferay.portal.model.User user : users) {
9742                            roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9743                    }
9744            }
9745    
9746            /**
9747             * 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.
9748             *
9749             * @param pk the primary key of the role
9750             * @param userPKs the primary keys of the users to be associated with the role
9751             * @throws SystemException if a system exception occurred
9752             */
9753            @Override
9754            public void setUsers(long pk, long[] userPKs) throws SystemException {
9755                    Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
9756                    Set<Long> oldUserPKsSet = SetUtil.fromArray(roleToUserTableMapper.getRightPrimaryKeys(
9757                                            pk));
9758    
9759                    Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
9760    
9761                    removeUserPKsSet.removeAll(newUserPKsSet);
9762    
9763                    for (long removeUserPK : removeUserPKsSet) {
9764                            roleToUserTableMapper.deleteTableMapping(pk, removeUserPK);
9765                    }
9766    
9767                    newUserPKsSet.removeAll(oldUserPKsSet);
9768    
9769                    for (long newUserPK : newUserPKsSet) {
9770                            roleToUserTableMapper.addTableMapping(pk, newUserPK);
9771                    }
9772            }
9773    
9774            /**
9775             * 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.
9776             *
9777             * @param pk the primary key of the role
9778             * @param users the users to be associated with the role
9779             * @throws SystemException if a system exception occurred
9780             */
9781            @Override
9782            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
9783                    throws SystemException {
9784                    try {
9785                            long[] userPKs = new long[users.size()];
9786    
9787                            for (int i = 0; i < users.size(); i++) {
9788                                    com.liferay.portal.model.User user = users.get(i);
9789    
9790                                    userPKs[i] = user.getPrimaryKey();
9791                            }
9792    
9793                            setUsers(pk, userPKs);
9794                    }
9795                    catch (Exception e) {
9796                            throw processException(e);
9797                    }
9798                    finally {
9799                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
9800                    }
9801            }
9802    
9803            @Override
9804            protected Set<String> getBadColumnNames() {
9805                    return _badColumnNames;
9806            }
9807    
9808            /**
9809             * Initializes the role persistence.
9810             */
9811            public void afterPropertiesSet() {
9812                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9813                                            com.liferay.portal.util.PropsUtil.get(
9814                                                    "value.object.listener.com.liferay.portal.model.Role")));
9815    
9816                    if (listenerClassNames.length > 0) {
9817                            try {
9818                                    List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
9819    
9820                                    for (String listenerClassName : listenerClassNames) {
9821                                            listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
9822                                                            getClassLoader(), listenerClassName));
9823                                    }
9824    
9825                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9826                            }
9827                            catch (Exception e) {
9828                                    _log.error(e);
9829                            }
9830                    }
9831    
9832                    roleToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Roles",
9833                                    "roleId", "groupId", this, groupPersistence);
9834    
9835                    roleToUserTableMapper = TableMapperFactory.getTableMapper("Users_Roles",
9836                                    "roleId", "userId", this, userPersistence);
9837            }
9838    
9839            public void destroy() {
9840                    EntityCacheUtil.removeCache(RoleImpl.class.getName());
9841                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9842                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9843                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9844    
9845                    TableMapperFactory.removeTableMapper("Groups_Roles");
9846                    TableMapperFactory.removeTableMapper("Users_Roles");
9847            }
9848    
9849            @BeanReference(type = GroupPersistence.class)
9850            protected GroupPersistence groupPersistence;
9851            protected TableMapper<Role, com.liferay.portal.model.Group> roleToGroupTableMapper;
9852            @BeanReference(type = UserPersistence.class)
9853            protected UserPersistence userPersistence;
9854            protected TableMapper<Role, com.liferay.portal.model.User> roleToUserTableMapper;
9855            private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
9856            private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
9857            private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
9858            private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
9859            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
9860            private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
9861            private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
9862                    "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
9863            private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
9864                    ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
9865            private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
9866            private static final String _FILTER_ENTITY_ALIAS = "role";
9867            private static final String _FILTER_ENTITY_TABLE = "Role_";
9868            private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
9869            private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
9870            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
9871            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
9872            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9873            private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
9874            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9875                                    "uuid", "type"
9876                            });
9877            private static Role _nullRole = new RoleImpl() {
9878                            @Override
9879                            public Object clone() {
9880                                    return this;
9881                            }
9882    
9883                            @Override
9884                            public CacheModel<Role> toCacheModel() {
9885                                    return _nullRoleCacheModel;
9886                            }
9887                    };
9888    
9889            private static CacheModel<Role> _nullRoleCacheModel = new CacheModel<Role>() {
9890                            @Override
9891                            public Role toEntityModel() {
9892                                    return _nullRole;
9893                            }
9894                    };
9895    }