001    /**
002     * Copyright (c) 2000-2011 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_WITHOUT_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_WITH_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) {
550                            StringBundler query = null;
551    
552                            if (orderByComparator != null) {
553                                    query = new StringBundler(3 +
554                                                    (orderByComparator.getOrderByFields().length * 3));
555                            }
556                            else {
557                                    query = new StringBundler(2);
558                            }
559    
560                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
561    
562                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
563    
564                            if (orderByComparator != null) {
565                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
566                                            orderByComparator);
567                            }
568    
569                            String sql = query.toString();
570    
571                            Session session = null;
572    
573                            try {
574                                    session = openSession();
575    
576                                    Query q = session.createQuery(sql);
577    
578                                    QueryPos qPos = QueryPos.getInstance(q);
579    
580                                    qPos.add(groupId);
581    
582                                    list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
583                                                    start, end);
584                            }
585                            catch (Exception e) {
586                                    throw processException(e);
587                            }
588                            finally {
589                                    if (list == null) {
590                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
591                                    }
592                                    else {
593                                            cacheResult(list);
594    
595                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
596                                    }
597    
598                                    closeSession(session);
599                            }
600                    }
601    
602                    return list;
603            }
604    
605            /**
606             * Returns the first org group role in the ordered set where groupId = &#63;.
607             *
608             * <p>
609             * 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.
610             * </p>
611             *
612             * @param groupId the group ID
613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
614             * @return the first matching org group role
615             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
616             * @throws SystemException if a system exception occurred
617             */
618            public OrgGroupRole findByGroupId_First(long groupId,
619                    OrderByComparator orderByComparator)
620                    throws NoSuchOrgGroupRoleException, SystemException {
621                    List<OrgGroupRole> list = findByGroupId(groupId, 0, 1, orderByComparator);
622    
623                    if (list.isEmpty()) {
624                            StringBundler msg = new StringBundler(4);
625    
626                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
627    
628                            msg.append("groupId=");
629                            msg.append(groupId);
630    
631                            msg.append(StringPool.CLOSE_CURLY_BRACE);
632    
633                            throw new NoSuchOrgGroupRoleException(msg.toString());
634                    }
635                    else {
636                            return list.get(0);
637                    }
638            }
639    
640            /**
641             * Returns the last org group role in the ordered set where groupId = &#63;.
642             *
643             * <p>
644             * 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.
645             * </p>
646             *
647             * @param groupId the group ID
648             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
649             * @return the last matching org group role
650             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
651             * @throws SystemException if a system exception occurred
652             */
653            public OrgGroupRole findByGroupId_Last(long groupId,
654                    OrderByComparator orderByComparator)
655                    throws NoSuchOrgGroupRoleException, SystemException {
656                    int count = countByGroupId(groupId);
657    
658                    List<OrgGroupRole> list = findByGroupId(groupId, count - 1, count,
659                                    orderByComparator);
660    
661                    if (list.isEmpty()) {
662                            StringBundler msg = new StringBundler(4);
663    
664                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
665    
666                            msg.append("groupId=");
667                            msg.append(groupId);
668    
669                            msg.append(StringPool.CLOSE_CURLY_BRACE);
670    
671                            throw new NoSuchOrgGroupRoleException(msg.toString());
672                    }
673                    else {
674                            return list.get(0);
675                    }
676            }
677    
678            /**
679             * Returns the org group roles before and after the current org group role in the ordered set where groupId = &#63;.
680             *
681             * <p>
682             * 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.
683             * </p>
684             *
685             * @param orgGroupRolePK the primary key of the current org group role
686             * @param groupId the group ID
687             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
688             * @return the previous, current, and next org group role
689             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
690             * @throws SystemException if a system exception occurred
691             */
692            public OrgGroupRole[] findByGroupId_PrevAndNext(
693                    OrgGroupRolePK orgGroupRolePK, long groupId,
694                    OrderByComparator orderByComparator)
695                    throws NoSuchOrgGroupRoleException, SystemException {
696                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
697    
698                    Session session = null;
699    
700                    try {
701                            session = openSession();
702    
703                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
704    
705                            array[0] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
706                                            orderByComparator, true);
707    
708                            array[1] = orgGroupRole;
709    
710                            array[2] = getByGroupId_PrevAndNext(session, orgGroupRole, groupId,
711                                            orderByComparator, false);
712    
713                            return array;
714                    }
715                    catch (Exception e) {
716                            throw processException(e);
717                    }
718                    finally {
719                            closeSession(session);
720                    }
721            }
722    
723            protected OrgGroupRole getByGroupId_PrevAndNext(Session session,
724                    OrgGroupRole orgGroupRole, long groupId,
725                    OrderByComparator orderByComparator, boolean previous) {
726                    StringBundler query = null;
727    
728                    if (orderByComparator != null) {
729                            query = new StringBundler(6 +
730                                            (orderByComparator.getOrderByFields().length * 6));
731                    }
732                    else {
733                            query = new StringBundler(3);
734                    }
735    
736                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
737    
738                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
739    
740                    if (orderByComparator != null) {
741                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
742    
743                            if (orderByConditionFields.length > 0) {
744                                    query.append(WHERE_AND);
745                            }
746    
747                            for (int i = 0; i < orderByConditionFields.length; i++) {
748                                    query.append(_ORDER_BY_ENTITY_ALIAS);
749                                    query.append(orderByConditionFields[i]);
750    
751                                    if ((i + 1) < orderByConditionFields.length) {
752                                            if (orderByComparator.isAscending() ^ previous) {
753                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
754                                            }
755                                            else {
756                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
757                                            }
758                                    }
759                                    else {
760                                            if (orderByComparator.isAscending() ^ previous) {
761                                                    query.append(WHERE_GREATER_THAN);
762                                            }
763                                            else {
764                                                    query.append(WHERE_LESSER_THAN);
765                                            }
766                                    }
767                            }
768    
769                            query.append(ORDER_BY_CLAUSE);
770    
771                            String[] orderByFields = orderByComparator.getOrderByFields();
772    
773                            for (int i = 0; i < orderByFields.length; i++) {
774                                    query.append(_ORDER_BY_ENTITY_ALIAS);
775                                    query.append(orderByFields[i]);
776    
777                                    if ((i + 1) < orderByFields.length) {
778                                            if (orderByComparator.isAscending() ^ previous) {
779                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
780                                            }
781                                            else {
782                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
783                                            }
784                                    }
785                                    else {
786                                            if (orderByComparator.isAscending() ^ previous) {
787                                                    query.append(ORDER_BY_ASC);
788                                            }
789                                            else {
790                                                    query.append(ORDER_BY_DESC);
791                                            }
792                                    }
793                            }
794                    }
795    
796                    String sql = query.toString();
797    
798                    Query q = session.createQuery(sql);
799    
800                    q.setFirstResult(0);
801                    q.setMaxResults(2);
802    
803                    QueryPos qPos = QueryPos.getInstance(q);
804    
805                    qPos.add(groupId);
806    
807                    if (orderByComparator != null) {
808                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
809    
810                            for (Object value : values) {
811                                    qPos.add(value);
812                            }
813                    }
814    
815                    List<OrgGroupRole> list = q.list();
816    
817                    if (list.size() == 2) {
818                            return list.get(1);
819                    }
820                    else {
821                            return null;
822                    }
823            }
824    
825            /**
826             * Returns all the org group roles where roleId = &#63;.
827             *
828             * @param roleId the role ID
829             * @return the matching org group roles
830             * @throws SystemException if a system exception occurred
831             */
832            public List<OrgGroupRole> findByRoleId(long roleId)
833                    throws SystemException {
834                    return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
835            }
836    
837            /**
838             * Returns a range of all the org group roles where roleId = &#63;.
839             *
840             * <p>
841             * 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.
842             * </p>
843             *
844             * @param roleId the role ID
845             * @param start the lower bound of the range of org group roles
846             * @param end the upper bound of the range of org group roles (not inclusive)
847             * @return the range of matching org group roles
848             * @throws SystemException if a system exception occurred
849             */
850            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end)
851                    throws SystemException {
852                    return findByRoleId(roleId, start, end, null);
853            }
854    
855            /**
856             * Returns an ordered range of all the org group roles where roleId = &#63;.
857             *
858             * <p>
859             * 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.
860             * </p>
861             *
862             * @param roleId the role ID
863             * @param start the lower bound of the range of org group roles
864             * @param end the upper bound of the range of org group roles (not inclusive)
865             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
866             * @return the ordered range of matching org group roles
867             * @throws SystemException if a system exception occurred
868             */
869            public List<OrgGroupRole> findByRoleId(long roleId, int start, int end,
870                    OrderByComparator orderByComparator) throws SystemException {
871                    FinderPath finderPath = null;
872                    Object[] finderArgs = null;
873    
874                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
875                                    (orderByComparator == null)) {
876                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
877                            finderArgs = new Object[] { roleId };
878                    }
879                    else {
880                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
881                            finderArgs = new Object[] { roleId, start, end, orderByComparator };
882                    }
883    
884                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
885                                    finderArgs, this);
886    
887                    if (list == null) {
888                            StringBundler query = null;
889    
890                            if (orderByComparator != null) {
891                                    query = new StringBundler(3 +
892                                                    (orderByComparator.getOrderByFields().length * 3));
893                            }
894                            else {
895                                    query = new StringBundler(2);
896                            }
897    
898                            query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
899    
900                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
901    
902                            if (orderByComparator != null) {
903                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
904                                            orderByComparator);
905                            }
906    
907                            String sql = query.toString();
908    
909                            Session session = null;
910    
911                            try {
912                                    session = openSession();
913    
914                                    Query q = session.createQuery(sql);
915    
916                                    QueryPos qPos = QueryPos.getInstance(q);
917    
918                                    qPos.add(roleId);
919    
920                                    list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
921                                                    start, end);
922                            }
923                            catch (Exception e) {
924                                    throw processException(e);
925                            }
926                            finally {
927                                    if (list == null) {
928                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
929                                    }
930                                    else {
931                                            cacheResult(list);
932    
933                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
934                                    }
935    
936                                    closeSession(session);
937                            }
938                    }
939    
940                    return list;
941            }
942    
943            /**
944             * Returns the first org group role in the ordered set where roleId = &#63;.
945             *
946             * <p>
947             * 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.
948             * </p>
949             *
950             * @param roleId the role ID
951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
952             * @return the first matching org group role
953             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
954             * @throws SystemException if a system exception occurred
955             */
956            public OrgGroupRole findByRoleId_First(long roleId,
957                    OrderByComparator orderByComparator)
958                    throws NoSuchOrgGroupRoleException, SystemException {
959                    List<OrgGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
960    
961                    if (list.isEmpty()) {
962                            StringBundler msg = new StringBundler(4);
963    
964                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
965    
966                            msg.append("roleId=");
967                            msg.append(roleId);
968    
969                            msg.append(StringPool.CLOSE_CURLY_BRACE);
970    
971                            throw new NoSuchOrgGroupRoleException(msg.toString());
972                    }
973                    else {
974                            return list.get(0);
975                    }
976            }
977    
978            /**
979             * Returns the last org group role in the ordered set where roleId = &#63;.
980             *
981             * <p>
982             * 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.
983             * </p>
984             *
985             * @param roleId the role ID
986             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
987             * @return the last matching org group role
988             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a matching org group role could not be found
989             * @throws SystemException if a system exception occurred
990             */
991            public OrgGroupRole findByRoleId_Last(long roleId,
992                    OrderByComparator orderByComparator)
993                    throws NoSuchOrgGroupRoleException, SystemException {
994                    int count = countByRoleId(roleId);
995    
996                    List<OrgGroupRole> list = findByRoleId(roleId, count - 1, count,
997                                    orderByComparator);
998    
999                    if (list.isEmpty()) {
1000                            StringBundler msg = new StringBundler(4);
1001    
1002                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1003    
1004                            msg.append("roleId=");
1005                            msg.append(roleId);
1006    
1007                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1008    
1009                            throw new NoSuchOrgGroupRoleException(msg.toString());
1010                    }
1011                    else {
1012                            return list.get(0);
1013                    }
1014            }
1015    
1016            /**
1017             * Returns the org group roles before and after the current org group role in the ordered set where roleId = &#63;.
1018             *
1019             * <p>
1020             * 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.
1021             * </p>
1022             *
1023             * @param orgGroupRolePK the primary key of the current org group role
1024             * @param roleId the role ID
1025             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1026             * @return the previous, current, and next org group role
1027             * @throws com.liferay.portal.NoSuchOrgGroupRoleException if a org group role with the primary key could not be found
1028             * @throws SystemException if a system exception occurred
1029             */
1030            public OrgGroupRole[] findByRoleId_PrevAndNext(
1031                    OrgGroupRolePK orgGroupRolePK, long roleId,
1032                    OrderByComparator orderByComparator)
1033                    throws NoSuchOrgGroupRoleException, SystemException {
1034                    OrgGroupRole orgGroupRole = findByPrimaryKey(orgGroupRolePK);
1035    
1036                    Session session = null;
1037    
1038                    try {
1039                            session = openSession();
1040    
1041                            OrgGroupRole[] array = new OrgGroupRoleImpl[3];
1042    
1043                            array[0] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
1044                                            orderByComparator, true);
1045    
1046                            array[1] = orgGroupRole;
1047    
1048                            array[2] = getByRoleId_PrevAndNext(session, orgGroupRole, roleId,
1049                                            orderByComparator, false);
1050    
1051                            return array;
1052                    }
1053                    catch (Exception e) {
1054                            throw processException(e);
1055                    }
1056                    finally {
1057                            closeSession(session);
1058                    }
1059            }
1060    
1061            protected OrgGroupRole getByRoleId_PrevAndNext(Session session,
1062                    OrgGroupRole orgGroupRole, long roleId,
1063                    OrderByComparator orderByComparator, boolean previous) {
1064                    StringBundler query = null;
1065    
1066                    if (orderByComparator != null) {
1067                            query = new StringBundler(6 +
1068                                            (orderByComparator.getOrderByFields().length * 6));
1069                    }
1070                    else {
1071                            query = new StringBundler(3);
1072                    }
1073    
1074                    query.append(_SQL_SELECT_ORGGROUPROLE_WHERE);
1075    
1076                    query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1077    
1078                    if (orderByComparator != null) {
1079                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1080    
1081                            if (orderByConditionFields.length > 0) {
1082                                    query.append(WHERE_AND);
1083                            }
1084    
1085                            for (int i = 0; i < orderByConditionFields.length; i++) {
1086                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1087                                    query.append(orderByConditionFields[i]);
1088    
1089                                    if ((i + 1) < orderByConditionFields.length) {
1090                                            if (orderByComparator.isAscending() ^ previous) {
1091                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1092                                            }
1093                                            else {
1094                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1095                                            }
1096                                    }
1097                                    else {
1098                                            if (orderByComparator.isAscending() ^ previous) {
1099                                                    query.append(WHERE_GREATER_THAN);
1100                                            }
1101                                            else {
1102                                                    query.append(WHERE_LESSER_THAN);
1103                                            }
1104                                    }
1105                            }
1106    
1107                            query.append(ORDER_BY_CLAUSE);
1108    
1109                            String[] orderByFields = orderByComparator.getOrderByFields();
1110    
1111                            for (int i = 0; i < orderByFields.length; i++) {
1112                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1113                                    query.append(orderByFields[i]);
1114    
1115                                    if ((i + 1) < orderByFields.length) {
1116                                            if (orderByComparator.isAscending() ^ previous) {
1117                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1118                                            }
1119                                            else {
1120                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1121                                            }
1122                                    }
1123                                    else {
1124                                            if (orderByComparator.isAscending() ^ previous) {
1125                                                    query.append(ORDER_BY_ASC);
1126                                            }
1127                                            else {
1128                                                    query.append(ORDER_BY_DESC);
1129                                            }
1130                                    }
1131                            }
1132                    }
1133    
1134                    String sql = query.toString();
1135    
1136                    Query q = session.createQuery(sql);
1137    
1138                    q.setFirstResult(0);
1139                    q.setMaxResults(2);
1140    
1141                    QueryPos qPos = QueryPos.getInstance(q);
1142    
1143                    qPos.add(roleId);
1144    
1145                    if (orderByComparator != null) {
1146                            Object[] values = orderByComparator.getOrderByConditionValues(orgGroupRole);
1147    
1148                            for (Object value : values) {
1149                                    qPos.add(value);
1150                            }
1151                    }
1152    
1153                    List<OrgGroupRole> list = q.list();
1154    
1155                    if (list.size() == 2) {
1156                            return list.get(1);
1157                    }
1158                    else {
1159                            return null;
1160                    }
1161            }
1162    
1163            /**
1164             * Returns all the org group roles.
1165             *
1166             * @return the org group roles
1167             * @throws SystemException if a system exception occurred
1168             */
1169            public List<OrgGroupRole> findAll() throws SystemException {
1170                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1171            }
1172    
1173            /**
1174             * Returns a range of all the org group roles.
1175             *
1176             * <p>
1177             * 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.
1178             * </p>
1179             *
1180             * @param start the lower bound of the range of org group roles
1181             * @param end the upper bound of the range of org group roles (not inclusive)
1182             * @return the range of org group roles
1183             * @throws SystemException if a system exception occurred
1184             */
1185            public List<OrgGroupRole> findAll(int start, int end)
1186                    throws SystemException {
1187                    return findAll(start, end, null);
1188            }
1189    
1190            /**
1191             * Returns an ordered range of all the org group roles.
1192             *
1193             * <p>
1194             * 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.
1195             * </p>
1196             *
1197             * @param start the lower bound of the range of org group roles
1198             * @param end the upper bound of the range of org group roles (not inclusive)
1199             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1200             * @return the ordered range of org group roles
1201             * @throws SystemException if a system exception occurred
1202             */
1203            public List<OrgGroupRole> findAll(int start, int end,
1204                    OrderByComparator orderByComparator) throws SystemException {
1205                    FinderPath finderPath = null;
1206                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1207    
1208                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1209                                    (orderByComparator == null)) {
1210                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1211                            finderArgs = FINDER_ARGS_EMPTY;
1212                    }
1213                    else {
1214                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1215                            finderArgs = new Object[] { start, end, orderByComparator };
1216                    }
1217    
1218                    List<OrgGroupRole> list = (List<OrgGroupRole>)FinderCacheUtil.getResult(finderPath,
1219                                    finderArgs, this);
1220    
1221                    if (list == null) {
1222                            StringBundler query = null;
1223                            String sql = null;
1224    
1225                            if (orderByComparator != null) {
1226                                    query = new StringBundler(2 +
1227                                                    (orderByComparator.getOrderByFields().length * 3));
1228    
1229                                    query.append(_SQL_SELECT_ORGGROUPROLE);
1230    
1231                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1232                                            orderByComparator);
1233    
1234                                    sql = query.toString();
1235                            }
1236                            else {
1237                                    sql = _SQL_SELECT_ORGGROUPROLE;
1238                            }
1239    
1240                            Session session = null;
1241    
1242                            try {
1243                                    session = openSession();
1244    
1245                                    Query q = session.createQuery(sql);
1246    
1247                                    if (orderByComparator == null) {
1248                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1249                                                            start, end, false);
1250    
1251                                            Collections.sort(list);
1252                                    }
1253                                    else {
1254                                            list = (List<OrgGroupRole>)QueryUtil.list(q, getDialect(),
1255                                                            start, end);
1256                                    }
1257                            }
1258                            catch (Exception e) {
1259                                    throw processException(e);
1260                            }
1261                            finally {
1262                                    if (list == null) {
1263                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1264                                    }
1265                                    else {
1266                                            cacheResult(list);
1267    
1268                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1269                                    }
1270    
1271                                    closeSession(session);
1272                            }
1273                    }
1274    
1275                    return list;
1276            }
1277    
1278            /**
1279             * Removes all the org group roles where groupId = &#63; from the database.
1280             *
1281             * @param groupId the group ID
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public void removeByGroupId(long groupId) throws SystemException {
1285                    for (OrgGroupRole orgGroupRole : findByGroupId(groupId)) {
1286                            remove(orgGroupRole);
1287                    }
1288            }
1289    
1290            /**
1291             * Removes all the org group roles where roleId = &#63; from the database.
1292             *
1293             * @param roleId the role ID
1294             * @throws SystemException if a system exception occurred
1295             */
1296            public void removeByRoleId(long roleId) throws SystemException {
1297                    for (OrgGroupRole orgGroupRole : findByRoleId(roleId)) {
1298                            remove(orgGroupRole);
1299                    }
1300            }
1301    
1302            /**
1303             * Removes all the org group roles from the database.
1304             *
1305             * @throws SystemException if a system exception occurred
1306             */
1307            public void removeAll() throws SystemException {
1308                    for (OrgGroupRole orgGroupRole : findAll()) {
1309                            remove(orgGroupRole);
1310                    }
1311            }
1312    
1313            /**
1314             * Returns the number of org group roles where groupId = &#63;.
1315             *
1316             * @param groupId the group ID
1317             * @return the number of matching org group roles
1318             * @throws SystemException if a system exception occurred
1319             */
1320            public int countByGroupId(long groupId) throws SystemException {
1321                    Object[] finderArgs = new Object[] { groupId };
1322    
1323                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1324                                    finderArgs, this);
1325    
1326                    if (count == null) {
1327                            StringBundler query = new StringBundler(2);
1328    
1329                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1330    
1331                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1332    
1333                            String sql = query.toString();
1334    
1335                            Session session = null;
1336    
1337                            try {
1338                                    session = openSession();
1339    
1340                                    Query q = session.createQuery(sql);
1341    
1342                                    QueryPos qPos = QueryPos.getInstance(q);
1343    
1344                                    qPos.add(groupId);
1345    
1346                                    count = (Long)q.uniqueResult();
1347                            }
1348                            catch (Exception e) {
1349                                    throw processException(e);
1350                            }
1351                            finally {
1352                                    if (count == null) {
1353                                            count = Long.valueOf(0);
1354                                    }
1355    
1356                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1357                                            finderArgs, count);
1358    
1359                                    closeSession(session);
1360                            }
1361                    }
1362    
1363                    return count.intValue();
1364            }
1365    
1366            /**
1367             * Returns the number of org group roles where roleId = &#63;.
1368             *
1369             * @param roleId the role ID
1370             * @return the number of matching org group roles
1371             * @throws SystemException if a system exception occurred
1372             */
1373            public int countByRoleId(long roleId) throws SystemException {
1374                    Object[] finderArgs = new Object[] { roleId };
1375    
1376                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROLEID,
1377                                    finderArgs, this);
1378    
1379                    if (count == null) {
1380                            StringBundler query = new StringBundler(2);
1381    
1382                            query.append(_SQL_COUNT_ORGGROUPROLE_WHERE);
1383    
1384                            query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1385    
1386                            String sql = query.toString();
1387    
1388                            Session session = null;
1389    
1390                            try {
1391                                    session = openSession();
1392    
1393                                    Query q = session.createQuery(sql);
1394    
1395                                    QueryPos qPos = QueryPos.getInstance(q);
1396    
1397                                    qPos.add(roleId);
1398    
1399                                    count = (Long)q.uniqueResult();
1400                            }
1401                            catch (Exception e) {
1402                                    throw processException(e);
1403                            }
1404                            finally {
1405                                    if (count == null) {
1406                                            count = Long.valueOf(0);
1407                                    }
1408    
1409                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROLEID,
1410                                            finderArgs, count);
1411    
1412                                    closeSession(session);
1413                            }
1414                    }
1415    
1416                    return count.intValue();
1417            }
1418    
1419            /**
1420             * Returns the number of org group roles.
1421             *
1422             * @return the number of org group roles
1423             * @throws SystemException if a system exception occurred
1424             */
1425            public int countAll() throws SystemException {
1426                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1427                                    FINDER_ARGS_EMPTY, this);
1428    
1429                    if (count == null) {
1430                            Session session = null;
1431    
1432                            try {
1433                                    session = openSession();
1434    
1435                                    Query q = session.createQuery(_SQL_COUNT_ORGGROUPROLE);
1436    
1437                                    count = (Long)q.uniqueResult();
1438                            }
1439                            catch (Exception e) {
1440                                    throw processException(e);
1441                            }
1442                            finally {
1443                                    if (count == null) {
1444                                            count = Long.valueOf(0);
1445                                    }
1446    
1447                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1448                                            FINDER_ARGS_EMPTY, count);
1449    
1450                                    closeSession(session);
1451                            }
1452                    }
1453    
1454                    return count.intValue();
1455            }
1456    
1457            /**
1458             * Initializes the org group role persistence.
1459             */
1460            public void afterPropertiesSet() {
1461                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1462                                            com.liferay.portal.util.PropsUtil.get(
1463                                                    "value.object.listener.com.liferay.portal.model.OrgGroupRole")));
1464    
1465                    if (listenerClassNames.length > 0) {
1466                            try {
1467                                    List<ModelListener<OrgGroupRole>> listenersList = new ArrayList<ModelListener<OrgGroupRole>>();
1468    
1469                                    for (String listenerClassName : listenerClassNames) {
1470                                            listenersList.add((ModelListener<OrgGroupRole>)InstanceFactory.newInstance(
1471                                                            listenerClassName));
1472                                    }
1473    
1474                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1475                            }
1476                            catch (Exception e) {
1477                                    _log.error(e);
1478                            }
1479                    }
1480            }
1481    
1482            public void destroy() {
1483                    EntityCacheUtil.removeCache(OrgGroupRoleImpl.class.getName());
1484                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1485                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1486            }
1487    
1488            @BeanReference(type = AccountPersistence.class)
1489            protected AccountPersistence accountPersistence;
1490            @BeanReference(type = AddressPersistence.class)
1491            protected AddressPersistence addressPersistence;
1492            @BeanReference(type = BrowserTrackerPersistence.class)
1493            protected BrowserTrackerPersistence browserTrackerPersistence;
1494            @BeanReference(type = ClassNamePersistence.class)
1495            protected ClassNamePersistence classNamePersistence;
1496            @BeanReference(type = ClusterGroupPersistence.class)
1497            protected ClusterGroupPersistence clusterGroupPersistence;
1498            @BeanReference(type = CompanyPersistence.class)
1499            protected CompanyPersistence companyPersistence;
1500            @BeanReference(type = ContactPersistence.class)
1501            protected ContactPersistence contactPersistence;
1502            @BeanReference(type = CountryPersistence.class)
1503            protected CountryPersistence countryPersistence;
1504            @BeanReference(type = EmailAddressPersistence.class)
1505            protected EmailAddressPersistence emailAddressPersistence;
1506            @BeanReference(type = GroupPersistence.class)
1507            protected GroupPersistence groupPersistence;
1508            @BeanReference(type = ImagePersistence.class)
1509            protected ImagePersistence imagePersistence;
1510            @BeanReference(type = LayoutPersistence.class)
1511            protected LayoutPersistence layoutPersistence;
1512            @BeanReference(type = LayoutBranchPersistence.class)
1513            protected LayoutBranchPersistence layoutBranchPersistence;
1514            @BeanReference(type = LayoutPrototypePersistence.class)
1515            protected LayoutPrototypePersistence layoutPrototypePersistence;
1516            @BeanReference(type = LayoutRevisionPersistence.class)
1517            protected LayoutRevisionPersistence layoutRevisionPersistence;
1518            @BeanReference(type = LayoutSetPersistence.class)
1519            protected LayoutSetPersistence layoutSetPersistence;
1520            @BeanReference(type = LayoutSetBranchPersistence.class)
1521            protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1522            @BeanReference(type = LayoutSetPrototypePersistence.class)
1523            protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1524            @BeanReference(type = ListTypePersistence.class)
1525            protected ListTypePersistence listTypePersistence;
1526            @BeanReference(type = LockPersistence.class)
1527            protected LockPersistence lockPersistence;
1528            @BeanReference(type = MembershipRequestPersistence.class)
1529            protected MembershipRequestPersistence membershipRequestPersistence;
1530            @BeanReference(type = OrganizationPersistence.class)
1531            protected OrganizationPersistence organizationPersistence;
1532            @BeanReference(type = OrgGroupPermissionPersistence.class)
1533            protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1534            @BeanReference(type = OrgGroupRolePersistence.class)
1535            protected OrgGroupRolePersistence orgGroupRolePersistence;
1536            @BeanReference(type = OrgLaborPersistence.class)
1537            protected OrgLaborPersistence orgLaborPersistence;
1538            @BeanReference(type = PasswordPolicyPersistence.class)
1539            protected PasswordPolicyPersistence passwordPolicyPersistence;
1540            @BeanReference(type = PasswordPolicyRelPersistence.class)
1541            protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1542            @BeanReference(type = PasswordTrackerPersistence.class)
1543            protected PasswordTrackerPersistence passwordTrackerPersistence;
1544            @BeanReference(type = PermissionPersistence.class)
1545            protected PermissionPersistence permissionPersistence;
1546            @BeanReference(type = PhonePersistence.class)
1547            protected PhonePersistence phonePersistence;
1548            @BeanReference(type = PluginSettingPersistence.class)
1549            protected PluginSettingPersistence pluginSettingPersistence;
1550            @BeanReference(type = PortalPreferencesPersistence.class)
1551            protected PortalPreferencesPersistence portalPreferencesPersistence;
1552            @BeanReference(type = PortletPersistence.class)
1553            protected PortletPersistence portletPersistence;
1554            @BeanReference(type = PortletItemPersistence.class)
1555            protected PortletItemPersistence portletItemPersistence;
1556            @BeanReference(type = PortletPreferencesPersistence.class)
1557            protected PortletPreferencesPersistence portletPreferencesPersistence;
1558            @BeanReference(type = RegionPersistence.class)
1559            protected RegionPersistence regionPersistence;
1560            @BeanReference(type = ReleasePersistence.class)
1561            protected ReleasePersistence releasePersistence;
1562            @BeanReference(type = RepositoryPersistence.class)
1563            protected RepositoryPersistence repositoryPersistence;
1564            @BeanReference(type = RepositoryEntryPersistence.class)
1565            protected RepositoryEntryPersistence repositoryEntryPersistence;
1566            @BeanReference(type = ResourcePersistence.class)
1567            protected ResourcePersistence resourcePersistence;
1568            @BeanReference(type = ResourceActionPersistence.class)
1569            protected ResourceActionPersistence resourceActionPersistence;
1570            @BeanReference(type = ResourceBlockPersistence.class)
1571            protected ResourceBlockPersistence resourceBlockPersistence;
1572            @BeanReference(type = ResourceBlockPermissionPersistence.class)
1573            protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1574            @BeanReference(type = ResourceCodePersistence.class)
1575            protected ResourceCodePersistence resourceCodePersistence;
1576            @BeanReference(type = ResourcePermissionPersistence.class)
1577            protected ResourcePermissionPersistence resourcePermissionPersistence;
1578            @BeanReference(type = ResourceTypePermissionPersistence.class)
1579            protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1580            @BeanReference(type = RolePersistence.class)
1581            protected RolePersistence rolePersistence;
1582            @BeanReference(type = ServiceComponentPersistence.class)
1583            protected ServiceComponentPersistence serviceComponentPersistence;
1584            @BeanReference(type = ShardPersistence.class)
1585            protected ShardPersistence shardPersistence;
1586            @BeanReference(type = SubscriptionPersistence.class)
1587            protected SubscriptionPersistence subscriptionPersistence;
1588            @BeanReference(type = TeamPersistence.class)
1589            protected TeamPersistence teamPersistence;
1590            @BeanReference(type = TicketPersistence.class)
1591            protected TicketPersistence ticketPersistence;
1592            @BeanReference(type = UserPersistence.class)
1593            protected UserPersistence userPersistence;
1594            @BeanReference(type = UserGroupPersistence.class)
1595            protected UserGroupPersistence userGroupPersistence;
1596            @BeanReference(type = UserGroupGroupRolePersistence.class)
1597            protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1598            @BeanReference(type = UserGroupRolePersistence.class)
1599            protected UserGroupRolePersistence userGroupRolePersistence;
1600            @BeanReference(type = UserIdMapperPersistence.class)
1601            protected UserIdMapperPersistence userIdMapperPersistence;
1602            @BeanReference(type = UserNotificationEventPersistence.class)
1603            protected UserNotificationEventPersistence userNotificationEventPersistence;
1604            @BeanReference(type = UserTrackerPersistence.class)
1605            protected UserTrackerPersistence userTrackerPersistence;
1606            @BeanReference(type = UserTrackerPathPersistence.class)
1607            protected UserTrackerPathPersistence userTrackerPathPersistence;
1608            @BeanReference(type = VirtualHostPersistence.class)
1609            protected VirtualHostPersistence virtualHostPersistence;
1610            @BeanReference(type = WebDAVPropsPersistence.class)
1611            protected WebDAVPropsPersistence webDAVPropsPersistence;
1612            @BeanReference(type = WebsitePersistence.class)
1613            protected WebsitePersistence websitePersistence;
1614            @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1615            protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1616            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1617            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1618            private static final String _SQL_SELECT_ORGGROUPROLE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole";
1619            private static final String _SQL_SELECT_ORGGROUPROLE_WHERE = "SELECT orgGroupRole FROM OrgGroupRole orgGroupRole WHERE ";
1620            private static final String _SQL_COUNT_ORGGROUPROLE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole";
1621            private static final String _SQL_COUNT_ORGGROUPROLE_WHERE = "SELECT COUNT(orgGroupRole) FROM OrgGroupRole orgGroupRole WHERE ";
1622            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupRole.id.groupId = ?";
1623            private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "orgGroupRole.id.roleId = ?";
1624            private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupRole.";
1625            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupRole exists with the primary key ";
1626            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupRole exists with the key {";
1627            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1628            private static Log _log = LogFactoryUtil.getLog(OrgGroupRolePersistenceImpl.class);
1629            private static OrgGroupRole _nullOrgGroupRole = new OrgGroupRoleImpl() {
1630                            @Override
1631                            public Object clone() {
1632                                    return this;
1633                            }
1634    
1635                            @Override
1636                            public CacheModel<OrgGroupRole> toCacheModel() {
1637                                    return _nullOrgGroupRoleCacheModel;
1638                            }
1639                    };
1640    
1641            private static CacheModel<OrgGroupRole> _nullOrgGroupRoleCacheModel = new CacheModel<OrgGroupRole>() {
1642                            public OrgGroupRole toEntityModel() {
1643                                    return _nullOrgGroupRole;
1644                            }
1645                    };
1646    }