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.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.model.MVCCModel;
036 import com.liferay.portal.model.UserGroupRole;
037 import com.liferay.portal.model.impl.UserGroupRoleImpl;
038 import com.liferay.portal.model.impl.UserGroupRoleModelImpl;
039 import com.liferay.portal.service.persistence.UserGroupRolePK;
040 import com.liferay.portal.service.persistence.UserGroupRolePersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.List;
047 import java.util.Map;
048 import java.util.Set;
049
050
062 @ProviderType
063 public class UserGroupRolePersistenceImpl extends BasePersistenceImpl<UserGroupRole>
064 implements UserGroupRolePersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = UserGroupRoleImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
076 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
077 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
078 "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
080 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
081 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
082 "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
084 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
087 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
088 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
089 "findByUserId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
097 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
098 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
099 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
100 "findByUserId", new String[] { Long.class.getName() },
101 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK);
102 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
103 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
105 new String[] { Long.class.getName() });
106
107
113 @Override
114 public List<UserGroupRole> findByUserId(long userId) {
115 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116 }
117
118
130 @Override
131 public List<UserGroupRole> findByUserId(long userId, int start, int end) {
132 return findByUserId(userId, start, end, null);
133 }
134
135
148 @Override
149 public List<UserGroupRole> findByUserId(long userId, int start, int end,
150 OrderByComparator<UserGroupRole> orderByComparator) {
151 return findByUserId(userId, start, end, orderByComparator, true);
152 }
153
154
168 @Override
169 public List<UserGroupRole> findByUserId(long userId, int start, int end,
170 OrderByComparator<UserGroupRole> orderByComparator,
171 boolean retrieveFromCache) {
172 boolean pagination = true;
173 FinderPath finderPath = null;
174 Object[] finderArgs = null;
175
176 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
177 (orderByComparator == null)) {
178 pagination = false;
179 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
180 finderArgs = new Object[] { userId };
181 }
182 else {
183 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
184 finderArgs = new Object[] { userId, start, end, orderByComparator };
185 }
186
187 List<UserGroupRole> list = null;
188
189 if (retrieveFromCache) {
190 list = (List<UserGroupRole>)finderCache.getResult(finderPath,
191 finderArgs, this);
192
193 if ((list != null) && !list.isEmpty()) {
194 for (UserGroupRole userGroupRole : list) {
195 if ((userId != userGroupRole.getUserId())) {
196 list = null;
197
198 break;
199 }
200 }
201 }
202 }
203
204 if (list == null) {
205 StringBundler query = null;
206
207 if (orderByComparator != null) {
208 query = new StringBundler(3 +
209 (orderByComparator.getOrderByFields().length * 3));
210 }
211 else {
212 query = new StringBundler(3);
213 }
214
215 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
216
217 query.append(_FINDER_COLUMN_USERID_USERID_2);
218
219 if (orderByComparator != null) {
220 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
221 orderByComparator);
222 }
223 else
224 if (pagination) {
225 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
226 }
227
228 String sql = query.toString();
229
230 Session session = null;
231
232 try {
233 session = openSession();
234
235 Query q = session.createQuery(sql);
236
237 QueryPos qPos = QueryPos.getInstance(q);
238
239 qPos.add(userId);
240
241 if (!pagination) {
242 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
243 start, end, false);
244
245 Collections.sort(list);
246
247 list = Collections.unmodifiableList(list);
248 }
249 else {
250 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
251 start, end);
252 }
253
254 cacheResult(list);
255
256 finderCache.putResult(finderPath, finderArgs, list);
257 }
258 catch (Exception e) {
259 finderCache.removeResult(finderPath, finderArgs);
260
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266 }
267
268 return list;
269 }
270
271
279 @Override
280 public UserGroupRole findByUserId_First(long userId,
281 OrderByComparator<UserGroupRole> orderByComparator)
282 throws NoSuchUserGroupRoleException {
283 UserGroupRole userGroupRole = fetchByUserId_First(userId,
284 orderByComparator);
285
286 if (userGroupRole != null) {
287 return userGroupRole;
288 }
289
290 StringBundler msg = new StringBundler(4);
291
292 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293
294 msg.append("userId=");
295 msg.append(userId);
296
297 msg.append(StringPool.CLOSE_CURLY_BRACE);
298
299 throw new NoSuchUserGroupRoleException(msg.toString());
300 }
301
302
309 @Override
310 public UserGroupRole fetchByUserId_First(long userId,
311 OrderByComparator<UserGroupRole> orderByComparator) {
312 List<UserGroupRole> list = findByUserId(userId, 0, 1, orderByComparator);
313
314 if (!list.isEmpty()) {
315 return list.get(0);
316 }
317
318 return null;
319 }
320
321
329 @Override
330 public UserGroupRole findByUserId_Last(long userId,
331 OrderByComparator<UserGroupRole> orderByComparator)
332 throws NoSuchUserGroupRoleException {
333 UserGroupRole userGroupRole = fetchByUserId_Last(userId,
334 orderByComparator);
335
336 if (userGroupRole != null) {
337 return userGroupRole;
338 }
339
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("userId=");
345 msg.append(userId);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchUserGroupRoleException(msg.toString());
350 }
351
352
359 @Override
360 public UserGroupRole fetchByUserId_Last(long userId,
361 OrderByComparator<UserGroupRole> orderByComparator) {
362 int count = countByUserId(userId);
363
364 if (count == 0) {
365 return null;
366 }
367
368 List<UserGroupRole> list = findByUserId(userId, count - 1, count,
369 orderByComparator);
370
371 if (!list.isEmpty()) {
372 return list.get(0);
373 }
374
375 return null;
376 }
377
378
387 @Override
388 public UserGroupRole[] findByUserId_PrevAndNext(
389 UserGroupRolePK userGroupRolePK, long userId,
390 OrderByComparator<UserGroupRole> orderByComparator)
391 throws NoSuchUserGroupRoleException {
392 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
393
394 Session session = null;
395
396 try {
397 session = openSession();
398
399 UserGroupRole[] array = new UserGroupRoleImpl[3];
400
401 array[0] = getByUserId_PrevAndNext(session, userGroupRole, userId,
402 orderByComparator, true);
403
404 array[1] = userGroupRole;
405
406 array[2] = getByUserId_PrevAndNext(session, userGroupRole, userId,
407 orderByComparator, false);
408
409 return array;
410 }
411 catch (Exception e) {
412 throw processException(e);
413 }
414 finally {
415 closeSession(session);
416 }
417 }
418
419 protected UserGroupRole getByUserId_PrevAndNext(Session session,
420 UserGroupRole userGroupRole, long userId,
421 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
422 StringBundler query = null;
423
424 if (orderByComparator != null) {
425 query = new StringBundler(6 +
426 (orderByComparator.getOrderByFields().length * 6));
427 }
428 else {
429 query = new StringBundler(3);
430 }
431
432 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
433
434 query.append(_FINDER_COLUMN_USERID_USERID_2);
435
436 if (orderByComparator != null) {
437 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438
439 if (orderByConditionFields.length > 0) {
440 query.append(WHERE_AND);
441 }
442
443 for (int i = 0; i < orderByConditionFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByConditionFields[i]);
446
447 if ((i + 1) < orderByConditionFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(WHERE_GREATER_THAN_HAS_NEXT);
450 }
451 else {
452 query.append(WHERE_LESSER_THAN_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN);
461 }
462 }
463 }
464
465 query.append(ORDER_BY_CLAUSE);
466
467 String[] orderByFields = orderByComparator.getOrderByFields();
468
469 for (int i = 0; i < orderByFields.length; i++) {
470 query.append(_ORDER_BY_ENTITY_ALIAS);
471 query.append(orderByFields[i]);
472
473 if ((i + 1) < orderByFields.length) {
474 if (orderByComparator.isAscending() ^ previous) {
475 query.append(ORDER_BY_ASC_HAS_NEXT);
476 }
477 else {
478 query.append(ORDER_BY_DESC_HAS_NEXT);
479 }
480 }
481 else {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC);
484 }
485 else {
486 query.append(ORDER_BY_DESC);
487 }
488 }
489 }
490 }
491 else {
492 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
493 }
494
495 String sql = query.toString();
496
497 Query q = session.createQuery(sql);
498
499 q.setFirstResult(0);
500 q.setMaxResults(2);
501
502 QueryPos qPos = QueryPos.getInstance(q);
503
504 qPos.add(userId);
505
506 if (orderByComparator != null) {
507 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
508
509 for (Object value : values) {
510 qPos.add(value);
511 }
512 }
513
514 List<UserGroupRole> list = q.list();
515
516 if (list.size() == 2) {
517 return list.get(1);
518 }
519 else {
520 return null;
521 }
522 }
523
524
529 @Override
530 public void removeByUserId(long userId) {
531 for (UserGroupRole userGroupRole : findByUserId(userId,
532 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
533 remove(userGroupRole);
534 }
535 }
536
537
543 @Override
544 public int countByUserId(long userId) {
545 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
546
547 Object[] finderArgs = new Object[] { userId };
548
549 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
550
551 if (count == null) {
552 StringBundler query = new StringBundler(2);
553
554 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
555
556 query.append(_FINDER_COLUMN_USERID_USERID_2);
557
558 String sql = query.toString();
559
560 Session session = null;
561
562 try {
563 session = openSession();
564
565 Query q = session.createQuery(sql);
566
567 QueryPos qPos = QueryPos.getInstance(q);
568
569 qPos.add(userId);
570
571 count = (Long)q.uniqueResult();
572
573 finderCache.putResult(finderPath, finderArgs, count);
574 }
575 catch (Exception e) {
576 finderCache.removeResult(finderPath, finderArgs);
577
578 throw processException(e);
579 }
580 finally {
581 closeSession(session);
582 }
583 }
584
585 return count.intValue();
586 }
587
588 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userGroupRole.id.userId = ?";
589 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
590 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
591 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
592 "findByGroupId",
593 new String[] {
594 Long.class.getName(),
595
596 Integer.class.getName(), Integer.class.getName(),
597 OrderByComparator.class.getName()
598 });
599 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
600 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
601 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
602 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
603 "findByGroupId", new String[] { Long.class.getName() },
604 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
605 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
606 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
607 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
608 new String[] { Long.class.getName() });
609
610
616 @Override
617 public List<UserGroupRole> findByGroupId(long groupId) {
618 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
619 }
620
621
633 @Override
634 public List<UserGroupRole> findByGroupId(long groupId, int start, int end) {
635 return findByGroupId(groupId, start, end, null);
636 }
637
638
651 @Override
652 public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
653 OrderByComparator<UserGroupRole> orderByComparator) {
654 return findByGroupId(groupId, start, end, orderByComparator, true);
655 }
656
657
671 @Override
672 public List<UserGroupRole> findByGroupId(long groupId, int start, int end,
673 OrderByComparator<UserGroupRole> orderByComparator,
674 boolean retrieveFromCache) {
675 boolean pagination = true;
676 FinderPath finderPath = null;
677 Object[] finderArgs = null;
678
679 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
680 (orderByComparator == null)) {
681 pagination = false;
682 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
683 finderArgs = new Object[] { groupId };
684 }
685 else {
686 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
687 finderArgs = new Object[] { groupId, start, end, orderByComparator };
688 }
689
690 List<UserGroupRole> list = null;
691
692 if (retrieveFromCache) {
693 list = (List<UserGroupRole>)finderCache.getResult(finderPath,
694 finderArgs, this);
695
696 if ((list != null) && !list.isEmpty()) {
697 for (UserGroupRole userGroupRole : list) {
698 if ((groupId != userGroupRole.getGroupId())) {
699 list = null;
700
701 break;
702 }
703 }
704 }
705 }
706
707 if (list == null) {
708 StringBundler query = null;
709
710 if (orderByComparator != null) {
711 query = new StringBundler(3 +
712 (orderByComparator.getOrderByFields().length * 3));
713 }
714 else {
715 query = new StringBundler(3);
716 }
717
718 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
719
720 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
721
722 if (orderByComparator != null) {
723 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
724 orderByComparator);
725 }
726 else
727 if (pagination) {
728 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
729 }
730
731 String sql = query.toString();
732
733 Session session = null;
734
735 try {
736 session = openSession();
737
738 Query q = session.createQuery(sql);
739
740 QueryPos qPos = QueryPos.getInstance(q);
741
742 qPos.add(groupId);
743
744 if (!pagination) {
745 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
746 start, end, false);
747
748 Collections.sort(list);
749
750 list = Collections.unmodifiableList(list);
751 }
752 else {
753 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
754 start, end);
755 }
756
757 cacheResult(list);
758
759 finderCache.putResult(finderPath, finderArgs, list);
760 }
761 catch (Exception e) {
762 finderCache.removeResult(finderPath, finderArgs);
763
764 throw processException(e);
765 }
766 finally {
767 closeSession(session);
768 }
769 }
770
771 return list;
772 }
773
774
782 @Override
783 public UserGroupRole findByGroupId_First(long groupId,
784 OrderByComparator<UserGroupRole> orderByComparator)
785 throws NoSuchUserGroupRoleException {
786 UserGroupRole userGroupRole = fetchByGroupId_First(groupId,
787 orderByComparator);
788
789 if (userGroupRole != null) {
790 return userGroupRole;
791 }
792
793 StringBundler msg = new StringBundler(4);
794
795 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
796
797 msg.append("groupId=");
798 msg.append(groupId);
799
800 msg.append(StringPool.CLOSE_CURLY_BRACE);
801
802 throw new NoSuchUserGroupRoleException(msg.toString());
803 }
804
805
812 @Override
813 public UserGroupRole fetchByGroupId_First(long groupId,
814 OrderByComparator<UserGroupRole> orderByComparator) {
815 List<UserGroupRole> list = findByGroupId(groupId, 0, 1,
816 orderByComparator);
817
818 if (!list.isEmpty()) {
819 return list.get(0);
820 }
821
822 return null;
823 }
824
825
833 @Override
834 public UserGroupRole findByGroupId_Last(long groupId,
835 OrderByComparator<UserGroupRole> orderByComparator)
836 throws NoSuchUserGroupRoleException {
837 UserGroupRole userGroupRole = fetchByGroupId_Last(groupId,
838 orderByComparator);
839
840 if (userGroupRole != null) {
841 return userGroupRole;
842 }
843
844 StringBundler msg = new StringBundler(4);
845
846 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
847
848 msg.append("groupId=");
849 msg.append(groupId);
850
851 msg.append(StringPool.CLOSE_CURLY_BRACE);
852
853 throw new NoSuchUserGroupRoleException(msg.toString());
854 }
855
856
863 @Override
864 public UserGroupRole fetchByGroupId_Last(long groupId,
865 OrderByComparator<UserGroupRole> orderByComparator) {
866 int count = countByGroupId(groupId);
867
868 if (count == 0) {
869 return null;
870 }
871
872 List<UserGroupRole> list = findByGroupId(groupId, count - 1, count,
873 orderByComparator);
874
875 if (!list.isEmpty()) {
876 return list.get(0);
877 }
878
879 return null;
880 }
881
882
891 @Override
892 public UserGroupRole[] findByGroupId_PrevAndNext(
893 UserGroupRolePK userGroupRolePK, long groupId,
894 OrderByComparator<UserGroupRole> orderByComparator)
895 throws NoSuchUserGroupRoleException {
896 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
897
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 UserGroupRole[] array = new UserGroupRoleImpl[3];
904
905 array[0] = getByGroupId_PrevAndNext(session, userGroupRole,
906 groupId, orderByComparator, true);
907
908 array[1] = userGroupRole;
909
910 array[2] = getByGroupId_PrevAndNext(session, userGroupRole,
911 groupId, orderByComparator, false);
912
913 return array;
914 }
915 catch (Exception e) {
916 throw processException(e);
917 }
918 finally {
919 closeSession(session);
920 }
921 }
922
923 protected UserGroupRole getByGroupId_PrevAndNext(Session session,
924 UserGroupRole userGroupRole, long groupId,
925 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
926 StringBundler query = null;
927
928 if (orderByComparator != null) {
929 query = new StringBundler(6 +
930 (orderByComparator.getOrderByFields().length * 6));
931 }
932 else {
933 query = new StringBundler(3);
934 }
935
936 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
937
938 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
939
940 if (orderByComparator != null) {
941 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
942
943 if (orderByConditionFields.length > 0) {
944 query.append(WHERE_AND);
945 }
946
947 for (int i = 0; i < orderByConditionFields.length; i++) {
948 query.append(_ORDER_BY_ENTITY_ALIAS);
949 query.append(orderByConditionFields[i]);
950
951 if ((i + 1) < orderByConditionFields.length) {
952 if (orderByComparator.isAscending() ^ previous) {
953 query.append(WHERE_GREATER_THAN_HAS_NEXT);
954 }
955 else {
956 query.append(WHERE_LESSER_THAN_HAS_NEXT);
957 }
958 }
959 else {
960 if (orderByComparator.isAscending() ^ previous) {
961 query.append(WHERE_GREATER_THAN);
962 }
963 else {
964 query.append(WHERE_LESSER_THAN);
965 }
966 }
967 }
968
969 query.append(ORDER_BY_CLAUSE);
970
971 String[] orderByFields = orderByComparator.getOrderByFields();
972
973 for (int i = 0; i < orderByFields.length; i++) {
974 query.append(_ORDER_BY_ENTITY_ALIAS);
975 query.append(orderByFields[i]);
976
977 if ((i + 1) < orderByFields.length) {
978 if (orderByComparator.isAscending() ^ previous) {
979 query.append(ORDER_BY_ASC_HAS_NEXT);
980 }
981 else {
982 query.append(ORDER_BY_DESC_HAS_NEXT);
983 }
984 }
985 else {
986 if (orderByComparator.isAscending() ^ previous) {
987 query.append(ORDER_BY_ASC);
988 }
989 else {
990 query.append(ORDER_BY_DESC);
991 }
992 }
993 }
994 }
995 else {
996 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
997 }
998
999 String sql = query.toString();
1000
1001 Query q = session.createQuery(sql);
1002
1003 q.setFirstResult(0);
1004 q.setMaxResults(2);
1005
1006 QueryPos qPos = QueryPos.getInstance(q);
1007
1008 qPos.add(groupId);
1009
1010 if (orderByComparator != null) {
1011 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1012
1013 for (Object value : values) {
1014 qPos.add(value);
1015 }
1016 }
1017
1018 List<UserGroupRole> list = q.list();
1019
1020 if (list.size() == 2) {
1021 return list.get(1);
1022 }
1023 else {
1024 return null;
1025 }
1026 }
1027
1028
1033 @Override
1034 public void removeByGroupId(long groupId) {
1035 for (UserGroupRole userGroupRole : findByGroupId(groupId,
1036 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1037 remove(userGroupRole);
1038 }
1039 }
1040
1041
1047 @Override
1048 public int countByGroupId(long groupId) {
1049 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1050
1051 Object[] finderArgs = new Object[] { groupId };
1052
1053 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1054
1055 if (count == null) {
1056 StringBundler query = new StringBundler(2);
1057
1058 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1059
1060 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1061
1062 String sql = query.toString();
1063
1064 Session session = null;
1065
1066 try {
1067 session = openSession();
1068
1069 Query q = session.createQuery(sql);
1070
1071 QueryPos qPos = QueryPos.getInstance(q);
1072
1073 qPos.add(groupId);
1074
1075 count = (Long)q.uniqueResult();
1076
1077 finderCache.putResult(finderPath, finderArgs, count);
1078 }
1079 catch (Exception e) {
1080 finderCache.removeResult(finderPath, finderArgs);
1081
1082 throw processException(e);
1083 }
1084 finally {
1085 closeSession(session);
1086 }
1087 }
1088
1089 return count.intValue();
1090 }
1091
1092 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "userGroupRole.id.groupId = ?";
1093 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1094 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1095 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1096 "findByRoleId",
1097 new String[] {
1098 Long.class.getName(),
1099
1100 Integer.class.getName(), Integer.class.getName(),
1101 OrderByComparator.class.getName()
1102 });
1103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID =
1104 new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1105 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1106 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1107 "findByRoleId", new String[] { Long.class.getName() },
1108 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
1109 public static final FinderPath FINDER_PATH_COUNT_BY_ROLEID = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1110 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRoleId",
1112 new String[] { Long.class.getName() });
1113
1114
1120 @Override
1121 public List<UserGroupRole> findByRoleId(long roleId) {
1122 return findByRoleId(roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1123 }
1124
1125
1137 @Override
1138 public List<UserGroupRole> findByRoleId(long roleId, int start, int end) {
1139 return findByRoleId(roleId, start, end, null);
1140 }
1141
1142
1155 @Override
1156 public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
1157 OrderByComparator<UserGroupRole> orderByComparator) {
1158 return findByRoleId(roleId, start, end, orderByComparator, true);
1159 }
1160
1161
1175 @Override
1176 public List<UserGroupRole> findByRoleId(long roleId, int start, int end,
1177 OrderByComparator<UserGroupRole> orderByComparator,
1178 boolean retrieveFromCache) {
1179 boolean pagination = true;
1180 FinderPath finderPath = null;
1181 Object[] finderArgs = null;
1182
1183 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1184 (orderByComparator == null)) {
1185 pagination = false;
1186 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID;
1187 finderArgs = new Object[] { roleId };
1188 }
1189 else {
1190 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ROLEID;
1191 finderArgs = new Object[] { roleId, start, end, orderByComparator };
1192 }
1193
1194 List<UserGroupRole> list = null;
1195
1196 if (retrieveFromCache) {
1197 list = (List<UserGroupRole>)finderCache.getResult(finderPath,
1198 finderArgs, this);
1199
1200 if ((list != null) && !list.isEmpty()) {
1201 for (UserGroupRole userGroupRole : list) {
1202 if ((roleId != userGroupRole.getRoleId())) {
1203 list = null;
1204
1205 break;
1206 }
1207 }
1208 }
1209 }
1210
1211 if (list == null) {
1212 StringBundler query = null;
1213
1214 if (orderByComparator != null) {
1215 query = new StringBundler(3 +
1216 (orderByComparator.getOrderByFields().length * 3));
1217 }
1218 else {
1219 query = new StringBundler(3);
1220 }
1221
1222 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1223
1224 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1225
1226 if (orderByComparator != null) {
1227 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1228 orderByComparator);
1229 }
1230 else
1231 if (pagination) {
1232 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1233 }
1234
1235 String sql = query.toString();
1236
1237 Session session = null;
1238
1239 try {
1240 session = openSession();
1241
1242 Query q = session.createQuery(sql);
1243
1244 QueryPos qPos = QueryPos.getInstance(q);
1245
1246 qPos.add(roleId);
1247
1248 if (!pagination) {
1249 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1250 start, end, false);
1251
1252 Collections.sort(list);
1253
1254 list = Collections.unmodifiableList(list);
1255 }
1256 else {
1257 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1258 start, end);
1259 }
1260
1261 cacheResult(list);
1262
1263 finderCache.putResult(finderPath, finderArgs, list);
1264 }
1265 catch (Exception e) {
1266 finderCache.removeResult(finderPath, finderArgs);
1267
1268 throw processException(e);
1269 }
1270 finally {
1271 closeSession(session);
1272 }
1273 }
1274
1275 return list;
1276 }
1277
1278
1286 @Override
1287 public UserGroupRole findByRoleId_First(long roleId,
1288 OrderByComparator<UserGroupRole> orderByComparator)
1289 throws NoSuchUserGroupRoleException {
1290 UserGroupRole userGroupRole = fetchByRoleId_First(roleId,
1291 orderByComparator);
1292
1293 if (userGroupRole != null) {
1294 return userGroupRole;
1295 }
1296
1297 StringBundler msg = new StringBundler(4);
1298
1299 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1300
1301 msg.append("roleId=");
1302 msg.append(roleId);
1303
1304 msg.append(StringPool.CLOSE_CURLY_BRACE);
1305
1306 throw new NoSuchUserGroupRoleException(msg.toString());
1307 }
1308
1309
1316 @Override
1317 public UserGroupRole fetchByRoleId_First(long roleId,
1318 OrderByComparator<UserGroupRole> orderByComparator) {
1319 List<UserGroupRole> list = findByRoleId(roleId, 0, 1, orderByComparator);
1320
1321 if (!list.isEmpty()) {
1322 return list.get(0);
1323 }
1324
1325 return null;
1326 }
1327
1328
1336 @Override
1337 public UserGroupRole findByRoleId_Last(long roleId,
1338 OrderByComparator<UserGroupRole> orderByComparator)
1339 throws NoSuchUserGroupRoleException {
1340 UserGroupRole userGroupRole = fetchByRoleId_Last(roleId,
1341 orderByComparator);
1342
1343 if (userGroupRole != null) {
1344 return userGroupRole;
1345 }
1346
1347 StringBundler msg = new StringBundler(4);
1348
1349 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1350
1351 msg.append("roleId=");
1352 msg.append(roleId);
1353
1354 msg.append(StringPool.CLOSE_CURLY_BRACE);
1355
1356 throw new NoSuchUserGroupRoleException(msg.toString());
1357 }
1358
1359
1366 @Override
1367 public UserGroupRole fetchByRoleId_Last(long roleId,
1368 OrderByComparator<UserGroupRole> orderByComparator) {
1369 int count = countByRoleId(roleId);
1370
1371 if (count == 0) {
1372 return null;
1373 }
1374
1375 List<UserGroupRole> list = findByRoleId(roleId, count - 1, count,
1376 orderByComparator);
1377
1378 if (!list.isEmpty()) {
1379 return list.get(0);
1380 }
1381
1382 return null;
1383 }
1384
1385
1394 @Override
1395 public UserGroupRole[] findByRoleId_PrevAndNext(
1396 UserGroupRolePK userGroupRolePK, long roleId,
1397 OrderByComparator<UserGroupRole> orderByComparator)
1398 throws NoSuchUserGroupRoleException {
1399 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1400
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 UserGroupRole[] array = new UserGroupRoleImpl[3];
1407
1408 array[0] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1409 orderByComparator, true);
1410
1411 array[1] = userGroupRole;
1412
1413 array[2] = getByRoleId_PrevAndNext(session, userGroupRole, roleId,
1414 orderByComparator, false);
1415
1416 return array;
1417 }
1418 catch (Exception e) {
1419 throw processException(e);
1420 }
1421 finally {
1422 closeSession(session);
1423 }
1424 }
1425
1426 protected UserGroupRole getByRoleId_PrevAndNext(Session session,
1427 UserGroupRole userGroupRole, long roleId,
1428 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
1429 StringBundler query = null;
1430
1431 if (orderByComparator != null) {
1432 query = new StringBundler(6 +
1433 (orderByComparator.getOrderByFields().length * 6));
1434 }
1435 else {
1436 query = new StringBundler(3);
1437 }
1438
1439 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1440
1441 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1442
1443 if (orderByComparator != null) {
1444 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1445
1446 if (orderByConditionFields.length > 0) {
1447 query.append(WHERE_AND);
1448 }
1449
1450 for (int i = 0; i < orderByConditionFields.length; i++) {
1451 query.append(_ORDER_BY_ENTITY_ALIAS);
1452 query.append(orderByConditionFields[i]);
1453
1454 if ((i + 1) < orderByConditionFields.length) {
1455 if (orderByComparator.isAscending() ^ previous) {
1456 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1457 }
1458 else {
1459 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1460 }
1461 }
1462 else {
1463 if (orderByComparator.isAscending() ^ previous) {
1464 query.append(WHERE_GREATER_THAN);
1465 }
1466 else {
1467 query.append(WHERE_LESSER_THAN);
1468 }
1469 }
1470 }
1471
1472 query.append(ORDER_BY_CLAUSE);
1473
1474 String[] orderByFields = orderByComparator.getOrderByFields();
1475
1476 for (int i = 0; i < orderByFields.length; i++) {
1477 query.append(_ORDER_BY_ENTITY_ALIAS);
1478 query.append(orderByFields[i]);
1479
1480 if ((i + 1) < orderByFields.length) {
1481 if (orderByComparator.isAscending() ^ previous) {
1482 query.append(ORDER_BY_ASC_HAS_NEXT);
1483 }
1484 else {
1485 query.append(ORDER_BY_DESC_HAS_NEXT);
1486 }
1487 }
1488 else {
1489 if (orderByComparator.isAscending() ^ previous) {
1490 query.append(ORDER_BY_ASC);
1491 }
1492 else {
1493 query.append(ORDER_BY_DESC);
1494 }
1495 }
1496 }
1497 }
1498 else {
1499 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1500 }
1501
1502 String sql = query.toString();
1503
1504 Query q = session.createQuery(sql);
1505
1506 q.setFirstResult(0);
1507 q.setMaxResults(2);
1508
1509 QueryPos qPos = QueryPos.getInstance(q);
1510
1511 qPos.add(roleId);
1512
1513 if (orderByComparator != null) {
1514 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
1515
1516 for (Object value : values) {
1517 qPos.add(value);
1518 }
1519 }
1520
1521 List<UserGroupRole> list = q.list();
1522
1523 if (list.size() == 2) {
1524 return list.get(1);
1525 }
1526 else {
1527 return null;
1528 }
1529 }
1530
1531
1536 @Override
1537 public void removeByRoleId(long roleId) {
1538 for (UserGroupRole userGroupRole : findByRoleId(roleId,
1539 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1540 remove(userGroupRole);
1541 }
1542 }
1543
1544
1550 @Override
1551 public int countByRoleId(long roleId) {
1552 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROLEID;
1553
1554 Object[] finderArgs = new Object[] { roleId };
1555
1556 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1557
1558 if (count == null) {
1559 StringBundler query = new StringBundler(2);
1560
1561 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
1562
1563 query.append(_FINDER_COLUMN_ROLEID_ROLEID_2);
1564
1565 String sql = query.toString();
1566
1567 Session session = null;
1568
1569 try {
1570 session = openSession();
1571
1572 Query q = session.createQuery(sql);
1573
1574 QueryPos qPos = QueryPos.getInstance(q);
1575
1576 qPos.add(roleId);
1577
1578 count = (Long)q.uniqueResult();
1579
1580 finderCache.putResult(finderPath, finderArgs, count);
1581 }
1582 catch (Exception e) {
1583 finderCache.removeResult(finderPath, finderArgs);
1584
1585 throw processException(e);
1586 }
1587 finally {
1588 closeSession(session);
1589 }
1590 }
1591
1592 return count.intValue();
1593 }
1594
1595 private static final String _FINDER_COLUMN_ROLEID_ROLEID_2 = "userGroupRole.id.roleId = ?";
1596 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1597 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1598 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1599 "findByU_G",
1600 new String[] {
1601 Long.class.getName(), Long.class.getName(),
1602
1603 Integer.class.getName(), Integer.class.getName(),
1604 OrderByComparator.class.getName()
1605 });
1606 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1607 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
1608 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1609 "findByU_G",
1610 new String[] { Long.class.getName(), Long.class.getName() },
1611 UserGroupRoleModelImpl.USERID_COLUMN_BITMASK |
1612 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK);
1613 public static final FinderPath FINDER_PATH_COUNT_BY_U_G = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
1614 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_G",
1616 new String[] { Long.class.getName(), Long.class.getName() });
1617
1618
1625 @Override
1626 public List<UserGroupRole> findByU_G(long userId, long groupId) {
1627 return findByU_G(userId, groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1628 null);
1629 }
1630
1631
1644 @Override
1645 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1646 int end) {
1647 return findByU_G(userId, groupId, start, end, null);
1648 }
1649
1650
1664 @Override
1665 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1666 int end, OrderByComparator<UserGroupRole> orderByComparator) {
1667 return findByU_G(userId, groupId, start, end, orderByComparator, true);
1668 }
1669
1670
1685 @Override
1686 public List<UserGroupRole> findByU_G(long userId, long groupId, int start,
1687 int end, OrderByComparator<UserGroupRole> orderByComparator,
1688 boolean retrieveFromCache) {
1689 boolean pagination = true;
1690 FinderPath finderPath = null;
1691 Object[] finderArgs = null;
1692
1693 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1694 (orderByComparator == null)) {
1695 pagination = false;
1696 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G;
1697 finderArgs = new Object[] { userId, groupId };
1698 }
1699 else {
1700 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_G;
1701 finderArgs = new Object[] {
1702 userId, groupId,
1703
1704 start, end, orderByComparator
1705 };
1706 }
1707
1708 List<UserGroupRole> list = null;
1709
1710 if (retrieveFromCache) {
1711 list = (List<UserGroupRole>)finderCache.getResult(finderPath,
1712 finderArgs, this);
1713
1714 if ((list != null) && !list.isEmpty()) {
1715 for (UserGroupRole userGroupRole : list) {
1716 if ((userId != userGroupRole.getUserId()) ||
1717 (groupId != userGroupRole.getGroupId())) {
1718 list = null;
1719
1720 break;
1721 }
1722 }
1723 }
1724 }
1725
1726 if (list == null) {
1727 StringBundler query = null;
1728
1729 if (orderByComparator != null) {
1730 query = new StringBundler(4 +
1731 (orderByComparator.getOrderByFields().length * 3));
1732 }
1733 else {
1734 query = new StringBundler(4);
1735 }
1736
1737 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1738
1739 query.append(_FINDER_COLUMN_U_G_USERID_2);
1740
1741 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1742
1743 if (orderByComparator != null) {
1744 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1745 orderByComparator);
1746 }
1747 else
1748 if (pagination) {
1749 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
1750 }
1751
1752 String sql = query.toString();
1753
1754 Session session = null;
1755
1756 try {
1757 session = openSession();
1758
1759 Query q = session.createQuery(sql);
1760
1761 QueryPos qPos = QueryPos.getInstance(q);
1762
1763 qPos.add(userId);
1764
1765 qPos.add(groupId);
1766
1767 if (!pagination) {
1768 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1769 start, end, false);
1770
1771 Collections.sort(list);
1772
1773 list = Collections.unmodifiableList(list);
1774 }
1775 else {
1776 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
1777 start, end);
1778 }
1779
1780 cacheResult(list);
1781
1782 finderCache.putResult(finderPath, finderArgs, list);
1783 }
1784 catch (Exception e) {
1785 finderCache.removeResult(finderPath, finderArgs);
1786
1787 throw processException(e);
1788 }
1789 finally {
1790 closeSession(session);
1791 }
1792 }
1793
1794 return list;
1795 }
1796
1797
1806 @Override
1807 public UserGroupRole findByU_G_First(long userId, long groupId,
1808 OrderByComparator<UserGroupRole> orderByComparator)
1809 throws NoSuchUserGroupRoleException {
1810 UserGroupRole userGroupRole = fetchByU_G_First(userId, groupId,
1811 orderByComparator);
1812
1813 if (userGroupRole != null) {
1814 return userGroupRole;
1815 }
1816
1817 StringBundler msg = new StringBundler(6);
1818
1819 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1820
1821 msg.append("userId=");
1822 msg.append(userId);
1823
1824 msg.append(", groupId=");
1825 msg.append(groupId);
1826
1827 msg.append(StringPool.CLOSE_CURLY_BRACE);
1828
1829 throw new NoSuchUserGroupRoleException(msg.toString());
1830 }
1831
1832
1840 @Override
1841 public UserGroupRole fetchByU_G_First(long userId, long groupId,
1842 OrderByComparator<UserGroupRole> orderByComparator) {
1843 List<UserGroupRole> list = findByU_G(userId, groupId, 0, 1,
1844 orderByComparator);
1845
1846 if (!list.isEmpty()) {
1847 return list.get(0);
1848 }
1849
1850 return null;
1851 }
1852
1853
1862 @Override
1863 public UserGroupRole findByU_G_Last(long userId, long groupId,
1864 OrderByComparator<UserGroupRole> orderByComparator)
1865 throws NoSuchUserGroupRoleException {
1866 UserGroupRole userGroupRole = fetchByU_G_Last(userId, groupId,
1867 orderByComparator);
1868
1869 if (userGroupRole != null) {
1870 return userGroupRole;
1871 }
1872
1873 StringBundler msg = new StringBundler(6);
1874
1875 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1876
1877 msg.append("userId=");
1878 msg.append(userId);
1879
1880 msg.append(", groupId=");
1881 msg.append(groupId);
1882
1883 msg.append(StringPool.CLOSE_CURLY_BRACE);
1884
1885 throw new NoSuchUserGroupRoleException(msg.toString());
1886 }
1887
1888
1896 @Override
1897 public UserGroupRole fetchByU_G_Last(long userId, long groupId,
1898 OrderByComparator<UserGroupRole> orderByComparator) {
1899 int count = countByU_G(userId, groupId);
1900
1901 if (count == 0) {
1902 return null;
1903 }
1904
1905 List<UserGroupRole> list = findByU_G(userId, groupId, count - 1, count,
1906 orderByComparator);
1907
1908 if (!list.isEmpty()) {
1909 return list.get(0);
1910 }
1911
1912 return null;
1913 }
1914
1915
1925 @Override
1926 public UserGroupRole[] findByU_G_PrevAndNext(
1927 UserGroupRolePK userGroupRolePK, long userId, long groupId,
1928 OrderByComparator<UserGroupRole> orderByComparator)
1929 throws NoSuchUserGroupRoleException {
1930 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
1931
1932 Session session = null;
1933
1934 try {
1935 session = openSession();
1936
1937 UserGroupRole[] array = new UserGroupRoleImpl[3];
1938
1939 array[0] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1940 groupId, orderByComparator, true);
1941
1942 array[1] = userGroupRole;
1943
1944 array[2] = getByU_G_PrevAndNext(session, userGroupRole, userId,
1945 groupId, orderByComparator, false);
1946
1947 return array;
1948 }
1949 catch (Exception e) {
1950 throw processException(e);
1951 }
1952 finally {
1953 closeSession(session);
1954 }
1955 }
1956
1957 protected UserGroupRole getByU_G_PrevAndNext(Session session,
1958 UserGroupRole userGroupRole, long userId, long groupId,
1959 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
1960 StringBundler query = null;
1961
1962 if (orderByComparator != null) {
1963 query = new StringBundler(6 +
1964 (orderByComparator.getOrderByFields().length * 6));
1965 }
1966 else {
1967 query = new StringBundler(3);
1968 }
1969
1970 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
1971
1972 query.append(_FINDER_COLUMN_U_G_USERID_2);
1973
1974 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
1975
1976 if (orderByComparator != null) {
1977 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1978
1979 if (orderByConditionFields.length > 0) {
1980 query.append(WHERE_AND);
1981 }
1982
1983 for (int i = 0; i < orderByConditionFields.length; i++) {
1984 query.append(_ORDER_BY_ENTITY_ALIAS);
1985 query.append(orderByConditionFields[i]);
1986
1987 if ((i + 1) < orderByConditionFields.length) {
1988 if (orderByComparator.isAscending() ^ previous) {
1989 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1990 }
1991 else {
1992 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1993 }
1994 }
1995 else {
1996 if (orderByComparator.isAscending() ^ previous) {
1997 query.append(WHERE_GREATER_THAN);
1998 }
1999 else {
2000 query.append(WHERE_LESSER_THAN);
2001 }
2002 }
2003 }
2004
2005 query.append(ORDER_BY_CLAUSE);
2006
2007 String[] orderByFields = orderByComparator.getOrderByFields();
2008
2009 for (int i = 0; i < orderByFields.length; i++) {
2010 query.append(_ORDER_BY_ENTITY_ALIAS);
2011 query.append(orderByFields[i]);
2012
2013 if ((i + 1) < orderByFields.length) {
2014 if (orderByComparator.isAscending() ^ previous) {
2015 query.append(ORDER_BY_ASC_HAS_NEXT);
2016 }
2017 else {
2018 query.append(ORDER_BY_DESC_HAS_NEXT);
2019 }
2020 }
2021 else {
2022 if (orderByComparator.isAscending() ^ previous) {
2023 query.append(ORDER_BY_ASC);
2024 }
2025 else {
2026 query.append(ORDER_BY_DESC);
2027 }
2028 }
2029 }
2030 }
2031 else {
2032 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2033 }
2034
2035 String sql = query.toString();
2036
2037 Query q = session.createQuery(sql);
2038
2039 q.setFirstResult(0);
2040 q.setMaxResults(2);
2041
2042 QueryPos qPos = QueryPos.getInstance(q);
2043
2044 qPos.add(userId);
2045
2046 qPos.add(groupId);
2047
2048 if (orderByComparator != null) {
2049 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
2050
2051 for (Object value : values) {
2052 qPos.add(value);
2053 }
2054 }
2055
2056 List<UserGroupRole> list = q.list();
2057
2058 if (list.size() == 2) {
2059 return list.get(1);
2060 }
2061 else {
2062 return null;
2063 }
2064 }
2065
2066
2072 @Override
2073 public void removeByU_G(long userId, long groupId) {
2074 for (UserGroupRole userGroupRole : findByU_G(userId, groupId,
2075 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2076 remove(userGroupRole);
2077 }
2078 }
2079
2080
2087 @Override
2088 public int countByU_G(long userId, long groupId) {
2089 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_G;
2090
2091 Object[] finderArgs = new Object[] { userId, groupId };
2092
2093 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2094
2095 if (count == null) {
2096 StringBundler query = new StringBundler(3);
2097
2098 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2099
2100 query.append(_FINDER_COLUMN_U_G_USERID_2);
2101
2102 query.append(_FINDER_COLUMN_U_G_GROUPID_2);
2103
2104 String sql = query.toString();
2105
2106 Session session = null;
2107
2108 try {
2109 session = openSession();
2110
2111 Query q = session.createQuery(sql);
2112
2113 QueryPos qPos = QueryPos.getInstance(q);
2114
2115 qPos.add(userId);
2116
2117 qPos.add(groupId);
2118
2119 count = (Long)q.uniqueResult();
2120
2121 finderCache.putResult(finderPath, finderArgs, count);
2122 }
2123 catch (Exception e) {
2124 finderCache.removeResult(finderPath, finderArgs);
2125
2126 throw processException(e);
2127 }
2128 finally {
2129 closeSession(session);
2130 }
2131 }
2132
2133 return count.intValue();
2134 }
2135
2136 private static final String _FINDER_COLUMN_U_G_USERID_2 = "userGroupRole.id.userId = ? AND ";
2137 private static final String _FINDER_COLUMN_U_G_GROUPID_2 = "userGroupRole.id.groupId = ?";
2138 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2139 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2140 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2141 "findByG_R",
2142 new String[] {
2143 Long.class.getName(), Long.class.getName(),
2144
2145 Integer.class.getName(), Integer.class.getName(),
2146 OrderByComparator.class.getName()
2147 });
2148 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2149 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED,
2150 UserGroupRoleImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
2151 "findByG_R",
2152 new String[] { Long.class.getName(), Long.class.getName() },
2153 UserGroupRoleModelImpl.GROUPID_COLUMN_BITMASK |
2154 UserGroupRoleModelImpl.ROLEID_COLUMN_BITMASK);
2155 public static final FinderPath FINDER_PATH_COUNT_BY_G_R = new FinderPath(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2156 UserGroupRoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2157 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_R",
2158 new String[] { Long.class.getName(), Long.class.getName() });
2159
2160
2167 @Override
2168 public List<UserGroupRole> findByG_R(long groupId, long roleId) {
2169 return findByG_R(groupId, roleId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2170 null);
2171 }
2172
2173
2186 @Override
2187 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2188 int end) {
2189 return findByG_R(groupId, roleId, start, end, null);
2190 }
2191
2192
2206 @Override
2207 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2208 int end, OrderByComparator<UserGroupRole> orderByComparator) {
2209 return findByG_R(groupId, roleId, start, end, orderByComparator, true);
2210 }
2211
2212
2227 @Override
2228 public List<UserGroupRole> findByG_R(long groupId, long roleId, int start,
2229 int end, OrderByComparator<UserGroupRole> orderByComparator,
2230 boolean retrieveFromCache) {
2231 boolean pagination = true;
2232 FinderPath finderPath = null;
2233 Object[] finderArgs = null;
2234
2235 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2236 (orderByComparator == null)) {
2237 pagination = false;
2238 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R;
2239 finderArgs = new Object[] { groupId, roleId };
2240 }
2241 else {
2242 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_R;
2243 finderArgs = new Object[] {
2244 groupId, roleId,
2245
2246 start, end, orderByComparator
2247 };
2248 }
2249
2250 List<UserGroupRole> list = null;
2251
2252 if (retrieveFromCache) {
2253 list = (List<UserGroupRole>)finderCache.getResult(finderPath,
2254 finderArgs, this);
2255
2256 if ((list != null) && !list.isEmpty()) {
2257 for (UserGroupRole userGroupRole : list) {
2258 if ((groupId != userGroupRole.getGroupId()) ||
2259 (roleId != userGroupRole.getRoleId())) {
2260 list = null;
2261
2262 break;
2263 }
2264 }
2265 }
2266 }
2267
2268 if (list == null) {
2269 StringBundler query = null;
2270
2271 if (orderByComparator != null) {
2272 query = new StringBundler(4 +
2273 (orderByComparator.getOrderByFields().length * 3));
2274 }
2275 else {
2276 query = new StringBundler(4);
2277 }
2278
2279 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2280
2281 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2282
2283 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2284
2285 if (orderByComparator != null) {
2286 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2287 orderByComparator);
2288 }
2289 else
2290 if (pagination) {
2291 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2292 }
2293
2294 String sql = query.toString();
2295
2296 Session session = null;
2297
2298 try {
2299 session = openSession();
2300
2301 Query q = session.createQuery(sql);
2302
2303 QueryPos qPos = QueryPos.getInstance(q);
2304
2305 qPos.add(groupId);
2306
2307 qPos.add(roleId);
2308
2309 if (!pagination) {
2310 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2311 start, end, false);
2312
2313 Collections.sort(list);
2314
2315 list = Collections.unmodifiableList(list);
2316 }
2317 else {
2318 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
2319 start, end);
2320 }
2321
2322 cacheResult(list);
2323
2324 finderCache.putResult(finderPath, finderArgs, list);
2325 }
2326 catch (Exception e) {
2327 finderCache.removeResult(finderPath, finderArgs);
2328
2329 throw processException(e);
2330 }
2331 finally {
2332 closeSession(session);
2333 }
2334 }
2335
2336 return list;
2337 }
2338
2339
2348 @Override
2349 public UserGroupRole findByG_R_First(long groupId, long roleId,
2350 OrderByComparator<UserGroupRole> orderByComparator)
2351 throws NoSuchUserGroupRoleException {
2352 UserGroupRole userGroupRole = fetchByG_R_First(groupId, roleId,
2353 orderByComparator);
2354
2355 if (userGroupRole != null) {
2356 return userGroupRole;
2357 }
2358
2359 StringBundler msg = new StringBundler(6);
2360
2361 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2362
2363 msg.append("groupId=");
2364 msg.append(groupId);
2365
2366 msg.append(", roleId=");
2367 msg.append(roleId);
2368
2369 msg.append(StringPool.CLOSE_CURLY_BRACE);
2370
2371 throw new NoSuchUserGroupRoleException(msg.toString());
2372 }
2373
2374
2382 @Override
2383 public UserGroupRole fetchByG_R_First(long groupId, long roleId,
2384 OrderByComparator<UserGroupRole> orderByComparator) {
2385 List<UserGroupRole> list = findByG_R(groupId, roleId, 0, 1,
2386 orderByComparator);
2387
2388 if (!list.isEmpty()) {
2389 return list.get(0);
2390 }
2391
2392 return null;
2393 }
2394
2395
2404 @Override
2405 public UserGroupRole findByG_R_Last(long groupId, long roleId,
2406 OrderByComparator<UserGroupRole> orderByComparator)
2407 throws NoSuchUserGroupRoleException {
2408 UserGroupRole userGroupRole = fetchByG_R_Last(groupId, roleId,
2409 orderByComparator);
2410
2411 if (userGroupRole != null) {
2412 return userGroupRole;
2413 }
2414
2415 StringBundler msg = new StringBundler(6);
2416
2417 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2418
2419 msg.append("groupId=");
2420 msg.append(groupId);
2421
2422 msg.append(", roleId=");
2423 msg.append(roleId);
2424
2425 msg.append(StringPool.CLOSE_CURLY_BRACE);
2426
2427 throw new NoSuchUserGroupRoleException(msg.toString());
2428 }
2429
2430
2438 @Override
2439 public UserGroupRole fetchByG_R_Last(long groupId, long roleId,
2440 OrderByComparator<UserGroupRole> orderByComparator) {
2441 int count = countByG_R(groupId, roleId);
2442
2443 if (count == 0) {
2444 return null;
2445 }
2446
2447 List<UserGroupRole> list = findByG_R(groupId, roleId, count - 1, count,
2448 orderByComparator);
2449
2450 if (!list.isEmpty()) {
2451 return list.get(0);
2452 }
2453
2454 return null;
2455 }
2456
2457
2467 @Override
2468 public UserGroupRole[] findByG_R_PrevAndNext(
2469 UserGroupRolePK userGroupRolePK, long groupId, long roleId,
2470 OrderByComparator<UserGroupRole> orderByComparator)
2471 throws NoSuchUserGroupRoleException {
2472 UserGroupRole userGroupRole = findByPrimaryKey(userGroupRolePK);
2473
2474 Session session = null;
2475
2476 try {
2477 session = openSession();
2478
2479 UserGroupRole[] array = new UserGroupRoleImpl[3];
2480
2481 array[0] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2482 roleId, orderByComparator, true);
2483
2484 array[1] = userGroupRole;
2485
2486 array[2] = getByG_R_PrevAndNext(session, userGroupRole, groupId,
2487 roleId, orderByComparator, false);
2488
2489 return array;
2490 }
2491 catch (Exception e) {
2492 throw processException(e);
2493 }
2494 finally {
2495 closeSession(session);
2496 }
2497 }
2498
2499 protected UserGroupRole getByG_R_PrevAndNext(Session session,
2500 UserGroupRole userGroupRole, long groupId, long roleId,
2501 OrderByComparator<UserGroupRole> orderByComparator, boolean previous) {
2502 StringBundler query = null;
2503
2504 if (orderByComparator != null) {
2505 query = new StringBundler(6 +
2506 (orderByComparator.getOrderByFields().length * 6));
2507 }
2508 else {
2509 query = new StringBundler(3);
2510 }
2511
2512 query.append(_SQL_SELECT_USERGROUPROLE_WHERE);
2513
2514 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2515
2516 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2517
2518 if (orderByComparator != null) {
2519 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2520
2521 if (orderByConditionFields.length > 0) {
2522 query.append(WHERE_AND);
2523 }
2524
2525 for (int i = 0; i < orderByConditionFields.length; i++) {
2526 query.append(_ORDER_BY_ENTITY_ALIAS);
2527 query.append(orderByConditionFields[i]);
2528
2529 if ((i + 1) < orderByConditionFields.length) {
2530 if (orderByComparator.isAscending() ^ previous) {
2531 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2532 }
2533 else {
2534 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2535 }
2536 }
2537 else {
2538 if (orderByComparator.isAscending() ^ previous) {
2539 query.append(WHERE_GREATER_THAN);
2540 }
2541 else {
2542 query.append(WHERE_LESSER_THAN);
2543 }
2544 }
2545 }
2546
2547 query.append(ORDER_BY_CLAUSE);
2548
2549 String[] orderByFields = orderByComparator.getOrderByFields();
2550
2551 for (int i = 0; i < orderByFields.length; i++) {
2552 query.append(_ORDER_BY_ENTITY_ALIAS);
2553 query.append(orderByFields[i]);
2554
2555 if ((i + 1) < orderByFields.length) {
2556 if (orderByComparator.isAscending() ^ previous) {
2557 query.append(ORDER_BY_ASC_HAS_NEXT);
2558 }
2559 else {
2560 query.append(ORDER_BY_DESC_HAS_NEXT);
2561 }
2562 }
2563 else {
2564 if (orderByComparator.isAscending() ^ previous) {
2565 query.append(ORDER_BY_ASC);
2566 }
2567 else {
2568 query.append(ORDER_BY_DESC);
2569 }
2570 }
2571 }
2572 }
2573 else {
2574 query.append(UserGroupRoleModelImpl.ORDER_BY_JPQL);
2575 }
2576
2577 String sql = query.toString();
2578
2579 Query q = session.createQuery(sql);
2580
2581 q.setFirstResult(0);
2582 q.setMaxResults(2);
2583
2584 QueryPos qPos = QueryPos.getInstance(q);
2585
2586 qPos.add(groupId);
2587
2588 qPos.add(roleId);
2589
2590 if (orderByComparator != null) {
2591 Object[] values = orderByComparator.getOrderByConditionValues(userGroupRole);
2592
2593 for (Object value : values) {
2594 qPos.add(value);
2595 }
2596 }
2597
2598 List<UserGroupRole> list = q.list();
2599
2600 if (list.size() == 2) {
2601 return list.get(1);
2602 }
2603 else {
2604 return null;
2605 }
2606 }
2607
2608
2614 @Override
2615 public void removeByG_R(long groupId, long roleId) {
2616 for (UserGroupRole userGroupRole : findByG_R(groupId, roleId,
2617 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2618 remove(userGroupRole);
2619 }
2620 }
2621
2622
2629 @Override
2630 public int countByG_R(long groupId, long roleId) {
2631 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_R;
2632
2633 Object[] finderArgs = new Object[] { groupId, roleId };
2634
2635 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2636
2637 if (count == null) {
2638 StringBundler query = new StringBundler(3);
2639
2640 query.append(_SQL_COUNT_USERGROUPROLE_WHERE);
2641
2642 query.append(_FINDER_COLUMN_G_R_GROUPID_2);
2643
2644 query.append(_FINDER_COLUMN_G_R_ROLEID_2);
2645
2646 String sql = query.toString();
2647
2648 Session session = null;
2649
2650 try {
2651 session = openSession();
2652
2653 Query q = session.createQuery(sql);
2654
2655 QueryPos qPos = QueryPos.getInstance(q);
2656
2657 qPos.add(groupId);
2658
2659 qPos.add(roleId);
2660
2661 count = (Long)q.uniqueResult();
2662
2663 finderCache.putResult(finderPath, finderArgs, count);
2664 }
2665 catch (Exception e) {
2666 finderCache.removeResult(finderPath, finderArgs);
2667
2668 throw processException(e);
2669 }
2670 finally {
2671 closeSession(session);
2672 }
2673 }
2674
2675 return count.intValue();
2676 }
2677
2678 private static final String _FINDER_COLUMN_G_R_GROUPID_2 = "userGroupRole.id.groupId = ? AND ";
2679 private static final String _FINDER_COLUMN_G_R_ROLEID_2 = "userGroupRole.id.roleId = ?";
2680
2681 public UserGroupRolePersistenceImpl() {
2682 setModelClass(UserGroupRole.class);
2683 }
2684
2685
2690 @Override
2691 public void cacheResult(UserGroupRole userGroupRole) {
2692 entityCache.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2693 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2694 userGroupRole);
2695
2696 userGroupRole.resetOriginalValues();
2697 }
2698
2699
2704 @Override
2705 public void cacheResult(List<UserGroupRole> userGroupRoles) {
2706 for (UserGroupRole userGroupRole : userGroupRoles) {
2707 if (entityCache.getResult(
2708 UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2709 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey()) == null) {
2710 cacheResult(userGroupRole);
2711 }
2712 else {
2713 userGroupRole.resetOriginalValues();
2714 }
2715 }
2716 }
2717
2718
2725 @Override
2726 public void clearCache() {
2727 entityCache.clearCache(UserGroupRoleImpl.class);
2728
2729 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2730 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2731 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2732 }
2733
2734
2741 @Override
2742 public void clearCache(UserGroupRole userGroupRole) {
2743 entityCache.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2744 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2745
2746 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2747 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2748 }
2749
2750 @Override
2751 public void clearCache(List<UserGroupRole> userGroupRoles) {
2752 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2753 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2754
2755 for (UserGroupRole userGroupRole : userGroupRoles) {
2756 entityCache.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2757 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey());
2758 }
2759 }
2760
2761
2767 @Override
2768 public UserGroupRole create(UserGroupRolePK userGroupRolePK) {
2769 UserGroupRole userGroupRole = new UserGroupRoleImpl();
2770
2771 userGroupRole.setNew(true);
2772 userGroupRole.setPrimaryKey(userGroupRolePK);
2773
2774 return userGroupRole;
2775 }
2776
2777
2784 @Override
2785 public UserGroupRole remove(UserGroupRolePK userGroupRolePK)
2786 throws NoSuchUserGroupRoleException {
2787 return remove((Serializable)userGroupRolePK);
2788 }
2789
2790
2797 @Override
2798 public UserGroupRole remove(Serializable primaryKey)
2799 throws NoSuchUserGroupRoleException {
2800 Session session = null;
2801
2802 try {
2803 session = openSession();
2804
2805 UserGroupRole userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2806 primaryKey);
2807
2808 if (userGroupRole == null) {
2809 if (_log.isWarnEnabled()) {
2810 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2811 }
2812
2813 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2814 primaryKey);
2815 }
2816
2817 return remove(userGroupRole);
2818 }
2819 catch (NoSuchUserGroupRoleException nsee) {
2820 throw nsee;
2821 }
2822 catch (Exception e) {
2823 throw processException(e);
2824 }
2825 finally {
2826 closeSession(session);
2827 }
2828 }
2829
2830 @Override
2831 protected UserGroupRole removeImpl(UserGroupRole userGroupRole) {
2832 userGroupRole = toUnwrappedModel(userGroupRole);
2833
2834 Session session = null;
2835
2836 try {
2837 session = openSession();
2838
2839 if (!session.contains(userGroupRole)) {
2840 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
2841 userGroupRole.getPrimaryKeyObj());
2842 }
2843
2844 if (userGroupRole != null) {
2845 session.delete(userGroupRole);
2846 }
2847 }
2848 catch (Exception e) {
2849 throw processException(e);
2850 }
2851 finally {
2852 closeSession(session);
2853 }
2854
2855 if (userGroupRole != null) {
2856 clearCache(userGroupRole);
2857 }
2858
2859 return userGroupRole;
2860 }
2861
2862 @Override
2863 public UserGroupRole updateImpl(UserGroupRole userGroupRole) {
2864 userGroupRole = toUnwrappedModel(userGroupRole);
2865
2866 boolean isNew = userGroupRole.isNew();
2867
2868 UserGroupRoleModelImpl userGroupRoleModelImpl = (UserGroupRoleModelImpl)userGroupRole;
2869
2870 Session session = null;
2871
2872 try {
2873 session = openSession();
2874
2875 if (userGroupRole.isNew()) {
2876 session.save(userGroupRole);
2877
2878 userGroupRole.setNew(false);
2879 }
2880 else {
2881 userGroupRole = (UserGroupRole)session.merge(userGroupRole);
2882 }
2883 }
2884 catch (Exception e) {
2885 throw processException(e);
2886 }
2887 finally {
2888 closeSession(session);
2889 }
2890
2891 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2892
2893 if (isNew || !UserGroupRoleModelImpl.COLUMN_BITMASK_ENABLED) {
2894 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2895 }
2896
2897 else {
2898 if ((userGroupRoleModelImpl.getColumnBitmask() &
2899 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2900 Object[] args = new Object[] {
2901 userGroupRoleModelImpl.getOriginalUserId()
2902 };
2903
2904 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2905 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2906 args);
2907
2908 args = new Object[] { userGroupRoleModelImpl.getUserId() };
2909
2910 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2911 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2912 args);
2913 }
2914
2915 if ((userGroupRoleModelImpl.getColumnBitmask() &
2916 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2917 Object[] args = new Object[] {
2918 userGroupRoleModelImpl.getOriginalGroupId()
2919 };
2920
2921 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2922 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2923 args);
2924
2925 args = new Object[] { userGroupRoleModelImpl.getGroupId() };
2926
2927 finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2928 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2929 args);
2930 }
2931
2932 if ((userGroupRoleModelImpl.getColumnBitmask() &
2933 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID.getColumnBitmask()) != 0) {
2934 Object[] args = new Object[] {
2935 userGroupRoleModelImpl.getOriginalRoleId()
2936 };
2937
2938 finderCache.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2939 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2940 args);
2941
2942 args = new Object[] { userGroupRoleModelImpl.getRoleId() };
2943
2944 finderCache.removeResult(FINDER_PATH_COUNT_BY_ROLEID, args);
2945 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ROLEID,
2946 args);
2947 }
2948
2949 if ((userGroupRoleModelImpl.getColumnBitmask() &
2950 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G.getColumnBitmask()) != 0) {
2951 Object[] args = new Object[] {
2952 userGroupRoleModelImpl.getOriginalUserId(),
2953 userGroupRoleModelImpl.getOriginalGroupId()
2954 };
2955
2956 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2957 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2958 args);
2959
2960 args = new Object[] {
2961 userGroupRoleModelImpl.getUserId(),
2962 userGroupRoleModelImpl.getGroupId()
2963 };
2964
2965 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_G, args);
2966 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_G,
2967 args);
2968 }
2969
2970 if ((userGroupRoleModelImpl.getColumnBitmask() &
2971 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R.getColumnBitmask()) != 0) {
2972 Object[] args = new Object[] {
2973 userGroupRoleModelImpl.getOriginalGroupId(),
2974 userGroupRoleModelImpl.getOriginalRoleId()
2975 };
2976
2977 finderCache.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2978 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2979 args);
2980
2981 args = new Object[] {
2982 userGroupRoleModelImpl.getGroupId(),
2983 userGroupRoleModelImpl.getRoleId()
2984 };
2985
2986 finderCache.removeResult(FINDER_PATH_COUNT_BY_G_R, args);
2987 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_R,
2988 args);
2989 }
2990 }
2991
2992 entityCache.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
2993 UserGroupRoleImpl.class, userGroupRole.getPrimaryKey(),
2994 userGroupRole, false);
2995
2996 userGroupRole.resetOriginalValues();
2997
2998 return userGroupRole;
2999 }
3000
3001 protected UserGroupRole toUnwrappedModel(UserGroupRole userGroupRole) {
3002 if (userGroupRole instanceof UserGroupRoleImpl) {
3003 return userGroupRole;
3004 }
3005
3006 UserGroupRoleImpl userGroupRoleImpl = new UserGroupRoleImpl();
3007
3008 userGroupRoleImpl.setNew(userGroupRole.isNew());
3009 userGroupRoleImpl.setPrimaryKey(userGroupRole.getPrimaryKey());
3010
3011 userGroupRoleImpl.setMvccVersion(userGroupRole.getMvccVersion());
3012 userGroupRoleImpl.setUserId(userGroupRole.getUserId());
3013 userGroupRoleImpl.setGroupId(userGroupRole.getGroupId());
3014 userGroupRoleImpl.setRoleId(userGroupRole.getRoleId());
3015
3016 return userGroupRoleImpl;
3017 }
3018
3019
3026 @Override
3027 public UserGroupRole findByPrimaryKey(Serializable primaryKey)
3028 throws NoSuchUserGroupRoleException {
3029 UserGroupRole userGroupRole = fetchByPrimaryKey(primaryKey);
3030
3031 if (userGroupRole == null) {
3032 if (_log.isWarnEnabled()) {
3033 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3034 }
3035
3036 throw new NoSuchUserGroupRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3037 primaryKey);
3038 }
3039
3040 return userGroupRole;
3041 }
3042
3043
3050 @Override
3051 public UserGroupRole findByPrimaryKey(UserGroupRolePK userGroupRolePK)
3052 throws NoSuchUserGroupRoleException {
3053 return findByPrimaryKey((Serializable)userGroupRolePK);
3054 }
3055
3056
3062 @Override
3063 public UserGroupRole fetchByPrimaryKey(Serializable primaryKey) {
3064 UserGroupRole userGroupRole = (UserGroupRole)entityCache.getResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
3065 UserGroupRoleImpl.class, primaryKey);
3066
3067 if (userGroupRole == _nullUserGroupRole) {
3068 return null;
3069 }
3070
3071 if (userGroupRole == null) {
3072 Session session = null;
3073
3074 try {
3075 session = openSession();
3076
3077 userGroupRole = (UserGroupRole)session.get(UserGroupRoleImpl.class,
3078 primaryKey);
3079
3080 if (userGroupRole != null) {
3081 cacheResult(userGroupRole);
3082 }
3083 else {
3084 entityCache.putResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
3085 UserGroupRoleImpl.class, primaryKey, _nullUserGroupRole);
3086 }
3087 }
3088 catch (Exception e) {
3089 entityCache.removeResult(UserGroupRoleModelImpl.ENTITY_CACHE_ENABLED,
3090 UserGroupRoleImpl.class, primaryKey);
3091
3092 throw processException(e);
3093 }
3094 finally {
3095 closeSession(session);
3096 }
3097 }
3098
3099 return userGroupRole;
3100 }
3101
3102
3108 @Override
3109 public UserGroupRole fetchByPrimaryKey(UserGroupRolePK userGroupRolePK) {
3110 return fetchByPrimaryKey((Serializable)userGroupRolePK);
3111 }
3112
3113 @Override
3114 public Map<Serializable, UserGroupRole> fetchByPrimaryKeys(
3115 Set<Serializable> primaryKeys) {
3116 if (primaryKeys.isEmpty()) {
3117 return Collections.emptyMap();
3118 }
3119
3120 Map<Serializable, UserGroupRole> map = new HashMap<Serializable, UserGroupRole>();
3121
3122 for (Serializable primaryKey : primaryKeys) {
3123 UserGroupRole userGroupRole = fetchByPrimaryKey(primaryKey);
3124
3125 if (userGroupRole != null) {
3126 map.put(primaryKey, userGroupRole);
3127 }
3128 }
3129
3130 return map;
3131 }
3132
3133
3138 @Override
3139 public List<UserGroupRole> findAll() {
3140 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3141 }
3142
3143
3154 @Override
3155 public List<UserGroupRole> findAll(int start, int end) {
3156 return findAll(start, end, null);
3157 }
3158
3159
3171 @Override
3172 public List<UserGroupRole> findAll(int start, int end,
3173 OrderByComparator<UserGroupRole> orderByComparator) {
3174 return findAll(start, end, orderByComparator, true);
3175 }
3176
3177
3190 @Override
3191 public List<UserGroupRole> findAll(int start, int end,
3192 OrderByComparator<UserGroupRole> orderByComparator,
3193 boolean retrieveFromCache) {
3194 boolean pagination = true;
3195 FinderPath finderPath = null;
3196 Object[] finderArgs = null;
3197
3198 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3199 (orderByComparator == null)) {
3200 pagination = false;
3201 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3202 finderArgs = FINDER_ARGS_EMPTY;
3203 }
3204 else {
3205 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3206 finderArgs = new Object[] { start, end, orderByComparator };
3207 }
3208
3209 List<UserGroupRole> list = null;
3210
3211 if (retrieveFromCache) {
3212 list = (List<UserGroupRole>)finderCache.getResult(finderPath,
3213 finderArgs, this);
3214 }
3215
3216 if (list == null) {
3217 StringBundler query = null;
3218 String sql = null;
3219
3220 if (orderByComparator != null) {
3221 query = new StringBundler(2 +
3222 (orderByComparator.getOrderByFields().length * 3));
3223
3224 query.append(_SQL_SELECT_USERGROUPROLE);
3225
3226 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3227 orderByComparator);
3228
3229 sql = query.toString();
3230 }
3231 else {
3232 sql = _SQL_SELECT_USERGROUPROLE;
3233
3234 if (pagination) {
3235 sql = sql.concat(UserGroupRoleModelImpl.ORDER_BY_JPQL);
3236 }
3237 }
3238
3239 Session session = null;
3240
3241 try {
3242 session = openSession();
3243
3244 Query q = session.createQuery(sql);
3245
3246 if (!pagination) {
3247 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3248 start, end, false);
3249
3250 Collections.sort(list);
3251
3252 list = Collections.unmodifiableList(list);
3253 }
3254 else {
3255 list = (List<UserGroupRole>)QueryUtil.list(q, getDialect(),
3256 start, end);
3257 }
3258
3259 cacheResult(list);
3260
3261 finderCache.putResult(finderPath, finderArgs, list);
3262 }
3263 catch (Exception e) {
3264 finderCache.removeResult(finderPath, finderArgs);
3265
3266 throw processException(e);
3267 }
3268 finally {
3269 closeSession(session);
3270 }
3271 }
3272
3273 return list;
3274 }
3275
3276
3280 @Override
3281 public void removeAll() {
3282 for (UserGroupRole userGroupRole : findAll()) {
3283 remove(userGroupRole);
3284 }
3285 }
3286
3287
3292 @Override
3293 public int countAll() {
3294 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3295 FINDER_ARGS_EMPTY, this);
3296
3297 if (count == null) {
3298 Session session = null;
3299
3300 try {
3301 session = openSession();
3302
3303 Query q = session.createQuery(_SQL_COUNT_USERGROUPROLE);
3304
3305 count = (Long)q.uniqueResult();
3306
3307 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3308 count);
3309 }
3310 catch (Exception e) {
3311 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3312 FINDER_ARGS_EMPTY);
3313
3314 throw processException(e);
3315 }
3316 finally {
3317 closeSession(session);
3318 }
3319 }
3320
3321 return count.intValue();
3322 }
3323
3324 @Override
3325 protected Map<String, Integer> getTableColumnsMap() {
3326 return UserGroupRoleModelImpl.TABLE_COLUMNS_MAP;
3327 }
3328
3329
3332 public void afterPropertiesSet() {
3333 }
3334
3335 public void destroy() {
3336 entityCache.removeCache(UserGroupRoleImpl.class.getName());
3337 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3338 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3339 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3340 }
3341
3342 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3343 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3344 private static final String _SQL_SELECT_USERGROUPROLE = "SELECT userGroupRole FROM UserGroupRole userGroupRole";
3345 private static final String _SQL_SELECT_USERGROUPROLE_WHERE = "SELECT userGroupRole FROM UserGroupRole userGroupRole WHERE ";
3346 private static final String _SQL_COUNT_USERGROUPROLE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole";
3347 private static final String _SQL_COUNT_USERGROUPROLE_WHERE = "SELECT COUNT(userGroupRole) FROM UserGroupRole userGroupRole WHERE ";
3348 private static final String _ORDER_BY_ENTITY_ALIAS = "userGroupRole.";
3349 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserGroupRole exists with the primary key ";
3350 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserGroupRole exists with the key {";
3351 private static final Log _log = LogFactoryUtil.getLog(UserGroupRolePersistenceImpl.class);
3352 private static final UserGroupRole _nullUserGroupRole = new UserGroupRoleImpl() {
3353 @Override
3354 public Object clone() {
3355 return this;
3356 }
3357
3358 @Override
3359 public CacheModel<UserGroupRole> toCacheModel() {
3360 return _nullUserGroupRoleCacheModel;
3361 }
3362 };
3363
3364 private static final CacheModel<UserGroupRole> _nullUserGroupRoleCacheModel = new NullCacheModel();
3365
3366 private static class NullCacheModel implements CacheModel<UserGroupRole>,
3367 MVCCModel {
3368 @Override
3369 public long getMvccVersion() {
3370 return -1;
3371 }
3372
3373 @Override
3374 public void setMvccVersion(long mvccVersion) {
3375 }
3376
3377 @Override
3378 public UserGroupRole toEntityModel() {
3379 return _nullUserGroupRole;
3380 }
3381 }
3382 }