1515 */
1616package org .springframework .data .mongodb .repository .query ;
1717
18- import java .io .Serializable ;
1918import java .lang .annotation .Annotation ;
2019import java .lang .reflect .Method ;
21- import java .util .Arrays ;
22- import java .util .List ;
2320import java .util .Map ;
2421import java .util .Optional ;
22+ import java .util .function .Function ;
2523
2624import 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 ;
3025import org .springframework .data .mapping .context .MappingContext ;
3126import org .springframework .data .mongodb .core .annotation .Collation ;
3227import org .springframework .data .mongodb .core .mapping .MongoPersistentEntity ;
6560 */
6661public class MongoQueryMethod extends QueryMethod {
6762
68- @ SuppressWarnings ("unchecked" ) private static final List <Class <? extends Serializable >> GEO_NEAR_RESULTS = Arrays
69- .asList (GeoResult .class , GeoResults .class , GeoPage .class );
70-
7163 private final Method method ;
7264 private final MappingContext <? extends MongoPersistentEntity <?>, MongoPersistentProperty > mappingContext ;
7365 private final Map <Class <? extends Annotation >, Optional <Annotation >> annotationCache ;
7466
7567 private @ Nullable MongoEntityMetadata <?> metadata ;
76- private Lazy <Boolean > isModifying = Lazy .of (this ::resolveModifyingQueryIndicators );
68+ private final Lazy <Boolean > isModifying = Lazy .of (this ::resolveModifyingQueryIndicators );
7769
7870 /**
7971 * Creates a new {@link MongoQueryMethod} from the given {@link Method}.
@@ -85,8 +77,22 @@ public class MongoQueryMethod extends QueryMethod {
8577 */
8678 public MongoQueryMethod (Method method , RepositoryMetadata metadata , ProjectionFactory projectionFactory ,
8779 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 ) {
8894
89- super (method , metadata , projectionFactory );
95+ super (method , metadata , projectionFactory , parametersFunction );
9096
9197 Assert .notNull (mappingContext , "MappingContext must not be null" );
9298
@@ -95,11 +101,6 @@ public MongoQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFa
95101 this .annotationCache = new ConcurrentReferenceHashMap <>();
96102 }
97103
98- @ Override
99- protected MongoParameters createParameters (ParametersSource parametersSource ) {
100- return new MongoParameters (parametersSource , isGeoNearQuery (parametersSource .getMethod ()));
101- }
102-
103104 /**
104105 * Returns whether the method has an annotated query.
105106 *
@@ -186,25 +187,7 @@ public MongoParameters getParameters() {
186187 * @return
187188 */
188189 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 );
208191 }
209192
210193 /**
0 commit comments