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