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