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