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