1
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.OrderByComparator;
30 import com.liferay.portal.kernel.util.StringMaker;
31 import com.liferay.portal.kernel.util.StringPool;
32 import com.liferay.portal.model.UserGroupRole;
33 import com.liferay.portal.model.impl.UserGroupRoleImpl;
34 import com.liferay.portal.service.persistence.BasePersistence;
35 import com.liferay.portal.spring.hibernate.FinderCache;
36 import com.liferay.portal.spring.hibernate.HibernateUtil;
37
38 import com.liferay.util.dao.hibernate.QueryUtil;
39
40 import org.apache.commons.logging.Log;
41 import org.apache.commons.logging.LogFactory;
42
43 import org.hibernate.Query;
44 import org.hibernate.Session;
45
46 import java.util.Collections;
47 import java.util.Iterator;
48 import java.util.List;
49
50
56 public class UserGroupRolePersistenceImpl extends BasePersistence
57 implements UserGroupRolePersistence {
58 public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
59 UserGroupRole userGroupRole = new UserGroupRoleImpl();
60 userGroupRole.setNew(true);
61 userGroupRole.setPrimaryKey(userGroupRolePK);
62
63 return userGroupRole;
64 }
65
66 public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
67 throws NoSuchUserGroupRoleException, SystemException {
68 Session session = null;
69
70 try {
71 session = openSession();
72
73 UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
74 userGroupRolePK);
75
76 if (userGroupRole == null) {
77 if (_log.isWarnEnabled()) {
78 _log.warn("No UserGroupRole exists with the primary key " +
79 userGroupRolePK);
80 }
81
82 throw new NoSuchUserGroupRoleException(
83 "No UserGroupRole exists with the primary key " +
84 userGroupRolePK);
85 }
86
87 return remove(userGroupRole);
88 }
89 catch (NoSuchUserGroupRoleException nsee) {
90 throw nsee;
91 }
92 catch (Exception e) {
93 throw HibernateUtil.processException(e);
94 }
95 finally {
96 closeSession(session);
97 }
98 }
99
100 public UserGroupRole remove(UserGroupRole userGroupRole)
101 throws SystemException {
102 Session session = null;
103
104 try {
105 session = openSession();
106 session.delete(userGroupRole);
107 session.flush();
108
109 return userGroupRole;
110 }
111 catch (Exception e) {
112 throw HibernateUtil.processException(e);
113 }
114 finally {
115 closeSession(session);
116 FinderCache.clearCache(UserGroupRole.class.getName());
117 }
118 }
119
120 public UserGroupRole update(
121 com.liferay.portal.model.UserGroupRole userGroupRole)
122 throws SystemException {
123 return update(userGroupRole, false);
124 }
125
126 public UserGroupRole update(
127 com.liferay.portal.model.UserGroupRole userGroupRole, boolean merge)
128 throws SystemException {
129 Session session = null;
130
131 try {
132 session = openSession();
133
134 if (merge) {
135 session.merge(userGroupRole);
136 }
137 else {
138 if (userGroupRole.isNew()) {
139 session.save(userGroupRole);
140 }
141 }
142
143 session.flush();
144 userGroupRole.setNew(false);
145
146 return userGroupRole;
147 }
148 catch (Exception e) {
149 throw HibernateUtil.processException(e);
150 }
151 finally {
152 closeSession(session);
153 FinderCache.clearCache(UserGroupRole.class.getName());
154 }
155 }
156
157 public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
158 throws NoSuchUserGroupRoleException, SystemException {
159 UserGroupRole userGroupRole = fetchByPrimaryKey(userGroupRolePK);
160
161 if (userGroupRole == null) {
162 if (_log.isWarnEnabled()) {
163 _log.warn("No UserGroupRole exists with the primary key " +
164 userGroupRolePK);
165 }
166
167 throw new NoSuchUserGroupRoleException(
168 "No UserGroupRole exists with the primary key " +
169 userGroupRolePK);
170 }
171
172 return userGroupRole;
173 }
174
175 public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK)
176 throws SystemException {
177 Session session = null;
178
179 try {
180 session = openSession();
181
182 return (UserGroupRole)session.get(UserGroupRoleImpl.class,
183 userGroupRolePK);
184 }
185 catch (Exception e) {
186 throw HibernateUtil.processException(e);
187 }
188 finally {
189 closeSession(session);
190 }
191 }
192
193 public List findByU_G(long userId, long groupId) throws SystemException {
194 String finderClassName = UserGroupRole.class.getName();
195 String finderMethodName = "findByU_G";
196 String[] finderParams = new String[] {
197 Long.class.getName(), Long.class.getName()
198 };
199 Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
200 Object result = FinderCache.getResult(finderClassName,
201 finderMethodName, finderParams, finderArgs, getSessionFactory());
202
203 if (result == null) {
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 StringMaker query = new StringMaker();
210 query.append(
211 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
212 query.append("userId = ?");
213 query.append(" AND ");
214 query.append("groupId = ?");
215 query.append(" ");
216
217 Query q = session.createQuery(query.toString());
218 int queryPos = 0;
219 q.setLong(queryPos++, userId);
220 q.setLong(queryPos++, groupId);
221
222 List list = q.list();
223 FinderCache.putResult(finderClassName, finderMethodName,
224 finderParams, finderArgs, list);
225
226 return list;
227 }
228 catch (Exception e) {
229 throw HibernateUtil.processException(e);
230 }
231 finally {
232 closeSession(session);
233 }
234 }
235 else {
236 return (List)result;
237 }
238 }
239
240 public List findByU_G(long userId, long groupId, int begin, int end)
241 throws SystemException {
242 return findByU_G(userId, groupId, begin, end, null);
243 }
244
245 public List findByU_G(long userId, long groupId, int begin, int end,
246 OrderByComparator obc) throws SystemException {
247 String finderClassName = UserGroupRole.class.getName();
248 String finderMethodName = "findByU_G";
249 String[] finderParams = new String[] {
250 Long.class.getName(), Long.class.getName(), "java.lang.Integer",
251 "java.lang.Integer",
252 "com.liferay.portal.kernel.util.OrderByComparator"
253 };
254 Object[] finderArgs = new Object[] {
255 new Long(userId), new Long(groupId), String.valueOf(begin),
256 String.valueOf(end), String.valueOf(obc)
257 };
258 Object result = FinderCache.getResult(finderClassName,
259 finderMethodName, finderParams, finderArgs, getSessionFactory());
260
261 if (result == null) {
262 Session session = null;
263
264 try {
265 session = openSession();
266
267 StringMaker query = new StringMaker();
268 query.append(
269 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
270 query.append("userId = ?");
271 query.append(" AND ");
272 query.append("groupId = ?");
273 query.append(" ");
274
275 if (obc != null) {
276 query.append("ORDER BY ");
277 query.append(obc.getOrderBy());
278 }
279
280 Query q = session.createQuery(query.toString());
281 int queryPos = 0;
282 q.setLong(queryPos++, userId);
283 q.setLong(queryPos++, groupId);
284
285 List list = QueryUtil.list(q, getDialect(), begin, end);
286 FinderCache.putResult(finderClassName, finderMethodName,
287 finderParams, finderArgs, list);
288
289 return list;
290 }
291 catch (Exception e) {
292 throw HibernateUtil.processException(e);
293 }
294 finally {
295 closeSession(session);
296 }
297 }
298 else {
299 return (List)result;
300 }
301 }
302
303 public UserGroupRole findByU_G_First(long userId, long groupId,
304 OrderByComparator obc)
305 throws NoSuchUserGroupRoleException, SystemException {
306 List list = findByU_G(userId, groupId, 0, 1, obc);
307
308 if (list.size() == 0) {
309 StringMaker msg = new StringMaker();
310 msg.append("No UserGroupRole exists with the key ");
311 msg.append(StringPool.OPEN_CURLY_BRACE);
312 msg.append("userId=");
313 msg.append(userId);
314 msg.append(", ");
315 msg.append("groupId=");
316 msg.append(groupId);
317 msg.append(StringPool.CLOSE_CURLY_BRACE);
318 throw new NoSuchUserGroupRoleException(msg.toString());
319 }
320 else {
321 return (UserGroupRole)list.get(0);
322 }
323 }
324
325 public UserGroupRole findByU_G_Last(long userId, long groupId,
326 OrderByComparator obc)
327 throws NoSuchUserGroupRoleException, SystemException {
328 int count = countByU_G(userId, groupId);
329 List list = findByU_G(userId, groupId, count - 1, count, obc);
330
331 if (list.size() == 0) {
332 StringMaker msg = new StringMaker();
333 msg.append("No UserGroupRole exists with the key ");
334 msg.append(StringPool.OPEN_CURLY_BRACE);
335 msg.append("userId=");
336 msg.append(userId);
337 msg.append(", ");
338 msg.append("groupId=");
339 msg.append(groupId);
340 msg.append(StringPool.CLOSE_CURLY_BRACE);
341 throw new NoSuchUserGroupRoleException(msg.toString());
342 }
343 else {
344 return (UserGroupRole)list.get(0);
345 }
346 }
347
348 public UserGroupRole[] findByU_G_PrevAndNext(
349 UserGroupRolePK userGroupRolePK, long userId, long groupId,
350 OrderByComparator obc)
351 throws NoSuchUserGroupRoleException, SystemException {
352 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
353 int count = countByU_G(userId, groupId);
354 Session session = null;
355
356 try {
357 session = openSession();
358
359 StringMaker query = new StringMaker();
360 query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
361 query.append("userId = ?");
362 query.append(" AND ");
363 query.append("groupId = ?");
364 query.append(" ");
365
366 if (obc != null) {
367 query.append("ORDER BY ");
368 query.append(obc.getOrderBy());
369 }
370
371 Query q = session.createQuery(query.toString());
372 int queryPos = 0;
373 q.setLong(queryPos++, userId);
374 q.setLong(queryPos++, groupId);
375
376 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
377 userGroupRole);
378 UserGroupRole[] array = new UserGroupRoleImpl[3];
379 array[0] = (UserGroupRole)objArray[0];
380 array[1] = (UserGroupRole)objArray[1];
381 array[2] = (UserGroupRole)objArray[2];
382
383 return array;
384 }
385 catch (Exception e) {
386 throw HibernateUtil.processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392
393 public List findByUserId(long userId) throws SystemException {
394 String finderClassName = UserGroupRole.class.getName();
395 String finderMethodName = "findByUserId";
396 String[] finderParams = new String[] { Long.class.getName() };
397 Object[] finderArgs = new Object[] { new Long(userId) };
398 Object result = FinderCache.getResult(finderClassName,
399 finderMethodName, finderParams, finderArgs, getSessionFactory());
400
401 if (result == null) {
402 Session session = null;
403
404 try {
405 session = openSession();
406
407 StringMaker query = new StringMaker();
408 query.append(
409 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
410 query.append("userId = ?");
411 query.append(" ");
412
413 Query q = session.createQuery(query.toString());
414 int queryPos = 0;
415 q.setLong(queryPos++, userId);
416
417 List list = q.list();
418 FinderCache.putResult(finderClassName, finderMethodName,
419 finderParams, finderArgs, list);
420
421 return list;
422 }
423 catch (Exception e) {
424 throw HibernateUtil.processException(e);
425 }
426 finally {
427 closeSession(session);
428 }
429 }
430 else {
431 return (List)result;
432 }
433 }
434
435 public List findByUserId(long userId, int begin, int end)
436 throws SystemException {
437 return findByUserId(userId, begin, end, null);
438 }
439
440 public List findByUserId(long userId, int begin, int end,
441 OrderByComparator obc) throws SystemException {
442 String finderClassName = UserGroupRole.class.getName();
443 String finderMethodName = "findByUserId";
444 String[] finderParams = new String[] {
445 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
446 "com.liferay.portal.kernel.util.OrderByComparator"
447 };
448 Object[] finderArgs = new Object[] {
449 new Long(userId), String.valueOf(begin), String.valueOf(end),
450 String.valueOf(obc)
451 };
452 Object result = FinderCache.getResult(finderClassName,
453 finderMethodName, finderParams, finderArgs, getSessionFactory());
454
455 if (result == null) {
456 Session session = null;
457
458 try {
459 session = openSession();
460
461 StringMaker query = new StringMaker();
462 query.append(
463 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
464 query.append("userId = ?");
465 query.append(" ");
466
467 if (obc != null) {
468 query.append("ORDER BY ");
469 query.append(obc.getOrderBy());
470 }
471
472 Query q = session.createQuery(query.toString());
473 int queryPos = 0;
474 q.setLong(queryPos++, userId);
475
476 List list = QueryUtil.list(q, getDialect(), begin, end);
477 FinderCache.putResult(finderClassName, finderMethodName,
478 finderParams, finderArgs, list);
479
480 return list;
481 }
482 catch (Exception e) {
483 throw HibernateUtil.processException(e);
484 }
485 finally {
486 closeSession(session);
487 }
488 }
489 else {
490 return (List)result;
491 }
492 }
493
494 public UserGroupRole findByUserId_First(long userId, OrderByComparator obc)
495 throws NoSuchUserGroupRoleException, SystemException {
496 List list = findByUserId(userId, 0, 1, obc);
497
498 if (list.size() == 0) {
499 StringMaker msg = new StringMaker();
500 msg.append("No UserGroupRole exists with the key ");
501 msg.append(StringPool.OPEN_CURLY_BRACE);
502 msg.append("userId=");
503 msg.append(userId);
504 msg.append(StringPool.CLOSE_CURLY_BRACE);
505 throw new NoSuchUserGroupRoleException(msg.toString());
506 }
507 else {
508 return (UserGroupRole)list.get(0);
509 }
510 }
511
512 public UserGroupRole findByUserId_Last(long userId, OrderByComparator obc)
513 throws NoSuchUserGroupRoleException, SystemException {
514 int count = countByUserId(userId);
515 List list = findByUserId(userId, count - 1, count, obc);
516
517 if (list.size() == 0) {
518 StringMaker msg = new StringMaker();
519 msg.append("No UserGroupRole exists with the key ");
520 msg.append(StringPool.OPEN_CURLY_BRACE);
521 msg.append("userId=");
522 msg.append(userId);
523 msg.append(StringPool.CLOSE_CURLY_BRACE);
524 throw new NoSuchUserGroupRoleException(msg.toString());
525 }
526 else {
527 return (UserGroupRole)list.get(0);
528 }
529 }
530
531 public UserGroupRole[] findByUserId_PrevAndNext(
532 UserGroupRolePK userGroupRolePK, long userId, OrderByComparator obc)
533 throws NoSuchUserGroupRoleException, SystemException {
534 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
535 int count = countByUserId(userId);
536 Session session = null;
537
538 try {
539 session = openSession();
540
541 StringMaker query = new StringMaker();
542 query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
543 query.append("userId = ?");
544 query.append(" ");
545
546 if (obc != null) {
547 query.append("ORDER BY ");
548 query.append(obc.getOrderBy());
549 }
550
551 Query q = session.createQuery(query.toString());
552 int queryPos = 0;
553 q.setLong(queryPos++, userId);
554
555 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
556 userGroupRole);
557 UserGroupRole[] array = new UserGroupRoleImpl[3];
558 array[0] = (UserGroupRole)objArray[0];
559 array[1] = (UserGroupRole)objArray[1];
560 array[2] = (UserGroupRole)objArray[2];
561
562 return array;
563 }
564 catch (Exception e) {
565 throw HibernateUtil.processException(e);
566 }
567 finally {
568 closeSession(session);
569 }
570 }
571
572 public List findByGroupId(long groupId) throws SystemException {
573 String finderClassName = UserGroupRole.class.getName();
574 String finderMethodName = "findByGroupId";
575 String[] finderParams = new String[] { Long.class.getName() };
576 Object[] finderArgs = new Object[] { new Long(groupId) };
577 Object result = FinderCache.getResult(finderClassName,
578 finderMethodName, finderParams, finderArgs, getSessionFactory());
579
580 if (result == null) {
581 Session session = null;
582
583 try {
584 session = openSession();
585
586 StringMaker query = new StringMaker();
587 query.append(
588 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
589 query.append("groupId = ?");
590 query.append(" ");
591
592 Query q = session.createQuery(query.toString());
593 int queryPos = 0;
594 q.setLong(queryPos++, groupId);
595
596 List list = q.list();
597 FinderCache.putResult(finderClassName, finderMethodName,
598 finderParams, finderArgs, list);
599
600 return list;
601 }
602 catch (Exception e) {
603 throw HibernateUtil.processException(e);
604 }
605 finally {
606 closeSession(session);
607 }
608 }
609 else {
610 return (List)result;
611 }
612 }
613
614 public List findByGroupId(long groupId, int begin, int end)
615 throws SystemException {
616 return findByGroupId(groupId, begin, end, null);
617 }
618
619 public List findByGroupId(long groupId, int begin, int end,
620 OrderByComparator obc) throws SystemException {
621 String finderClassName = UserGroupRole.class.getName();
622 String finderMethodName = "findByGroupId";
623 String[] finderParams = new String[] {
624 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
625 "com.liferay.portal.kernel.util.OrderByComparator"
626 };
627 Object[] finderArgs = new Object[] {
628 new Long(groupId), String.valueOf(begin), String.valueOf(end),
629 String.valueOf(obc)
630 };
631 Object result = FinderCache.getResult(finderClassName,
632 finderMethodName, finderParams, finderArgs, getSessionFactory());
633
634 if (result == null) {
635 Session session = null;
636
637 try {
638 session = openSession();
639
640 StringMaker query = new StringMaker();
641 query.append(
642 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
643 query.append("groupId = ?");
644 query.append(" ");
645
646 if (obc != null) {
647 query.append("ORDER BY ");
648 query.append(obc.getOrderBy());
649 }
650
651 Query q = session.createQuery(query.toString());
652 int queryPos = 0;
653 q.setLong(queryPos++, groupId);
654
655 List list = QueryUtil.list(q, getDialect(), begin, end);
656 FinderCache.putResult(finderClassName, finderMethodName,
657 finderParams, finderArgs, list);
658
659 return list;
660 }
661 catch (Exception e) {
662 throw HibernateUtil.processException(e);
663 }
664 finally {
665 closeSession(session);
666 }
667 }
668 else {
669 return (List)result;
670 }
671 }
672
673 public UserGroupRole findByGroupId_First(long groupId, OrderByComparator obc)
674 throws NoSuchUserGroupRoleException, SystemException {
675 List list = findByGroupId(groupId, 0, 1, obc);
676
677 if (list.size() == 0) {
678 StringMaker msg = new StringMaker();
679 msg.append("No UserGroupRole exists with the key ");
680 msg.append(StringPool.OPEN_CURLY_BRACE);
681 msg.append("groupId=");
682 msg.append(groupId);
683 msg.append(StringPool.CLOSE_CURLY_BRACE);
684 throw new NoSuchUserGroupRoleException(msg.toString());
685 }
686 else {
687 return (UserGroupRole)list.get(0);
688 }
689 }
690
691 public UserGroupRole findByGroupId_Last(long groupId, OrderByComparator obc)
692 throws NoSuchUserGroupRoleException, SystemException {
693 int count = countByGroupId(groupId);
694 List list = findByGroupId(groupId, count - 1, count, obc);
695
696 if (list.size() == 0) {
697 StringMaker msg = new StringMaker();
698 msg.append("No UserGroupRole exists with the key ");
699 msg.append(StringPool.OPEN_CURLY_BRACE);
700 msg.append("groupId=");
701 msg.append(groupId);
702 msg.append(StringPool.CLOSE_CURLY_BRACE);
703 throw new NoSuchUserGroupRoleException(msg.toString());
704 }
705 else {
706 return (UserGroupRole)list.get(0);
707 }
708 }
709
710 public UserGroupRole[] findByGroupId_PrevAndNext(
711 UserGroupRolePK userGroupRolePK, long groupId, OrderByComparator obc)
712 throws NoSuchUserGroupRoleException, SystemException {
713 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
714 int count = countByGroupId(groupId);
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 StringMaker query = new StringMaker();
721 query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
722 query.append("groupId = ?");
723 query.append(" ");
724
725 if (obc != null) {
726 query.append("ORDER BY ");
727 query.append(obc.getOrderBy());
728 }
729
730 Query q = session.createQuery(query.toString());
731 int queryPos = 0;
732 q.setLong(queryPos++, groupId);
733
734 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
735 userGroupRole);
736 UserGroupRole[] array = new UserGroupRoleImpl[3];
737 array[0] = (UserGroupRole)objArray[0];
738 array[1] = (UserGroupRole)objArray[1];
739 array[2] = (UserGroupRole)objArray[2];
740
741 return array;
742 }
743 catch (Exception e) {
744 throw HibernateUtil.processException(e);
745 }
746 finally {
747 closeSession(session);
748 }
749 }
750
751 public List findByRoleId(long roleId) throws SystemException {
752 String finderClassName = UserGroupRole.class.getName();
753 String finderMethodName = "findByRoleId";
754 String[] finderParams = new String[] { Long.class.getName() };
755 Object[] finderArgs = new Object[] { new Long(roleId) };
756 Object result = FinderCache.getResult(finderClassName,
757 finderMethodName, finderParams, finderArgs, getSessionFactory());
758
759 if (result == null) {
760 Session session = null;
761
762 try {
763 session = openSession();
764
765 StringMaker query = new StringMaker();
766 query.append(
767 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
768 query.append("roleId = ?");
769 query.append(" ");
770
771 Query q = session.createQuery(query.toString());
772 int queryPos = 0;
773 q.setLong(queryPos++, roleId);
774
775 List list = q.list();
776 FinderCache.putResult(finderClassName, finderMethodName,
777 finderParams, finderArgs, list);
778
779 return list;
780 }
781 catch (Exception e) {
782 throw HibernateUtil.processException(e);
783 }
784 finally {
785 closeSession(session);
786 }
787 }
788 else {
789 return (List)result;
790 }
791 }
792
793 public List findByRoleId(long roleId, int begin, int end)
794 throws SystemException {
795 return findByRoleId(roleId, begin, end, null);
796 }
797
798 public List findByRoleId(long roleId, int begin, int end,
799 OrderByComparator obc) throws SystemException {
800 String finderClassName = UserGroupRole.class.getName();
801 String finderMethodName = "findByRoleId";
802 String[] finderParams = new String[] {
803 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
804 "com.liferay.portal.kernel.util.OrderByComparator"
805 };
806 Object[] finderArgs = new Object[] {
807 new Long(roleId), String.valueOf(begin), String.valueOf(end),
808 String.valueOf(obc)
809 };
810 Object result = FinderCache.getResult(finderClassName,
811 finderMethodName, finderParams, finderArgs, getSessionFactory());
812
813 if (result == null) {
814 Session session = null;
815
816 try {
817 session = openSession();
818
819 StringMaker query = new StringMaker();
820 query.append(
821 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
822 query.append("roleId = ?");
823 query.append(" ");
824
825 if (obc != null) {
826 query.append("ORDER BY ");
827 query.append(obc.getOrderBy());
828 }
829
830 Query q = session.createQuery(query.toString());
831 int queryPos = 0;
832 q.setLong(queryPos++, roleId);
833
834 List list = QueryUtil.list(q, getDialect(), begin, end);
835 FinderCache.putResult(finderClassName, finderMethodName,
836 finderParams, finderArgs, list);
837
838 return list;
839 }
840 catch (Exception e) {
841 throw HibernateUtil.processException(e);
842 }
843 finally {
844 closeSession(session);
845 }
846 }
847 else {
848 return (List)result;
849 }
850 }
851
852 public UserGroupRole findByRoleId_First(long roleId, OrderByComparator obc)
853 throws NoSuchUserGroupRoleException, SystemException {
854 List list = findByRoleId(roleId, 0, 1, obc);
855
856 if (list.size() == 0) {
857 StringMaker msg = new StringMaker();
858 msg.append("No UserGroupRole exists with the key ");
859 msg.append(StringPool.OPEN_CURLY_BRACE);
860 msg.append("roleId=");
861 msg.append(roleId);
862 msg.append(StringPool.CLOSE_CURLY_BRACE);
863 throw new NoSuchUserGroupRoleException(msg.toString());
864 }
865 else {
866 return (UserGroupRole)list.get(0);
867 }
868 }
869
870 public UserGroupRole findByRoleId_Last(long roleId, OrderByComparator obc)
871 throws NoSuchUserGroupRoleException, SystemException {
872 int count = countByRoleId(roleId);
873 List list = findByRoleId(roleId, count - 1, count, obc);
874
875 if (list.size() == 0) {
876 StringMaker msg = new StringMaker();
877 msg.append("No UserGroupRole exists with the key ");
878 msg.append(StringPool.OPEN_CURLY_BRACE);
879 msg.append("roleId=");
880 msg.append(roleId);
881 msg.append(StringPool.CLOSE_CURLY_BRACE);
882 throw new NoSuchUserGroupRoleException(msg.toString());
883 }
884 else {
885 return (UserGroupRole)list.get(0);
886 }
887 }
888
889 public UserGroupRole[] findByRoleId_PrevAndNext(
890 UserGroupRolePK userGroupRolePK, long roleId, OrderByComparator obc)
891 throws NoSuchUserGroupRoleException, SystemException {
892 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
893 int count = countByRoleId(roleId);
894 Session session = null;
895
896 try {
897 session = openSession();
898
899 StringMaker query = new StringMaker();
900 query.append("FROM com.liferay.portal.model.UserGroupRole WHERE ");
901 query.append("roleId = ?");
902 query.append(" ");
903
904 if (obc != null) {
905 query.append("ORDER BY ");
906 query.append(obc.getOrderBy());
907 }
908
909 Query q = session.createQuery(query.toString());
910 int queryPos = 0;
911 q.setLong(queryPos++, roleId);
912
913 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
914 userGroupRole);
915 UserGroupRole[] array = new UserGroupRoleImpl[3];
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 HibernateUtil.processException(e);
924 }
925 finally {
926 closeSession(session);
927 }
928 }
929
930 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
931 throws SystemException {
932 Session session = null;
933
934 try {
935 session = openSession();
936
937 DynamicQuery query = queryInitializer.initialize(session);
938
939 return query.list();
940 }
941 catch (Exception e) {
942 throw HibernateUtil.processException(e);
943 }
944 finally {
945 closeSession(session);
946 }
947 }
948
949 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
950 int begin, int end) throws SystemException {
951 Session session = null;
952
953 try {
954 session = openSession();
955
956 DynamicQuery query = queryInitializer.initialize(session);
957 query.setLimit(begin, end);
958
959 return query.list();
960 }
961 catch (Exception e) {
962 throw HibernateUtil.processException(e);
963 }
964 finally {
965 closeSession(session);
966 }
967 }
968
969 public List findAll() throws SystemException {
970 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
971 }
972
973 public List findAll(int begin, int end) throws SystemException {
974 return findAll(begin, end, null);
975 }
976
977 public List findAll(int begin, int end, OrderByComparator obc)
978 throws SystemException {
979 String finderClassName = UserGroupRole.class.getName();
980 String finderMethodName = "findAll";
981 String[] finderParams = new String[] {
982 "java.lang.Integer", "java.lang.Integer",
983 "com.liferay.portal.kernel.util.OrderByComparator"
984 };
985 Object[] finderArgs = new Object[] {
986 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
987 };
988 Object result = FinderCache.getResult(finderClassName,
989 finderMethodName, finderParams, finderArgs, getSessionFactory());
990
991 if (result == null) {
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 StringMaker query = new StringMaker();
998 query.append("FROM com.liferay.portal.model.UserGroupRole ");
999
1000 if (obc != null) {
1001 query.append("ORDER BY ");
1002 query.append(obc.getOrderBy());
1003 }
1004
1005 Query q = session.createQuery(query.toString());
1006 List list = QueryUtil.list(q, getDialect(), begin, end);
1007
1008 if (obc == null) {
1009 Collections.sort(list);
1010 }
1011
1012 FinderCache.putResult(finderClassName, finderMethodName,
1013 finderParams, finderArgs, list);
1014
1015 return list;
1016 }
1017 catch (Exception e) {
1018 throw HibernateUtil.processException(e);
1019 }
1020 finally {
1021 closeSession(session);
1022 }
1023 }
1024 else {
1025 return (List)result;
1026 }
1027 }
1028
1029 public void removeByU_G(long userId, long groupId)
1030 throws SystemException {
1031 Iterator itr = findByU_G(userId, groupId).iterator();
1032
1033 while (itr.hasNext()) {
1034 UserGroupRole userGroupRole = (UserGroupRole)itr.next();
1035 remove(userGroupRole);
1036 }
1037 }
1038
1039 public void removeByUserId(long userId) throws SystemException {
1040 Iterator itr = findByUserId(userId).iterator();
1041
1042 while (itr.hasNext()) {
1043 UserGroupRole userGroupRole = (UserGroupRole)itr.next();
1044 remove(userGroupRole);
1045 }
1046 }
1047
1048 public void removeByGroupId(long groupId) throws SystemException {
1049 Iterator itr = findByGroupId(groupId).iterator();
1050
1051 while (itr.hasNext()) {
1052 UserGroupRole userGroupRole = (UserGroupRole)itr.next();
1053 remove(userGroupRole);
1054 }
1055 }
1056
1057 public void removeByRoleId(long roleId) throws SystemException {
1058 Iterator itr = findByRoleId(roleId).iterator();
1059
1060 while (itr.hasNext()) {
1061 UserGroupRole userGroupRole = (UserGroupRole)itr.next();
1062 remove(userGroupRole);
1063 }
1064 }
1065
1066 public void removeAll() throws SystemException {
1067 Iterator itr = findAll().iterator();
1068
1069 while (itr.hasNext()) {
1070 remove((UserGroupRole)itr.next());
1071 }
1072 }
1073
1074 public int countByU_G(long userId, long groupId) throws SystemException {
1075 String finderClassName = UserGroupRole.class.getName();
1076 String finderMethodName = "countByU_G";
1077 String[] finderParams = new String[] {
1078 Long.class.getName(), Long.class.getName()
1079 };
1080 Object[] finderArgs = new Object[] { new Long(userId), new Long(groupId) };
1081 Object result = FinderCache.getResult(finderClassName,
1082 finderMethodName, finderParams, finderArgs, getSessionFactory());
1083
1084 if (result == null) {
1085 Session session = null;
1086
1087 try {
1088 session = openSession();
1089
1090 StringMaker query = new StringMaker();
1091 query.append("SELECT COUNT(*) ");
1092 query.append(
1093 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1094 query.append("userId = ?");
1095 query.append(" AND ");
1096 query.append("groupId = ?");
1097 query.append(" ");
1098
1099 Query q = session.createQuery(query.toString());
1100 int queryPos = 0;
1101 q.setLong(queryPos++, userId);
1102 q.setLong(queryPos++, groupId);
1103
1104 Long count = null;
1105 Iterator itr = q.list().iterator();
1106
1107 if (itr.hasNext()) {
1108 count = (Long)itr.next();
1109 }
1110
1111 if (count == null) {
1112 count = new Long(0);
1113 }
1114
1115 FinderCache.putResult(finderClassName, finderMethodName,
1116 finderParams, finderArgs, count);
1117
1118 return count.intValue();
1119 }
1120 catch (Exception e) {
1121 throw HibernateUtil.processException(e);
1122 }
1123 finally {
1124 closeSession(session);
1125 }
1126 }
1127 else {
1128 return ((Long)result).intValue();
1129 }
1130 }
1131
1132 public int countByUserId(long userId) throws SystemException {
1133 String finderClassName = UserGroupRole.class.getName();
1134 String finderMethodName = "countByUserId";
1135 String[] finderParams = new String[] { Long.class.getName() };
1136 Object[] finderArgs = new Object[] { new Long(userId) };
1137 Object result = FinderCache.getResult(finderClassName,
1138 finderMethodName, finderParams, finderArgs, getSessionFactory());
1139
1140 if (result == null) {
1141 Session session = null;
1142
1143 try {
1144 session = openSession();
1145
1146 StringMaker query = new StringMaker();
1147 query.append("SELECT COUNT(*) ");
1148 query.append(
1149 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1150 query.append("userId = ?");
1151 query.append(" ");
1152
1153 Query q = session.createQuery(query.toString());
1154 int queryPos = 0;
1155 q.setLong(queryPos++, userId);
1156
1157 Long count = null;
1158 Iterator itr = q.list().iterator();
1159
1160 if (itr.hasNext()) {
1161 count = (Long)itr.next();
1162 }
1163
1164 if (count == null) {
1165 count = new Long(0);
1166 }
1167
1168 FinderCache.putResult(finderClassName, finderMethodName,
1169 finderParams, finderArgs, count);
1170
1171 return count.intValue();
1172 }
1173 catch (Exception e) {
1174 throw HibernateUtil.processException(e);
1175 }
1176 finally {
1177 closeSession(session);
1178 }
1179 }
1180 else {
1181 return ((Long)result).intValue();
1182 }
1183 }
1184
1185 public int countByGroupId(long groupId) throws SystemException {
1186 String finderClassName = UserGroupRole.class.getName();
1187 String finderMethodName = "countByGroupId";
1188 String[] finderParams = new String[] { Long.class.getName() };
1189 Object[] finderArgs = new Object[] { new Long(groupId) };
1190 Object result = FinderCache.getResult(finderClassName,
1191 finderMethodName, finderParams, finderArgs, getSessionFactory());
1192
1193 if (result == null) {
1194 Session session = null;
1195
1196 try {
1197 session = openSession();
1198
1199 StringMaker query = new StringMaker();
1200 query.append("SELECT COUNT(*) ");
1201 query.append(
1202 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1203 query.append("groupId = ?");
1204 query.append(" ");
1205
1206 Query q = session.createQuery(query.toString());
1207 int queryPos = 0;
1208 q.setLong(queryPos++, groupId);
1209
1210 Long count = null;
1211 Iterator itr = q.list().iterator();
1212
1213 if (itr.hasNext()) {
1214 count = (Long)itr.next();
1215 }
1216
1217 if (count == null) {
1218 count = new Long(0);
1219 }
1220
1221 FinderCache.putResult(finderClassName, finderMethodName,
1222 finderParams, finderArgs, count);
1223
1224 return count.intValue();
1225 }
1226 catch (Exception e) {
1227 throw HibernateUtil.processException(e);
1228 }
1229 finally {
1230 closeSession(session);
1231 }
1232 }
1233 else {
1234 return ((Long)result).intValue();
1235 }
1236 }
1237
1238 public int countByRoleId(long roleId) throws SystemException {
1239 String finderClassName = UserGroupRole.class.getName();
1240 String finderMethodName = "countByRoleId";
1241 String[] finderParams = new String[] { Long.class.getName() };
1242 Object[] finderArgs = new Object[] { new Long(roleId) };
1243 Object result = FinderCache.getResult(finderClassName,
1244 finderMethodName, finderParams, finderArgs, getSessionFactory());
1245
1246 if (result == null) {
1247 Session session = null;
1248
1249 try {
1250 session = openSession();
1251
1252 StringMaker query = new StringMaker();
1253 query.append("SELECT COUNT(*) ");
1254 query.append(
1255 "FROM com.liferay.portal.model.UserGroupRole WHERE ");
1256 query.append("roleId = ?");
1257 query.append(" ");
1258
1259 Query q = session.createQuery(query.toString());
1260 int queryPos = 0;
1261 q.setLong(queryPos++, roleId);
1262
1263 Long count = null;
1264 Iterator itr = q.list().iterator();
1265
1266 if (itr.hasNext()) {
1267 count = (Long)itr.next();
1268 }
1269
1270 if (count == null) {
1271 count = new Long(0);
1272 }
1273
1274 FinderCache.putResult(finderClassName, finderMethodName,
1275 finderParams, finderArgs, count);
1276
1277 return count.intValue();
1278 }
1279 catch (Exception e) {
1280 throw HibernateUtil.processException(e);
1281 }
1282 finally {
1283 closeSession(session);
1284 }
1285 }
1286 else {
1287 return ((Long)result).intValue();
1288 }
1289 }
1290
1291 public int countAll() throws SystemException {
1292 String finderClassName = UserGroupRole.class.getName();
1293 String finderMethodName = "countAll";
1294 String[] finderParams = new String[] { };
1295 Object[] finderArgs = new Object[] { };
1296 Object result = FinderCache.getResult(finderClassName,
1297 finderMethodName, finderParams, finderArgs, getSessionFactory());
1298
1299 if (result == null) {
1300 Session session = null;
1301
1302 try {
1303 session = openSession();
1304
1305 StringMaker query = new StringMaker();
1306 query.append("SELECT COUNT(*) ");
1307 query.append("FROM com.liferay.portal.model.UserGroupRole");
1308
1309 Query q = session.createQuery(query.toString());
1310 Long count = null;
1311 Iterator itr = q.list().iterator();
1312
1313 if (itr.hasNext()) {
1314 count = (Long)itr.next();
1315 }
1316
1317 if (count == null) {
1318 count = new Long(0);
1319 }
1320
1321 FinderCache.putResult(finderClassName, finderMethodName,
1322 finderParams, finderArgs, count);
1323
1324 return count.intValue();
1325 }
1326 catch (Exception e) {
1327 throw HibernateUtil.processException(e);
1328 }
1329 finally {
1330 closeSession(session);
1331 }
1332 }
1333 else {
1334 return ((Long)result).intValue();
1335 }
1336 }
1337
1338 protected void initDao() {
1339 }
1340
1341 private static Log _log = LogFactory.getLog(UserGroupRolePersistenceImpl.class);
1342}