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