001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchUserGroupRoleException;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.model.UserGroupRole;
040 import com.liferay.portal.model.impl.UserGroupRoleImpl;
041 import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class UserGroupRolePersistenceImpl extends BasePersistenceImpl<UserGroupRole>
063 implements UserGroupRolePersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = UserGroupRoleImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
075 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
076 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
077 "findAll", new String[0]);
078 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
079 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
080 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
081 "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
083 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
086 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
087 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
088 "findByUserId",
089 new String[] {
090 Long.class.getName(),
091
092 Integer.class.getName(), Integer.class.getName(),
093 OrderByComparator.class.getName()
094 });
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
096 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
097 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
098 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
099 "findByUserId", new String[] { Long.class.getName() },
100 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
102 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
104 new String[] { Long.class.getName() });
105
106
113 public List<UserGroupRole> findByUserId(long userId)
114 throws SystemException {
115 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116 }
117
118
131 public List<UserGroupRole> findByUserId(long userId, int start, int end)
132 throws SystemException {
133 return findByUserId(userId, start, end, null);
134 }
135
136
150 public List<UserGroupRole> findByUserId(long userId, int start, int end,
151 OrderByComparator orderByComparator) throws SystemException {
152 boolean pagination = true;
153 FinderPath finderPath = null;
154 Object[] finderArgs = null;
155
156 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
157 (orderByComparator == null)) {
158 pagination = false;
159 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
160 finderArgs = new Object[] { userId };
161 }
162 else {
163 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
164 finderArgs = new Object[] { userId, start, end, orderByComparator };
165 }
166
167 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
168 finderArgs, this);
169
170 if ((list != null) && !list.isEmpty()) {
171 for (UserGroupRole userGroupRole : list) {
172 if ((userId != userGroupRole.getUserId())) {
173 list = null;
174
175 break;
176 }
177 }
178 }
179
180 if (list == null) {
181 StringBundler query = null;
182
183 if (orderByComparator != null) {
184 query = new StringBundler(3 +
185 (orderByComparator.getOrderByFields().length * 3));
186 }
187 else {
188 query = new StringBundler(3);
189 }
190
191 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
192
193 query.append(_FINDER_COLUMN_USERID_USERID_2);
194
195 if (orderByComparator != null) {
196 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
197 orderByComparator);
198 }
199 else
200 if (pagination) {
201 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
202 }
203
204 String sql = query.toString();
205
206 Session session = null;
207
208 try {
209 session = openSession();
210
211 Query q = session.createQuery(sql);
212
213 QueryPos qPos = QueryPos.getInstance(q);
214
215 qPos.add(userId);
216
217 if (!pagination) {
218 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
219 start, end, false);
220
221 Collections.sort(list);
222
223 list = new UnmodifiableList<UserGroupRole>(list);
224 }
225 else {
226 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
227 start, end);
228 }
229
230 cacheResult(list);
231
232 FinderCacheUtil.putResult(finderPath, finderArgs, list);
233 }
234 catch (Exception e) {
235 FinderCacheUtil.removeResult(finderPath, finderArgs);
236
237 throw processException(e);
238 }
239 finally {
240 closeSession(session);
241 }
242 }
243
244 return list;
245 }
246
247
256 public UserGroupRole findByUserId_First(long userId,
257 OrderByComparator orderByComparator)
258 throws NoSuchUserGroupRoleException, SystemException {
259 UserGroupRole userGroupRole = fetchByUserId_First(userId,
260 orderByComparator);
261
262 if (userGroupRole != null) {
263 return userGroupRole;
264 }
265
266 StringBundler msg = new StringBundler(4);
267
268 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
269
270 msg.append("userId=");
271 msg.append(userId);
272
273 msg.append(StringPool.CLOSE_CURLY_BRACE);
274
275 throw new NoSuchUserGroupRoleException(msg.toString());
276 }
277
278
286 public UserGroupRole fetchByUserId_First(long userId,
287 OrderByComparator orderByComparator) throws SystemException {
288 List<UserGroupRole> list = findByUserId(userId, 0, 1, orderByComparator);
289
290 if (!list.isEmpty()) {
291 return list.get(0);
292 }
293
294 return null;
295 }
296
297
306 public UserGroupRole findByUserId_Last(long userId,
307 OrderByComparator orderByComparator)
308 throws NoSuchUserGroupRoleException, SystemException {
309 UserGroupRole userGroupRole = fetchByUserId_Last(userId,
310 orderByComparator);
311
312 if (userGroupRole != null) {
313 return userGroupRole;
314 }
315
316 StringBundler msg = new StringBundler(4);
317
318 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
319
320 msg.append("userId=");
321 msg.append(userId);
322
323 msg.append(StringPool.CLOSE_CURLY_BRACE);
324
325 throw new NoSuchUserGroupRoleException(msg.toString());
326 }
327
328
336 public UserGroupRole fetchByUserId_Last(long userId,
337 OrderByComparator orderByComparator) throws SystemException {
338 int count = countByUserId(userId);
339
340 List<UserGroupRole> list = findByUserId(userId, count - 1, count,
341 orderByComparator);
342
343 if (!list.isEmpty()) {
344 return list.get(0);
345 }
346
347 return null;
348 }
349
350
360 public UserGroupRole[] findByUserId_PrevAndNext(
361 UserGroupRolePK userGroupRolePK, long userId,
362 OrderByComparator orderByComparator)
363 throws NoSuchUserGroupRoleException, SystemException {
364 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
365
366 Session session = null;
367
368 try {
369 session = openSession();
370
371 UserGroupRole[] array = new UserGroupRoleImpl[3];
372
373 array[0] = getByUserId_PrevAndNext(session, userGroupRole, userId,
374 orderByComparator, true);
375
376 array[1] = userGroupRole;
377
378 array[2] = getByUserId_PrevAndNext(session, userGroupRole, userId,
379 orderByComparator, false);
380
381 return array;
382 }
383 catch (Exception e) {
384 throw processException(e);
385 }
386 finally {
387 closeSession(session);
388 }
389 }
390
391 protected UserGroupRole getByUserId_PrevAndNext(Session session,
392 UserGroupRole userGroupRole, long userId,
393 OrderByComparator orderByComparator, boolean previous) {
394 StringBundler query = null;
395
396 if (orderByComparator != null) {
397 query = new StringBundler(6 +
398 (orderByComparator.getOrderByFields().length * 6));
399 }
400 else {
401 query = new StringBundler(3);
402 }
403
404 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
405
406 query.append(_FINDER_COLUMN_USERID_USERID_2);
407
408 if (orderByComparator != null) {
409 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
410
411 if (orderByConditionFields.length > 0) {
412 query.append(WHERE_AND);
413 }
414
415 for (int i = 0; i < orderByConditionFields.length; i++) {
416 query.append(_ORDER_BY_ENTITY_ALIAS);
417 query.append(orderByConditionFields[i]);
418
419 if ((i + 1) < orderByConditionFields.length) {
420 if (orderByComparator.isAscending() ^ previous) {
421 query.append(WHERE_GREATER_THAN_HAS_NEXT);
422 }
423 else {
424 query.append(WHERE_LESSER_THAN_HAS_NEXT);
425 }
426 }
427 else {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN);
433 }
434 }
435 }
436
437 query.append(ORDER_BY_CLAUSE);
438
439 String[] orderByFields = orderByComparator.getOrderByFields();
440
441 for (int i = 0; i < orderByFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByFields[i]);
444
445 if ((i + 1) < orderByFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(ORDER_BY_ASC_HAS_NEXT);
448 }
449 else {
450 query.append(ORDER_BY_DESC_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC);
456 }
457 else {
458 query.append(ORDER_BY_DESC);
459 }
460 }
461 }
462 }
463 else {
464 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
465 }
466
467 String sql = query.toString();
468
469 Query q = session.createQuery(sql);
470
471 q.setFirstResult(0);
472 q.setMaxResults(2);
473
474 QueryPos qPos = QueryPos.getInstance(q);
475
476 qPos.add(userId);
477
478 if (orderByComparator != null) {
479 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
480
481 for (Object value : values) {
482 qPos.add(value);
483 }
484 }
485
486 List<UserGroupRole> list = q.list();
487
488 if (list.size() == 2) {
489 return list.get(1);
490 }
491 else {
492 return null;
493 }
494 }
495
496
502 public void removeByUserId(long userId) throws SystemException {
503 for (UserGroupRole userGroupRole : findByUserId(userId,
504 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
505 remove(userGroupRole);
506 }
507 }
508
509
516 public int countByUserId(long userId) throws SystemException {
517 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
518
519 Object[] finderArgs = new Object[] { userId };
520
521 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
522 this);
523
524 if (count == null) {
525 StringBundler query = new StringBundler(2);
526
527 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
528
529 query.append(_FINDER_COLUMN_USERID_USERID_2);
530
531 String sql = query.toString();
532
533 Session session = null;
534
535 try {
536 session = openSession();
537
538 Query q = session.createQuery(sql);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(userId);
543
544 count = (Long)q.uniqueResult();
545
546 FinderCacheUtil.putResult(finderPath, finderArgs, count);
547 }
548 catch (Exception e) {
549 FinderCacheUtil.removeResult(finderPath, finderArgs);
550
551 throw processException(e);
552 }
553 finally {
554 closeSession(session);
555 }
556 }
557
558 return count.intValue();
559 }
560
561 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userGroupRole.id.userId = ?";
562 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
563 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
564 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
565 "findByGroupId",
566 new String[] {
567 Long.class.getName(),
568
569 Integer.class.getName(), Integer.class.getName(),
570 OrderByComparator.class.getName()
571 });
572 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
573 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
574 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
575 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
576 "findByGroupId", new String[] { Long.class.getName() },
577 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
578 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
579 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
580 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
581 new String[] { Long.class.getName() });
582
583
590 public List<UserGroupRole> findByGroupId(long groupId)
591 throws SystemException {
592 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
593 }
594
595
608 public List<UserGroupRole> findByGroupId(long groupId, int start, int end)
609 throws SystemException {
610 return findByGroupId(groupId, start, end, null);
611 }
612
613
627 public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
628 OrderByComparator orderByComparator) throws SystemException {
629 boolean pagination = true;
630 FinderPath finderPath = null;
631 Object[] finderArgs = null;
632
633 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
634 (orderByComparator == null)) {
635 pagination = false;
636 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
637 finderArgs = new Object[] { groupId };
638 }
639 else {
640 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
641 finderArgs = new Object[] { groupId, start, end, orderByComparator };
642 }
643
644 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
645 finderArgs, this);
646
647 if ((list != null) && !list.isEmpty()) {
648 for (UserGroupRole userGroupRole : list) {
649 if ((groupId != userGroupRole.getGroupId())) {
650 list = null;
651
652 break;
653 }
654 }
655 }
656
657 if (list == null) {
658 StringBundler query = null;
659
660 if (orderByComparator != null) {
661 query = new StringBundler(3 +
662 (orderByComparator.getOrderByFields().length * 3));
663 }
664 else {
665 query = new StringBundler(3);
666 }
667
668 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
669
670 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
671
672 if (orderByComparator != null) {
673 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
674 orderByComparator);
675 }
676 else
677 if (pagination) {
678 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
679 }
680
681 String sql = query.toString();
682
683 Session session = null;
684
685 try {
686 session = openSession();
687
688 Query q = session.createQuery(sql);
689
690 QueryPos qPos = QueryPos.getInstance(q);
691
692 qPos.add(groupId);
693
694 if (!pagination) {
695 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
696 start, end, false);
697
698 Collections.sort(list);
699
700 list = new UnmodifiableList<UserGroupRole>(list);
701 }
702 else {
703 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
704 start, end);
705 }
706
707 cacheResult(list);
708
709 FinderCacheUtil.putResult(finderPath, finderArgs, list);
710 }
711 catch (Exception e) {
712 FinderCacheUtil.removeResult(finderPath, finderArgs);
713
714 throw processException(e);
715 }
716 finally {
717 closeSession(session);
718 }
719 }
720
721 return list;
722 }
723
724
733 public UserGroupRole findByGroupId_First(long groupId,
734 OrderByComparator orderByComparator)
735 throws NoSuchUserGroupRoleException, SystemException {
736 UserGroupRole userGroupRole = fetchByGroupId_First(groupId,
737 orderByComparator);
738
739 if (userGroupRole != null) {
740 return userGroupRole;
741 }
742
743 StringBundler msg = new StringBundler(4);
744
745 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
746
747 msg.append("groupId=");
748 msg.append(groupId);
749
750 msg.append(StringPool.CLOSE_CURLY_BRACE);
751
752 throw new NoSuchUserGroupRoleException(msg.toString());
753 }
754
755
763 public UserGroupRole fetchByGroupId_First(long groupId,
764 OrderByComparator orderByComparator) throws SystemException {
765 List<UserGroupRole> list = findByGroupId(groupId, 0, 1,
766 orderByComparator);
767
768 if (!list.isEmpty()) {
769 return list.get(0);
770 }
771
772 return null;
773 }
774
775
784 public UserGroupRole findByGroupId_Last(long groupId,
785 OrderByComparator orderByComparator)
786 throws NoSuchUserGroupRoleException, SystemException {
787 UserGroupRole userGroupRole = fetchByGroupId_Last(groupId,
788 orderByComparator);
789
790 if (userGroupRole != null) {
791 return userGroupRole;
792 }
793
794 StringBundler msg = new StringBundler(4);
795
796 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
797
798 msg.append("groupId=");
799 msg.append(groupId);
800
801 msg.append(StringPool.CLOSE_CURLY_BRACE);
802
803 throw new NoSuchUserGroupRoleException(msg.toString());
804 }
805
806
814 public UserGroupRole fetchByGroupId_Last(long groupId,
815 OrderByComparator orderByComparator) throws SystemException {
816 int count = countByGroupId(groupId);
817
818 List<UserGroupRole> list = findByGroupId(groupId, count - 1, count,
819 orderByComparator);
820
821 if (!list.isEmpty()) {
822 return list.get(0);
823 }
824
825 return null;
826 }
827
828
838 public UserGroupRole[] findByGroupId_PrevAndNext(
839 UserGroupRolePK userGroupRolePK, long groupId,
840 OrderByComparator orderByComparator)
841 throws NoSuchUserGroupRoleException, SystemException {
842 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
843
844 Session session = null;
845
846 try {
847 session = openSession();
848
849 UserGroupRole[] array = new UserGroupRoleImpl[3];
850
851 array[0] = getByGroupId_PrevAndNext(session, userGroupRole,
852 groupId, orderByComparator, true);
853
854 array[1] = userGroupRole;
855
856 array[2] = getByGroupId_PrevAndNext(session, userGroupRole,
857 groupId, orderByComparator, false);
858
859 return array;
860 }
861 catch (Exception e) {
862 throw processException(e);
863 }
864 finally {
865 closeSession(session);
866 }
867 }
868
869 protected UserGroupRole getByGroupId_PrevAndNext(Session session,
870 UserGroupRole userGroupRole, long groupId,
871 OrderByComparator orderByComparator, boolean previous) {
872 StringBundler query = null;
873
874 if (orderByComparator != null) {
875 query = new StringBundler(6 +
876 (orderByComparator.getOrderByFields().length * 6));
877 }
878 else {
879 query = new StringBundler(3);
880 }
881
882 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
883
884 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
885
886 if (orderByComparator != null) {
887 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
888
889 if (orderByConditionFields.length > 0) {
890 query.append(WHERE_AND);
891 }
892
893 for (int i = 0; i < orderByConditionFields.length; i++) {
894 query.append(_ORDER_BY_ENTITY_ALIAS);
895 query.append(orderByConditionFields[i]);
896
897 if ((i + 1) < orderByConditionFields.length) {
898 if (orderByComparator.isAscending() ^ previous) {
899 query.append(WHERE_GREATER_THAN_HAS_NEXT);
900 }
901 else {
902 query.append(WHERE_LESSER_THAN_HAS_NEXT);
903 }
904 }
905 else {
906 if (orderByComparator.isAscending() ^ previous) {
907 query.append(WHERE_GREATER_THAN);
908 }
909 else {
910 query.append(WHERE_LESSER_THAN);
911 }
912 }
913 }
914
915 query.append(ORDER_BY_CLAUSE);
916
917 String[] orderByFields = orderByComparator.getOrderByFields();
918
919 for (int i = 0; i < orderByFields.length; i++) {
920 query.append(_ORDER_BY_ENTITY_ALIAS);
921 query.append(orderByFields[i]);
922
923 if ((i + 1) < orderByFields.length) {
924 if (orderByComparator.isAscending() ^ previous) {
925 query.append(ORDER_BY_ASC_HAS_NEXT);
926 }
927 else {
928 query.append(ORDER_BY_DESC_HAS_NEXT);
929 }
930 }
931 else {
932 if (orderByComparator.isAscending() ^ previous) {
933 query.append(ORDER_BY_ASC);
934 }
935 else {
936 query.append(ORDER_BY_DESC);
937 }
938 }
939 }
940 }
941 else {
942 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
943 }
944
945 String sql = query.toString();
946
947 Query q = session.createQuery(sql);
948
949 q.setFirstResult(0);
950 q.setMaxResults(2);
951
952 QueryPos qPos = QueryPos.getInstance(q);
953
954 qPos.add(groupId);
955
956 if (orderByComparator != null) {
957 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
958
959 for (Object value : values) {
960 qPos.add(value);
961 }
962 }
963
964 List<UserGroupRole> list = q.list();
965
966 if (list.size() == 2) {
967 return list.get(1);
968 }
969 else {
970 return null;
971 }
972 }
973
974
980 public void removeByGroupId(long groupId) throws SystemException {
981 for (UserGroupRole userGroupRole : findByGroupId(groupId,
982 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
983 remove(userGroupRole);
984 }
985 }
986
987
994 public int countByGroupId(long groupId) throws SystemException {
995 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
996
997 Object[] finderArgs = new Object[] { groupId };
998
999 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1000 this);
1001
1002 if (count == null) {
1003 StringBundler query = new StringBundler(2);
1004
1005 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1006
1007 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1008
1009 String sql = query.toString();
1010
1011 Session session = null;
1012
1013 try {
1014 session = openSession();
1015
1016 Query q = session.createQuery(sql);
1017
1018 QueryPos qPos = QueryPos.getInstance(q);
1019
1020 qPos.add(groupId);
1021
1022 count = (Long)q.uniqueResult();
1023
1024 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1025 }
1026 catch (Exception e) {
1027 FinderCacheUtil.removeResult(finderPath, finderArgs);
1028
1029 throw processException(e);
1030 }
1031 finally {
1032 closeSession(session);
1033 }
1034 }
1035
1036 return count.intValue();
1037 }
1038
1039 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "userGroupRole.id.groupId = ?";
1040 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1041 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1042 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1043 "findByRoleId",
1044 new String[] {
1045 Long.class.getName(),
1046
1047 Integer.class.getName(), Integer.class.getName(),
1048 OrderByComparator.class.getName()
1049 });
1050 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
1051 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1052 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1053 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1054 "findByRoleId", new String[] { Long.class.getName() },
1055 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
1056 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1057 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1058 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
1059 new String[] { Long.class.getName() });
1060
1061
1068 public List<UserGroupRole> findByRoleId(long roleId)
1069 throws SystemException {
1070 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1071 }
1072
1073
1086 public List<UserGroupRole> findByRoleId(long roleId, int start, int end)
1087 throws SystemException {
1088 return findByRoleId(roleId, start, end, null);
1089 }
1090
1091
1105 public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
1106 OrderByComparator orderByComparator) throws SystemException {
1107 boolean pagination = true;
1108 FinderPath finderPath = null;
1109 Object[] finderArgs = null;
1110
1111 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1112 (orderByComparator == null)) {
1113 pagination = false;
1114 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
1115 finderArgs = new Object[] { roleId };
1116 }
1117 else {
1118 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
1119 finderArgs = new Object[] { roleId, start, end, orderByComparator };
1120 }
1121
1122 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
1123 finderArgs, this);
1124
1125 if ((list != null) && !list.isEmpty()) {
1126 for (UserGroupRole userGroupRole : list) {
1127 if ((roleId != userGroupRole.getRoleId())) {
1128 list = null;
1129
1130 break;
1131 }
1132 }
1133 }
1134
1135 if (list == null) {
1136 StringBundler query = null;
1137
1138 if (orderByComparator != null) {
1139 query = new StringBundler(3 +
1140 (orderByComparator.getOrderByFields().length * 3));
1141 }
1142 else {
1143 query = new StringBundler(3);
1144 }
1145
1146 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1147
1148 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1149
1150 if (orderByComparator != null) {
1151 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1152 orderByComparator);
1153 }
1154 else
1155 if (pagination) {
1156 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1157 }
1158
1159 String sql = query.toString();
1160
1161 Session session = null;
1162
1163 try {
1164 session = openSession();
1165
1166 Query q = session.createQuery(sql);
1167
1168 QueryPos qPos = QueryPos.getInstance(q);
1169
1170 qPos.add(roleId);
1171
1172 if (!pagination) {
1173 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1174 start, end, false);
1175
1176 Collections.sort(list);
1177
1178 list = new UnmodifiableList<UserGroupRole>(list);
1179 }
1180 else {
1181 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1182 start, end);
1183 }
1184
1185 cacheResult(list);
1186
1187 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1188 }
1189 catch (Exception e) {
1190 FinderCacheUtil.removeResult(finderPath, finderArgs);
1191
1192 throw processException(e);
1193 }
1194 finally {
1195 closeSession(session);
1196 }
1197 }
1198
1199 return list;
1200 }
1201
1202
1211 public UserGroupRole findByRoleId_First(long roleId,
1212 OrderByComparator orderByComparator)
1213 throws NoSuchUserGroupRoleException, SystemException {
1214 UserGroupRole userGroupRole = fetchByRoleId_First(roleId,
1215 orderByComparator);
1216
1217 if (userGroupRole != null) {
1218 return userGroupRole;
1219 }
1220
1221 StringBundler msg = new StringBundler(4);
1222
1223 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1224
1225 msg.append("roleId=");
1226 msg.append(roleId);
1227
1228 msg.append(StringPool.CLOSE_CURLY_BRACE);
1229
1230 throw new NoSuchUserGroupRoleException(msg.toString());
1231 }
1232
1233
1241 public UserGroupRole fetchByRoleId_First(long roleId,
1242 OrderByComparator orderByComparator) throws SystemException {
1243 List<UserGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1244
1245 if (!list.isEmpty()) {
1246 return list.get(0);
1247 }
1248
1249 return null;
1250 }
1251
1252
1261 public UserGroupRole findByRoleId_Last(long roleId,
1262 OrderByComparator orderByComparator)
1263 throws NoSuchUserGroupRoleException, SystemException {
1264 UserGroupRole userGroupRole = fetchByRoleId_Last(roleId,
1265 orderByComparator);
1266
1267 if (userGroupRole != null) {
1268 return userGroupRole;
1269 }
1270
1271 StringBundler msg = new StringBundler(4);
1272
1273 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1274
1275 msg.append("roleId=");
1276 msg.append(roleId);
1277
1278 msg.append(StringPool.CLOSE_CURLY_BRACE);
1279
1280 throw new NoSuchUserGroupRoleException(msg.toString());
1281 }
1282
1283
1291 public UserGroupRole fetchByRoleId_Last(long roleId,
1292 OrderByComparator orderByComparator) throws SystemException {
1293 int count = countByRoleId(roleId);
1294
1295 List<UserGroupRole> list = findByRoleId(roleId, count - 1, count,
1296 orderByComparator);
1297
1298 if (!list.isEmpty()) {
1299 return list.get(0);
1300 }
1301
1302 return null;
1303 }
1304
1305
1315 public UserGroupRole[] findByRoleId_PrevAndNext(
1316 UserGroupRolePK userGroupRolePK, long roleId,
1317 OrderByComparator orderByComparator)
1318 throws NoSuchUserGroupRoleException, SystemException {
1319 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1320
1321 Session session = null;
1322
1323 try {
1324 session = openSession();
1325
1326 UserGroupRole[] array = new UserGroupRoleImpl[3];
1327
1328 array[0] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1329 orderByComparator, true);
1330
1331 array[1] = userGroupRole;
1332
1333 array[2] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1334 orderByComparator, false);
1335
1336 return array;
1337 }
1338 catch (Exception e) {
1339 throw processException(e);
1340 }
1341 finally {
1342 closeSession(session);
1343 }
1344 }
1345
1346 protected UserGroupRole getByRoleId_PrevAndNext(Session session,
1347 UserGroupRole userGroupRole, long roleId,
1348 OrderByComparator orderByComparator, boolean previous) {
1349 StringBundler query = null;
1350
1351 if (orderByComparator != null) {
1352 query = new StringBundler(6 +
1353 (orderByComparator.getOrderByFields().length * 6));
1354 }
1355 else {
1356 query = new StringBundler(3);
1357 }
1358
1359 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1360
1361 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1362
1363 if (orderByComparator != null) {
1364 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1365
1366 if (orderByConditionFields.length > 0) {
1367 query.append(WHERE_AND);
1368 }
1369
1370 for (int i = 0; i < orderByConditionFields.length; i++) {
1371 query.append(_ORDER_BY_ENTITY_ALIAS);
1372 query.append(orderByConditionFields[i]);
1373
1374 if ((i + 1) < orderByConditionFields.length) {
1375 if (orderByComparator.isAscending() ^ previous) {
1376 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1377 }
1378 else {
1379 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1380 }
1381 }
1382 else {
1383 if (orderByComparator.isAscending() ^ previous) {
1384 query.append(WHERE_GREATER_THAN);
1385 }
1386 else {
1387 query.append(WHERE_LESSER_THAN);
1388 }
1389 }
1390 }
1391
1392 query.append(ORDER_BY_CLAUSE);
1393
1394 String[] orderByFields = orderByComparator.getOrderByFields();
1395
1396 for (int i = 0; i < orderByFields.length; i++) {
1397 query.append(_ORDER_BY_ENTITY_ALIAS);
1398 query.append(orderByFields[i]);
1399
1400 if ((i + 1) < orderByFields.length) {
1401 if (orderByComparator.isAscending() ^ previous) {
1402 query.append(ORDER_BY_ASC_HAS_NEXT);
1403 }
1404 else {
1405 query.append(ORDER_BY_DESC_HAS_NEXT);
1406 }
1407 }
1408 else {
1409 if (orderByComparator.isAscending() ^ previous) {
1410 query.append(ORDER_BY_ASC);
1411 }
1412 else {
1413 query.append(ORDER_BY_DESC);
1414 }
1415 }
1416 }
1417 }
1418 else {
1419 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1420 }
1421
1422 String sql = query.toString();
1423
1424 Query q = session.createQuery(sql);
1425
1426 q.setFirstResult(0);
1427 q.setMaxResults(2);
1428
1429 QueryPos qPos = QueryPos.getInstance(q);
1430
1431 qPos.add(roleId);
1432
1433 if (orderByComparator != null) {
1434 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1435
1436 for (Object value : values) {
1437 qPos.add(value);
1438 }
1439 }
1440
1441 List<UserGroupRole> list = q.list();
1442
1443 if (list.size() == 2) {
1444 return list.get(1);
1445 }
1446 else {
1447 return null;
1448 }
1449 }
1450
1451
1457 public void removeByRoleId(long roleId) throws SystemException {
1458 for (UserGroupRole userGroupRole : findByRoleId(roleId,
1459 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1460 remove(userGroupRole);
1461 }
1462 }
1463
1464
1471 public int countByRoleId(long roleId) throws SystemException {
1472 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1473
1474 Object[] finderArgs = new Object[] { roleId };
1475
1476 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1477 this);
1478
1479 if (count == null) {
1480 StringBundler query = new StringBundler(2);
1481
1482 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1483
1484 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1485
1486 String sql = query.toString();
1487
1488 Session session = null;
1489
1490 try {
1491 session = openSession();
1492
1493 Query q = session.createQuery(sql);
1494
1495 QueryPos qPos = QueryPos.getInstance(q);
1496
1497 qPos.add(roleId);
1498
1499 count = (Long)q.uniqueResult();
1500
1501 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1502 }
1503 catch (Exception e) {
1504 FinderCacheUtil.removeResult(finderPath, finderArgs);
1505
1506 throw processException(e);
1507 }
1508 finally {
1509 closeSession(session);
1510 }
1511 }
1512
1513 return count.intValue();
1514 }
1515
1516 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "userGroupRole.id.roleId = ?";
1517 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1518 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1519 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1520 "findByU_G",
1521 new String[] {
1522 Long.class.getName(), Long.class.getName(),
1523
1524 Integer.class.getName(), Integer.class.getName(),
1525 OrderByComparator.class.getName()
1526 });
1527 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1528 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1529 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1530 "findByU_G",
1531 new String[] { Long.class.getName(), Long.class.getName() },
1532 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK |
1533 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
1534 public static final FinderPath FINDER_PATH_COUNT_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1535 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1536 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_G",
1537 new String[] { Long.class.getName(), Long.class.getName() });
1538
1539
1547 public List<UserGroupRole> findByU_G(long userId, long groupId)
1548 throws SystemException {
1549 return findByU_G(userId, groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1550 null);
1551 }
1552
1553
1567 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1568 int end) throws SystemException {
1569 return findByU_G(userId, groupId, start, end, null);
1570 }
1571
1572
1587 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1588 int end, OrderByComparator orderByComparator) throws SystemException {
1589 boolean pagination = true;
1590 FinderPath finderPath = null;
1591 Object[] finderArgs = null;
1592
1593 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1594 (orderByComparator == null)) {
1595 pagination = false;
1596 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G;
1597 finderArgs = new Object[] { userId, groupId };
1598 }
1599 else {
1600 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G;
1601 finderArgs = new Object[] {
1602 userId, groupId,
1603
1604 start, end, orderByComparator
1605 };
1606 }
1607
1608 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
1609 finderArgs, this);
1610
1611 if ((list != null) && !list.isEmpty()) {
1612 for (UserGroupRole userGroupRole : list) {
1613 if ((userId != userGroupRole.getUserId()) ||
1614 (groupId != userGroupRole.getGroupId())) {
1615 list = null;
1616
1617 break;
1618 }
1619 }
1620 }
1621
1622 if (list == null) {
1623 StringBundler query = null;
1624
1625 if (orderByComparator != null) {
1626 query = new StringBundler(4 +
1627 (orderByComparator.getOrderByFields().length * 3));
1628 }
1629 else {
1630 query = new StringBundler(4);
1631 }
1632
1633 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1634
1635 query.append(_FINDER_COLUMN_U_G_USERID_2);
1636
1637 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1638
1639 if (orderByComparator != null) {
1640 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1641 orderByComparator);
1642 }
1643 else
1644 if (pagination) {
1645 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1646 }
1647
1648 String sql = query.toString();
1649
1650 Session session = null;
1651
1652 try {
1653 session = openSession();
1654
1655 Query q = session.createQuery(sql);
1656
1657 QueryPos qPos = QueryPos.getInstance(q);
1658
1659 qPos.add(userId);
1660
1661 qPos.add(groupId);
1662
1663 if (!pagination) {
1664 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1665 start, end, false);
1666
1667 Collections.sort(list);
1668
1669 list = new UnmodifiableList<UserGroupRole>(list);
1670 }
1671 else {
1672 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1673 start, end);
1674 }
1675
1676 cacheResult(list);
1677
1678 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1679 }
1680 catch (Exception e) {
1681 FinderCacheUtil.removeResult(finderPath, finderArgs);
1682
1683 throw processException(e);
1684 }
1685 finally {
1686 closeSession(session);
1687 }
1688 }
1689
1690 return list;
1691 }
1692
1693
1703 public UserGroupRole findByU_G_First(long userId, long groupId,
1704 OrderByComparator orderByComparator)
1705 throws NoSuchUserGroupRoleException, SystemException {
1706 UserGroupRole userGroupRole = fetchByU_G_First(userId, groupId,
1707 orderByComparator);
1708
1709 if (userGroupRole != null) {
1710 return userGroupRole;
1711 }
1712
1713 StringBundler msg = new StringBundler(6);
1714
1715 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1716
1717 msg.append("userId=");
1718 msg.append(userId);
1719
1720 msg.append(", groupId=");
1721 msg.append(groupId);
1722
1723 msg.append(StringPool.CLOSE_CURLY_BRACE);
1724
1725 throw new NoSuchUserGroupRoleException(msg.toString());
1726 }
1727
1728
1737 public UserGroupRole fetchByU_G_First(long userId, long groupId,
1738 OrderByComparator orderByComparator) throws SystemException {
1739 List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1,
1740 orderByComparator);
1741
1742 if (!list.isEmpty()) {
1743 return list.get(0);
1744 }
1745
1746 return null;
1747 }
1748
1749
1759 public UserGroupRole findByU_G_Last(long userId, long groupId,
1760 OrderByComparator orderByComparator)
1761 throws NoSuchUserGroupRoleException, SystemException {
1762 UserGroupRole userGroupRole = fetchByU_G_Last(userId, groupId,
1763 orderByComparator);
1764
1765 if (userGroupRole != null) {
1766 return userGroupRole;
1767 }
1768
1769 StringBundler msg = new StringBundler(6);
1770
1771 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1772
1773 msg.append("userId=");
1774 msg.append(userId);
1775
1776 msg.append(", groupId=");
1777 msg.append(groupId);
1778
1779 msg.append(StringPool.CLOSE_CURLY_BRACE);
1780
1781 throw new NoSuchUserGroupRoleException(msg.toString());
1782 }
1783
1784
1793 public UserGroupRole fetchByU_G_Last(long userId, long groupId,
1794 OrderByComparator orderByComparator) throws SystemException {
1795 int count = countByU_G(userId, groupId);
1796
1797 List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1798 orderByComparator);
1799
1800 if (!list.isEmpty()) {
1801 return list.get(0);
1802 }
1803
1804 return null;
1805 }
1806
1807
1818 public UserGroupRole[] findByU_G_PrevAndNext(
1819 UserGroupRolePK userGroupRolePK, long userId, long groupId,
1820 OrderByComparator orderByComparator)
1821 throws NoSuchUserGroupRoleException, SystemException {
1822 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1823
1824 Session session = null;
1825
1826 try {
1827 session = openSession();
1828
1829 UserGroupRole[] array = new UserGroupRoleImpl[3];
1830
1831 array[0] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1832 groupId, orderByComparator, true);
1833
1834 array[1] = userGroupRole;
1835
1836 array[2] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1837 groupId, orderByComparator, false);
1838
1839 return array;
1840 }
1841 catch (Exception e) {
1842 throw processException(e);
1843 }
1844 finally {
1845 closeSession(session);
1846 }
1847 }
1848
1849 protected UserGroupRole getByU_G_PrevAndNext(Session session,
1850 UserGroupRole userGroupRole, long userId, long groupId,
1851 OrderByComparator orderByComparator, boolean previous) {
1852 StringBundler query = null;
1853
1854 if (orderByComparator != null) {
1855 query = new StringBundler(6 +
1856 (orderByComparator.getOrderByFields().length * 6));
1857 }
1858 else {
1859 query = new StringBundler(3);
1860 }
1861
1862 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1863
1864 query.append(_FINDER_COLUMN_U_G_USERID_2);
1865
1866 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1867
1868 if (orderByComparator != null) {
1869 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1870
1871 if (orderByConditionFields.length > 0) {
1872 query.append(WHERE_AND);
1873 }
1874
1875 for (int i = 0; i < orderByConditionFields.length; i++) {
1876 query.append(_ORDER_BY_ENTITY_ALIAS);
1877 query.append(orderByConditionFields[i]);
1878
1879 if ((i + 1) < orderByConditionFields.length) {
1880 if (orderByComparator.isAscending() ^ previous) {
1881 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1882 }
1883 else {
1884 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1885 }
1886 }
1887 else {
1888 if (orderByComparator.isAscending() ^ previous) {
1889 query.append(WHERE_GREATER_THAN);
1890 }
1891 else {
1892 query.append(WHERE_LESSER_THAN);
1893 }
1894 }
1895 }
1896
1897 query.append(ORDER_BY_CLAUSE);
1898
1899 String[] orderByFields = orderByComparator.getOrderByFields();
1900
1901 for (int i = 0; i < orderByFields.length; i++) {
1902 query.append(_ORDER_BY_ENTITY_ALIAS);
1903 query.append(orderByFields[i]);
1904
1905 if ((i + 1) < orderByFields.length) {
1906 if (orderByComparator.isAscending() ^ previous) {
1907 query.append(ORDER_BY_ASC_HAS_NEXT);
1908 }
1909 else {
1910 query.append(ORDER_BY_DESC_HAS_NEXT);
1911 }
1912 }
1913 else {
1914 if (orderByComparator.isAscending() ^ previous) {
1915 query.append(ORDER_BY_ASC);
1916 }
1917 else {
1918 query.append(ORDER_BY_DESC);
1919 }
1920 }
1921 }
1922 }
1923 else {
1924 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1925 }
1926
1927 String sql = query.toString();
1928
1929 Query q = session.createQuery(sql);
1930
1931 q.setFirstResult(0);
1932 q.setMaxResults(2);
1933
1934 QueryPos qPos = QueryPos.getInstance(q);
1935
1936 qPos.add(userId);
1937
1938 qPos.add(groupId);
1939
1940 if (orderByComparator != null) {
1941 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1942
1943 for (Object value : values) {
1944 qPos.add(value);
1945 }
1946 }
1947
1948 List<UserGroupRole> list = q.list();
1949
1950 if (list.size() == 2) {
1951 return list.get(1);
1952 }
1953 else {
1954 return null;
1955 }
1956 }
1957
1958
1965 public void removeByU_G(long userId, long groupId)
1966 throws SystemException {
1967 for (UserGroupRole userGroupRole : findByU_G(userId, groupId,
1968 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1969 remove(userGroupRole);
1970 }
1971 }
1972
1973
1981 public int countByU_G(long userId, long groupId) throws SystemException {
1982 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_G;
1983
1984 Object[] finderArgs = new Object[] { userId, groupId };
1985
1986 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1987 this);
1988
1989 if (count == null) {
1990 StringBundler query = new StringBundler(3);
1991
1992 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1993
1994 query.append(_FINDER_COLUMN_U_G_USERID_2);
1995
1996 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1997
1998 String sql = query.toString();
1999
2000 Session session = null;
2001
2002 try {
2003 session = openSession();
2004
2005 Query q = session.createQuery(sql);
2006
2007 QueryPos qPos = QueryPos.getInstance(q);
2008
2009 qPos.add(userId);
2010
2011 qPos.add(groupId);
2012
2013 count = (Long)q.uniqueResult();
2014
2015 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2016 }
2017 catch (Exception e) {
2018 FinderCacheUtil.removeResult(finderPath, finderArgs);
2019
2020 throw processException(e);
2021 }
2022 finally {
2023 closeSession(session);
2024 }
2025 }
2026
2027 return count.intValue();
2028 }
2029
2030 private static final String _FINDER_COLUMN_U_G_USERID_2 = "userGroupRole.id.userId = ? AND ";
2031 private static final String _FINDER_COLUMN_U_G_GROUPID_2 = "userGroupRole.id.groupId = ?";
2032 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2033 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2034 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2035 "findByG_R",
2036 new String[] {
2037 Long.class.getName(), Long.class.getName(),
2038
2039 Integer.class.getName(), Integer.class.getName(),
2040 OrderByComparator.class.getName()
2041 });
2042 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2043 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2044 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2045 "findByG_R",
2046 new String[] { Long.class.getName(), Long.class.getName() },
2047 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK |
2048 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
2049 public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2050 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2051 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_R",
2052 new String[] { Long.class.getName(), Long.class.getName() });
2053
2054
2062 public List<UserGroupRole> findByG_R(long groupId, long roleId)
2063 throws SystemException {
2064 return findByG_R(groupId, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2065 null);
2066 }
2067
2068
2082 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2083 int end) throws SystemException {
2084 return findByG_R(groupId, roleId, start, end, null);
2085 }
2086
2087
2102 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2103 int end, OrderByComparator orderByComparator) throws SystemException {
2104 boolean pagination = true;
2105 FinderPath finderPath = null;
2106 Object[] finderArgs = null;
2107
2108 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2109 (orderByComparator == null)) {
2110 pagination = false;
2111 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R;
2112 finderArgs = new Object[] { groupId, roleId };
2113 }
2114 else {
2115 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R;
2116 finderArgs = new Object[] {
2117 groupId, roleId,
2118
2119 start, end, orderByComparator
2120 };
2121 }
2122
2123 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
2124 finderArgs, this);
2125
2126 if ((list != null) && !list.isEmpty()) {
2127 for (UserGroupRole userGroupRole : list) {
2128 if ((groupId != userGroupRole.getGroupId()) ||
2129 (roleId != userGroupRole.getRoleId())) {
2130 list = null;
2131
2132 break;
2133 }
2134 }
2135 }
2136
2137 if (list == null) {
2138 StringBundler query = null;
2139
2140 if (orderByComparator != null) {
2141 query = new StringBundler(4 +
2142 (orderByComparator.getOrderByFields().length * 3));
2143 }
2144 else {
2145 query = new StringBundler(4);
2146 }
2147
2148 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2149
2150 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2151
2152 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2153
2154 if (orderByComparator != null) {
2155 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2156 orderByComparator);
2157 }
2158 else
2159 if (pagination) {
2160 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2161 }
2162
2163 String sql = query.toString();
2164
2165 Session session = null;
2166
2167 try {
2168 session = openSession();
2169
2170 Query q = session.createQuery(sql);
2171
2172 QueryPos qPos = QueryPos.getInstance(q);
2173
2174 qPos.add(groupId);
2175
2176 qPos.add(roleId);
2177
2178 if (!pagination) {
2179 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2180 start, end, false);
2181
2182 Collections.sort(list);
2183
2184 list = new UnmodifiableList<UserGroupRole>(list);
2185 }
2186 else {
2187 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2188 start, end);
2189 }
2190
2191 cacheResult(list);
2192
2193 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2194 }
2195 catch (Exception e) {
2196 FinderCacheUtil.removeResult(finderPath, finderArgs);
2197
2198 throw processException(e);
2199 }
2200 finally {
2201 closeSession(session);
2202 }
2203 }
2204
2205 return list;
2206 }
2207
2208
2218 public UserGroupRole findByG_R_First(long groupId, long roleId,
2219 OrderByComparator orderByComparator)
2220 throws NoSuchUserGroupRoleException, SystemException {
2221 UserGroupRole userGroupRole = fetchByG_R_First(groupId, roleId,
2222 orderByComparator);
2223
2224 if (userGroupRole != null) {
2225 return userGroupRole;
2226 }
2227
2228 StringBundler msg = new StringBundler(6);
2229
2230 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2231
2232 msg.append("groupId=");
2233 msg.append(groupId);
2234
2235 msg.append(", roleId=");
2236 msg.append(roleId);
2237
2238 msg.append(StringPool.CLOSE_CURLY_BRACE);
2239
2240 throw new NoSuchUserGroupRoleException(msg.toString());
2241 }
2242
2243
2252 public UserGroupRole fetchByG_R_First(long groupId, long roleId,
2253 OrderByComparator orderByComparator) throws SystemException {
2254 List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1,
2255 orderByComparator);
2256
2257 if (!list.isEmpty()) {
2258 return list.get(0);
2259 }
2260
2261 return null;
2262 }
2263
2264
2274 public UserGroupRole findByG_R_Last(long groupId, long roleId,
2275 OrderByComparator orderByComparator)
2276 throws NoSuchUserGroupRoleException, SystemException {
2277 UserGroupRole userGroupRole = fetchByG_R_Last(groupId, roleId,
2278 orderByComparator);
2279
2280 if (userGroupRole != null) {
2281 return userGroupRole;
2282 }
2283
2284 StringBundler msg = new StringBundler(6);
2285
2286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2287
2288 msg.append("groupId=");
2289 msg.append(groupId);
2290
2291 msg.append(", roleId=");
2292 msg.append(roleId);
2293
2294 msg.append(StringPool.CLOSE_CURLY_BRACE);
2295
2296 throw new NoSuchUserGroupRoleException(msg.toString());
2297 }
2298
2299
2308 public UserGroupRole fetchByG_R_Last(long groupId, long roleId,
2309 OrderByComparator orderByComparator) throws SystemException {
2310 int count = countByG_R(groupId, roleId);
2311
2312 List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
2313 orderByComparator);
2314
2315 if (!list.isEmpty()) {
2316 return list.get(0);
2317 }
2318
2319 return null;
2320 }
2321
2322
2333 public UserGroupRole[] findByG_R_PrevAndNext(
2334 UserGroupRolePK userGroupRolePK, long groupId, long roleId,
2335 OrderByComparator orderByComparator)
2336 throws NoSuchUserGroupRoleException, SystemException {
2337 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
2338
2339 Session session = null;
2340
2341 try {
2342 session = openSession();
2343
2344 UserGroupRole[] array = new UserGroupRoleImpl[3];
2345
2346 array[0] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2347 roleId, orderByComparator, true);
2348
2349 array[1] = userGroupRole;
2350
2351 array[2] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2352 roleId, orderByComparator, false);
2353
2354 return array;
2355 }
2356 catch (Exception e) {
2357 throw processException(e);
2358 }
2359 finally {
2360 closeSession(session);
2361 }
2362 }
2363
2364 protected UserGroupRole getByG_R_PrevAndNext(Session session,
2365 UserGroupRole userGroupRole, long groupId, long roleId,
2366 OrderByComparator orderByComparator, boolean previous) {
2367 StringBundler query = null;
2368
2369 if (orderByComparator != null) {
2370 query = new StringBundler(6 +
2371 (orderByComparator.getOrderByFields().length * 6));
2372 }
2373 else {
2374 query = new StringBundler(3);
2375 }
2376
2377 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2378
2379 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2380
2381 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2382
2383 if (orderByComparator != null) {
2384 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2385
2386 if (orderByConditionFields.length > 0) {
2387 query.append(WHERE_AND);
2388 }
2389
2390 for (int i = 0; i < orderByConditionFields.length; i++) {
2391 query.append(_ORDER_BY_ENTITY_ALIAS);
2392 query.append(orderByConditionFields[i]);
2393
2394 if ((i + 1) < orderByConditionFields.length) {
2395 if (orderByComparator.isAscending() ^ previous) {
2396 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2397 }
2398 else {
2399 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2400 }
2401 }
2402 else {
2403 if (orderByComparator.isAscending() ^ previous) {
2404 query.append(WHERE_GREATER_THAN);
2405 }
2406 else {
2407 query.append(WHERE_LESSER_THAN);
2408 }
2409 }
2410 }
2411
2412 query.append(ORDER_BY_CLAUSE);
2413
2414 String[] orderByFields = orderByComparator.getOrderByFields();
2415
2416 for (int i = 0; i < orderByFields.length; i++) {
2417 query.append(_ORDER_BY_ENTITY_ALIAS);
2418 query.append(orderByFields[i]);
2419
2420 if ((i + 1) < orderByFields.length) {
2421 if (orderByComparator.isAscending() ^ previous) {
2422 query.append(ORDER_BY_ASC_HAS_NEXT);
2423 }
2424 else {
2425 query.append(ORDER_BY_DESC_HAS_NEXT);
2426 }
2427 }
2428 else {
2429 if (orderByComparator.isAscending() ^ previous) {
2430 query.append(ORDER_BY_ASC);
2431 }
2432 else {
2433 query.append(ORDER_BY_DESC);
2434 }
2435 }
2436 }
2437 }
2438 else {
2439 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2440 }
2441
2442 String sql = query.toString();
2443
2444 Query q = session.createQuery(sql);
2445
2446 q.setFirstResult(0);
2447 q.setMaxResults(2);
2448
2449 QueryPos qPos = QueryPos.getInstance(q);
2450
2451 qPos.add(groupId);
2452
2453 qPos.add(roleId);
2454
2455 if (orderByComparator != null) {
2456 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
2457
2458 for (Object value : values) {
2459 qPos.add(value);
2460 }
2461 }
2462
2463 List<UserGroupRole> list = q.list();
2464
2465 if (list.size() == 2) {
2466 return list.get(1);
2467 }
2468 else {
2469 return null;
2470 }
2471 }
2472
2473
2480 public void removeByG_R(long groupId, long roleId)
2481 throws SystemException {
2482 for (UserGroupRole userGroupRole : findByG_R(groupId, roleId,
2483 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2484 remove(userGroupRole);
2485 }
2486 }
2487
2488
2496 public int countByG_R(long groupId, long roleId) throws SystemException {
2497 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_R;
2498
2499 Object[] finderArgs = new Object[] { groupId, roleId };
2500
2501 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2502 this);
2503
2504 if (count == null) {
2505 StringBundler query = new StringBundler(3);
2506
2507 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2508
2509 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2510
2511 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2512
2513 String sql = query.toString();
2514
2515 Session session = null;
2516
2517 try {
2518 session = openSession();
2519
2520 Query q = session.createQuery(sql);
2521
2522 QueryPos qPos = QueryPos.getInstance(q);
2523
2524 qPos.add(groupId);
2525
2526 qPos.add(roleId);
2527
2528 count = (Long)q.uniqueResult();
2529
2530 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2531 }
2532 catch (Exception e) {
2533 FinderCacheUtil.removeResult(finderPath, finderArgs);
2534
2535 throw processException(e);
2536 }
2537 finally {
2538 closeSession(session);
2539 }
2540 }
2541
2542 return count.intValue();
2543 }
2544
2545 private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "userGroupRole.id.groupId = ? AND ";
2546 private static final String _FINDER_COLUMN_G_R_ROLEID_2 = "userGroupRole.id.roleId = ?";
2547
2548
2553 public void cacheResult(UserGroupRole userGroupRole) {
2554 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2555 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2556 userGroupRole);
2557
2558 userGroupRole.resetOriginalValues();
2559 }
2560
2561
2566 public void cacheResult(List<UserGroupRole> userGroupRoles) {
2567 for (UserGroupRole userGroupRole : userGroupRoles) {
2568 if (EntityCacheUtil.getResult(
2569 UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2570 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey()) == null) {
2571 cacheResult(userGroupRole);
2572 }
2573 else {
2574 userGroupRole.resetOriginalValues();
2575 }
2576 }
2577 }
2578
2579
2586 @Override
2587 public void clearCache() {
2588 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2589 CacheRegistryUtil.clear(UserGroupRoleImpl.class.getName());
2590 }
2591
2592 EntityCacheUtil.clearCache(UserGroupRoleImpl.class.getName());
2593
2594 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2595 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2596 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2597 }
2598
2599
2606 @Override
2607 public void clearCache(UserGroupRole userGroupRole) {
2608 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2609 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2610
2611 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2612 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2613 }
2614
2615 @Override
2616 public void clearCache(List<UserGroupRole> userGroupRoles) {
2617 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2618 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2619
2620 for (UserGroupRole userGroupRole : userGroupRoles) {
2621 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2622 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2623 }
2624 }
2625
2626
2632 public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
2633 UserGroupRole userGroupRole = new UserGroupRoleImpl();
2634
2635 userGroupRole.setNew(true);
2636 userGroupRole.setPrimaryKey(userGroupRolePK);
2637
2638 return userGroupRole;
2639 }
2640
2641
2649 public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
2650 throws NoSuchUserGroupRoleException, SystemException {
2651 return remove((Serializable)userGroupRolePK);
2652 }
2653
2654
2662 @Override
2663 public UserGroupRole remove(Serializable primaryKey)
2664 throws NoSuchUserGroupRoleException, SystemException {
2665 Session session = null;
2666
2667 try {
2668 session = openSession();
2669
2670 UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2671 primaryKey);
2672
2673 if (userGroupRole == null) {
2674 if (_log.isWarnEnabled()) {
2675 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2676 }
2677
2678 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2679 primaryKey);
2680 }
2681
2682 return remove(userGroupRole);
2683 }
2684 catch (NoSuchUserGroupRoleException nsee) {
2685 throw nsee;
2686 }
2687 catch (Exception e) {
2688 throw processException(e);
2689 }
2690 finally {
2691 closeSession(session);
2692 }
2693 }
2694
2695 @Override
2696 protected UserGroupRole removeImpl(UserGroupRole userGroupRole)
2697 throws SystemException {
2698 userGroupRole = toUnwrappedModel(userGroupRole);
2699
2700 Session session = null;
2701
2702 try {
2703 session = openSession();
2704
2705 if (!session.contains(userGroupRole)) {
2706 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2707 userGroupRole.getPrimaryKeyObj());
2708 }
2709
2710 if (userGroupRole != null) {
2711 session.delete(userGroupRole);
2712 }
2713 }
2714 catch (Exception e) {
2715 throw processException(e);
2716 }
2717 finally {
2718 closeSession(session);
2719 }
2720
2721 if (userGroupRole != null) {
2722 clearCache(userGroupRole);
2723 }
2724
2725 return userGroupRole;
2726 }
2727
2728 @Override
2729 public UserGroupRole updateImpl(
2730 com.liferay.portal.model.UserGroupRole userGroupRole)
2731 throws SystemException {
2732 userGroupRole = toUnwrappedModel(userGroupRole);
2733
2734 boolean isNew = userGroupRole.isNew();
2735
2736 UserGroupRoleModelImpl userGroupRoleModelImpl = (UserGroupRoleModelImpl)userGroupRole;
2737
2738 Session session = null;
2739
2740 try {
2741 session = openSession();
2742
2743 if (userGroupRole.isNew()) {
2744 session.save(userGroupRole);
2745
2746 userGroupRole.setNew(false);
2747 }
2748 else {
2749 session.merge(userGroupRole);
2750 }
2751 }
2752 catch (Exception e) {
2753 throw processException(e);
2754 }
2755 finally {
2756 closeSession(session);
2757 }
2758
2759 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2760
2761 if (isNew || !UserGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
2762 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2763 }
2764
2765 else {
2766 if ((userGroupRoleModelImpl.getColumnBitmask() &
2767 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2768 Object[] args = new Object[] {
2769 Long.valueOf(userGroupRoleModelImpl.getOriginalUserId())
2770 };
2771
2772 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2773 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2774 args);
2775
2776 args = new Object[] {
2777 Long.valueOf(userGroupRoleModelImpl.getUserId())
2778 };
2779
2780 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2781 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2782 args);
2783 }
2784
2785 if ((userGroupRoleModelImpl.getColumnBitmask() &
2786 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2787 Object[] args = new Object[] {
2788 Long.valueOf(userGroupRoleModelImpl.getOriginalGroupId())
2789 };
2790
2791 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2792 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2793 args);
2794
2795 args = new Object[] {
2796 Long.valueOf(userGroupRoleModelImpl.getGroupId())
2797 };
2798
2799 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2800 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2801 args);
2802 }
2803
2804 if ((userGroupRoleModelImpl.getColumnBitmask() &
2805 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
2806 Object[] args = new Object[] {
2807 Long.valueOf(userGroupRoleModelImpl.getOriginalRoleId())
2808 };
2809
2810 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2811 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2812 args);
2813
2814 args = new Object[] {
2815 Long.valueOf(userGroupRoleModelImpl.getRoleId())
2816 };
2817
2818 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2819 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2820 args);
2821 }
2822
2823 if ((userGroupRoleModelImpl.getColumnBitmask() &
2824 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G.getColumnBitmask()) != 0) {
2825 Object[] args = new Object[] {
2826 Long.valueOf(userGroupRoleModelImpl.getOriginalUserId()),
2827 Long.valueOf(userGroupRoleModelImpl.getOriginalGroupId())
2828 };
2829
2830 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2831 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2832 args);
2833
2834 args = new Object[] {
2835 Long.valueOf(userGroupRoleModelImpl.getUserId()),
2836 Long.valueOf(userGroupRoleModelImpl.getGroupId())
2837 };
2838
2839 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2840 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2841 args);
2842 }
2843
2844 if ((userGroupRoleModelImpl.getColumnBitmask() &
2845 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R.getColumnBitmask()) != 0) {
2846 Object[] args = new Object[] {
2847 Long.valueOf(userGroupRoleModelImpl.getOriginalGroupId()),
2848 Long.valueOf(userGroupRoleModelImpl.getOriginalRoleId())
2849 };
2850
2851 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2852 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2853 args);
2854
2855 args = new Object[] {
2856 Long.valueOf(userGroupRoleModelImpl.getGroupId()),
2857 Long.valueOf(userGroupRoleModelImpl.getRoleId())
2858 };
2859
2860 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2861 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2862 args);
2863 }
2864 }
2865
2866 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2867 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2868 userGroupRole);
2869
2870 return userGroupRole;
2871 }
2872
2873 protected UserGroupRole toUnwrappedModel(UserGroupRole userGroupRole) {
2874 if (userGroupRole instanceof UserGroupRoleImpl) {
2875 return userGroupRole;
2876 }
2877
2878 UserGroupRoleImpl userGroupRoleImpl = new UserGroupRoleImpl();
2879
2880 userGroupRoleImpl.setNew(userGroupRole.isNew());
2881 userGroupRoleImpl.setPrimaryKey(userGroupRole.getPrimaryKey());
2882
2883 userGroupRoleImpl.setUserId(userGroupRole.getUserId());
2884 userGroupRoleImpl.setGroupId(userGroupRole.getGroupId());
2885 userGroupRoleImpl.setRoleId(userGroupRole.getRoleId());
2886
2887 return userGroupRoleImpl;
2888 }
2889
2890
2898 @Override
2899 public UserGroupRole findByPrimaryKey(Serializable primaryKey)
2900 throws NoSuchModelException, SystemException {
2901 return findByPrimaryKey((UserGroupRolePK)primaryKey);
2902 }
2903
2904
2912 public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
2913 throws NoSuchUserGroupRoleException, SystemException {
2914 UserGroupRole userGroupRole = fetchByPrimaryKey(userGroupRolePK);
2915
2916 if (userGroupRole == null) {
2917 if (_log.isWarnEnabled()) {
2918 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + userGroupRolePK);
2919 }
2920
2921 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2922 userGroupRolePK);
2923 }
2924
2925 return userGroupRole;
2926 }
2927
2928
2935 @Override
2936 public UserGroupRole fetchByPrimaryKey(Serializable primaryKey)
2937 throws SystemException {
2938 return fetchByPrimaryKey((UserGroupRolePK)primaryKey);
2939 }
2940
2941
2948 public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK)
2949 throws SystemException {
2950 UserGroupRole userGroupRole = (UserGroupRole)EntityCacheUtil.getResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2951 UserGroupRoleImpl.class, userGroupRolePK);
2952
2953 if (userGroupRole == _nullUserGroupRole) {
2954 return null;
2955 }
2956
2957 if (userGroupRole == null) {
2958 Session session = null;
2959
2960 try {
2961 session = openSession();
2962
2963 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2964 userGroupRolePK);
2965
2966 if (userGroupRole != null) {
2967 cacheResult(userGroupRole);
2968 }
2969 else {
2970 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2971 UserGroupRoleImpl.class, userGroupRolePK,
2972 _nullUserGroupRole);
2973 }
2974 }
2975 catch (Exception e) {
2976 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2977 UserGroupRoleImpl.class, userGroupRolePK);
2978
2979 throw processException(e);
2980 }
2981 finally {
2982 closeSession(session);
2983 }
2984 }
2985
2986 return userGroupRole;
2987 }
2988
2989
2995 public List<UserGroupRole> findAll() throws SystemException {
2996 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2997 }
2998
2999
3011 public List<UserGroupRole> findAll(int start, int end)
3012 throws SystemException {
3013 return findAll(start, end, null);
3014 }
3015
3016
3029 public List<UserGroupRole> findAll(int start, int end,
3030 OrderByComparator orderByComparator) throws SystemException {
3031 boolean pagination = true;
3032 FinderPath finderPath = null;
3033 Object[] finderArgs = null;
3034
3035 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3036 (orderByComparator == null)) {
3037 pagination = false;
3038 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3039 finderArgs = FINDER_ARGS_EMPTY;
3040 }
3041 else {
3042 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3043 finderArgs = new Object[] { start, end, orderByComparator };
3044 }
3045
3046 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
3047 finderArgs, this);
3048
3049 if (list == null) {
3050 StringBundler query = null;
3051 String sql = null;
3052
3053 if (orderByComparator != null) {
3054 query = new StringBundler(2 +
3055 (orderByComparator.getOrderByFields().length * 3));
3056
3057 query.append(_SQL_SELECT_USERGROUPROLE);
3058
3059 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3060 orderByComparator);
3061
3062 sql = query.toString();
3063 }
3064 else {
3065 sql = _SQL_SELECT_USERGROUPROLE;
3066
3067 if (pagination) {
3068 sql = sql.concat(UserGroupRoleModelImpl.ORDER_BY_JPQL);
3069 }
3070 }
3071
3072 Session session = null;
3073
3074 try {
3075 session = openSession();
3076
3077 Query q = session.createQuery(sql);
3078
3079 if (!pagination) {
3080 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3081 start, end, false);
3082
3083 Collections.sort(list);
3084
3085 list = new UnmodifiableList<UserGroupRole>(list);
3086 }
3087 else {
3088 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3089 start, end);
3090 }
3091
3092 cacheResult(list);
3093
3094 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3095 }
3096 catch (Exception e) {
3097 FinderCacheUtil.removeResult(finderPath, finderArgs);
3098
3099 throw processException(e);
3100 }
3101 finally {
3102 closeSession(session);
3103 }
3104 }
3105
3106 return list;
3107 }
3108
3109
3114 public void removeAll() throws SystemException {
3115 for (UserGroupRole userGroupRole : findAll()) {
3116 remove(userGroupRole);
3117 }
3118 }
3119
3120
3126 public int countAll() throws SystemException {
3127 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3128 FINDER_ARGS_EMPTY, this);
3129
3130 if (count == null) {
3131 Session session = null;
3132
3133 try {
3134 session = openSession();
3135
3136 Query q = session.createQuery(_SQL_COUNT_USERGROUPROLE);
3137
3138 count = (Long)q.uniqueResult();
3139
3140 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3141 FINDER_ARGS_EMPTY, count);
3142 }
3143 catch (Exception e) {
3144 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3145 FINDER_ARGS_EMPTY);
3146
3147 throw processException(e);
3148 }
3149 finally {
3150 closeSession(session);
3151 }
3152 }
3153
3154 return count.intValue();
3155 }
3156
3157
3160 public void afterPropertiesSet() {
3161 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3162 com.liferay.portal.util.PropsUtil.get(
3163 "value.object.listener.com.liferay.portal.model.UserGroupRole")));
3164
3165 if (listenerClassNames.length > 0) {
3166 try {
3167 List<ModelListener<UserGroupRole>> listenersList = new ArrayList<ModelListener<UserGroupRole>>();
3168
3169 for (String listenerClassName : listenerClassNames) {
3170 listenersList.add((ModelListener<UserGroupRole>)InstanceFactory.newInstance(
3171 listenerClassName));
3172 }
3173
3174 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3175 }
3176 catch (Exception e) {
3177 _log.error(e);
3178 }
3179 }
3180 }
3181
3182 public void destroy() {
3183 EntityCacheUtil.removeCache(UserGroupRoleImpl.class.getName());
3184 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3185 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3186 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3187 }
3188
3189 private static final String _SQL_SELECT_USERGROUPROLE = "SELECT userGroupRole FROM UserGroupRole userGroupRole";
3190 private static final String _SQL_SELECT_USERGROUPROLE_WHERE = "SELECT userGroupRole FROM UserGroupRole userGroupRole WHERE ";
3191 private static final String _SQL_COUNT_USERGROUPROLE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole";
3192 private static final String _SQL_COUNT_USERGROUPROLE_WHERE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole WHERE ";
3193 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroupRole.";
3194 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroupRole exists with the primary key ";
3195 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroupRole exists with the key {";
3196 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3197 private static Log _log = LogFactoryUtil.getLog(UserGroupRolePersistenceImpl.class);
3198 private static UserGroupRole _nullUserGroupRole = new UserGroupRoleImpl() {
3199 @Override
3200 public Object clone() {
3201 return this;
3202 }
3203
3204 @Override
3205 public CacheModel<UserGroupRole> toCacheModel() {
3206 return _nullUserGroupRoleCacheModel;
3207 }
3208 };
3209
3210 private static CacheModel<UserGroupRole> _nullUserGroupRoleCacheModel = new CacheModel<UserGroupRole>() {
3211 public UserGroupRole toEntityModel() {
3212 return _nullUserGroupRole;
3213 }
3214 };
3215 }