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