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