15
15
*/
16
16
package org .springframework .data .mongodb .repository .query ;
17
17
18
- import java .io .Serializable ;
19
18
import java .lang .annotation .Annotation ;
20
19
import java .lang .reflect .Method ;
21
- import java .util .Arrays ;
22
- import java .util .List ;
23
20
import java .util .Map ;
24
21
import java .util .Optional ;
22
+ import java .util .function .Function ;
25
23
26
24
import org .springframework .core .annotation .AnnotatedElementUtils ;
27
- import org .springframework .data .geo .GeoPage ;
28
- import org .springframework .data .geo .GeoResult ;
29
- import org .springframework .data .geo .GeoResults ;
30
25
import org .springframework .data .mapping .context .MappingContext ;
31
26
import org .springframework .data .mongodb .core .annotation .Collation ;
32
27
import org .springframework .data .mongodb .core .mapping .MongoPersistentEntity ;
65
60
*/
66
61
public class MongoQueryMethod extends QueryMethod {
67
62
68
- @ SuppressWarnings ("unchecked" ) private static final List <Class <? extends Serializable >> GEO_NEAR_RESULTS = Arrays
69
- .asList (GeoResult .class , GeoResults .class , GeoPage .class );
70
-
71
63
private final Method method ;
72
64
private final MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ;
73
65
private final Map <Class <? extends Annotation >, Optional <Annotation >> annotationCache ;
74
66
75
67
private @ Nullable MongoEntityMetadata <?> metadata ;
76
- private Lazy <Boolean > isModifying = Lazy .of (this ::resolveModifyingQueryIndicators );
68
+ private final Lazy <Boolean > isModifying = Lazy .of (this ::resolveModifyingQueryIndicators );
77
69
78
70
/**
79
71
* Creates a new {@link MongoQueryMethod} from the given {@link Method}.
@@ -85,8 +77,22 @@ public class MongoQueryMethod extends QueryMethod {
85
77
*/
86
78
public MongoQueryMethod (Method method , RepositoryMetadata metadata , ProjectionFactory projectionFactory ,
87
79
MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ) {
80
+ this (method , metadata , projectionFactory , mappingContext , MongoParameters ::new );
81
+ }
82
+
83
+ /**
84
+ * Creates a new {@link MongoQueryMethod} from the given {@link Method}.
85
+ *
86
+ * @param method must not be {@literal null}.
87
+ * @param metadata must not be {@literal null}.
88
+ * @param projectionFactory must not be {@literal null}.
89
+ * @param mappingContext must not be {@literal null}.
90
+ */
91
+ MongoQueryMethod (Method method , RepositoryMetadata metadata , ProjectionFactory projectionFactory ,
92
+ MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ,
93
+ Function <ParametersSource , ? extends MongoParameters > parametersFunction ) {
88
94
89
- super (method , metadata , projectionFactory );
95
+ super (method , metadata , projectionFactory , parametersFunction );
90
96
91
97
Assert .notNull (mappingContext , "MappingContext must not be null" );
92
98
@@ -95,11 +101,6 @@ public MongoQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFa
95
101
this .annotationCache = new ConcurrentReferenceHashMap <>();
96
102
}
97
103
98
- @ Override
99
- protected MongoParameters createParameters (ParametersSource parametersSource ) {
100
- return new MongoParameters (parametersSource , isGeoNearQuery (parametersSource .getMethod ()));
101
- }
102
-
103
104
/**
104
105
* Returns whether the method has an annotated query.
105
106
*
@@ -186,25 +187,7 @@ public MongoParameters getParameters() {
186
187
* @return
187
188
*/
188
189
public boolean isGeoNearQuery () {
189
- return isGeoNearQuery (this .method );
190
- }
191
-
192
- private boolean isGeoNearQuery (Method method ) {
193
-
194
- Class <?> returnType = method .getReturnType ();
195
-
196
- for (Class <?> type : GEO_NEAR_RESULTS ) {
197
- if (type .isAssignableFrom (returnType )) {
198
- return true ;
199
- }
200
- }
201
-
202
- if (Iterable .class .isAssignableFrom (returnType )) {
203
- TypeInformation <?> from = TypeInformation .fromReturnTypeOf (method );
204
- return GeoResult .class .equals (from .getRequiredComponentType ().getType ());
205
- }
206
-
207
- return false ;
190
+ return MongoParameters .isGeoNearQuery (this .method );
208
191
}
209
192
210
193
/**
0 commit comments