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