55
55
import org .springframework .data .mongodb .MongoDatabaseUtils ;
56
56
import org .springframework .data .mongodb .SessionSynchronization ;
57
57
import org .springframework .data .mongodb .core .BulkOperations .BulkMode ;
58
+ import org .springframework .data .mongodb .core .CollectionPreparerSupport .CollectionPreparerDelegate ;
58
59
import org .springframework .data .mongodb .core .DefaultBulkOperations .BulkOperationContext ;
59
60
import org .springframework .data .mongodb .core .EntityOperations .AdaptibleEntity ;
60
61
import org .springframework .data .mongodb .core .QueryOperations .AggregationDefinition ;
@@ -1120,7 +1121,8 @@ public long estimatedCount(String collectionName) {
1120
1121
return doEstimatedCount (CollectionPreparerDelegate .of (this ), collectionName , new EstimatedDocumentCountOptions ());
1121
1122
}
1122
1123
1123
- protected long doEstimatedCount (CollectionPreparer collectionPreparer , String collectionName ,
1124
+ protected long doEstimatedCount (CollectionPreparer <MongoCollection <Document >> collectionPreparer ,
1125
+ String collectionName ,
1124
1126
EstimatedDocumentCountOptions options ) {
1125
1127
return execute (collectionName ,
1126
1128
collection -> collectionPreparer .prepare (collection ).estimatedDocumentCount (options ));
@@ -1137,11 +1139,10 @@ public long exactCount(Query query, @Nullable Class<?> entityClass, String colle
1137
1139
return doExactCount (createDelegate (query ), collectionName , mappedQuery , options );
1138
1140
}
1139
1141
1140
- protected long doExactCount (CollectionPreparer collectionPreparer , String collectionName , Document filter ,
1141
- CountOptions options ) {
1142
- return execute (collectionName ,
1143
- collection -> collectionPreparer .prepare (collection ).countDocuments (CountQuery .of (filter ).toQueryDocument (),
1144
- options ));
1142
+ protected long doExactCount (CollectionPreparer <MongoCollection <Document >> collectionPreparer , String collectionName ,
1143
+ Document filter , CountOptions options ) {
1144
+ return execute (collectionName , collection -> collectionPreparer .prepare (collection )
1145
+ .countDocuments (CountQuery .of (filter ).toQueryDocument (), options ));
1145
1146
}
1146
1147
1147
1148
protected boolean countCanBeEstimated (Document filter , CountOptions options ) {
@@ -1202,7 +1203,7 @@ protected void ensureNotCollectionLike(@Nullable Object source) {
1202
1203
protected MongoCollection <Document > prepareCollection (MongoCollection <Document > collection ) {
1203
1204
1204
1205
if (this .readPreference != null && this .readPreference != collection .getReadPreference ()) {
1205
- collection = collection .withReadPreference (readPreference );
1206
+ return collection .withReadPreference (readPreference );
1206
1207
}
1207
1208
1208
1209
return collection ;
@@ -2401,8 +2402,7 @@ protected <T> T doFindOne(CollectionPreparer collectionPreparer, String collecti
2401
2402
@ Nullable
2402
2403
@ SuppressWarnings ("ConstantConditions" )
2403
2404
protected <T > T doFindOne (CollectionPreparer collectionPreparer , String collectionName , Document query ,
2404
- Document fields , CursorPreparer preparer ,
2405
- Class <T > entityClass ) {
2405
+ Document fields , CursorPreparer preparer , Class <T > entityClass ) {
2406
2406
2407
2407
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
2408
2408
@@ -2449,15 +2449,13 @@ protected <T> List<T> doFind(CollectionPreparer collectionPreparer, String colle
2449
2449
* @return the {@link List} of converted objects.
2450
2450
*/
2451
2451
protected <T > List <T > doFind (CollectionPreparer collectionPreparer , String collectionName , Document query ,
2452
- Document fields , Class <T > entityClass ,
2453
- CursorPreparer preparer ) {
2452
+ Document fields , Class <T > entityClass , CursorPreparer preparer ) {
2454
2453
return doFind (collectionPreparer , collectionName , query , fields , entityClass , preparer ,
2455
2454
new ReadDocumentCallback <>(mongoConverter , entityClass , collectionName ));
2456
2455
}
2457
2456
2458
2457
protected <S , T > List <T > doFind (CollectionPreparer collectionPreparer , String collectionName , Document query ,
2459
- Document fields , Class <S > entityClass ,
2460
- @ Nullable CursorPreparer preparer , DocumentCallback <T > objectCallback ) {
2458
+ Document fields , Class <S > entityClass , @ Nullable CursorPreparer preparer , DocumentCallback <T > objectCallback ) {
2461
2459
2462
2460
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
2463
2461
@@ -2481,8 +2479,7 @@ protected <S, T> List<T> doFind(CollectionPreparer collectionPreparer, String co
2481
2479
* @since 2.0
2482
2480
*/
2483
2481
<S , T > List <T > doFind (CollectionPreparer collectionPreparer , String collectionName , Document query , Document fields ,
2484
- Class <S > sourceClass ,
2485
- Class <T > targetClass , CursorPreparer preparer ) {
2482
+ Class <S > sourceClass , Class <T > targetClass , CursorPreparer preparer ) {
2486
2483
2487
2484
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (sourceClass );
2488
2485
EntityProjection <T , S > projection = operations .introspectProjection (targetClass , sourceClass );
@@ -2571,8 +2568,7 @@ Document getMappedValidator(Validator validator, Class<?> domainType) {
2571
2568
*/
2572
2569
@ SuppressWarnings ("ConstantConditions" )
2573
2570
protected <T > T doFindAndRemove (CollectionPreparer collectionPreparer , String collectionName , Document query ,
2574
- Document fields , Document sort ,
2575
- @ Nullable Collation collation , Class <T > entityClass ) {
2571
+ Document fields , Document sort , @ Nullable Collation collation , Class <T > entityClass ) {
2576
2572
2577
2573
EntityReader <? super T , Bson > readerToUse = this .mongoConverter ;
2578
2574
@@ -2583,16 +2579,15 @@ protected <T> T doFindAndRemove(CollectionPreparer collectionPreparer, String co
2583
2579
2584
2580
MongoPersistentEntity <?> entity = mappingContext .getPersistentEntity (entityClass );
2585
2581
2586
- return executeFindOneInternal (
2587
- new FindAndRemoveCallback (collectionPreparer , queryMapper .getMappedObject (query , entity ), fields , sort ,
2588
- collation ),
2582
+ return executeFindOneInternal (new FindAndRemoveCallback (collectionPreparer ,
2583
+ queryMapper .getMappedObject (query , entity ), fields , sort , collation ),
2589
2584
new ReadDocumentCallback <>(readerToUse , entityClass , collectionName ), collectionName );
2590
2585
}
2591
2586
2592
2587
@ SuppressWarnings ("ConstantConditions" )
2593
2588
protected <T > T doFindAndModify (CollectionPreparer collectionPreparer , String collectionName , Document query ,
2594
- Document fields , Document sort ,
2595
- Class < T > entityClass , UpdateDefinition update , @ Nullable FindAndModifyOptions options ) {
2589
+ Document fields , Document sort , Class < T > entityClass , UpdateDefinition update ,
2590
+ @ Nullable FindAndModifyOptions options ) {
2596
2591
2597
2592
EntityReader <? super T , Bson > readerToUse = this .mongoConverter ;
2598
2593
@@ -2639,15 +2634,13 @@ protected <T> T doFindAndModify(CollectionPreparer collectionPreparer, String co
2639
2634
*/
2640
2635
@ Nullable
2641
2636
protected <T > T doFindAndReplace (CollectionPreparer collectionPreparer , String collectionName , Document mappedQuery ,
2642
- Document mappedFields ,
2643
- Document mappedSort , @ Nullable com .mongodb .client .model .Collation collation , Class <?> entityType ,
2644
- Document replacement , FindAndReplaceOptions options , Class <T > resultType ) {
2637
+ Document mappedFields , Document mappedSort , @ Nullable com .mongodb .client .model .Collation collation ,
2638
+ Class <?> entityType , Document replacement , FindAndReplaceOptions options , Class <T > resultType ) {
2645
2639
2646
2640
EntityProjection <T , ?> projection = operations .introspectProjection (resultType , entityType );
2647
2641
2648
2642
return doFindAndReplace (collectionPreparer , collectionName , mappedQuery , mappedFields , mappedSort , collation ,
2649
- entityType , replacement ,
2650
- options , projection );
2643
+ entityType , replacement , options , projection );
2651
2644
}
2652
2645
2653
2646
CollectionPreparerDelegate createDelegate (Query query ) {
@@ -2672,9 +2665,8 @@ CollectionPreparerDelegate createDelegate(Query query) {
2672
2665
*/
2673
2666
@ Nullable
2674
2667
private <T > T doFindAndReplace (CollectionPreparer collectionPreparer , String collectionName , Document mappedQuery ,
2675
- Document mappedFields ,
2676
- Document mappedSort , @ Nullable com .mongodb .client .model .Collation collation , Class <?> entityType ,
2677
- Document replacement , FindAndReplaceOptions options , EntityProjection <T , ?> projection ) {
2668
+ Document mappedFields , Document mappedSort , @ Nullable com .mongodb .client .model .Collation collation ,
2669
+ Class <?> entityType , Document replacement , FindAndReplaceOptions options , EntityProjection <T , ?> projection ) {
2678
2670
2679
2671
if (LOGGER .isDebugEnabled ()) {
2680
2672
LOGGER
@@ -2685,10 +2677,9 @@ private <T> T doFindAndReplace(CollectionPreparer collectionPreparer, String col
2685
2677
serializeToJsonSafely (mappedSort ), entityType , serializeToJsonSafely (replacement ), collectionName ));
2686
2678
}
2687
2679
2688
- return executeFindOneInternal (
2689
- new FindAndReplaceCallback (collectionPreparer , mappedQuery , mappedFields , mappedSort , replacement , collation ,
2690
- options ),
2691
- new ProjectingReadCallback <>(mongoConverter , projection , collectionName ), collectionName );
2680
+ return executeFindOneInternal (new FindAndReplaceCallback (collectionPreparer , mappedQuery , mappedFields , mappedSort ,
2681
+ replacement , collation , options ), new ProjectingReadCallback <>(mongoConverter , projection , collectionName ),
2682
+ collectionName );
2692
2683
}
2693
2684
2694
2685
/**
@@ -2858,12 +2849,13 @@ static RuntimeException potentiallyConvertRuntimeException(RuntimeException ex,
2858
2849
*/
2859
2850
private static class FindOneCallback implements CollectionCallback <Document > {
2860
2851
2861
- private final CollectionPreparer collectionPreparer ;
2852
+ private final CollectionPreparer < MongoCollection < Document >> collectionPreparer ;
2862
2853
private final Document query ;
2863
2854
private final Optional <Document > fields ;
2864
2855
private final CursorPreparer cursorPreparer ;
2865
2856
2866
- FindOneCallback (CollectionPreparer collectionPreparer , Document query , Document fields , CursorPreparer preparer ) {
2857
+ FindOneCallback (CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query , Document fields ,
2858
+ CursorPreparer preparer ) {
2867
2859
2868
2860
this .collectionPreparer = collectionPreparer ;
2869
2861
this .query = query ;
@@ -2902,12 +2894,13 @@ public Document doInCollection(MongoCollection<Document> collection) throws Mong
2902
2894
*/
2903
2895
private static class FindCallback implements CollectionCallback <FindIterable <Document >> {
2904
2896
2905
- private final CollectionPreparer collectionPreparer ;
2897
+ private final CollectionPreparer < MongoCollection < Document >> collectionPreparer ;
2906
2898
private final Document query ;
2907
2899
private final Document fields ;
2908
2900
private final @ Nullable com .mongodb .client .model .Collation collation ;
2909
2901
2910
- public FindCallback (CollectionPreparer collectionPreparer , Document query , Document fields ,
2902
+ public FindCallback (CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query ,
2903
+ Document fields ,
2911
2904
@ Nullable com .mongodb .client .model .Collation collation ) {
2912
2905
2913
2906
Assert .notNull (query , "Query must not be null" );
@@ -2970,13 +2963,14 @@ public Boolean doInCollection(MongoCollection<Document> collection) throws Mongo
2970
2963
*/
2971
2964
private static class FindAndRemoveCallback implements CollectionCallback <Document > {
2972
2965
2973
- private final CollectionPreparer collectionPreparer ;
2966
+ private final CollectionPreparer < MongoCollection < Document >> collectionPreparer ;
2974
2967
private final Document query ;
2975
2968
private final Document fields ;
2976
2969
private final Document sort ;
2977
2970
private final Optional <Collation > collation ;
2978
2971
2979
- FindAndRemoveCallback (CollectionPreparer collectionPreparer , Document query , Document fields , Document sort ,
2972
+ FindAndRemoveCallback (CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query ,
2973
+ Document fields , Document sort ,
2980
2974
@ Nullable Collation collation ) {
2981
2975
this .collectionPreparer = collectionPreparer ;
2982
2976
@@ -2998,15 +2992,16 @@ public Document doInCollection(MongoCollection<Document> collection) throws Mong
2998
2992
2999
2993
private static class FindAndModifyCallback implements CollectionCallback <Document > {
3000
2994
3001
- private final CollectionPreparer collectionPreparer ;
2995
+ private final CollectionPreparer < MongoCollection < Document >> collectionPreparer ;
3002
2996
private final Document query ;
3003
2997
private final Document fields ;
3004
2998
private final Document sort ;
3005
2999
private final Object update ;
3006
3000
private final List <Document > arrayFilters ;
3007
3001
private final FindAndModifyOptions options ;
3008
3002
3009
- FindAndModifyCallback (CollectionPreparer collectionPreparer , Document query , Document fields , Document sort ,
3003
+ FindAndModifyCallback (CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query ,
3004
+ Document fields , Document sort ,
3010
3005
Object update , List <Document > arrayFilters , FindAndModifyOptions options ) {
3011
3006
3012
3007
this .collectionPreparer = collectionPreparer ;
@@ -3056,15 +3051,16 @@ public Document doInCollection(MongoCollection<Document> collection) throws Mong
3056
3051
*/
3057
3052
private static class FindAndReplaceCallback implements CollectionCallback <Document > {
3058
3053
3059
- private final CollectionPreparer collectionPreparer ;
3054
+ private final CollectionPreparer < MongoCollection < Document >> collectionPreparer ;
3060
3055
private final Document query ;
3061
3056
private final Document fields ;
3062
3057
private final Document sort ;
3063
3058
private final Document update ;
3064
3059
private final @ Nullable com .mongodb .client .model .Collation collation ;
3065
3060
private final FindAndReplaceOptions options ;
3066
3061
3067
- FindAndReplaceCallback (CollectionPreparer collectionPreparer , Document query , Document fields , Document sort ,
3062
+ FindAndReplaceCallback (CollectionPreparer <MongoCollection <Document >> collectionPreparer , Document query ,
3063
+ Document fields , Document sort ,
3068
3064
Document update , @ Nullable com .mongodb .client .model .Collation collation , FindAndReplaceOptions options ) {
3069
3065
this .collectionPreparer = collectionPreparer ;
3070
3066
this .query = query ;
0 commit comments