001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.NoSuchOrgGroupRoleException;
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.model.OrgGroupRole;
040    import com.liferay.portal.model.impl.OrgGroupRoleImpl;
041    import com.liferay.portal.model.impl.OrgGroupRoleModelImpl;
042    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the org group role service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see OrgGroupRolePersistence
059     * @see OrgGroupRoleUtil
060     * @generated
061     */
062    public class OrgGroupRolePersistenceImpl extends BasePersistenceImpl<OrgGroupRole>
063            implements OrgGroupRolePersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link OrgGroupRoleUtil} to access the org group role persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = OrgGroupRoleImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
075                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
084                    new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
085                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
087                            new String[] { Long.class.getName() },
088                            OrgGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
089            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
090                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
092                            new String[] { Long.class.getName() });
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
094                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByRoleId",
096                            new String[] {
097                                    Long.class.getName(),
098                                    
099                            "java.lang.Integer", "java.lang.Integer",
100                                    "com.liferay.portal.kernel.util.OrderByComparator"
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
103                    new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
104                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
105                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByRoleId",
106                            new String[] { Long.class.getName() },
107                            OrgGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
109                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
111                            new String[] { Long.class.getName() });
112            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
113                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
114                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
115            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
116                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, OrgGroupRoleImpl.class,
117                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
118            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
119                            OrgGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
121    
122            /**
123             * Caches the org group role in the entity cache if it is enabled.
124             *
125             * @param orgGroupRole the org group role
126             */
127            public void cacheResult(OrgGroupRole orgGroupRole) {
128                    EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
129                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
130    
131                    orgGroupRole.resetOriginalValues();
132            }
133    
134            /**
135             * Caches the org group roles in the entity cache if it is enabled.
136             *
137             * @param orgGroupRoles the org group roles
138             */
139            public void cacheResult(List<OrgGroupRole> orgGroupRoles) {
140                    for (OrgGroupRole orgGroupRole : orgGroupRoles) {
141                            if (EntityCacheUtil.getResult(
142                                                    OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
143                                                    OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey()) == null) {
144                                    cacheResult(orgGroupRole);
145                            }
146                            else {
147                                    orgGroupRole.resetOriginalValues();
148                            }
149                    }
150            }
151    
152            /**
153             * Clears the cache for all org group roles.
154             *
155             * <p>
156             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
157             * </p>
158             */
159            @Override
160            public void clearCache() {
161                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
162                            CacheRegistryUtil.clear(OrgGroupRoleImpl.class.getName());
163                    }
164    
165                    EntityCacheUtil.clearCache(OrgGroupRoleImpl.class.getName());
166    
167                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
168                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
169                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
170            }
171    
172            /**
173             * Clears the cache for the org group role.
174             *
175             * <p>
176             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
177             * </p>
178             */
179            @Override
180            public void clearCache(OrgGroupRole orgGroupRole) {
181                    EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
182                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
183    
184                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
185                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
186            }
187    
188            @Override
189            public void clearCache(List<OrgGroupRole> orgGroupRoles) {
190                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
191                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
192    
193                    for (OrgGroupRole orgGroupRole : orgGroupRoles) {
194                            EntityCacheUtil.removeResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
195                                    OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey());
196                    }
197            }
198    
199            /**
200             * Creates a new org group role with the primary key. Does not add the org group role to the database.
201             *
202             * @param orgGroupRolePK the primary key for the new org group role
203             * @return the new org group role
204             */
205            public OrgGroupRole create(OrgGroupRolePK orgGroupRolePK) {
206                    OrgGroupRole orgGroupRole = new OrgGroupRoleImpl();
207    
208                    orgGroupRole.setNew(true);
209                    orgGroupRole.setPrimaryKey(orgGroupRolePK);
210    
211                    return orgGroupRole;
212            }
213    
214            /**
215             * Removes the org group role with the primary key from the database. Also notifies the appropriate model listeners.
216             *
217             * @param orgGroupRolePK the primary key of the org group role
218             * @return the org group role that was removed
219             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
220             * @throws SystemException if a system exception occurred
221             */
222            public OrgGroupRole remove(OrgGroupRolePK orgGroupRolePK)
223                    throws NoSuchOrgGroupRoleException, SystemException {
224                    return remove((Serializable)orgGroupRolePK);
225            }
226    
227            /**
228             * Removes the org group role with the primary key from the database. Also notifies the appropriate model listeners.
229             *
230             * @param primaryKey the primary key of the org group role
231             * @return the org group role that was removed
232             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
233             * @throws SystemException if a system exception occurred
234             */
235            @Override
236            public OrgGroupRole remove(Serializable primaryKey)
237                    throws NoSuchOrgGroupRoleException, SystemException {
238                    Session session = null;
239    
240                    try {
241                            session = openSession();
242    
243                            OrgGroupRole orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
244                                            primaryKey);
245    
246                            if (orgGroupRole == null) {
247                                    if (_log.isWarnEnabled()) {
248                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
249                                    }
250    
251                                    throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
252                                            primaryKey);
253                            }
254    
255                            return remove(orgGroupRole);
256                    }
257                    catch (NoSuchOrgGroupRoleException nsee) {
258                            throw nsee;
259                    }
260                    catch (Exception e) {
261                            throw processException(e);
262                    }
263                    finally {
264                            closeSession(session);
265                    }
266            }
267    
268            @Override
269            protected OrgGroupRole removeImpl(OrgGroupRole orgGroupRole)
270                    throws SystemException {
271                    orgGroupRole = toUnwrappedModel(orgGroupRole);
272    
273                    Session session = null;
274    
275                    try {
276                            session = openSession();
277    
278                            BatchSessionUtil.delete(session, orgGroupRole);
279                    }
280                    catch (Exception e) {
281                            throw processException(e);
282                    }
283                    finally {
284                            closeSession(session);
285                    }
286    
287                    clearCache(orgGroupRole);
288    
289                    return orgGroupRole;
290            }
291    
292            @Override
293            public OrgGroupRole updateImpl(
294                    com.liferay.portal.model.OrgGroupRole orgGroupRole, boolean merge)
295                    throws SystemException {
296                    orgGroupRole = toUnwrappedModel(orgGroupRole);
297    
298                    boolean isNew = orgGroupRole.isNew();
299    
300                    OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
301    
302                    Session session = null;
303    
304                    try {
305                            session = openSession();
306    
307                            BatchSessionUtil.update(session, orgGroupRole, merge);
308    
309                            orgGroupRole.setNew(false);
310                    }
311                    catch (Exception e) {
312                            throw processException(e);
313                    }
314                    finally {
315                            closeSession(session);
316                    }
317    
318                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
319    
320                    if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
321                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
322                    }
323    
324                    else {
325                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
326                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
327                                    Object[] args = new Object[] {
328                                                    Long.valueOf(orgGroupRoleModelImpl.getOriginalGroupId())
329                                            };
330    
331                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
332                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
333                                            args);
334    
335                                    args = new Object[] {
336                                                    Long.valueOf(orgGroupRoleModelImpl.getGroupId())
337                                            };
338    
339                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
340                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
341                                            args);
342                            }
343    
344                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
345                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
346                                    Object[] args = new Object[] {
347                                                    Long.valueOf(orgGroupRoleModelImpl.getOriginalRoleId())
348                                            };
349    
350                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
351                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
352                                            args);
353    
354                                    args = new Object[] {
355                                                    Long.valueOf(orgGroupRoleModelImpl.getRoleId())
356                                            };
357    
358                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
359                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
360                                            args);
361                            }
362                    }
363    
364                    EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
365                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
366    
367                    return orgGroupRole;
368            }
369    
370            protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
371                    if (orgGroupRole instanceof OrgGroupRoleImpl) {
372                            return orgGroupRole;
373                    }
374    
375                    OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
376    
377                    orgGroupRoleImpl.setNew(orgGroupRole.isNew());
378                    orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
379    
380                    orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
381                    orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
382                    orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
383    
384                    return orgGroupRoleImpl;
385            }
386    
387            /**
388             * Returns the org group role with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
389             *
390             * @param primaryKey the primary key of the org group role
391             * @return the org group role
392             * @throws com.liferay.portal.NoSuchModelException if a org group role with the primary key could not be found
393             * @throws SystemException if a system exception occurred
394             */
395            @Override
396            public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
397                    throws NoSuchModelException, SystemException {
398                    return findByPrimaryKey((OrgGroupRolePK)primaryKey);
399            }
400    
401            /**
402             * Returns the org group role with the primary key or throws a {@link com.liferay.portal.NoSuchOrgGroupRoleException} if it could not be found.
403             *
404             * @param orgGroupRolePK the primary key of the org group role
405             * @return the org group role
406             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
407             * @throws SystemException if a system exception occurred
408             */
409            public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
410                    throws NoSuchOrgGroupRoleException, SystemException {
411                    OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
412    
413                    if (orgGroupRole == null) {
414                            if (_log.isWarnEnabled()) {
415                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
416                            }
417    
418                            throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
419                                    orgGroupRolePK);
420                    }
421    
422                    return orgGroupRole;
423            }
424    
425            /**
426             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
427             *
428             * @param primaryKey the primary key of the org group role
429             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
430             * @throws SystemException if a system exception occurred
431             */
432            @Override
433            public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
434                    throws SystemException {
435                    return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
436            }
437    
438            /**
439             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
440             *
441             * @param orgGroupRolePK the primary key of the org group role
442             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
443             * @throws SystemException if a system exception occurred
444             */
445            public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
446                    throws SystemException {
447                    OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
448                                    OrgGroupRoleImpl.class, orgGroupRolePK);
449    
450                    if (orgGroupRole == _nullOrgGroupRole) {
451                            return null;
452                    }
453    
454                    if (orgGroupRole == null) {
455                            Session session = null;
456    
457                            boolean hasException = false;
458    
459                            try {
460                                    session = openSession();
461    
462                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
463                                                    orgGroupRolePK);
464                            }
465                            catch (Exception e) {
466                                    hasException = true;
467    
468                                    throw processException(e);
469                            }
470                            finally {
471                                    if (orgGroupRole != null) {
472                                            cacheResult(orgGroupRole);
473                                    }
474                                    else if (!hasException) {
475                                            EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
476                                                    OrgGroupRoleImpl.class, orgGroupRolePK,
477                                                    _nullOrgGroupRole);
478                                    }
479    
480                                    closeSession(session);
481                            }
482                    }
483    
484                    return orgGroupRole;
485            }
486    
487            /**
488             * Returns all the org group roles where groupId = &#63;.
489             *
490             * @param groupId the group ID
491             * @return the matching org group roles
492             * @throws SystemException if a system exception occurred
493             */
494            public List<OrgGroupRole> findByGroupId(long groupId)
495                    throws SystemException {
496                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
497            }
498    
499            /**
500             * Returns a range of all the org group roles where groupId = &#63;.
501             *
502             * <p>
503             * 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.
504             * </p>
505             *
506             * @param groupId the group ID
507             * @param start the lower bound of the range of org group roles
508             * @param end the upper bound of the range of org group roles (not inclusive)
509             * @return the range of matching org group roles
510             * @throws SystemException if a system exception occurred
511             */
512            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
513                    throws SystemException {
514                    return findByGroupId(groupId, start, end, null);
515            }
516    
517            /**
518             * Returns an ordered range of all the org group roles where groupId = &#63;.
519             *
520             * <p>
521             * 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.
522             * </p>
523             *
524             * @param groupId the group ID
525             * @param start the lower bound of the range of org group roles
526             * @param end the upper bound of the range of org group roles (not inclusive)
527             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
528             * @return the ordered range of matching org group roles
529             * @throws SystemException if a system exception occurred
530             */
531            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
532                    OrderByComparator orderByComparator) throws SystemException {
533                    FinderPath finderPath = null;
534                    Object[] finderArgs = null;
535    
536                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
537                                    (orderByComparator == null)) {
538                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
539                            finderArgs = new Object[] { groupId };
540                    }
541                    else {
542                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
543                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
544                    }
545    
546                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
547                                    finderArgs, this);
548    
549                    if ((list != null) && !list.isEmpty()) {
550                            for (OrgGroupRole orgGroupRole : list) {
551                                    if ((groupId != orgGroupRole.getGroupId())) {
552                                            list = null;
553    
554                                            break;
555                                    }
556                            }
557                    }
558    
559                    if (list == null) {
560                            StringBundler query = null;
561    
562                            if (orderByComparator != null) {
563                                    query = new StringBundler(3 +
564                                                    (orderByComparator.getOrderByFields().length * 3));
565                            }
566                            else {
567                                    query = new StringBundler(2);
568                            }
569    
570                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
571    
572                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
573    
574                            if (orderByComparator != null) {
575                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
576                                            orderByComparator);
577                            }
578    
579                            String sql = query.toString();
580    
581                            Session session = null;
582    
583                            try {
584                                    session = openSession();
585    
586                                    Query q = session.createQuery(sql);
587    
588                                    QueryPos qPos = QueryPos.getInstance(q);
589    
590                                    qPos.add(groupId);
591    
592                                    list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
593                                                    start, end);
594                            }
595                            catch (Exception e) {
596                                    throw processException(e);
597                            }
598                            finally {
599                                    if (list == null) {
600                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
601                                    }
602                                    else {
603                                            cacheResult(list);
604    
605                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
606                                    }
607    
608                                    closeSession(session);
609                            }
610                    }
611    
612                    return list;
613            }
614    
615            /**
616             * Returns the first org group role in the ordered set where groupId = &#63;.
617             *
618             * @param groupId the group ID
619             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
620             * @return the first matching org group role
621             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
622             * @throws SystemException if a system exception occurred
623             */
624            public OrgGroupRole findByGroupId_First(long groupId,
625                    OrderByComparator orderByComparator)
626                    throws NoSuchOrgGroupRoleException, SystemException {
627                    OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
628                                    orderByComparator);
629    
630                    if (orgGroupRole != null) {
631                            return orgGroupRole;
632                    }
633    
634                    StringBundler msg = new StringBundler(4);
635    
636                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
637    
638                    msg.append("groupId=");
639                    msg.append(groupId);
640    
641                    msg.append(StringPool.CLOSE_CURLY_BRACE);
642    
643                    throw new NoSuchOrgGroupRoleException(msg.toString());
644            }
645    
646            /**
647             * Returns the first org group role in the ordered set where groupId = &#63;.
648             *
649             * @param groupId the group ID
650             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
651             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
652             * @throws SystemException if a system exception occurred
653             */
654            public OrgGroupRole fetchByGroupId_First(long groupId,
655                    OrderByComparator orderByComparator) throws SystemException {
656                    List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
657    
658                    if (!list.isEmpty()) {
659                            return list.get(0);
660                    }
661    
662                    return null;
663            }
664    
665            /**
666             * Returns the last org group role in the ordered set where groupId = &#63;.
667             *
668             * @param groupId the group ID
669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
670             * @return the last matching org group role
671             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
672             * @throws SystemException if a system exception occurred
673             */
674            public OrgGroupRole findByGroupId_Last(long groupId,
675                    OrderByComparator orderByComparator)
676                    throws NoSuchOrgGroupRoleException, SystemException {
677                    OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
678                                    orderByComparator);
679    
680                    if (orgGroupRole != null) {
681                            return orgGroupRole;
682                    }
683    
684                    StringBundler msg = new StringBundler(4);
685    
686                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
687    
688                    msg.append("groupId=");
689                    msg.append(groupId);
690    
691                    msg.append(StringPool.CLOSE_CURLY_BRACE);
692    
693                    throw new NoSuchOrgGroupRoleException(msg.toString());
694            }
695    
696            /**
697             * Returns the last org group role in the ordered set where groupId = &#63;.
698             *
699             * @param groupId the group ID
700             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
701             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
702             * @throws SystemException if a system exception occurred
703             */
704            public OrgGroupRole fetchByGroupId_Last(long groupId,
705                    OrderByComparator orderByComparator) throws SystemException {
706                    int count = countByGroupId(groupId);
707    
708                    List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
709                                    orderByComparator);
710    
711                    if (!list.isEmpty()) {
712                            return list.get(0);
713                    }
714    
715                    return null;
716            }
717    
718            /**
719             * Returns the org group roles before and after the current org group role in the ordered set where groupId = &#63;.
720             *
721             * @param orgGroupRolePK the primary key of the current org group role
722             * @param groupId the group ID
723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
724             * @return the previous, current, and next org group role
725             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
726             * @throws SystemException if a system exception occurred
727             */
728            public OrgGroupRole[] findByGroupId_PrevAndNext(
729                    OrgGroupRolePK orgGroupRolePK, long groupId,
730                    OrderByComparator orderByComparator)
731                    throws NoSuchOrgGroupRoleException, SystemException {
732                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
733    
734                    Session session = null;
735    
736                    try {
737                            session = openSession();
738    
739                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
740    
741                            array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
742                                            orderByComparator, true);
743    
744                            array[1] = orgGroupRole;
745    
746                            array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
747                                            orderByComparator, false);
748    
749                            return array;
750                    }
751                    catch (Exception e) {
752                            throw processException(e);
753                    }
754                    finally {
755                            closeSession(session);
756                    }
757            }
758    
759            protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
760                    OrgGroupRole orgGroupRole, long groupId,
761                    OrderByComparator orderByComparator, boolean previous) {
762                    StringBundler query = null;
763    
764                    if (orderByComparator != null) {
765                            query = new StringBundler(6 +
766                                            (orderByComparator.getOrderByFields().length * 6));
767                    }
768                    else {
769                            query = new StringBundler(3);
770                    }
771    
772                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
773    
774                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
775    
776                    if (orderByComparator != null) {
777                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
778    
779                            if (orderByConditionFields.length > 0) {
780                                    query.append(WHERE_AND);
781                            }
782    
783                            for (int i = 0; i < orderByConditionFields.length; i++) {
784                                    query.append(_ORDER_BY_ENTITY_ALIAS);
785                                    query.append(orderByConditionFields[i]);
786    
787                                    if ((i + 1) < orderByConditionFields.length) {
788                                            if (orderByComparator.isAscending() ^ previous) {
789                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
790                                            }
791                                            else {
792                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
793                                            }
794                                    }
795                                    else {
796                                            if (orderByComparator.isAscending() ^ previous) {
797                                                    query.append(WHERE_GREATER_THAN);
798                                            }
799                                            else {
800                                                    query.append(WHERE_LESSER_THAN);
801                                            }
802                                    }
803                            }
804    
805                            query.append(ORDER_BY_CLAUSE);
806    
807                            String[] orderByFields = orderByComparator.getOrderByFields();
808    
809                            for (int i = 0; i < orderByFields.length; i++) {
810                                    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                    String sql = query.toString();
833    
834                    Query q = session.createQuery(sql);
835    
836                    q.setFirstResult(0);
837                    q.setMaxResults(2);
838    
839                    QueryPos qPos = QueryPos.getInstance(q);
840    
841                    qPos.add(groupId);
842    
843                    if (orderByComparator != null) {
844                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
845    
846                            for (Object value : values) {
847                                    qPos.add(value);
848                            }
849                    }
850    
851                    List<OrgGroupRole> list = q.list();
852    
853                    if (list.size() == 2) {
854                            return list.get(1);
855                    }
856                    else {
857                            return null;
858                    }
859            }
860    
861            /**
862             * Returns all the org group roles where roleId = &#63;.
863             *
864             * @param roleId the role ID
865             * @return the matching org group roles
866             * @throws SystemException if a system exception occurred
867             */
868            public List<OrgGroupRole> findByRoleId(long roleId)
869                    throws SystemException {
870                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
871            }
872    
873            /**
874             * Returns a range of all the org group roles where roleId = &#63;.
875             *
876             * <p>
877             * 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.
878             * </p>
879             *
880             * @param roleId the role ID
881             * @param start the lower bound of the range of org group roles
882             * @param end the upper bound of the range of org group roles (not inclusive)
883             * @return the range of matching org group roles
884             * @throws SystemException if a system exception occurred
885             */
886            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
887                    throws SystemException {
888                    return findByRoleId(roleId, start, end, null);
889            }
890    
891            /**
892             * Returns an ordered range of all the org group roles where roleId = &#63;.
893             *
894             * <p>
895             * 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.
896             * </p>
897             *
898             * @param roleId the role ID
899             * @param start the lower bound of the range of org group roles
900             * @param end the upper bound of the range of org group roles (not inclusive)
901             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
902             * @return the ordered range of matching org group roles
903             * @throws SystemException if a system exception occurred
904             */
905            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
906                    OrderByComparator orderByComparator) throws SystemException {
907                    FinderPath finderPath = null;
908                    Object[] finderArgs = null;
909    
910                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
911                                    (orderByComparator == null)) {
912                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
913                            finderArgs = new Object[] { roleId };
914                    }
915                    else {
916                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
917                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
918                    }
919    
920                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
921                                    finderArgs, this);
922    
923                    if ((list != null) && !list.isEmpty()) {
924                            for (OrgGroupRole orgGroupRole : list) {
925                                    if ((roleId != orgGroupRole.getRoleId())) {
926                                            list = null;
927    
928                                            break;
929                                    }
930                            }
931                    }
932    
933                    if (list == null) {
934                            StringBundler query = null;
935    
936                            if (orderByComparator != null) {
937                                    query = new StringBundler(3 +
938                                                    (orderByComparator.getOrderByFields().length * 3));
939                            }
940                            else {
941                                    query = new StringBundler(2);
942                            }
943    
944                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
945    
946                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
947    
948                            if (orderByComparator != null) {
949                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
950                                            orderByComparator);
951                            }
952    
953                            String sql = query.toString();
954    
955                            Session session = null;
956    
957                            try {
958                                    session = openSession();
959    
960                                    Query q = session.createQuery(sql);
961    
962                                    QueryPos qPos = QueryPos.getInstance(q);
963    
964                                    qPos.add(roleId);
965    
966                                    list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
967                                                    start, end);
968                            }
969                            catch (Exception e) {
970                                    throw processException(e);
971                            }
972                            finally {
973                                    if (list == null) {
974                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
975                                    }
976                                    else {
977                                            cacheResult(list);
978    
979                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
980                                    }
981    
982                                    closeSession(session);
983                            }
984                    }
985    
986                    return list;
987            }
988    
989            /**
990             * Returns the first org group role in the ordered set where roleId = &#63;.
991             *
992             * @param roleId the role ID
993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
994             * @return the first matching org group role
995             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
996             * @throws SystemException if a system exception occurred
997             */
998            public OrgGroupRole findByRoleId_First(long roleId,
999                    OrderByComparator orderByComparator)
1000                    throws NoSuchOrgGroupRoleException, SystemException {
1001                    OrgGroupRole orgGroupRole = fetchByRoleId_First(roleId,
1002                                    orderByComparator);
1003    
1004                    if (orgGroupRole != null) {
1005                            return orgGroupRole;
1006                    }
1007    
1008                    StringBundler msg = new StringBundler(4);
1009    
1010                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1011    
1012                    msg.append("roleId=");
1013                    msg.append(roleId);
1014    
1015                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1016    
1017                    throw new NoSuchOrgGroupRoleException(msg.toString());
1018            }
1019    
1020            /**
1021             * Returns the first org group role in the ordered set where roleId = &#63;.
1022             *
1023             * @param roleId the role ID
1024             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1025             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
1026             * @throws SystemException if a system exception occurred
1027             */
1028            public OrgGroupRole fetchByRoleId_First(long roleId,
1029                    OrderByComparator orderByComparator) throws SystemException {
1030                    List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1031    
1032                    if (!list.isEmpty()) {
1033                            return list.get(0);
1034                    }
1035    
1036                    return null;
1037            }
1038    
1039            /**
1040             * Returns the last org group role in the ordered set where roleId = &#63;.
1041             *
1042             * @param roleId the role ID
1043             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1044             * @return the last matching org group role
1045             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
1046             * @throws SystemException if a system exception occurred
1047             */
1048            public OrgGroupRole findByRoleId_Last(long roleId,
1049                    OrderByComparator orderByComparator)
1050                    throws NoSuchOrgGroupRoleException, SystemException {
1051                    OrgGroupRole orgGroupRole = fetchByRoleId_Last(roleId, orderByComparator);
1052    
1053                    if (orgGroupRole != null) {
1054                            return orgGroupRole;
1055                    }
1056    
1057                    StringBundler msg = new StringBundler(4);
1058    
1059                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1060    
1061                    msg.append("roleId=");
1062                    msg.append(roleId);
1063    
1064                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1065    
1066                    throw new NoSuchOrgGroupRoleException(msg.toString());
1067            }
1068    
1069            /**
1070             * Returns the last org group role in the ordered set where roleId = &#63;.
1071             *
1072             * @param roleId the role ID
1073             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1074             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
1075             * @throws SystemException if a system exception occurred
1076             */
1077            public OrgGroupRole fetchByRoleId_Last(long roleId,
1078                    OrderByComparator orderByComparator) throws SystemException {
1079                    int count = countByRoleId(roleId);
1080    
1081                    List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
1082                                    orderByComparator);
1083    
1084                    if (!list.isEmpty()) {
1085                            return list.get(0);
1086                    }
1087    
1088                    return null;
1089            }
1090    
1091            /**
1092             * Returns the org group roles before and after the current org group role in the ordered set where roleId = &#63;.
1093             *
1094             * @param orgGroupRolePK the primary key of the current org group role
1095             * @param roleId the role ID
1096             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1097             * @return the previous, current, and next org group role
1098             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1099             * @throws SystemException if a system exception occurred
1100             */
1101            public OrgGroupRole[] findByRoleId_PrevAndNext(
1102                    OrgGroupRolePK orgGroupRolePK, long roleId,
1103                    OrderByComparator orderByComparator)
1104                    throws NoSuchOrgGroupRoleException, SystemException {
1105                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
1106    
1107                    Session session = null;
1108    
1109                    try {
1110                            session = openSession();
1111    
1112                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
1113    
1114                            array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
1115                                            orderByComparator, true);
1116    
1117                            array[1] = orgGroupRole;
1118    
1119                            array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
1120                                            orderByComparator, false);
1121    
1122                            return array;
1123                    }
1124                    catch (Exception e) {
1125                            throw processException(e);
1126                    }
1127                    finally {
1128                            closeSession(session);
1129                    }
1130            }
1131    
1132            protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
1133                    OrgGroupRole orgGroupRole, long roleId,
1134                    OrderByComparator orderByComparator, boolean previous) {
1135                    StringBundler query = null;
1136    
1137                    if (orderByComparator != null) {
1138                            query = new StringBundler(6 +
1139                                            (orderByComparator.getOrderByFields().length * 6));
1140                    }
1141                    else {
1142                            query = new StringBundler(3);
1143                    }
1144    
1145                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
1146    
1147                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1148    
1149                    if (orderByComparator != null) {
1150                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1151    
1152                            if (orderByConditionFields.length > 0) {
1153                                    query.append(WHERE_AND);
1154                            }
1155    
1156                            for (int i = 0; i < orderByConditionFields.length; i++) {
1157                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1158                                    query.append(orderByConditionFields[i]);
1159    
1160                                    if ((i + 1) < orderByConditionFields.length) {
1161                                            if (orderByComparator.isAscending() ^ previous) {
1162                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1163                                            }
1164                                            else {
1165                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1166                                            }
1167                                    }
1168                                    else {
1169                                            if (orderByComparator.isAscending() ^ previous) {
1170                                                    query.append(WHERE_GREATER_THAN);
1171                                            }
1172                                            else {
1173                                                    query.append(WHERE_LESSER_THAN);
1174                                            }
1175                                    }
1176                            }
1177    
1178                            query.append(ORDER_BY_CLAUSE);
1179    
1180                            String[] orderByFields = orderByComparator.getOrderByFields();
1181    
1182                            for (int i = 0; i < orderByFields.length; i++) {
1183                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1184                                    query.append(orderByFields[i]);
1185    
1186                                    if ((i + 1) < orderByFields.length) {
1187                                            if (orderByComparator.isAscending() ^ previous) {
1188                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1189                                            }
1190                                            else {
1191                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1192                                            }
1193                                    }
1194                                    else {
1195                                            if (orderByComparator.isAscending() ^ previous) {
1196                                                    query.append(ORDER_BY_ASC);
1197                                            }
1198                                            else {
1199                                                    query.append(ORDER_BY_DESC);
1200                                            }
1201                                    }
1202                            }
1203                    }
1204    
1205                    String sql = query.toString();
1206    
1207                    Query q = session.createQuery(sql);
1208    
1209                    q.setFirstResult(0);
1210                    q.setMaxResults(2);
1211    
1212                    QueryPos qPos = QueryPos.getInstance(q);
1213    
1214                    qPos.add(roleId);
1215    
1216                    if (orderByComparator != null) {
1217                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
1218    
1219                            for (Object value : values) {
1220                                    qPos.add(value);
1221                            }
1222                    }
1223    
1224                    List<OrgGroupRole> list = q.list();
1225    
1226                    if (list.size() == 2) {
1227                            return list.get(1);
1228                    }
1229                    else {
1230                            return null;
1231                    }
1232            }
1233    
1234            /**
1235             * Returns all the org group roles.
1236             *
1237             * @return the org group roles
1238             * @throws SystemException if a system exception occurred
1239             */
1240            public List<OrgGroupRole> findAll() throws SystemException {
1241                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1242            }
1243    
1244            /**
1245             * Returns a range of all the org group roles.
1246             *
1247             * <p>
1248             * 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.
1249             * </p>
1250             *
1251             * @param start the lower bound of the range of org group roles
1252             * @param end the upper bound of the range of org group roles (not inclusive)
1253             * @return the range of org group roles
1254             * @throws SystemException if a system exception occurred
1255             */
1256            public List<OrgGroupRole> findAll(int start, int end)
1257                    throws SystemException {
1258                    return findAll(start, end, null);
1259            }
1260    
1261            /**
1262             * Returns an ordered range of all the org group roles.
1263             *
1264             * <p>
1265             * 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.
1266             * </p>
1267             *
1268             * @param start the lower bound of the range of org group roles
1269             * @param end the upper bound of the range of org group roles (not inclusive)
1270             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1271             * @return the ordered range of org group roles
1272             * @throws SystemException if a system exception occurred
1273             */
1274            public List<OrgGroupRole> findAll(int start, int end,
1275                    OrderByComparator orderByComparator) throws SystemException {
1276                    FinderPath finderPath = null;
1277                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1278    
1279                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1280                                    (orderByComparator == null)) {
1281                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1282                            finderArgs = FINDER_ARGS_EMPTY;
1283                    }
1284                    else {
1285                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1286                            finderArgs = new Object[] { start, end, orderByComparator };
1287                    }
1288    
1289                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1290                                    finderArgs, this);
1291    
1292                    if (list == null) {
1293                            StringBundler query = null;
1294                            String sql = null;
1295    
1296                            if (orderByComparator != null) {
1297                                    query = new StringBundler(2 +
1298                                                    (orderByComparator.getOrderByFields().length * 3));
1299    
1300                                    query.append(_SQL_SELECT_ORGGROUPROLE);
1301    
1302                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1303                                            orderByComparator);
1304    
1305                                    sql = query.toString();
1306                            }
1307                            else {
1308                                    sql = _SQL_SELECT_ORGGROUPROLE;
1309                            }
1310    
1311                            Session session = null;
1312    
1313                            try {
1314                                    session = openSession();
1315    
1316                                    Query q = session.createQuery(sql);
1317    
1318                                    if (orderByComparator == null) {
1319                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1320                                                            start, end, false);
1321    
1322                                            Collections.sort(list);
1323                                    }
1324                                    else {
1325                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1326                                                            start, end);
1327                                    }
1328                            }
1329                            catch (Exception e) {
1330                                    throw processException(e);
1331                            }
1332                            finally {
1333                                    if (list == null) {
1334                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1335                                    }
1336                                    else {
1337                                            cacheResult(list);
1338    
1339                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1340                                    }
1341    
1342                                    closeSession(session);
1343                            }
1344                    }
1345    
1346                    return list;
1347            }
1348    
1349            /**
1350             * Removes all the org group roles where groupId = &#63; from the database.
1351             *
1352             * @param groupId the group ID
1353             * @throws SystemException if a system exception occurred
1354             */
1355            public void removeByGroupId(long groupId) throws SystemException {
1356                    for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
1357                            remove(orgGroupRole);
1358                    }
1359            }
1360    
1361            /**
1362             * Removes all the org group roles where roleId = &#63; from the database.
1363             *
1364             * @param roleId the role ID
1365             * @throws SystemException if a system exception occurred
1366             */
1367            public void removeByRoleId(long roleId) throws SystemException {
1368                    for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
1369                            remove(orgGroupRole);
1370                    }
1371            }
1372    
1373            /**
1374             * Removes all the org group roles from the database.
1375             *
1376             * @throws SystemException if a system exception occurred
1377             */
1378            public void removeAll() throws SystemException {
1379                    for (OrgGroupRole orgGroupRole : findAll()) {
1380                            remove(orgGroupRole);
1381                    }
1382            }
1383    
1384            /**
1385             * Returns the number of org group roles where groupId = &#63;.
1386             *
1387             * @param groupId the group ID
1388             * @return the number of matching org group roles
1389             * @throws SystemException if a system exception occurred
1390             */
1391            public int countByGroupId(long groupId) throws SystemException {
1392                    Object[] finderArgs = new Object[] { groupId };
1393    
1394                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1395                                    finderArgs, this);
1396    
1397                    if (count == null) {
1398                            StringBundler query = new StringBundler(2);
1399    
1400                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1401    
1402                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1403    
1404                            String sql = query.toString();
1405    
1406                            Session session = null;
1407    
1408                            try {
1409                                    session = openSession();
1410    
1411                                    Query q = session.createQuery(sql);
1412    
1413                                    QueryPos qPos = QueryPos.getInstance(q);
1414    
1415                                    qPos.add(groupId);
1416    
1417                                    count = (Long)q.uniqueResult();
1418                            }
1419                            catch (Exception e) {
1420                                    throw processException(e);
1421                            }
1422                            finally {
1423                                    if (count == null) {
1424                                            count = Long.valueOf(0);
1425                                    }
1426    
1427                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1428                                            finderArgs, count);
1429    
1430                                    closeSession(session);
1431                            }
1432                    }
1433    
1434                    return count.intValue();
1435            }
1436    
1437            /**
1438             * Returns the number of org group roles where roleId = &#63;.
1439             *
1440             * @param roleId the role ID
1441             * @return the number of matching org group roles
1442             * @throws SystemException if a system exception occurred
1443             */
1444            public int countByRoleId(long roleId) throws SystemException {
1445                    Object[] finderArgs = new Object[] { roleId };
1446    
1447                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1448                                    finderArgs, this);
1449    
1450                    if (count == null) {
1451                            StringBundler query = new StringBundler(2);
1452    
1453                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1454    
1455                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1456    
1457                            String sql = query.toString();
1458    
1459                            Session session = null;
1460    
1461                            try {
1462                                    session = openSession();
1463    
1464                                    Query q = session.createQuery(sql);
1465    
1466                                    QueryPos qPos = QueryPos.getInstance(q);
1467    
1468                                    qPos.add(roleId);
1469    
1470                                    count = (Long)q.uniqueResult();
1471                            }
1472                            catch (Exception e) {
1473                                    throw processException(e);
1474                            }
1475                            finally {
1476                                    if (count == null) {
1477                                            count = Long.valueOf(0);
1478                                    }
1479    
1480                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1481                                            finderArgs, count);
1482    
1483                                    closeSession(session);
1484                            }
1485                    }
1486    
1487                    return count.intValue();
1488            }
1489    
1490            /**
1491             * Returns the number of org group roles.
1492             *
1493             * @return the number of org group roles
1494             * @throws SystemException if a system exception occurred
1495             */
1496            public int countAll() throws SystemException {
1497                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1498                                    FINDER_ARGS_EMPTY, this);
1499    
1500                    if (count == null) {
1501                            Session session = null;
1502    
1503                            try {
1504                                    session = openSession();
1505    
1506                                    Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1507    
1508                                    count = (Long)q.uniqueResult();
1509                            }
1510                            catch (Exception e) {
1511                                    throw processException(e);
1512                            }
1513                            finally {
1514                                    if (count == null) {
1515                                            count = Long.valueOf(0);
1516                                    }
1517    
1518                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1519                                            FINDER_ARGS_EMPTY, count);
1520    
1521                                    closeSession(session);
1522                            }
1523                    }
1524    
1525                    return count.intValue();
1526            }
1527    
1528            /**
1529             * Initializes the org group role persistence.
1530             */
1531            public void afterPropertiesSet() {
1532                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1533                                            com.liferay.portal.util.PropsUtil.get(
1534                                                    "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1535    
1536                    if (listenerClassNames.length > 0) {
1537                            try {
1538                                    List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1539    
1540                                    for (String listenerClassName : listenerClassNames) {
1541                                            Class<?> clazz = getClass();
1542    
1543                                            listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1544                                                            clazz.getClassLoader(), listenerClassName));
1545                                    }
1546    
1547                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1548                            }
1549                            catch (Exception e) {
1550                                    _log.error(e);
1551                            }
1552                    }
1553            }
1554    
1555            public void destroy() {
1556                    EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1557                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1558                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1559            }
1560    
1561            @BeanReference(type = AccountPersistence.class)
1562            protected AccountPersistence accountPersistence;
1563            @BeanReference(type = AddressPersistence.class)
1564            protected AddressPersistence addressPersistence;
1565            @BeanReference(type = BrowserTrackerPersistence.class)
1566            protected BrowserTrackerPersistence browserTrackerPersistence;
1567            @BeanReference(type = ClassNamePersistence.class)
1568            protected ClassNamePersistence classNamePersistence;
1569            @BeanReference(type = ClusterGroupPersistence.class)
1570            protected ClusterGroupPersistence clusterGroupPersistence;
1571            @BeanReference(type = CompanyPersistence.class)
1572            protected CompanyPersistence companyPersistence;
1573            @BeanReference(type = ContactPersistence.class)
1574            protected ContactPersistence contactPersistence;
1575            @BeanReference(type = CountryPersistence.class)
1576            protected CountryPersistence countryPersistence;
1577            @BeanReference(type = EmailAddressPersistence.class)
1578            protected EmailAddressPersistence emailAddressPersistence;
1579            @BeanReference(type = GroupPersistence.class)
1580            protected GroupPersistence groupPersistence;
1581            @BeanReference(type = ImagePersistence.class)
1582            protected ImagePersistence imagePersistence;
1583            @BeanReference(type = LayoutPersistence.class)
1584            protected LayoutPersistence layoutPersistence;
1585            @BeanReference(type = LayoutBranchPersistence.class)
1586            protected LayoutBranchPersistence layoutBranchPersistence;
1587            @BeanReference(type = LayoutPrototypePersistence.class)
1588            protected LayoutPrototypePersistence layoutPrototypePersistence;
1589            @BeanReference(type = LayoutRevisionPersistence.class)
1590            protected LayoutRevisionPersistence layoutRevisionPersistence;
1591            @BeanReference(type = LayoutSetPersistence.class)
1592            protected LayoutSetPersistence layoutSetPersistence;
1593            @BeanReference(type = LayoutSetBranchPersistence.class)
1594            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1595            @BeanReference(type = LayoutSetPrototypePersistence.class)
1596            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1597            @BeanReference(type = ListTypePersistence.class)
1598            protected ListTypePersistence listTypePersistence;
1599            @BeanReference(type = LockPersistence.class)
1600            protected LockPersistence lockPersistence;
1601            @BeanReference(type = MembershipRequestPersistence.class)
1602            protected MembershipRequestPersistence membershipRequestPersistence;
1603            @BeanReference(type = OrganizationPersistence.class)
1604            protected OrganizationPersistence organizationPersistence;
1605            @BeanReference(type = OrgGroupPermissionPersistence.class)
1606            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1607            @BeanReference(type = OrgGroupRolePersistence.class)
1608            protected OrgGroupRolePersistence orgGroupRolePersistence;
1609            @BeanReference(type = OrgLaborPersistence.class)
1610            protected OrgLaborPersistence orgLaborPersistence;
1611            @BeanReference(type = PasswordPolicyPersistence.class)
1612            protected PasswordPolicyPersistence passwordPolicyPersistence;
1613            @BeanReference(type = PasswordPolicyRelPersistence.class)
1614            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1615            @BeanReference(type = PasswordTrackerPersistence.class)
1616            protected PasswordTrackerPersistence passwordTrackerPersistence;
1617            @BeanReference(type = PermissionPersistence.class)
1618            protected PermissionPersistence permissionPersistence;
1619            @BeanReference(type = PhonePersistence.class)
1620            protected PhonePersistence phonePersistence;
1621            @BeanReference(type = PluginSettingPersistence.class)
1622            protected PluginSettingPersistence pluginSettingPersistence;
1623            @BeanReference(type = PortalPreferencesPersistence.class)
1624            protected PortalPreferencesPersistence portalPreferencesPersistence;
1625            @BeanReference(type = PortletPersistence.class)
1626            protected PortletPersistence portletPersistence;
1627            @BeanReference(type = PortletItemPersistence.class)
1628            protected PortletItemPersistence portletItemPersistence;
1629            @BeanReference(type = PortletPreferencesPersistence.class)
1630            protected PortletPreferencesPersistence portletPreferencesPersistence;
1631            @BeanReference(type = RegionPersistence.class)
1632            protected RegionPersistence regionPersistence;
1633            @BeanReference(type = ReleasePersistence.class)
1634            protected ReleasePersistence releasePersistence;
1635            @BeanReference(type = RepositoryPersistence.class)
1636            protected RepositoryPersistence repositoryPersistence;
1637            @BeanReference(type = RepositoryEntryPersistence.class)
1638            protected RepositoryEntryPersistence repositoryEntryPersistence;
1639            @BeanReference(type = ResourcePersistence.class)
1640            protected ResourcePersistence resourcePersistence;
1641            @BeanReference(type = ResourceActionPersistence.class)
1642            protected ResourceActionPersistence resourceActionPersistence;
1643            @BeanReference(type = ResourceBlockPersistence.class)
1644            protected ResourceBlockPersistence resourceBlockPersistence;
1645            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1646            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1647            @BeanReference(type = ResourceCodePersistence.class)
1648            protected ResourceCodePersistence resourceCodePersistence;
1649            @BeanReference(type = ResourcePermissionPersistence.class)
1650            protected ResourcePermissionPersistence resourcePermissionPersistence;
1651            @BeanReference(type = ResourceTypePermissionPersistence.class)
1652            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1653            @BeanReference(type = RolePersistence.class)
1654            protected RolePersistence rolePersistence;
1655            @BeanReference(type = ServiceComponentPersistence.class)
1656            protected ServiceComponentPersistence serviceComponentPersistence;
1657            @BeanReference(type = ShardPersistence.class)
1658            protected ShardPersistence shardPersistence;
1659            @BeanReference(type = SubscriptionPersistence.class)
1660            protected SubscriptionPersistence subscriptionPersistence;
1661            @BeanReference(type = TeamPersistence.class)
1662            protected TeamPersistence teamPersistence;
1663            @BeanReference(type = TicketPersistence.class)
1664            protected TicketPersistence ticketPersistence;
1665            @BeanReference(type = UserPersistence.class)
1666            protected UserPersistence userPersistence;
1667            @BeanReference(type = UserGroupPersistence.class)
1668            protected UserGroupPersistence userGroupPersistence;
1669            @BeanReference(type = UserGroupGroupRolePersistence.class)
1670            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1671            @BeanReference(type = UserGroupRolePersistence.class)
1672            protected UserGroupRolePersistence userGroupRolePersistence;
1673            @BeanReference(type = UserIdMapperPersistence.class)
1674            protected UserIdMapperPersistence userIdMapperPersistence;
1675            @BeanReference(type = UserNotificationEventPersistence.class)
1676            protected UserNotificationEventPersistence userNotificationEventPersistence;
1677            @BeanReference(type = UserTrackerPersistence.class)
1678            protected UserTrackerPersistence userTrackerPersistence;
1679            @BeanReference(type = UserTrackerPathPersistence.class)
1680            protected UserTrackerPathPersistence userTrackerPathPersistence;
1681            @BeanReference(type = VirtualHostPersistence.class)
1682            protected VirtualHostPersistence virtualHostPersistence;
1683            @BeanReference(type = WebDAVPropsPersistence.class)
1684            protected WebDAVPropsPersistence webDAVPropsPersistence;
1685            @BeanReference(type = WebsitePersistence.class)
1686            protected WebsitePersistence websitePersistence;
1687            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1688            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1689            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1690            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1691            private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1692            private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1693            private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1694            private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1695            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
1696            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1697            private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1698            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1699            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1700            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1701            private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1702            private static OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1703                            @Override
1704                            public Object clone() {
1705                                    return this;
1706                            }
1707    
1708                            @Override
1709                            public CacheModel<OrgGroupRole> toCacheModel() {
1710                                    return _nullOrgGroupRoleCacheModel;
1711                            }
1712                    };
1713    
1714            private static CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new CacheModel<OrgGroupRole>() {
1715                            public OrgGroupRole toEntityModel() {
1716                                    return _nullOrgGroupRole;
1717                            }
1718                    };
1719    }