1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -107,15 +107,9 @@ public abstract class QueryByExampleDataFetcher<T> {
107
107
108
108
private final GraphQlArgumentBinder argumentBinder ;
109
109
110
- @ Nullable
111
- private final CursorStrategy <ScrollPosition > cursorStrategy ;
112
-
113
-
114
- QueryByExampleDataFetcher (
115
- TypeInformation <T > domainType , @ Nullable CursorStrategy <ScrollPosition > cursorStrategy ) {
116
110
111
+ QueryByExampleDataFetcher (TypeInformation <T > domainType ) {
117
112
this .domainType = domainType ;
118
- this .cursorStrategy = cursorStrategy ;
119
113
this .argumentBinder = new GraphQlArgumentBinder ();
120
114
}
121
115
@@ -174,11 +168,6 @@ protected Collection<String> buildPropertyPaths(DataFetchingFieldSelectionSet se
174
168
return Collections .emptyList ();
175
169
}
176
170
177
- protected ScrollSubrange buildScrollSubrange (DataFetchingEnvironment environment ) {
178
- Assert .state (this .cursorStrategy != null , "Expected CursorStrategy" );
179
- return RepositoryUtils .buildScrollSubrange (environment , this .cursorStrategy );
180
- }
181
-
182
171
@ Override
183
172
public String toString () {
184
173
return getDescription ();
@@ -434,7 +423,7 @@ public Builder<T, R> cursorStrategy(@Nullable CursorStrategy<ScrollPosition> cur
434
423
/**
435
424
* Configure a {@link ScrollSubrange} to use when a paginated request does
436
425
* not specify a cursor and/or a count of items.
437
- * <p>By default, this is {@link OffsetScrollPosition#initial ()} with a
426
+ * <p>By default, this is {@link OffsetScrollPosition#offset ()} with a
438
427
* count of 20.
439
428
* @return a new {@link Builder} instance with all previously configured
440
429
* options and {@code Sort} applied
@@ -468,7 +457,7 @@ public DataFetcher<R> single() {
468
457
* Build a {@link DataFetcher} to fetch many object instances.
469
458
*/
470
459
public DataFetcher <Iterable <R >> many () {
471
- return new ManyEntityFetcher <>(this .executor , this .domainType , this .resultType , null , this .sort );
460
+ return new ManyEntityFetcher <>(this .executor , this .domainType , this .resultType , this .sort );
472
461
}
473
462
474
463
/**
@@ -581,7 +570,7 @@ public ReactiveBuilder<T, R> cursorStrategy(@Nullable CursorStrategy<ScrollPosit
581
570
/**
582
571
* Configure a {@link ScrollSubrange} to use when a paginated request does
583
572
* not specify a cursor and/or a count of items.
584
- * <p>By default, this is {@link OffsetScrollPosition#initial ()} with a
573
+ * <p>By default, this is {@link OffsetScrollPosition#offset ()} with a
585
574
* count of 20.
586
575
* @return a new {@link Builder} instance with all previously configured
587
576
* options and {@code Sort} applied
@@ -666,7 +655,7 @@ private static class SingleEntityFetcher<T, R>
666
655
SingleEntityFetcher (
667
656
QueryByExampleExecutor <T > executor , TypeInformation <T > domainType , Class <R > resultType , Sort sort ) {
668
657
669
- super (domainType , null );
658
+ super (domainType );
670
659
this .executor = executor ;
671
660
this .resultType = resultType ;
672
661
this .sort = sort ;
@@ -712,10 +701,10 @@ private static class ManyEntityFetcher<T, R>
712
701
private final Sort sort ;
713
702
714
703
ManyEntityFetcher (
715
- QueryByExampleExecutor <T > executor , TypeInformation <T > domainType , Class < R > resultType ,
716
- @ Nullable CursorStrategy < ScrollPosition > cursorStrategy , Sort sort ) {
704
+ QueryByExampleExecutor <T > executor , TypeInformation <T > domainType ,
705
+ Class < R > resultType , Sort sort ) {
717
706
718
- super (domainType , cursorStrategy );
707
+ super (domainType );
719
708
this .executor = executor ;
720
709
this .resultType = resultType ;
721
710
this .sort = sort ;
@@ -756,23 +745,24 @@ protected Iterable<R> getResult(FluentQuery.FetchableFluentQuery<R> queryToUse,
756
745
757
746
private static class ScrollableEntityFetcher <T , R > extends ManyEntityFetcher <T , R > {
758
747
748
+ private final CursorStrategy <ScrollPosition > cursorStrategy ;
749
+
759
750
private final ScrollSubrange defaultSubrange ;
760
751
761
752
private final ResolvableType scrollableResultType ;
762
753
763
754
ScrollableEntityFetcher (
764
755
QueryByExampleExecutor <T > executor , TypeInformation <T > domainType , Class <R > resultType ,
765
- CursorStrategy <ScrollPosition > cursorStrategy ,
766
- ScrollSubrange defaultSubrange ,
767
- Sort sort ) {
756
+ CursorStrategy <ScrollPosition > cursorStrategy , ScrollSubrange defaultSubrange , Sort sort ) {
768
757
769
- super (executor , domainType , resultType , cursorStrategy , sort );
758
+ super (executor , domainType , resultType , sort );
770
759
771
760
Assert .notNull (cursorStrategy , "CursorStrategy is required" );
772
761
Assert .notNull (defaultSubrange , "Default ScrollSubrange is required" );
773
762
Assert .isTrue (defaultSubrange .position ().isPresent (), "Default ScrollPosition is required" );
774
763
Assert .isTrue (defaultSubrange .count ().isPresent (), "Default scroll limit is required" );
775
764
765
+ this .cursorStrategy = cursorStrategy ;
776
766
this .defaultSubrange = defaultSubrange ;
777
767
this .scrollableResultType = ResolvableType .forClassWithGenerics (Window .class , resultType );
778
768
}
@@ -785,10 +775,10 @@ public ResolvableType getReturnType() {
785
775
@ SuppressWarnings ("OptionalGetWithoutIsPresent" )
786
776
@ Override
787
777
protected Iterable <R > getResult (FluentQuery .FetchableFluentQuery <R > queryToUse , DataFetchingEnvironment env ) {
788
- ScrollSubrange subrange = buildScrollSubrange (env );
789
- int limit = subrange .count ().orElse ( this . defaultSubrange . count (). getAsInt () );
790
- ScrollPosition position = subrange .position ().orElse ( this . defaultSubrange . position (). get () );
791
- return queryToUse .limit (limit ).scroll (position );
778
+ ScrollSubrange range = RepositoryUtils . getScrollSubrange (env , this . cursorStrategy , this . defaultSubrange );
779
+ int count = range .count ().getAsInt ();
780
+ ScrollPosition position = range .position ().get ();
781
+ return queryToUse .limit (count ).scroll (position );
792
782
}
793
783
794
784
}
@@ -807,7 +797,7 @@ private static class ReactiveSingleEntityFetcher<T, R>
807
797
ReactiveQueryByExampleExecutor <T > executor , TypeInformation <T > domainType ,
808
798
Class <R > resultType , Sort sort ) {
809
799
810
- super (domainType , null );
800
+ super (domainType );
811
801
this .executor = executor ;
812
802
this .resultType = resultType ;
813
803
this .sort = sort ;
@@ -855,7 +845,7 @@ private static class ReactiveManyEntityFetcher<T, R>
855
845
ReactiveQueryByExampleExecutor <T > executor , TypeInformation <T > domainType ,
856
846
Class <R > resultType , Sort sort ) {
857
847
858
- super (domainType , null );
848
+ super (domainType );
859
849
this .executor = executor ;
860
850
this .resultType = resultType ;
861
851
this .sort = sort ;
@@ -899,6 +889,8 @@ private static class ReactiveScrollableEntityFetcher<T, R>
899
889
900
890
private final ResolvableType scrollableResultType ;
901
891
892
+ private final CursorStrategy <ScrollPosition > cursorStrategy ;
893
+
902
894
private final ScrollSubrange defaultSubrange ;
903
895
904
896
private final Sort sort ;
@@ -907,7 +899,7 @@ private static class ReactiveScrollableEntityFetcher<T, R>
907
899
ReactiveQueryByExampleExecutor <T > executor , TypeInformation <T > domainType , Class <R > resultType ,
908
900
CursorStrategy <ScrollPosition > cursorStrategy , ScrollSubrange defaultSubrange , Sort sort ) {
909
901
910
- super (domainType , cursorStrategy );
902
+ super (domainType );
911
903
912
904
Assert .notNull (cursorStrategy , "CursorStrategy is required" );
913
905
Assert .notNull (defaultSubrange , "Default ScrollSubrange is required" );
@@ -917,6 +909,7 @@ private static class ReactiveScrollableEntityFetcher<T, R>
917
909
this .executor = executor ;
918
910
this .resultType = resultType ;
919
911
this .scrollableResultType = ResolvableType .forClassWithGenerics (Iterable .class , resultType );
912
+ this .cursorStrategy = cursorStrategy ;
920
913
this .defaultSubrange = defaultSubrange ;
921
914
this .sort = sort ;
922
915
}
@@ -943,11 +936,10 @@ public Mono<Iterable<R>> get(DataFetchingEnvironment env) throws BindException {
943
936
queryToUse = queryToUse .project (buildPropertyPaths (env .getSelectionSet (), this .resultType ));
944
937
}
945
938
946
- ScrollSubrange subrange = buildScrollSubrange (env );
947
- int limit = subrange .count ().orElse (this .defaultSubrange .count ().getAsInt ());
948
- ScrollPosition position = subrange .position ().orElse (this .defaultSubrange .position ().get ());
949
-
950
- return queryToUse .limit (limit ).scroll (position ).map (Function .identity ());
939
+ ScrollSubrange range = RepositoryUtils .getScrollSubrange (env , this .cursorStrategy , this .defaultSubrange );
940
+ int count = range .count ().getAsInt ();
941
+ ScrollPosition position = range .position ().get ();
942
+ return queryToUse .limit (count ).scroll (position ).map (Function .identity ());
951
943
});
952
944
}
953
945
0 commit comments