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