001    /**
002     * Copyright (c) 2000-2012 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                            if (orgGroupRole.isCachedModel()) {
279                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
280                                                    orgGroupRole.getPrimaryKeyObj());
281                            }
282    
283                            session.delete(orgGroupRole);
284                    }
285                    catch (Exception e) {
286                            throw processException(e);
287                    }
288                    finally {
289                            closeSession(session);
290                    }
291    
292                    clearCache(orgGroupRole);
293    
294                    return orgGroupRole;
295            }
296    
297            @Override
298            public OrgGroupRole updateImpl(
299                    com.liferay.portal.model.OrgGroupRole orgGroupRole)
300                    throws SystemException {
301                    orgGroupRole = toUnwrappedModel(orgGroupRole);
302    
303                    boolean isNew = orgGroupRole.isNew();
304    
305                    OrgGroupRoleModelImpl orgGroupRoleModelImpl = (OrgGroupRoleModelImpl)orgGroupRole;
306    
307                    Session session = null;
308    
309                    try {
310                            session = openSession();
311    
312                            if (orgGroupRole.isNew()) {
313                                    session.save(orgGroupRole);
314    
315                                    orgGroupRole.setNew(false);
316                            }
317                            else {
318                                    session.merge(orgGroupRole);
319                            }
320                    }
321                    catch (Exception e) {
322                            throw processException(e);
323                    }
324                    finally {
325                            closeSession(session);
326                    }
327    
328                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
329    
330                    if (isNew || !OrgGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
331                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
332                    }
333    
334                    else {
335                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
336                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
337                                    Object[] args = new Object[] {
338                                                    Long.valueOf(orgGroupRoleModelImpl.getOriginalGroupId())
339                                            };
340    
341                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
342                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
343                                            args);
344    
345                                    args = new Object[] {
346                                                    Long.valueOf(orgGroupRoleModelImpl.getGroupId())
347                                            };
348    
349                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
350                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
351                                            args);
352                            }
353    
354                            if ((orgGroupRoleModelImpl.getColumnBitmask() &
355                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
356                                    Object[] args = new Object[] {
357                                                    Long.valueOf(orgGroupRoleModelImpl.getOriginalRoleId())
358                                            };
359    
360                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
361                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
362                                            args);
363    
364                                    args = new Object[] {
365                                                    Long.valueOf(orgGroupRoleModelImpl.getRoleId())
366                                            };
367    
368                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
369                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
370                                            args);
371                            }
372                    }
373    
374                    EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
375                            OrgGroupRoleImpl.class, orgGroupRole.getPrimaryKey(), orgGroupRole);
376    
377                    return orgGroupRole;
378            }
379    
380            protected OrgGroupRole toUnwrappedModel(OrgGroupRole orgGroupRole) {
381                    if (orgGroupRole instanceof OrgGroupRoleImpl) {
382                            return orgGroupRole;
383                    }
384    
385                    OrgGroupRoleImpl orgGroupRoleImpl = new OrgGroupRoleImpl();
386    
387                    orgGroupRoleImpl.setNew(orgGroupRole.isNew());
388                    orgGroupRoleImpl.setPrimaryKey(orgGroupRole.getPrimaryKey());
389    
390                    orgGroupRoleImpl.setOrganizationId(orgGroupRole.getOrganizationId());
391                    orgGroupRoleImpl.setGroupId(orgGroupRole.getGroupId());
392                    orgGroupRoleImpl.setRoleId(orgGroupRole.getRoleId());
393    
394                    return orgGroupRoleImpl;
395            }
396    
397            /**
398             * Returns the org group role with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
399             *
400             * @param primaryKey the primary key of the org group role
401             * @return the org group role
402             * @throws com.liferay.portal.NoSuchModelException if a org group role with the primary key could not be found
403             * @throws SystemException if a system exception occurred
404             */
405            @Override
406            public OrgGroupRole findByPrimaryKey(Serializable primaryKey)
407                    throws NoSuchModelException, SystemException {
408                    return findByPrimaryKey((OrgGroupRolePK)primaryKey);
409            }
410    
411            /**
412             * Returns the org group role with the primary key or throws a {@link com.liferay.portal.NoSuchOrgGroupRoleException} if it could not be found.
413             *
414             * @param orgGroupRolePK the primary key of the org group role
415             * @return the org group role
416             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
417             * @throws SystemException if a system exception occurred
418             */
419            public OrgGroupRole findByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
420                    throws NoSuchOrgGroupRoleException, SystemException {
421                    OrgGroupRole orgGroupRole = fetchByPrimaryKey(orgGroupRolePK);
422    
423                    if (orgGroupRole == null) {
424                            if (_log.isWarnEnabled()) {
425                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + orgGroupRolePK);
426                            }
427    
428                            throw new NoSuchOrgGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
429                                    orgGroupRolePK);
430                    }
431    
432                    return orgGroupRole;
433            }
434    
435            /**
436             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
437             *
438             * @param primaryKey the primary key of the org group role
439             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
440             * @throws SystemException if a system exception occurred
441             */
442            @Override
443            public OrgGroupRole fetchByPrimaryKey(Serializable primaryKey)
444                    throws SystemException {
445                    return fetchByPrimaryKey((OrgGroupRolePK)primaryKey);
446            }
447    
448            /**
449             * Returns the org group role with the primary key or returns <code>null</code> if it could not be found.
450             *
451             * @param orgGroupRolePK the primary key of the org group role
452             * @return the org group role, or <code>null</code> if a org group role with the primary key could not be found
453             * @throws SystemException if a system exception occurred
454             */
455            public OrgGroupRole fetchByPrimaryKey(OrgGroupRolePK orgGroupRolePK)
456                    throws SystemException {
457                    OrgGroupRole orgGroupRole = (OrgGroupRole)EntityCacheUtil.getResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
458                                    OrgGroupRoleImpl.class, orgGroupRolePK);
459    
460                    if (orgGroupRole == _nullOrgGroupRole) {
461                            return null;
462                    }
463    
464                    if (orgGroupRole == null) {
465                            Session session = null;
466    
467                            boolean hasException = false;
468    
469                            try {
470                                    session = openSession();
471    
472                                    orgGroupRole = (OrgGroupRole)session.get(OrgGroupRoleImpl.class,
473                                                    orgGroupRolePK);
474                            }
475                            catch (Exception e) {
476                                    hasException = true;
477    
478                                    throw processException(e);
479                            }
480                            finally {
481                                    if (orgGroupRole != null) {
482                                            cacheResult(orgGroupRole);
483                                    }
484                                    else if (!hasException) {
485                                            EntityCacheUtil.putResult(OrgGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
486                                                    OrgGroupRoleImpl.class, orgGroupRolePK,
487                                                    _nullOrgGroupRole);
488                                    }
489    
490                                    closeSession(session);
491                            }
492                    }
493    
494                    return orgGroupRole;
495            }
496    
497            /**
498             * Returns all the org group roles where groupId = &#63;.
499             *
500             * @param groupId the group ID
501             * @return the matching org group roles
502             * @throws SystemException if a system exception occurred
503             */
504            public List<OrgGroupRole> findByGroupId(long groupId)
505                    throws SystemException {
506                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
507            }
508    
509            /**
510             * Returns a range of all the org group roles where groupId = &#63;.
511             *
512             * <p>
513             * 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.
514             * </p>
515             *
516             * @param groupId the group ID
517             * @param start the lower bound of the range of org group roles
518             * @param end the upper bound of the range of org group roles (not inclusive)
519             * @return the range of matching org group roles
520             * @throws SystemException if a system exception occurred
521             */
522            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end)
523                    throws SystemException {
524                    return findByGroupId(groupId, start, end, null);
525            }
526    
527            /**
528             * Returns an ordered range of all the org group roles where groupId = &#63;.
529             *
530             * <p>
531             * 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.
532             * </p>
533             *
534             * @param groupId the group ID
535             * @param start the lower bound of the range of org group roles
536             * @param end the upper bound of the range of org group roles (not inclusive)
537             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
538             * @return the ordered range of matching org group roles
539             * @throws SystemException if a system exception occurred
540             */
541            public List<OrgGroupRole> findByGroupId(long groupId, int start, int end,
542                    OrderByComparator orderByComparator) throws SystemException {
543                    FinderPath finderPath = null;
544                    Object[] finderArgs = null;
545    
546                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
547                                    (orderByComparator == null)) {
548                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
549                            finderArgs = new Object[] { groupId };
550                    }
551                    else {
552                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
553                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
554                    }
555    
556                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
557                                    finderArgs, this);
558    
559                    if ((list != null) && !list.isEmpty()) {
560                            for (OrgGroupRole orgGroupRole : list) {
561                                    if ((groupId != orgGroupRole.getGroupId())) {
562                                            list = null;
563    
564                                            break;
565                                    }
566                            }
567                    }
568    
569                    if (list == null) {
570                            StringBundler query = null;
571    
572                            if (orderByComparator != null) {
573                                    query = new StringBundler(3 +
574                                                    (orderByComparator.getOrderByFields().length * 3));
575                            }
576                            else {
577                                    query = new StringBundler(2);
578                            }
579    
580                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
581    
582                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
583    
584                            if (orderByComparator != null) {
585                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
586                                            orderByComparator);
587                            }
588    
589                            String sql = query.toString();
590    
591                            Session session = null;
592    
593                            try {
594                                    session = openSession();
595    
596                                    Query q = session.createQuery(sql);
597    
598                                    QueryPos qPos = QueryPos.getInstance(q);
599    
600                                    qPos.add(groupId);
601    
602                                    list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
603                                                    start, end);
604                            }
605                            catch (Exception e) {
606                                    throw processException(e);
607                            }
608                            finally {
609                                    if (list == null) {
610                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
611                                    }
612                                    else {
613                                            cacheResult(list);
614    
615                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
616                                    }
617    
618                                    closeSession(session);
619                            }
620                    }
621    
622                    return list;
623            }
624    
625            /**
626             * Returns the first org group role in the ordered set where groupId = &#63;.
627             *
628             * @param groupId the group ID
629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
630             * @return the first matching org group role
631             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
632             * @throws SystemException if a system exception occurred
633             */
634            public OrgGroupRole findByGroupId_First(long groupId,
635                    OrderByComparator orderByComparator)
636                    throws NoSuchOrgGroupRoleException, SystemException {
637                    OrgGroupRole orgGroupRole = fetchByGroupId_First(groupId,
638                                    orderByComparator);
639    
640                    if (orgGroupRole != null) {
641                            return orgGroupRole;
642                    }
643    
644                    StringBundler msg = new StringBundler(4);
645    
646                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
647    
648                    msg.append("groupId=");
649                    msg.append(groupId);
650    
651                    msg.append(StringPool.CLOSE_CURLY_BRACE);
652    
653                    throw new NoSuchOrgGroupRoleException(msg.toString());
654            }
655    
656            /**
657             * Returns the first org group role in the ordered set where groupId = &#63;.
658             *
659             * @param groupId the group ID
660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
661             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
662             * @throws SystemException if a system exception occurred
663             */
664            public OrgGroupRole fetchByGroupId_First(long groupId,
665                    OrderByComparator orderByComparator) throws SystemException {
666                    List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
667    
668                    if (!list.isEmpty()) {
669                            return list.get(0);
670                    }
671    
672                    return null;
673            }
674    
675            /**
676             * Returns the last org group role in the ordered set where groupId = &#63;.
677             *
678             * @param groupId the group ID
679             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
680             * @return the last matching org group role
681             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
682             * @throws SystemException if a system exception occurred
683             */
684            public OrgGroupRole findByGroupId_Last(long groupId,
685                    OrderByComparator orderByComparator)
686                    throws NoSuchOrgGroupRoleException, SystemException {
687                    OrgGroupRole orgGroupRole = fetchByGroupId_Last(groupId,
688                                    orderByComparator);
689    
690                    if (orgGroupRole != null) {
691                            return orgGroupRole;
692                    }
693    
694                    StringBundler msg = new StringBundler(4);
695    
696                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
697    
698                    msg.append("groupId=");
699                    msg.append(groupId);
700    
701                    msg.append(StringPool.CLOSE_CURLY_BRACE);
702    
703                    throw new NoSuchOrgGroupRoleException(msg.toString());
704            }
705    
706            /**
707             * Returns the last org group role in the ordered set where groupId = &#63;.
708             *
709             * @param groupId the group ID
710             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
711             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
712             * @throws SystemException if a system exception occurred
713             */
714            public OrgGroupRole fetchByGroupId_Last(long groupId,
715                    OrderByComparator orderByComparator) throws SystemException {
716                    int count = countByGroupId(groupId);
717    
718                    List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
719                                    orderByComparator);
720    
721                    if (!list.isEmpty()) {
722                            return list.get(0);
723                    }
724    
725                    return null;
726            }
727    
728            /**
729             * Returns the org group roles before and after the current org group role in the ordered set where groupId = &#63;.
730             *
731             * @param orgGroupRolePK the primary key of the current org group role
732             * @param groupId the group ID
733             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
734             * @return the previous, current, and next org group role
735             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
736             * @throws SystemException if a system exception occurred
737             */
738            public OrgGroupRole[] findByGroupId_PrevAndNext(
739                    OrgGroupRolePK orgGroupRolePK, long groupId,
740                    OrderByComparator orderByComparator)
741                    throws NoSuchOrgGroupRoleException, SystemException {
742                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
743    
744                    Session session = null;
745    
746                    try {
747                            session = openSession();
748    
749                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
750    
751                            array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
752                                            orderByComparator, true);
753    
754                            array[1] = orgGroupRole;
755    
756                            array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
757                                            orderByComparator, false);
758    
759                            return array;
760                    }
761                    catch (Exception e) {
762                            throw processException(e);
763                    }
764                    finally {
765                            closeSession(session);
766                    }
767            }
768    
769            protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
770                    OrgGroupRole orgGroupRole, long groupId,
771                    OrderByComparator orderByComparator, boolean previous) {
772                    StringBundler query = null;
773    
774                    if (orderByComparator != null) {
775                            query = new StringBundler(6 +
776                                            (orderByComparator.getOrderByFields().length * 6));
777                    }
778                    else {
779                            query = new StringBundler(3);
780                    }
781    
782                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
783    
784                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
785    
786                    if (orderByComparator != null) {
787                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
788    
789                            if (orderByConditionFields.length > 0) {
790                                    query.append(WHERE_AND);
791                            }
792    
793                            for (int i = 0; i < orderByConditionFields.length; i++) {
794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
795                                    query.append(orderByConditionFields[i]);
796    
797                                    if ((i + 1) < orderByConditionFields.length) {
798                                            if (orderByComparator.isAscending() ^ previous) {
799                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
800                                            }
801                                            else {
802                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
803                                            }
804                                    }
805                                    else {
806                                            if (orderByComparator.isAscending() ^ previous) {
807                                                    query.append(WHERE_GREATER_THAN);
808                                            }
809                                            else {
810                                                    query.append(WHERE_LESSER_THAN);
811                                            }
812                                    }
813                            }
814    
815                            query.append(ORDER_BY_CLAUSE);
816    
817                            String[] orderByFields = orderByComparator.getOrderByFields();
818    
819                            for (int i = 0; i < orderByFields.length; i++) {
820                                    query.append(_ORDER_BY_ENTITY_ALIAS);
821                                    query.append(orderByFields[i]);
822    
823                                    if ((i + 1) < orderByFields.length) {
824                                            if (orderByComparator.isAscending() ^ previous) {
825                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
826                                            }
827                                            else {
828                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
829                                            }
830                                    }
831                                    else {
832                                            if (orderByComparator.isAscending() ^ previous) {
833                                                    query.append(ORDER_BY_ASC);
834                                            }
835                                            else {
836                                                    query.append(ORDER_BY_DESC);
837                                            }
838                                    }
839                            }
840                    }
841    
842                    String sql = query.toString();
843    
844                    Query q = session.createQuery(sql);
845    
846                    q.setFirstResult(0);
847                    q.setMaxResults(2);
848    
849                    QueryPos qPos = QueryPos.getInstance(q);
850    
851                    qPos.add(groupId);
852    
853                    if (orderByComparator != null) {
854                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
855    
856                            for (Object value : values) {
857                                    qPos.add(value);
858                            }
859                    }
860    
861                    List<OrgGroupRole> list = q.list();
862    
863                    if (list.size() == 2) {
864                            return list.get(1);
865                    }
866                    else {
867                            return null;
868                    }
869            }
870    
871            /**
872             * Returns all the org group roles where roleId = &#63;.
873             *
874             * @param roleId the role ID
875             * @return the matching org group roles
876             * @throws SystemException if a system exception occurred
877             */
878            public List<OrgGroupRole> findByRoleId(long roleId)
879                    throws SystemException {
880                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
881            }
882    
883            /**
884             * Returns a range of all the org group roles where roleId = &#63;.
885             *
886             * <p>
887             * 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.
888             * </p>
889             *
890             * @param roleId the role ID
891             * @param start the lower bound of the range of org group roles
892             * @param end the upper bound of the range of org group roles (not inclusive)
893             * @return the range of matching org group roles
894             * @throws SystemException if a system exception occurred
895             */
896            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
897                    throws SystemException {
898                    return findByRoleId(roleId, start, end, null);
899            }
900    
901            /**
902             * Returns an ordered range of all the org group roles where roleId = &#63;.
903             *
904             * <p>
905             * 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.
906             * </p>
907             *
908             * @param roleId the role ID
909             * @param start the lower bound of the range of org group roles
910             * @param end the upper bound of the range of org group roles (not inclusive)
911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
912             * @return the ordered range of matching org group roles
913             * @throws SystemException if a system exception occurred
914             */
915            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
916                    OrderByComparator orderByComparator) throws SystemException {
917                    FinderPath finderPath = null;
918                    Object[] finderArgs = null;
919    
920                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
921                                    (orderByComparator == null)) {
922                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
923                            finderArgs = new Object[] { roleId };
924                    }
925                    else {
926                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
927                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
928                    }
929    
930                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
931                                    finderArgs, this);
932    
933                    if ((list != null) && !list.isEmpty()) {
934                            for (OrgGroupRole orgGroupRole : list) {
935                                    if ((roleId != orgGroupRole.getRoleId())) {
936                                            list = null;
937    
938                                            break;
939                                    }
940                            }
941                    }
942    
943                    if (list == null) {
944                            StringBundler query = null;
945    
946                            if (orderByComparator != null) {
947                                    query = new StringBundler(3 +
948                                                    (orderByComparator.getOrderByFields().length * 3));
949                            }
950                            else {
951                                    query = new StringBundler(2);
952                            }
953    
954                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
955    
956                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
957    
958                            if (orderByComparator != null) {
959                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
960                                            orderByComparator);
961                            }
962    
963                            String sql = query.toString();
964    
965                            Session session = null;
966    
967                            try {
968                                    session = openSession();
969    
970                                    Query q = session.createQuery(sql);
971    
972                                    QueryPos qPos = QueryPos.getInstance(q);
973    
974                                    qPos.add(roleId);
975    
976                                    list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
977                                                    start, end);
978                            }
979                            catch (Exception e) {
980                                    throw processException(e);
981                            }
982                            finally {
983                                    if (list == null) {
984                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
985                                    }
986                                    else {
987                                            cacheResult(list);
988    
989                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
990                                    }
991    
992                                    closeSession(session);
993                            }
994                    }
995    
996                    return list;
997            }
998    
999            /**
1000             * Returns the first org group role in the ordered set where roleId = &#63;.
1001             *
1002             * @param roleId the role ID
1003             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1004             * @return the first matching org group role
1005             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
1006             * @throws SystemException if a system exception occurred
1007             */
1008            public OrgGroupRole findByRoleId_First(long roleId,
1009                    OrderByComparator orderByComparator)
1010                    throws NoSuchOrgGroupRoleException, SystemException {
1011                    OrgGroupRole orgGroupRole = fetchByRoleId_First(roleId,
1012                                    orderByComparator);
1013    
1014                    if (orgGroupRole != null) {
1015                            return orgGroupRole;
1016                    }
1017    
1018                    StringBundler msg = new StringBundler(4);
1019    
1020                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1021    
1022                    msg.append("roleId=");
1023                    msg.append(roleId);
1024    
1025                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1026    
1027                    throw new NoSuchOrgGroupRoleException(msg.toString());
1028            }
1029    
1030            /**
1031             * Returns the first org group role in the ordered set where roleId = &#63;.
1032             *
1033             * @param roleId the role ID
1034             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1035             * @return the first matching org group role, or <code>null</code> if a matching org group role could not be found
1036             * @throws SystemException if a system exception occurred
1037             */
1038            public OrgGroupRole fetchByRoleId_First(long roleId,
1039                    OrderByComparator orderByComparator) throws SystemException {
1040                    List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1041    
1042                    if (!list.isEmpty()) {
1043                            return list.get(0);
1044                    }
1045    
1046                    return null;
1047            }
1048    
1049            /**
1050             * Returns the last org group role in the ordered set where roleId = &#63;.
1051             *
1052             * @param roleId the role ID
1053             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1054             * @return the last matching org group role
1055             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
1056             * @throws SystemException if a system exception occurred
1057             */
1058            public OrgGroupRole findByRoleId_Last(long roleId,
1059                    OrderByComparator orderByComparator)
1060                    throws NoSuchOrgGroupRoleException, SystemException {
1061                    OrgGroupRole orgGroupRole = fetchByRoleId_Last(roleId, orderByComparator);
1062    
1063                    if (orgGroupRole != null) {
1064                            return orgGroupRole;
1065                    }
1066    
1067                    StringBundler msg = new StringBundler(4);
1068    
1069                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1070    
1071                    msg.append("roleId=");
1072                    msg.append(roleId);
1073    
1074                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1075    
1076                    throw new NoSuchOrgGroupRoleException(msg.toString());
1077            }
1078    
1079            /**
1080             * Returns the last org group role in the ordered set where roleId = &#63;.
1081             *
1082             * @param roleId the role ID
1083             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1084             * @return the last matching org group role, or <code>null</code> if a matching org group role could not be found
1085             * @throws SystemException if a system exception occurred
1086             */
1087            public OrgGroupRole fetchByRoleId_Last(long roleId,
1088                    OrderByComparator orderByComparator) throws SystemException {
1089                    int count = countByRoleId(roleId);
1090    
1091                    List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
1092                                    orderByComparator);
1093    
1094                    if (!list.isEmpty()) {
1095                            return list.get(0);
1096                    }
1097    
1098                    return null;
1099            }
1100    
1101            /**
1102             * Returns the org group roles before and after the current org group role in the ordered set where roleId = &#63;.
1103             *
1104             * @param orgGroupRolePK the primary key of the current org group role
1105             * @param roleId the role ID
1106             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1107             * @return the previous, current, and next org group role
1108             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1109             * @throws SystemException if a system exception occurred
1110             */
1111            public OrgGroupRole[] findByRoleId_PrevAndNext(
1112                    OrgGroupRolePK orgGroupRolePK, long roleId,
1113                    OrderByComparator orderByComparator)
1114                    throws NoSuchOrgGroupRoleException, SystemException {
1115                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
1116    
1117                    Session session = null;
1118    
1119                    try {
1120                            session = openSession();
1121    
1122                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
1123    
1124                            array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
1125                                            orderByComparator, true);
1126    
1127                            array[1] = orgGroupRole;
1128    
1129                            array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
1130                                            orderByComparator, false);
1131    
1132                            return array;
1133                    }
1134                    catch (Exception e) {
1135                            throw processException(e);
1136                    }
1137                    finally {
1138                            closeSession(session);
1139                    }
1140            }
1141    
1142            protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
1143                    OrgGroupRole orgGroupRole, long roleId,
1144                    OrderByComparator orderByComparator, boolean previous) {
1145                    StringBundler query = null;
1146    
1147                    if (orderByComparator != null) {
1148                            query = new StringBundler(6 +
1149                                            (orderByComparator.getOrderByFields().length * 6));
1150                    }
1151                    else {
1152                            query = new StringBundler(3);
1153                    }
1154    
1155                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
1156    
1157                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1158    
1159                    if (orderByComparator != null) {
1160                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1161    
1162                            if (orderByConditionFields.length > 0) {
1163                                    query.append(WHERE_AND);
1164                            }
1165    
1166                            for (int i = 0; i < orderByConditionFields.length; i++) {
1167                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1168                                    query.append(orderByConditionFields[i]);
1169    
1170                                    if ((i + 1) < orderByConditionFields.length) {
1171                                            if (orderByComparator.isAscending() ^ previous) {
1172                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1173                                            }
1174                                            else {
1175                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1176                                            }
1177                                    }
1178                                    else {
1179                                            if (orderByComparator.isAscending() ^ previous) {
1180                                                    query.append(WHERE_GREATER_THAN);
1181                                            }
1182                                            else {
1183                                                    query.append(WHERE_LESSER_THAN);
1184                                            }
1185                                    }
1186                            }
1187    
1188                            query.append(ORDER_BY_CLAUSE);
1189    
1190                            String[] orderByFields = orderByComparator.getOrderByFields();
1191    
1192                            for (int i = 0; i < orderByFields.length; i++) {
1193                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1194                                    query.append(orderByFields[i]);
1195    
1196                                    if ((i + 1) < orderByFields.length) {
1197                                            if (orderByComparator.isAscending() ^ previous) {
1198                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1199                                            }
1200                                            else {
1201                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1202                                            }
1203                                    }
1204                                    else {
1205                                            if (orderByComparator.isAscending() ^ previous) {
1206                                                    query.append(ORDER_BY_ASC);
1207                                            }
1208                                            else {
1209                                                    query.append(ORDER_BY_DESC);
1210                                            }
1211                                    }
1212                            }
1213                    }
1214    
1215                    String sql = query.toString();
1216    
1217                    Query q = session.createQuery(sql);
1218    
1219                    q.setFirstResult(0);
1220                    q.setMaxResults(2);
1221    
1222                    QueryPos qPos = QueryPos.getInstance(q);
1223    
1224                    qPos.add(roleId);
1225    
1226                    if (orderByComparator != null) {
1227                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
1228    
1229                            for (Object value : values) {
1230                                    qPos.add(value);
1231                            }
1232                    }
1233    
1234                    List<OrgGroupRole> list = q.list();
1235    
1236                    if (list.size() == 2) {
1237                            return list.get(1);
1238                    }
1239                    else {
1240                            return null;
1241                    }
1242            }
1243    
1244            /**
1245             * Returns all the org group roles.
1246             *
1247             * @return the org group roles
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public List<OrgGroupRole> findAll() throws SystemException {
1251                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1252            }
1253    
1254            /**
1255             * Returns a range of all the org group roles.
1256             *
1257             * <p>
1258             * 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.
1259             * </p>
1260             *
1261             * @param start the lower bound of the range of org group roles
1262             * @param end the upper bound of the range of org group roles (not inclusive)
1263             * @return the range of org group roles
1264             * @throws SystemException if a system exception occurred
1265             */
1266            public List<OrgGroupRole> findAll(int start, int end)
1267                    throws SystemException {
1268                    return findAll(start, end, null);
1269            }
1270    
1271            /**
1272             * Returns an ordered range of all the org group roles.
1273             *
1274             * <p>
1275             * 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.
1276             * </p>
1277             *
1278             * @param start the lower bound of the range of org group roles
1279             * @param end the upper bound of the range of org group roles (not inclusive)
1280             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1281             * @return the ordered range of org group roles
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public List<OrgGroupRole> findAll(int start, int end,
1285                    OrderByComparator orderByComparator) throws SystemException {
1286                    FinderPath finderPath = null;
1287                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1288    
1289                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1290                                    (orderByComparator == null)) {
1291                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1292                            finderArgs = FINDER_ARGS_EMPTY;
1293                    }
1294                    else {
1295                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1296                            finderArgs = new Object[] { start, end, orderByComparator };
1297                    }
1298    
1299                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1300                                    finderArgs, this);
1301    
1302                    if (list == null) {
1303                            StringBundler query = null;
1304                            String sql = null;
1305    
1306                            if (orderByComparator != null) {
1307                                    query = new StringBundler(2 +
1308                                                    (orderByComparator.getOrderByFields().length * 3));
1309    
1310                                    query.append(_SQL_SELECT_ORGGROUPROLE);
1311    
1312                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1313                                            orderByComparator);
1314    
1315                                    sql = query.toString();
1316                            }
1317                            else {
1318                                    sql = _SQL_SELECT_ORGGROUPROLE;
1319                            }
1320    
1321                            Session session = null;
1322    
1323                            try {
1324                                    session = openSession();
1325    
1326                                    Query q = session.createQuery(sql);
1327    
1328                                    if (orderByComparator == null) {
1329                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1330                                                            start, end, false);
1331    
1332                                            Collections.sort(list);
1333                                    }
1334                                    else {
1335                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1336                                                            start, end);
1337                                    }
1338                            }
1339                            catch (Exception e) {
1340                                    throw processException(e);
1341                            }
1342                            finally {
1343                                    if (list == null) {
1344                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1345                                    }
1346                                    else {
1347                                            cacheResult(list);
1348    
1349                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1350                                    }
1351    
1352                                    closeSession(session);
1353                            }
1354                    }
1355    
1356                    return list;
1357            }
1358    
1359            /**
1360             * Removes all the org group roles where groupId = &#63; from the database.
1361             *
1362             * @param groupId the group ID
1363             * @throws SystemException if a system exception occurred
1364             */
1365            public void removeByGroupId(long groupId) throws SystemException {
1366                    for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
1367                            remove(orgGroupRole);
1368                    }
1369            }
1370    
1371            /**
1372             * Removes all the org group roles where roleId = &#63; from the database.
1373             *
1374             * @param roleId the role ID
1375             * @throws SystemException if a system exception occurred
1376             */
1377            public void removeByRoleId(long roleId) throws SystemException {
1378                    for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
1379                            remove(orgGroupRole);
1380                    }
1381            }
1382    
1383            /**
1384             * Removes all the org group roles from the database.
1385             *
1386             * @throws SystemException if a system exception occurred
1387             */
1388            public void removeAll() throws SystemException {
1389                    for (OrgGroupRole orgGroupRole : findAll()) {
1390                            remove(orgGroupRole);
1391                    }
1392            }
1393    
1394            /**
1395             * Returns the number of org group roles where groupId = &#63;.
1396             *
1397             * @param groupId the group ID
1398             * @return the number of matching org group roles
1399             * @throws SystemException if a system exception occurred
1400             */
1401            public int countByGroupId(long groupId) throws SystemException {
1402                    Object[] finderArgs = new Object[] { groupId };
1403    
1404                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1405                                    finderArgs, this);
1406    
1407                    if (count == null) {
1408                            StringBundler query = new StringBundler(2);
1409    
1410                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1411    
1412                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1413    
1414                            String sql = query.toString();
1415    
1416                            Session session = null;
1417    
1418                            try {
1419                                    session = openSession();
1420    
1421                                    Query q = session.createQuery(sql);
1422    
1423                                    QueryPos qPos = QueryPos.getInstance(q);
1424    
1425                                    qPos.add(groupId);
1426    
1427                                    count = (Long)q.uniqueResult();
1428                            }
1429                            catch (Exception e) {
1430                                    throw processException(e);
1431                            }
1432                            finally {
1433                                    if (count == null) {
1434                                            count = Long.valueOf(0);
1435                                    }
1436    
1437                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1438                                            finderArgs, count);
1439    
1440                                    closeSession(session);
1441                            }
1442                    }
1443    
1444                    return count.intValue();
1445            }
1446    
1447            /**
1448             * Returns the number of org group roles where roleId = &#63;.
1449             *
1450             * @param roleId the role ID
1451             * @return the number of matching org group roles
1452             * @throws SystemException if a system exception occurred
1453             */
1454            public int countByRoleId(long roleId) throws SystemException {
1455                    Object[] finderArgs = new Object[] { roleId };
1456    
1457                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1458                                    finderArgs, this);
1459    
1460                    if (count == null) {
1461                            StringBundler query = new StringBundler(2);
1462    
1463                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1464    
1465                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1466    
1467                            String sql = query.toString();
1468    
1469                            Session session = null;
1470    
1471                            try {
1472                                    session = openSession();
1473    
1474                                    Query q = session.createQuery(sql);
1475    
1476                                    QueryPos qPos = QueryPos.getInstance(q);
1477    
1478                                    qPos.add(roleId);
1479    
1480                                    count = (Long)q.uniqueResult();
1481                            }
1482                            catch (Exception e) {
1483                                    throw processException(e);
1484                            }
1485                            finally {
1486                                    if (count == null) {
1487                                            count = Long.valueOf(0);
1488                                    }
1489    
1490                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1491                                            finderArgs, count);
1492    
1493                                    closeSession(session);
1494                            }
1495                    }
1496    
1497                    return count.intValue();
1498            }
1499    
1500            /**
1501             * Returns the number of org group roles.
1502             *
1503             * @return the number of org group roles
1504             * @throws SystemException if a system exception occurred
1505             */
1506            public int countAll() throws SystemException {
1507                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1508                                    FINDER_ARGS_EMPTY, this);
1509    
1510                    if (count == null) {
1511                            Session session = null;
1512    
1513                            try {
1514                                    session = openSession();
1515    
1516                                    Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1517    
1518                                    count = (Long)q.uniqueResult();
1519                            }
1520                            catch (Exception e) {
1521                                    throw processException(e);
1522                            }
1523                            finally {
1524                                    if (count == null) {
1525                                            count = Long.valueOf(0);
1526                                    }
1527    
1528                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1529                                            FINDER_ARGS_EMPTY, count);
1530    
1531                                    closeSession(session);
1532                            }
1533                    }
1534    
1535                    return count.intValue();
1536            }
1537    
1538            /**
1539             * Initializes the org group role persistence.
1540             */
1541            public void afterPropertiesSet() {
1542                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1543                                            com.liferay.portal.util.PropsUtil.get(
1544                                                    "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1545    
1546                    if (listenerClassNames.length > 0) {
1547                            try {
1548                                    List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1549    
1550                                    for (String listenerClassName : listenerClassNames) {
1551                                            listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1552                                                            listenerClassName));
1553                                    }
1554    
1555                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1556                            }
1557                            catch (Exception e) {
1558                                    _log.error(e);
1559                            }
1560                    }
1561            }
1562    
1563            public void destroy() {
1564                    EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1565                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1566                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1567            }
1568    
1569            @BeanReference(type = AccountPersistence.class)
1570            protected AccountPersistence accountPersistence;
1571            @BeanReference(type = AddressPersistence.class)
1572            protected AddressPersistence addressPersistence;
1573            @BeanReference(type = BrowserTrackerPersistence.class)
1574            protected BrowserTrackerPersistence browserTrackerPersistence;
1575            @BeanReference(type = ClassNamePersistence.class)
1576            protected ClassNamePersistence classNamePersistence;
1577            @BeanReference(type = ClusterGroupPersistence.class)
1578            protected ClusterGroupPersistence clusterGroupPersistence;
1579            @BeanReference(type = CompanyPersistence.class)
1580            protected CompanyPersistence companyPersistence;
1581            @BeanReference(type = ContactPersistence.class)
1582            protected ContactPersistence contactPersistence;
1583            @BeanReference(type = CountryPersistence.class)
1584            protected CountryPersistence countryPersistence;
1585            @BeanReference(type = EmailAddressPersistence.class)
1586            protected EmailAddressPersistence emailAddressPersistence;
1587            @BeanReference(type = GroupPersistence.class)
1588            protected GroupPersistence groupPersistence;
1589            @BeanReference(type = ImagePersistence.class)
1590            protected ImagePersistence imagePersistence;
1591            @BeanReference(type = LayoutPersistence.class)
1592            protected LayoutPersistence layoutPersistence;
1593            @BeanReference(type = LayoutBranchPersistence.class)
1594            protected LayoutBranchPersistence layoutBranchPersistence;
1595            @BeanReference(type = LayoutPrototypePersistence.class)
1596            protected LayoutPrototypePersistence layoutPrototypePersistence;
1597            @BeanReference(type = LayoutRevisionPersistence.class)
1598            protected LayoutRevisionPersistence layoutRevisionPersistence;
1599            @BeanReference(type = LayoutSetPersistence.class)
1600            protected LayoutSetPersistence layoutSetPersistence;
1601            @BeanReference(type = LayoutSetBranchPersistence.class)
1602            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1603            @BeanReference(type = LayoutSetPrototypePersistence.class)
1604            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1605            @BeanReference(type = ListTypePersistence.class)
1606            protected ListTypePersistence listTypePersistence;
1607            @BeanReference(type = LockPersistence.class)
1608            protected LockPersistence lockPersistence;
1609            @BeanReference(type = MembershipRequestPersistence.class)
1610            protected MembershipRequestPersistence membershipRequestPersistence;
1611            @BeanReference(type = OrganizationPersistence.class)
1612            protected OrganizationPersistence organizationPersistence;
1613            @BeanReference(type = OrgGroupRolePersistence.class)
1614            protected OrgGroupRolePersistence orgGroupRolePersistence;
1615            @BeanReference(type = OrgLaborPersistence.class)
1616            protected OrgLaborPersistence orgLaborPersistence;
1617            @BeanReference(type = PasswordPolicyPersistence.class)
1618            protected PasswordPolicyPersistence passwordPolicyPersistence;
1619            @BeanReference(type = PasswordPolicyRelPersistence.class)
1620            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1621            @BeanReference(type = PasswordTrackerPersistence.class)
1622            protected PasswordTrackerPersistence passwordTrackerPersistence;
1623            @BeanReference(type = PhonePersistence.class)
1624            protected PhonePersistence phonePersistence;
1625            @BeanReference(type = PluginSettingPersistence.class)
1626            protected PluginSettingPersistence pluginSettingPersistence;
1627            @BeanReference(type = PortalPreferencesPersistence.class)
1628            protected PortalPreferencesPersistence portalPreferencesPersistence;
1629            @BeanReference(type = PortletPersistence.class)
1630            protected PortletPersistence portletPersistence;
1631            @BeanReference(type = PortletItemPersistence.class)
1632            protected PortletItemPersistence portletItemPersistence;
1633            @BeanReference(type = PortletPreferencesPersistence.class)
1634            protected PortletPreferencesPersistence portletPreferencesPersistence;
1635            @BeanReference(type = RegionPersistence.class)
1636            protected RegionPersistence regionPersistence;
1637            @BeanReference(type = ReleasePersistence.class)
1638            protected ReleasePersistence releasePersistence;
1639            @BeanReference(type = RepositoryPersistence.class)
1640            protected RepositoryPersistence repositoryPersistence;
1641            @BeanReference(type = RepositoryEntryPersistence.class)
1642            protected RepositoryEntryPersistence repositoryEntryPersistence;
1643            @BeanReference(type = ResourceActionPersistence.class)
1644            protected ResourceActionPersistence resourceActionPersistence;
1645            @BeanReference(type = ResourceBlockPersistence.class)
1646            protected ResourceBlockPersistence resourceBlockPersistence;
1647            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1648            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
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    }