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