1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions 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.NoSuchUserGroupRoleException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.kernel.bean.InitializingBean;
28  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
30  import com.liferay.portal.kernel.dao.orm.Query;
31  import com.liferay.portal.kernel.dao.orm.QueryPos;
32  import com.liferay.portal.kernel.dao.orm.QueryUtil;
33  import com.liferay.portal.kernel.dao.orm.Session;
34  import com.liferay.portal.kernel.util.GetterUtil;
35  import com.liferay.portal.kernel.util.ListUtil;
36  import com.liferay.portal.kernel.util.OrderByComparator;
37  import com.liferay.portal.kernel.util.StringPool;
38  import com.liferay.portal.kernel.util.StringUtil;
39  import com.liferay.portal.model.ModelListener;
40  import com.liferay.portal.model.UserGroupRole;
41  import com.liferay.portal.model.impl.UserGroupRoleImpl;
42  import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
43  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
44  
45  import org.apache.commons.logging.Log;
46  import org.apache.commons.logging.LogFactory;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.Iterator;
51  import java.util.List;
52  
53  /**
54   * <a href="UserGroupRolePersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   */
59  public class UserGroupRolePersistenceImpl extends BasePersistenceImpl
60      implements UserGroupRolePersistence, InitializingBean {
61      public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
62          UserGroupRole userGroupRole = new UserGroupRoleImpl();
63  
64          userGroupRole.setNew(true);
65          userGroupRole.setPrimaryKey(userGroupRolePK);
66  
67          return userGroupRole;
68      }
69  
70      public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
71          throws NoSuchUserGroupRoleException, SystemException {
72          Session session = null;
73  
74          try {
75              session = openSession();
76  
77              UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
78                      userGroupRolePK);
79  
80              if (userGroupRole == null) {
81                  if (_log.isWarnEnabled()) {
82                      _log.warn("No UserGroupRole exists with the primary key " +
83                          userGroupRolePK);
84                  }
85  
86                  throw new NoSuchUserGroupRoleException(
87                      "No UserGroupRole exists with the primary key " +
88                      userGroupRolePK);
89              }
90  
91              return remove(userGroupRole);
92          }
93          catch (NoSuchUserGroupRoleException nsee) {
94              throw nsee;
95          }
96          catch (Exception e) {
97              throw processException(e);
98          }
99          finally {
100             closeSession(session);
101         }
102     }
103 
104     public UserGroupRole remove(UserGroupRole userGroupRole)
105         throws SystemException {
106         if (_listeners.length > 0) {
107             for (ModelListener listener : _listeners) {
108                 listener.onBeforeRemove(userGroupRole);
109             }
110         }
111 
112         userGroupRole = removeImpl(userGroupRole);
113 
114         if (_listeners.length > 0) {
115             for (ModelListener listener : _listeners) {
116                 listener.onAfterRemove(userGroupRole);
117             }
118         }
119 
120         return userGroupRole;
121     }
122 
123     protected UserGroupRole removeImpl(UserGroupRole userGroupRole)
124         throws SystemException {
125         Session session = null;
126 
127         try {
128             session = openSession();
129 
130             session.delete(userGroupRole);
131 
132             session.flush();
133 
134             return userGroupRole;
135         }
136         catch (Exception e) {
137             throw processException(e);
138         }
139         finally {
140             closeSession(session);
141 
142             FinderCacheUtil.clearCache(UserGroupRole.class.getName());
143         }
144     }
145 
146     /**
147      * @deprecated Use <code>update(UserGroupRole userGroupRole, boolean merge)</code>.
148      */
149     public UserGroupRole update(UserGroupRole userGroupRole)
150         throws SystemException {
151         if (_log.isWarnEnabled()) {
152             _log.warn(
153                 "Using the deprecated update(UserGroupRole userGroupRole) method. Use update(UserGroupRole userGroupRole, boolean merge) instead.");
154         }
155 
156         return update(userGroupRole, false);
157     }
158 
159     /**
160      * Add, update, or merge, the entity. This method also calls the model
161      * listeners to trigger the proper events associated with adding, deleting,
162      * or updating an entity.
163      *
164      * @param        userGroupRole the entity to add, update, or merge
165      * @param        merge boolean value for whether to merge the entity. The
166      *                default value is false. Setting merge to true is more
167      *                expensive and should only be true when userGroupRole is
168      *                transient. See LEP-5473 for a detailed discussion of this
169      *                method.
170      * @return        true if the portlet can be displayed via Ajax
171      */
172     public UserGroupRole update(UserGroupRole userGroupRole, boolean merge)
173         throws SystemException {
174         boolean isNew = userGroupRole.isNew();
175 
176         if (_listeners.length > 0) {
177             for (ModelListener listener : _listeners) {
178                 if (isNew) {
179                     listener.onBeforeCreate(userGroupRole);
180                 }
181                 else {
182                     listener.onBeforeUpdate(userGroupRole);
183                 }
184             }
185         }
186 
187         userGroupRole = updateImpl(userGroupRole, merge);
188 
189         if (_listeners.length > 0) {
190             for (ModelListener listener : _listeners) {
191                 if (isNew) {
192                     listener.onAfterCreate(userGroupRole);
193                 }
194                 else {
195                     listener.onAfterUpdate(userGroupRole);
196                 }
197             }
198         }
199 
200         return userGroupRole;
201     }
202 
203     public UserGroupRole updateImpl(
204         com.liferay.portal.model.UserGroupRole userGroupRole, boolean merge)
205         throws SystemException {
206         Session session = null;
207 
208         try {
209             session = openSession();
210 
211             if (merge) {
212                 session.merge(userGroupRole);
213             }
214             else {
215                 if (userGroupRole.isNew()) {
216                     session.save(userGroupRole);
217                 }
218             }
219 
220             session.flush();
221 
222             userGroupRole.setNew(false);
223 
224             return userGroupRole;
225         }
226         catch (Exception e) {
227             throw processException(e);
228         }
229         finally {
230             closeSession(session);
231 
232             FinderCacheUtil.clearCache(UserGroupRole.class.getName());
233         }
234     }
235 
236     public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
237         throws NoSuchUserGroupRoleException, SystemException {
238         UserGroupRole userGroupRole = fetchByPrimaryKey(userGroupRolePK);
239 
240         if (userGroupRole == null) {
241             if (_log.isWarnEnabled()) {
242                 _log.warn("No UserGroupRole exists with the primary key " +
243                     userGroupRolePK);
244             }
245 
246             throw new NoSuchUserGroupRoleException(
247                 "No UserGroupRole exists with the primary key " +
248                 userGroupRolePK);
249         }
250 
251         return userGroupRole;
252     }
253 
254     public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK)
255         throws SystemException {
256         Session session = null;
257 
258         try {
259             session = openSession();
260 
261             return (UserGroupRole)session.get(UserGroupRoleImpl.class,
262                 userGroupRolePK);
263         }
264         catch (Exception e) {
265             throw processException(e);
266         }
267         finally {
268             closeSession(session);
269         }
270     }
271 
272     public List<UserGroupRole> findByUserId(long userId)
273         throws SystemException {
274         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
275         String finderClassName = UserGroupRole.class.getName();
276         String finderMethodName = "findByUserId";
277         String[] finderParams = new String[] { Long.class.getName() };
278         Object[] finderArgs = new Object[] { new Long(userId) };
279 
280         Object result = null;
281 
282         if (finderClassNameCacheEnabled) {
283             result = FinderCacheUtil.getResult(finderClassName,
284                     finderMethodName, finderParams, finderArgs, this);
285         }
286 
287         if (result == null) {
288             Session session = null;
289 
290             try {
291                 session = openSession();
292 
293                 StringBuilder query = new StringBuilder();
294 
295                 query.append(
296                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
297 
298                 query.append("userId = ?");
299 
300                 query.append(" ");
301 
302                 Query q = session.createQuery(query.toString());
303 
304                 QueryPos qPos = QueryPos.getInstance(q);
305 
306                 qPos.add(userId);
307 
308                 List<UserGroupRole> list = q.list();
309 
310                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
311                     finderClassName, finderMethodName, finderParams,
312                     finderArgs, list);
313 
314                 return list;
315             }
316             catch (Exception e) {
317                 throw processException(e);
318             }
319             finally {
320                 closeSession(session);
321             }
322         }
323         else {
324             return (List<UserGroupRole>)result;
325         }
326     }
327 
328     public List<UserGroupRole> findByUserId(long userId, int start, int end)
329         throws SystemException {
330         return findByUserId(userId, start, end, null);
331     }
332 
333     public List<UserGroupRole> findByUserId(long userId, int start, int end,
334         OrderByComparator obc) throws SystemException {
335         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
336         String finderClassName = UserGroupRole.class.getName();
337         String finderMethodName = "findByUserId";
338         String[] finderParams = new String[] {
339                 Long.class.getName(),
340                 
341                 "java.lang.Integer", "java.lang.Integer",
342                 "com.liferay.portal.kernel.util.OrderByComparator"
343             };
344         Object[] finderArgs = new Object[] {
345                 new Long(userId),
346                 
347                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
348             };
349 
350         Object result = null;
351 
352         if (finderClassNameCacheEnabled) {
353             result = FinderCacheUtil.getResult(finderClassName,
354                     finderMethodName, finderParams, finderArgs, this);
355         }
356 
357         if (result == null) {
358             Session session = null;
359 
360             try {
361                 session = openSession();
362 
363                 StringBuilder query = new StringBuilder();
364 
365                 query.append(
366                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
367 
368                 query.append("userId = ?");
369 
370                 query.append(" ");
371 
372                 if (obc != null) {
373                     query.append("ORDER BY ");
374                     query.append(obc.getOrderBy());
375                 }
376 
377                 Query q = session.createQuery(query.toString());
378 
379                 QueryPos qPos = QueryPos.getInstance(q);
380 
381                 qPos.add(userId);
382 
383                 List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
384                         getDialect(), start, end);
385 
386                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
387                     finderClassName, finderMethodName, finderParams,
388                     finderArgs, list);
389 
390                 return list;
391             }
392             catch (Exception e) {
393                 throw processException(e);
394             }
395             finally {
396                 closeSession(session);
397             }
398         }
399         else {
400             return (List<UserGroupRole>)result;
401         }
402     }
403 
404     public UserGroupRole findByUserId_First(long userId, OrderByComparator obc)
405         throws NoSuchUserGroupRoleException, SystemException {
406         List<UserGroupRole> list = findByUserId(userId, 0, 1, obc);
407 
408         if (list.size() == 0) {
409             StringBuilder msg = new StringBuilder();
410 
411             msg.append("No UserGroupRole exists with the key {");
412 
413             msg.append("userId=" + userId);
414 
415             msg.append(StringPool.CLOSE_CURLY_BRACE);
416 
417             throw new NoSuchUserGroupRoleException(msg.toString());
418         }
419         else {
420             return list.get(0);
421         }
422     }
423 
424     public UserGroupRole findByUserId_Last(long userId, OrderByComparator obc)
425         throws NoSuchUserGroupRoleException, SystemException {
426         int count = countByUserId(userId);
427 
428         List<UserGroupRole> list = findByUserId(userId, count - 1, count, obc);
429 
430         if (list.size() == 0) {
431             StringBuilder msg = new StringBuilder();
432 
433             msg.append("No UserGroupRole exists with the key {");
434 
435             msg.append("userId=" + userId);
436 
437             msg.append(StringPool.CLOSE_CURLY_BRACE);
438 
439             throw new NoSuchUserGroupRoleException(msg.toString());
440         }
441         else {
442             return list.get(0);
443         }
444     }
445 
446     public UserGroupRole[] findByUserId_PrevAndNext(
447         UserGroupRolePK userGroupRolePK, long userId, OrderByComparator obc)
448         throws NoSuchUserGroupRoleException, SystemException {
449         UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
450 
451         int count = countByUserId(userId);
452 
453         Session session = null;
454 
455         try {
456             session = openSession();
457 
458             StringBuilder query = new StringBuilder();
459 
460             query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
461 
462             query.append("userId = ?");
463 
464             query.append(" ");
465 
466             if (obc != null) {
467                 query.append("ORDER BY ");
468                 query.append(obc.getOrderBy());
469             }
470 
471             Query q = session.createQuery(query.toString());
472 
473             QueryPos qPos = QueryPos.getInstance(q);
474 
475             qPos.add(userId);
476 
477             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
478                     userGroupRole);
479 
480             UserGroupRole[] array = new UserGroupRoleImpl[3];
481 
482             array[0] = (UserGroupRole)objArray[0];
483             array[1] = (UserGroupRole)objArray[1];
484             array[2] = (UserGroupRole)objArray[2];
485 
486             return array;
487         }
488         catch (Exception e) {
489             throw processException(e);
490         }
491         finally {
492             closeSession(session);
493         }
494     }
495 
496     public List<UserGroupRole> findByGroupId(long groupId)
497         throws SystemException {
498         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
499         String finderClassName = UserGroupRole.class.getName();
500         String finderMethodName = "findByGroupId";
501         String[] finderParams = new String[] { Long.class.getName() };
502         Object[] finderArgs = new Object[] { new Long(groupId) };
503 
504         Object result = null;
505 
506         if (finderClassNameCacheEnabled) {
507             result = FinderCacheUtil.getResult(finderClassName,
508                     finderMethodName, finderParams, finderArgs, this);
509         }
510 
511         if (result == null) {
512             Session session = null;
513 
514             try {
515                 session = openSession();
516 
517                 StringBuilder query = new StringBuilder();
518 
519                 query.append(
520                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
521 
522                 query.append("groupId = ?");
523 
524                 query.append(" ");
525 
526                 Query q = session.createQuery(query.toString());
527 
528                 QueryPos qPos = QueryPos.getInstance(q);
529 
530                 qPos.add(groupId);
531 
532                 List<UserGroupRole> list = q.list();
533 
534                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
535                     finderClassName, finderMethodName, finderParams,
536                     finderArgs, list);
537 
538                 return list;
539             }
540             catch (Exception e) {
541                 throw processException(e);
542             }
543             finally {
544                 closeSession(session);
545             }
546         }
547         else {
548             return (List<UserGroupRole>)result;
549         }
550     }
551 
552     public List<UserGroupRole> findByGroupId(long groupId, int start, int end)
553         throws SystemException {
554         return findByGroupId(groupId, start, end, null);
555     }
556 
557     public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
558         OrderByComparator obc) throws SystemException {
559         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
560         String finderClassName = UserGroupRole.class.getName();
561         String finderMethodName = "findByGroupId";
562         String[] finderParams = new String[] {
563                 Long.class.getName(),
564                 
565                 "java.lang.Integer", "java.lang.Integer",
566                 "com.liferay.portal.kernel.util.OrderByComparator"
567             };
568         Object[] finderArgs = new Object[] {
569                 new Long(groupId),
570                 
571                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
572             };
573 
574         Object result = null;
575 
576         if (finderClassNameCacheEnabled) {
577             result = FinderCacheUtil.getResult(finderClassName,
578                     finderMethodName, finderParams, finderArgs, this);
579         }
580 
581         if (result == null) {
582             Session session = null;
583 
584             try {
585                 session = openSession();
586 
587                 StringBuilder query = new StringBuilder();
588 
589                 query.append(
590                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
591 
592                 query.append("groupId = ?");
593 
594                 query.append(" ");
595 
596                 if (obc != null) {
597                     query.append("ORDER BY ");
598                     query.append(obc.getOrderBy());
599                 }
600 
601                 Query q = session.createQuery(query.toString());
602 
603                 QueryPos qPos = QueryPos.getInstance(q);
604 
605                 qPos.add(groupId);
606 
607                 List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
608                         getDialect(), start, end);
609 
610                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
611                     finderClassName, finderMethodName, finderParams,
612                     finderArgs, list);
613 
614                 return list;
615             }
616             catch (Exception e) {
617                 throw processException(e);
618             }
619             finally {
620                 closeSession(session);
621             }
622         }
623         else {
624             return (List<UserGroupRole>)result;
625         }
626     }
627 
628     public UserGroupRole findByGroupId_First(long groupId, OrderByComparator obc)
629         throws NoSuchUserGroupRoleException, SystemException {
630         List<UserGroupRole> list = findByGroupId(groupId, 0, 1, obc);
631 
632         if (list.size() == 0) {
633             StringBuilder msg = new StringBuilder();
634 
635             msg.append("No UserGroupRole exists with the key {");
636 
637             msg.append("groupId=" + groupId);
638 
639             msg.append(StringPool.CLOSE_CURLY_BRACE);
640 
641             throw new NoSuchUserGroupRoleException(msg.toString());
642         }
643         else {
644             return list.get(0);
645         }
646     }
647 
648     public UserGroupRole findByGroupId_Last(long groupId, OrderByComparator obc)
649         throws NoSuchUserGroupRoleException, SystemException {
650         int count = countByGroupId(groupId);
651 
652         List<UserGroupRole> list = findByGroupId(groupId, count - 1, count, obc);
653 
654         if (list.size() == 0) {
655             StringBuilder msg = new StringBuilder();
656 
657             msg.append("No UserGroupRole exists with the key {");
658 
659             msg.append("groupId=" + groupId);
660 
661             msg.append(StringPool.CLOSE_CURLY_BRACE);
662 
663             throw new NoSuchUserGroupRoleException(msg.toString());
664         }
665         else {
666             return list.get(0);
667         }
668     }
669 
670     public UserGroupRole[] findByGroupId_PrevAndNext(
671         UserGroupRolePK userGroupRolePK, long groupId, OrderByComparator obc)
672         throws NoSuchUserGroupRoleException, SystemException {
673         UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
674 
675         int count = countByGroupId(groupId);
676 
677         Session session = null;
678 
679         try {
680             session = openSession();
681 
682             StringBuilder query = new StringBuilder();
683 
684             query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
685 
686             query.append("groupId = ?");
687 
688             query.append(" ");
689 
690             if (obc != null) {
691                 query.append("ORDER BY ");
692                 query.append(obc.getOrderBy());
693             }
694 
695             Query q = session.createQuery(query.toString());
696 
697             QueryPos qPos = QueryPos.getInstance(q);
698 
699             qPos.add(groupId);
700 
701             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
702                     userGroupRole);
703 
704             UserGroupRole[] array = new UserGroupRoleImpl[3];
705 
706             array[0] = (UserGroupRole)objArray[0];
707             array[1] = (UserGroupRole)objArray[1];
708             array[2] = (UserGroupRole)objArray[2];
709 
710             return array;
711         }
712         catch (Exception e) {
713             throw processException(e);
714         }
715         finally {
716             closeSession(session);
717         }
718     }
719 
720     public List<UserGroupRole> findByRoleId(long roleId)
721         throws SystemException {
722         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
723         String finderClassName = UserGroupRole.class.getName();
724         String finderMethodName = "findByRoleId";
725         String[] finderParams = new String[] { Long.class.getName() };
726         Object[] finderArgs = new Object[] { new Long(roleId) };
727 
728         Object result = null;
729 
730         if (finderClassNameCacheEnabled) {
731             result = FinderCacheUtil.getResult(finderClassName,
732                     finderMethodName, finderParams, finderArgs, this);
733         }
734 
735         if (result == null) {
736             Session session = null;
737 
738             try {
739                 session = openSession();
740 
741                 StringBuilder query = new StringBuilder();
742 
743                 query.append(
744                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
745 
746                 query.append("roleId = ?");
747 
748                 query.append(" ");
749 
750                 Query q = session.createQuery(query.toString());
751 
752                 QueryPos qPos = QueryPos.getInstance(q);
753 
754                 qPos.add(roleId);
755 
756                 List<UserGroupRole> list = q.list();
757 
758                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
759                     finderClassName, finderMethodName, finderParams,
760                     finderArgs, list);
761 
762                 return list;
763             }
764             catch (Exception e) {
765                 throw processException(e);
766             }
767             finally {
768                 closeSession(session);
769             }
770         }
771         else {
772             return (List<UserGroupRole>)result;
773         }
774     }
775 
776     public List<UserGroupRole> findByRoleId(long roleId, int start, int end)
777         throws SystemException {
778         return findByRoleId(roleId, start, end, null);
779     }
780 
781     public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
782         OrderByComparator obc) throws SystemException {
783         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
784         String finderClassName = UserGroupRole.class.getName();
785         String finderMethodName = "findByRoleId";
786         String[] finderParams = new String[] {
787                 Long.class.getName(),
788                 
789                 "java.lang.Integer", "java.lang.Integer",
790                 "com.liferay.portal.kernel.util.OrderByComparator"
791             };
792         Object[] finderArgs = new Object[] {
793                 new Long(roleId),
794                 
795                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
796             };
797 
798         Object result = null;
799 
800         if (finderClassNameCacheEnabled) {
801             result = FinderCacheUtil.getResult(finderClassName,
802                     finderMethodName, finderParams, finderArgs, this);
803         }
804 
805         if (result == null) {
806             Session session = null;
807 
808             try {
809                 session = openSession();
810 
811                 StringBuilder query = new StringBuilder();
812 
813                 query.append(
814                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
815 
816                 query.append("roleId = ?");
817 
818                 query.append(" ");
819 
820                 if (obc != null) {
821                     query.append("ORDER BY ");
822                     query.append(obc.getOrderBy());
823                 }
824 
825                 Query q = session.createQuery(query.toString());
826 
827                 QueryPos qPos = QueryPos.getInstance(q);
828 
829                 qPos.add(roleId);
830 
831                 List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
832                         getDialect(), start, end);
833 
834                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
835                     finderClassName, finderMethodName, finderParams,
836                     finderArgs, list);
837 
838                 return list;
839             }
840             catch (Exception e) {
841                 throw processException(e);
842             }
843             finally {
844                 closeSession(session);
845             }
846         }
847         else {
848             return (List<UserGroupRole>)result;
849         }
850     }
851 
852     public UserGroupRole findByRoleId_First(long roleId, OrderByComparator obc)
853         throws NoSuchUserGroupRoleException, SystemException {
854         List<UserGroupRole> list = findByRoleId(roleId, 0, 1, obc);
855 
856         if (list.size() == 0) {
857             StringBuilder msg = new StringBuilder();
858 
859             msg.append("No UserGroupRole exists with the key {");
860 
861             msg.append("roleId=" + roleId);
862 
863             msg.append(StringPool.CLOSE_CURLY_BRACE);
864 
865             throw new NoSuchUserGroupRoleException(msg.toString());
866         }
867         else {
868             return list.get(0);
869         }
870     }
871 
872     public UserGroupRole findByRoleId_Last(long roleId, OrderByComparator obc)
873         throws NoSuchUserGroupRoleException, SystemException {
874         int count = countByRoleId(roleId);
875 
876         List<UserGroupRole> list = findByRoleId(roleId, count - 1, count, obc);
877 
878         if (list.size() == 0) {
879             StringBuilder msg = new StringBuilder();
880 
881             msg.append("No UserGroupRole exists with the key {");
882 
883             msg.append("roleId=" + roleId);
884 
885             msg.append(StringPool.CLOSE_CURLY_BRACE);
886 
887             throw new NoSuchUserGroupRoleException(msg.toString());
888         }
889         else {
890             return list.get(0);
891         }
892     }
893 
894     public UserGroupRole[] findByRoleId_PrevAndNext(
895         UserGroupRolePK userGroupRolePK, long roleId, OrderByComparator obc)
896         throws NoSuchUserGroupRoleException, SystemException {
897         UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
898 
899         int count = countByRoleId(roleId);
900 
901         Session session = null;
902 
903         try {
904             session = openSession();
905 
906             StringBuilder query = new StringBuilder();
907 
908             query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
909 
910             query.append("roleId = ?");
911 
912             query.append(" ");
913 
914             if (obc != null) {
915                 query.append("ORDER BY ");
916                 query.append(obc.getOrderBy());
917             }
918 
919             Query q = session.createQuery(query.toString());
920 
921             QueryPos qPos = QueryPos.getInstance(q);
922 
923             qPos.add(roleId);
924 
925             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
926                     userGroupRole);
927 
928             UserGroupRole[] array = new UserGroupRoleImpl[3];
929 
930             array[0] = (UserGroupRole)objArray[0];
931             array[1] = (UserGroupRole)objArray[1];
932             array[2] = (UserGroupRole)objArray[2];
933 
934             return array;
935         }
936         catch (Exception e) {
937             throw processException(e);
938         }
939         finally {
940             closeSession(session);
941         }
942     }
943 
944     public List<UserGroupRole> findByU_G(long userId, long groupId)
945         throws SystemException {
946         boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
947         String finderClassName = UserGroupRole.class.getName();
948         String finderMethodName = "findByU_G";
949         String[] finderParams = new String[] {
950                 Long.class.getName(), Long.class.getName()
951             };
952         Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
953 
954         Object result = null;
955 
956         if (finderClassNameCacheEnabled) {
957             result = FinderCacheUtil.getResult(finderClassName,
958                     finderMethodName, finderParams, finderArgs, this);
959         }
960 
961         if (result == null) {
962             Session session = null;
963 
964             try {
965                 session = openSession();
966 
967                 StringBuilder query = new StringBuilder();
968 
969                 query.append(
970                     "FROM com.liferay.portal.model.UserGroupRole WHERE ");
971 
972                 query.append("userId = ?");
973 
974                 query.append(" AND ");
975 
976                 query.append("groupId = ?");
977 
978                 query.append(" ");
979 
980                 Query q = session.createQuery(query.toString());
981 
982                 QueryPos qPos = QueryPos.getInstance(q);
983 
984                 qPos.add(userId);
985 
986                 qPos.add(groupId);
987 
988                 List<UserGroupRole> list = q.list();
989 
990                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
991                     finderClassName, finderMethodName, finderParams,
992                     finderArgs, list);
993 
994                 return list;
995             }
996             catch (Exception e) {
997                 throw processException(e);
998             }
999             finally {
1000                closeSession(session);
1001            }
1002        }
1003        else {
1004            return (List<UserGroupRole>)result;
1005        }
1006    }
1007
1008    public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1009        int end) throws SystemException {
1010        return findByU_G(userId, groupId, start, end, null);
1011    }
1012
1013    public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1014        int end, OrderByComparator obc) throws SystemException {
1015        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1016        String finderClassName = UserGroupRole.class.getName();
1017        String finderMethodName = "findByU_G";
1018        String[] finderParams = new String[] {
1019                Long.class.getName(), Long.class.getName(),
1020                
1021                "java.lang.Integer", "java.lang.Integer",
1022                "com.liferay.portal.kernel.util.OrderByComparator"
1023            };
1024        Object[] finderArgs = new Object[] {
1025                new Long(userId), new Long(groupId),
1026                
1027                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1028            };
1029
1030        Object result = null;
1031
1032        if (finderClassNameCacheEnabled) {
1033            result = FinderCacheUtil.getResult(finderClassName,
1034                    finderMethodName, finderParams, finderArgs, this);
1035        }
1036
1037        if (result == null) {
1038            Session session = null;
1039
1040            try {
1041                session = openSession();
1042
1043                StringBuilder query = new StringBuilder();
1044
1045                query.append(
1046                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1047
1048                query.append("userId = ?");
1049
1050                query.append(" AND ");
1051
1052                query.append("groupId = ?");
1053
1054                query.append(" ");
1055
1056                if (obc != null) {
1057                    query.append("ORDER BY ");
1058                    query.append(obc.getOrderBy());
1059                }
1060
1061                Query q = session.createQuery(query.toString());
1062
1063                QueryPos qPos = QueryPos.getInstance(q);
1064
1065                qPos.add(userId);
1066
1067                qPos.add(groupId);
1068
1069                List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
1070                        getDialect(), start, end);
1071
1072                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1073                    finderClassName, finderMethodName, finderParams,
1074                    finderArgs, list);
1075
1076                return list;
1077            }
1078            catch (Exception e) {
1079                throw processException(e);
1080            }
1081            finally {
1082                closeSession(session);
1083            }
1084        }
1085        else {
1086            return (List<UserGroupRole>)result;
1087        }
1088    }
1089
1090    public UserGroupRole findByU_G_First(long userId, long groupId,
1091        OrderByComparator obc)
1092        throws NoSuchUserGroupRoleException, SystemException {
1093        List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1, obc);
1094
1095        if (list.size() == 0) {
1096            StringBuilder msg = new StringBuilder();
1097
1098            msg.append("No UserGroupRole exists with the key {");
1099
1100            msg.append("userId=" + userId);
1101
1102            msg.append(", ");
1103            msg.append("groupId=" + groupId);
1104
1105            msg.append(StringPool.CLOSE_CURLY_BRACE);
1106
1107            throw new NoSuchUserGroupRoleException(msg.toString());
1108        }
1109        else {
1110            return list.get(0);
1111        }
1112    }
1113
1114    public UserGroupRole findByU_G_Last(long userId, long groupId,
1115        OrderByComparator obc)
1116        throws NoSuchUserGroupRoleException, SystemException {
1117        int count = countByU_G(userId, groupId);
1118
1119        List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1120                obc);
1121
1122        if (list.size() == 0) {
1123            StringBuilder msg = new StringBuilder();
1124
1125            msg.append("No UserGroupRole exists with the key {");
1126
1127            msg.append("userId=" + userId);
1128
1129            msg.append(", ");
1130            msg.append("groupId=" + groupId);
1131
1132            msg.append(StringPool.CLOSE_CURLY_BRACE);
1133
1134            throw new NoSuchUserGroupRoleException(msg.toString());
1135        }
1136        else {
1137            return list.get(0);
1138        }
1139    }
1140
1141    public UserGroupRole[] findByU_G_PrevAndNext(
1142        UserGroupRolePK userGroupRolePK, long userId, long groupId,
1143        OrderByComparator obc)
1144        throws NoSuchUserGroupRoleException, SystemException {
1145        UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1146
1147        int count = countByU_G(userId, groupId);
1148
1149        Session session = null;
1150
1151        try {
1152            session = openSession();
1153
1154            StringBuilder query = new StringBuilder();
1155
1156            query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1157
1158            query.append("userId = ?");
1159
1160            query.append(" AND ");
1161
1162            query.append("groupId = ?");
1163
1164            query.append(" ");
1165
1166            if (obc != null) {
1167                query.append("ORDER BY ");
1168                query.append(obc.getOrderBy());
1169            }
1170
1171            Query q = session.createQuery(query.toString());
1172
1173            QueryPos qPos = QueryPos.getInstance(q);
1174
1175            qPos.add(userId);
1176
1177            qPos.add(groupId);
1178
1179            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1180                    userGroupRole);
1181
1182            UserGroupRole[] array = new UserGroupRoleImpl[3];
1183
1184            array[0] = (UserGroupRole)objArray[0];
1185            array[1] = (UserGroupRole)objArray[1];
1186            array[2] = (UserGroupRole)objArray[2];
1187
1188            return array;
1189        }
1190        catch (Exception e) {
1191            throw processException(e);
1192        }
1193        finally {
1194            closeSession(session);
1195        }
1196    }
1197
1198    public List<UserGroupRole> findByG_R(long groupId, long roleId)
1199        throws SystemException {
1200        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1201        String finderClassName = UserGroupRole.class.getName();
1202        String finderMethodName = "findByG_R";
1203        String[] finderParams = new String[] {
1204                Long.class.getName(), Long.class.getName()
1205            };
1206        Object[] finderArgs = new Object[] { new Long(groupId), new Long(roleId) };
1207
1208        Object result = null;
1209
1210        if (finderClassNameCacheEnabled) {
1211            result = FinderCacheUtil.getResult(finderClassName,
1212                    finderMethodName, finderParams, finderArgs, this);
1213        }
1214
1215        if (result == null) {
1216            Session session = null;
1217
1218            try {
1219                session = openSession();
1220
1221                StringBuilder query = new StringBuilder();
1222
1223                query.append(
1224                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1225
1226                query.append("groupId = ?");
1227
1228                query.append(" AND ");
1229
1230                query.append("roleId = ?");
1231
1232                query.append(" ");
1233
1234                Query q = session.createQuery(query.toString());
1235
1236                QueryPos qPos = QueryPos.getInstance(q);
1237
1238                qPos.add(groupId);
1239
1240                qPos.add(roleId);
1241
1242                List<UserGroupRole> list = q.list();
1243
1244                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1245                    finderClassName, finderMethodName, finderParams,
1246                    finderArgs, list);
1247
1248                return list;
1249            }
1250            catch (Exception e) {
1251                throw processException(e);
1252            }
1253            finally {
1254                closeSession(session);
1255            }
1256        }
1257        else {
1258            return (List<UserGroupRole>)result;
1259        }
1260    }
1261
1262    public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
1263        int end) throws SystemException {
1264        return findByG_R(groupId, roleId, start, end, null);
1265    }
1266
1267    public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
1268        int end, OrderByComparator obc) throws SystemException {
1269        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1270        String finderClassName = UserGroupRole.class.getName();
1271        String finderMethodName = "findByG_R";
1272        String[] finderParams = new String[] {
1273                Long.class.getName(), Long.class.getName(),
1274                
1275                "java.lang.Integer", "java.lang.Integer",
1276                "com.liferay.portal.kernel.util.OrderByComparator"
1277            };
1278        Object[] finderArgs = new Object[] {
1279                new Long(groupId), new Long(roleId),
1280                
1281                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1282            };
1283
1284        Object result = null;
1285
1286        if (finderClassNameCacheEnabled) {
1287            result = FinderCacheUtil.getResult(finderClassName,
1288                    finderMethodName, finderParams, finderArgs, this);
1289        }
1290
1291        if (result == null) {
1292            Session session = null;
1293
1294            try {
1295                session = openSession();
1296
1297                StringBuilder query = new StringBuilder();
1298
1299                query.append(
1300                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1301
1302                query.append("groupId = ?");
1303
1304                query.append(" AND ");
1305
1306                query.append("roleId = ?");
1307
1308                query.append(" ");
1309
1310                if (obc != null) {
1311                    query.append("ORDER BY ");
1312                    query.append(obc.getOrderBy());
1313                }
1314
1315                Query q = session.createQuery(query.toString());
1316
1317                QueryPos qPos = QueryPos.getInstance(q);
1318
1319                qPos.add(groupId);
1320
1321                qPos.add(roleId);
1322
1323                List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
1324                        getDialect(), start, end);
1325
1326                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1327                    finderClassName, finderMethodName, finderParams,
1328                    finderArgs, list);
1329
1330                return list;
1331            }
1332            catch (Exception e) {
1333                throw processException(e);
1334            }
1335            finally {
1336                closeSession(session);
1337            }
1338        }
1339        else {
1340            return (List<UserGroupRole>)result;
1341        }
1342    }
1343
1344    public UserGroupRole findByG_R_First(long groupId, long roleId,
1345        OrderByComparator obc)
1346        throws NoSuchUserGroupRoleException, SystemException {
1347        List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1, obc);
1348
1349        if (list.size() == 0) {
1350            StringBuilder msg = new StringBuilder();
1351
1352            msg.append("No UserGroupRole exists with the key {");
1353
1354            msg.append("groupId=" + groupId);
1355
1356            msg.append(", ");
1357            msg.append("roleId=" + roleId);
1358
1359            msg.append(StringPool.CLOSE_CURLY_BRACE);
1360
1361            throw new NoSuchUserGroupRoleException(msg.toString());
1362        }
1363        else {
1364            return list.get(0);
1365        }
1366    }
1367
1368    public UserGroupRole findByG_R_Last(long groupId, long roleId,
1369        OrderByComparator obc)
1370        throws NoSuchUserGroupRoleException, SystemException {
1371        int count = countByG_R(groupId, roleId);
1372
1373        List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
1374                obc);
1375
1376        if (list.size() == 0) {
1377            StringBuilder msg = new StringBuilder();
1378
1379            msg.append("No UserGroupRole exists with the key {");
1380
1381            msg.append("groupId=" + groupId);
1382
1383            msg.append(", ");
1384            msg.append("roleId=" + roleId);
1385
1386            msg.append(StringPool.CLOSE_CURLY_BRACE);
1387
1388            throw new NoSuchUserGroupRoleException(msg.toString());
1389        }
1390        else {
1391            return list.get(0);
1392        }
1393    }
1394
1395    public UserGroupRole[] findByG_R_PrevAndNext(
1396        UserGroupRolePK userGroupRolePK, long groupId, long roleId,
1397        OrderByComparator obc)
1398        throws NoSuchUserGroupRoleException, SystemException {
1399        UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1400
1401        int count = countByG_R(groupId, roleId);
1402
1403        Session session = null;
1404
1405        try {
1406            session = openSession();
1407
1408            StringBuilder query = new StringBuilder();
1409
1410            query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
1411
1412            query.append("groupId = ?");
1413
1414            query.append(" AND ");
1415
1416            query.append("roleId = ?");
1417
1418            query.append(" ");
1419
1420            if (obc != null) {
1421                query.append("ORDER BY ");
1422                query.append(obc.getOrderBy());
1423            }
1424
1425            Query q = session.createQuery(query.toString());
1426
1427            QueryPos qPos = QueryPos.getInstance(q);
1428
1429            qPos.add(groupId);
1430
1431            qPos.add(roleId);
1432
1433            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1434                    userGroupRole);
1435
1436            UserGroupRole[] array = new UserGroupRoleImpl[3];
1437
1438            array[0] = (UserGroupRole)objArray[0];
1439            array[1] = (UserGroupRole)objArray[1];
1440            array[2] = (UserGroupRole)objArray[2];
1441
1442            return array;
1443        }
1444        catch (Exception e) {
1445            throw processException(e);
1446        }
1447        finally {
1448            closeSession(session);
1449        }
1450    }
1451
1452    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1453        throws SystemException {
1454        Session session = null;
1455
1456        try {
1457            session = openSession();
1458
1459            dynamicQuery.compile(session);
1460
1461            return dynamicQuery.list();
1462        }
1463        catch (Exception e) {
1464            throw processException(e);
1465        }
1466        finally {
1467            closeSession(session);
1468        }
1469    }
1470
1471    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1472        int start, int end) throws SystemException {
1473        Session session = null;
1474
1475        try {
1476            session = openSession();
1477
1478            dynamicQuery.setLimit(start, end);
1479
1480            dynamicQuery.compile(session);
1481
1482            return dynamicQuery.list();
1483        }
1484        catch (Exception e) {
1485            throw processException(e);
1486        }
1487        finally {
1488            closeSession(session);
1489        }
1490    }
1491
1492    public List<UserGroupRole> findAll() throws SystemException {
1493        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1494    }
1495
1496    public List<UserGroupRole> findAll(int start, int end)
1497        throws SystemException {
1498        return findAll(start, end, null);
1499    }
1500
1501    public List<UserGroupRole> findAll(int start, int end, OrderByComparator obc)
1502        throws SystemException {
1503        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1504        String finderClassName = UserGroupRole.class.getName();
1505        String finderMethodName = "findAll";
1506        String[] finderParams = new String[] {
1507                "java.lang.Integer", "java.lang.Integer",
1508                "com.liferay.portal.kernel.util.OrderByComparator"
1509            };
1510        Object[] finderArgs = new Object[] {
1511                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1512            };
1513
1514        Object result = null;
1515
1516        if (finderClassNameCacheEnabled) {
1517            result = FinderCacheUtil.getResult(finderClassName,
1518                    finderMethodName, finderParams, finderArgs, this);
1519        }
1520
1521        if (result == null) {
1522            Session session = null;
1523
1524            try {
1525                session = openSession();
1526
1527                StringBuilder query = new StringBuilder();
1528
1529                query.append("FROM com.liferay.portal.model.UserGroupRole ");
1530
1531                if (obc != null) {
1532                    query.append("ORDER BY ");
1533                    query.append(obc.getOrderBy());
1534                }
1535
1536                Query q = session.createQuery(query.toString());
1537
1538                List<UserGroupRole> list = (List<UserGroupRole>)QueryUtil.list(q,
1539                        getDialect(), start, end);
1540
1541                if (obc == null) {
1542                    Collections.sort(list);
1543                }
1544
1545                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1546                    finderClassName, finderMethodName, finderParams,
1547                    finderArgs, list);
1548
1549                return list;
1550            }
1551            catch (Exception e) {
1552                throw processException(e);
1553            }
1554            finally {
1555                closeSession(session);
1556            }
1557        }
1558        else {
1559            return (List<UserGroupRole>)result;
1560        }
1561    }
1562
1563    public void removeByUserId(long userId) throws SystemException {
1564        for (UserGroupRole userGroupRole : findByUserId(userId)) {
1565            remove(userGroupRole);
1566        }
1567    }
1568
1569    public void removeByGroupId(long groupId) throws SystemException {
1570        for (UserGroupRole userGroupRole : findByGroupId(groupId)) {
1571            remove(userGroupRole);
1572        }
1573    }
1574
1575    public void removeByRoleId(long roleId) throws SystemException {
1576        for (UserGroupRole userGroupRole : findByRoleId(roleId)) {
1577            remove(userGroupRole);
1578        }
1579    }
1580
1581    public void removeByU_G(long userId, long groupId)
1582        throws SystemException {
1583        for (UserGroupRole userGroupRole : findByU_G(userId, groupId)) {
1584            remove(userGroupRole);
1585        }
1586    }
1587
1588    public void removeByG_R(long groupId, long roleId)
1589        throws SystemException {
1590        for (UserGroupRole userGroupRole : findByG_R(groupId, roleId)) {
1591            remove(userGroupRole);
1592        }
1593    }
1594
1595    public void removeAll() throws SystemException {
1596        for (UserGroupRole userGroupRole : findAll()) {
1597            remove(userGroupRole);
1598        }
1599    }
1600
1601    public int countByUserId(long userId) throws SystemException {
1602        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1603        String finderClassName = UserGroupRole.class.getName();
1604        String finderMethodName = "countByUserId";
1605        String[] finderParams = new String[] { Long.class.getName() };
1606        Object[] finderArgs = new Object[] { new Long(userId) };
1607
1608        Object result = null;
1609
1610        if (finderClassNameCacheEnabled) {
1611            result = FinderCacheUtil.getResult(finderClassName,
1612                    finderMethodName, finderParams, finderArgs, this);
1613        }
1614
1615        if (result == null) {
1616            Session session = null;
1617
1618            try {
1619                session = openSession();
1620
1621                StringBuilder query = new StringBuilder();
1622
1623                query.append("SELECT COUNT(*) ");
1624                query.append(
1625                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1626
1627                query.append("userId = ?");
1628
1629                query.append(" ");
1630
1631                Query q = session.createQuery(query.toString());
1632
1633                QueryPos qPos = QueryPos.getInstance(q);
1634
1635                qPos.add(userId);
1636
1637                Long count = null;
1638
1639                Iterator<Long> itr = q.list().iterator();
1640
1641                if (itr.hasNext()) {
1642                    count = itr.next();
1643                }
1644
1645                if (count == null) {
1646                    count = new Long(0);
1647                }
1648
1649                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1650                    finderClassName, finderMethodName, finderParams,
1651                    finderArgs, count);
1652
1653                return count.intValue();
1654            }
1655            catch (Exception e) {
1656                throw processException(e);
1657            }
1658            finally {
1659                closeSession(session);
1660            }
1661        }
1662        else {
1663            return ((Long)result).intValue();
1664        }
1665    }
1666
1667    public int countByGroupId(long groupId) throws SystemException {
1668        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1669        String finderClassName = UserGroupRole.class.getName();
1670        String finderMethodName = "countByGroupId";
1671        String[] finderParams = new String[] { Long.class.getName() };
1672        Object[] finderArgs = new Object[] { new Long(groupId) };
1673
1674        Object result = null;
1675
1676        if (finderClassNameCacheEnabled) {
1677            result = FinderCacheUtil.getResult(finderClassName,
1678                    finderMethodName, finderParams, finderArgs, this);
1679        }
1680
1681        if (result == null) {
1682            Session session = null;
1683
1684            try {
1685                session = openSession();
1686
1687                StringBuilder query = new StringBuilder();
1688
1689                query.append("SELECT COUNT(*) ");
1690                query.append(
1691                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1692
1693                query.append("groupId = ?");
1694
1695                query.append(" ");
1696
1697                Query q = session.createQuery(query.toString());
1698
1699                QueryPos qPos = QueryPos.getInstance(q);
1700
1701                qPos.add(groupId);
1702
1703                Long count = null;
1704
1705                Iterator<Long> itr = q.list().iterator();
1706
1707                if (itr.hasNext()) {
1708                    count = itr.next();
1709                }
1710
1711                if (count == null) {
1712                    count = new Long(0);
1713                }
1714
1715                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1716                    finderClassName, finderMethodName, finderParams,
1717                    finderArgs, count);
1718
1719                return count.intValue();
1720            }
1721            catch (Exception e) {
1722                throw processException(e);
1723            }
1724            finally {
1725                closeSession(session);
1726            }
1727        }
1728        else {
1729            return ((Long)result).intValue();
1730        }
1731    }
1732
1733    public int countByRoleId(long roleId) throws SystemException {
1734        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1735        String finderClassName = UserGroupRole.class.getName();
1736        String finderMethodName = "countByRoleId";
1737        String[] finderParams = new String[] { Long.class.getName() };
1738        Object[] finderArgs = new Object[] { new Long(roleId) };
1739
1740        Object result = null;
1741
1742        if (finderClassNameCacheEnabled) {
1743            result = FinderCacheUtil.getResult(finderClassName,
1744                    finderMethodName, finderParams, finderArgs, this);
1745        }
1746
1747        if (result == null) {
1748            Session session = null;
1749
1750            try {
1751                session = openSession();
1752
1753                StringBuilder query = new StringBuilder();
1754
1755                query.append("SELECT COUNT(*) ");
1756                query.append(
1757                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1758
1759                query.append("roleId = ?");
1760
1761                query.append(" ");
1762
1763                Query q = session.createQuery(query.toString());
1764
1765                QueryPos qPos = QueryPos.getInstance(q);
1766
1767                qPos.add(roleId);
1768
1769                Long count = null;
1770
1771                Iterator<Long> itr = q.list().iterator();
1772
1773                if (itr.hasNext()) {
1774                    count = itr.next();
1775                }
1776
1777                if (count == null) {
1778                    count = new Long(0);
1779                }
1780
1781                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1782                    finderClassName, finderMethodName, finderParams,
1783                    finderArgs, count);
1784
1785                return count.intValue();
1786            }
1787            catch (Exception e) {
1788                throw processException(e);
1789            }
1790            finally {
1791                closeSession(session);
1792            }
1793        }
1794        else {
1795            return ((Long)result).intValue();
1796        }
1797    }
1798
1799    public int countByU_G(long userId, long groupId) throws SystemException {
1800        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1801        String finderClassName = UserGroupRole.class.getName();
1802        String finderMethodName = "countByU_G";
1803        String[] finderParams = new String[] {
1804                Long.class.getName(), Long.class.getName()
1805            };
1806        Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
1807
1808        Object result = null;
1809
1810        if (finderClassNameCacheEnabled) {
1811            result = FinderCacheUtil.getResult(finderClassName,
1812                    finderMethodName, finderParams, finderArgs, this);
1813        }
1814
1815        if (result == null) {
1816            Session session = null;
1817
1818            try {
1819                session = openSession();
1820
1821                StringBuilder query = new StringBuilder();
1822
1823                query.append("SELECT COUNT(*) ");
1824                query.append(
1825                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1826
1827                query.append("userId = ?");
1828
1829                query.append(" AND ");
1830
1831                query.append("groupId = ?");
1832
1833                query.append(" ");
1834
1835                Query q = session.createQuery(query.toString());
1836
1837                QueryPos qPos = QueryPos.getInstance(q);
1838
1839                qPos.add(userId);
1840
1841                qPos.add(groupId);
1842
1843                Long count = null;
1844
1845                Iterator<Long> itr = q.list().iterator();
1846
1847                if (itr.hasNext()) {
1848                    count = itr.next();
1849                }
1850
1851                if (count == null) {
1852                    count = new Long(0);
1853                }
1854
1855                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1856                    finderClassName, finderMethodName, finderParams,
1857                    finderArgs, count);
1858
1859                return count.intValue();
1860            }
1861            catch (Exception e) {
1862                throw processException(e);
1863            }
1864            finally {
1865                closeSession(session);
1866            }
1867        }
1868        else {
1869            return ((Long)result).intValue();
1870        }
1871    }
1872
1873    public int countByG_R(long groupId, long roleId) throws SystemException {
1874        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1875        String finderClassName = UserGroupRole.class.getName();
1876        String finderMethodName = "countByG_R";
1877        String[] finderParams = new String[] {
1878                Long.class.getName(), Long.class.getName()
1879            };
1880        Object[] finderArgs = new Object[] { new Long(groupId), new Long(roleId) };
1881
1882        Object result = null;
1883
1884        if (finderClassNameCacheEnabled) {
1885            result = FinderCacheUtil.getResult(finderClassName,
1886                    finderMethodName, finderParams, finderArgs, this);
1887        }
1888
1889        if (result == null) {
1890            Session session = null;
1891
1892            try {
1893                session = openSession();
1894
1895                StringBuilder query = new StringBuilder();
1896
1897                query.append("SELECT COUNT(*) ");
1898                query.append(
1899                    "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1900
1901                query.append("groupId = ?");
1902
1903                query.append(" AND ");
1904
1905                query.append("roleId = ?");
1906
1907                query.append(" ");
1908
1909                Query q = session.createQuery(query.toString());
1910
1911                QueryPos qPos = QueryPos.getInstance(q);
1912
1913                qPos.add(groupId);
1914
1915                qPos.add(roleId);
1916
1917                Long count = null;
1918
1919                Iterator<Long> itr = q.list().iterator();
1920
1921                if (itr.hasNext()) {
1922                    count = itr.next();
1923                }
1924
1925                if (count == null) {
1926                    count = new Long(0);
1927                }
1928
1929                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1930                    finderClassName, finderMethodName, finderParams,
1931                    finderArgs, count);
1932
1933                return count.intValue();
1934            }
1935            catch (Exception e) {
1936                throw processException(e);
1937            }
1938            finally {
1939                closeSession(session);
1940            }
1941        }
1942        else {
1943            return ((Long)result).intValue();
1944        }
1945    }
1946
1947    public int countAll() throws SystemException {
1948        boolean finderClassNameCacheEnabled = UserGroupRoleModelImpl.CACHE_ENABLED;
1949        String finderClassName = UserGroupRole.class.getName();
1950        String finderMethodName = "countAll";
1951        String[] finderParams = new String[] {  };
1952        Object[] finderArgs = new Object[] {  };
1953
1954        Object result = null;
1955
1956        if (finderClassNameCacheEnabled) {
1957            result = FinderCacheUtil.getResult(finderClassName,
1958                    finderMethodName, finderParams, finderArgs, this);
1959        }
1960
1961        if (result == null) {
1962            Session session = null;
1963
1964            try {
1965                session = openSession();
1966
1967                Query q = session.createQuery(
1968                        "SELECT COUNT(*) FROM com.liferay.portal.model.UserGroupRole");
1969
1970                Long count = null;
1971
1972                Iterator<Long> itr = q.list().iterator();
1973
1974                if (itr.hasNext()) {
1975                    count = itr.next();
1976                }
1977
1978                if (count == null) {
1979                    count = new Long(0);
1980                }
1981
1982                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1983                    finderClassName, finderMethodName, finderParams,
1984                    finderArgs, count);
1985
1986                return count.intValue();
1987            }
1988            catch (Exception e) {
1989                throw processException(e);
1990            }
1991            finally {
1992                closeSession(session);
1993            }
1994        }
1995        else {
1996            return ((Long)result).intValue();
1997        }
1998    }
1999
2000    public void registerListener(ModelListener listener) {
2001        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2002
2003        listeners.add(listener);
2004
2005        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2006    }
2007
2008    public void unregisterListener(ModelListener listener) {
2009        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2010
2011        listeners.remove(listener);
2012
2013        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2014    }
2015
2016    public void afterPropertiesSet() {
2017        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2018                    com.liferay.portal.util.PropsUtil.get(
2019                        "value.object.listener.com.liferay.portal.model.UserGroupRole")));
2020
2021        if (listenerClassNames.length > 0) {
2022            try {
2023                List<ModelListener> listeners = new ArrayList<ModelListener>();
2024
2025                for (String listenerClassName : listenerClassNames) {
2026                    listeners.add((ModelListener)Class.forName(
2027                            listenerClassName).newInstance());
2028                }
2029
2030                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2031            }
2032            catch (Exception e) {
2033                _log.error(e);
2034            }
2035        }
2036    }
2037
2038    private static Log _log = LogFactory.getLog(UserGroupRolePersistenceImpl.class);
2039    private ModelListener[] _listeners = new ModelListener[0];
2040}