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