001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchUserGroupRoleException;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.model.MVCCModel;
035 import com.liferay.portal.model.UserGroupRole;
036 import com.liferay.portal.model.impl.UserGroupRoleImpl;
037 import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
038 import com.liferay.portal.service.persistence.UserGroupRolePK;
039 import com.liferay.portal.service.persistence.UserGroupRolePersistence;
040
041 import java.io.Serializable;
042
043 import java.util.Collections;
044 import java.util.HashMap;
045 import java.util.List;
046 import java.util.Map;
047 import java.util.Set;
048
049
061 @ProviderType
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
112 @Override
113 public List<UserGroupRole> findByUserId(long userId) {
114 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
115 }
116
117
129 @Override
130 public List<UserGroupRole> findByUserId(long userId, int start, int end) {
131 return findByUserId(userId, start, end, null);
132 }
133
134
147 @Override
148 public List<UserGroupRole> findByUserId(long userId, int start, int end,
149 OrderByComparator<UserGroupRole> orderByComparator) {
150 boolean pagination = true;
151 FinderPath finderPath = null;
152 Object[] finderArgs = null;
153
154 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155 (orderByComparator == null)) {
156 pagination = false;
157 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
158 finderArgs = new Object[] { userId };
159 }
160 else {
161 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
162 finderArgs = new Object[] { userId, start, end, orderByComparator };
163 }
164
165 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
166 finderArgs, this);
167
168 if ((list != null) && !list.isEmpty()) {
169 for (UserGroupRole userGroupRole : list) {
170 if ((userId != userGroupRole.getUserId())) {
171 list = null;
172
173 break;
174 }
175 }
176 }
177
178 if (list == null) {
179 StringBundler query = null;
180
181 if (orderByComparator != null) {
182 query = new StringBundler(3 +
183 (orderByComparator.getOrderByFields().length * 3));
184 }
185 else {
186 query = new StringBundler(3);
187 }
188
189 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
190
191 query.append(_FINDER_COLUMN_USERID_USERID_2);
192
193 if (orderByComparator != null) {
194 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
195 orderByComparator);
196 }
197 else
198 if (pagination) {
199 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
200 }
201
202 String sql = query.toString();
203
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 Query q = session.createQuery(sql);
210
211 QueryPos qPos = QueryPos.getInstance(q);
212
213 qPos.add(userId);
214
215 if (!pagination) {
216 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
217 start, end, false);
218
219 Collections.sort(list);
220
221 list = Collections.unmodifiableList(list);
222 }
223 else {
224 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
225 start, end);
226 }
227
228 cacheResult(list);
229
230 FinderCacheUtil.putResult(finderPath, finderArgs, list);
231 }
232 catch (Exception e) {
233 FinderCacheUtil.removeResult(finderPath, finderArgs);
234
235 throw processException(e);
236 }
237 finally {
238 closeSession(session);
239 }
240 }
241
242 return list;
243 }
244
245
253 @Override
254 public UserGroupRole findByUserId_First(long userId,
255 OrderByComparator<UserGroupRole> orderByComparator)
256 throws NoSuchUserGroupRoleException {
257 UserGroupRole userGroupRole = fetchByUserId_First(userId,
258 orderByComparator);
259
260 if (userGroupRole != null) {
261 return userGroupRole;
262 }
263
264 StringBundler msg = new StringBundler(4);
265
266 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
267
268 msg.append("userId=");
269 msg.append(userId);
270
271 msg.append(StringPool.CLOSE_CURLY_BRACE);
272
273 throw new NoSuchUserGroupRoleException(msg.toString());
274 }
275
276
283 @Override
284 public UserGroupRole fetchByUserId_First(long userId,
285 OrderByComparator<UserGroupRole> orderByComparator) {
286 List<UserGroupRole> list = findByUserId(userId, 0, 1, orderByComparator);
287
288 if (!list.isEmpty()) {
289 return list.get(0);
290 }
291
292 return null;
293 }
294
295
303 @Override
304 public UserGroupRole findByUserId_Last(long userId,
305 OrderByComparator<UserGroupRole> orderByComparator)
306 throws NoSuchUserGroupRoleException {
307 UserGroupRole userGroupRole = fetchByUserId_Last(userId,
308 orderByComparator);
309
310 if (userGroupRole != null) {
311 return userGroupRole;
312 }
313
314 StringBundler msg = new StringBundler(4);
315
316 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
317
318 msg.append("userId=");
319 msg.append(userId);
320
321 msg.append(StringPool.CLOSE_CURLY_BRACE);
322
323 throw new NoSuchUserGroupRoleException(msg.toString());
324 }
325
326
333 @Override
334 public UserGroupRole fetchByUserId_Last(long userId,
335 OrderByComparator<UserGroupRole> orderByComparator) {
336 int count = countByUserId(userId);
337
338 if (count == 0) {
339 return null;
340 }
341
342 List<UserGroupRole> list = findByUserId(userId, count - 1, count,
343 orderByComparator);
344
345 if (!list.isEmpty()) {
346 return list.get(0);
347 }
348
349 return null;
350 }
351
352
361 @Override
362 public UserGroupRole[] findByUserId_PrevAndNext(
363 UserGroupRolePK userGroupRolePK, long userId,
364 OrderByComparator<UserGroupRole> orderByComparator)
365 throws NoSuchUserGroupRoleException {
366 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
367
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 UserGroupRole[] array = new UserGroupRoleImpl[3];
374
375 array[0] = getByUserId_PrevAndNext(session, userGroupRole, userId,
376 orderByComparator, true);
377
378 array[1] = userGroupRole;
379
380 array[2] = getByUserId_PrevAndNext(session, userGroupRole, userId,
381 orderByComparator, false);
382
383 return array;
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392
393 protected UserGroupRole getByUserId_PrevAndNext(Session session,
394 UserGroupRole userGroupRole, long userId,
395 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
396 StringBundler query = null;
397
398 if (orderByComparator != null) {
399 query = new StringBundler(6 +
400 (orderByComparator.getOrderByFields().length * 6));
401 }
402 else {
403 query = new StringBundler(3);
404 }
405
406 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
407
408 query.append(_FINDER_COLUMN_USERID_USERID_2);
409
410 if (orderByComparator != null) {
411 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
412
413 if (orderByConditionFields.length > 0) {
414 query.append(WHERE_AND);
415 }
416
417 for (int i = 0; i < orderByConditionFields.length; i++) {
418 query.append(_ORDER_BY_ENTITY_ALIAS);
419 query.append(orderByConditionFields[i]);
420
421 if ((i + 1) < orderByConditionFields.length) {
422 if (orderByComparator.isAscending() ^ previous) {
423 query.append(WHERE_GREATER_THAN_HAS_NEXT);
424 }
425 else {
426 query.append(WHERE_LESSER_THAN_HAS_NEXT);
427 }
428 }
429 else {
430 if (orderByComparator.isAscending() ^ previous) {
431 query.append(WHERE_GREATER_THAN);
432 }
433 else {
434 query.append(WHERE_LESSER_THAN);
435 }
436 }
437 }
438
439 query.append(ORDER_BY_CLAUSE);
440
441 String[] orderByFields = orderByComparator.getOrderByFields();
442
443 for (int i = 0; i < orderByFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByFields[i]);
446
447 if ((i + 1) < orderByFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(ORDER_BY_ASC_HAS_NEXT);
450 }
451 else {
452 query.append(ORDER_BY_DESC_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(ORDER_BY_ASC);
458 }
459 else {
460 query.append(ORDER_BY_DESC);
461 }
462 }
463 }
464 }
465 else {
466 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
467 }
468
469 String sql = query.toString();
470
471 Query q = session.createQuery(sql);
472
473 q.setFirstResult(0);
474 q.setMaxResults(2);
475
476 QueryPos qPos = QueryPos.getInstance(q);
477
478 qPos.add(userId);
479
480 if (orderByComparator != null) {
481 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
482
483 for (Object value : values) {
484 qPos.add(value);
485 }
486 }
487
488 List<UserGroupRole> list = q.list();
489
490 if (list.size() == 2) {
491 return list.get(1);
492 }
493 else {
494 return null;
495 }
496 }
497
498
503 @Override
504 public void removeByUserId(long userId) {
505 for (UserGroupRole userGroupRole : findByUserId(userId,
506 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
507 remove(userGroupRole);
508 }
509 }
510
511
517 @Override
518 public int countByUserId(long userId) {
519 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
520
521 Object[] finderArgs = new Object[] { userId };
522
523 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
524 this);
525
526 if (count == null) {
527 StringBundler query = new StringBundler(2);
528
529 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
530
531 query.append(_FINDER_COLUMN_USERID_USERID_2);
532
533 String sql = query.toString();
534
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 Query q = session.createQuery(sql);
541
542 QueryPos qPos = QueryPos.getInstance(q);
543
544 qPos.add(userId);
545
546 count = (Long)q.uniqueResult();
547
548 FinderCacheUtil.putResult(finderPath, finderArgs, count);
549 }
550 catch (Exception e) {
551 FinderCacheUtil.removeResult(finderPath, finderArgs);
552
553 throw processException(e);
554 }
555 finally {
556 closeSession(session);
557 }
558 }
559
560 return count.intValue();
561 }
562
563 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userGroupRole.id.userId = ?";
564 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
565 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
566 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
567 "findByGroupId",
568 new String[] {
569 Long.class.getName(),
570
571 Integer.class.getName(), Integer.class.getName(),
572 OrderByComparator.class.getName()
573 });
574 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
575 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
576 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
577 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
578 "findByGroupId", new String[] { Long.class.getName() },
579 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
580 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
581 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
582 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
583 new String[] { Long.class.getName() });
584
585
591 @Override
592 public List<UserGroupRole> findByGroupId(long groupId) {
593 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
594 }
595
596
608 @Override
609 public List<UserGroupRole> findByGroupId(long groupId, int start, int end) {
610 return findByGroupId(groupId, start, end, null);
611 }
612
613
626 @Override
627 public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
628 OrderByComparator<UserGroupRole> orderByComparator) {
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 = Collections.unmodifiableList(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
732 @Override
733 public UserGroupRole findByGroupId_First(long groupId,
734 OrderByComparator<UserGroupRole> orderByComparator)
735 throws NoSuchUserGroupRoleException {
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
762 @Override
763 public UserGroupRole fetchByGroupId_First(long groupId,
764 OrderByComparator<UserGroupRole> orderByComparator) {
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
783 @Override
784 public UserGroupRole findByGroupId_Last(long groupId,
785 OrderByComparator<UserGroupRole> orderByComparator)
786 throws NoSuchUserGroupRoleException {
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
813 @Override
814 public UserGroupRole fetchByGroupId_Last(long groupId,
815 OrderByComparator<UserGroupRole> orderByComparator) {
816 int count = countByGroupId(groupId);
817
818 if (count == 0) {
819 return null;
820 }
821
822 List<UserGroupRole> list = findByGroupId(groupId, count - 1, count,
823 orderByComparator);
824
825 if (!list.isEmpty()) {
826 return list.get(0);
827 }
828
829 return null;
830 }
831
832
841 @Override
842 public UserGroupRole[] findByGroupId_PrevAndNext(
843 UserGroupRolePK userGroupRolePK, long groupId,
844 OrderByComparator<UserGroupRole> orderByComparator)
845 throws NoSuchUserGroupRoleException {
846 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
847
848 Session session = null;
849
850 try {
851 session = openSession();
852
853 UserGroupRole[] array = new UserGroupRoleImpl[3];
854
855 array[0] = getByGroupId_PrevAndNext(session, userGroupRole,
856 groupId, orderByComparator, true);
857
858 array[1] = userGroupRole;
859
860 array[2] = getByGroupId_PrevAndNext(session, userGroupRole,
861 groupId, orderByComparator, false);
862
863 return array;
864 }
865 catch (Exception e) {
866 throw processException(e);
867 }
868 finally {
869 closeSession(session);
870 }
871 }
872
873 protected UserGroupRole getByGroupId_PrevAndNext(Session session,
874 UserGroupRole userGroupRole, long groupId,
875 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
876 StringBundler query = null;
877
878 if (orderByComparator != null) {
879 query = new StringBundler(6 +
880 (orderByComparator.getOrderByFields().length * 6));
881 }
882 else {
883 query = new StringBundler(3);
884 }
885
886 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
887
888 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
889
890 if (orderByComparator != null) {
891 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
892
893 if (orderByConditionFields.length > 0) {
894 query.append(WHERE_AND);
895 }
896
897 for (int i = 0; i < orderByConditionFields.length; i++) {
898 query.append(_ORDER_BY_ENTITY_ALIAS);
899 query.append(orderByConditionFields[i]);
900
901 if ((i + 1) < orderByConditionFields.length) {
902 if (orderByComparator.isAscending() ^ previous) {
903 query.append(WHERE_GREATER_THAN_HAS_NEXT);
904 }
905 else {
906 query.append(WHERE_LESSER_THAN_HAS_NEXT);
907 }
908 }
909 else {
910 if (orderByComparator.isAscending() ^ previous) {
911 query.append(WHERE_GREATER_THAN);
912 }
913 else {
914 query.append(WHERE_LESSER_THAN);
915 }
916 }
917 }
918
919 query.append(ORDER_BY_CLAUSE);
920
921 String[] orderByFields = orderByComparator.getOrderByFields();
922
923 for (int i = 0; i < orderByFields.length; i++) {
924 query.append(_ORDER_BY_ENTITY_ALIAS);
925 query.append(orderByFields[i]);
926
927 if ((i + 1) < orderByFields.length) {
928 if (orderByComparator.isAscending() ^ previous) {
929 query.append(ORDER_BY_ASC_HAS_NEXT);
930 }
931 else {
932 query.append(ORDER_BY_DESC_HAS_NEXT);
933 }
934 }
935 else {
936 if (orderByComparator.isAscending() ^ previous) {
937 query.append(ORDER_BY_ASC);
938 }
939 else {
940 query.append(ORDER_BY_DESC);
941 }
942 }
943 }
944 }
945 else {
946 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
947 }
948
949 String sql = query.toString();
950
951 Query q = session.createQuery(sql);
952
953 q.setFirstResult(0);
954 q.setMaxResults(2);
955
956 QueryPos qPos = QueryPos.getInstance(q);
957
958 qPos.add(groupId);
959
960 if (orderByComparator != null) {
961 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
962
963 for (Object value : values) {
964 qPos.add(value);
965 }
966 }
967
968 List<UserGroupRole> list = q.list();
969
970 if (list.size() == 2) {
971 return list.get(1);
972 }
973 else {
974 return null;
975 }
976 }
977
978
983 @Override
984 public void removeByGroupId(long groupId) {
985 for (UserGroupRole userGroupRole : findByGroupId(groupId,
986 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
987 remove(userGroupRole);
988 }
989 }
990
991
997 @Override
998 public int countByGroupId(long groupId) {
999 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1000
1001 Object[] finderArgs = new Object[] { groupId };
1002
1003 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1004 this);
1005
1006 if (count == null) {
1007 StringBundler query = new StringBundler(2);
1008
1009 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1010
1011 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1012
1013 String sql = query.toString();
1014
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 Query q = session.createQuery(sql);
1021
1022 QueryPos qPos = QueryPos.getInstance(q);
1023
1024 qPos.add(groupId);
1025
1026 count = (Long)q.uniqueResult();
1027
1028 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1029 }
1030 catch (Exception e) {
1031 FinderCacheUtil.removeResult(finderPath, finderArgs);
1032
1033 throw processException(e);
1034 }
1035 finally {
1036 closeSession(session);
1037 }
1038 }
1039
1040 return count.intValue();
1041 }
1042
1043 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "userGroupRole.id.groupId = ?";
1044 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1045 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1046 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1047 "findByRoleId",
1048 new String[] {
1049 Long.class.getName(),
1050
1051 Integer.class.getName(), Integer.class.getName(),
1052 OrderByComparator.class.getName()
1053 });
1054 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
1055 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1056 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1057 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1058 "findByRoleId", new String[] { Long.class.getName() },
1059 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
1060 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1061 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1062 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
1063 new String[] { Long.class.getName() });
1064
1065
1071 @Override
1072 public List<UserGroupRole> findByRoleId(long roleId) {
1073 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1074 }
1075
1076
1088 @Override
1089 public List<UserGroupRole> findByRoleId(long roleId, int start, int end) {
1090 return findByRoleId(roleId, start, end, null);
1091 }
1092
1093
1106 @Override
1107 public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
1108 OrderByComparator<UserGroupRole> orderByComparator) {
1109 boolean pagination = true;
1110 FinderPath finderPath = null;
1111 Object[] finderArgs = null;
1112
1113 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1114 (orderByComparator == null)) {
1115 pagination = false;
1116 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
1117 finderArgs = new Object[] { roleId };
1118 }
1119 else {
1120 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
1121 finderArgs = new Object[] { roleId, start, end, orderByComparator };
1122 }
1123
1124 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
1125 finderArgs, this);
1126
1127 if ((list != null) && !list.isEmpty()) {
1128 for (UserGroupRole userGroupRole : list) {
1129 if ((roleId != userGroupRole.getRoleId())) {
1130 list = null;
1131
1132 break;
1133 }
1134 }
1135 }
1136
1137 if (list == null) {
1138 StringBundler query = null;
1139
1140 if (orderByComparator != null) {
1141 query = new StringBundler(3 +
1142 (orderByComparator.getOrderByFields().length * 3));
1143 }
1144 else {
1145 query = new StringBundler(3);
1146 }
1147
1148 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1149
1150 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1151
1152 if (orderByComparator != null) {
1153 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1154 orderByComparator);
1155 }
1156 else
1157 if (pagination) {
1158 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1159 }
1160
1161 String sql = query.toString();
1162
1163 Session session = null;
1164
1165 try {
1166 session = openSession();
1167
1168 Query q = session.createQuery(sql);
1169
1170 QueryPos qPos = QueryPos.getInstance(q);
1171
1172 qPos.add(roleId);
1173
1174 if (!pagination) {
1175 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1176 start, end, false);
1177
1178 Collections.sort(list);
1179
1180 list = Collections.unmodifiableList(list);
1181 }
1182 else {
1183 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1184 start, end);
1185 }
1186
1187 cacheResult(list);
1188
1189 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1190 }
1191 catch (Exception e) {
1192 FinderCacheUtil.removeResult(finderPath, finderArgs);
1193
1194 throw processException(e);
1195 }
1196 finally {
1197 closeSession(session);
1198 }
1199 }
1200
1201 return list;
1202 }
1203
1204
1212 @Override
1213 public UserGroupRole findByRoleId_First(long roleId,
1214 OrderByComparator<UserGroupRole> orderByComparator)
1215 throws NoSuchUserGroupRoleException {
1216 UserGroupRole userGroupRole = fetchByRoleId_First(roleId,
1217 orderByComparator);
1218
1219 if (userGroupRole != null) {
1220 return userGroupRole;
1221 }
1222
1223 StringBundler msg = new StringBundler(4);
1224
1225 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1226
1227 msg.append("roleId=");
1228 msg.append(roleId);
1229
1230 msg.append(StringPool.CLOSE_CURLY_BRACE);
1231
1232 throw new NoSuchUserGroupRoleException(msg.toString());
1233 }
1234
1235
1242 @Override
1243 public UserGroupRole fetchByRoleId_First(long roleId,
1244 OrderByComparator<UserGroupRole> orderByComparator) {
1245 List<UserGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1246
1247 if (!list.isEmpty()) {
1248 return list.get(0);
1249 }
1250
1251 return null;
1252 }
1253
1254
1262 @Override
1263 public UserGroupRole findByRoleId_Last(long roleId,
1264 OrderByComparator<UserGroupRole> orderByComparator)
1265 throws NoSuchUserGroupRoleException {
1266 UserGroupRole userGroupRole = fetchByRoleId_Last(roleId,
1267 orderByComparator);
1268
1269 if (userGroupRole != null) {
1270 return userGroupRole;
1271 }
1272
1273 StringBundler msg = new StringBundler(4);
1274
1275 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1276
1277 msg.append("roleId=");
1278 msg.append(roleId);
1279
1280 msg.append(StringPool.CLOSE_CURLY_BRACE);
1281
1282 throw new NoSuchUserGroupRoleException(msg.toString());
1283 }
1284
1285
1292 @Override
1293 public UserGroupRole fetchByRoleId_Last(long roleId,
1294 OrderByComparator<UserGroupRole> orderByComparator) {
1295 int count = countByRoleId(roleId);
1296
1297 if (count == 0) {
1298 return null;
1299 }
1300
1301 List<UserGroupRole> list = findByRoleId(roleId, count - 1, count,
1302 orderByComparator);
1303
1304 if (!list.isEmpty()) {
1305 return list.get(0);
1306 }
1307
1308 return null;
1309 }
1310
1311
1320 @Override
1321 public UserGroupRole[] findByRoleId_PrevAndNext(
1322 UserGroupRolePK userGroupRolePK, long roleId,
1323 OrderByComparator<UserGroupRole> orderByComparator)
1324 throws NoSuchUserGroupRoleException {
1325 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1326
1327 Session session = null;
1328
1329 try {
1330 session = openSession();
1331
1332 UserGroupRole[] array = new UserGroupRoleImpl[3];
1333
1334 array[0] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1335 orderByComparator, true);
1336
1337 array[1] = userGroupRole;
1338
1339 array[2] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1340 orderByComparator, false);
1341
1342 return array;
1343 }
1344 catch (Exception e) {
1345 throw processException(e);
1346 }
1347 finally {
1348 closeSession(session);
1349 }
1350 }
1351
1352 protected UserGroupRole getByRoleId_PrevAndNext(Session session,
1353 UserGroupRole userGroupRole, long roleId,
1354 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
1355 StringBundler query = null;
1356
1357 if (orderByComparator != null) {
1358 query = new StringBundler(6 +
1359 (orderByComparator.getOrderByFields().length * 6));
1360 }
1361 else {
1362 query = new StringBundler(3);
1363 }
1364
1365 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1366
1367 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1368
1369 if (orderByComparator != null) {
1370 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1371
1372 if (orderByConditionFields.length > 0) {
1373 query.append(WHERE_AND);
1374 }
1375
1376 for (int i = 0; i < orderByConditionFields.length; i++) {
1377 query.append(_ORDER_BY_ENTITY_ALIAS);
1378 query.append(orderByConditionFields[i]);
1379
1380 if ((i + 1) < orderByConditionFields.length) {
1381 if (orderByComparator.isAscending() ^ previous) {
1382 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1383 }
1384 else {
1385 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1386 }
1387 }
1388 else {
1389 if (orderByComparator.isAscending() ^ previous) {
1390 query.append(WHERE_GREATER_THAN);
1391 }
1392 else {
1393 query.append(WHERE_LESSER_THAN);
1394 }
1395 }
1396 }
1397
1398 query.append(ORDER_BY_CLAUSE);
1399
1400 String[] orderByFields = orderByComparator.getOrderByFields();
1401
1402 for (int i = 0; i < orderByFields.length; i++) {
1403 query.append(_ORDER_BY_ENTITY_ALIAS);
1404 query.append(orderByFields[i]);
1405
1406 if ((i + 1) < orderByFields.length) {
1407 if (orderByComparator.isAscending() ^ previous) {
1408 query.append(ORDER_BY_ASC_HAS_NEXT);
1409 }
1410 else {
1411 query.append(ORDER_BY_DESC_HAS_NEXT);
1412 }
1413 }
1414 else {
1415 if (orderByComparator.isAscending() ^ previous) {
1416 query.append(ORDER_BY_ASC);
1417 }
1418 else {
1419 query.append(ORDER_BY_DESC);
1420 }
1421 }
1422 }
1423 }
1424 else {
1425 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1426 }
1427
1428 String sql = query.toString();
1429
1430 Query q = session.createQuery(sql);
1431
1432 q.setFirstResult(0);
1433 q.setMaxResults(2);
1434
1435 QueryPos qPos = QueryPos.getInstance(q);
1436
1437 qPos.add(roleId);
1438
1439 if (orderByComparator != null) {
1440 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1441
1442 for (Object value : values) {
1443 qPos.add(value);
1444 }
1445 }
1446
1447 List<UserGroupRole> list = q.list();
1448
1449 if (list.size() == 2) {
1450 return list.get(1);
1451 }
1452 else {
1453 return null;
1454 }
1455 }
1456
1457
1462 @Override
1463 public void removeByRoleId(long roleId) {
1464 for (UserGroupRole userGroupRole : findByRoleId(roleId,
1465 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1466 remove(userGroupRole);
1467 }
1468 }
1469
1470
1476 @Override
1477 public int countByRoleId(long roleId) {
1478 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1479
1480 Object[] finderArgs = new Object[] { roleId };
1481
1482 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1483 this);
1484
1485 if (count == null) {
1486 StringBundler query = new StringBundler(2);
1487
1488 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1489
1490 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1491
1492 String sql = query.toString();
1493
1494 Session session = null;
1495
1496 try {
1497 session = openSession();
1498
1499 Query q = session.createQuery(sql);
1500
1501 QueryPos qPos = QueryPos.getInstance(q);
1502
1503 qPos.add(roleId);
1504
1505 count = (Long)q.uniqueResult();
1506
1507 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1508 }
1509 catch (Exception e) {
1510 FinderCacheUtil.removeResult(finderPath, finderArgs);
1511
1512 throw processException(e);
1513 }
1514 finally {
1515 closeSession(session);
1516 }
1517 }
1518
1519 return count.intValue();
1520 }
1521
1522 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "userGroupRole.id.roleId = ?";
1523 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1524 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1525 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1526 "findByU_G",
1527 new String[] {
1528 Long.class.getName(), Long.class.getName(),
1529
1530 Integer.class.getName(), Integer.class.getName(),
1531 OrderByComparator.class.getName()
1532 });
1533 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1534 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1535 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1536 "findByU_G",
1537 new String[] { Long.class.getName(), Long.class.getName() },
1538 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK |
1539 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
1540 public static final FinderPath FINDER_PATH_COUNT_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1541 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1542 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_G",
1543 new String[] { Long.class.getName(), Long.class.getName() });
1544
1545
1552 @Override
1553 public List<UserGroupRole> findByU_G(long userId, long groupId) {
1554 return findByU_G(userId, groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1555 null);
1556 }
1557
1558
1571 @Override
1572 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1573 int end) {
1574 return findByU_G(userId, groupId, start, end, null);
1575 }
1576
1577
1591 @Override
1592 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1593 int end, OrderByComparator<UserGroupRole> orderByComparator) {
1594 boolean pagination = true;
1595 FinderPath finderPath = null;
1596 Object[] finderArgs = null;
1597
1598 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1599 (orderByComparator == null)) {
1600 pagination = false;
1601 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G;
1602 finderArgs = new Object[] { userId, groupId };
1603 }
1604 else {
1605 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G;
1606 finderArgs = new Object[] {
1607 userId, groupId,
1608
1609 start, end, orderByComparator
1610 };
1611 }
1612
1613 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
1614 finderArgs, this);
1615
1616 if ((list != null) && !list.isEmpty()) {
1617 for (UserGroupRole userGroupRole : list) {
1618 if ((userId != userGroupRole.getUserId()) ||
1619 (groupId != userGroupRole.getGroupId())) {
1620 list = null;
1621
1622 break;
1623 }
1624 }
1625 }
1626
1627 if (list == null) {
1628 StringBundler query = null;
1629
1630 if (orderByComparator != null) {
1631 query = new StringBundler(4 +
1632 (orderByComparator.getOrderByFields().length * 3));
1633 }
1634 else {
1635 query = new StringBundler(4);
1636 }
1637
1638 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1639
1640 query.append(_FINDER_COLUMN_U_G_USERID_2);
1641
1642 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1643
1644 if (orderByComparator != null) {
1645 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1646 orderByComparator);
1647 }
1648 else
1649 if (pagination) {
1650 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1651 }
1652
1653 String sql = query.toString();
1654
1655 Session session = null;
1656
1657 try {
1658 session = openSession();
1659
1660 Query q = session.createQuery(sql);
1661
1662 QueryPos qPos = QueryPos.getInstance(q);
1663
1664 qPos.add(userId);
1665
1666 qPos.add(groupId);
1667
1668 if (!pagination) {
1669 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1670 start, end, false);
1671
1672 Collections.sort(list);
1673
1674 list = Collections.unmodifiableList(list);
1675 }
1676 else {
1677 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1678 start, end);
1679 }
1680
1681 cacheResult(list);
1682
1683 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1684 }
1685 catch (Exception e) {
1686 FinderCacheUtil.removeResult(finderPath, finderArgs);
1687
1688 throw processException(e);
1689 }
1690 finally {
1691 closeSession(session);
1692 }
1693 }
1694
1695 return list;
1696 }
1697
1698
1707 @Override
1708 public UserGroupRole findByU_G_First(long userId, long groupId,
1709 OrderByComparator<UserGroupRole> orderByComparator)
1710 throws NoSuchUserGroupRoleException {
1711 UserGroupRole userGroupRole = fetchByU_G_First(userId, groupId,
1712 orderByComparator);
1713
1714 if (userGroupRole != null) {
1715 return userGroupRole;
1716 }
1717
1718 StringBundler msg = new StringBundler(6);
1719
1720 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1721
1722 msg.append("userId=");
1723 msg.append(userId);
1724
1725 msg.append(", groupId=");
1726 msg.append(groupId);
1727
1728 msg.append(StringPool.CLOSE_CURLY_BRACE);
1729
1730 throw new NoSuchUserGroupRoleException(msg.toString());
1731 }
1732
1733
1741 @Override
1742 public UserGroupRole fetchByU_G_First(long userId, long groupId,
1743 OrderByComparator<UserGroupRole> orderByComparator) {
1744 List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1,
1745 orderByComparator);
1746
1747 if (!list.isEmpty()) {
1748 return list.get(0);
1749 }
1750
1751 return null;
1752 }
1753
1754
1763 @Override
1764 public UserGroupRole findByU_G_Last(long userId, long groupId,
1765 OrderByComparator<UserGroupRole> orderByComparator)
1766 throws NoSuchUserGroupRoleException {
1767 UserGroupRole userGroupRole = fetchByU_G_Last(userId, groupId,
1768 orderByComparator);
1769
1770 if (userGroupRole != null) {
1771 return userGroupRole;
1772 }
1773
1774 StringBundler msg = new StringBundler(6);
1775
1776 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1777
1778 msg.append("userId=");
1779 msg.append(userId);
1780
1781 msg.append(", groupId=");
1782 msg.append(groupId);
1783
1784 msg.append(StringPool.CLOSE_CURLY_BRACE);
1785
1786 throw new NoSuchUserGroupRoleException(msg.toString());
1787 }
1788
1789
1797 @Override
1798 public UserGroupRole fetchByU_G_Last(long userId, long groupId,
1799 OrderByComparator<UserGroupRole> orderByComparator) {
1800 int count = countByU_G(userId, groupId);
1801
1802 if (count == 0) {
1803 return null;
1804 }
1805
1806 List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1807 orderByComparator);
1808
1809 if (!list.isEmpty()) {
1810 return list.get(0);
1811 }
1812
1813 return null;
1814 }
1815
1816
1826 @Override
1827 public UserGroupRole[] findByU_G_PrevAndNext(
1828 UserGroupRolePK userGroupRolePK, long userId, long groupId,
1829 OrderByComparator<UserGroupRole> orderByComparator)
1830 throws NoSuchUserGroupRoleException {
1831 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1832
1833 Session session = null;
1834
1835 try {
1836 session = openSession();
1837
1838 UserGroupRole[] array = new UserGroupRoleImpl[3];
1839
1840 array[0] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1841 groupId, orderByComparator, true);
1842
1843 array[1] = userGroupRole;
1844
1845 array[2] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1846 groupId, orderByComparator, false);
1847
1848 return array;
1849 }
1850 catch (Exception e) {
1851 throw processException(e);
1852 }
1853 finally {
1854 closeSession(session);
1855 }
1856 }
1857
1858 protected UserGroupRole getByU_G_PrevAndNext(Session session,
1859 UserGroupRole userGroupRole, long userId, long groupId,
1860 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
1861 StringBundler query = null;
1862
1863 if (orderByComparator != null) {
1864 query = new StringBundler(6 +
1865 (orderByComparator.getOrderByFields().length * 6));
1866 }
1867 else {
1868 query = new StringBundler(3);
1869 }
1870
1871 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1872
1873 query.append(_FINDER_COLUMN_U_G_USERID_2);
1874
1875 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1876
1877 if (orderByComparator != null) {
1878 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1879
1880 if (orderByConditionFields.length > 0) {
1881 query.append(WHERE_AND);
1882 }
1883
1884 for (int i = 0; i < orderByConditionFields.length; i++) {
1885 query.append(_ORDER_BY_ENTITY_ALIAS);
1886 query.append(orderByConditionFields[i]);
1887
1888 if ((i + 1) < orderByConditionFields.length) {
1889 if (orderByComparator.isAscending() ^ previous) {
1890 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1891 }
1892 else {
1893 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1894 }
1895 }
1896 else {
1897 if (orderByComparator.isAscending() ^ previous) {
1898 query.append(WHERE_GREATER_THAN);
1899 }
1900 else {
1901 query.append(WHERE_LESSER_THAN);
1902 }
1903 }
1904 }
1905
1906 query.append(ORDER_BY_CLAUSE);
1907
1908 String[] orderByFields = orderByComparator.getOrderByFields();
1909
1910 for (int i = 0; i < orderByFields.length; i++) {
1911 query.append(_ORDER_BY_ENTITY_ALIAS);
1912 query.append(orderByFields[i]);
1913
1914 if ((i + 1) < orderByFields.length) {
1915 if (orderByComparator.isAscending() ^ previous) {
1916 query.append(ORDER_BY_ASC_HAS_NEXT);
1917 }
1918 else {
1919 query.append(ORDER_BY_DESC_HAS_NEXT);
1920 }
1921 }
1922 else {
1923 if (orderByComparator.isAscending() ^ previous) {
1924 query.append(ORDER_BY_ASC);
1925 }
1926 else {
1927 query.append(ORDER_BY_DESC);
1928 }
1929 }
1930 }
1931 }
1932 else {
1933 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1934 }
1935
1936 String sql = query.toString();
1937
1938 Query q = session.createQuery(sql);
1939
1940 q.setFirstResult(0);
1941 q.setMaxResults(2);
1942
1943 QueryPos qPos = QueryPos.getInstance(q);
1944
1945 qPos.add(userId);
1946
1947 qPos.add(groupId);
1948
1949 if (orderByComparator != null) {
1950 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1951
1952 for (Object value : values) {
1953 qPos.add(value);
1954 }
1955 }
1956
1957 List<UserGroupRole> list = q.list();
1958
1959 if (list.size() == 2) {
1960 return list.get(1);
1961 }
1962 else {
1963 return null;
1964 }
1965 }
1966
1967
1973 @Override
1974 public void removeByU_G(long userId, long groupId) {
1975 for (UserGroupRole userGroupRole : findByU_G(userId, groupId,
1976 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1977 remove(userGroupRole);
1978 }
1979 }
1980
1981
1988 @Override
1989 public int countByU_G(long userId, long groupId) {
1990 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_G;
1991
1992 Object[] finderArgs = new Object[] { userId, groupId };
1993
1994 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1995 this);
1996
1997 if (count == null) {
1998 StringBundler query = new StringBundler(3);
1999
2000 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2001
2002 query.append(_FINDER_COLUMN_U_G_USERID_2);
2003
2004 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
2005
2006 String sql = query.toString();
2007
2008 Session session = null;
2009
2010 try {
2011 session = openSession();
2012
2013 Query q = session.createQuery(sql);
2014
2015 QueryPos qPos = QueryPos.getInstance(q);
2016
2017 qPos.add(userId);
2018
2019 qPos.add(groupId);
2020
2021 count = (Long)q.uniqueResult();
2022
2023 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2024 }
2025 catch (Exception e) {
2026 FinderCacheUtil.removeResult(finderPath, finderArgs);
2027
2028 throw processException(e);
2029 }
2030 finally {
2031 closeSession(session);
2032 }
2033 }
2034
2035 return count.intValue();
2036 }
2037
2038 private static final String _FINDER_COLUMN_U_G_USERID_2 = "userGroupRole.id.userId = ? AND ";
2039 private static final String _FINDER_COLUMN_U_G_GROUPID_2 = "userGroupRole.id.groupId = ?";
2040 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2041 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2042 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2043 "findByG_R",
2044 new String[] {
2045 Long.class.getName(), Long.class.getName(),
2046
2047 Integer.class.getName(), Integer.class.getName(),
2048 OrderByComparator.class.getName()
2049 });
2050 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2051 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2052 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2053 "findByG_R",
2054 new String[] { Long.class.getName(), Long.class.getName() },
2055 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK |
2056 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
2057 public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2058 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2059 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_R",
2060 new String[] { Long.class.getName(), Long.class.getName() });
2061
2062
2069 @Override
2070 public List<UserGroupRole> findByG_R(long groupId, long roleId) {
2071 return findByG_R(groupId, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2072 null);
2073 }
2074
2075
2088 @Override
2089 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2090 int end) {
2091 return findByG_R(groupId, roleId, start, end, null);
2092 }
2093
2094
2108 @Override
2109 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2110 int end, OrderByComparator<UserGroupRole> orderByComparator) {
2111 boolean pagination = true;
2112 FinderPath finderPath = null;
2113 Object[] finderArgs = null;
2114
2115 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2116 (orderByComparator == null)) {
2117 pagination = false;
2118 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R;
2119 finderArgs = new Object[] { groupId, roleId };
2120 }
2121 else {
2122 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R;
2123 finderArgs = new Object[] {
2124 groupId, roleId,
2125
2126 start, end, orderByComparator
2127 };
2128 }
2129
2130 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
2131 finderArgs, this);
2132
2133 if ((list != null) && !list.isEmpty()) {
2134 for (UserGroupRole userGroupRole : list) {
2135 if ((groupId != userGroupRole.getGroupId()) ||
2136 (roleId != userGroupRole.getRoleId())) {
2137 list = null;
2138
2139 break;
2140 }
2141 }
2142 }
2143
2144 if (list == null) {
2145 StringBundler query = null;
2146
2147 if (orderByComparator != null) {
2148 query = new StringBundler(4 +
2149 (orderByComparator.getOrderByFields().length * 3));
2150 }
2151 else {
2152 query = new StringBundler(4);
2153 }
2154
2155 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2156
2157 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2158
2159 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2160
2161 if (orderByComparator != null) {
2162 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2163 orderByComparator);
2164 }
2165 else
2166 if (pagination) {
2167 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2168 }
2169
2170 String sql = query.toString();
2171
2172 Session session = null;
2173
2174 try {
2175 session = openSession();
2176
2177 Query q = session.createQuery(sql);
2178
2179 QueryPos qPos = QueryPos.getInstance(q);
2180
2181 qPos.add(groupId);
2182
2183 qPos.add(roleId);
2184
2185 if (!pagination) {
2186 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2187 start, end, false);
2188
2189 Collections.sort(list);
2190
2191 list = Collections.unmodifiableList(list);
2192 }
2193 else {
2194 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2195 start, end);
2196 }
2197
2198 cacheResult(list);
2199
2200 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2201 }
2202 catch (Exception e) {
2203 FinderCacheUtil.removeResult(finderPath, finderArgs);
2204
2205 throw processException(e);
2206 }
2207 finally {
2208 closeSession(session);
2209 }
2210 }
2211
2212 return list;
2213 }
2214
2215
2224 @Override
2225 public UserGroupRole findByG_R_First(long groupId, long roleId,
2226 OrderByComparator<UserGroupRole> orderByComparator)
2227 throws NoSuchUserGroupRoleException {
2228 UserGroupRole userGroupRole = fetchByG_R_First(groupId, roleId,
2229 orderByComparator);
2230
2231 if (userGroupRole != null) {
2232 return userGroupRole;
2233 }
2234
2235 StringBundler msg = new StringBundler(6);
2236
2237 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2238
2239 msg.append("groupId=");
2240 msg.append(groupId);
2241
2242 msg.append(", roleId=");
2243 msg.append(roleId);
2244
2245 msg.append(StringPool.CLOSE_CURLY_BRACE);
2246
2247 throw new NoSuchUserGroupRoleException(msg.toString());
2248 }
2249
2250
2258 @Override
2259 public UserGroupRole fetchByG_R_First(long groupId, long roleId,
2260 OrderByComparator<UserGroupRole> orderByComparator) {
2261 List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1,
2262 orderByComparator);
2263
2264 if (!list.isEmpty()) {
2265 return list.get(0);
2266 }
2267
2268 return null;
2269 }
2270
2271
2280 @Override
2281 public UserGroupRole findByG_R_Last(long groupId, long roleId,
2282 OrderByComparator<UserGroupRole> orderByComparator)
2283 throws NoSuchUserGroupRoleException {
2284 UserGroupRole userGroupRole = fetchByG_R_Last(groupId, roleId,
2285 orderByComparator);
2286
2287 if (userGroupRole != null) {
2288 return userGroupRole;
2289 }
2290
2291 StringBundler msg = new StringBundler(6);
2292
2293 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2294
2295 msg.append("groupId=");
2296 msg.append(groupId);
2297
2298 msg.append(", roleId=");
2299 msg.append(roleId);
2300
2301 msg.append(StringPool.CLOSE_CURLY_BRACE);
2302
2303 throw new NoSuchUserGroupRoleException(msg.toString());
2304 }
2305
2306
2314 @Override
2315 public UserGroupRole fetchByG_R_Last(long groupId, long roleId,
2316 OrderByComparator<UserGroupRole> orderByComparator) {
2317 int count = countByG_R(groupId, roleId);
2318
2319 if (count == 0) {
2320 return null;
2321 }
2322
2323 List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
2324 orderByComparator);
2325
2326 if (!list.isEmpty()) {
2327 return list.get(0);
2328 }
2329
2330 return null;
2331 }
2332
2333
2343 @Override
2344 public UserGroupRole[] findByG_R_PrevAndNext(
2345 UserGroupRolePK userGroupRolePK, long groupId, long roleId,
2346 OrderByComparator<UserGroupRole> orderByComparator)
2347 throws NoSuchUserGroupRoleException {
2348 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
2349
2350 Session session = null;
2351
2352 try {
2353 session = openSession();
2354
2355 UserGroupRole[] array = new UserGroupRoleImpl[3];
2356
2357 array[0] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2358 roleId, orderByComparator, true);
2359
2360 array[1] = userGroupRole;
2361
2362 array[2] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2363 roleId, orderByComparator, false);
2364
2365 return array;
2366 }
2367 catch (Exception e) {
2368 throw processException(e);
2369 }
2370 finally {
2371 closeSession(session);
2372 }
2373 }
2374
2375 protected UserGroupRole getByG_R_PrevAndNext(Session session,
2376 UserGroupRole userGroupRole, long groupId, long roleId,
2377 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
2378 StringBundler query = null;
2379
2380 if (orderByComparator != null) {
2381 query = new StringBundler(6 +
2382 (orderByComparator.getOrderByFields().length * 6));
2383 }
2384 else {
2385 query = new StringBundler(3);
2386 }
2387
2388 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2389
2390 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2391
2392 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2393
2394 if (orderByComparator != null) {
2395 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2396
2397 if (orderByConditionFields.length > 0) {
2398 query.append(WHERE_AND);
2399 }
2400
2401 for (int i = 0; i < orderByConditionFields.length; i++) {
2402 query.append(_ORDER_BY_ENTITY_ALIAS);
2403 query.append(orderByConditionFields[i]);
2404
2405 if ((i + 1) < orderByConditionFields.length) {
2406 if (orderByComparator.isAscending() ^ previous) {
2407 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2408 }
2409 else {
2410 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2411 }
2412 }
2413 else {
2414 if (orderByComparator.isAscending() ^ previous) {
2415 query.append(WHERE_GREATER_THAN);
2416 }
2417 else {
2418 query.append(WHERE_LESSER_THAN);
2419 }
2420 }
2421 }
2422
2423 query.append(ORDER_BY_CLAUSE);
2424
2425 String[] orderByFields = orderByComparator.getOrderByFields();
2426
2427 for (int i = 0; i < orderByFields.length; i++) {
2428 query.append(_ORDER_BY_ENTITY_ALIAS);
2429 query.append(orderByFields[i]);
2430
2431 if ((i + 1) < orderByFields.length) {
2432 if (orderByComparator.isAscending() ^ previous) {
2433 query.append(ORDER_BY_ASC_HAS_NEXT);
2434 }
2435 else {
2436 query.append(ORDER_BY_DESC_HAS_NEXT);
2437 }
2438 }
2439 else {
2440 if (orderByComparator.isAscending() ^ previous) {
2441 query.append(ORDER_BY_ASC);
2442 }
2443 else {
2444 query.append(ORDER_BY_DESC);
2445 }
2446 }
2447 }
2448 }
2449 else {
2450 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2451 }
2452
2453 String sql = query.toString();
2454
2455 Query q = session.createQuery(sql);
2456
2457 q.setFirstResult(0);
2458 q.setMaxResults(2);
2459
2460 QueryPos qPos = QueryPos.getInstance(q);
2461
2462 qPos.add(groupId);
2463
2464 qPos.add(roleId);
2465
2466 if (orderByComparator != null) {
2467 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
2468
2469 for (Object value : values) {
2470 qPos.add(value);
2471 }
2472 }
2473
2474 List<UserGroupRole> list = q.list();
2475
2476 if (list.size() == 2) {
2477 return list.get(1);
2478 }
2479 else {
2480 return null;
2481 }
2482 }
2483
2484
2490 @Override
2491 public void removeByG_R(long groupId, long roleId) {
2492 for (UserGroupRole userGroupRole : findByG_R(groupId, roleId,
2493 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2494 remove(userGroupRole);
2495 }
2496 }
2497
2498
2505 @Override
2506 public int countByG_R(long groupId, long roleId) {
2507 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_R;
2508
2509 Object[] finderArgs = new Object[] { groupId, roleId };
2510
2511 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2512 this);
2513
2514 if (count == null) {
2515 StringBundler query = new StringBundler(3);
2516
2517 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2518
2519 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2520
2521 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2522
2523 String sql = query.toString();
2524
2525 Session session = null;
2526
2527 try {
2528 session = openSession();
2529
2530 Query q = session.createQuery(sql);
2531
2532 QueryPos qPos = QueryPos.getInstance(q);
2533
2534 qPos.add(groupId);
2535
2536 qPos.add(roleId);
2537
2538 count = (Long)q.uniqueResult();
2539
2540 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2541 }
2542 catch (Exception e) {
2543 FinderCacheUtil.removeResult(finderPath, finderArgs);
2544
2545 throw processException(e);
2546 }
2547 finally {
2548 closeSession(session);
2549 }
2550 }
2551
2552 return count.intValue();
2553 }
2554
2555 private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "userGroupRole.id.groupId = ? AND ";
2556 private static final String _FINDER_COLUMN_G_R_ROLEID_2 = "userGroupRole.id.roleId = ?";
2557
2558 public UserGroupRolePersistenceImpl() {
2559 setModelClass(UserGroupRole.class);
2560 }
2561
2562
2567 @Override
2568 public void cacheResult(UserGroupRole userGroupRole) {
2569 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2570 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2571 userGroupRole);
2572
2573 userGroupRole.resetOriginalValues();
2574 }
2575
2576
2581 @Override
2582 public void cacheResult(List<UserGroupRole> userGroupRoles) {
2583 for (UserGroupRole userGroupRole : userGroupRoles) {
2584 if (EntityCacheUtil.getResult(
2585 UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2586 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey()) == null) {
2587 cacheResult(userGroupRole);
2588 }
2589 else {
2590 userGroupRole.resetOriginalValues();
2591 }
2592 }
2593 }
2594
2595
2602 @Override
2603 public void clearCache() {
2604 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2605 CacheRegistryUtil.clear(UserGroupRoleImpl.class.getName());
2606 }
2607
2608 EntityCacheUtil.clearCache(UserGroupRoleImpl.class);
2609
2610 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2611 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2612 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2613 }
2614
2615
2622 @Override
2623 public void clearCache(UserGroupRole userGroupRole) {
2624 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2625 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2626
2627 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2628 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2629 }
2630
2631 @Override
2632 public void clearCache(List<UserGroupRole> userGroupRoles) {
2633 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2634 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2635
2636 for (UserGroupRole userGroupRole : userGroupRoles) {
2637 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2638 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2639 }
2640 }
2641
2642
2648 @Override
2649 public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
2650 UserGroupRole userGroupRole = new UserGroupRoleImpl();
2651
2652 userGroupRole.setNew(true);
2653 userGroupRole.setPrimaryKey(userGroupRolePK);
2654
2655 return userGroupRole;
2656 }
2657
2658
2665 @Override
2666 public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
2667 throws NoSuchUserGroupRoleException {
2668 return remove((Serializable)userGroupRolePK);
2669 }
2670
2671
2678 @Override
2679 public UserGroupRole remove(Serializable primaryKey)
2680 throws NoSuchUserGroupRoleException {
2681 Session session = null;
2682
2683 try {
2684 session = openSession();
2685
2686 UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2687 primaryKey);
2688
2689 if (userGroupRole == null) {
2690 if (_log.isWarnEnabled()) {
2691 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2692 }
2693
2694 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2695 primaryKey);
2696 }
2697
2698 return remove(userGroupRole);
2699 }
2700 catch (NoSuchUserGroupRoleException nsee) {
2701 throw nsee;
2702 }
2703 catch (Exception e) {
2704 throw processException(e);
2705 }
2706 finally {
2707 closeSession(session);
2708 }
2709 }
2710
2711 @Override
2712 protected UserGroupRole removeImpl(UserGroupRole userGroupRole) {
2713 userGroupRole = toUnwrappedModel(userGroupRole);
2714
2715 Session session = null;
2716
2717 try {
2718 session = openSession();
2719
2720 if (!session.contains(userGroupRole)) {
2721 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2722 userGroupRole.getPrimaryKeyObj());
2723 }
2724
2725 if (userGroupRole != null) {
2726 session.delete(userGroupRole);
2727 }
2728 }
2729 catch (Exception e) {
2730 throw processException(e);
2731 }
2732 finally {
2733 closeSession(session);
2734 }
2735
2736 if (userGroupRole != null) {
2737 clearCache(userGroupRole);
2738 }
2739
2740 return userGroupRole;
2741 }
2742
2743 @Override
2744 public UserGroupRole updateImpl(
2745 com.liferay.portal.model.UserGroupRole userGroupRole) {
2746 userGroupRole = toUnwrappedModel(userGroupRole);
2747
2748 boolean isNew = userGroupRole.isNew();
2749
2750 UserGroupRoleModelImpl userGroupRoleModelImpl = (UserGroupRoleModelImpl)userGroupRole;
2751
2752 Session session = null;
2753
2754 try {
2755 session = openSession();
2756
2757 if (userGroupRole.isNew()) {
2758 session.save(userGroupRole);
2759
2760 userGroupRole.setNew(false);
2761 }
2762 else {
2763 session.merge(userGroupRole);
2764 }
2765 }
2766 catch (Exception e) {
2767 throw processException(e);
2768 }
2769 finally {
2770 closeSession(session);
2771 }
2772
2773 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2774
2775 if (isNew || !UserGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
2776 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2777 }
2778
2779 else {
2780 if ((userGroupRoleModelImpl.getColumnBitmask() &
2781 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2782 Object[] args = new Object[] {
2783 userGroupRoleModelImpl.getOriginalUserId()
2784 };
2785
2786 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2787 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2788 args);
2789
2790 args = new Object[] { userGroupRoleModelImpl.getUserId() };
2791
2792 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2793 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2794 args);
2795 }
2796
2797 if ((userGroupRoleModelImpl.getColumnBitmask() &
2798 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2799 Object[] args = new Object[] {
2800 userGroupRoleModelImpl.getOriginalGroupId()
2801 };
2802
2803 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2804 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2805 args);
2806
2807 args = new Object[] { userGroupRoleModelImpl.getGroupId() };
2808
2809 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2810 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2811 args);
2812 }
2813
2814 if ((userGroupRoleModelImpl.getColumnBitmask() &
2815 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
2816 Object[] args = new Object[] {
2817 userGroupRoleModelImpl.getOriginalRoleId()
2818 };
2819
2820 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2821 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2822 args);
2823
2824 args = new Object[] { userGroupRoleModelImpl.getRoleId() };
2825
2826 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2827 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2828 args);
2829 }
2830
2831 if ((userGroupRoleModelImpl.getColumnBitmask() &
2832 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G.getColumnBitmask()) != 0) {
2833 Object[] args = new Object[] {
2834 userGroupRoleModelImpl.getOriginalUserId(),
2835 userGroupRoleModelImpl.getOriginalGroupId()
2836 };
2837
2838 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2839 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2840 args);
2841
2842 args = new Object[] {
2843 userGroupRoleModelImpl.getUserId(),
2844 userGroupRoleModelImpl.getGroupId()
2845 };
2846
2847 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2848 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2849 args);
2850 }
2851
2852 if ((userGroupRoleModelImpl.getColumnBitmask() &
2853 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R.getColumnBitmask()) != 0) {
2854 Object[] args = new Object[] {
2855 userGroupRoleModelImpl.getOriginalGroupId(),
2856 userGroupRoleModelImpl.getOriginalRoleId()
2857 };
2858
2859 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2860 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2861 args);
2862
2863 args = new Object[] {
2864 userGroupRoleModelImpl.getGroupId(),
2865 userGroupRoleModelImpl.getRoleId()
2866 };
2867
2868 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2869 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2870 args);
2871 }
2872 }
2873
2874 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2875 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2876 userGroupRole, false);
2877
2878 userGroupRole.resetOriginalValues();
2879
2880 return userGroupRole;
2881 }
2882
2883 protected UserGroupRole toUnwrappedModel(UserGroupRole userGroupRole) {
2884 if (userGroupRole instanceof UserGroupRoleImpl) {
2885 return userGroupRole;
2886 }
2887
2888 UserGroupRoleImpl userGroupRoleImpl = new UserGroupRoleImpl();
2889
2890 userGroupRoleImpl.setNew(userGroupRole.isNew());
2891 userGroupRoleImpl.setPrimaryKey(userGroupRole.getPrimaryKey());
2892
2893 userGroupRoleImpl.setMvccVersion(userGroupRole.getMvccVersion());
2894 userGroupRoleImpl.setUserId(userGroupRole.getUserId());
2895 userGroupRoleImpl.setGroupId(userGroupRole.getGroupId());
2896 userGroupRoleImpl.setRoleId(userGroupRole.getRoleId());
2897
2898 return userGroupRoleImpl;
2899 }
2900
2901
2908 @Override
2909 public UserGroupRole findByPrimaryKey(Serializable primaryKey)
2910 throws NoSuchUserGroupRoleException {
2911 UserGroupRole userGroupRole = fetchByPrimaryKey(primaryKey);
2912
2913 if (userGroupRole == null) {
2914 if (_log.isWarnEnabled()) {
2915 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2916 }
2917
2918 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2919 primaryKey);
2920 }
2921
2922 return userGroupRole;
2923 }
2924
2925
2932 @Override
2933 public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
2934 throws NoSuchUserGroupRoleException {
2935 return findByPrimaryKey((Serializable)userGroupRolePK);
2936 }
2937
2938
2944 @Override
2945 public UserGroupRole fetchByPrimaryKey(Serializable primaryKey) {
2946 UserGroupRole userGroupRole = (UserGroupRole)EntityCacheUtil.getResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2947 UserGroupRoleImpl.class, primaryKey);
2948
2949 if (userGroupRole == _nullUserGroupRole) {
2950 return null;
2951 }
2952
2953 if (userGroupRole == null) {
2954 Session session = null;
2955
2956 try {
2957 session = openSession();
2958
2959 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2960 primaryKey);
2961
2962 if (userGroupRole != null) {
2963 cacheResult(userGroupRole);
2964 }
2965 else {
2966 EntityCacheUtil.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2967 UserGroupRoleImpl.class, primaryKey, _nullUserGroupRole);
2968 }
2969 }
2970 catch (Exception e) {
2971 EntityCacheUtil.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2972 UserGroupRoleImpl.class, primaryKey);
2973
2974 throw processException(e);
2975 }
2976 finally {
2977 closeSession(session);
2978 }
2979 }
2980
2981 return userGroupRole;
2982 }
2983
2984
2990 @Override
2991 public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK) {
2992 return fetchByPrimaryKey((Serializable)userGroupRolePK);
2993 }
2994
2995 @Override
2996 public Map<Serializable, UserGroupRole> fetchByPrimaryKeys(
2997 Set<Serializable> primaryKeys) {
2998 if (primaryKeys.isEmpty()) {
2999 return Collections.emptyMap();
3000 }
3001
3002 Map<Serializable, UserGroupRole> map = new HashMap<Serializable, UserGroupRole>();
3003
3004 for (Serializable primaryKey : primaryKeys) {
3005 UserGroupRole userGroupRole = fetchByPrimaryKey(primaryKey);
3006
3007 if (userGroupRole != null) {
3008 map.put(primaryKey, userGroupRole);
3009 }
3010 }
3011
3012 return map;
3013 }
3014
3015
3020 @Override
3021 public List<UserGroupRole> findAll() {
3022 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3023 }
3024
3025
3036 @Override
3037 public List<UserGroupRole> findAll(int start, int end) {
3038 return findAll(start, end, null);
3039 }
3040
3041
3053 @Override
3054 public List<UserGroupRole> findAll(int start, int end,
3055 OrderByComparator<UserGroupRole> orderByComparator) {
3056 boolean pagination = true;
3057 FinderPath finderPath = null;
3058 Object[] finderArgs = null;
3059
3060 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3061 (orderByComparator == null)) {
3062 pagination = false;
3063 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3064 finderArgs = FINDER_ARGS_EMPTY;
3065 }
3066 else {
3067 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3068 finderArgs = new Object[] { start, end, orderByComparator };
3069 }
3070
3071 List<UserGroupRole> list = (List<UserGroupRole>)FinderCacheUtil.getResult(finderPath,
3072 finderArgs, this);
3073
3074 if (list == null) {
3075 StringBundler query = null;
3076 String sql = null;
3077
3078 if (orderByComparator != null) {
3079 query = new StringBundler(2 +
3080 (orderByComparator.getOrderByFields().length * 3));
3081
3082 query.append(_SQL_SELECT_USERGROUPROLE);
3083
3084 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3085 orderByComparator);
3086
3087 sql = query.toString();
3088 }
3089 else {
3090 sql = _SQL_SELECT_USERGROUPROLE;
3091
3092 if (pagination) {
3093 sql = sql.concat(UserGroupRoleModelImpl.ORDER_BY_JPQL);
3094 }
3095 }
3096
3097 Session session = null;
3098
3099 try {
3100 session = openSession();
3101
3102 Query q = session.createQuery(sql);
3103
3104 if (!pagination) {
3105 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3106 start, end, false);
3107
3108 Collections.sort(list);
3109
3110 list = Collections.unmodifiableList(list);
3111 }
3112 else {
3113 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3114 start, end);
3115 }
3116
3117 cacheResult(list);
3118
3119 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3120 }
3121 catch (Exception e) {
3122 FinderCacheUtil.removeResult(finderPath, finderArgs);
3123
3124 throw processException(e);
3125 }
3126 finally {
3127 closeSession(session);
3128 }
3129 }
3130
3131 return list;
3132 }
3133
3134
3138 @Override
3139 public void removeAll() {
3140 for (UserGroupRole userGroupRole : findAll()) {
3141 remove(userGroupRole);
3142 }
3143 }
3144
3145
3150 @Override
3151 public int countAll() {
3152 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3153 FINDER_ARGS_EMPTY, this);
3154
3155 if (count == null) {
3156 Session session = null;
3157
3158 try {
3159 session = openSession();
3160
3161 Query q = session.createQuery(_SQL_COUNT_USERGROUPROLE);
3162
3163 count = (Long)q.uniqueResult();
3164
3165 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3166 FINDER_ARGS_EMPTY, count);
3167 }
3168 catch (Exception e) {
3169 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3170 FINDER_ARGS_EMPTY);
3171
3172 throw processException(e);
3173 }
3174 finally {
3175 closeSession(session);
3176 }
3177 }
3178
3179 return count.intValue();
3180 }
3181
3182
3185 public void afterPropertiesSet() {
3186 }
3187
3188 public void destroy() {
3189 EntityCacheUtil.removeCache(UserGroupRoleImpl.class.getName());
3190 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3191 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3192 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3193 }
3194
3195 private static final String _SQL_SELECT_USERGROUPROLE = "SELECT userGroupRole FROM UserGroupRole userGroupRole";
3196 private static final String _SQL_SELECT_USERGROUPROLE_WHERE = "SELECT userGroupRole FROM UserGroupRole userGroupRole WHERE ";
3197 private static final String _SQL_COUNT_USERGROUPROLE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole";
3198 private static final String _SQL_COUNT_USERGROUPROLE_WHERE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole WHERE ";
3199 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroupRole.";
3200 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroupRole exists with the primary key ";
3201 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroupRole exists with the key {";
3202 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3203 private static final Log _log = LogFactoryUtil.getLog(UserGroupRolePersistenceImpl.class);
3204 private static final UserGroupRole _nullUserGroupRole = new UserGroupRoleImpl() {
3205 @Override
3206 public Object clone() {
3207 return this;
3208 }
3209
3210 @Override
3211 public CacheModel<UserGroupRole> toCacheModel() {
3212 return _nullUserGroupRoleCacheModel;
3213 }
3214 };
3215
3216 private static final CacheModel<UserGroupRole> _nullUserGroupRoleCacheModel = new NullCacheModel();
3217
3218 private static class NullCacheModel implements CacheModel<UserGroupRole>,
3219 MVCCModel {
3220 @Override
3221 public long getMvccVersion() {
3222 return -1;
3223 }
3224
3225 @Override
3226 public void setMvccVersion(long mvccVersion) {
3227 }
3228
3229 @Override
3230 public UserGroupRole toEntityModel() {
3231 return _nullUserGroupRole;
3232 }
3233 }
3234 }