@@ -200,33 +200,33 @@ DeleteContext deleteSingleContext(Query query) {
200
200
}
201
201
202
202
/**
203
- * Create a new {@link AggregateContext } for the given {@link Aggregation}.
203
+ * Create a new {@link AggregationDefinition } for the given {@link Aggregation}.
204
204
*
205
205
* @param aggregation must not be {@literal null}.
206
206
* @param inputType fallback mapping type in case of untyped aggregation. Can be {@literal null}.
207
- * @return new instance of {@link AggregateContext }.
207
+ * @return new instance of {@link AggregationDefinition }.
208
208
* @since 3.2
209
209
*/
210
- AggregateContext createAggregationContext (Aggregation aggregation , @ Nullable Class <?> inputType ) {
211
- return new AggregateContext (aggregation , inputType );
210
+ AggregationDefinition createAggregation (Aggregation aggregation , @ Nullable Class <?> inputType ) {
211
+ return new AggregationDefinition (aggregation , inputType );
212
212
}
213
213
214
214
/**
215
- * Create a new {@link AggregateContext } for the given {@link Aggregation}.
215
+ * Create a new {@link AggregationDefinition } for the given {@link Aggregation}.
216
216
*
217
217
* @param aggregation must not be {@literal null}.
218
218
* @param aggregationOperationContext the {@link AggregationOperationContext} to use. Can be {@literal null}.
219
- * @return new instance of {@link AggregateContext }.
219
+ * @return new instance of {@link AggregationDefinition }.
220
220
* @since 3.2
221
221
*/
222
- AggregateContext createAggregationContext (Aggregation aggregation ,
222
+ AggregationDefinition createAggregation (Aggregation aggregation ,
223
223
@ Nullable AggregationOperationContext aggregationOperationContext ) {
224
- return new AggregateContext (aggregation , aggregationOperationContext );
224
+ return new AggregationDefinition (aggregation , aggregationOperationContext );
225
225
}
226
226
227
227
/**
228
228
* {@link QueryContext} encapsulates common tasks required to convert a {@link Query} into its MongoDB document
229
- * representation, mapping fieldnames , as well as determinging and applying {@link Collation collations}.
229
+ * representation, mapping field names , as well as determining and applying {@link Collation collations}.
230
230
*
231
231
* @author Christoph Strobl
232
232
*/
@@ -235,7 +235,7 @@ class QueryContext {
235
235
private final Query query ;
236
236
237
237
/**
238
- * Create new a {@link QueryContext} instance from the given {@literal query} (can be eihter a {@link Query} or a
238
+ * Create new a {@link QueryContext} instance from the given {@literal query} (can be either a {@link Query} or a
239
239
* plain {@link Document}.
240
240
*
241
241
* @param query can be {@literal null}.
@@ -305,7 +305,7 @@ Document getMappedFields(@Nullable MongoPersistentEntity<?> entity, Class<?> tar
305
305
mappingContext .getRequiredPersistentEntity (targetType ));
306
306
}
307
307
308
- if (entity != null && entity .hasTextScoreProperty () && !query .getQueryObject ().containsKey ("$text" )) {
308
+ if (entity .hasTextScoreProperty () && !query .getQueryObject ().containsKey ("$text" )) {
309
309
mappedFields .remove (entity .getTextScoreProperty ().getFieldName ());
310
310
}
311
311
@@ -793,19 +793,19 @@ boolean isMulti() {
793
793
}
794
794
795
795
/**
796
- * A context class that encapsulates common tasks required when running {@literal aggregations}.
796
+ * A value object that encapsulates common tasks required when running {@literal aggregations}.
797
797
*
798
798
* @since 3.2
799
799
*/
800
- class AggregateContext {
800
+ class AggregationDefinition {
801
801
802
- private Aggregation aggregation ;
803
- private Lazy <AggregationOperationContext > aggregationOperationContext ;
804
- private Lazy <List <Document >> pipeline ;
805
- private @ Nullable Class <?> inputType ;
802
+ private final Aggregation aggregation ;
803
+ private final Lazy <AggregationOperationContext > aggregationOperationContext ;
804
+ private final Lazy <List <Document >> pipeline ;
805
+ private final @ Nullable Class <?> inputType ;
806
806
807
807
/**
808
- * Creates new instance of {@link AggregateContext } extracting the input type from either the
808
+ * Creates new instance of {@link AggregationDefinition } extracting the input type from either the
809
809
* {@link org.springframework.data.mongodb.core.aggregation.Aggregation} in case of a {@link TypedAggregation} or
810
810
* the given {@literal aggregationOperationContext} if present. <br />
811
811
* Creates a new {@link AggregationOperationContext} if none given, based on the {@link Aggregation} input type and
@@ -815,21 +815,25 @@ class AggregateContext {
815
815
* @param aggregation the source aggregation.
816
816
* @param aggregationOperationContext can be {@literal null}.
817
817
*/
818
- AggregateContext (Aggregation aggregation , @ Nullable AggregationOperationContext aggregationOperationContext ) {
818
+ AggregationDefinition (Aggregation aggregation , @ Nullable AggregationOperationContext aggregationOperationContext ) {
819
819
820
820
this .aggregation = aggregation ;
821
+
821
822
if (aggregation instanceof TypedAggregation ) {
822
- this .inputType = ((TypedAggregation ) aggregation ).getInputType ();
823
+ this .inputType = ((TypedAggregation <?> ) aggregation ).getInputType ();
823
824
} else if (aggregationOperationContext instanceof TypeBasedAggregationOperationContext ) {
824
825
this .inputType = ((TypeBasedAggregationOperationContext ) aggregationOperationContext ).getType ();
826
+ } else {
827
+ this .inputType = null ;
825
828
}
829
+
826
830
this .aggregationOperationContext = Lazy .of (() -> aggregationOperationContext != null ? aggregationOperationContext
827
831
: aggregationUtil .createAggregationContext (aggregation , getInputType ()));
828
832
this .pipeline = Lazy .of (() -> aggregationUtil .createPipeline (this .aggregation , getAggregationOperationContext ()));
829
833
}
830
834
831
835
/**
832
- * Creates new instance of {@link AggregateContext } extracting the input type from either the
836
+ * Creates new instance of {@link AggregationDefinition } extracting the input type from either the
833
837
* {@link org.springframework.data.mongodb.core.aggregation.Aggregation} in case of a {@link TypedAggregation} or
834
838
* the given {@literal aggregationOperationContext} if present. <br />
835
839
* Creates a new {@link AggregationOperationContext} based on the {@link Aggregation} input type and the desired
@@ -839,12 +843,12 @@ class AggregateContext {
839
843
* @param aggregation the source aggregation.
840
844
* @param inputType can be {@literal null}.
841
845
*/
842
- AggregateContext (Aggregation aggregation , @ Nullable Class <?> inputType ) {
846
+ AggregationDefinition (Aggregation aggregation , @ Nullable Class <?> inputType ) {
843
847
844
848
this .aggregation = aggregation ;
845
849
846
850
if (aggregation instanceof TypedAggregation ) {
847
- this .inputType = ((TypedAggregation ) aggregation ).getInputType ();
851
+ this .inputType = ((TypedAggregation <?> ) aggregation ).getInputType ();
848
852
} else {
849
853
this .inputType = inputType ;
850
854
}
@@ -887,9 +891,5 @@ AggregationOperationContext getAggregationOperationContext() {
887
891
Class <?> getInputType () {
888
892
return inputType ;
889
893
}
890
-
891
- Document getAggregationCommand (String collectionName ) {
892
- return aggregationUtil .createCommand (collectionName , aggregation , getAggregationOperationContext ());
893
- }
894
894
}
895
895
}
0 commit comments