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