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