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