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