diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoDbFactory.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoDbFactory.java
deleted file mode 100644
index 9356a9e7d..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/MongoDbFactory.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2011-2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.mongodb;
-
-import org.springframework.dao.DataAccessException;
-
-import com.mongodb.client.MongoDatabase;
-
-/**
- * Interface for factories creating {@link MongoDatabase} instances.
- *
- * @author Mark Pollack
- * @author Thomas Darimont
- * @author Christoph Strobl
- * @deprecated since 3.0, use {@link MongoDatabaseFactory} instead.
- */
-@Deprecated
-public interface MongoDbFactory extends MongoDatabaseFactory {
-
- /**
- * Creates a default {@link MongoDatabase} instance.
- *
- * @return never {@literal null}.
- * @throws DataAccessException
- * @deprecated since 3.0. Use {@link #getMongoDatabase()} instead.
- */
- @Deprecated
- default MongoDatabase getDb() throws DataAccessException {
- return getMongoDatabase();
- }
-
- /**
- * Obtain a {@link MongoDatabase} instance to access the database with the given name.
- *
- * @param dbName must not be {@literal null} or empty.
- * @return never {@literal null}.
- * @throws DataAccessException
- * @deprecated since 3.0. Use {@link #getMongoDatabase(String)} instead.
- */
- @Deprecated
- default MongoDatabase getDb(String dbName) throws DataAccessException {
- return getMongoDatabase(dbName);
- }
-}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/AbstractMongoClientConfiguration.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/AbstractMongoClientConfiguration.java
index 96df484aa..ac9a608e3 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/AbstractMongoClientConfiguration.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/AbstractMongoClientConfiguration.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018-2021 the original author or authors.
+ * Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,9 +25,7 @@ import org.springframework.data.mongodb.core.convert.DbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
-import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
-import org.springframework.lang.Nullable;
import com.mongodb.MongoClientSettings;
import com.mongodb.MongoClientSettings.Builder;
@@ -80,24 +78,6 @@ public abstract class AbstractMongoClientConfiguration extends MongoConfiguratio
return new SimpleMongoClientDatabaseFactory(mongoClient(), getDatabaseName());
}
- /**
- * Return the base package to scan for mapped {@link Document}s. Will return the package name of the configuration
- * class' (the concrete class, not this one here) by default. So if you have a {@code com.acme.AppConfig} extending
- * {@link AbstractMongoClientConfiguration} the base package will be considered {@code com.acme} unless the method is
- * overridden to implement alternate behavior.
- *
- * @return the base package to scan for mapped {@link Document} classes or {@literal null} to not enable scanning for
- * entities.
- * @deprecated use {@link #getMappingBasePackages()} instead.
- */
- @Deprecated
- @Nullable
- protected String getMappingBasePackage() {
-
- Package mappingBasePackage = getClass().getPackage();
- return mappingBasePackage == null ? null : mappingBasePackage.getName();
- }
-
/**
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
* {@link #mongoMappingContext(MongoCustomConversions)}. Will get {@link #customConversions()} applied.
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoParsingUtils.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoParsingUtils.java
index 935be9550..48ff485e1 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoParsingUtils.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoParsingUtils.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011-2021 the original author or authors.
+ * Copyright 2011-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,7 +40,6 @@ import org.w3c.dom.Element;
* @author Christoph Strobl
* @author Mark Paluch
*/
-@SuppressWarnings("deprecation")
abstract class MongoParsingUtils {
private MongoParsingUtils() {}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionOptions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionOptions.java
index f86689669..c7b4574a3 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionOptions.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/CollectionOptions.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2010-2021 the original author or authors.
+ * Copyright 2010-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,20 +47,6 @@ public class CollectionOptions {
private ValidationOptions validationOptions;
private @Nullable TimeSeriesOptions timeSeriesOptions;
- /**
- * Constructs a new CollectionOptions instance.
- *
- * @param size the collection size in bytes, this data space is preallocated. Can be {@literal null}.
- * @param maxDocuments the maximum number of documents in the collection. Can be {@literal null}.
- * @param capped true to created a "capped" collection (fixed size with auto-FIFO behavior based on insertion order),
- * false otherwise. Can be {@literal null}.
- * @deprecated since 2.0 please use {@link CollectionOptions#empty()} as entry point.
- */
- @Deprecated
- public CollectionOptions(@Nullable Long size, @Nullable Long maxDocuments, @Nullable Boolean capped) {
- this(size, maxDocuments, capped, null, ValidationOptions.none(), null);
- }
-
private CollectionOptions(@Nullable Long size, @Nullable Long maxDocuments, @Nullable Boolean capped,
@Nullable Collation collation, ValidationOptions validationOptions,
@Nullable TimeSeriesOptions timeSeriesOptions) {
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoClientFactoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoClientFactoryBean.java
index cf218e581..6da2bbebf 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoClientFactoryBean.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoClientFactoryBean.java
@@ -337,6 +337,11 @@ public class MongoClientFactoryBean extends AbstractFactoryBean imp
}
private String getOrDefault(Object value, String defaultValue) {
- return !StringUtils.isEmpty(value) ? value.toString() : defaultValue;
+
+ if(value == null) {
+ return defaultValue;
+ }
+ String sValue = value.toString();
+ return StringUtils.hasText(sValue) ? sValue : defaultValue;
}
}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbFactorySupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbFactorySupport.java
deleted file mode 100644
index ba530d502..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoDbFactorySupport.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2018-2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.mongodb.core;
-
-import org.springframework.dao.support.PersistenceExceptionTranslator;
-
-/**
- * Common base class for usage with both {@link com.mongodb.client.MongoClients} defining common properties such as
- * database name and exception translator.
- *
- * Not intended to be used directly.
- *
- * @author Christoph Strobl
- * @author Mark Paluch
- * @param Client type.
- * @since 2.1
- * @see SimpleMongoClientDatabaseFactory
- * @deprecated since 3.0, use {@link MongoDatabaseFactorySupport} instead.
- */
-@Deprecated
-public abstract class MongoDbFactorySupport extends MongoDatabaseFactorySupport {
-
- /**
- * Create a new {@link MongoDbFactorySupport} object given {@code mongoClient}, {@code databaseName},
- * {@code mongoInstanceCreated} and {@link PersistenceExceptionTranslator}.
- *
- * @param mongoClient must not be {@literal null}.
- * @param databaseName must not be {@literal null} or empty.
- * @param mongoInstanceCreated {@literal true} if the client instance was created by a subclass of
- * {@link MongoDbFactorySupport} to close the client on {@link #destroy()}.
- * @param exceptionTranslator must not be {@literal null}.
- */
- protected MongoDbFactorySupport(C mongoClient, String databaseName, boolean mongoInstanceCreated,
- PersistenceExceptionTranslator exceptionTranslator) {
- super(mongoClient, databaseName, mongoInstanceCreated, exceptionTranslator);
- }
-}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java
index 24a3223de..8cf23c25e 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java
@@ -23,7 +23,6 @@ import java.util.function.Supplier;
import java.util.stream.Stream;
import org.bson.Document;
-
import org.springframework.data.geo.GeoResults;
import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
@@ -34,8 +33,6 @@ import org.springframework.data.mongodb.core.aggregation.TypedAggregation;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.index.IndexOperations;
-import org.springframework.data.mongodb.core.mapreduce.GroupBy;
-import org.springframework.data.mongodb.core.mapreduce.GroupByResults;
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
import org.springframework.data.mongodb.core.mapreduce.MapReduceResults;
import org.springframework.data.mongodb.core.query.BasicQuery;
@@ -431,43 +428,6 @@ public interface MongoOperations extends FluentMongoOperations {
*/
List findAll(Class entityClass, String collectionName);
- /**
- * Execute a group operation over the entire collection. The group operation entity class should match the 'shape' of
- * the returned object that takes int account the initial document structure as well as any finalize functions.
- *
- * @param inputCollectionName the collection where the group operation will read from
- * @param groupBy the conditions under which the group operation will be performed, e.g. keys, initial document,
- * reduce function.
- * @param entityClass The parametrized type of the returned list
- * @return The results of the group operation
- * @deprecated since 2.2. The {@code group} command has been removed in MongoDB Server 4.2.0.
- * Please use {@link #aggregate(TypedAggregation, String, Class) } with a
- * {@link org.springframework.data.mongodb.core.aggregation.GroupOperation} instead.
- */
- @Deprecated
- GroupByResults group(String inputCollectionName, GroupBy groupBy, Class entityClass);
-
- /**
- * Execute a group operation restricting the rows to those which match the provided Criteria. The group operation
- * entity class should match the 'shape' of the returned object that takes int account the initial document structure
- * as well as any finalize functions.
- *
- * @param criteria The criteria that restricts the row that are considered for grouping. If not specified all rows are
- * considered.
- * @param inputCollectionName the collection where the group operation will read from
- * @param groupBy the conditions under which the group operation will be performed, e.g. keys, initial document,
- * reduce function.
- * @param entityClass The parametrized type of the returned list
- * @return The results of the group operation
- * @deprecated since 2.2. The {@code group} command has been removed in MongoDB Server 4.2.0.
- * Please use {@link #aggregate(TypedAggregation, String, Class) } with a
- * {@link org.springframework.data.mongodb.core.aggregation.GroupOperation} and
- * {@link org.springframework.data.mongodb.core.aggregation.MatchOperation} instead.
- */
- @Deprecated
- GroupByResults group(@Nullable Criteria criteria, String inputCollectionName, GroupBy groupBy,
- Class entityClass);
-
/**
* Execute an aggregation operation. The raw results will be mapped to the given entity class. The name of the
* inputCollection is derived from the inputType of the aggregation.
@@ -606,7 +566,9 @@ public interface MongoOperations extends FluentMongoOperations {
* @param reduceFunction The JavaScript reduce function
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
* @return The results of the map reduce operation
+ * @deprecated since MongoDB server version 5.0
*/
+ @Deprecated
MapReduceResults mapReduce(String inputCollectionName, String mapFunction, String reduceFunction,
Class entityClass);
@@ -619,7 +581,9 @@ public interface MongoOperations extends FluentMongoOperations {
* @param mapReduceOptions Options that specify detailed map-reduce behavior.
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
* @return The results of the map reduce operation
+ * @deprecated since MongoDB server version 5.0
*/
+ @Deprecated
MapReduceResults mapReduce(String inputCollectionName, String mapFunction, String reduceFunction,
@Nullable MapReduceOptions mapReduceOptions, Class entityClass);
@@ -633,7 +597,9 @@ public interface MongoOperations extends FluentMongoOperations {
* @param reduceFunction The JavaScript reduce function
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
* @return The results of the map reduce operation
+ * @deprecated since MongoDB server version 5.0
*/
+ @Deprecated
MapReduceResults mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction,
Class entityClass);
@@ -647,7 +613,9 @@ public interface MongoOperations extends FluentMongoOperations {
* @param mapReduceOptions Options that specify detailed map-reduce behavior
* @param entityClass The parametrized type of the returned list. Must not be {@literal null}.
* @return The results of the map reduce operation
+ * @deprecated since MongoDB server version 5.0
*/
+ @Deprecated
MapReduceResults mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction,
@Nullable MapReduceOptions mapReduceOptions, Class entityClass);
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
index 8fb3310ae..84b3983a8 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java
@@ -29,7 +29,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.bson.Document;
import org.bson.conversions.Bson;
-
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -87,13 +86,10 @@ import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.mapping.event.*;
-import org.springframework.data.mongodb.core.mapreduce.GroupBy;
-import org.springframework.data.mongodb.core.mapreduce.GroupByResults;
import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
import org.springframework.data.mongodb.core.mapreduce.MapReduceResults;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Collation;
-import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Meta;
import org.springframework.data.mongodb.core.query.Meta.CursorOption;
import org.springframework.data.mongodb.core.query.NearQuery;
@@ -386,8 +382,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
}
@SuppressWarnings("ConstantConditions")
- protected Stream doStream(Query query, Class> entityType, String collectionName,
- Class returnType) {
+ protected Stream doStream(Query query, Class> entityType, String collectionName, Class returnType) {
Assert.notNull(query, "Query must not be null!");
Assert.notNull(entityType, "Entity type must not be null!");
@@ -399,8 +394,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
MongoPersistentEntity> persistentEntity = mappingContext.getPersistentEntity(entityType);
QueryContext queryContext = queryOperations.createQueryContext(query);
- EntityProjection projection = operations.introspectProjection(returnType,
- entityType);
+ EntityProjection projection = operations.introspectProjection(returnType, entityType);
Document mappedQuery = queryContext.getMappedQuery(persistentEntity);
Document mappedFields = queryContext.getMappedFields(persistentEntity, projection);
@@ -570,7 +564,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@Nullable CollectionOptions collectionOptions) {
Assert.notNull(collectionName, "CollectionName must not be null!");
- return doCreateCollection(collectionName, convertToDocument(collectionOptions));
+ return doCreateCollection(collectionName, convertToDocument(collectionOptions, Object.class));
}
@SuppressWarnings("ConstantConditions")
@@ -836,8 +830,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
.withOptions(AggregationOptions.builder().collation(near.getCollation()).build());
AggregationResults results = aggregate($geoNear, collection, Document.class);
- EntityProjection projection = operations.introspectProjection(returnType,
- domainType);
+ EntityProjection projection = operations.introspectProjection(returnType, domainType);
DocumentCallback> callback = new GeoNearResultDocumentCallback<>(distanceField,
new ProjectingReadCallback<>(mongoConverter, projection, collection), near.getMetric());
@@ -920,8 +913,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityType);
QueryContext queryContext = queryOperations.createQueryContext(query);
- EntityProjection projection = operations.introspectProjection(resultType,
- entityType);
+ EntityProjection projection = operations.introspectProjection(resultType, entityType);
Document mappedQuery = queryContext.getMappedQuery(entity);
Document mappedFields = queryContext.getMappedFields(entity, projection);
Document mappedSort = queryContext.getMappedSort(entity);
@@ -933,8 +925,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
maybeCallBeforeSave(replacement, mappedReplacement, collectionName);
T saved = doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort,
- queryContext.getCollation(entityType).orElse(null), entityType, mappedReplacement, options,
- projection);
+ queryContext.getCollation(entityType).orElse(null), entityType, mappedReplacement, options, projection);
if (saved != null) {
maybeEmitEvent(new AfterSaveEvent<>(saved, mappedReplacement, collectionName));
@@ -1017,7 +1008,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Assert.notNull(objectToSave, "ObjectToSave must not be null!");
- ensureNotIterable(objectToSave);
+ ensureNotCollectionLike(objectToSave);
return insert(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave)));
}
@@ -1028,21 +1019,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Assert.notNull(objectToSave, "ObjectToSave must not be null!");
Assert.notNull(collectionName, "CollectionName must not be null!");
- ensureNotIterable(objectToSave);
+ ensureNotCollectionLike(objectToSave);
return (T) doInsert(collectionName, objectToSave, this.mongoConverter);
}
- /**
- * Ensure the given {@literal source} is not an {@link java.lang.reflect.Array}, {@link Collection} or
- * {@link Iterator}.
- *
- * @param source can be {@literal null}.
- * @deprecated since 3.2. Call {@link #ensureNotCollectionLike(Object)} instead.
- */
- protected void ensureNotIterable(@Nullable Object source) {
- ensureNotCollectionLike(source);
- }
-
/**
* Ensure the given {@literal source} is not an {@link java.lang.reflect.Array}, {@link Collection} or
* {@link Iterator}.
@@ -1646,8 +1626,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@Override
public MapReduceResults mapReduce(String inputCollectionName, String mapFunction, String reduceFunction,
Class entityClass) {
- return mapReduce(new Query(), inputCollectionName, mapFunction, reduceFunction,
- new MapReduceOptions().outputTypeInline(), entityClass);
+ return mapReduce(new Query(), inputCollectionName, mapFunction, reduceFunction, new MapReduceOptions(),
+ entityClass);
}
@Override
@@ -1659,8 +1639,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@Override
public MapReduceResults mapReduce(Query query, String inputCollectionName, String mapFunction,
String reduceFunction, Class entityClass) {
- return mapReduce(query, inputCollectionName, mapFunction, reduceFunction, new MapReduceOptions().outputTypeInline(),
- entityClass);
+ return mapReduce(query, inputCollectionName, mapFunction, reduceFunction, new MapReduceOptions(), entityClass);
}
@Override
@@ -1774,66 +1753,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
return mappedResults;
}
- public GroupByResults group(String inputCollectionName, GroupBy groupBy, Class entityClass) {
- return group(null, inputCollectionName, groupBy, entityClass);
- }
-
- public GroupByResults group(@Nullable Criteria criteria, String inputCollectionName, GroupBy groupBy,
- Class entityClass) {
-
- Document document = groupBy.getGroupByObject();
- document.put("ns", inputCollectionName);
-
- if (criteria == null) {
- document.put("cond", null);
- } else {
- document.put("cond", queryMapper.getMappedObject(criteria.getCriteriaObject(), Optional.empty()));
- }
- // If initial document was a JavaScript string, potentially loaded by Spring's Resource abstraction, load it and
- // convert to Document
-
- if (document.containsKey("initial")) {
- Object initialObj = document.get("initial");
- if (initialObj instanceof String) {
- String initialAsString = replaceWithResourceIfNecessary((String) initialObj);
- document.put("initial", Document.parse(initialAsString));
- }
- }
-
- if (document.containsKey("$reduce")) {
- document.put("$reduce", replaceWithResourceIfNecessary(ObjectUtils.nullSafeToString(document.get("$reduce"))));
- }
- if (document.containsKey("$keyf")) {
- document.put("$keyf", replaceWithResourceIfNecessary(ObjectUtils.nullSafeToString(document.get("$keyf"))));
- }
- if (document.containsKey("finalize")) {
- document.put("finalize", replaceWithResourceIfNecessary(ObjectUtils.nullSafeToString(document.get("finalize"))));
- }
-
- Document commandObject = new Document("group", document);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(String.format("Executing Group with Document [%s]", serializeToJsonSafely(commandObject)));
- }
-
- Document commandResult = executeCommand(commandObject, this.readPreference);
-
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(String.format("Group command result = [%s]", commandResult));
- }
-
- @SuppressWarnings("unchecked")
- Iterable resultSet = (Iterable) commandResult.get("retval");
- List mappedResults = new ArrayList<>();
- DocumentCallback callback = new ReadDocumentCallback<>(mongoConverter, entityClass, inputCollectionName);
-
- for (Document resultDocument : resultSet) {
- mappedResults.add(callback.doWith(resultDocument));
- }
-
- return new GroupByResults<>(mappedResults, commandResult);
- }
-
@Override
public AggregationResults aggregate(TypedAggregation> aggregation, Class outputType) {
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
@@ -2022,8 +1941,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
}
@SuppressWarnings("ConstantConditions")
- protected Stream aggregateStream(Aggregation aggregation, String collectionName,
- Class outputType, @Nullable AggregationOperationContext context) {
+ protected Stream aggregateStream(Aggregation aggregation, String collectionName, Class outputType,
+ @Nullable AggregationOperationContext context) {
Assert.hasText(collectionName, "Collection name must not be null or empty!");
Assert.notNull(aggregation, "Aggregation pipeline must not be null!");
@@ -2295,8 +2214,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
- Document mappedFields = queryContext.getMappedFields(entity,
- EntityProjection.nonProjecting(entityClass));
+ Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass));
Document mappedQuery = queryContext.getMappedQuery(entity);
if (LOGGER.isDebugEnabled()) {
@@ -2348,8 +2266,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
- Document mappedFields = queryContext.getMappedFields(entity,
- EntityProjection.nonProjecting(entityClass));
+ Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass));
Document mappedQuery = queryContext.getMappedQuery(entity);
if (LOGGER.isDebugEnabled()) {
@@ -2371,8 +2288,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Class targetClass, CursorPreparer preparer) {
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(sourceClass);
- EntityProjection projection = operations.introspectProjection(targetClass,
- sourceClass);
+ EntityProjection projection = operations.introspectProjection(targetClass, sourceClass);
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
Document mappedFields = queryContext.getMappedFields(entity, projection);
@@ -2387,13 +2303,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
new ProjectingReadCallback<>(mongoConverter, projection, collectionName), collectionName);
}
-
/**
* Convert given {@link CollectionOptions} to a document and take the domain type information into account when
* creating a mapped schema for validation.
- * This method calls {@link #convertToDocument(CollectionOptions)} for backwards compatibility and potentially
- * overwrites the validator with the mapped validator document. In the long run
- * {@link #convertToDocument(CollectionOptions)} will be removed so that this one becomes the only source of truth.
*
* @param collectionOptions can be {@literal null}.
* @param targetType must not be {@literal null}. Use {@link Object} type instead.
@@ -2402,58 +2314,38 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
*/
protected Document convertToDocument(@Nullable CollectionOptions collectionOptions, Class> targetType) {
- Document doc = convertToDocument(collectionOptions);
-
- if (collectionOptions != null) {
-
- collectionOptions.getValidationOptions().ifPresent(it -> it.getValidator() //
- .ifPresent(val -> doc.put("validator", getMappedValidator(val, targetType))));
-
- collectionOptions.getTimeSeriesOptions().map(operations.forType(targetType)::mapTimeSeriesOptions)
- .ifPresent(it -> {
-
- Document timeseries = new Document("timeField", it.getTimeField());
- if (StringUtils.hasText(it.getMetaField())) {
- timeseries.append("metaField", it.getMetaField());
- }
- if (!Granularity.DEFAULT.equals(it.getGranularity())) {
- timeseries.append("granularity", it.getGranularity().name().toLowerCase());
- }
- doc.put("timeseries", timeseries);
- });
+ if (collectionOptions == null) {
+ return new Document();
}
+ Document doc = new Document();
+ collectionOptions.getCapped().ifPresent(val -> doc.put("capped", val));
+ collectionOptions.getSize().ifPresent(val -> doc.put("size", val));
+ collectionOptions.getMaxDocuments().ifPresent(val -> doc.put("max", val));
+ collectionOptions.getCollation().ifPresent(val -> doc.append("collation", val.toDocument()));
+
+ collectionOptions.getValidationOptions().ifPresent(it -> {
+
+ it.getValidationLevel().ifPresent(val -> doc.append("validationLevel", val.getValue()));
+ it.getValidationAction().ifPresent(val -> doc.append("validationAction", val.getValue()));
+ it.getValidator().ifPresent(val -> doc.append("validator", getMappedValidator(val, targetType)));
+ });
+
+ collectionOptions.getTimeSeriesOptions().map(operations.forType(targetType)::mapTimeSeriesOptions).ifPresent(it -> {
+
+ Document timeseries = new Document("timeField", it.getTimeField());
+ if (StringUtils.hasText(it.getMetaField())) {
+ timeseries.append("metaField", it.getMetaField());
+ }
+ if (!Granularity.DEFAULT.equals(it.getGranularity())) {
+ timeseries.append("granularity", it.getGranularity().name().toLowerCase());
+ }
+ doc.put("timeseries", timeseries);
+ });
+
return doc;
}
- /**
- * @param collectionOptions can be {@literal null}.
- * @return never {@literal null}.
- * @deprecated since 2.1 in favor of {@link #convertToDocument(CollectionOptions, Class)}.
- */
- @Deprecated
- protected Document convertToDocument(@Nullable CollectionOptions collectionOptions) {
-
- Document document = new Document();
-
- if (collectionOptions != null) {
-
- collectionOptions.getCapped().ifPresent(val -> document.put("capped", val));
- collectionOptions.getSize().ifPresent(val -> document.put("size", val));
- collectionOptions.getMaxDocuments().ifPresent(val -> document.put("max", val));
- collectionOptions.getCollation().ifPresent(val -> document.append("collation", val.toDocument()));
-
- collectionOptions.getValidationOptions().ifPresent(it -> {
-
- it.getValidationLevel().ifPresent(val -> document.append("validationLevel", val.getValue()));
- it.getValidationAction().ifPresent(val -> document.append("validationAction", val.getValue()));
- it.getValidator().ifPresent(val -> document.append("validator", getMappedValidator(val, Object.class)));
- });
- }
-
- return document;
- }
-
Document getMappedValidator(Validator validator, Class> domainType) {
Document validationRules = validator.toDocument();
@@ -2467,8 +2359,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
/**
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
- * The first document that matches the query is returned and also removed from the collection in the database.
- *
+ * The first document that matches the query is returned and also removed from the collection in the database.
* The query document is specified as a standard Document and so is the fields specification.
*
* @param collectionName name of the collection to retrieve the objects from
@@ -2546,8 +2437,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Document mappedSort, @Nullable com.mongodb.client.model.Collation collation, Class> entityType,
Document replacement, FindAndReplaceOptions options, Class resultType) {
- EntityProjection projection = operations.introspectProjection(resultType,
- entityType);
+ EntityProjection projection = operations.introspectProjection(resultType, entityType);
return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort, collation, entityType, replacement,
options, projection);
@@ -2575,10 +2465,12 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
Document replacement, FindAndReplaceOptions options, EntityProjection projection) {
if (LOGGER.isDebugEnabled()) {
- LOGGER.debug(String.format(
- "findAndReplace using query: %s fields: %s sort: %s for class: %s and replacement: %s " + "in collection: %s",
- serializeToJsonSafely(mappedQuery), serializeToJsonSafely(mappedFields), serializeToJsonSafely(mappedSort),
- entityType, serializeToJsonSafely(replacement), collectionName));
+ LOGGER
+ .debug(String.format(
+ "findAndReplace using query: %s fields: %s sort: %s for class: %s and replacement: %s "
+ + "in collection: %s",
+ serializeToJsonSafely(mappedQuery), serializeToJsonSafely(mappedFields),
+ serializeToJsonSafely(mappedSort), entityType, serializeToJsonSafely(replacement), collectionName));
}
return executeFindOneInternal(
@@ -2771,8 +2663,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("findOne using query: %s fields: %s in db.collection: %s",
- serializeToJsonSafely(query),
- serializeToJsonSafely(fields.orElseGet(Document::new)),
+ serializeToJsonSafely(query), serializeToJsonSafely(fields.orElseGet(Document::new)),
collection.getNamespace() != null ? collection.getNamespace().getFullName() : "n/a"));
}
@@ -3034,8 +2925,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
private final EntityProjection projection;
private final String collectionName;
- ProjectingReadCallback(MongoConverter mongoConverter, EntityProjection projection,
- String collectionName) {
+ ProjectingReadCallback(MongoConverter mongoConverter, EntityProjection projection, String collectionName) {
this.mongoConverter = mongoConverter;
this.projection = projection;
@@ -3139,7 +3029,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
cursorToUse = cursorToUse.partial(true);
break;
case SECONDARY_READS:
- case SLAVE_OK:
break;
default:
throw new IllegalArgumentException(String.format("%s is no supported flag.", option));
@@ -3156,8 +3045,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
@Override
public ReadPreference getReadPreference() {
- return (query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS)
- || query.getMeta().getFlags().contains(CursorOption.SLAVE_OK)) ? ReadPreference.primaryPreferred() : null;
+ return query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS) ? ReadPreference.primaryPreferred()
+ : null;
}
}
@@ -3204,15 +3093,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
}
}
- /**
- * @deprecated since 3.1.4. Use {@link #getMongoDatabaseFactory()} instead.
- * @return the {@link MongoDatabaseFactory} in use.
- */
- @Deprecated
- public MongoDatabaseFactory getMongoDbFactory() {
- return getMongoDatabaseFactory();
- }
-
/**
* @return the {@link MongoDatabaseFactory} in use.
* @since 3.1.4
@@ -3306,8 +3186,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
/**
* {@link MongoTemplate} extension bound to a specific {@link ClientSession} that is applied when interacting with the
- * server through the driver API.
- *
+ * server through the driver API.
* The prepare steps for {@link MongoDatabase} and {@link MongoCollection} proxy the target and invoke the desired
* target method matching the actual arguments plus a {@link ClientSession}.
*
@@ -3325,7 +3204,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
*/
SessionBoundMongoTemplate(ClientSession session, MongoTemplate that) {
- super(that.getMongoDbFactory().withSession(session), that);
+ super(that.getMongoDatabaseFactory().withSession(session), that);
this.delegate = that;
this.session = session;
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoClientSettingsFactoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoClientSettingsFactoryBean.java
deleted file mode 100644
index fd7ea5ab7..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoClientSettingsFactoryBean.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2016-2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.mongodb.core;
-
-import com.mongodb.MongoClientSettings;
-
-/**
- * A factory bean for construction of a {@link MongoClientSettings} instance to be used with the async MongoDB driver.
- *
- * @author Mark Paluch
- * @author Christoph Strobl
- * @since 2.0
- * @deprecated since 3.0 - Use {@link MongoClientSettingsFactoryBean} instead.
- */
-@Deprecated
-public class ReactiveMongoClientSettingsFactoryBean extends MongoClientSettingsFactoryBean {
-
-}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java
index 0f54bef68..904ea3f50 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2021 the original author or authors.
+ * Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@ import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.mongodb.core.query.UpdateDefinition;
import org.springframework.lang.Nullable;
-import org.springframework.transaction.reactive.TransactionalOperator;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
@@ -58,8 +57,7 @@ import com.mongodb.reactivestreams.client.MongoCollection;
*
* Implemented by {@link ReactiveMongoTemplate}. Not often used but a useful option for extensibility and testability
* (as it can be easily mocked, stubbed, or be the target of a JDK proxy). Command execution using
- * {@link ReactiveMongoOperations} is deferred until subscriber subscribes to the {@link Publisher}.
- *
+ * {@link ReactiveMongoOperations} is deferred until subscriber subscribes to the {@link Publisher}.
* NOTE: Some operations cannot be executed within a MongoDB transaction. Please refer to the MongoDB
* specific documentation to learn more about Multi
* Document Transactions.
@@ -120,8 +118,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono executeCommand(Document command, @Nullable ReadPreference readPreference);
/**
- * Executes a {@link ReactiveDatabaseCallback} translating any exceptions as necessary.
- *
+ * Executes a {@link ReactiveDatabaseCallback} translating any exceptions as necessary.
* Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param action callback object that specifies the MongoDB actions to perform on the passed in DB instance. Must not
@@ -132,8 +129,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux execute(ReactiveDatabaseCallback action);
/**
- * Executes the given {@link ReactiveCollectionCallback} on the entity collection of the specified class.
- *
+ * Executes the given {@link ReactiveCollectionCallback} on the entity collection of the specified class.
* Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param entityClass class that determines the collection to use. Must not be {@literal null}.
@@ -144,8 +140,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux execute(Class> entityClass, ReactiveCollectionCallback action);
/**
- * Executes the given {@link ReactiveCollectionCallback} on the collection of the given name.
- *
+ * Executes the given {@link ReactiveCollectionCallback} on the collection of the given name.
* Allows for returning a result object, that is a domain object or a collection of domain objects.
*
* @param collectionName the name of the collection that specifies which {@link MongoCollection} instance will be
@@ -158,8 +153,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Obtain a {@link ClientSession session} bound instance of {@link SessionScoped} binding the {@link ClientSession}
- * provided by the given {@link Supplier} to each and every command issued against MongoDB.
- *
+ * provided by the given {@link Supplier} to each and every command issued against MongoDB.
* Note: It is up to the caller to manage the {@link ClientSession} lifecycle. Use
* {@link ReactiveSessionScoped#execute(ReactiveSessionCallback, Consumer)} to provide a hook for processing the
* {@link ClientSession} when done.
@@ -177,8 +171,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Obtain a {@link ClientSession session} bound instance of {@link SessionScoped} binding a new {@link ClientSession}
- * with given {@literal sessionOptions} to each and every command issued against MongoDB.
- *
+ * with given {@literal sessionOptions} to each and every command issued against MongoDB.
* Note: It is up to the caller to manage the {@link ClientSession} lifecycle. Use
* {@link ReactiveSessionScoped#execute(ReactiveSessionCallback, Consumer)} to provide a hook for processing the
* {@link ClientSession} when done.
@@ -204,8 +197,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
ReactiveSessionScoped withSession(Publisher sessionProvider);
/**
- * Obtain a {@link ClientSession} bound instance of {@link ReactiveMongoOperations}.
- *
+ * Obtain a {@link ClientSession} bound instance of {@link ReactiveMongoOperations}.
* Note: It is up to the caller to manage the {@link ClientSession} lifecycle.
*
* @param session must not be {@literal null}.
@@ -214,38 +206,6 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
*/
ReactiveMongoOperations withSession(ClientSession session);
- /**
- * Initiate a new {@link ClientSession} and obtain a {@link ClientSession session} bound instance of
- * {@link ReactiveSessionScoped}. Starts the transaction and adds the {@link ClientSession} to each and every command
- * issued against MongoDB.
- *
- * Each {@link ReactiveSessionScoped#execute(ReactiveSessionCallback) execution} initiates a new managed transaction
- * that is {@link ClientSession#commitTransaction() committed} on success. Transactions are
- * {@link ClientSession#abortTransaction() rolled back} upon errors.
- *
- * @return new instance of {@link ReactiveSessionScoped}. Never {@literal null}.
- * @deprecated since 2.2. Use {@code @Transactional} or {@link TransactionalOperator}.
- */
- @Deprecated
- ReactiveSessionScoped inTransaction();
-
- /**
- * Obtain a {@link ClientSession session} bound instance of {@link ReactiveSessionScoped}, start the transaction and
- * bind the {@link ClientSession} provided by the given {@link Publisher} to each and every command issued against
- * MongoDB.
- *
- * Each {@link ReactiveSessionScoped#execute(ReactiveSessionCallback) execution} initiates a new managed transaction
- * that is {@link ClientSession#commitTransaction() committed} on success. Transactions are
- * {@link ClientSession#abortTransaction() rolled back} upon errors.
- *
- * @param sessionProvider must not be {@literal null}.
- * @return new instance of {@link ReactiveSessionScoped}. Never {@literal null}.
- * @since 2.1
- * @deprecated since 2.2. Use {@code @Transactional} or {@link TransactionalOperator}.
- */
- @Deprecated
- ReactiveSessionScoped inTransaction(Publisher sessionProvider);
-
/**
* Create an uncapped collection with a name based on the provided entity class.
*
@@ -292,8 +252,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* Get a {@link MongoCollection} by name. The returned collection may not exists yet (except in local memory) and is
* created on first interaction with the server. Collections can be explicitly created via
* {@link #createCollection(Class)}. Please make sure to check if the collection {@link #collectionExists(Class)
- * exists} first.
- *
+ * exists} first.
* Translate any exceptions as necessary.
*
* @param collectionName name of the collection.
@@ -302,8 +261,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono> getCollection(String collectionName);
/**
- * Check to see if a collection with a name indicated by the entity class exists.
- *
+ * Check to see if a collection with a name indicated by the entity class exists.
* Translate any exceptions as necessary.
*
* @param entityClass class that determines the name of the collection. Must not be {@literal null}.
@@ -312,8 +270,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono collectionExists(Class entityClass);
/**
- * Check to see if a collection with a given name exists.
- *
+ * Check to see if a collection with a given name exists.
* Translate any exceptions as necessary.
*
* @param collectionName name of the collection. Must not be {@literal null}.
@@ -322,8 +279,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono collectionExists(String collectionName);
/**
- * Drop the collection with the name indicated by the entity class.
- *
+ * Drop the collection with the name indicated by the entity class.
* Translate any exceptions as necessary.
*
* @param entityClass class that determines the collection to drop/delete. Must not be {@literal null}.
@@ -331,8 +287,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono dropCollection(Class entityClass);
/**
- * Drop the collection with the given name.
- *
+ * Drop the collection with the given name.
* Translate any exceptions as necessary.
*
* @param collectionName name of the collection to drop/delete.
@@ -340,11 +295,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono dropCollection(String collectionName);
/**
- * Query for a {@link Flux} of objects of type T from the collection used by the entity class.
- *
+ * Query for a {@link Flux} of objects of type T from the collection used by the entity class.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
* to map objects since the test for class type is done in the client and not on the server.
*
@@ -354,11 +307,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux findAll(Class entityClass);
/**
- * Query for a {@link Flux} of objects of type T from the specified collection.
- *
+ * Query for a {@link Flux} of objects of type T from the specified collection.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
* to map objects since the test for class type is done in the client and not on the server.
*
@@ -370,11 +321,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the
- * specified type.
- *
+ * specified type.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -387,11 +336,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
- * type.
- *
+ * type.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -437,8 +384,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* Map the results of an ad-hoc query on the collection for the entity class to a {@link Flux} of the specified type.
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -450,11 +396,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux find(Query query, Class entityClass);
/**
- * Map the results of an ad-hoc query on the specified collection to a {@link Flux} of the specified type.
- *
+ * Map the results of an ad-hoc query on the specified collection to a {@link Flux} of the specified type.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -565,11 +509,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux aggregate(TypedAggregation> aggregation, String collectionName, Class outputType);
/**
- * Execute an aggregation operation.
- *
+ * Execute an aggregation operation.
* The raw results will be mapped to the given entity class and are returned as stream. The name of the
- * inputCollection is derived from the {@link TypedAggregation#getInputType() aggregation input type}.
- *
+ * inputCollection is derived from the {@link TypedAggregation#getInputType() aggregation input type}.
* Aggregation streaming cannot be used with {@link AggregationOptions#isExplain() aggregation explain} nor with
* {@link AggregationOptions#getCursorBatchSize()}. Enabling explanation mode or setting batch size cause
* {@link IllegalArgumentException}.
@@ -583,11 +525,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux aggregate(TypedAggregation> aggregation, Class outputType);
/**
- * Execute an aggregation operation.
- *
+ * Execute an aggregation operation.
* The raw results will be mapped to the given {@code ouputType}. The name of the inputCollection is derived from the
- * {@code inputType}.
- *
+ * {@code inputType}.
* Aggregation streaming cannot be used with {@link AggregationOptions#isExplain() aggregation explain} nor with
* {@link AggregationOptions#getCursorBatchSize()}. Enabling explanation mode or setting batch size cause
* {@link IllegalArgumentException}.
@@ -603,10 +543,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux aggregate(Aggregation aggregation, Class> inputType, Class outputType);
/**
- * Execute an aggregation operation.
- *
- * The raw results will be mapped to the given entity class.
- *
+ * Execute an aggregation operation.
+ * The raw results will be mapped to the given entity class.
* Aggregation streaming cannot be used with {@link AggregationOptions#isExplain() aggregation explain} nor with
* {@link AggregationOptions#getCursorBatchSize()}. Enabling explanation mode or setting batch size cause
* {@link IllegalArgumentException}.
@@ -901,10 +839,8 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Map the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the
* specified type. The first document that matches the query is returned and also removed from the collection in the
- * database.
- *
- * The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}.
- *
+ * database.
+ * The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -920,8 +856,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* type. The first document that matches the query is returned and also removed from the collection in the database.
*
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -939,8 +874,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* NOTE: Query {@link Query#getSkip() offset} and {@link Query#getLimit() limit} can have direct
* influence on the resulting number of documents found as those values are passed on to the server and potentially
* limit the range and order within which the server performs the count operation. Use an {@literal unpaged} query to
- * count all matches.
- *
+ * count all matches.
* This method uses an
* {@link com.mongodb.reactivestreams.client.MongoCollection#countDocuments(org.bson.conversions.Bson, com.mongodb.client.model.CountOptions)
* aggregation execution} even for empty {@link Query queries} which may have an impact on performance, but guarantees
@@ -961,8 +895,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* NOTE: Query {@link Query#getSkip() offset} and {@link Query#getLimit() limit} can have direct
* influence on the resulting number of documents found as those values are passed on to the server and potentially
* limit the range and order within which the server performs the count operation. Use an {@literal unpaged} query to
- * count all matches.
- *
+ * count all matches.
* This method uses an
* {@link com.mongodb.reactivestreams.client.MongoCollection#countDocuments(org.bson.conversions.Bson, com.mongodb.client.model.CountOptions)
* aggregation execution} even for empty {@link Query queries} which may have an impact on performance, but guarantees
@@ -982,8 +915,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* NOTE: Query {@link Query#getSkip() offset} and {@link Query#getLimit() limit} can have direct
* influence on the resulting number of documents found as those values are passed on to the server and potentially
* limit the range and order within which the server performs the count operation. Use an {@literal unpaged} query to
- * count all matches.
- *
+ * count all matches.
* This method uses an
* {@link com.mongodb.reactivestreams.client.MongoCollection#countDocuments(org.bson.conversions.Bson, com.mongodb.client.model.CountOptions)
* aggregation execution} even for empty {@link Query queries} which may have an impact on performance, but guarantees
@@ -1000,8 +932,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Estimate the number of documents, in the collection {@link #getCollectionName(Class) identified by the given type},
- * based on collection statistics.
- *
+ * based on collection statistics.
* Please make sure to read the MongoDB reference documentation about limitations on eg. sharded cluster or inside
* transactions.
*
@@ -1016,8 +947,7 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
}
/**
- * Estimate the number of documents in the given collection based on collection statistics.
- *
+ * Estimate the number of documents in the given collection based on collection statistics.
* Please make sure to read the MongoDB reference documentation about limitations on eg. sharded cluster or inside
* transactions.
*
@@ -1028,16 +958,13 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono estimatedCount(String collectionName);
/**
- * Insert the object into the collection for the entity type of the object to save.
- *
- * The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
- *
+ * Insert the object into the collection for the entity type of the object to save.
+ * The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
* If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* Spring's
- * Type Conversion" for more details.
- *
+ * Type Conversion" for more details.
* Insert is used to initially store the object into the database. To update an existing object use the save method.
*
* The {@code objectToSave} must not be collection-like.
@@ -1049,11 +976,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Mono insert(T objectToSave);
/**
- * Insert the object into the specified collection.
- *
+ * Insert the object into the specified collection.
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* Insert is used to initially store the object into the database. To update an existing object use the save method.
*
* The {@code objectToSave} must not be collection-like.
@@ -1093,16 +1018,13 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
Flux insertAll(Collection extends T> objectsToSave);
/**
- * Insert the object into the collection for the entity type of the object to save.
- *
- * The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
- *
+ * Insert the object into the collection for the entity type of the object to save.
+ * The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}.
* If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* Spring's
- * Type Conversion" for more details.
- *
+ * Type Conversion" for more details.
* Insert is used to initially store the object into the database. To update an existing object use the save method.
*
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
@@ -1139,17 +1061,14 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Save the object to the collection for the entity type of the object to save. This will perform an insert if the
- * object is not already present, that is an 'upsert'.
- *
+ * object is not already present, that is an 'upsert'.
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
* property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
* Spring's
- * Type Conversion" for more details.
- *
+ * Type Conversion" for more details.
* The {@code objectToSave} must not be collection-like.
*
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
@@ -1160,15 +1079,14 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Save the object to the specified collection. This will perform an insert if the object is not already present, that
- * is an 'upsert'.
- *
+ * is an 'upsert'.
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
- * property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API.
- * See Spring's Type Conversion for more details.
+ * property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
+ * Spring's Type
+ * Conversion for more details.
*
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
* @param collectionName name of the collection to store the object in. Must not be {@literal null}.
@@ -1179,15 +1097,14 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Save the object to the collection for the entity type of the object to save. This will perform an insert if the
- * object is not already present, that is an 'upsert'.
- *
+ * object is not already present, that is an 'upsert'.
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
- * property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API.
- * See Spring's Type Conversion for more details.
+ * property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
+ * Spring's Type
+ * Conversion for more details.
*
* @param objectToSave the object to store in the collection. Must not be {@literal null}.
* @return the saved object.
@@ -1196,15 +1113,14 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Save the object to the specified collection. This will perform an insert if the object is not already present, that
- * is an 'upsert'.
- *
+ * is an 'upsert'.
* The object is converted to the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* If your object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
* String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
- * property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API.
- * See Spring's Type Conversion for more details.
+ * property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
+ * Spring's Type
+ * Conversion for more details.
*
* @param objectToSave the object to store in the collReactiveMongoOperationsection. Must not be {@literal null}.
* @param collectionName name of the collection to store the object in. Must not be {@literal null}.
@@ -1477,11 +1393,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* Map the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified
* type. The stream uses a {@link com.mongodb.CursorType#TailableAwait tailable} cursor that may be an infinite
* stream. The stream will not be completed unless the {@link org.reactivestreams.Subscription} is
- * {@link Subscription#cancel() canceled}.
- *
+ * {@link Subscription#cancel() canceled}.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -1496,11 +1410,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* Map the results of an ad-hoc query on the collection for the entity class to a stream of objects of the specified
* type. The stream uses a {@link com.mongodb.CursorType#TailableAwait tailable} cursor that may be an infinite
* stream. The stream will not be completed unless the {@link org.reactivestreams.Subscription} is
- * {@link Subscription#cancel() canceled}.
- *
+ * {@link Subscription#cancel() canceled}.
* The object is converted from the MongoDB native representation using an instance of {@see MongoConverter}. Unless
- * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
- *
+ * configured otherwise, an instance of {@link MappingMongoConverter} will be used.
* The query is specified as a {@link Query} which can be created either using the {@link BasicQuery} or the more
* feature rich {@link Query}.
*
@@ -1516,11 +1428,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* Subscribe to a MongoDB Change Stream for all events in
* the configured default database via the reactive infrastructure. Use the optional provided {@link Aggregation} to
* filter events. The stream will not be completed unless the {@link org.reactivestreams.Subscription} is
- * {@link Subscription#cancel() canceled}.
- *
+ * {@link Subscription#cancel() canceled}.
* The {@link ChangeStreamEvent#getBody()} is mapped to the {@literal resultType} while the
- * {@link ChangeStreamEvent#getRaw()} contains the unmodified payload.
- *
+ * {@link ChangeStreamEvent#getRaw()} contains the unmodified payload.
* Use {@link ChangeStreamOptions} to set arguments like {@link ChangeStreamOptions#getResumeToken() the resumseToken}
* for resuming change streams.
*
@@ -1540,11 +1450,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* Subscribe to a MongoDB Change Stream for all events in
* the given collection via the reactive infrastructure. Use the optional provided {@link Aggregation} to filter
* events. The stream will not be completed unless the {@link org.reactivestreams.Subscription} is
- * {@link Subscription#cancel() canceled}.
- *
+ * {@link Subscription#cancel() canceled}.
* The {@link ChangeStreamEvent#getBody()} is mapped to the {@literal resultType} while the
- * {@link ChangeStreamEvent#getRaw()} contains the unmodified payload.
- *
+ * {@link ChangeStreamEvent#getRaw()} contains the unmodified payload.
* Use {@link ChangeStreamOptions} to set arguments like {@link ChangeStreamOptions#getResumeToken() the resumseToken}
* for resuming change streams.
*
@@ -1565,11 +1473,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
/**
* Subscribe to a MongoDB Change Stream via the reactive
* infrastructure. Use the optional provided {@link Aggregation} to filter events. The stream will not be completed
- * unless the {@link org.reactivestreams.Subscription} is {@link Subscription#cancel() canceled}.
- *
+ * unless the {@link org.reactivestreams.Subscription} is {@link Subscription#cancel() canceled}.
* The {@link ChangeStreamEvent#getBody()} is mapped to the {@literal resultType} while the
- * {@link ChangeStreamEvent#getRaw()} contains the unmodified payload.
- *
+ * {@link ChangeStreamEvent#getRaw()} contains the unmodified payload.
* Use {@link ChangeStreamOptions} to set arguments like {@link ChangeStreamOptions#getResumeToken() the resumseToken}
* for resuming change streams.
*
@@ -1599,7 +1505,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* @param options additional options like output collection. Must not be {@literal null}.
* @return a {@link Flux} emitting the result document sequence. Never {@literal null}.
* @since 2.1
+ * @deprecated since MongoDB server version 5.0
*/
+ @Deprecated
Flux mapReduce(Query filterQuery, Class> domainType, Class resultType, String mapFunction,
String reduceFunction, MapReduceOptions options);
@@ -1617,7 +1525,9 @@ public interface ReactiveMongoOperations extends ReactiveFluentMongoOperations {
* @param options additional options like output collection. Must not be {@literal null}.
* @return a {@link Flux} emitting the result document sequence. Never {@literal null}.
* @since 2.1
+ * @deprecated since MongoDB server version 5.0
*/
+ @Deprecated
Flux mapReduce(Query filterQuery, Class> domainType, String inputCollectionName, Class resultType,
String mapFunction, String reduceFunction, MapReduceOptions options);
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
index 94364ddc2..b37360ab9 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016-2021 the original author or authors.
+ * Copyright 2016-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@ package org.springframework.data.mongodb.core;
import static org.springframework.data.mongodb.core.query.SerializationUtils.*;
-import org.springframework.data.projection.EntityProjection;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;
@@ -45,7 +44,6 @@ import org.bson.conversions.Bson;
import org.bson.types.ObjectId;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
-
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -114,6 +112,7 @@ import org.springframework.data.mongodb.core.query.UpdateDefinition.ArrayFilter;
import org.springframework.data.mongodb.core.timeseries.Granularity;
import org.springframework.data.mongodb.core.validation.Validator;
import org.springframework.data.mongodb.util.BsonUtils;
+import org.springframework.data.projection.EntityProjection;
import org.springframework.data.util.Optionals;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
@@ -351,8 +350,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
/**
* Set the {@link ReactiveEntityCallbacks} instance to use when invoking
* {@link org.springframework.data.mapping.callback.EntityCallback callbacks} like the
- * {@link ReactiveBeforeSaveCallback}.
- *
+ * {@link ReactiveBeforeSaveCallback}.
* Overrides potentially existing {@link ReactiveEntityCallbacks}.
*
* @param entityCallbacks must not be {@literal null}.
@@ -480,39 +478,6 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
this.sessionSynchronization = sessionSynchronization;
}
- @Override
- public ReactiveSessionScoped inTransaction() {
- return inTransaction(
- mongoDatabaseFactory.getSession(ClientSessionOptions.builder().causallyConsistent(true).build()));
- }
-
- @Override
- public ReactiveSessionScoped inTransaction(Publisher sessionProvider) {
-
- Mono cachedSession = Mono.from(sessionProvider).cache();
-
- return new ReactiveSessionScoped() {
-
- @Override
- public Flux execute(ReactiveSessionCallback action, Consumer doFinally) {
-
- return cachedSession.flatMapMany(session -> {
-
- if (!session.hasActiveTransaction()) {
- session.startTransaction();
- }
-
- return Flux.usingWhen(Mono.just(session), //
- s -> ReactiveMongoTemplate.this.withSession(action, s), //
- ClientSession::commitTransaction, //
- (sess, err) -> sess.abortTransaction(), //
- ClientSession::commitTransaction) //
- .doFinally(signalType -> doFinally.accept(session));
- });
- }
- };
- }
-
private Flux withSession(ReactiveSessionCallback action, ClientSession session) {
ReactiveSessionBoundMongoTemplate operations = new ReactiveSessionBoundMongoTemplate(session,
@@ -888,8 +853,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
String collection = StringUtils.hasText(collectionName) ? collectionName : getCollectionName(entityClass);
String distanceField = operations.nearQueryDistanceFieldName(entityClass);
- EntityProjection projection = operations.introspectProjection(returnType,
- entityClass);
+ EntityProjection projection = operations.introspectProjection(returnType, entityClass);
GeoNearResultDocumentCallback callback = new GeoNearResultDocumentCallback<>(distanceField,
new ProjectingReadCallback<>(mongoConverter, projection, collection), near.getMetric());
@@ -951,8 +915,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityType);
QueryContext queryContext = queryOperations.createQueryContext(query);
- EntityProjection projection = operations.introspectProjection(resultType,
- entityType);
+ EntityProjection projection = operations.introspectProjection(resultType, entityType);
Document mappedQuery = queryContext.getMappedQuery(entity);
Document mappedFields = queryContext.getMappedFields(entity, projection);
@@ -975,8 +938,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
}).flatMap(it -> {
Mono afterFindAndReplace = doFindAndReplace(it.getCollection(), mappedQuery, mappedFields, mappedSort,
- queryContext.getCollation(entityType).orElse(null), entityType, it.getTarget(), options,
- projection);
+ queryContext.getCollation(entityType).orElse(null), entityType, it.getTarget(), options, projection);
return afterFindAndReplace.flatMap(saved -> {
maybeEmitEvent(new AfterSaveEvent<>(saved, it.getTarget(), it.getCollection()));
return maybeCallAfterSave(saved, it.getTarget(), it.getCollection());
@@ -1078,7 +1040,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
Assert.notNull(objectToSave, "Object to insert must not be null!");
- ensureNotIterable(objectToSave);
+ ensureNotCollectionLike(objectToSave);
return insert(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave)));
}
@@ -1086,7 +1048,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
Assert.notNull(objectToSave, "Object to insert must not be null!");
- ensureNotIterable(objectToSave);
+ ensureNotCollectionLike(objectToSave);
return doInsert(collectionName, objectToSave, this.mongoConverter);
}
@@ -1988,8 +1950,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
QueryContext queryContext = queryOperations
.createQueryContext(new BasicQuery(query, fields != null ? fields : new Document()));
- Document mappedFields = queryContext.getMappedFields(entity,
- EntityProjection.nonProjecting(entityClass));
+ Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass));
Document mappedQuery = queryContext.getMappedQuery(entity);
if (LOGGER.isDebugEnabled()) {
@@ -2041,8 +2002,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(entityClass);
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
- Document mappedFields = queryContext.getMappedFields(entity,
- EntityProjection.nonProjecting(entityClass));
+ Document mappedFields = queryContext.getMappedFields(entity, EntityProjection.nonProjecting(entityClass));
Document mappedQuery = queryContext.getMappedQuery(entity);
if (LOGGER.isDebugEnabled()) {
@@ -2064,8 +2024,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
Class targetClass, FindPublisherPreparer preparer) {
MongoPersistentEntity> entity = mappingContext.getPersistentEntity(sourceClass);
- EntityProjection projection = operations.introspectProjection(targetClass,
- sourceClass);
+ EntityProjection projection = operations.introspectProjection(targetClass, sourceClass);
QueryContext queryContext = queryOperations.createQueryContext(new BasicQuery(query, fields));
Document mappedFields = queryContext.getMappedFields(entity, projection);
@@ -2140,8 +2099,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
/**
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
- * The first document that matches the query is returned and also removed from the collection in the database.
- *
+ * The first document that matches the query is returned and also removed from the collection in the database.
* The query document is specified as a standard Document and so is the fields specification.
*
* @param collectionName name of the collection to retrieve the objects from
@@ -2212,8 +2170,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
Document mappedSort, com.mongodb.client.model.Collation collation, Class> entityType, Document replacement,
FindAndReplaceOptions options, Class resultType) {
- EntityProjection projection = operations.introspectProjection(resultType,
- entityType);
+ EntityProjection projection = operations.introspectProjection(resultType, entityType);
return doFindAndReplace(collectionName, mappedQuery, mappedFields, mappedSort, collation, entityType, replacement,
options, projection);
@@ -2311,17 +2268,6 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
}
}
- /**
- * Ensure the given {@literal source} is not an {@link java.lang.reflect.Array}, {@link Collection} or
- * {@link Iterator}.
- *
- * @param source can be {@literal null}.
- * @deprecated since 3.2. Call {@link #ensureNotCollectionLike(Object)} instead.
- */
- protected void ensureNotIterable(@Nullable Object source) {
- ensureNotCollectionLike(source);
- }
-
/**
* Ensure the given {@literal source} is not an {@link java.lang.reflect.Array}, {@link Collection} or
* {@link Iterator}.
@@ -2832,8 +2778,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
private final EntityProjection projection;
private final String collectionName;
- ProjectingReadCallback(MongoConverter reader, EntityProjection projection,
- String collectionName) {
+ ProjectingReadCallback(MongoConverter reader, EntityProjection projection, String collectionName) {
this.reader = reader;
this.projection = projection;
this.collectionName = collectionName;
@@ -2987,8 +2932,8 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
@Override
public ReadPreference getReadPreference() {
- return (query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS)
- || query.getMeta().getFlags().contains(CursorOption.SLAVE_OK)) ? ReadPreference.primaryPreferred() : null;
+ return query.getMeta().getFlags().contains(CursorOption.SECONDARY_READS) ? ReadPreference.primaryPreferred()
+ : null;
}
}
@@ -3010,8 +2955,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
/**
* {@link MongoTemplate} extension bound to a specific {@link ClientSession} that is applied when interacting with the
- * server through the driver API.
- *
+ * server through the driver API.
* The prepare steps for {@link MongoDatabase} and {@link MongoCollection} proxy the target and invoke the desired
* target method matching the actual arguments plus a {@link ClientSession}.
*
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoClientDbFactory.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoClientDbFactory.java
deleted file mode 100644
index 3ce3ce577..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/SimpleMongoClientDbFactory.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2018-2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.mongodb.core;
-
-import com.mongodb.ConnectionString;
-import com.mongodb.client.MongoClient;
-import com.mongodb.client.MongoClients;
-import com.mongodb.client.MongoDatabase;
-
-/**
- * Factory to create {@link MongoDatabase} instances from a {@link MongoClient} instance.
- *
- * @author Christoph Strobl
- * @since 2.1
- * @deprecated since 3.0, use {@link SimpleMongoClientDatabaseFactory} instead.
- */
-@Deprecated
-public class SimpleMongoClientDbFactory extends SimpleMongoClientDatabaseFactory {
-
- /**
- * Creates a new {@link SimpleMongoClientDbFactory} instance for the given {@code connectionString}.
- *
- * @param connectionString connection coordinates for a database connection. Must contain a database name and must not
- * be {@literal null} or empty.
- * @see MongoDB Connection String reference
- */
- public SimpleMongoClientDbFactory(String connectionString) {
- this(new ConnectionString(connectionString));
- }
-
- /**
- * Creates a new {@link SimpleMongoClientDbFactory} instance from the given {@link MongoClient}.
- *
- * @param connectionString connection coordinates for a database connection. Must contain also a database name and not
- * be {@literal null}.
- */
- public SimpleMongoClientDbFactory(ConnectionString connectionString) {
- this(MongoClients.create(connectionString), connectionString.getDatabase(), true);
- }
-
- /**
- * Creates a new {@link SimpleMongoClientDbFactory} instance from the given {@link MongoClient}.
- *
- * @param mongoClient must not be {@literal null}.
- * @param databaseName must not be {@literal null} or empty.
- */
- public SimpleMongoClientDbFactory(MongoClient mongoClient, String databaseName) {
- this(mongoClient, databaseName, false);
- }
-
- /**
- * Creates a new {@link SimpleMongoClientDbFactory} instance from the given {@link MongoClient}.
- *
- * @param mongoClient must not be {@literal null}.
- * @param databaseName must not be {@literal null} or empty.
- * @param mongoInstanceCreated
- */
- private SimpleMongoClientDbFactory(MongoClient mongoClient, String databaseName, boolean mongoInstanceCreated) {
- super(mongoClient, databaseName, mongoInstanceCreated);
- }
-}
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
index f1e759452..f8e56e110 100644
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
+++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/Aggregation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2021 the original author or authors.
+ * Copyright 2013-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -226,8 +226,7 @@ public class Aggregation {
}
/**
- * Obtain an {@link AddFieldsOperationBuilder builder} instance to create a new {@link AddFieldsOperation}.
- *
+ * Obtain an {@link AddFieldsOperationBuilder builder} instance to create a new {@link AddFieldsOperation}.
* Starting in version 4.2, MongoDB adds a new aggregation pipeline stage {@link AggregationUpdate#set $set} that is
* an alias for {@code $addFields}.
*
@@ -435,18 +434,6 @@ public class Aggregation {
return new SortByCountOperation(groupAndSortExpression);
}
- /**
- * Creates a new {@link SkipOperation} skipping the given number of elements.
- *
- * @param elementsToSkip must not be less than zero.
- * @return new instance of {@link SkipOperation}.
- * @deprecated prepare to get this one removed in favor of {@link #skip(long)}.
- */
- @Deprecated
- public static SkipOperation skip(int elementsToSkip) {
- return new SkipOperation(elementsToSkip);
- }
-
/**
* Creates a new {@link SkipOperation} skipping the given number of elements.
*
@@ -725,8 +712,7 @@ public class Aggregation {
}
/**
- * Converts this {@link Aggregation} specification to a {@link Document}.
- *
+ * Converts this {@link Aggregation} specification to a {@link Document}.
* MongoDB requires as of 3.6 cursor-based aggregation. Use {@link #toPipeline(AggregationOperationContext)} to render
* an aggregation pipeline.
*
diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java
deleted file mode 100644
index cf1848d69..000000000
--- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/AggregationFunctionExpressions.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2015-2021 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.data.mongodb.core.aggregation;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.bson.Document;
-import org.springframework.util.Assert;
-
-/**
- * An enum of supported {@link AggregationExpression}s in aggregation pipeline stages.
- *
- * @author Thomas Darimont
- * @author Oliver Gierke
- * @author Christoph Strobl
- * @author Mark Paluch
- * @since 1.7
- * @deprecated since 1.10. Please use {@link ArithmeticOperators} and {@link ComparisonOperators} instead.
- */
-@Deprecated
-public enum AggregationFunctionExpressions {
-
- SIZE, CMP, EQ, GT, GTE, LT, LTE, NE, SUBTRACT, ADD, MULTIPLY;
-
- /**
- * Returns an {@link AggregationExpression} build from the current {@link Enum} name and the given parameters.
- *
- * @param parameters must not be {@literal null}
- * @return new instance of {@link AggregationExpression}.
- */
- public AggregationExpression of(Object... parameters) {
-
- Assert.notNull(parameters, "Parameters must not be null!");
- return new FunctionExpression(name().toLowerCase(), parameters);
- }
-
- /**
- * An {@link AggregationExpression} representing a function call.
- *
- * @author Thomas Darimont
- * @author Oliver Gierke
- * @since 1.7
- */
- static class FunctionExpression implements AggregationExpression {
-
- private final String name;
- private final List