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