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.DynamicQuery;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
29  import com.liferay.portal.kernel.exception.SystemException;
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     public OrgGroupPermission updateImpl(
233         com.liferay.portal.model.OrgGroupPermission orgGroupPermission,
234         boolean merge) throws SystemException {
235         orgGroupPermission = toUnwrappedModel(orgGroupPermission);
236 
237         Session session = null;
238 
239         try {
240             session = openSession();
241 
242             BatchSessionUtil.update(session, orgGroupPermission, merge);
243 
244             orgGroupPermission.setNew(false);
245         }
246         catch (Exception e) {
247             throw processException(e);
248         }
249         finally {
250             closeSession(session);
251         }
252 
253         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
254 
255         EntityCacheUtil.putResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
256             OrgGroupPermissionImpl.class, orgGroupPermission.getPrimaryKey(),
257             orgGroupPermission);
258 
259         return orgGroupPermission;
260     }
261 
262     protected OrgGroupPermission toUnwrappedModel(
263         OrgGroupPermission orgGroupPermission) {
264         if (orgGroupPermission instanceof OrgGroupPermissionImpl) {
265             return orgGroupPermission;
266         }
267 
268         OrgGroupPermissionImpl orgGroupPermissionImpl = new OrgGroupPermissionImpl();
269 
270         orgGroupPermissionImpl.setNew(orgGroupPermission.isNew());
271         orgGroupPermissionImpl.setPrimaryKey(orgGroupPermission.getPrimaryKey());
272 
273         orgGroupPermissionImpl.setOrganizationId(orgGroupPermission.getOrganizationId());
274         orgGroupPermissionImpl.setGroupId(orgGroupPermission.getGroupId());
275         orgGroupPermissionImpl.setPermissionId(orgGroupPermission.getPermissionId());
276 
277         return orgGroupPermissionImpl;
278     }
279 
280     public OrgGroupPermission findByPrimaryKey(Serializable primaryKey)
281         throws NoSuchModelException, SystemException {
282         return findByPrimaryKey((OrgGroupPermissionPK)primaryKey);
283     }
284 
285     public OrgGroupPermission findByPrimaryKey(
286         OrgGroupPermissionPK orgGroupPermissionPK)
287         throws NoSuchOrgGroupPermissionException, SystemException {
288         OrgGroupPermission orgGroupPermission = fetchByPrimaryKey(orgGroupPermissionPK);
289 
290         if (orgGroupPermission == null) {
291             if (_log.isWarnEnabled()) {
292                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
293                     orgGroupPermissionPK);
294             }
295 
296             throw new NoSuchOrgGroupPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
297                 orgGroupPermissionPK);
298         }
299 
300         return orgGroupPermission;
301     }
302 
303     public OrgGroupPermission fetchByPrimaryKey(Serializable primaryKey)
304         throws SystemException {
305         return fetchByPrimaryKey((OrgGroupPermissionPK)primaryKey);
306     }
307 
308     public OrgGroupPermission fetchByPrimaryKey(
309         OrgGroupPermissionPK orgGroupPermissionPK) throws SystemException {
310         OrgGroupPermission orgGroupPermission = (OrgGroupPermission)EntityCacheUtil.getResult(OrgGroupPermissionModelImpl.ENTITY_CACHE_ENABLED,
311                 OrgGroupPermissionImpl.class, orgGroupPermissionPK, this);
312 
313         if (orgGroupPermission == null) {
314             Session session = null;
315 
316             try {
317                 session = openSession();
318 
319                 orgGroupPermission = (OrgGroupPermission)session.get(OrgGroupPermissionImpl.class,
320                         orgGroupPermissionPK);
321             }
322             catch (Exception e) {
323                 throw processException(e);
324             }
325             finally {
326                 if (orgGroupPermission != null) {
327                     cacheResult(orgGroupPermission);
328                 }
329 
330                 closeSession(session);
331             }
332         }
333 
334         return orgGroupPermission;
335     }
336 
337     public List<OrgGroupPermission> findByGroupId(long groupId)
338         throws SystemException {
339         Object[] finderArgs = new Object[] { new Long(groupId) };
340 
341         List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
342                 finderArgs, this);
343 
344         if (list == null) {
345             Session session = null;
346 
347             try {
348                 session = openSession();
349 
350                 StringBundler query = new StringBundler(2);
351 
352                 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
353 
354                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
355 
356                 String sql = query.toString();
357 
358                 Query q = session.createQuery(sql);
359 
360                 QueryPos qPos = QueryPos.getInstance(q);
361 
362                 qPos.add(groupId);
363 
364                 list = q.list();
365             }
366             catch (Exception e) {
367                 throw processException(e);
368             }
369             finally {
370                 if (list == null) {
371                     list = new ArrayList<OrgGroupPermission>();
372                 }
373 
374                 cacheResult(list);
375 
376                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
377                     finderArgs, list);
378 
379                 closeSession(session);
380             }
381         }
382 
383         return list;
384     }
385 
386     public List<OrgGroupPermission> findByGroupId(long groupId, int start,
387         int end) throws SystemException {
388         return findByGroupId(groupId, start, end, null);
389     }
390 
391     public List<OrgGroupPermission> findByGroupId(long groupId, int start,
392         int end, OrderByComparator obc) throws SystemException {
393         Object[] finderArgs = new Object[] {
394                 new Long(groupId),
395                 
396                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
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 (obc != null) {
411                     query = new StringBundler(3 +
412                             (obc.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 (obc != null) {
423                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
424                 }
425 
426                 String sql = query.toString();
427 
428                 Query q = session.createQuery(sql);
429 
430                 QueryPos qPos = QueryPos.getInstance(q);
431 
432                 qPos.add(groupId);
433 
434                 list = (List<OrgGroupPermission>)QueryUtil.list(q,
435                         getDialect(), start, end);
436             }
437             catch (Exception e) {
438                 throw processException(e);
439             }
440             finally {
441                 if (list == null) {
442                     list = new ArrayList<OrgGroupPermission>();
443                 }
444 
445                 cacheResult(list);
446 
447                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
448                     finderArgs, list);
449 
450                 closeSession(session);
451             }
452         }
453 
454         return list;
455     }
456 
457     public OrgGroupPermission findByGroupId_First(long groupId,
458         OrderByComparator obc)
459         throws NoSuchOrgGroupPermissionException, SystemException {
460         List<OrgGroupPermission> list = findByGroupId(groupId, 0, 1, obc);
461 
462         if (list.isEmpty()) {
463             StringBundler msg = new StringBundler(4);
464 
465             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
466 
467             msg.append("groupId=");
468             msg.append(groupId);
469 
470             msg.append(StringPool.CLOSE_CURLY_BRACE);
471 
472             throw new NoSuchOrgGroupPermissionException(msg.toString());
473         }
474         else {
475             return list.get(0);
476         }
477     }
478 
479     public OrgGroupPermission findByGroupId_Last(long groupId,
480         OrderByComparator obc)
481         throws NoSuchOrgGroupPermissionException, SystemException {
482         int count = countByGroupId(groupId);
483 
484         List<OrgGroupPermission> list = findByGroupId(groupId, count - 1,
485                 count, obc);
486 
487         if (list.isEmpty()) {
488             StringBundler msg = new StringBundler(4);
489 
490             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
491 
492             msg.append("groupId=");
493             msg.append(groupId);
494 
495             msg.append(StringPool.CLOSE_CURLY_BRACE);
496 
497             throw new NoSuchOrgGroupPermissionException(msg.toString());
498         }
499         else {
500             return list.get(0);
501         }
502     }
503 
504     public OrgGroupPermission[] findByGroupId_PrevAndNext(
505         OrgGroupPermissionPK orgGroupPermissionPK, long groupId,
506         OrderByComparator obc)
507         throws NoSuchOrgGroupPermissionException, SystemException {
508         OrgGroupPermission orgGroupPermission = findByPrimaryKey(orgGroupPermissionPK);
509 
510         int count = countByGroupId(groupId);
511 
512         Session session = null;
513 
514         try {
515             session = openSession();
516 
517             StringBundler query = null;
518 
519             if (obc != null) {
520                 query = new StringBundler(3 +
521                         (obc.getOrderByFields().length * 3));
522             }
523             else {
524                 query = new StringBundler(2);
525             }
526 
527             query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
528 
529             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
530 
531             if (obc != null) {
532                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
533             }
534 
535             String sql = query.toString();
536 
537             Query q = session.createQuery(sql);
538 
539             QueryPos qPos = QueryPos.getInstance(q);
540 
541             qPos.add(groupId);
542 
543             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
544                     orgGroupPermission);
545 
546             OrgGroupPermission[] array = new OrgGroupPermissionImpl[3];
547 
548             array[0] = (OrgGroupPermission)objArray[0];
549             array[1] = (OrgGroupPermission)objArray[1];
550             array[2] = (OrgGroupPermission)objArray[2];
551 
552             return array;
553         }
554         catch (Exception e) {
555             throw processException(e);
556         }
557         finally {
558             closeSession(session);
559         }
560     }
561 
562     public List<OrgGroupPermission> findByPermissionId(long permissionId)
563         throws SystemException {
564         Object[] finderArgs = new Object[] { new Long(permissionId) };
565 
566         List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_PERMISSIONID,
567                 finderArgs, this);
568 
569         if (list == null) {
570             Session session = null;
571 
572             try {
573                 session = openSession();
574 
575                 StringBundler query = new StringBundler(2);
576 
577                 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
578 
579                 query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
580 
581                 String sql = query.toString();
582 
583                 Query q = session.createQuery(sql);
584 
585                 QueryPos qPos = QueryPos.getInstance(q);
586 
587                 qPos.add(permissionId);
588 
589                 list = q.list();
590             }
591             catch (Exception e) {
592                 throw processException(e);
593             }
594             finally {
595                 if (list == null) {
596                     list = new ArrayList<OrgGroupPermission>();
597                 }
598 
599                 cacheResult(list);
600 
601                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_PERMISSIONID,
602                     finderArgs, list);
603 
604                 closeSession(session);
605             }
606         }
607 
608         return list;
609     }
610 
611     public List<OrgGroupPermission> findByPermissionId(long permissionId,
612         int start, int end) throws SystemException {
613         return findByPermissionId(permissionId, start, end, null);
614     }
615 
616     public List<OrgGroupPermission> findByPermissionId(long permissionId,
617         int start, int end, OrderByComparator obc) throws SystemException {
618         Object[] finderArgs = new Object[] {
619                 new Long(permissionId),
620                 
621                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
622             };
623 
624         List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_PERMISSIONID,
625                 finderArgs, this);
626 
627         if (list == null) {
628             Session session = null;
629 
630             try {
631                 session = openSession();
632 
633                 StringBundler query = null;
634 
635                 if (obc != null) {
636                     query = new StringBundler(3 +
637                             (obc.getOrderByFields().length * 3));
638                 }
639                 else {
640                     query = new StringBundler(2);
641                 }
642 
643                 query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
644 
645                 query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
646 
647                 if (obc != null) {
648                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
649                 }
650 
651                 String sql = query.toString();
652 
653                 Query q = session.createQuery(sql);
654 
655                 QueryPos qPos = QueryPos.getInstance(q);
656 
657                 qPos.add(permissionId);
658 
659                 list = (List<OrgGroupPermission>)QueryUtil.list(q,
660                         getDialect(), start, end);
661             }
662             catch (Exception e) {
663                 throw processException(e);
664             }
665             finally {
666                 if (list == null) {
667                     list = new ArrayList<OrgGroupPermission>();
668                 }
669 
670                 cacheResult(list);
671 
672                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_PERMISSIONID,
673                     finderArgs, list);
674 
675                 closeSession(session);
676             }
677         }
678 
679         return list;
680     }
681 
682     public OrgGroupPermission findByPermissionId_First(long permissionId,
683         OrderByComparator obc)
684         throws NoSuchOrgGroupPermissionException, SystemException {
685         List<OrgGroupPermission> list = findByPermissionId(permissionId, 0, 1,
686                 obc);
687 
688         if (list.isEmpty()) {
689             StringBundler msg = new StringBundler(4);
690 
691             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
692 
693             msg.append("permissionId=");
694             msg.append(permissionId);
695 
696             msg.append(StringPool.CLOSE_CURLY_BRACE);
697 
698             throw new NoSuchOrgGroupPermissionException(msg.toString());
699         }
700         else {
701             return list.get(0);
702         }
703     }
704 
705     public OrgGroupPermission findByPermissionId_Last(long permissionId,
706         OrderByComparator obc)
707         throws NoSuchOrgGroupPermissionException, SystemException {
708         int count = countByPermissionId(permissionId);
709 
710         List<OrgGroupPermission> list = findByPermissionId(permissionId,
711                 count - 1, count, obc);
712 
713         if (list.isEmpty()) {
714             StringBundler msg = new StringBundler(4);
715 
716             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
717 
718             msg.append("permissionId=");
719             msg.append(permissionId);
720 
721             msg.append(StringPool.CLOSE_CURLY_BRACE);
722 
723             throw new NoSuchOrgGroupPermissionException(msg.toString());
724         }
725         else {
726             return list.get(0);
727         }
728     }
729 
730     public OrgGroupPermission[] findByPermissionId_PrevAndNext(
731         OrgGroupPermissionPK orgGroupPermissionPK, long permissionId,
732         OrderByComparator obc)
733         throws NoSuchOrgGroupPermissionException, SystemException {
734         OrgGroupPermission orgGroupPermission = findByPrimaryKey(orgGroupPermissionPK);
735 
736         int count = countByPermissionId(permissionId);
737 
738         Session session = null;
739 
740         try {
741             session = openSession();
742 
743             StringBundler query = null;
744 
745             if (obc != null) {
746                 query = new StringBundler(3 +
747                         (obc.getOrderByFields().length * 3));
748             }
749             else {
750                 query = new StringBundler(2);
751             }
752 
753             query.append(_SQL_SELECT_ORGGROUPPERMISSION_WHERE);
754 
755             query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
756 
757             if (obc != null) {
758                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
759             }
760 
761             String sql = query.toString();
762 
763             Query q = session.createQuery(sql);
764 
765             QueryPos qPos = QueryPos.getInstance(q);
766 
767             qPos.add(permissionId);
768 
769             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
770                     orgGroupPermission);
771 
772             OrgGroupPermission[] array = new OrgGroupPermissionImpl[3];
773 
774             array[0] = (OrgGroupPermission)objArray[0];
775             array[1] = (OrgGroupPermission)objArray[1];
776             array[2] = (OrgGroupPermission)objArray[2];
777 
778             return array;
779         }
780         catch (Exception e) {
781             throw processException(e);
782         }
783         finally {
784             closeSession(session);
785         }
786     }
787 
788     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
789         throws SystemException {
790         Session session = null;
791 
792         try {
793             session = openSession();
794 
795             dynamicQuery.compile(session);
796 
797             return dynamicQuery.list();
798         }
799         catch (Exception e) {
800             throw processException(e);
801         }
802         finally {
803             closeSession(session);
804         }
805     }
806 
807     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
808         int start, int end) throws SystemException {
809         Session session = null;
810 
811         try {
812             session = openSession();
813 
814             dynamicQuery.setLimit(start, end);
815 
816             dynamicQuery.compile(session);
817 
818             return dynamicQuery.list();
819         }
820         catch (Exception e) {
821             throw processException(e);
822         }
823         finally {
824             closeSession(session);
825         }
826     }
827 
828     public List<OrgGroupPermission> findAll() throws SystemException {
829         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
830     }
831 
832     public List<OrgGroupPermission> findAll(int start, int end)
833         throws SystemException {
834         return findAll(start, end, null);
835     }
836 
837     public List<OrgGroupPermission> findAll(int start, int end,
838         OrderByComparator obc) throws SystemException {
839         Object[] finderArgs = new Object[] {
840                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
841             };
842 
843         List<OrgGroupPermission> list = (List<OrgGroupPermission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
844                 finderArgs, this);
845 
846         if (list == null) {
847             Session session = null;
848 
849             try {
850                 session = openSession();
851 
852                 StringBundler query = null;
853                 String sql = null;
854 
855                 if (obc != null) {
856                     query = new StringBundler(2 +
857                             (obc.getOrderByFields().length * 3));
858 
859                     query.append(_SQL_SELECT_ORGGROUPPERMISSION);
860 
861                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
862 
863                     sql = query.toString();
864                 }
865 
866                 sql = _SQL_SELECT_ORGGROUPPERMISSION;
867 
868                 Query q = session.createQuery(sql);
869 
870                 if (obc == null) {
871                     list = (List<OrgGroupPermission>)QueryUtil.list(q,
872                             getDialect(), start, end, false);
873 
874                     Collections.sort(list);
875                 }
876                 else {
877                     list = (List<OrgGroupPermission>)QueryUtil.list(q,
878                             getDialect(), start, end);
879                 }
880             }
881             catch (Exception e) {
882                 throw processException(e);
883             }
884             finally {
885                 if (list == null) {
886                     list = new ArrayList<OrgGroupPermission>();
887                 }
888 
889                 cacheResult(list);
890 
891                 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
892 
893                 closeSession(session);
894             }
895         }
896 
897         return list;
898     }
899 
900     public void removeByGroupId(long groupId) throws SystemException {
901         for (OrgGroupPermission orgGroupPermission : findByGroupId(groupId)) {
902             remove(orgGroupPermission);
903         }
904     }
905 
906     public void removeByPermissionId(long permissionId)
907         throws SystemException {
908         for (OrgGroupPermission orgGroupPermission : findByPermissionId(
909                 permissionId)) {
910             remove(orgGroupPermission);
911         }
912     }
913 
914     public void removeAll() throws SystemException {
915         for (OrgGroupPermission orgGroupPermission : findAll()) {
916             remove(orgGroupPermission);
917         }
918     }
919 
920     public int countByGroupId(long groupId) throws SystemException {
921         Object[] finderArgs = new Object[] { new Long(groupId) };
922 
923         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
924                 finderArgs, this);
925 
926         if (count == null) {
927             Session session = null;
928 
929             try {
930                 session = openSession();
931 
932                 StringBundler query = new StringBundler(2);
933 
934                 query.append(_SQL_COUNT_ORGGROUPPERMISSION_WHERE);
935 
936                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
937 
938                 String sql = query.toString();
939 
940                 Query q = session.createQuery(sql);
941 
942                 QueryPos qPos = QueryPos.getInstance(q);
943 
944                 qPos.add(groupId);
945 
946                 count = (Long)q.uniqueResult();
947             }
948             catch (Exception e) {
949                 throw processException(e);
950             }
951             finally {
952                 if (count == null) {
953                     count = Long.valueOf(0);
954                 }
955 
956                 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
957                     finderArgs, count);
958 
959                 closeSession(session);
960             }
961         }
962 
963         return count.intValue();
964     }
965 
966     public int countByPermissionId(long permissionId) throws SystemException {
967         Object[] finderArgs = new Object[] { new Long(permissionId) };
968 
969         Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_PERMISSIONID,
970                 finderArgs, this);
971 
972         if (count == null) {
973             Session session = null;
974 
975             try {
976                 session = openSession();
977 
978                 StringBundler query = new StringBundler(2);
979 
980                 query.append(_SQL_COUNT_ORGGROUPPERMISSION_WHERE);
981 
982                 query.append(_FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2);
983 
984                 String sql = query.toString();
985 
986                 Query q = session.createQuery(sql);
987 
988                 QueryPos qPos = QueryPos.getInstance(q);
989 
990                 qPos.add(permissionId);
991 
992                 count = (Long)q.uniqueResult();
993             }
994             catch (Exception e) {
995                 throw processException(e);
996             }
997             finally {
998                 if (count == null) {
999                     count = Long.valueOf(0);
1000                }
1001
1002                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_PERMISSIONID,
1003                    finderArgs, count);
1004
1005                closeSession(session);
1006            }
1007        }
1008
1009        return count.intValue();
1010    }
1011
1012    public int countAll() throws SystemException {
1013        Object[] finderArgs = new Object[0];
1014
1015        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1016                finderArgs, this);
1017
1018        if (count == null) {
1019            Session session = null;
1020
1021            try {
1022                session = openSession();
1023
1024                Query q = session.createQuery(_SQL_COUNT_ORGGROUPPERMISSION);
1025
1026                count = (Long)q.uniqueResult();
1027            }
1028            catch (Exception e) {
1029                throw processException(e);
1030            }
1031            finally {
1032                if (count == null) {
1033                    count = Long.valueOf(0);
1034                }
1035
1036                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1037                    count);
1038
1039                closeSession(session);
1040            }
1041        }
1042
1043        return count.intValue();
1044    }
1045
1046    public void afterPropertiesSet() {
1047        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1048                    com.liferay.portal.util.PropsUtil.get(
1049                        "value.object.listener.com.liferay.portal.model.OrgGroupPermission")));
1050
1051        if (listenerClassNames.length > 0) {
1052            try {
1053                List<ModelListener<OrgGroupPermission>> listenersList = new ArrayList<ModelListener<OrgGroupPermission>>();
1054
1055                for (String listenerClassName : listenerClassNames) {
1056                    listenersList.add((ModelListener<OrgGroupPermission>)Class.forName(
1057                            listenerClassName).newInstance());
1058                }
1059
1060                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1061            }
1062            catch (Exception e) {
1063                _log.error(e);
1064            }
1065        }
1066    }
1067
1068    @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence")
1069    protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
1070    @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence")
1071    protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
1072    @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence")
1073    protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
1074    @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence")
1075    protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
1076    @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence")
1077    protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
1078    @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence")
1079    protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
1080    @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence")
1081    protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
1082    @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence")
1083    protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
1084    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1085    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1086    @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence")
1087    protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
1088    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence")
1089    protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
1090    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPrototypePersistence")
1091    protected com.liferay.portal.service.persistence.LayoutPrototypePersistence layoutPrototypePersistence;
1092    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence")
1093    protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
1094    @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPrototypePersistence")
1095    protected com.liferay.portal.service.persistence.LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1096    @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence")
1097    protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
1098    @BeanReference(name = "com.liferay.portal.service.persistence.LockPersistence")
1099    protected com.liferay.portal.service.persistence.LockPersistence lockPersistence;
1100    @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence")
1101    protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
1102    @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence")
1103    protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
1104    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence")
1105    protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1106    @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence")
1107    protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
1108    @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence")
1109    protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
1110    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence")
1111    protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
1112    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence")
1113    protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1114    @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence")
1115    protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
1116    @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence")
1117    protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
1118    @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence")
1119    protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
1120    @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence")
1121    protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
1122    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence")
1123    protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
1124    @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence")
1125    protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
1126    @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence")
1127    protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
1128    @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence")
1129    protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
1130    @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence")
1131    protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
1132    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1133    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1134    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence")
1135    protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
1136    @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence")
1137    protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
1138    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence")
1139    protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
1140    @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence")
1141    protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
1142    @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence")
1143    protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
1144    @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence")
1145    protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
1146    @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence")
1147    protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
1148    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1149    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1150    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence")
1151    protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
1152    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupGroupRolePersistence")
1153    protected com.liferay.portal.service.persistence.UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1154    @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence")
1155    protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
1156    @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence")
1157    protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
1158    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence")
1159    protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
1160    @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence")
1161    protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
1162    @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence")
1163    protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
1164    @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence")
1165    protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
1166    @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence")
1167    protected com.liferay.portal.service.persistence.WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1168    @BeanReference(name = "com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence")
1169    protected com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1170    private static final String _SQL_SELECT_ORGGROUPPERMISSION = "SELECT orgGroupPermission FROM OrgGroupPermission orgGroupPermission";
1171    private static final String _SQL_SELECT_ORGGROUPPERMISSION_WHERE = "SELECT orgGroupPermission FROM OrgGroupPermission orgGroupPermission WHERE ";
1172    private static final String _SQL_COUNT_ORGGROUPPERMISSION = "SELECT COUNT(orgGroupPermission) FROM OrgGroupPermission orgGroupPermission";
1173    private static final String _SQL_COUNT_ORGGROUPPERMISSION_WHERE = "SELECT COUNT(orgGroupPermission) FROM OrgGroupPermission orgGroupPermission WHERE ";
1174    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "orgGroupPermission.id.groupId = ?";
1175    private static final String _FINDER_COLUMN_PERMISSIONID_PERMISSIONID_2 = "orgGroupPermission.id.permissionId = ?";
1176    private static final String _ORDER_BY_ENTITY_ALIAS = "orgGroupPermission.";
1177    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No OrgGroupPermission exists with the primary key ";
1178    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No OrgGroupPermission exists with the key {";
1179    private static Log _log = LogFactoryUtil.getLog(OrgGroupPermissionPersistenceImpl.class);
1180}