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