|
15 | 15 | */
|
16 | 16 | package org.springframework.data.mongodb.core;
|
17 | 17 |
|
18 |
| -import static org.springframework.data.mongodb.core.query.SerializationUtils.serializeToJsonSafely; |
| 18 | +import static org.springframework.data.mongodb.core.query.SerializationUtils.*; |
19 | 19 |
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.math.BigDecimal;
|
22 | 22 | import java.math.RoundingMode;
|
23 |
| -import java.util.ArrayList; |
24 |
| -import java.util.Collection; |
25 |
| -import java.util.Collections; |
26 |
| -import java.util.HashMap; |
27 |
| -import java.util.Iterator; |
28 |
| -import java.util.LinkedHashSet; |
29 |
| -import java.util.List; |
30 |
| -import java.util.Map; |
31 |
| -import java.util.Optional; |
32 |
| -import java.util.Scanner; |
33 |
| -import java.util.Set; |
| 23 | +import java.util.*; |
34 | 24 | import java.util.concurrent.TimeUnit;
|
35 | 25 | import java.util.function.BiPredicate;
|
36 | 26 | import java.util.stream.Collectors;
|
|
40 | 30 | import org.apache.commons.logging.LogFactory;
|
41 | 31 | import org.bson.Document;
|
42 | 32 | import org.bson.conversions.Bson;
|
43 |
| - |
44 | 33 | import org.jspecify.annotations.Nullable;
|
| 34 | + |
45 | 35 | import org.springframework.beans.BeansException;
|
46 | 36 | import org.springframework.context.ApplicationContext;
|
47 | 37 | import org.springframework.context.ApplicationContextAware;
|
|
106 | 96 | import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
|
107 | 97 | import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
|
108 | 98 | import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
109 |
| -import org.springframework.data.mongodb.core.mapping.event.AfterConvertCallback; |
110 |
| -import org.springframework.data.mongodb.core.mapping.event.AfterConvertEvent; |
111 |
| -import org.springframework.data.mongodb.core.mapping.event.AfterDeleteEvent; |
112 |
| -import org.springframework.data.mongodb.core.mapping.event.AfterLoadEvent; |
113 |
| -import org.springframework.data.mongodb.core.mapping.event.AfterSaveCallback; |
114 |
| -import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent; |
115 |
| -import org.springframework.data.mongodb.core.mapping.event.BeforeConvertCallback; |
116 |
| -import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent; |
117 |
| -import org.springframework.data.mongodb.core.mapping.event.BeforeDeleteEvent; |
118 |
| -import org.springframework.data.mongodb.core.mapping.event.BeforeSaveCallback; |
119 |
| -import org.springframework.data.mongodb.core.mapping.event.BeforeSaveEvent; |
120 |
| -import org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent; |
| 99 | +import org.springframework.data.mongodb.core.mapping.event.*; |
121 | 100 | import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
|
122 | 101 | import org.springframework.data.mongodb.core.mapreduce.MapReduceResults;
|
123 | 102 | import org.springframework.data.mongodb.core.query.BasicQuery;
|
|
157 | 136 | import com.mongodb.client.MongoCursor;
|
158 | 137 | import com.mongodb.client.MongoDatabase;
|
159 | 138 | import com.mongodb.client.MongoIterable;
|
160 |
| -import com.mongodb.client.model.CountOptions; |
161 |
| -import com.mongodb.client.model.CreateCollectionOptions; |
162 |
| -import com.mongodb.client.model.CreateViewOptions; |
163 |
| -import com.mongodb.client.model.DeleteOptions; |
164 |
| -import com.mongodb.client.model.EstimatedDocumentCountOptions; |
165 |
| -import com.mongodb.client.model.FindOneAndDeleteOptions; |
166 |
| -import com.mongodb.client.model.FindOneAndReplaceOptions; |
167 |
| -import com.mongodb.client.model.FindOneAndUpdateOptions; |
168 |
| -import com.mongodb.client.model.ReturnDocument; |
169 |
| -import com.mongodb.client.model.TimeSeriesGranularity; |
170 |
| -import com.mongodb.client.model.TimeSeriesOptions; |
171 |
| -import com.mongodb.client.model.UpdateOptions; |
172 |
| -import com.mongodb.client.model.ValidationAction; |
173 |
| -import com.mongodb.client.model.ValidationLevel; |
174 |
| -import com.mongodb.client.model.ValidationOptions; |
| 139 | +import com.mongodb.client.model.*; |
175 | 140 | import com.mongodb.client.result.DeleteResult;
|
176 | 141 | import com.mongodb.client.result.UpdateResult;
|
177 | 142 |
|
@@ -1148,7 +1113,6 @@ public <T> T findAndModify(Query query, UpdateDefinition update, FindAndModifyOp
|
1148 | 1113 | return findAndModify(query, update, options, entityClass, collectionName, QueryResultConverter.entity());
|
1149 | 1114 | }
|
1150 | 1115 |
|
1151 |
| - |
1152 | 1116 | <S, T> T findAndModify(Query query, UpdateDefinition update, FindAndModifyOptions options,
|
1153 | 1117 | Class<S> entityClass, String collectionName, QueryResultConverter<? super S, ? extends T> resultConverter) {
|
1154 | 1118 |
|
@@ -1179,7 +1143,7 @@ <S, T> T findAndModify(Query query, UpdateDefinition update, FindAndModifyOption
|
1179 | 1143 | return findAndReplace(query, replacement, options, entityType, collectionName, resultType, QueryResultConverter.entity());
|
1180 | 1144 | }
|
1181 | 1145 |
|
1182 |
| - public <S, T, R> @Nullable R findAndReplace(Query query, S replacement, FindAndReplaceOptions options, |
| 1146 | + <S, T, R> @Nullable R findAndReplace(Query query, S replacement, FindAndReplaceOptions options, |
1183 | 1147 | Class<S> entityType, String collectionName, Class<T> resultType, QueryResultConverter<? super T, ? extends R> resultConverter) {
|
1184 | 1148 |
|
1185 | 1149 | Assert.notNull(query, "Query must not be null");
|
@@ -1207,7 +1171,6 @@ <S, T> T findAndModify(Query query, UpdateDefinition update, FindAndModifyOption
|
1207 | 1171 | maybeEmitEvent(new BeforeSaveEvent<>(replacement, mappedReplacement, collectionName));
|
1208 | 1172 | maybeCallBeforeSave(replacement, mappedReplacement, collectionName);
|
1209 | 1173 |
|
1210 |
| - |
1211 | 1174 | R saved = doFindAndReplace(collectionPreparer, collectionName, mappedQuery, mappedFields, mappedSort,
|
1212 | 1175 | queryContext.getCollation(entityType).orElse(null), entityType, mappedReplacement, options, projection, resultConverter);
|
1213 | 1176 |
|
@@ -2203,25 +2166,15 @@ protected <T> List<T> doFindAndDelete(String collectionName, Query query, Class<
|
2203 | 2166 | return doFindAndDelete(collectionName, query, entityClass, QueryResultConverter.entity());
|
2204 | 2167 | }
|
2205 | 2168 |
|
2206 |
| - protected <S,T> List<T> doFindAndDelete(String collectionName, Query query, Class<S> entityClass, QueryResultConverter<? super S, ? extends T> resultConverter) { |
| 2169 | + <S, T> List<T> doFindAndDelete(String collectionName, Query query, Class<S> entityClass, |
| 2170 | + QueryResultConverter<? super S, ? extends T> resultConverter) { |
2207 | 2171 |
|
2208 | 2172 | List<Object> ids = new ArrayList<>();
|
2209 | 2173 |
|
2210 |
| - |
2211 |
| - |
2212 |
| -// QueryResultConverter<S,T> tmpConverter = new QueryResultConverter<S, S>() { |
2213 |
| -// @Override |
2214 |
| -// public S mapDocument(Document document, ConversionResultSupplier<S> reader) { |
2215 |
| -// ids.add(document.get("_id")); |
2216 |
| -// return reader.get(); |
2217 |
| -// } |
2218 |
| -// }.andThen(resultConverter); |
2219 |
| - |
2220 |
| -// DocumentCallback<T> callback = getResultReader(EntityProjection.nonProjecting(entityClass), collectionName, tmpConverter); |
2221 |
| - |
2222 |
| - QueryResultConverterCallback callback = new QueryResultConverterCallback(resultConverter, new ProjectingReadCallback<S,S>(getConverter(), EntityProjection.nonProjecting(entityClass), collectionName)) { |
| 2174 | + QueryResultConverterCallback<S, T> callback = new QueryResultConverterCallback<>(resultConverter, |
| 2175 | + new ProjectingReadCallback<>(getConverter(), EntityProjection.nonProjecting(entityClass), collectionName)) { |
2223 | 2176 | @Override
|
2224 |
| - public Object doWith(Document object) { |
| 2177 | + public T doWith(Document object) { |
2225 | 2178 | ids.add(object.get("_id"));
|
2226 | 2179 | return super.doWith(object);
|
2227 | 2180 | }
|
@@ -2366,7 +2319,7 @@ protected <O> Stream<O> aggregateStream(Aggregation aggregation, String collecti
|
2366 | 2319 | }
|
2367 | 2320 |
|
2368 | 2321 | @SuppressWarnings({ "ConstantConditions", "NullAway" })
|
2369 |
| - protected <T, O> Stream<O> doAggregateStream(Aggregation aggregation, String collectionName, Class<T> outputType, |
| 2322 | + <T, O> Stream<O> doAggregateStream(Aggregation aggregation, String collectionName, Class<T> outputType, |
2370 | 2323 | QueryResultConverter<? super T, ? extends O> resultConverter,
|
2371 | 2324 | @Nullable AggregationOperationContext context) {
|
2372 | 2325 |
|
@@ -2412,7 +2365,8 @@ protected <T, O> Stream<O> doAggregateStream(Aggregation aggregation, String col
|
2412 | 2365 | cursor = cursor.maxTime(options.getMaxTime().toMillis(), TimeUnit.MILLISECONDS);
|
2413 | 2366 | }
|
2414 | 2367 |
|
2415 |
| - Class<?> domainType = aggregation instanceof TypedAggregation typedAggregation ? typedAggregation.getInputType() |
| 2368 | + Class<?> domainType = aggregation instanceof TypedAggregation<?> typedAggregation |
| 2369 | + ? typedAggregation.getInputType() |
2416 | 2370 | : null;
|
2417 | 2371 |
|
2418 | 2372 | Optionals.firstNonEmpty(options::getCollation, //
|
@@ -2863,7 +2817,8 @@ Document getMappedValidator(Validator validator, Class<?> domainType) {
|
2863 | 2817 | }
|
2864 | 2818 |
|
2865 | 2819 | @SuppressWarnings("ConstantConditions")
|
2866 |
| - protected <S, T> @Nullable T doFindAndModify(CollectionPreparer collectionPreparer, String collectionName, |
| 2820 | + <S, T> @Nullable T doFindAndModify(CollectionPreparer<MongoCollection<Document>> collectionPreparer, |
| 2821 | + String collectionName, |
2867 | 2822 | Document query, @Nullable Document fields, @Nullable Document sort, Class<S> entityClass, UpdateDefinition update,
|
2868 | 2823 | @Nullable FindAndModifyOptions options, QueryResultConverter<? super S, ? extends T> resultConverter) {
|
2869 | 2824 |
|
@@ -2911,7 +2866,8 @@ Document getMappedValidator(Validator validator, Class<?> domainType) {
|
2911 | 2866 | * {@literal false} and {@link FindAndReplaceOptions#isUpsert() upsert} is {@literal false}.
|
2912 | 2867 | */
|
2913 | 2868 | @Nullable
|
2914 |
| - protected <S, T> T doFindAndReplace(CollectionPreparer collectionPreparer, String collectionName, |
| 2869 | + protected <S, T> T doFindAndReplace(CollectionPreparer<MongoCollection<Document>> collectionPreparer, |
| 2870 | + String collectionName, |
2915 | 2871 | Document mappedQuery, Document mappedFields, Document mappedSort,
|
2916 | 2872 | com.mongodb.client.model.@Nullable Collation collation, Class<S> entityType, Document replacement,
|
2917 | 2873 | FindAndReplaceOptions options, Class<T> resultType) {
|
@@ -2954,7 +2910,8 @@ CollectionPreparer<MongoCollection<Document>> createCollectionPreparer(Query que
|
2954 | 2910 | * @since 3.4
|
2955 | 2911 | */
|
2956 | 2912 | @Nullable
|
2957 |
| - private <S, T, R> R doFindAndReplace(CollectionPreparer collectionPreparer, String collectionName, |
| 2913 | + private <S, T, R> R doFindAndReplace(CollectionPreparer<MongoCollection<Document>> collectionPreparer, |
| 2914 | + String collectionName, |
2958 | 2915 | Document mappedQuery, Document mappedFields, Document mappedSort,
|
2959 | 2916 | com.mongodb.client.model.@Nullable Collation collation, Class<T> entityType, Document replacement,
|
2960 | 2917 | FindAndReplaceOptions options, EntityProjection<S, T> projection, QueryResultConverter<? super S, ? extends R> resultConverter) {
|
|
0 commit comments