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