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