111
111
import org .springframework .data .mongodb .core .timeseries .Granularity ;
112
112
import org .springframework .data .mongodb .core .validation .Validator ;
113
113
import org .springframework .data .projection .EntityProjection ;
114
- import org .springframework .data .projection .ProjectionFactory ;
115
114
import org .springframework .data .util .CloseableIterator ;
116
115
import org .springframework .data .util .Lazy ;
117
116
import org .springframework .data .util .Optionals ;
118
- import org .springframework .data .util .TypeInformation ;
119
117
import org .springframework .lang .Contract ;
120
118
import org .springframework .util .Assert ;
121
119
import org .springframework .util .ClassUtils ;
@@ -498,7 +496,7 @@ protected <T> Stream<T> doStream(Query query, Class<?> entityType, String collec
498
496
return doStream (query , entityType , collectionName , returnType , QueryResultConverter .entity ());
499
497
}
500
498
501
- @ SuppressWarnings ({"ConstantConditions" , "NullAway" })
499
+ @ SuppressWarnings ({ "ConstantConditions" , "NullAway" })
502
500
<T , R > Stream <R > doStream (Query query , Class <?> entityType , String collectionName , Class <T > returnType ,
503
501
QueryResultConverter <? super T , ? extends R > resultConverter ) {
504
502
@@ -523,8 +521,7 @@ <T, R> Stream<R> doStream(Query query, Class<?> entityType, String collectionNam
523
521
524
522
DocumentCallback <R > resultReader = getResultReader (projection , collectionName , resultConverter );
525
523
526
- return new CloseableIterableCursorAdapter <>(cursor , exceptionTranslator ,
527
- resultReader ).stream ();
524
+ return new CloseableIterableCursorAdapter <>(cursor , exceptionTranslator , resultReader ).stream ();
528
525
});
529
526
}
530
527
@@ -1152,7 +1149,7 @@ <T, R> GeoResults<R> doGeoNear(NearQuery near, Class<?> domainType, String colle
1152
1149
1153
1150
@ Override
1154
1151
public <T > @ Nullable T findAndModify (Query query , UpdateDefinition update , FindAndModifyOptions options ,
1155
- Class <T > entityClass , String collectionName ) {
1152
+ Class <T > entityClass , String collectionName ) {
1156
1153
return findAndModify (query , update , options , entityClass , collectionName , QueryResultConverter .entity ());
1157
1154
}
1158
1155
@@ -1182,12 +1179,13 @@ <T, R> GeoResults<R> doGeoNear(NearQuery near, Class<?> domainType, String colle
1182
1179
1183
1180
@ Override
1184
1181
public <S , T > @ Nullable T findAndReplace (Query query , S replacement , FindAndReplaceOptions options ,
1185
- Class <S > entityType , String collectionName , Class <T > resultType ) {
1186
- return findAndReplace (query , replacement , options , entityType , collectionName , resultType , QueryResultConverter .entity ());
1182
+ Class <S > entityType , String collectionName , Class <T > resultType ) {
1183
+ return findAndReplace (query , replacement , options , entityType , collectionName , resultType ,
1184
+ QueryResultConverter .entity ());
1187
1185
}
1188
1186
1189
- <S , T , R > @ Nullable R findAndReplace (Query query , S replacement , FindAndReplaceOptions options ,
1190
- Class < S > entityType , String collectionName , Class <T > resultType , QueryResultConverter <? super T , ? extends R > resultConverter ) {
1187
+ <S , T , R > @ Nullable R findAndReplace (Query query , S replacement , FindAndReplaceOptions options , Class < S > entityType ,
1188
+ String collectionName , Class <T > resultType , QueryResultConverter <? super T , ? extends R > resultConverter ) {
1191
1189
1192
1190
Assert .notNull (query , "Query must not be null" );
1193
1191
Assert .notNull (replacement , "Replacement must not be null" );
@@ -1215,7 +1213,8 @@ <T, R> GeoResults<R> doGeoNear(NearQuery near, Class<?> domainType, String colle
1215
1213
maybeCallBeforeSave (replacement , mappedReplacement , collectionName );
1216
1214
1217
1215
R saved = doFindAndReplace (collectionPreparer , collectionName , mappedQuery , mappedFields , mappedSort ,
1218
- queryContext .getCollation (entityType ).orElse (null ), entityType , mappedReplacement , options , projection , resultConverter );
1216
+ queryContext .getCollation (entityType ).orElse (null ), entityType , mappedReplacement , options , projection ,
1217
+ resultConverter );
1219
1218
1220
1219
if (saved != null ) {
1221
1220
maybeEmitEvent (new AfterSaveEvent <>(saved , mappedReplacement , collectionName ));
@@ -1508,7 +1507,7 @@ protected <T> Collection<T> doInsertBatch(String collectionName, Collection<? ex
1508
1507
initialized = maybeCallBeforeSave (initialized , document , collectionName );
1509
1508
1510
1509
MappedDocument mappedDocument = queryOperations .createInsertContext (MappedDocument .of (document ))
1511
- .prepareId (uninitialized .getClass ());
1510
+ .prepareId (uninitialized .getClass ());
1512
1511
1513
1512
documentList .add (mappedDocument .getDocument ());
1514
1513
initializedBatchToSave .add (initialized );
@@ -2221,14 +2220,14 @@ public T doWith(Document object) {
2221
2220
}
2222
2221
};
2223
2222
2224
- List <T > result = doFind (collectionName , createDelegate (query ), query .getQueryObject (), query .getFieldsObject (), entityClass ,
2225
- new QueryCursorPreparer (query , entityClass ), callback );
2223
+ List <T > result = doFind (collectionName , createDelegate (query ), query .getQueryObject (), query .getFieldsObject (),
2224
+ entityClass , new QueryCursorPreparer (query , entityClass ), callback );
2226
2225
2227
2226
if (!CollectionUtils .isEmpty (result )) {
2228
2227
2229
2228
Criteria [] criterias = ids .stream () //
2230
- .map (it -> Criteria .where ("_id" ).is (it )) //
2231
- .toArray (Criteria []::new );
2229
+ .map (it -> Criteria .where ("_id" ).is (it )) //
2230
+ .toArray (Criteria []::new );
2232
2231
2233
2232
Query removeQuery = new Query (criterias .length == 1 ? criterias [0 ] : new Criteria ().orOperator (criterias ));
2234
2233
if (query .hasReadPreference ()) {
@@ -2270,20 +2269,19 @@ protected <O> AggregationResults<O> doAggregate(Aggregation aggregation, String
2270
2269
return doAggregate (aggregation , collectionName , outputType , QueryResultConverter .entity (), context );
2271
2270
}
2272
2271
2273
- @ SuppressWarnings ({"ConstantConditions" , "NullAway" })
2272
+ @ SuppressWarnings ({ "ConstantConditions" , "NullAway" })
2274
2273
<T , O > AggregationResults <O > doAggregate (Aggregation aggregation , String collectionName , Class <T > outputType ,
2275
2274
QueryResultConverter <? super T , ? extends O > resultConverter , AggregationOperationContext context ) {
2276
2275
2277
2276
final DocumentCallback <O > callback ;
2278
- if (aggregation instanceof TypedAggregation <?> ta && outputType .isInterface ()) {
2277
+ if (aggregation instanceof TypedAggregation <?> ta && outputType .isInterface ()) {
2279
2278
EntityProjection <T , ?> projection = operations .introspectProjection (outputType , ta .getInputType ());
2280
2279
ProjectingReadCallback cb = new ProjectingReadCallback (mongoConverter , projection , collectionName );
2281
- callback = new QueryResultConverterCallback <>(resultConverter ,
2282
- cb );
2280
+ callback = new QueryResultConverterCallback <>(resultConverter , cb );
2283
2281
} else {
2284
2282
2285
2283
callback = new QueryResultConverterCallback <>(resultConverter ,
2286
- new ReadDocumentCallback <>(mongoConverter , outputType , collectionName ));
2284
+ new ReadDocumentCallback <>(mongoConverter , outputType , collectionName ));
2287
2285
}
2288
2286
2289
2287
AggregationOptions options = aggregation .getOptions ();
@@ -2370,8 +2368,7 @@ protected <O> Stream<O> aggregateStream(Aggregation aggregation, String collecti
2370
2368
2371
2369
@ SuppressWarnings ({ "ConstantConditions" , "NullAway" })
2372
2370
<T , O > Stream <O > doAggregateStream (Aggregation aggregation , String collectionName , Class <T > outputType ,
2373
- QueryResultConverter <? super T , ? extends O > resultConverter ,
2374
- @ Nullable AggregationOperationContext context ) {
2371
+ QueryResultConverter <? super T , ? extends O > resultConverter , @ Nullable AggregationOperationContext context ) {
2375
2372
2376
2373
Assert .notNull (aggregation , "Aggregation pipeline must not be null" );
2377
2374
Assert .hasText (collectionName , "Collection name must not be null or empty" );
@@ -2649,9 +2646,8 @@ private CreateCollectionOptions getCreateCollectionOptions(Document document) {
2649
2646
* @return the converted object or {@literal null} if none exists.
2650
2647
*/
2651
2648
@ Nullable
2652
- protected <T > T doFindOne (String collectionName ,
2653
- CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query , Document fields ,
2654
- Class <T > entityClass ) {
2649
+ protected <T > T doFindOne (String collectionName , CollectionPreparer <MongoCollection <Document >> collectionPreparer ,
2650
+ Document query , Document fields , Class <T > entityClass ) {
2655
2651
return doFindOne (collectionName , collectionPreparer , query , fields , CursorPreparer .NO_OP_PREPARER , entityClass );
2656
2652
}
2657
2653
@@ -2670,9 +2666,8 @@ protected <T> T doFindOne(String collectionName,
2670
2666
*/
2671
2667
@ Nullable
2672
2668
@ SuppressWarnings ("ConstantConditions" )
2673
- protected <T > T doFindOne (String collectionName ,
2674
- CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query , Document fields ,
2675
- CursorPreparer preparer , Class <T > entityClass ) {
2669
+ protected <T > T doFindOne (String collectionName , CollectionPreparer <MongoCollection <Document >> collectionPreparer ,
2670
+ Document query , Document fields , CursorPreparer preparer , Class <T > entityClass ) {
2676
2671
2677
2672
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
2678
2673
@@ -2870,9 +2865,9 @@ Document getMappedValidator(Validator validator, Class<?> domainType) {
2870
2865
2871
2866
@ SuppressWarnings ("ConstantConditions" )
2872
2867
<S , T > @ Nullable T doFindAndModify (CollectionPreparer <MongoCollection <Document >> collectionPreparer ,
2873
- String collectionName ,
2874
- Document query , @ Nullable Document fields , @ Nullable Document sort , Class < S > entityClass , UpdateDefinition update ,
2875
- @ Nullable FindAndModifyOptions options , QueryResultConverter <? super S , ? extends T > resultConverter ) {
2868
+ String collectionName , Document query , @ Nullable Document fields , @ Nullable Document sort , Class < S > entityClass ,
2869
+ UpdateDefinition update , @ Nullable FindAndModifyOptions options ,
2870
+ QueryResultConverter <? super S , ? extends T > resultConverter ) {
2876
2871
2877
2872
if (options == null ) {
2878
2873
options = new FindAndModifyOptions ();
@@ -2894,7 +2889,8 @@ Document getMappedValidator(Validator validator, Class<?> domainType) {
2894
2889
serializeToJsonSafely (mappedUpdate ), collectionName ));
2895
2890
}
2896
2891
2897
- DocumentCallback <T > callback = getResultReader (EntityProjection .nonProjecting (entityClass ), collectionName , resultConverter );
2892
+ DocumentCallback <T > callback = getResultReader (EntityProjection .nonProjecting (entityClass ), collectionName ,
2893
+ resultConverter );
2898
2894
2899
2895
return executeFindOneInternal (
2900
2896
new FindAndModifyCallback (collectionPreparer , mappedQuery , fields , sort , mappedUpdate ,
@@ -2919,8 +2915,7 @@ Document getMappedValidator(Validator validator, Class<?> domainType) {
2919
2915
*/
2920
2916
@ Nullable
2921
2917
protected <S , T > T doFindAndReplace (CollectionPreparer <MongoCollection <Document >> collectionPreparer ,
2922
- String collectionName ,
2923
- Document mappedQuery , Document mappedFields , Document mappedSort ,
2918
+ String collectionName , Document mappedQuery , Document mappedFields , Document mappedSort ,
2924
2919
com .mongodb .client .model .@ Nullable Collation collation , Class <S > entityType , Document replacement ,
2925
2920
FindAndReplaceOptions options , Class <T > resultType ) {
2926
2921
@@ -2963,10 +2958,10 @@ CollectionPreparer<MongoCollection<Document>> createCollectionPreparer(Query que
2963
2958
*/
2964
2959
@ Nullable
2965
2960
private <S , T , R > R doFindAndReplace (CollectionPreparer <MongoCollection <Document >> collectionPreparer ,
2966
- String collectionName ,
2967
- Document mappedQuery , Document mappedFields , Document mappedSort ,
2961
+ String collectionName , Document mappedQuery , Document mappedFields , Document mappedSort ,
2968
2962
com .mongodb .client .model .@ Nullable Collation collation , Class <T > entityType , Document replacement ,
2969
- FindAndReplaceOptions options , EntityProjection <S , T > projection , QueryResultConverter <? super S , ? extends R > resultConverter ) {
2963
+ FindAndReplaceOptions options , EntityProjection <S , T > projection ,
2964
+ QueryResultConverter <? super S , ? extends R > resultConverter ) {
2970
2965
2971
2966
if (LOGGER .isDebugEnabled ()) {
2972
2967
LOGGER
@@ -2979,8 +2974,7 @@ private <S, T, R> R doFindAndReplace(CollectionPreparer<MongoCollection<Document
2979
2974
2980
2975
DocumentCallback <R > callback = getResultReader (projection , collectionName , resultConverter );
2981
2976
return executeFindOneInternal (new FindAndReplaceCallback (collectionPreparer , mappedQuery , mappedFields , mappedSort ,
2982
- replacement , collation , options ),callback ,
2983
- collectionName );
2977
+ replacement , collation , options ), callback , collectionName );
2984
2978
}
2985
2979
2986
2980
@ SuppressWarnings ("NullAway" )
@@ -3158,8 +3152,8 @@ private Document getMappedSortObject(@Nullable Query query, Class<?> type) {
3158
3152
return getMappedSortObject (sortObject , mappingContext .getPersistentEntity (type ));
3159
3153
}
3160
3154
3161
-
3162
- private @ Nullable Document getMappedSortObject ( @ Nullable Document sortObject , @ Nullable MongoPersistentEntity <?> entity ) {
3155
+ private @ Nullable Document getMappedSortObject ( @ Nullable Document sortObject ,
3156
+ @ Nullable MongoPersistentEntity <?> entity ) {
3163
3157
3164
3158
if (ObjectUtils .isEmpty (sortObject )) {
3165
3159
return null ;
@@ -3392,7 +3386,7 @@ private static class FindAndReplaceCallback implements CollectionCallback<Docume
3392
3386
private final Document fields ;
3393
3387
private final Document sort ;
3394
3388
private final Document update ;
3395
- private final com .mongodb .client .model .@ Nullable Collation collation ;
3389
+ private final com .mongodb .client .model .@ Nullable Collation collation ;
3396
3390
private final FindAndReplaceOptions options ;
3397
3391
3398
3392
FindAndReplaceCallback (CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query ,
0 commit comments