001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchRoleException;
019    import com.liferay.portal.kernel.annotation.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022    import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023    import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024    import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025    import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028    import com.liferay.portal.kernel.dao.orm.FinderPath;
029    import com.liferay.portal.kernel.dao.orm.Query;
030    import com.liferay.portal.kernel.dao.orm.QueryPos;
031    import com.liferay.portal.kernel.dao.orm.QueryUtil;
032    import com.liferay.portal.kernel.dao.orm.SQLQuery;
033    import com.liferay.portal.kernel.dao.orm.Session;
034    import com.liferay.portal.kernel.exception.SystemException;
035    import com.liferay.portal.kernel.log.Log;
036    import com.liferay.portal.kernel.log.LogFactoryUtil;
037    import com.liferay.portal.kernel.util.GetterUtil;
038    import com.liferay.portal.kernel.util.InstanceFactory;
039    import com.liferay.portal.kernel.util.OrderByComparator;
040    import com.liferay.portal.kernel.util.SetUtil;
041    import com.liferay.portal.kernel.util.StringBundler;
042    import com.liferay.portal.kernel.util.StringPool;
043    import com.liferay.portal.kernel.util.StringUtil;
044    import com.liferay.portal.kernel.util.Validator;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.model.Role;
047    import com.liferay.portal.model.impl.RoleImpl;
048    import com.liferay.portal.model.impl.RoleModelImpl;
049    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Collections;
055    import java.util.List;
056    import java.util.Set;
057    
058    /**
059     * The persistence implementation for the role service.
060     *
061     * <p>
062     * 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.
063     * </p>
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see RolePersistence
071     * @see RoleUtil
072     * @generated
073     */
074    public class RolePersistenceImpl extends BasePersistenceImpl<Role>
075            implements RolePersistence {
076            public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078                    ".List";
079            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
080                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081                            "findByCompanyId",
082                            new String[] {
083                                    Long.class.getName(),
084                                    
085                            "java.lang.Integer", "java.lang.Integer",
086                                    "com.liferay.portal.kernel.util.OrderByComparator"
087                            });
088            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
089                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090                            "countByCompanyId", new String[] { Long.class.getName() });
091            public static final FinderPath FINDER_PATH_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
092                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "findBySubtype",
094                            new String[] {
095                                    String.class.getName(),
096                                    
097                            "java.lang.Integer", "java.lang.Integer",
098                                    "com.liferay.portal.kernel.util.OrderByComparator"
099                            });
100            public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
101                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
102                            "countBySubtype", new String[] { String.class.getName() });
103            public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
104                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
105                            "fetchByC_N",
106                            new String[] { Long.class.getName(), String.class.getName() });
107            public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
108                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "countByC_N",
110                            new String[] { Long.class.getName(), String.class.getName() });
111            public static final FinderPath FINDER_PATH_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
112                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113                            "findByT_S",
114                            new String[] {
115                                    Integer.class.getName(), String.class.getName(),
116                                    
117                            "java.lang.Integer", "java.lang.Integer",
118                                    "com.liferay.portal.kernel.util.OrderByComparator"
119                            });
120            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
121                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
122                            "countByT_S",
123                            new String[] { Integer.class.getName(), String.class.getName() });
124            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
125                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
126                            "fetchByC_C_C",
127                            new String[] {
128                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
129                            });
130            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
131                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
132                            "countByC_C_C",
133                            new String[] {
134                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
135                            });
136            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
137                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
138                            "findAll", new String[0]);
139            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
140                            RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
141                            "countAll", new String[0]);
142    
143            /**
144             * Caches the role in the entity cache if it is enabled.
145             *
146             * @param role the role to cache
147             */
148            public void cacheResult(Role role) {
149                    EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
150                            RoleImpl.class, role.getPrimaryKey(), role);
151    
152                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
153                            new Object[] { new Long(role.getCompanyId()), role.getName() }, role);
154    
155                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
156                            new Object[] {
157                                    new Long(role.getCompanyId()), new Long(role.getClassNameId()),
158                                    new Long(role.getClassPK())
159                            }, role);
160            }
161    
162            /**
163             * Caches the roles in the entity cache if it is enabled.
164             *
165             * @param roles the roles to cache
166             */
167            public void cacheResult(List<Role> roles) {
168                    for (Role role : roles) {
169                            if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
170                                                    RoleImpl.class, role.getPrimaryKey(), this) == null) {
171                                    cacheResult(role);
172                            }
173                    }
174            }
175    
176            /**
177             * Clears the cache for all roles.
178             *
179             * <p>
180             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
181             * </p>
182             */
183            public void clearCache() {
184                    CacheRegistryUtil.clear(RoleImpl.class.getName());
185                    EntityCacheUtil.clearCache(RoleImpl.class.getName());
186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
188            }
189    
190            /**
191             * Clears the cache for the role.
192             *
193             * <p>
194             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
195             * </p>
196             */
197            public void clearCache(Role role) {
198                    EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
199                            RoleImpl.class, role.getPrimaryKey());
200    
201                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
202                            new Object[] { new Long(role.getCompanyId()), role.getName() });
203    
204                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
205                            new Object[] {
206                                    new Long(role.getCompanyId()), new Long(role.getClassNameId()),
207                                    new Long(role.getClassPK())
208                            });
209            }
210    
211            /**
212             * Creates a new role with the primary key. Does not add the role to the database.
213             *
214             * @param roleId the primary key for the new role
215             * @return the new role
216             */
217            public Role create(long roleId) {
218                    Role role = new RoleImpl();
219    
220                    role.setNew(true);
221                    role.setPrimaryKey(roleId);
222    
223                    return role;
224            }
225    
226            /**
227             * Removes the role with the primary key from the database. Also notifies the appropriate model listeners.
228             *
229             * @param primaryKey the primary key of the role to remove
230             * @return the role that was removed
231             * @throws com.liferay.portal.NoSuchModelException if a role with the primary key could not be found
232             * @throws SystemException if a system exception occurred
233             */
234            public Role remove(Serializable primaryKey)
235                    throws NoSuchModelException, SystemException {
236                    return remove(((Long)primaryKey).longValue());
237            }
238    
239            /**
240             * Removes the role with the primary key from the database. Also notifies the appropriate model listeners.
241             *
242             * @param roleId the primary key of the role to remove
243             * @return the role that was removed
244             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
245             * @throws SystemException if a system exception occurred
246             */
247            public Role remove(long roleId) throws NoSuchRoleException, SystemException {
248                    Session session = null;
249    
250                    try {
251                            session = openSession();
252    
253                            Role role = (Role)session.get(RoleImpl.class, new Long(roleId));
254    
255                            if (role == null) {
256                                    if (_log.isWarnEnabled()) {
257                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + roleId);
258                                    }
259    
260                                    throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
261                                            roleId);
262                            }
263    
264                            return remove(role);
265                    }
266                    catch (NoSuchRoleException nsee) {
267                            throw nsee;
268                    }
269                    catch (Exception e) {
270                            throw processException(e);
271                    }
272                    finally {
273                            closeSession(session);
274                    }
275            }
276    
277            protected Role removeImpl(Role role) throws SystemException {
278                    role = toUnwrappedModel(role);
279    
280                    try {
281                            clearGroups.clear(role.getPrimaryKey());
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
288                    }
289    
290                    try {
291                            clearPermissions.clear(role.getPrimaryKey());
292                    }
293                    catch (Exception e) {
294                            throw processException(e);
295                    }
296                    finally {
297                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
298                    }
299    
300                    try {
301                            clearUsers.clear(role.getPrimaryKey());
302                    }
303                    catch (Exception e) {
304                            throw processException(e);
305                    }
306                    finally {
307                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
308                    }
309    
310                    Session session = null;
311    
312                    try {
313                            session = openSession();
314    
315                            BatchSessionUtil.delete(session, role);
316                    }
317                    catch (Exception e) {
318                            throw processException(e);
319                    }
320                    finally {
321                            closeSession(session);
322                    }
323    
324                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325    
326                    RoleModelImpl roleModelImpl = (RoleModelImpl)role;
327    
328                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
329                            new Object[] {
330                                    new Long(roleModelImpl.getOriginalCompanyId()),
331                                    
332                            roleModelImpl.getOriginalName()
333                            });
334    
335                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
336                            new Object[] {
337                                    new Long(roleModelImpl.getOriginalCompanyId()),
338                                    new Long(roleModelImpl.getOriginalClassNameId()),
339                                    new Long(roleModelImpl.getOriginalClassPK())
340                            });
341    
342                    EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
343                            RoleImpl.class, role.getPrimaryKey());
344    
345                    return role;
346            }
347    
348            public Role updateImpl(com.liferay.portal.model.Role role, boolean merge)
349                    throws SystemException {
350                    role = toUnwrappedModel(role);
351    
352                    boolean isNew = role.isNew();
353    
354                    RoleModelImpl roleModelImpl = (RoleModelImpl)role;
355    
356                    Session session = null;
357    
358                    try {
359                            session = openSession();
360    
361                            BatchSessionUtil.update(session, role, merge);
362    
363                            role.setNew(false);
364                    }
365                    catch (Exception e) {
366                            throw processException(e);
367                    }
368                    finally {
369                            closeSession(session);
370                    }
371    
372                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
373    
374                    EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
375                            RoleImpl.class, role.getPrimaryKey(), role);
376    
377                    if (!isNew &&
378                                    ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
379                                    !Validator.equals(role.getName(),
380                                            roleModelImpl.getOriginalName()))) {
381                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
382                                    new Object[] {
383                                            new Long(roleModelImpl.getOriginalCompanyId()),
384                                            
385                                    roleModelImpl.getOriginalName()
386                                    });
387                    }
388    
389                    if (isNew ||
390                                    ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
391                                    !Validator.equals(role.getName(),
392                                            roleModelImpl.getOriginalName()))) {
393                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
394                                    new Object[] { new Long(role.getCompanyId()), role.getName() },
395                                    role);
396                    }
397    
398                    if (!isNew &&
399                                    ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
400                                    (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
401                                    (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
402                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
403                                    new Object[] {
404                                            new Long(roleModelImpl.getOriginalCompanyId()),
405                                            new Long(roleModelImpl.getOriginalClassNameId()),
406                                            new Long(roleModelImpl.getOriginalClassPK())
407                                    });
408                    }
409    
410                    if (isNew ||
411                                    ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
412                                    (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
413                                    (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
414                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
415                                    new Object[] {
416                                            new Long(role.getCompanyId()),
417                                            new Long(role.getClassNameId()), new Long(role.getClassPK())
418                                    }, role);
419                    }
420    
421                    return role;
422            }
423    
424            protected Role toUnwrappedModel(Role role) {
425                    if (role instanceof RoleImpl) {
426                            return role;
427                    }
428    
429                    RoleImpl roleImpl = new RoleImpl();
430    
431                    roleImpl.setNew(role.isNew());
432                    roleImpl.setPrimaryKey(role.getPrimaryKey());
433    
434                    roleImpl.setRoleId(role.getRoleId());
435                    roleImpl.setCompanyId(role.getCompanyId());
436                    roleImpl.setClassNameId(role.getClassNameId());
437                    roleImpl.setClassPK(role.getClassPK());
438                    roleImpl.setName(role.getName());
439                    roleImpl.setTitle(role.getTitle());
440                    roleImpl.setDescription(role.getDescription());
441                    roleImpl.setType(role.getType());
442                    roleImpl.setSubtype(role.getSubtype());
443    
444                    return roleImpl;
445            }
446    
447            /**
448             * Finds the role with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
449             *
450             * @param primaryKey the primary key of the role to find
451             * @return the role
452             * @throws com.liferay.portal.NoSuchModelException if a role with the primary key could not be found
453             * @throws SystemException if a system exception occurred
454             */
455            public Role findByPrimaryKey(Serializable primaryKey)
456                    throws NoSuchModelException, SystemException {
457                    return findByPrimaryKey(((Long)primaryKey).longValue());
458            }
459    
460            /**
461             * Finds the role with the primary key or throws a {@link com.liferay.portal.NoSuchRoleException} if it could not be found.
462             *
463             * @param roleId the primary key of the role to find
464             * @return the role
465             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
466             * @throws SystemException if a system exception occurred
467             */
468            public Role findByPrimaryKey(long roleId)
469                    throws NoSuchRoleException, SystemException {
470                    Role role = fetchByPrimaryKey(roleId);
471    
472                    if (role == null) {
473                            if (_log.isWarnEnabled()) {
474                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + roleId);
475                            }
476    
477                            throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
478                                    roleId);
479                    }
480    
481                    return role;
482            }
483    
484            /**
485             * Finds the role with the primary key or returns <code>null</code> if it could not be found.
486             *
487             * @param primaryKey the primary key of the role to find
488             * @return the role, or <code>null</code> if a role with the primary key could not be found
489             * @throws SystemException if a system exception occurred
490             */
491            public Role fetchByPrimaryKey(Serializable primaryKey)
492                    throws SystemException {
493                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
494            }
495    
496            /**
497             * Finds the role with the primary key or returns <code>null</code> if it could not be found.
498             *
499             * @param roleId the primary key of the role to find
500             * @return the role, or <code>null</code> if a role with the primary key could not be found
501             * @throws SystemException if a system exception occurred
502             */
503            public Role fetchByPrimaryKey(long roleId) throws SystemException {
504                    Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
505                                    RoleImpl.class, roleId, this);
506    
507                    if (role == null) {
508                            Session session = null;
509    
510                            try {
511                                    session = openSession();
512    
513                                    role = (Role)session.get(RoleImpl.class, new Long(roleId));
514                            }
515                            catch (Exception e) {
516                                    throw processException(e);
517                            }
518                            finally {
519                                    if (role != null) {
520                                            cacheResult(role);
521                                    }
522    
523                                    closeSession(session);
524                            }
525                    }
526    
527                    return role;
528            }
529    
530            /**
531             * Finds all the roles where companyId = &#63;.
532             *
533             * @param companyId the company id to search with
534             * @return the matching roles
535             * @throws SystemException if a system exception occurred
536             */
537            public List<Role> findByCompanyId(long companyId) throws SystemException {
538                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
539                            null);
540            }
541    
542            /**
543             * Finds a range of all the roles where companyId = &#63;.
544             *
545             * <p>
546             * 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.
547             * </p>
548             *
549             * @param companyId the company id to search with
550             * @param start the lower bound of the range of roles to return
551             * @param end the upper bound of the range of roles to return (not inclusive)
552             * @return the range of matching roles
553             * @throws SystemException if a system exception occurred
554             */
555            public List<Role> findByCompanyId(long companyId, int start, int end)
556                    throws SystemException {
557                    return findByCompanyId(companyId, start, end, null);
558            }
559    
560            /**
561             * Finds an ordered range of all the roles where companyId = &#63;.
562             *
563             * <p>
564             * 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.
565             * </p>
566             *
567             * @param companyId the company id to search with
568             * @param start the lower bound of the range of roles to return
569             * @param end the upper bound of the range of roles to return (not inclusive)
570             * @param orderByComparator the comparator to order the results by
571             * @return the ordered range of matching roles
572             * @throws SystemException if a system exception occurred
573             */
574            public List<Role> findByCompanyId(long companyId, int start, int end,
575                    OrderByComparator orderByComparator) throws SystemException {
576                    Object[] finderArgs = new Object[] {
577                                    companyId,
578                                    
579                                    String.valueOf(start), String.valueOf(end),
580                                    String.valueOf(orderByComparator)
581                            };
582    
583                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
584                                    finderArgs, this);
585    
586                    if (list == null) {
587                            Session session = null;
588    
589                            try {
590                                    session = openSession();
591    
592                                    StringBundler query = null;
593    
594                                    if (orderByComparator != null) {
595                                            query = new StringBundler(3 +
596                                                            (orderByComparator.getOrderByFields().length * 3));
597                                    }
598                                    else {
599                                            query = new StringBundler(3);
600                                    }
601    
602                                    query.append(_SQL_SELECT_ROLE_WHERE);
603    
604                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
605    
606                                    if (orderByComparator != null) {
607                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
608                                                    orderByComparator);
609                                    }
610    
611                                    else {
612                                            query.append(RoleModelImpl.ORDER_BY_JPQL);
613                                    }
614    
615                                    String sql = query.toString();
616    
617                                    Query q = session.createQuery(sql);
618    
619                                    QueryPos qPos = QueryPos.getInstance(q);
620    
621                                    qPos.add(companyId);
622    
623                                    list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
624                            }
625                            catch (Exception e) {
626                                    throw processException(e);
627                            }
628                            finally {
629                                    if (list == null) {
630                                            list = new ArrayList<Role>();
631                                    }
632    
633                                    cacheResult(list);
634    
635                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
636                                            finderArgs, list);
637    
638                                    closeSession(session);
639                            }
640                    }
641    
642                    return list;
643            }
644    
645            /**
646             * Finds the first role in the ordered set where companyId = &#63;.
647             *
648             * <p>
649             * 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.
650             * </p>
651             *
652             * @param companyId the company id to search with
653             * @param orderByComparator the comparator to order the set by
654             * @return the first matching role
655             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
656             * @throws SystemException if a system exception occurred
657             */
658            public Role findByCompanyId_First(long companyId,
659                    OrderByComparator orderByComparator)
660                    throws NoSuchRoleException, SystemException {
661                    List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
662    
663                    if (list.isEmpty()) {
664                            StringBundler msg = new StringBundler(4);
665    
666                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
667    
668                            msg.append("companyId=");
669                            msg.append(companyId);
670    
671                            msg.append(StringPool.CLOSE_CURLY_BRACE);
672    
673                            throw new NoSuchRoleException(msg.toString());
674                    }
675                    else {
676                            return list.get(0);
677                    }
678            }
679    
680            /**
681             * Finds the last role in the ordered set where companyId = &#63;.
682             *
683             * <p>
684             * 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.
685             * </p>
686             *
687             * @param companyId the company id to search with
688             * @param orderByComparator the comparator to order the set by
689             * @return the last matching role
690             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
691             * @throws SystemException if a system exception occurred
692             */
693            public Role findByCompanyId_Last(long companyId,
694                    OrderByComparator orderByComparator)
695                    throws NoSuchRoleException, SystemException {
696                    int count = countByCompanyId(companyId);
697    
698                    List<Role> list = findByCompanyId(companyId, count - 1, count,
699                                    orderByComparator);
700    
701                    if (list.isEmpty()) {
702                            StringBundler msg = new StringBundler(4);
703    
704                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
705    
706                            msg.append("companyId=");
707                            msg.append(companyId);
708    
709                            msg.append(StringPool.CLOSE_CURLY_BRACE);
710    
711                            throw new NoSuchRoleException(msg.toString());
712                    }
713                    else {
714                            return list.get(0);
715                    }
716            }
717    
718            /**
719             * Finds the roles before and after the current role in the ordered set where companyId = &#63;.
720             *
721             * <p>
722             * 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.
723             * </p>
724             *
725             * @param roleId the primary key of the current role
726             * @param companyId the company id to search with
727             * @param orderByComparator the comparator to order the set by
728             * @return the previous, current, and next role
729             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
730             * @throws SystemException if a system exception occurred
731             */
732            public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
733                    OrderByComparator orderByComparator)
734                    throws NoSuchRoleException, SystemException {
735                    Role role = findByPrimaryKey(roleId);
736    
737                    Session session = null;
738    
739                    try {
740                            session = openSession();
741    
742                            Role[] array = new RoleImpl[3];
743    
744                            array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
745                                            orderByComparator, true);
746    
747                            array[1] = role;
748    
749                            array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
750                                            orderByComparator, false);
751    
752                            return array;
753                    }
754                    catch (Exception e) {
755                            throw processException(e);
756                    }
757                    finally {
758                            closeSession(session);
759                    }
760            }
761    
762            protected Role getByCompanyId_PrevAndNext(Session session, Role role,
763                    long companyId, OrderByComparator orderByComparator, boolean previous) {
764                    StringBundler query = null;
765    
766                    if (orderByComparator != null) {
767                            query = new StringBundler(6 +
768                                            (orderByComparator.getOrderByFields().length * 6));
769                    }
770                    else {
771                            query = new StringBundler(3);
772                    }
773    
774                    query.append(_SQL_SELECT_ROLE_WHERE);
775    
776                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
777    
778                    if (orderByComparator != null) {
779                            String[] orderByFields = orderByComparator.getOrderByFields();
780    
781                            if (orderByFields.length > 0) {
782                                    query.append(WHERE_AND);
783                            }
784    
785                            for (int i = 0; i < orderByFields.length; i++) {
786                                    query.append(_ORDER_BY_ENTITY_ALIAS);
787                                    query.append(orderByFields[i]);
788    
789                                    if ((i + 1) < orderByFields.length) {
790                                            if (orderByComparator.isAscending() ^ previous) {
791                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
792                                            }
793                                            else {
794                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
795                                            }
796                                    }
797                                    else {
798                                            if (orderByComparator.isAscending() ^ previous) {
799                                                    query.append(WHERE_GREATER_THAN);
800                                            }
801                                            else {
802                                                    query.append(WHERE_LESSER_THAN);
803                                            }
804                                    }
805                            }
806    
807                            query.append(ORDER_BY_CLAUSE);
808    
809                            for (int i = 0; i < orderByFields.length; i++) {
810                                    query.append(_ORDER_BY_ENTITY_ALIAS);
811                                    query.append(orderByFields[i]);
812    
813                                    if ((i + 1) < orderByFields.length) {
814                                            if (orderByComparator.isAscending() ^ previous) {
815                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
816                                            }
817                                            else {
818                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
819                                            }
820                                    }
821                                    else {
822                                            if (orderByComparator.isAscending() ^ previous) {
823                                                    query.append(ORDER_BY_ASC);
824                                            }
825                                            else {
826                                                    query.append(ORDER_BY_DESC);
827                                            }
828                                    }
829                            }
830                    }
831    
832                    else {
833                            query.append(RoleModelImpl.ORDER_BY_JPQL);
834                    }
835    
836                    String sql = query.toString();
837    
838                    Query q = session.createQuery(sql);
839    
840                    q.setFirstResult(0);
841                    q.setMaxResults(2);
842    
843                    QueryPos qPos = QueryPos.getInstance(q);
844    
845                    qPos.add(companyId);
846    
847                    if (orderByComparator != null) {
848                            Object[] values = orderByComparator.getOrderByValues(role);
849    
850                            for (Object value : values) {
851                                    qPos.add(value);
852                            }
853                    }
854    
855                    List<Role> list = q.list();
856    
857                    if (list.size() == 2) {
858                            return list.get(1);
859                    }
860                    else {
861                            return null;
862                    }
863            }
864    
865            /**
866             * Finds all the roles where subtype = &#63;.
867             *
868             * @param subtype the subtype to search with
869             * @return the matching roles
870             * @throws SystemException if a system exception occurred
871             */
872            public List<Role> findBySubtype(String subtype) throws SystemException {
873                    return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
874            }
875    
876            /**
877             * Finds a range of all the roles where subtype = &#63;.
878             *
879             * <p>
880             * 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.
881             * </p>
882             *
883             * @param subtype the subtype to search with
884             * @param start the lower bound of the range of roles to return
885             * @param end the upper bound of the range of roles to return (not inclusive)
886             * @return the range of matching roles
887             * @throws SystemException if a system exception occurred
888             */
889            public List<Role> findBySubtype(String subtype, int start, int end)
890                    throws SystemException {
891                    return findBySubtype(subtype, start, end, null);
892            }
893    
894            /**
895             * Finds an ordered range of all the roles where subtype = &#63;.
896             *
897             * <p>
898             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
899             * </p>
900             *
901             * @param subtype the subtype to search with
902             * @param start the lower bound of the range of roles to return
903             * @param end the upper bound of the range of roles to return (not inclusive)
904             * @param orderByComparator the comparator to order the results by
905             * @return the ordered range of matching roles
906             * @throws SystemException if a system exception occurred
907             */
908            public List<Role> findBySubtype(String subtype, int start, int end,
909                    OrderByComparator orderByComparator) throws SystemException {
910                    Object[] finderArgs = new Object[] {
911                                    subtype,
912                                    
913                                    String.valueOf(start), String.valueOf(end),
914                                    String.valueOf(orderByComparator)
915                            };
916    
917                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_SUBTYPE,
918                                    finderArgs, this);
919    
920                    if (list == null) {
921                            Session session = null;
922    
923                            try {
924                                    session = openSession();
925    
926                                    StringBundler query = null;
927    
928                                    if (orderByComparator != null) {
929                                            query = new StringBundler(3 +
930                                                            (orderByComparator.getOrderByFields().length * 3));
931                                    }
932                                    else {
933                                            query = new StringBundler(3);
934                                    }
935    
936                                    query.append(_SQL_SELECT_ROLE_WHERE);
937    
938                                    if (subtype == null) {
939                                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
940                                    }
941                                    else {
942                                            if (subtype.equals(StringPool.BLANK)) {
943                                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
944                                            }
945                                            else {
946                                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
947                                            }
948                                    }
949    
950                                    if (orderByComparator != null) {
951                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
952                                                    orderByComparator);
953                                    }
954    
955                                    else {
956                                            query.append(RoleModelImpl.ORDER_BY_JPQL);
957                                    }
958    
959                                    String sql = query.toString();
960    
961                                    Query q = session.createQuery(sql);
962    
963                                    QueryPos qPos = QueryPos.getInstance(q);
964    
965                                    if (subtype != null) {
966                                            qPos.add(subtype);
967                                    }
968    
969                                    list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
970                            }
971                            catch (Exception e) {
972                                    throw processException(e);
973                            }
974                            finally {
975                                    if (list == null) {
976                                            list = new ArrayList<Role>();
977                                    }
978    
979                                    cacheResult(list);
980    
981                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_SUBTYPE,
982                                            finderArgs, list);
983    
984                                    closeSession(session);
985                            }
986                    }
987    
988                    return list;
989            }
990    
991            /**
992             * Finds the first role in the ordered set where subtype = &#63;.
993             *
994             * <p>
995             * 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.
996             * </p>
997             *
998             * @param subtype the subtype to search with
999             * @param orderByComparator the comparator to order the set by
1000             * @return the first matching role
1001             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1002             * @throws SystemException if a system exception occurred
1003             */
1004            public Role findBySubtype_First(String subtype,
1005                    OrderByComparator orderByComparator)
1006                    throws NoSuchRoleException, SystemException {
1007                    List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
1008    
1009                    if (list.isEmpty()) {
1010                            StringBundler msg = new StringBundler(4);
1011    
1012                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1013    
1014                            msg.append("subtype=");
1015                            msg.append(subtype);
1016    
1017                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1018    
1019                            throw new NoSuchRoleException(msg.toString());
1020                    }
1021                    else {
1022                            return list.get(0);
1023                    }
1024            }
1025    
1026            /**
1027             * Finds the last role in the ordered set where subtype = &#63;.
1028             *
1029             * <p>
1030             * 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.
1031             * </p>
1032             *
1033             * @param subtype the subtype to search with
1034             * @param orderByComparator the comparator to order the set by
1035             * @return the last matching role
1036             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1037             * @throws SystemException if a system exception occurred
1038             */
1039            public Role findBySubtype_Last(String subtype,
1040                    OrderByComparator orderByComparator)
1041                    throws NoSuchRoleException, SystemException {
1042                    int count = countBySubtype(subtype);
1043    
1044                    List<Role> list = findBySubtype(subtype, count - 1, count,
1045                                    orderByComparator);
1046    
1047                    if (list.isEmpty()) {
1048                            StringBundler msg = new StringBundler(4);
1049    
1050                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1051    
1052                            msg.append("subtype=");
1053                            msg.append(subtype);
1054    
1055                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1056    
1057                            throw new NoSuchRoleException(msg.toString());
1058                    }
1059                    else {
1060                            return list.get(0);
1061                    }
1062            }
1063    
1064            /**
1065             * Finds the roles before and after the current role in the ordered set where subtype = &#63;.
1066             *
1067             * <p>
1068             * 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.
1069             * </p>
1070             *
1071             * @param roleId the primary key of the current role
1072             * @param subtype the subtype to search with
1073             * @param orderByComparator the comparator to order the set by
1074             * @return the previous, current, and next role
1075             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
1076             * @throws SystemException if a system exception occurred
1077             */
1078            public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
1079                    OrderByComparator orderByComparator)
1080                    throws NoSuchRoleException, SystemException {
1081                    Role role = findByPrimaryKey(roleId);
1082    
1083                    Session session = null;
1084    
1085                    try {
1086                            session = openSession();
1087    
1088                            Role[] array = new RoleImpl[3];
1089    
1090                            array[0] = getBySubtype_PrevAndNext(session, role, subtype,
1091                                            orderByComparator, true);
1092    
1093                            array[1] = role;
1094    
1095                            array[2] = getBySubtype_PrevAndNext(session, role, subtype,
1096                                            orderByComparator, false);
1097    
1098                            return array;
1099                    }
1100                    catch (Exception e) {
1101                            throw processException(e);
1102                    }
1103                    finally {
1104                            closeSession(session);
1105                    }
1106            }
1107    
1108            protected Role getBySubtype_PrevAndNext(Session session, Role role,
1109                    String subtype, OrderByComparator orderByComparator, boolean previous) {
1110                    StringBundler query = null;
1111    
1112                    if (orderByComparator != null) {
1113                            query = new StringBundler(6 +
1114                                            (orderByComparator.getOrderByFields().length * 6));
1115                    }
1116                    else {
1117                            query = new StringBundler(3);
1118                    }
1119    
1120                    query.append(_SQL_SELECT_ROLE_WHERE);
1121    
1122                    if (subtype == null) {
1123                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
1124                    }
1125                    else {
1126                            if (subtype.equals(StringPool.BLANK)) {
1127                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
1128                            }
1129                            else {
1130                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
1131                            }
1132                    }
1133    
1134                    if (orderByComparator != null) {
1135                            String[] orderByFields = orderByComparator.getOrderByFields();
1136    
1137                            if (orderByFields.length > 0) {
1138                                    query.append(WHERE_AND);
1139                            }
1140    
1141                            for (int i = 0; i < orderByFields.length; i++) {
1142                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1143                                    query.append(orderByFields[i]);
1144    
1145                                    if ((i + 1) < orderByFields.length) {
1146                                            if (orderByComparator.isAscending() ^ previous) {
1147                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1148                                            }
1149                                            else {
1150                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1151                                            }
1152                                    }
1153                                    else {
1154                                            if (orderByComparator.isAscending() ^ previous) {
1155                                                    query.append(WHERE_GREATER_THAN);
1156                                            }
1157                                            else {
1158                                                    query.append(WHERE_LESSER_THAN);
1159                                            }
1160                                    }
1161                            }
1162    
1163                            query.append(ORDER_BY_CLAUSE);
1164    
1165                            for (int i = 0; i < orderByFields.length; i++) {
1166                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1167                                    query.append(orderByFields[i]);
1168    
1169                                    if ((i + 1) < orderByFields.length) {
1170                                            if (orderByComparator.isAscending() ^ previous) {
1171                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1172                                            }
1173                                            else {
1174                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1175                                            }
1176                                    }
1177                                    else {
1178                                            if (orderByComparator.isAscending() ^ previous) {
1179                                                    query.append(ORDER_BY_ASC);
1180                                            }
1181                                            else {
1182                                                    query.append(ORDER_BY_DESC);
1183                                            }
1184                                    }
1185                            }
1186                    }
1187    
1188                    else {
1189                            query.append(RoleModelImpl.ORDER_BY_JPQL);
1190                    }
1191    
1192                    String sql = query.toString();
1193    
1194                    Query q = session.createQuery(sql);
1195    
1196                    q.setFirstResult(0);
1197                    q.setMaxResults(2);
1198    
1199                    QueryPos qPos = QueryPos.getInstance(q);
1200    
1201                    if (subtype != null) {
1202                            qPos.add(subtype);
1203                    }
1204    
1205                    if (orderByComparator != null) {
1206                            Object[] values = orderByComparator.getOrderByValues(role);
1207    
1208                            for (Object value : values) {
1209                                    qPos.add(value);
1210                            }
1211                    }
1212    
1213                    List<Role> list = q.list();
1214    
1215                    if (list.size() == 2) {
1216                            return list.get(1);
1217                    }
1218                    else {
1219                            return null;
1220                    }
1221            }
1222    
1223            /**
1224             * Finds the role where companyId = &#63; and name = &#63; or throws a {@link com.liferay.portal.NoSuchRoleException} if it could not be found.
1225             *
1226             * @param companyId the company id to search with
1227             * @param name the name to search with
1228             * @return the matching role
1229             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1230             * @throws SystemException if a system exception occurred
1231             */
1232            public Role findByC_N(long companyId, String name)
1233                    throws NoSuchRoleException, SystemException {
1234                    Role role = fetchByC_N(companyId, name);
1235    
1236                    if (role == null) {
1237                            StringBundler msg = new StringBundler(6);
1238    
1239                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1240    
1241                            msg.append("companyId=");
1242                            msg.append(companyId);
1243    
1244                            msg.append(", name=");
1245                            msg.append(name);
1246    
1247                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1248    
1249                            if (_log.isWarnEnabled()) {
1250                                    _log.warn(msg.toString());
1251                            }
1252    
1253                            throw new NoSuchRoleException(msg.toString());
1254                    }
1255    
1256                    return role;
1257            }
1258    
1259            /**
1260             * Finds the role where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1261             *
1262             * @param companyId the company id to search with
1263             * @param name the name to search with
1264             * @return the matching role, or <code>null</code> if a matching role could not be found
1265             * @throws SystemException if a system exception occurred
1266             */
1267            public Role fetchByC_N(long companyId, String name)
1268                    throws SystemException {
1269                    return fetchByC_N(companyId, name, true);
1270            }
1271    
1272            /**
1273             * Finds the role where companyId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1274             *
1275             * @param companyId the company id to search with
1276             * @param name the name to search with
1277             * @return the matching role, or <code>null</code> if a matching role could not be found
1278             * @throws SystemException if a system exception occurred
1279             */
1280            public Role fetchByC_N(long companyId, String name,
1281                    boolean retrieveFromCache) throws SystemException {
1282                    Object[] finderArgs = new Object[] { companyId, name };
1283    
1284                    Object result = null;
1285    
1286                    if (retrieveFromCache) {
1287                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
1288                                            finderArgs, this);
1289                    }
1290    
1291                    if (result == null) {
1292                            Session session = null;
1293    
1294                            try {
1295                                    session = openSession();
1296    
1297                                    StringBundler query = new StringBundler(4);
1298    
1299                                    query.append(_SQL_SELECT_ROLE_WHERE);
1300    
1301                                    query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1302    
1303                                    if (name == null) {
1304                                            query.append(_FINDER_COLUMN_C_N_NAME_1);
1305                                    }
1306                                    else {
1307                                            if (name.equals(StringPool.BLANK)) {
1308                                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
1309                                            }
1310                                            else {
1311                                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
1312                                            }
1313                                    }
1314    
1315                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
1316    
1317                                    String sql = query.toString();
1318    
1319                                    Query q = session.createQuery(sql);
1320    
1321                                    QueryPos qPos = QueryPos.getInstance(q);
1322    
1323                                    qPos.add(companyId);
1324    
1325                                    if (name != null) {
1326                                            qPos.add(name);
1327                                    }
1328    
1329                                    List<Role> list = q.list();
1330    
1331                                    result = list;
1332    
1333                                    Role role = null;
1334    
1335                                    if (list.isEmpty()) {
1336                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1337                                                    finderArgs, list);
1338                                    }
1339                                    else {
1340                                            role = list.get(0);
1341    
1342                                            cacheResult(role);
1343    
1344                                            if ((role.getCompanyId() != companyId) ||
1345                                                            (role.getName() == null) ||
1346                                                            !role.getName().equals(name)) {
1347                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1348                                                            finderArgs, role);
1349                                            }
1350                                    }
1351    
1352                                    return role;
1353                            }
1354                            catch (Exception e) {
1355                                    throw processException(e);
1356                            }
1357                            finally {
1358                                    if (result == null) {
1359                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1360                                                    finderArgs, new ArrayList<Role>());
1361                                    }
1362    
1363                                    closeSession(session);
1364                            }
1365                    }
1366                    else {
1367                            if (result instanceof List<?>) {
1368                                    return null;
1369                            }
1370                            else {
1371                                    return (Role)result;
1372                            }
1373                    }
1374            }
1375    
1376            /**
1377             * Finds all the roles where type = &#63; and subtype = &#63;.
1378             *
1379             * @param type the type to search with
1380             * @param subtype the subtype to search with
1381             * @return the matching roles
1382             * @throws SystemException if a system exception occurred
1383             */
1384            public List<Role> findByT_S(int type, String subtype)
1385                    throws SystemException {
1386                    return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1387                            null);
1388            }
1389    
1390            /**
1391             * Finds a range of all the roles where type = &#63; and subtype = &#63;.
1392             *
1393             * <p>
1394             * 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.
1395             * </p>
1396             *
1397             * @param type the type to search with
1398             * @param subtype the subtype to search with
1399             * @param start the lower bound of the range of roles to return
1400             * @param end the upper bound of the range of roles to return (not inclusive)
1401             * @return the range of matching roles
1402             * @throws SystemException if a system exception occurred
1403             */
1404            public List<Role> findByT_S(int type, String subtype, int start, int end)
1405                    throws SystemException {
1406                    return findByT_S(type, subtype, start, end, null);
1407            }
1408    
1409            /**
1410             * Finds an ordered range of all the roles where type = &#63; and subtype = &#63;.
1411             *
1412             * <p>
1413             * 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.
1414             * </p>
1415             *
1416             * @param type the type to search with
1417             * @param subtype the subtype to search with
1418             * @param start the lower bound of the range of roles to return
1419             * @param end the upper bound of the range of roles to return (not inclusive)
1420             * @param orderByComparator the comparator to order the results by
1421             * @return the ordered range of matching roles
1422             * @throws SystemException if a system exception occurred
1423             */
1424            public List<Role> findByT_S(int type, String subtype, int start, int end,
1425                    OrderByComparator orderByComparator) throws SystemException {
1426                    Object[] finderArgs = new Object[] {
1427                                    type, subtype,
1428                                    
1429                                    String.valueOf(start), String.valueOf(end),
1430                                    String.valueOf(orderByComparator)
1431                            };
1432    
1433                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_S,
1434                                    finderArgs, this);
1435    
1436                    if (list == null) {
1437                            Session session = null;
1438    
1439                            try {
1440                                    session = openSession();
1441    
1442                                    StringBundler query = null;
1443    
1444                                    if (orderByComparator != null) {
1445                                            query = new StringBundler(4 +
1446                                                            (orderByComparator.getOrderByFields().length * 3));
1447                                    }
1448                                    else {
1449                                            query = new StringBundler(4);
1450                                    }
1451    
1452                                    query.append(_SQL_SELECT_ROLE_WHERE);
1453    
1454                                    query.append(_FINDER_COLUMN_T_S_TYPE_2);
1455    
1456                                    if (subtype == null) {
1457                                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
1458                                    }
1459                                    else {
1460                                            if (subtype.equals(StringPool.BLANK)) {
1461                                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
1462                                            }
1463                                            else {
1464                                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
1465                                            }
1466                                    }
1467    
1468                                    if (orderByComparator != null) {
1469                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1470                                                    orderByComparator);
1471                                    }
1472    
1473                                    else {
1474                                            query.append(RoleModelImpl.ORDER_BY_JPQL);
1475                                    }
1476    
1477                                    String sql = query.toString();
1478    
1479                                    Query q = session.createQuery(sql);
1480    
1481                                    QueryPos qPos = QueryPos.getInstance(q);
1482    
1483                                    qPos.add(type);
1484    
1485                                    if (subtype != null) {
1486                                            qPos.add(subtype);
1487                                    }
1488    
1489                                    list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1490                            }
1491                            catch (Exception e) {
1492                                    throw processException(e);
1493                            }
1494                            finally {
1495                                    if (list == null) {
1496                                            list = new ArrayList<Role>();
1497                                    }
1498    
1499                                    cacheResult(list);
1500    
1501                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_S, finderArgs,
1502                                            list);
1503    
1504                                    closeSession(session);
1505                            }
1506                    }
1507    
1508                    return list;
1509            }
1510    
1511            /**
1512             * Finds the first role in the ordered set where type = &#63; and subtype = &#63;.
1513             *
1514             * <p>
1515             * 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.
1516             * </p>
1517             *
1518             * @param type the type to search with
1519             * @param subtype the subtype to search with
1520             * @param orderByComparator the comparator to order the set by
1521             * @return the first matching role
1522             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1523             * @throws SystemException if a system exception occurred
1524             */
1525            public Role findByT_S_First(int type, String subtype,
1526                    OrderByComparator orderByComparator)
1527                    throws NoSuchRoleException, SystemException {
1528                    List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
1529    
1530                    if (list.isEmpty()) {
1531                            StringBundler msg = new StringBundler(6);
1532    
1533                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1534    
1535                            msg.append("type=");
1536                            msg.append(type);
1537    
1538                            msg.append(", subtype=");
1539                            msg.append(subtype);
1540    
1541                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1542    
1543                            throw new NoSuchRoleException(msg.toString());
1544                    }
1545                    else {
1546                            return list.get(0);
1547                    }
1548            }
1549    
1550            /**
1551             * Finds the last role in the ordered set where type = &#63; and subtype = &#63;.
1552             *
1553             * <p>
1554             * 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.
1555             * </p>
1556             *
1557             * @param type the type to search with
1558             * @param subtype the subtype to search with
1559             * @param orderByComparator the comparator to order the set by
1560             * @return the last matching role
1561             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1562             * @throws SystemException if a system exception occurred
1563             */
1564            public Role findByT_S_Last(int type, String subtype,
1565                    OrderByComparator orderByComparator)
1566                    throws NoSuchRoleException, SystemException {
1567                    int count = countByT_S(type, subtype);
1568    
1569                    List<Role> list = findByT_S(type, subtype, count - 1, count,
1570                                    orderByComparator);
1571    
1572                    if (list.isEmpty()) {
1573                            StringBundler msg = new StringBundler(6);
1574    
1575                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1576    
1577                            msg.append("type=");
1578                            msg.append(type);
1579    
1580                            msg.append(", subtype=");
1581                            msg.append(subtype);
1582    
1583                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1584    
1585                            throw new NoSuchRoleException(msg.toString());
1586                    }
1587                    else {
1588                            return list.get(0);
1589                    }
1590            }
1591    
1592            /**
1593             * Finds the roles before and after the current role in the ordered set where type = &#63; and subtype = &#63;.
1594             *
1595             * <p>
1596             * 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.
1597             * </p>
1598             *
1599             * @param roleId the primary key of the current role
1600             * @param type the type to search with
1601             * @param subtype the subtype to search with
1602             * @param orderByComparator the comparator to order the set by
1603             * @return the previous, current, and next role
1604             * @throws com.liferay.portal.NoSuchRoleException if a role with the primary key could not be found
1605             * @throws SystemException if a system exception occurred
1606             */
1607            public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
1608                    OrderByComparator orderByComparator)
1609                    throws NoSuchRoleException, SystemException {
1610                    Role role = findByPrimaryKey(roleId);
1611    
1612                    Session session = null;
1613    
1614                    try {
1615                            session = openSession();
1616    
1617                            Role[] array = new RoleImpl[3];
1618    
1619                            array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
1620                                            orderByComparator, true);
1621    
1622                            array[1] = role;
1623    
1624                            array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
1625                                            orderByComparator, false);
1626    
1627                            return array;
1628                    }
1629                    catch (Exception e) {
1630                            throw processException(e);
1631                    }
1632                    finally {
1633                            closeSession(session);
1634                    }
1635            }
1636    
1637            protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
1638                    String subtype, OrderByComparator orderByComparator, boolean previous) {
1639                    StringBundler query = null;
1640    
1641                    if (orderByComparator != null) {
1642                            query = new StringBundler(6 +
1643                                            (orderByComparator.getOrderByFields().length * 6));
1644                    }
1645                    else {
1646                            query = new StringBundler(3);
1647                    }
1648    
1649                    query.append(_SQL_SELECT_ROLE_WHERE);
1650    
1651                    query.append(_FINDER_COLUMN_T_S_TYPE_2);
1652    
1653                    if (subtype == null) {
1654                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
1655                    }
1656                    else {
1657                            if (subtype.equals(StringPool.BLANK)) {
1658                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
1659                            }
1660                            else {
1661                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
1662                            }
1663                    }
1664    
1665                    if (orderByComparator != null) {
1666                            String[] orderByFields = orderByComparator.getOrderByFields();
1667    
1668                            if (orderByFields.length > 0) {
1669                                    query.append(WHERE_AND);
1670                            }
1671    
1672                            for (int i = 0; i < orderByFields.length; i++) {
1673                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1674                                    query.append(orderByFields[i]);
1675    
1676                                    if ((i + 1) < orderByFields.length) {
1677                                            if (orderByComparator.isAscending() ^ previous) {
1678                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1679                                            }
1680                                            else {
1681                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1682                                            }
1683                                    }
1684                                    else {
1685                                            if (orderByComparator.isAscending() ^ previous) {
1686                                                    query.append(WHERE_GREATER_THAN);
1687                                            }
1688                                            else {
1689                                                    query.append(WHERE_LESSER_THAN);
1690                                            }
1691                                    }
1692                            }
1693    
1694                            query.append(ORDER_BY_CLAUSE);
1695    
1696                            for (int i = 0; i < orderByFields.length; i++) {
1697                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1698                                    query.append(orderByFields[i]);
1699    
1700                                    if ((i + 1) < orderByFields.length) {
1701                                            if (orderByComparator.isAscending() ^ previous) {
1702                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1703                                            }
1704                                            else {
1705                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1706                                            }
1707                                    }
1708                                    else {
1709                                            if (orderByComparator.isAscending() ^ previous) {
1710                                                    query.append(ORDER_BY_ASC);
1711                                            }
1712                                            else {
1713                                                    query.append(ORDER_BY_DESC);
1714                                            }
1715                                    }
1716                            }
1717                    }
1718    
1719                    else {
1720                            query.append(RoleModelImpl.ORDER_BY_JPQL);
1721                    }
1722    
1723                    String sql = query.toString();
1724    
1725                    Query q = session.createQuery(sql);
1726    
1727                    q.setFirstResult(0);
1728                    q.setMaxResults(2);
1729    
1730                    QueryPos qPos = QueryPos.getInstance(q);
1731    
1732                    qPos.add(type);
1733    
1734                    if (subtype != null) {
1735                            qPos.add(subtype);
1736                    }
1737    
1738                    if (orderByComparator != null) {
1739                            Object[] values = orderByComparator.getOrderByValues(role);
1740    
1741                            for (Object value : values) {
1742                                    qPos.add(value);
1743                            }
1744                    }
1745    
1746                    List<Role> list = q.list();
1747    
1748                    if (list.size() == 2) {
1749                            return list.get(1);
1750                    }
1751                    else {
1752                            return null;
1753                    }
1754            }
1755    
1756            /**
1757             * Finds 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.
1758             *
1759             * @param companyId the company id to search with
1760             * @param classNameId the class name id to search with
1761             * @param classPK the class p k to search with
1762             * @return the matching role
1763             * @throws com.liferay.portal.NoSuchRoleException if a matching role could not be found
1764             * @throws SystemException if a system exception occurred
1765             */
1766            public Role findByC_C_C(long companyId, long classNameId, long classPK)
1767                    throws NoSuchRoleException, SystemException {
1768                    Role role = fetchByC_C_C(companyId, classNameId, classPK);
1769    
1770                    if (role == null) {
1771                            StringBundler msg = new StringBundler(8);
1772    
1773                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1774    
1775                            msg.append("companyId=");
1776                            msg.append(companyId);
1777    
1778                            msg.append(", classNameId=");
1779                            msg.append(classNameId);
1780    
1781                            msg.append(", classPK=");
1782                            msg.append(classPK);
1783    
1784                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1785    
1786                            if (_log.isWarnEnabled()) {
1787                                    _log.warn(msg.toString());
1788                            }
1789    
1790                            throw new NoSuchRoleException(msg.toString());
1791                    }
1792    
1793                    return role;
1794            }
1795    
1796            /**
1797             * Finds 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.
1798             *
1799             * @param companyId the company id to search with
1800             * @param classNameId the class name id to search with
1801             * @param classPK the class p k to search with
1802             * @return the matching role, or <code>null</code> if a matching role could not be found
1803             * @throws SystemException if a system exception occurred
1804             */
1805            public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
1806                    throws SystemException {
1807                    return fetchByC_C_C(companyId, classNameId, classPK, true);
1808            }
1809    
1810            /**
1811             * Finds 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.
1812             *
1813             * @param companyId the company id to search with
1814             * @param classNameId the class name id to search with
1815             * @param classPK the class p k to search with
1816             * @return the matching role, or <code>null</code> if a matching role could not be found
1817             * @throws SystemException if a system exception occurred
1818             */
1819            public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
1820                    boolean retrieveFromCache) throws SystemException {
1821                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
1822    
1823                    Object result = null;
1824    
1825                    if (retrieveFromCache) {
1826                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
1827                                            finderArgs, this);
1828                    }
1829    
1830                    if (result == null) {
1831                            Session session = null;
1832    
1833                            try {
1834                                    session = openSession();
1835    
1836                                    StringBundler query = new StringBundler(5);
1837    
1838                                    query.append(_SQL_SELECT_ROLE_WHERE);
1839    
1840                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
1841    
1842                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
1843    
1844                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
1845    
1846                                    query.append(RoleModelImpl.ORDER_BY_JPQL);
1847    
1848                                    String sql = query.toString();
1849    
1850                                    Query q = session.createQuery(sql);
1851    
1852                                    QueryPos qPos = QueryPos.getInstance(q);
1853    
1854                                    qPos.add(companyId);
1855    
1856                                    qPos.add(classNameId);
1857    
1858                                    qPos.add(classPK);
1859    
1860                                    List<Role> list = q.list();
1861    
1862                                    result = list;
1863    
1864                                    Role role = null;
1865    
1866                                    if (list.isEmpty()) {
1867                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1868                                                    finderArgs, list);
1869                                    }
1870                                    else {
1871                                            role = list.get(0);
1872    
1873                                            cacheResult(role);
1874    
1875                                            if ((role.getCompanyId() != companyId) ||
1876                                                            (role.getClassNameId() != classNameId) ||
1877                                                            (role.getClassPK() != classPK)) {
1878                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1879                                                            finderArgs, role);
1880                                            }
1881                                    }
1882    
1883                                    return role;
1884                            }
1885                            catch (Exception e) {
1886                                    throw processException(e);
1887                            }
1888                            finally {
1889                                    if (result == null) {
1890                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
1891                                                    finderArgs, new ArrayList<Role>());
1892                                    }
1893    
1894                                    closeSession(session);
1895                            }
1896                    }
1897                    else {
1898                            if (result instanceof List<?>) {
1899                                    return null;
1900                            }
1901                            else {
1902                                    return (Role)result;
1903                            }
1904                    }
1905            }
1906    
1907            /**
1908             * Finds all the roles.
1909             *
1910             * @return the roles
1911             * @throws SystemException if a system exception occurred
1912             */
1913            public List<Role> findAll() throws SystemException {
1914                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1915            }
1916    
1917            /**
1918             * Finds a range of all the roles.
1919             *
1920             * <p>
1921             * 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.
1922             * </p>
1923             *
1924             * @param start the lower bound of the range of roles to return
1925             * @param end the upper bound of the range of roles to return (not inclusive)
1926             * @return the range of roles
1927             * @throws SystemException if a system exception occurred
1928             */
1929            public List<Role> findAll(int start, int end) throws SystemException {
1930                    return findAll(start, end, null);
1931            }
1932    
1933            /**
1934             * Finds an ordered range of all the roles.
1935             *
1936             * <p>
1937             * 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.
1938             * </p>
1939             *
1940             * @param start the lower bound of the range of roles to return
1941             * @param end the upper bound of the range of roles to return (not inclusive)
1942             * @param orderByComparator the comparator to order the results by
1943             * @return the ordered range of roles
1944             * @throws SystemException if a system exception occurred
1945             */
1946            public List<Role> findAll(int start, int end,
1947                    OrderByComparator orderByComparator) throws SystemException {
1948                    Object[] finderArgs = new Object[] {
1949                                    String.valueOf(start), String.valueOf(end),
1950                                    String.valueOf(orderByComparator)
1951                            };
1952    
1953                    List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1954                                    finderArgs, this);
1955    
1956                    if (list == null) {
1957                            Session session = null;
1958    
1959                            try {
1960                                    session = openSession();
1961    
1962                                    StringBundler query = null;
1963                                    String sql = null;
1964    
1965                                    if (orderByComparator != null) {
1966                                            query = new StringBundler(2 +
1967                                                            (orderByComparator.getOrderByFields().length * 3));
1968    
1969                                            query.append(_SQL_SELECT_ROLE);
1970    
1971                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1972                                                    orderByComparator);
1973    
1974                                            sql = query.toString();
1975                                    }
1976                                    else {
1977                                            sql = _SQL_SELECT_ROLE.concat(RoleModelImpl.ORDER_BY_JPQL);
1978                                    }
1979    
1980                                    Query q = session.createQuery(sql);
1981    
1982                                    if (orderByComparator == null) {
1983                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1984                                                            end, false);
1985    
1986                                            Collections.sort(list);
1987                                    }
1988                                    else {
1989                                            list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1990                                                            end);
1991                                    }
1992                            }
1993                            catch (Exception e) {
1994                                    throw processException(e);
1995                            }
1996                            finally {
1997                                    if (list == null) {
1998                                            list = new ArrayList<Role>();
1999                                    }
2000    
2001                                    cacheResult(list);
2002    
2003                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2004    
2005                                    closeSession(session);
2006                            }
2007                    }
2008    
2009                    return list;
2010            }
2011    
2012            /**
2013             * Removes all the roles where companyId = &#63; from the database.
2014             *
2015             * @param companyId the company id to search with
2016             * @throws SystemException if a system exception occurred
2017             */
2018            public void removeByCompanyId(long companyId) throws SystemException {
2019                    for (Role role : findByCompanyId(companyId)) {
2020                            remove(role);
2021                    }
2022            }
2023    
2024            /**
2025             * Removes all the roles where subtype = &#63; from the database.
2026             *
2027             * @param subtype the subtype to search with
2028             * @throws SystemException if a system exception occurred
2029             */
2030            public void removeBySubtype(String subtype) throws SystemException {
2031                    for (Role role : findBySubtype(subtype)) {
2032                            remove(role);
2033                    }
2034            }
2035    
2036            /**
2037             * Removes the role where companyId = &#63; and name = &#63; from the database.
2038             *
2039             * @param companyId the company id to search with
2040             * @param name the name to search with
2041             * @throws SystemException if a system exception occurred
2042             */
2043            public void removeByC_N(long companyId, String name)
2044                    throws NoSuchRoleException, SystemException {
2045                    Role role = findByC_N(companyId, name);
2046    
2047                    remove(role);
2048            }
2049    
2050            /**
2051             * Removes all the roles where type = &#63; and subtype = &#63; from the database.
2052             *
2053             * @param type the type to search with
2054             * @param subtype the subtype to search with
2055             * @throws SystemException if a system exception occurred
2056             */
2057            public void removeByT_S(int type, String subtype) throws SystemException {
2058                    for (Role role : findByT_S(type, subtype)) {
2059                            remove(role);
2060                    }
2061            }
2062    
2063            /**
2064             * Removes the role where companyId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
2065             *
2066             * @param companyId the company id to search with
2067             * @param classNameId the class name id to search with
2068             * @param classPK the class p k to search with
2069             * @throws SystemException if a system exception occurred
2070             */
2071            public void removeByC_C_C(long companyId, long classNameId, long classPK)
2072                    throws NoSuchRoleException, SystemException {
2073                    Role role = findByC_C_C(companyId, classNameId, classPK);
2074    
2075                    remove(role);
2076            }
2077    
2078            /**
2079             * Removes all the roles from the database.
2080             *
2081             * @throws SystemException if a system exception occurred
2082             */
2083            public void removeAll() throws SystemException {
2084                    for (Role role : findAll()) {
2085                            remove(role);
2086                    }
2087            }
2088    
2089            /**
2090             * Counts all the roles where companyId = &#63;.
2091             *
2092             * @param companyId the company id to search with
2093             * @return the number of matching roles
2094             * @throws SystemException if a system exception occurred
2095             */
2096            public int countByCompanyId(long companyId) throws SystemException {
2097                    Object[] finderArgs = new Object[] { companyId };
2098    
2099                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2100                                    finderArgs, this);
2101    
2102                    if (count == null) {
2103                            Session session = null;
2104    
2105                            try {
2106                                    session = openSession();
2107    
2108                                    StringBundler query = new StringBundler(2);
2109    
2110                                    query.append(_SQL_COUNT_ROLE_WHERE);
2111    
2112                                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2113    
2114                                    String sql = query.toString();
2115    
2116                                    Query q = session.createQuery(sql);
2117    
2118                                    QueryPos qPos = QueryPos.getInstance(q);
2119    
2120                                    qPos.add(companyId);
2121    
2122                                    count = (Long)q.uniqueResult();
2123                            }
2124                            catch (Exception e) {
2125                                    throw processException(e);
2126                            }
2127                            finally {
2128                                    if (count == null) {
2129                                            count = Long.valueOf(0);
2130                                    }
2131    
2132                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2133                                            finderArgs, count);
2134    
2135                                    closeSession(session);
2136                            }
2137                    }
2138    
2139                    return count.intValue();
2140            }
2141    
2142            /**
2143             * Counts all the roles where subtype = &#63;.
2144             *
2145             * @param subtype the subtype to search with
2146             * @return the number of matching roles
2147             * @throws SystemException if a system exception occurred
2148             */
2149            public int countBySubtype(String subtype) throws SystemException {
2150                    Object[] finderArgs = new Object[] { subtype };
2151    
2152                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SUBTYPE,
2153                                    finderArgs, this);
2154    
2155                    if (count == null) {
2156                            Session session = null;
2157    
2158                            try {
2159                                    session = openSession();
2160    
2161                                    StringBundler query = new StringBundler(2);
2162    
2163                                    query.append(_SQL_COUNT_ROLE_WHERE);
2164    
2165                                    if (subtype == null) {
2166                                            query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2167                                    }
2168                                    else {
2169                                            if (subtype.equals(StringPool.BLANK)) {
2170                                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2171                                            }
2172                                            else {
2173                                                    query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2174                                            }
2175                                    }
2176    
2177                                    String sql = query.toString();
2178    
2179                                    Query q = session.createQuery(sql);
2180    
2181                                    QueryPos qPos = QueryPos.getInstance(q);
2182    
2183                                    if (subtype != null) {
2184                                            qPos.add(subtype);
2185                                    }
2186    
2187                                    count = (Long)q.uniqueResult();
2188                            }
2189                            catch (Exception e) {
2190                                    throw processException(e);
2191                            }
2192                            finally {
2193                                    if (count == null) {
2194                                            count = Long.valueOf(0);
2195                                    }
2196    
2197                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SUBTYPE,
2198                                            finderArgs, count);
2199    
2200                                    closeSession(session);
2201                            }
2202                    }
2203    
2204                    return count.intValue();
2205            }
2206    
2207            /**
2208             * Counts all the roles where companyId = &#63; and name = &#63;.
2209             *
2210             * @param companyId the company id to search with
2211             * @param name the name to search with
2212             * @return the number of matching roles
2213             * @throws SystemException if a system exception occurred
2214             */
2215            public int countByC_N(long companyId, String name)
2216                    throws SystemException {
2217                    Object[] finderArgs = new Object[] { companyId, name };
2218    
2219                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
2220                                    finderArgs, this);
2221    
2222                    if (count == null) {
2223                            Session session = null;
2224    
2225                            try {
2226                                    session = openSession();
2227    
2228                                    StringBundler query = new StringBundler(3);
2229    
2230                                    query.append(_SQL_COUNT_ROLE_WHERE);
2231    
2232                                    query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2233    
2234                                    if (name == null) {
2235                                            query.append(_FINDER_COLUMN_C_N_NAME_1);
2236                                    }
2237                                    else {
2238                                            if (name.equals(StringPool.BLANK)) {
2239                                                    query.append(_FINDER_COLUMN_C_N_NAME_3);
2240                                            }
2241                                            else {
2242                                                    query.append(_FINDER_COLUMN_C_N_NAME_2);
2243                                            }
2244                                    }
2245    
2246                                    String sql = query.toString();
2247    
2248                                    Query q = session.createQuery(sql);
2249    
2250                                    QueryPos qPos = QueryPos.getInstance(q);
2251    
2252                                    qPos.add(companyId);
2253    
2254                                    if (name != null) {
2255                                            qPos.add(name);
2256                                    }
2257    
2258                                    count = (Long)q.uniqueResult();
2259                            }
2260                            catch (Exception e) {
2261                                    throw processException(e);
2262                            }
2263                            finally {
2264                                    if (count == null) {
2265                                            count = Long.valueOf(0);
2266                                    }
2267    
2268                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
2269                                            count);
2270    
2271                                    closeSession(session);
2272                            }
2273                    }
2274    
2275                    return count.intValue();
2276            }
2277    
2278            /**
2279             * Counts all the roles where type = &#63; and subtype = &#63;.
2280             *
2281             * @param type the type to search with
2282             * @param subtype the subtype to search with
2283             * @return the number of matching roles
2284             * @throws SystemException if a system exception occurred
2285             */
2286            public int countByT_S(int type, String subtype) throws SystemException {
2287                    Object[] finderArgs = new Object[] { type, subtype };
2288    
2289                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
2290                                    finderArgs, this);
2291    
2292                    if (count == null) {
2293                            Session session = null;
2294    
2295                            try {
2296                                    session = openSession();
2297    
2298                                    StringBundler query = new StringBundler(3);
2299    
2300                                    query.append(_SQL_COUNT_ROLE_WHERE);
2301    
2302                                    query.append(_FINDER_COLUMN_T_S_TYPE_2);
2303    
2304                                    if (subtype == null) {
2305                                            query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
2306                                    }
2307                                    else {
2308                                            if (subtype.equals(StringPool.BLANK)) {
2309                                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
2310                                            }
2311                                            else {
2312                                                    query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
2313                                            }
2314                                    }
2315    
2316                                    String sql = query.toString();
2317    
2318                                    Query q = session.createQuery(sql);
2319    
2320                                    QueryPos qPos = QueryPos.getInstance(q);
2321    
2322                                    qPos.add(type);
2323    
2324                                    if (subtype != null) {
2325                                            qPos.add(subtype);
2326                                    }
2327    
2328                                    count = (Long)q.uniqueResult();
2329                            }
2330                            catch (Exception e) {
2331                                    throw processException(e);
2332                            }
2333                            finally {
2334                                    if (count == null) {
2335                                            count = Long.valueOf(0);
2336                                    }
2337    
2338                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
2339                                            count);
2340    
2341                                    closeSession(session);
2342                            }
2343                    }
2344    
2345                    return count.intValue();
2346            }
2347    
2348            /**
2349             * Counts all the roles where companyId = &#63; and classNameId = &#63; and classPK = &#63;.
2350             *
2351             * @param companyId the company id to search with
2352             * @param classNameId the class name id to search with
2353             * @param classPK the class p k to search with
2354             * @return the number of matching roles
2355             * @throws SystemException if a system exception occurred
2356             */
2357            public int countByC_C_C(long companyId, long classNameId, long classPK)
2358                    throws SystemException {
2359                    Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2360    
2361                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2362                                    finderArgs, this);
2363    
2364                    if (count == null) {
2365                            Session session = null;
2366    
2367                            try {
2368                                    session = openSession();
2369    
2370                                    StringBundler query = new StringBundler(4);
2371    
2372                                    query.append(_SQL_COUNT_ROLE_WHERE);
2373    
2374                                    query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2375    
2376                                    query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2377    
2378                                    query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2379    
2380                                    String sql = query.toString();
2381    
2382                                    Query q = session.createQuery(sql);
2383    
2384                                    QueryPos qPos = QueryPos.getInstance(q);
2385    
2386                                    qPos.add(companyId);
2387    
2388                                    qPos.add(classNameId);
2389    
2390                                    qPos.add(classPK);
2391    
2392                                    count = (Long)q.uniqueResult();
2393                            }
2394                            catch (Exception e) {
2395                                    throw processException(e);
2396                            }
2397                            finally {
2398                                    if (count == null) {
2399                                            count = Long.valueOf(0);
2400                                    }
2401    
2402                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2403                                            finderArgs, count);
2404    
2405                                    closeSession(session);
2406                            }
2407                    }
2408    
2409                    return count.intValue();
2410            }
2411    
2412            /**
2413             * Counts all the roles.
2414             *
2415             * @return the number of roles
2416             * @throws SystemException if a system exception occurred
2417             */
2418            public int countAll() throws SystemException {
2419                    Object[] finderArgs = new Object[0];
2420    
2421                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2422                                    finderArgs, this);
2423    
2424                    if (count == null) {
2425                            Session session = null;
2426    
2427                            try {
2428                                    session = openSession();
2429    
2430                                    Query q = session.createQuery(_SQL_COUNT_ROLE);
2431    
2432                                    count = (Long)q.uniqueResult();
2433                            }
2434                            catch (Exception e) {
2435                                    throw processException(e);
2436                            }
2437                            finally {
2438                                    if (count == null) {
2439                                            count = Long.valueOf(0);
2440                                    }
2441    
2442                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2443                                            count);
2444    
2445                                    closeSession(session);
2446                            }
2447                    }
2448    
2449                    return count.intValue();
2450            }
2451    
2452            /**
2453             * Gets all the groups associated with the role.
2454             *
2455             * @param pk the primary key of the role to get the associated groups for
2456             * @return the groups associated with the role
2457             * @throws SystemException if a system exception occurred
2458             */
2459            public List<com.liferay.portal.model.Group> getGroups(long pk)
2460                    throws SystemException {
2461                    return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2462            }
2463    
2464            /**
2465             * Gets a range of all the groups associated with the role.
2466             *
2467             * <p>
2468             * 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.
2469             * </p>
2470             *
2471             * @param pk the primary key of the role to get the associated groups for
2472             * @param start the lower bound of the range of roles to return
2473             * @param end the upper bound of the range of roles to return (not inclusive)
2474             * @return the range of groups associated with the role
2475             * @throws SystemException if a system exception occurred
2476             */
2477            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2478                    int end) throws SystemException {
2479                    return getGroups(pk, start, end, null);
2480            }
2481    
2482            public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2483                            RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
2484                            RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroups",
2485                            new String[] {
2486                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2487                                    "com.liferay.portal.kernel.util.OrderByComparator"
2488                            });
2489    
2490            /**
2491             * Gets an ordered range of all the groups associated with the role.
2492             *
2493             * <p>
2494             * 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.
2495             * </p>
2496             *
2497             * @param pk the primary key of the role to get the associated groups for
2498             * @param start the lower bound of the range of roles to return
2499             * @param end the upper bound of the range of roles to return (not inclusive)
2500             * @param orderByComparator the comparator to order the results by
2501             * @return the ordered range of groups associated with the role
2502             * @throws SystemException if a system exception occurred
2503             */
2504            public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
2505                    int end, OrderByComparator orderByComparator) throws SystemException {
2506                    Object[] finderArgs = new Object[] {
2507                                    pk, String.valueOf(start), String.valueOf(end),
2508                                    String.valueOf(orderByComparator)
2509                            };
2510    
2511                    List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
2512                                    finderArgs, this);
2513    
2514                    if (list == null) {
2515                            Session session = null;
2516    
2517                            try {
2518                                    session = openSession();
2519    
2520                                    String sql = null;
2521    
2522                                    if (orderByComparator != null) {
2523                                            sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
2524                                                                                    .concat(orderByComparator.getOrderBy());
2525                                    }
2526                                    else {
2527                                            sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
2528                                    }
2529    
2530                                    SQLQuery q = session.createSQLQuery(sql);
2531    
2532                                    q.addEntity("Group_",
2533                                            com.liferay.portal.model.impl.GroupImpl.class);
2534    
2535                                    QueryPos qPos = QueryPos.getInstance(q);
2536    
2537                                    qPos.add(pk);
2538    
2539                                    list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
2540                                                    getDialect(), start, end);
2541                            }
2542                            catch (Exception e) {
2543                                    throw processException(e);
2544                            }
2545                            finally {
2546                                    if (list == null) {
2547                                            list = new ArrayList<com.liferay.portal.model.Group>();
2548                                    }
2549    
2550                                    groupPersistence.cacheResult(list);
2551    
2552                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
2553                                            list);
2554    
2555                                    closeSession(session);
2556                            }
2557                    }
2558    
2559                    return list;
2560            }
2561    
2562            public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2563                            RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
2564                            RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroupsSize",
2565                            new String[] { Long.class.getName() });
2566    
2567            /**
2568             * Gets the number of groups associated with the role.
2569             *
2570             * @param pk the primary key of the role to get the number of associated groups for
2571             * @return the number of groups associated with the role
2572             * @throws SystemException if a system exception occurred
2573             */
2574            public int getGroupsSize(long pk) throws SystemException {
2575                    Object[] finderArgs = new Object[] { pk };
2576    
2577                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
2578                                    finderArgs, this);
2579    
2580                    if (count == null) {
2581                            Session session = null;
2582    
2583                            try {
2584                                    session = openSession();
2585    
2586                                    SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
2587    
2588                                    q.addScalar(COUNT_COLUMN_NAME,
2589                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
2590    
2591                                    QueryPos qPos = QueryPos.getInstance(q);
2592    
2593                                    qPos.add(pk);
2594    
2595                                    count = (Long)q.uniqueResult();
2596                            }
2597                            catch (Exception e) {
2598                                    throw processException(e);
2599                            }
2600                            finally {
2601                                    if (count == null) {
2602                                            count = Long.valueOf(0);
2603                                    }
2604    
2605                                    FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
2606                                            finderArgs, count);
2607    
2608                                    closeSession(session);
2609                            }
2610                    }
2611    
2612                    return count.intValue();
2613            }
2614    
2615            public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
2616                            RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
2617                            RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "containsGroup",
2618                            new String[] { Long.class.getName(), Long.class.getName() });
2619    
2620            /**
2621             * Determines whether the group is associated with the role.
2622             *
2623             * @param pk the primary key of the role
2624             * @param groupPK the primary key of the group
2625             * @return whether the group is associated with the role
2626             * @throws SystemException if a system exception occurred
2627             */
2628            public boolean containsGroup(long pk, long groupPK)
2629                    throws SystemException {
2630                    Object[] finderArgs = new Object[] { pk, groupPK };
2631    
2632                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
2633                                    finderArgs, this);
2634    
2635                    if (value == null) {
2636                            try {
2637                                    value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
2638                            }
2639                            catch (Exception e) {
2640                                    throw processException(e);
2641                            }
2642                            finally {
2643                                    if (value == null) {
2644                                            value = Boolean.FALSE;
2645                                    }
2646    
2647                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
2648                                            finderArgs, value);
2649                            }
2650                    }
2651    
2652                    return value.booleanValue();
2653            }
2654    
2655            /**
2656             * Determines whether the role has any groups associated with it.
2657             *
2658             * @param pk the primary key of the role to check for associations with groups
2659             * @return whether the role has any groups associated with it
2660             * @throws SystemException if a system exception occurred
2661             */
2662            public boolean containsGroups(long pk) throws SystemException {
2663                    if (getGroupsSize(pk) > 0) {
2664                            return true;
2665                    }
2666                    else {
2667                            return false;
2668                    }
2669            }
2670    
2671            /**
2672             * Adds an association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2673             *
2674             * @param pk the primary key of the role
2675             * @param groupPK the primary key of the group
2676             * @throws SystemException if a system exception occurred
2677             */
2678            public void addGroup(long pk, long groupPK) throws SystemException {
2679                    try {
2680                            addGroup.add(pk, groupPK);
2681                    }
2682                    catch (Exception e) {
2683                            throw processException(e);
2684                    }
2685                    finally {
2686                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2687                    }
2688            }
2689    
2690            /**
2691             * Adds an association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2692             *
2693             * @param pk the primary key of the role
2694             * @param group the group
2695             * @throws SystemException if a system exception occurred
2696             */
2697            public void addGroup(long pk, com.liferay.portal.model.Group group)
2698                    throws SystemException {
2699                    try {
2700                            addGroup.add(pk, group.getPrimaryKey());
2701                    }
2702                    catch (Exception e) {
2703                            throw processException(e);
2704                    }
2705                    finally {
2706                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2707                    }
2708            }
2709    
2710            /**
2711             * Adds an association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2712             *
2713             * @param pk the primary key of the role
2714             * @param groupPKs the primary keys of the groups
2715             * @throws SystemException if a system exception occurred
2716             */
2717            public void addGroups(long pk, long[] groupPKs) throws SystemException {
2718                    try {
2719                            for (long groupPK : groupPKs) {
2720                                    addGroup.add(pk, groupPK);
2721                            }
2722                    }
2723                    catch (Exception e) {
2724                            throw processException(e);
2725                    }
2726                    finally {
2727                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2728                    }
2729            }
2730    
2731            /**
2732             * Adds an association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2733             *
2734             * @param pk the primary key of the role
2735             * @param groups the groups
2736             * @throws SystemException if a system exception occurred
2737             */
2738            public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
2739                    throws SystemException {
2740                    try {
2741                            for (com.liferay.portal.model.Group group : groups) {
2742                                    addGroup.add(pk, group.getPrimaryKey());
2743                            }
2744                    }
2745                    catch (Exception e) {
2746                            throw processException(e);
2747                    }
2748                    finally {
2749                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2750                    }
2751            }
2752    
2753            /**
2754             * Clears all associations between the role and its groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2755             *
2756             * @param pk the primary key of the role to clear the associated groups from
2757             * @throws SystemException if a system exception occurred
2758             */
2759            public void clearGroups(long pk) throws SystemException {
2760                    try {
2761                            clearGroups.clear(pk);
2762                    }
2763                    catch (Exception e) {
2764                            throw processException(e);
2765                    }
2766                    finally {
2767                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2768                    }
2769            }
2770    
2771            /**
2772             * Removes the association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2773             *
2774             * @param pk the primary key of the role
2775             * @param groupPK the primary key of the group
2776             * @throws SystemException if a system exception occurred
2777             */
2778            public void removeGroup(long pk, long groupPK) throws SystemException {
2779                    try {
2780                            removeGroup.remove(pk, groupPK);
2781                    }
2782                    catch (Exception e) {
2783                            throw processException(e);
2784                    }
2785                    finally {
2786                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2787                    }
2788            }
2789    
2790            /**
2791             * Removes the association between the role and the group. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2792             *
2793             * @param pk the primary key of the role
2794             * @param group the group
2795             * @throws SystemException if a system exception occurred
2796             */
2797            public void removeGroup(long pk, com.liferay.portal.model.Group group)
2798                    throws SystemException {
2799                    try {
2800                            removeGroup.remove(pk, group.getPrimaryKey());
2801                    }
2802                    catch (Exception e) {
2803                            throw processException(e);
2804                    }
2805                    finally {
2806                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2807                    }
2808            }
2809    
2810            /**
2811             * Removes the association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2812             *
2813             * @param pk the primary key of the role
2814             * @param groupPKs the primary keys of the groups
2815             * @throws SystemException if a system exception occurred
2816             */
2817            public void removeGroups(long pk, long[] groupPKs)
2818                    throws SystemException {
2819                    try {
2820                            for (long groupPK : groupPKs) {
2821                                    removeGroup.remove(pk, groupPK);
2822                            }
2823                    }
2824                    catch (Exception e) {
2825                            throw processException(e);
2826                    }
2827                    finally {
2828                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2829                    }
2830            }
2831    
2832            /**
2833             * Removes the association between the role and the groups. Also notifies the appropriate model listeners and clears the mapping table finder cache.
2834             *
2835             * @param pk the primary key of the role
2836             * @param groups the groups
2837             * @throws SystemException if a system exception occurred
2838             */
2839            public void removeGroups(long pk,
2840                    List<com.liferay.portal.model.Group> groups) throws SystemException {
2841                    try {
2842                            for (com.liferay.portal.model.Group group : groups) {
2843                                    removeGroup.remove(pk, group.getPrimaryKey());
2844                            }
2845                    }
2846                    catch (Exception e) {
2847                            throw processException(e);
2848                    }
2849                    finally {
2850                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2851                    }
2852            }
2853    
2854            /**
2855             * 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.
2856             *
2857             * @param pk the primary key of the role to set the associations for
2858             * @param groupPKs the primary keys of the groups to be associated with the role
2859             * @throws SystemException if a system exception occurred
2860             */
2861            public void setGroups(long pk, long[] groupPKs) throws SystemException {
2862                    try {
2863                            Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
2864    
2865                            List<com.liferay.portal.model.Group> groups = getGroups(pk);
2866    
2867                            for (com.liferay.portal.model.Group group : groups) {
2868                                    if (!groupPKSet.remove(group.getPrimaryKey())) {
2869                                            removeGroup.remove(pk, group.getPrimaryKey());
2870                                    }
2871                            }
2872    
2873                            for (Long groupPK : groupPKSet) {
2874                                    addGroup.add(pk, groupPK);
2875                            }
2876                    }
2877                    catch (Exception e) {
2878                            throw processException(e);
2879                    }
2880                    finally {
2881                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2882                    }
2883            }
2884    
2885            /**
2886             * 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.
2887             *
2888             * @param pk the primary key of the role to set the associations for
2889             * @param groups the groups to be associated with the role
2890             * @throws SystemException if a system exception occurred
2891             */
2892            public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
2893                    throws SystemException {
2894                    try {
2895                            long[] groupPKs = new long[groups.size()];
2896    
2897                            for (int i = 0; i < groups.size(); i++) {
2898                                    com.liferay.portal.model.Group group = groups.get(i);
2899    
2900                                    groupPKs[i] = group.getPrimaryKey();
2901                            }
2902    
2903                            setGroups(pk, groupPKs);
2904                    }
2905                    catch (Exception e) {
2906                            throw processException(e);
2907                    }
2908                    finally {
2909                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
2910                    }
2911            }
2912    
2913            /**
2914             * Gets all the permissions associated with the role.
2915             *
2916             * @param pk the primary key of the role to get the associated permissions for
2917             * @return the permissions associated with the role
2918             * @throws SystemException if a system exception occurred
2919             */
2920            public List<com.liferay.portal.model.Permission> getPermissions(long pk)
2921                    throws SystemException {
2922                    return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2923            }
2924    
2925            /**
2926             * Gets a range of all the permissions associated with the role.
2927             *
2928             * <p>
2929             * 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.
2930             * </p>
2931             *
2932             * @param pk the primary key of the role to get the associated permissions for
2933             * @param start the lower bound of the range of roles to return
2934             * @param end the upper bound of the range of roles to return (not inclusive)
2935             * @return the range of permissions associated with the role
2936             * @throws SystemException if a system exception occurred
2937             */
2938            public List<com.liferay.portal.model.Permission> getPermissions(long pk,
2939                    int start, int end) throws SystemException {
2940                    return getPermissions(pk, start, end, null);
2941            }
2942    
2943            public static final FinderPath FINDER_PATH_GET_PERMISSIONS = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
2944                            RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2945                            RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
2946                            "getPermissions",
2947                            new String[] {
2948                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2949                                    "com.liferay.portal.kernel.util.OrderByComparator"
2950                            });
2951    
2952            /**
2953             * Gets an ordered range of all the permissions associated with the role.
2954             *
2955             * <p>
2956             * 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.
2957             * </p>
2958             *
2959             * @param pk the primary key of the role to get the associated permissions for
2960             * @param start the lower bound of the range of roles to return
2961             * @param end the upper bound of the range of roles to return (not inclusive)
2962             * @param orderByComparator the comparator to order the results by
2963             * @return the ordered range of permissions associated with the role
2964             * @throws SystemException if a system exception occurred
2965             */
2966            public List<com.liferay.portal.model.Permission> getPermissions(long pk,
2967                    int start, int end, OrderByComparator orderByComparator)
2968                    throws SystemException {
2969                    Object[] finderArgs = new Object[] {
2970                                    pk, String.valueOf(start), String.valueOf(end),
2971                                    String.valueOf(orderByComparator)
2972                            };
2973    
2974                    List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS,
2975                                    finderArgs, this);
2976    
2977                    if (list == null) {
2978                            Session session = null;
2979    
2980                            try {
2981                                    session = openSession();
2982    
2983                                    String sql = null;
2984    
2985                                    if (orderByComparator != null) {
2986                                            sql = _SQL_GETPERMISSIONS.concat(ORDER_BY_CLAUSE)
2987                                                                                             .concat(orderByComparator.getOrderBy());
2988                                    }
2989                                    else {
2990                                            sql = _SQL_GETPERMISSIONS;
2991                                    }
2992    
2993                                    SQLQuery q = session.createSQLQuery(sql);
2994    
2995                                    q.addEntity("Permission_",
2996                                            com.liferay.portal.model.impl.PermissionImpl.class);
2997    
2998                                    QueryPos qPos = QueryPos.getInstance(q);
2999    
3000                                    qPos.add(pk);
3001    
3002                                    list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
3003                                                    getDialect(), start, end);
3004                            }
3005                            catch (Exception e) {
3006                                    throw processException(e);
3007                            }
3008                            finally {
3009                                    if (list == null) {
3010                                            list = new ArrayList<com.liferay.portal.model.Permission>();
3011                                    }
3012    
3013                                    permissionPersistence.cacheResult(list);
3014    
3015                                    FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS,
3016                                            finderArgs, list);
3017    
3018                                    closeSession(session);
3019                            }
3020                    }
3021    
3022                    return list;
3023            }
3024    
3025            public static final FinderPath FINDER_PATH_GET_PERMISSIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3026                            RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
3027                            RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
3028                            "getPermissionsSize", new String[] { Long.class.getName() });
3029    
3030            /**
3031             * Gets the number of permissions associated with the role.
3032             *
3033             * @param pk the primary key of the role to get the number of associated permissions for
3034             * @return the number of permissions associated with the role
3035             * @throws SystemException if a system exception occurred
3036             */
3037            public int getPermissionsSize(long pk) throws SystemException {
3038                    Object[] finderArgs = new Object[] { pk };
3039    
3040                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
3041                                    finderArgs, this);
3042    
3043                    if (count == null) {
3044                            Session session = null;
3045    
3046                            try {
3047                                    session = openSession();
3048    
3049                                    SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
3050    
3051                                    q.addScalar(COUNT_COLUMN_NAME,
3052                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
3053    
3054                                    QueryPos qPos = QueryPos.getInstance(q);
3055    
3056                                    qPos.add(pk);
3057    
3058                                    count = (Long)q.uniqueResult();
3059                            }
3060                            catch (Exception e) {
3061                                    throw processException(e);
3062                            }
3063                            finally {
3064                                    if (count == null) {
3065                                            count = Long.valueOf(0);
3066                                    }
3067    
3068                                    FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
3069                                            finderArgs, count);
3070    
3071                                    closeSession(session);
3072                            }
3073                    }
3074    
3075                    return count.intValue();
3076            }
3077    
3078            public static final FinderPath FINDER_PATH_CONTAINS_PERMISSION = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3079                            RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
3080                            RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
3081                            "containsPermission",
3082                            new String[] { Long.class.getName(), Long.class.getName() });
3083    
3084            /**
3085             * Determines whether the permission is associated with the role.
3086             *
3087             * @param pk the primary key of the role
3088             * @param permissionPK the primary key of the permission
3089             * @return whether the permission is associated with the role
3090             * @throws SystemException if a system exception occurred
3091             */
3092            public boolean containsPermission(long pk, long permissionPK)
3093                    throws SystemException {
3094                    Object[] finderArgs = new Object[] { pk, permissionPK };
3095    
3096                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_PERMISSION,
3097                                    finderArgs, this);
3098    
3099                    if (value == null) {
3100                            try {
3101                                    value = Boolean.valueOf(containsPermission.contains(pk,
3102                                                            permissionPK));
3103                            }
3104                            catch (Exception e) {
3105                                    throw processException(e);
3106                            }
3107                            finally {
3108                                    if (value == null) {
3109                                            value = Boolean.FALSE;
3110                                    }
3111    
3112                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_PERMISSION,
3113                                            finderArgs, value);
3114                            }
3115                    }
3116    
3117                    return value.booleanValue();
3118            }
3119    
3120            /**
3121             * Determines whether the role has any permissions associated with it.
3122             *
3123             * @param pk the primary key of the role to check for associations with permissions
3124             * @return whether the role has any permissions associated with it
3125             * @throws SystemException if a system exception occurred
3126             */
3127            public boolean containsPermissions(long pk) throws SystemException {
3128                    if (getPermissionsSize(pk) > 0) {
3129                            return true;
3130                    }
3131                    else {
3132                            return false;
3133                    }
3134            }
3135    
3136            /**
3137             * Adds an association between the role and the permission. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3138             *
3139             * @param pk the primary key of the role
3140             * @param permissionPK the primary key of the permission
3141             * @throws SystemException if a system exception occurred
3142             */
3143            public void addPermission(long pk, long permissionPK)
3144                    throws SystemException {
3145                    try {
3146                            addPermission.add(pk, permissionPK);
3147                    }
3148                    catch (Exception e) {
3149                            throw processException(e);
3150                    }
3151                    finally {
3152                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3153                    }
3154            }
3155    
3156            /**
3157             * Adds an association between the role and the permission. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3158             *
3159             * @param pk the primary key of the role
3160             * @param permission the permission
3161             * @throws SystemException if a system exception occurred
3162             */
3163            public void addPermission(long pk,
3164                    com.liferay.portal.model.Permission permission)
3165                    throws SystemException {
3166                    try {
3167                            addPermission.add(pk, permission.getPrimaryKey());
3168                    }
3169                    catch (Exception e) {
3170                            throw processException(e);
3171                    }
3172                    finally {
3173                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3174                    }
3175            }
3176    
3177            /**
3178             * Adds an association between the role and the permissions. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3179             *
3180             * @param pk the primary key of the role
3181             * @param permissionPKs the primary keys of the permissions
3182             * @throws SystemException if a system exception occurred
3183             */
3184            public void addPermissions(long pk, long[] permissionPKs)
3185                    throws SystemException {
3186                    try {
3187                            for (long permissionPK : permissionPKs) {
3188                                    addPermission.add(pk, permissionPK);
3189                            }
3190                    }
3191                    catch (Exception e) {
3192                            throw processException(e);
3193                    }
3194                    finally {
3195                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3196                    }
3197            }
3198    
3199            /**
3200             * Adds an association between the role and the permissions. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3201             *
3202             * @param pk the primary key of the role
3203             * @param permissions the permissions
3204             * @throws SystemException if a system exception occurred
3205             */
3206            public void addPermissions(long pk,
3207                    List<com.liferay.portal.model.Permission> permissions)
3208                    throws SystemException {
3209                    try {
3210                            for (com.liferay.portal.model.Permission permission : permissions) {
3211                                    addPermission.add(pk, permission.getPrimaryKey());
3212                            }
3213                    }
3214                    catch (Exception e) {
3215                            throw processException(e);
3216                    }
3217                    finally {
3218                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3219                    }
3220            }
3221    
3222            /**
3223             * Clears all associations between the role and its permissions. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3224             *
3225             * @param pk the primary key of the role to clear the associated permissions from
3226             * @throws SystemException if a system exception occurred
3227             */
3228            public void clearPermissions(long pk) throws SystemException {
3229                    try {
3230                            clearPermissions.clear(pk);
3231                    }
3232                    catch (Exception e) {
3233                            throw processException(e);
3234                    }
3235                    finally {
3236                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3237                    }
3238            }
3239    
3240            /**
3241             * Removes the association between the role and the permission. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3242             *
3243             * @param pk the primary key of the role
3244             * @param permissionPK the primary key of the permission
3245             * @throws SystemException if a system exception occurred
3246             */
3247            public void removePermission(long pk, long permissionPK)
3248                    throws SystemException {
3249                    try {
3250                            removePermission.remove(pk, permissionPK);
3251                    }
3252                    catch (Exception e) {
3253                            throw processException(e);
3254                    }
3255                    finally {
3256                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3257                    }
3258            }
3259    
3260            /**
3261             * Removes the association between the role and the permission. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3262             *
3263             * @param pk the primary key of the role
3264             * @param permission the permission
3265             * @throws SystemException if a system exception occurred
3266             */
3267            public void removePermission(long pk,
3268                    com.liferay.portal.model.Permission permission)
3269                    throws SystemException {
3270                    try {
3271                            removePermission.remove(pk, permission.getPrimaryKey());
3272                    }
3273                    catch (Exception e) {
3274                            throw processException(e);
3275                    }
3276                    finally {
3277                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3278                    }
3279            }
3280    
3281            /**
3282             * Removes the association between the role and the permissions. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3283             *
3284             * @param pk the primary key of the role
3285             * @param permissionPKs the primary keys of the permissions
3286             * @throws SystemException if a system exception occurred
3287             */
3288            public void removePermissions(long pk, long[] permissionPKs)
3289                    throws SystemException {
3290                    try {
3291                            for (long permissionPK : permissionPKs) {
3292                                    removePermission.remove(pk, permissionPK);
3293                            }
3294                    }
3295                    catch (Exception e) {
3296                            throw processException(e);
3297                    }
3298                    finally {
3299                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3300                    }
3301            }
3302    
3303            /**
3304             * Removes the association between the role and the permissions. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3305             *
3306             * @param pk the primary key of the role
3307             * @param permissions the permissions
3308             * @throws SystemException if a system exception occurred
3309             */
3310            public void removePermissions(long pk,
3311                    List<com.liferay.portal.model.Permission> permissions)
3312                    throws SystemException {
3313                    try {
3314                            for (com.liferay.portal.model.Permission permission : permissions) {
3315                                    removePermission.remove(pk, permission.getPrimaryKey());
3316                            }
3317                    }
3318                    catch (Exception e) {
3319                            throw processException(e);
3320                    }
3321                    finally {
3322                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3323                    }
3324            }
3325    
3326            /**
3327             * Sets the permissions associated with the role, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3328             *
3329             * @param pk the primary key of the role to set the associations for
3330             * @param permissionPKs the primary keys of the permissions to be associated with the role
3331             * @throws SystemException if a system exception occurred
3332             */
3333            public void setPermissions(long pk, long[] permissionPKs)
3334                    throws SystemException {
3335                    try {
3336                            Set<Long> permissionPKSet = SetUtil.fromArray(permissionPKs);
3337    
3338                            List<com.liferay.portal.model.Permission> permissions = getPermissions(pk);
3339    
3340                            for (com.liferay.portal.model.Permission permission : permissions) {
3341                                    if (!permissionPKSet.remove(permission.getPrimaryKey())) {
3342                                            removePermission.remove(pk, permission.getPrimaryKey());
3343                                    }
3344                            }
3345    
3346                            for (Long permissionPK : permissionPKSet) {
3347                                    addPermission.add(pk, permissionPK);
3348                            }
3349                    }
3350                    catch (Exception e) {
3351                            throw processException(e);
3352                    }
3353                    finally {
3354                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3355                    }
3356            }
3357    
3358            /**
3359             * Sets the permissions associated with the role, removing and adding associations as necessary. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3360             *
3361             * @param pk the primary key of the role to set the associations for
3362             * @param permissions the permissions to be associated with the role
3363             * @throws SystemException if a system exception occurred
3364             */
3365            public void setPermissions(long pk,
3366                    List<com.liferay.portal.model.Permission> permissions)
3367                    throws SystemException {
3368                    try {
3369                            long[] permissionPKs = new long[permissions.size()];
3370    
3371                            for (int i = 0; i < permissions.size(); i++) {
3372                                    com.liferay.portal.model.Permission permission = permissions.get(i);
3373    
3374                                    permissionPKs[i] = permission.getPrimaryKey();
3375                            }
3376    
3377                            setPermissions(pk, permissionPKs);
3378                    }
3379                    catch (Exception e) {
3380                            throw processException(e);
3381                    }
3382                    finally {
3383                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3384                    }
3385            }
3386    
3387            /**
3388             * Gets all the users associated with the role.
3389             *
3390             * @param pk the primary key of the role to get the associated users for
3391             * @return the users associated with the role
3392             * @throws SystemException if a system exception occurred
3393             */
3394            public List<com.liferay.portal.model.User> getUsers(long pk)
3395                    throws SystemException {
3396                    return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3397            }
3398    
3399            /**
3400             * Gets a range of all the users associated with the role.
3401             *
3402             * <p>
3403             * 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.
3404             * </p>
3405             *
3406             * @param pk the primary key of the role to get the associated users for
3407             * @param start the lower bound of the range of roles to return
3408             * @param end the upper bound of the range of roles to return (not inclusive)
3409             * @return the range of users associated with the role
3410             * @throws SystemException if a system exception occurred
3411             */
3412            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3413                    int end) throws SystemException {
3414                    return getUsers(pk, start, end, null);
3415            }
3416    
3417            public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3418                            RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
3419                            RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsers",
3420                            new String[] {
3421                                    Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3422                                    "com.liferay.portal.kernel.util.OrderByComparator"
3423                            });
3424    
3425            /**
3426             * Gets an ordered range of all the users associated with the role.
3427             *
3428             * <p>
3429             * 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.
3430             * </p>
3431             *
3432             * @param pk the primary key of the role to get the associated users for
3433             * @param start the lower bound of the range of roles to return
3434             * @param end the upper bound of the range of roles to return (not inclusive)
3435             * @param orderByComparator the comparator to order the results by
3436             * @return the ordered range of users associated with the role
3437             * @throws SystemException if a system exception occurred
3438             */
3439            public List<com.liferay.portal.model.User> getUsers(long pk, int start,
3440                    int end, OrderByComparator orderByComparator) throws SystemException {
3441                    Object[] finderArgs = new Object[] {
3442                                    pk, String.valueOf(start), String.valueOf(end),
3443                                    String.valueOf(orderByComparator)
3444                            };
3445    
3446                    List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
3447                                    finderArgs, this);
3448    
3449                    if (list == null) {
3450                            Session session = null;
3451    
3452                            try {
3453                                    session = openSession();
3454    
3455                                    String sql = null;
3456    
3457                                    if (orderByComparator != null) {
3458                                            sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
3459                                                                               .concat(orderByComparator.getOrderBy());
3460                                    }
3461                                    else {
3462                                            sql = _SQL_GETUSERS;
3463                                    }
3464    
3465                                    SQLQuery q = session.createSQLQuery(sql);
3466    
3467                                    q.addEntity("User_",
3468                                            com.liferay.portal.model.impl.UserImpl.class);
3469    
3470                                    QueryPos qPos = QueryPos.getInstance(q);
3471    
3472                                    qPos.add(pk);
3473    
3474                                    list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
3475                                                    getDialect(), start, end);
3476                            }
3477                            catch (Exception e) {
3478                                    throw processException(e);
3479                            }
3480                            finally {
3481                                    if (list == null) {
3482                                            list = new ArrayList<com.liferay.portal.model.User>();
3483                                    }
3484    
3485                                    userPersistence.cacheResult(list);
3486    
3487                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
3488                                            list);
3489    
3490                                    closeSession(session);
3491                            }
3492                    }
3493    
3494                    return list;
3495            }
3496    
3497            public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3498                            RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
3499                            RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsersSize",
3500                            new String[] { Long.class.getName() });
3501    
3502            /**
3503             * Gets the number of users associated with the role.
3504             *
3505             * @param pk the primary key of the role to get the number of associated users for
3506             * @return the number of users associated with the role
3507             * @throws SystemException if a system exception occurred
3508             */
3509            public int getUsersSize(long pk) throws SystemException {
3510                    Object[] finderArgs = new Object[] { pk };
3511    
3512                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
3513                                    finderArgs, this);
3514    
3515                    if (count == null) {
3516                            Session session = null;
3517    
3518                            try {
3519                                    session = openSession();
3520    
3521                                    SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
3522    
3523                                    q.addScalar(COUNT_COLUMN_NAME,
3524                                            com.liferay.portal.kernel.dao.orm.Type.LONG);
3525    
3526                                    QueryPos qPos = QueryPos.getInstance(q);
3527    
3528                                    qPos.add(pk);
3529    
3530                                    count = (Long)q.uniqueResult();
3531                            }
3532                            catch (Exception e) {
3533                                    throw processException(e);
3534                            }
3535                            finally {
3536                                    if (count == null) {
3537                                            count = Long.valueOf(0);
3538                                    }
3539    
3540                                    FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
3541                                            finderArgs, count);
3542    
3543                                    closeSession(session);
3544                            }
3545                    }
3546    
3547                    return count.intValue();
3548            }
3549    
3550            public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
3551                            RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
3552                            RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "containsUser",
3553                            new String[] { Long.class.getName(), Long.class.getName() });
3554    
3555            /**
3556             * Determines whether the user is associated with the role.
3557             *
3558             * @param pk the primary key of the role
3559             * @param userPK the primary key of the user
3560             * @return whether the user is associated with the role
3561             * @throws SystemException if a system exception occurred
3562             */
3563            public boolean containsUser(long pk, long userPK) throws SystemException {
3564                    Object[] finderArgs = new Object[] { pk, userPK };
3565    
3566                    Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
3567                                    finderArgs, this);
3568    
3569                    if (value == null) {
3570                            try {
3571                                    value = Boolean.valueOf(containsUser.contains(pk, userPK));
3572                            }
3573                            catch (Exception e) {
3574                                    throw processException(e);
3575                            }
3576                            finally {
3577                                    if (value == null) {
3578                                            value = Boolean.FALSE;
3579                                    }
3580    
3581                                    FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
3582                                            finderArgs, value);
3583                            }
3584                    }
3585    
3586                    return value.booleanValue();
3587            }
3588    
3589            /**
3590             * Determines whether the role has any users associated with it.
3591             *
3592             * @param pk the primary key of the role to check for associations with users
3593             * @return whether the role has any users associated with it
3594             * @throws SystemException if a system exception occurred
3595             */
3596            public boolean containsUsers(long pk) throws SystemException {
3597                    if (getUsersSize(pk) > 0) {
3598                            return true;
3599                    }
3600                    else {
3601                            return false;
3602                    }
3603            }
3604    
3605            /**
3606             * Adds an association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3607             *
3608             * @param pk the primary key of the role
3609             * @param userPK the primary key of the user
3610             * @throws SystemException if a system exception occurred
3611             */
3612            public void addUser(long pk, long userPK) throws SystemException {
3613                    try {
3614                            addUser.add(pk, userPK);
3615                    }
3616                    catch (Exception e) {
3617                            throw processException(e);
3618                    }
3619                    finally {
3620                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3621                    }
3622            }
3623    
3624            /**
3625             * Adds an association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3626             *
3627             * @param pk the primary key of the role
3628             * @param user the user
3629             * @throws SystemException if a system exception occurred
3630             */
3631            public void addUser(long pk, com.liferay.portal.model.User user)
3632                    throws SystemException {
3633                    try {
3634                            addUser.add(pk, user.getPrimaryKey());
3635                    }
3636                    catch (Exception e) {
3637                            throw processException(e);
3638                    }
3639                    finally {
3640                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3641                    }
3642            }
3643    
3644            /**
3645             * Adds an association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3646             *
3647             * @param pk the primary key of the role
3648             * @param userPKs the primary keys of the users
3649             * @throws SystemException if a system exception occurred
3650             */
3651            public void addUsers(long pk, long[] userPKs) throws SystemException {
3652                    try {
3653                            for (long userPK : userPKs) {
3654                                    addUser.add(pk, userPK);
3655                            }
3656                    }
3657                    catch (Exception e) {
3658                            throw processException(e);
3659                    }
3660                    finally {
3661                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3662                    }
3663            }
3664    
3665            /**
3666             * Adds an association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3667             *
3668             * @param pk the primary key of the role
3669             * @param users the users
3670             * @throws SystemException if a system exception occurred
3671             */
3672            public void addUsers(long pk, List<com.liferay.portal.model.User> users)
3673                    throws SystemException {
3674                    try {
3675                            for (com.liferay.portal.model.User user : users) {
3676                                    addUser.add(pk, user.getPrimaryKey());
3677                            }
3678                    }
3679                    catch (Exception e) {
3680                            throw processException(e);
3681                    }
3682                    finally {
3683                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3684                    }
3685            }
3686    
3687            /**
3688             * Clears all associations between the role and its users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3689             *
3690             * @param pk the primary key of the role to clear the associated users from
3691             * @throws SystemException if a system exception occurred
3692             */
3693            public void clearUsers(long pk) throws SystemException {
3694                    try {
3695                            clearUsers.clear(pk);
3696                    }
3697                    catch (Exception e) {
3698                            throw processException(e);
3699                    }
3700                    finally {
3701                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3702                    }
3703            }
3704    
3705            /**
3706             * Removes the association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3707             *
3708             * @param pk the primary key of the role
3709             * @param userPK the primary key of the user
3710             * @throws SystemException if a system exception occurred
3711             */
3712            public void removeUser(long pk, long userPK) throws SystemException {
3713                    try {
3714                            removeUser.remove(pk, userPK);
3715                    }
3716                    catch (Exception e) {
3717                            throw processException(e);
3718                    }
3719                    finally {
3720                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3721                    }
3722            }
3723    
3724            /**
3725             * Removes the association between the role and the user. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3726             *
3727             * @param pk the primary key of the role
3728             * @param user the user
3729             * @throws SystemException if a system exception occurred
3730             */
3731            public void removeUser(long pk, com.liferay.portal.model.User user)
3732                    throws SystemException {
3733                    try {
3734                            removeUser.remove(pk, user.getPrimaryKey());
3735                    }
3736                    catch (Exception e) {
3737                            throw processException(e);
3738                    }
3739                    finally {
3740                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3741                    }
3742            }
3743    
3744            /**
3745             * Removes the association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3746             *
3747             * @param pk the primary key of the role
3748             * @param userPKs the primary keys of the users
3749             * @throws SystemException if a system exception occurred
3750             */
3751            public void removeUsers(long pk, long[] userPKs) throws SystemException {
3752                    try {
3753                            for (long userPK : userPKs) {
3754                                    removeUser.remove(pk, userPK);
3755                            }
3756                    }
3757                    catch (Exception e) {
3758                            throw processException(e);
3759                    }
3760                    finally {
3761                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3762                    }
3763            }
3764    
3765            /**
3766             * Removes the association between the role and the users. Also notifies the appropriate model listeners and clears the mapping table finder cache.
3767             *
3768             * @param pk the primary key of the role
3769             * @param users the users
3770             * @throws SystemException if a system exception occurred
3771             */
3772            public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
3773                    throws SystemException {
3774                    try {
3775                            for (com.liferay.portal.model.User user : users) {
3776                                    removeUser.remove(pk, user.getPrimaryKey());
3777                            }
3778                    }
3779                    catch (Exception e) {
3780                            throw processException(e);
3781                    }
3782                    finally {
3783                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3784                    }
3785            }
3786    
3787            /**
3788             * 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.
3789             *
3790             * @param pk the primary key of the role to set the associations for
3791             * @param userPKs the primary keys of the users to be associated with the role
3792             * @throws SystemException if a system exception occurred
3793             */
3794            public void setUsers(long pk, long[] userPKs) throws SystemException {
3795                    try {
3796                            Set<Long> userPKSet = SetUtil.fromArray(userPKs);
3797    
3798                            List<com.liferay.portal.model.User> users = getUsers(pk);
3799    
3800                            for (com.liferay.portal.model.User user : users) {
3801                                    if (!userPKSet.remove(user.getPrimaryKey())) {
3802                                            removeUser.remove(pk, user.getPrimaryKey());
3803                                    }
3804                            }
3805    
3806                            for (Long userPK : userPKSet) {
3807                                    addUser.add(pk, userPK);
3808                            }
3809                    }
3810                    catch (Exception e) {
3811                            throw processException(e);
3812                    }
3813                    finally {
3814                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3815                    }
3816            }
3817    
3818            /**
3819             * 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.
3820             *
3821             * @param pk the primary key of the role to set the associations for
3822             * @param users the users to be associated with the role
3823             * @throws SystemException if a system exception occurred
3824             */
3825            public void setUsers(long pk, List<com.liferay.portal.model.User> users)
3826                    throws SystemException {
3827                    try {
3828                            long[] userPKs = new long[users.size()];
3829    
3830                            for (int i = 0; i < users.size(); i++) {
3831                                    com.liferay.portal.model.User user = users.get(i);
3832    
3833                                    userPKs[i] = user.getPrimaryKey();
3834                            }
3835    
3836                            setUsers(pk, userPKs);
3837                    }
3838                    catch (Exception e) {
3839                            throw processException(e);
3840                    }
3841                    finally {
3842                            FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
3843                    }
3844            }
3845    
3846            /**
3847             * Initializes the role persistence.
3848             */
3849            public void afterPropertiesSet() {
3850                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3851                                            com.liferay.portal.util.PropsUtil.get(
3852                                                    "value.object.listener.com.liferay.portal.model.Role")));
3853    
3854                    if (listenerClassNames.length > 0) {
3855                            try {
3856                                    List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
3857    
3858                                    for (String listenerClassName : listenerClassNames) {
3859                                            listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
3860                                                            listenerClassName));
3861                                    }
3862    
3863                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3864                            }
3865                            catch (Exception e) {
3866                                    _log.error(e);
3867                            }
3868                    }
3869    
3870                    containsGroup = new ContainsGroup(this);
3871    
3872                    addGroup = new AddGroup(this);
3873                    clearGroups = new ClearGroups(this);
3874                    removeGroup = new RemoveGroup(this);
3875    
3876                    containsPermission = new ContainsPermission(this);
3877    
3878                    addPermission = new AddPermission(this);
3879                    clearPermissions = new ClearPermissions(this);
3880                    removePermission = new RemovePermission(this);
3881    
3882                    containsUser = new ContainsUser(this);
3883    
3884                    addUser = new AddUser(this);
3885                    clearUsers = new ClearUsers(this);
3886                    removeUser = new RemoveUser(this);
3887            }
3888    
3889            public void destroy() {
3890                    EntityCacheUtil.removeCache(RoleImpl.class.getName());
3891                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3892                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3893            }
3894    
3895            @BeanReference(type = AccountPersistence.class)
3896            protected AccountPersistence accountPersistence;
3897            @BeanReference(type = AddressPersistence.class)
3898            protected AddressPersistence addressPersistence;
3899            @BeanReference(type = BrowserTrackerPersistence.class)
3900            protected BrowserTrackerPersistence browserTrackerPersistence;
3901            @BeanReference(type = ClassNamePersistence.class)
3902            protected ClassNamePersistence classNamePersistence;
3903            @BeanReference(type = ClusterGroupPersistence.class)
3904            protected ClusterGroupPersistence clusterGroupPersistence;
3905            @BeanReference(type = CompanyPersistence.class)
3906            protected CompanyPersistence companyPersistence;
3907            @BeanReference(type = ContactPersistence.class)
3908            protected ContactPersistence contactPersistence;
3909            @BeanReference(type = CountryPersistence.class)
3910            protected CountryPersistence countryPersistence;
3911            @BeanReference(type = EmailAddressPersistence.class)
3912            protected EmailAddressPersistence emailAddressPersistence;
3913            @BeanReference(type = GroupPersistence.class)
3914            protected GroupPersistence groupPersistence;
3915            @BeanReference(type = ImagePersistence.class)
3916            protected ImagePersistence imagePersistence;
3917            @BeanReference(type = LayoutPersistence.class)
3918            protected LayoutPersistence layoutPersistence;
3919            @BeanReference(type = LayoutPrototypePersistence.class)
3920            protected LayoutPrototypePersistence layoutPrototypePersistence;
3921            @BeanReference(type = LayoutSetPersistence.class)
3922            protected LayoutSetPersistence layoutSetPersistence;
3923            @BeanReference(type = LayoutSetPrototypePersistence.class)
3924            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
3925            @BeanReference(type = ListTypePersistence.class)
3926            protected ListTypePersistence listTypePersistence;
3927            @BeanReference(type = LockPersistence.class)
3928            protected LockPersistence lockPersistence;
3929            @BeanReference(type = MembershipRequestPersistence.class)
3930            protected MembershipRequestPersistence membershipRequestPersistence;
3931            @BeanReference(type = OrganizationPersistence.class)
3932            protected OrganizationPersistence organizationPersistence;
3933            @BeanReference(type = OrgGroupPermissionPersistence.class)
3934            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
3935            @BeanReference(type = OrgGroupRolePersistence.class)
3936            protected OrgGroupRolePersistence orgGroupRolePersistence;
3937            @BeanReference(type = OrgLaborPersistence.class)
3938            protected OrgLaborPersistence orgLaborPersistence;
3939            @BeanReference(type = PasswordPolicyPersistence.class)
3940            protected PasswordPolicyPersistence passwordPolicyPersistence;
3941            @BeanReference(type = PasswordPolicyRelPersistence.class)
3942            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
3943            @BeanReference(type = PasswordTrackerPersistence.class)
3944            protected PasswordTrackerPersistence passwordTrackerPersistence;
3945            @BeanReference(type = PermissionPersistence.class)
3946            protected PermissionPersistence permissionPersistence;
3947            @BeanReference(type = PhonePersistence.class)
3948            protected PhonePersistence phonePersistence;
3949            @BeanReference(type = PluginSettingPersistence.class)
3950            protected PluginSettingPersistence pluginSettingPersistence;
3951            @BeanReference(type = PortletPersistence.class)
3952            protected PortletPersistence portletPersistence;
3953            @BeanReference(type = PortletItemPersistence.class)
3954            protected PortletItemPersistence portletItemPersistence;
3955            @BeanReference(type = PortletPreferencesPersistence.class)
3956            protected PortletPreferencesPersistence portletPreferencesPersistence;
3957            @BeanReference(type = RegionPersistence.class)
3958            protected RegionPersistence regionPersistence;
3959            @BeanReference(type = ReleasePersistence.class)
3960            protected ReleasePersistence releasePersistence;
3961            @BeanReference(type = ResourcePersistence.class)
3962            protected ResourcePersistence resourcePersistence;
3963            @BeanReference(type = ResourceActionPersistence.class)
3964            protected ResourceActionPersistence resourceActionPersistence;
3965            @BeanReference(type = ResourceCodePersistence.class)
3966            protected ResourceCodePersistence resourceCodePersistence;
3967            @BeanReference(type = ResourcePermissionPersistence.class)
3968            protected ResourcePermissionPersistence resourcePermissionPersistence;
3969            @BeanReference(type = RolePersistence.class)
3970            protected RolePersistence rolePersistence;
3971            @BeanReference(type = ServiceComponentPersistence.class)
3972            protected ServiceComponentPersistence serviceComponentPersistence;
3973            @BeanReference(type = ShardPersistence.class)
3974            protected ShardPersistence shardPersistence;
3975            @BeanReference(type = SubscriptionPersistence.class)
3976            protected SubscriptionPersistence subscriptionPersistence;
3977            @BeanReference(type = TicketPersistence.class)
3978            protected TicketPersistence ticketPersistence;
3979            @BeanReference(type = TeamPersistence.class)
3980            protected TeamPersistence teamPersistence;
3981            @BeanReference(type = UserPersistence.class)
3982            protected UserPersistence userPersistence;
3983            @BeanReference(type = UserGroupPersistence.class)
3984            protected UserGroupPersistence userGroupPersistence;
3985            @BeanReference(type = UserGroupGroupRolePersistence.class)
3986            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
3987            @BeanReference(type = UserGroupRolePersistence.class)
3988            protected UserGroupRolePersistence userGroupRolePersistence;
3989            @BeanReference(type = UserIdMapperPersistence.class)
3990            protected UserIdMapperPersistence userIdMapperPersistence;
3991            @BeanReference(type = UserTrackerPersistence.class)
3992            protected UserTrackerPersistence userTrackerPersistence;
3993            @BeanReference(type = UserTrackerPathPersistence.class)
3994            protected UserTrackerPathPersistence userTrackerPathPersistence;
3995            @BeanReference(type = WebDAVPropsPersistence.class)
3996            protected WebDAVPropsPersistence webDAVPropsPersistence;
3997            @BeanReference(type = WebsitePersistence.class)
3998            protected WebsitePersistence websitePersistence;
3999            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
4000            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4001            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4002            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4003            protected ContainsGroup containsGroup;
4004            protected AddGroup addGroup;
4005            protected ClearGroups clearGroups;
4006            protected RemoveGroup removeGroup;
4007            protected ContainsPermission containsPermission;
4008            protected AddPermission addPermission;
4009            protected ClearPermissions clearPermissions;
4010            protected RemovePermission removePermission;
4011            protected ContainsUser containsUser;
4012            protected AddUser addUser;
4013            protected ClearUsers clearUsers;
4014            protected RemoveUser removeUser;
4015    
4016            protected class ContainsGroup {
4017                    protected ContainsGroup(RolePersistenceImpl persistenceImpl) {
4018                            super();
4019    
4020                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4021                                            _SQL_CONTAINSGROUP,
4022                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4023                                            RowMapper.COUNT);
4024                    }
4025    
4026                    protected boolean contains(long roleId, long groupId) {
4027                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4028                                                    new Long(roleId), new Long(groupId)
4029                                            });
4030    
4031                            if (results.size() > 0) {
4032                                    Integer count = results.get(0);
4033    
4034                                    if (count.intValue() > 0) {
4035                                            return true;
4036                                    }
4037                            }
4038    
4039                            return false;
4040                    }
4041    
4042                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4043            }
4044    
4045            protected class AddGroup {
4046                    protected AddGroup(RolePersistenceImpl persistenceImpl) {
4047                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4048                                            "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
4049                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4050                            _persistenceImpl = persistenceImpl;
4051                    }
4052    
4053                    protected void add(long roleId, long groupId) throws SystemException {
4054                            if (!_persistenceImpl.containsGroup.contains(roleId, groupId)) {
4055                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4056    
4057                                    for (ModelListener<Role> listener : listeners) {
4058                                            listener.onBeforeAddAssociation(roleId,
4059                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4060                                    }
4061    
4062                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4063                                            listener.onBeforeAddAssociation(groupId,
4064                                                    Role.class.getName(), roleId);
4065                                    }
4066    
4067                                    _sqlUpdate.update(new Object[] {
4068                                                    new Long(roleId), new Long(groupId)
4069                                            });
4070    
4071                                    for (ModelListener<Role> listener : listeners) {
4072                                            listener.onAfterAddAssociation(roleId,
4073                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4074                                    }
4075    
4076                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4077                                            listener.onAfterAddAssociation(groupId,
4078                                                    Role.class.getName(), roleId);
4079                                    }
4080                            }
4081                    }
4082    
4083                    private SqlUpdate _sqlUpdate;
4084                    private RolePersistenceImpl _persistenceImpl;
4085            }
4086    
4087            protected class ClearGroups {
4088                    protected ClearGroups(RolePersistenceImpl persistenceImpl) {
4089                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4090                                            "DELETE FROM Groups_Roles WHERE roleId = ?",
4091                                            new int[] { java.sql.Types.BIGINT });
4092                    }
4093    
4094                    protected void clear(long roleId) throws SystemException {
4095                            ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4096    
4097                            List<com.liferay.portal.model.Group> groups = null;
4098    
4099                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4100                                    groups = getGroups(roleId);
4101    
4102                                    for (com.liferay.portal.model.Group group : groups) {
4103                                            for (ModelListener<Role> listener : listeners) {
4104                                                    listener.onBeforeRemoveAssociation(roleId,
4105                                                            com.liferay.portal.model.Group.class.getName(),
4106                                                            group.getPrimaryKey());
4107                                            }
4108    
4109                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4110                                                    listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4111                                                            Role.class.getName(), roleId);
4112                                            }
4113                                    }
4114                            }
4115    
4116                            _sqlUpdate.update(new Object[] { new Long(roleId) });
4117    
4118                            if ((listeners.length > 0) || (groupListeners.length > 0)) {
4119                                    for (com.liferay.portal.model.Group group : groups) {
4120                                            for (ModelListener<Role> listener : listeners) {
4121                                                    listener.onAfterRemoveAssociation(roleId,
4122                                                            com.liferay.portal.model.Group.class.getName(),
4123                                                            group.getPrimaryKey());
4124                                            }
4125    
4126                                            for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4127                                                    listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4128                                                            Role.class.getName(), roleId);
4129                                            }
4130                                    }
4131                            }
4132                    }
4133    
4134                    private SqlUpdate _sqlUpdate;
4135            }
4136    
4137            protected class RemoveGroup {
4138                    protected RemoveGroup(RolePersistenceImpl persistenceImpl) {
4139                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4140                                            "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
4141                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4142                            _persistenceImpl = persistenceImpl;
4143                    }
4144    
4145                    protected void remove(long roleId, long groupId)
4146                            throws SystemException {
4147                            if (_persistenceImpl.containsGroup.contains(roleId, groupId)) {
4148                                    ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4149    
4150                                    for (ModelListener<Role> listener : listeners) {
4151                                            listener.onBeforeRemoveAssociation(roleId,
4152                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4153                                    }
4154    
4155                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4156                                            listener.onBeforeRemoveAssociation(groupId,
4157                                                    Role.class.getName(), roleId);
4158                                    }
4159    
4160                                    _sqlUpdate.update(new Object[] {
4161                                                    new Long(roleId), new Long(groupId)
4162                                            });
4163    
4164                                    for (ModelListener<Role> listener : listeners) {
4165                                            listener.onAfterRemoveAssociation(roleId,
4166                                                    com.liferay.portal.model.Group.class.getName(), groupId);
4167                                    }
4168    
4169                                    for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4170                                            listener.onAfterRemoveAssociation(groupId,
4171                                                    Role.class.getName(), roleId);
4172                                    }
4173                            }
4174                    }
4175    
4176                    private SqlUpdate _sqlUpdate;
4177                    private RolePersistenceImpl _persistenceImpl;
4178            }
4179    
4180            protected class ContainsPermission {
4181                    protected ContainsPermission(RolePersistenceImpl persistenceImpl) {
4182                            super();
4183    
4184                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4185                                            _SQL_CONTAINSPERMISSION,
4186                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4187                                            RowMapper.COUNT);
4188                    }
4189    
4190                    protected boolean contains(long roleId, long permissionId) {
4191                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4192                                                    new Long(roleId), new Long(permissionId)
4193                                            });
4194    
4195                            if (results.size() > 0) {
4196                                    Integer count = results.get(0);
4197    
4198                                    if (count.intValue() > 0) {
4199                                            return true;
4200                                    }
4201                            }
4202    
4203                            return false;
4204                    }
4205    
4206                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4207            }
4208    
4209            protected class AddPermission {
4210                    protected AddPermission(RolePersistenceImpl persistenceImpl) {
4211                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4212                                            "INSERT INTO Roles_Permissions (roleId, permissionId) VALUES (?, ?)",
4213                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4214                            _persistenceImpl = persistenceImpl;
4215                    }
4216    
4217                    protected void add(long roleId, long permissionId)
4218                            throws SystemException {
4219                            if (!_persistenceImpl.containsPermission.contains(roleId,
4220                                                    permissionId)) {
4221                                    ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4222                                            permissionPersistence.getListeners();
4223    
4224                                    for (ModelListener<Role> listener : listeners) {
4225                                            listener.onBeforeAddAssociation(roleId,
4226                                                    com.liferay.portal.model.Permission.class.getName(),
4227                                                    permissionId);
4228                                    }
4229    
4230                                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4231                                            listener.onBeforeAddAssociation(permissionId,
4232                                                    Role.class.getName(), roleId);
4233                                    }
4234    
4235                                    _sqlUpdate.update(new Object[] {
4236                                                    new Long(roleId), new Long(permissionId)
4237                                            });
4238    
4239                                    for (ModelListener<Role> listener : listeners) {
4240                                            listener.onAfterAddAssociation(roleId,
4241                                                    com.liferay.portal.model.Permission.class.getName(),
4242                                                    permissionId);
4243                                    }
4244    
4245                                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4246                                            listener.onAfterAddAssociation(permissionId,
4247                                                    Role.class.getName(), roleId);
4248                                    }
4249                            }
4250                    }
4251    
4252                    private SqlUpdate _sqlUpdate;
4253                    private RolePersistenceImpl _persistenceImpl;
4254            }
4255    
4256            protected class ClearPermissions {
4257                    protected ClearPermissions(RolePersistenceImpl persistenceImpl) {
4258                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4259                                            "DELETE FROM Roles_Permissions WHERE roleId = ?",
4260                                            new int[] { java.sql.Types.BIGINT });
4261                    }
4262    
4263                    protected void clear(long roleId) throws SystemException {
4264                            ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4265                                    permissionPersistence.getListeners();
4266    
4267                            List<com.liferay.portal.model.Permission> permissions = null;
4268    
4269                            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
4270                                    permissions = getPermissions(roleId);
4271    
4272                                    for (com.liferay.portal.model.Permission permission : permissions) {
4273                                            for (ModelListener<Role> listener : listeners) {
4274                                                    listener.onBeforeRemoveAssociation(roleId,
4275                                                            com.liferay.portal.model.Permission.class.getName(),
4276                                                            permission.getPrimaryKey());
4277                                            }
4278    
4279                                            for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4280                                                    listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
4281                                                            Role.class.getName(), roleId);
4282                                            }
4283                                    }
4284                            }
4285    
4286                            _sqlUpdate.update(new Object[] { new Long(roleId) });
4287    
4288                            if ((listeners.length > 0) || (permissionListeners.length > 0)) {
4289                                    for (com.liferay.portal.model.Permission permission : permissions) {
4290                                            for (ModelListener<Role> listener : listeners) {
4291                                                    listener.onAfterRemoveAssociation(roleId,
4292                                                            com.liferay.portal.model.Permission.class.getName(),
4293                                                            permission.getPrimaryKey());
4294                                            }
4295    
4296                                            for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4297                                                    listener.onAfterRemoveAssociation(permission.getPrimaryKey(),
4298                                                            Role.class.getName(), roleId);
4299                                            }
4300                                    }
4301                            }
4302                    }
4303    
4304                    private SqlUpdate _sqlUpdate;
4305            }
4306    
4307            protected class RemovePermission {
4308                    protected RemovePermission(RolePersistenceImpl persistenceImpl) {
4309                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4310                                            "DELETE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?",
4311                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4312                            _persistenceImpl = persistenceImpl;
4313                    }
4314    
4315                    protected void remove(long roleId, long permissionId)
4316                            throws SystemException {
4317                            if (_persistenceImpl.containsPermission.contains(roleId,
4318                                                    permissionId)) {
4319                                    ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4320                                            permissionPersistence.getListeners();
4321    
4322                                    for (ModelListener<Role> listener : listeners) {
4323                                            listener.onBeforeRemoveAssociation(roleId,
4324                                                    com.liferay.portal.model.Permission.class.getName(),
4325                                                    permissionId);
4326                                    }
4327    
4328                                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4329                                            listener.onBeforeRemoveAssociation(permissionId,
4330                                                    Role.class.getName(), roleId);
4331                                    }
4332    
4333                                    _sqlUpdate.update(new Object[] {
4334                                                    new Long(roleId), new Long(permissionId)
4335                                            });
4336    
4337                                    for (ModelListener<Role> listener : listeners) {
4338                                            listener.onAfterRemoveAssociation(roleId,
4339                                                    com.liferay.portal.model.Permission.class.getName(),
4340                                                    permissionId);
4341                                    }
4342    
4343                                    for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4344                                            listener.onAfterRemoveAssociation(permissionId,
4345                                                    Role.class.getName(), roleId);
4346                                    }
4347                            }
4348                    }
4349    
4350                    private SqlUpdate _sqlUpdate;
4351                    private RolePersistenceImpl _persistenceImpl;
4352            }
4353    
4354            protected class ContainsUser {
4355                    protected ContainsUser(RolePersistenceImpl persistenceImpl) {
4356                            super();
4357    
4358                            _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4359                                            _SQL_CONTAINSUSER,
4360                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4361                                            RowMapper.COUNT);
4362                    }
4363    
4364                    protected boolean contains(long roleId, long userId) {
4365                            List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4366                                                    new Long(roleId), new Long(userId)
4367                                            });
4368    
4369                            if (results.size() > 0) {
4370                                    Integer count = results.get(0);
4371    
4372                                    if (count.intValue() > 0) {
4373                                            return true;
4374                                    }
4375                            }
4376    
4377                            return false;
4378                    }
4379    
4380                    private MappingSqlQuery<Integer> _mappingSqlQuery;
4381            }
4382    
4383            protected class AddUser {
4384                    protected AddUser(RolePersistenceImpl persistenceImpl) {
4385                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4386                                            "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
4387                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4388                            _persistenceImpl = persistenceImpl;
4389                    }
4390    
4391                    protected void add(long roleId, long userId) throws SystemException {
4392                            if (!_persistenceImpl.containsUser.contains(roleId, userId)) {
4393                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4394    
4395                                    for (ModelListener<Role> listener : listeners) {
4396                                            listener.onBeforeAddAssociation(roleId,
4397                                                    com.liferay.portal.model.User.class.getName(), userId);
4398                                    }
4399    
4400                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4401                                            listener.onBeforeAddAssociation(userId,
4402                                                    Role.class.getName(), roleId);
4403                                    }
4404    
4405                                    _sqlUpdate.update(new Object[] {
4406                                                    new Long(roleId), new Long(userId)
4407                                            });
4408    
4409                                    for (ModelListener<Role> listener : listeners) {
4410                                            listener.onAfterAddAssociation(roleId,
4411                                                    com.liferay.portal.model.User.class.getName(), userId);
4412                                    }
4413    
4414                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4415                                            listener.onAfterAddAssociation(userId,
4416                                                    Role.class.getName(), roleId);
4417                                    }
4418                            }
4419                    }
4420    
4421                    private SqlUpdate _sqlUpdate;
4422                    private RolePersistenceImpl _persistenceImpl;
4423            }
4424    
4425            protected class ClearUsers {
4426                    protected ClearUsers(RolePersistenceImpl persistenceImpl) {
4427                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4428                                            "DELETE FROM Users_Roles WHERE roleId = ?",
4429                                            new int[] { java.sql.Types.BIGINT });
4430                    }
4431    
4432                    protected void clear(long roleId) throws SystemException {
4433                            ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4434    
4435                            List<com.liferay.portal.model.User> users = null;
4436    
4437                            if ((listeners.length > 0) || (userListeners.length > 0)) {
4438                                    users = getUsers(roleId);
4439    
4440                                    for (com.liferay.portal.model.User user : users) {
4441                                            for (ModelListener<Role> listener : listeners) {
4442                                                    listener.onBeforeRemoveAssociation(roleId,
4443                                                            com.liferay.portal.model.User.class.getName(),
4444                                                            user.getPrimaryKey());
4445                                            }
4446    
4447                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4448                                                    listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
4449                                                            Role.class.getName(), roleId);
4450                                            }
4451                                    }
4452                            }
4453    
4454                            _sqlUpdate.update(new Object[] { new Long(roleId) });
4455    
4456                            if ((listeners.length > 0) || (userListeners.length > 0)) {
4457                                    for (com.liferay.portal.model.User user : users) {
4458                                            for (ModelListener<Role> listener : listeners) {
4459                                                    listener.onAfterRemoveAssociation(roleId,
4460                                                            com.liferay.portal.model.User.class.getName(),
4461                                                            user.getPrimaryKey());
4462                                            }
4463    
4464                                            for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4465                                                    listener.onAfterRemoveAssociation(user.getPrimaryKey(),
4466                                                            Role.class.getName(), roleId);
4467                                            }
4468                                    }
4469                            }
4470                    }
4471    
4472                    private SqlUpdate _sqlUpdate;
4473            }
4474    
4475            protected class RemoveUser {
4476                    protected RemoveUser(RolePersistenceImpl persistenceImpl) {
4477                            _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4478                                            "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
4479                                            new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4480                            _persistenceImpl = persistenceImpl;
4481                    }
4482    
4483                    protected void remove(long roleId, long userId)
4484                            throws SystemException {
4485                            if (_persistenceImpl.containsUser.contains(roleId, userId)) {
4486                                    ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4487    
4488                                    for (ModelListener<Role> listener : listeners) {
4489                                            listener.onBeforeRemoveAssociation(roleId,
4490                                                    com.liferay.portal.model.User.class.getName(), userId);
4491                                    }
4492    
4493                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4494                                            listener.onBeforeRemoveAssociation(userId,
4495                                                    Role.class.getName(), roleId);
4496                                    }
4497    
4498                                    _sqlUpdate.update(new Object[] {
4499                                                    new Long(roleId), new Long(userId)
4500                                            });
4501    
4502                                    for (ModelListener<Role> listener : listeners) {
4503                                            listener.onAfterRemoveAssociation(roleId,
4504                                                    com.liferay.portal.model.User.class.getName(), userId);
4505                                    }
4506    
4507                                    for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4508                                            listener.onAfterRemoveAssociation(userId,
4509                                                    Role.class.getName(), roleId);
4510                                    }
4511                            }
4512                    }
4513    
4514                    private SqlUpdate _sqlUpdate;
4515                    private RolePersistenceImpl _persistenceImpl;
4516            }
4517    
4518            private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
4519            private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
4520            private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
4521            private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
4522            private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
4523            private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
4524            private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
4525            private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Roles_Permissions ON (Roles_Permissions.permissionId = Permission_.permissionId) WHERE (Roles_Permissions.roleId = ?)";
4526            private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ?";
4527            private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?";
4528            private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
4529            private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
4530            private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
4531            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
4532            private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
4533            private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
4534            private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
4535            private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
4536            private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
4537            private static final String _FINDER_COLUMN_C_N_NAME_2 = "role.name = ?";
4538            private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = ?)";
4539            private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
4540            private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
4541            private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
4542            private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
4543            private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
4544            private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
4545            private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
4546            private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
4547            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
4548            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
4549            private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
4550    }