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