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