Polishing.
Documentation, refine parameter ordering. Original Pull Request: #4288
This commit is contained in:
committed by
Christoph Strobl
parent
c5c6fc107c
commit
e56f6ce87f
@@ -113,7 +113,23 @@ import com.mongodb.client.result.DeleteResult;
|
||||
import com.mongodb.client.result.UpdateResult;
|
||||
|
||||
/**
|
||||
* Primary implementation of {@link MongoOperations}.
|
||||
* Primary implementation of {@link MongoOperations}. It simplifies the use of imperative MongoDB usage and helps to
|
||||
* avoid common errors. It executes core MongoDB workflow, leaving application code to provide {@link Document} and
|
||||
* extract results. This class executes BSON queries or updates, initiating iteration over {@link FindIterable} and
|
||||
* catching MongoDB exceptions and translating them to the generic, more informative exception hierarchy defined in the
|
||||
* org.springframework.dao package. Can be used within a service implementation via direct instantiation with a
|
||||
* {@link MongoDatabaseFactory} reference, or get prepared in an application context and given to services as bean
|
||||
* reference.
|
||||
* <p>
|
||||
* Note: The {@link MongoDatabaseFactory} should always be configured as a bean in the application context, in the first
|
||||
* case given to the service directly, in the second case to the prepared template.
|
||||
* <h3>{@link ReadPreference} and {@link com.mongodb.ReadConcern}</h3>
|
||||
* <p>
|
||||
* {@code ReadPreference} and {@code ReadConcern} are generally considered from {@link Query} and
|
||||
* {@link AggregationOptions} objects for the action to be executed on a particular {@link MongoCollection}.
|
||||
* <p>
|
||||
* You can also set the default {@link #setReadPreference(ReadPreference) ReadPreference} on the template level to
|
||||
* generally apply a {@link ReadPreference}.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Graeme Rocher
|
||||
@@ -778,7 +794,7 @@ public class MongoTemplate
|
||||
|
||||
if (ObjectUtils.isEmpty(query.getSortObject())) {
|
||||
|
||||
return doFindOne(createDelegate(query), collectionName, query.getQueryObject(), query.getFieldsObject(),
|
||||
return doFindOne(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(),
|
||||
new QueryCursorPreparer(query, entityClass), entityClass);
|
||||
} else {
|
||||
query.limit(1);
|
||||
@@ -827,7 +843,7 @@ public class MongoTemplate
|
||||
Assert.notNull(collectionName, "CollectionName must not be null");
|
||||
Assert.notNull(entityClass, "EntityClass must not be null");
|
||||
|
||||
return doFind(createDelegate(query), collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
|
||||
return doFind(collectionName, createDelegate(query), query.getQueryObject(), query.getFieldsObject(), entityClass,
|
||||
new QueryCursorPreparer(query, entityClass));
|
||||
}
|
||||
|
||||
@@ -847,7 +863,7 @@ public class MongoTemplate
|
||||
|
||||
String idKey = operations.getIdPropertyName(entityClass);
|
||||
|
||||
return doFindOne(CollectionPreparer.identity(), collectionName, new Document(idKey, id), new Document(),
|
||||
return doFindOne(collectionName, CollectionPreparer.identity(), new Document(idKey, id), new Document(),
|
||||
entityClass);
|
||||
}
|
||||
|
||||
@@ -1122,8 +1138,7 @@ public class MongoTemplate
|
||||
}
|
||||
|
||||
protected long doEstimatedCount(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName,
|
||||
EstimatedDocumentCountOptions options) {
|
||||
String collectionName, EstimatedDocumentCountOptions options) {
|
||||
return execute(collectionName,
|
||||
collection -> collectionPreparer.prepare(collection).estimatedDocumentCount(options));
|
||||
}
|
||||
@@ -2376,15 +2391,16 @@ public class MongoTemplate
|
||||
* The query document is specified as a standard {@link Document} and so is the fields specification.
|
||||
*
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @return the converted object or {@literal null} if none exists.
|
||||
*/
|
||||
@Nullable
|
||||
protected <T> T doFindOne(CollectionPreparer collectionPreparer, String collectionName, Document query,
|
||||
Document fields, Class<T> entityClass) {
|
||||
return doFindOne(collectionPreparer, collectionName, query, fields, CursorPreparer.NO_OP_PREPARER, entityClass);
|
||||
protected <T> T doFindOne(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, Class<T> entityClass) {
|
||||
return doFindOne(collectionName, collectionPreparer, query, fields, CursorPreparer.NO_OP_PREPARER, entityClass);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2392,17 +2408,18 @@ public class MongoTemplate
|
||||
* The query document is specified as a standard {@link Document} and so is the fields specification.
|
||||
*
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @param preparer the preparer used to modify the cursor on execution.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @return the converted object or {@literal null} if none exists.
|
||||
* @since 2.2
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
protected <T> T doFindOne(CollectionPreparer collectionPreparer, String collectionName, Document query,
|
||||
Document fields, CursorPreparer preparer, Class<T> entityClass) {
|
||||
protected <T> T doFindOne(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, CursorPreparer preparer, Class<T> entityClass) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
@@ -2424,14 +2441,15 @@ public class MongoTemplate
|
||||
* 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
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record
|
||||
* @param fields the document that specifies the fields to be returned
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @return the List of converted objects.
|
||||
*/
|
||||
protected <T> List<T> doFind(CollectionPreparer collectionPreparer, String collectionName, Document query,
|
||||
Document fields, Class<T> entityClass) {
|
||||
return doFind(collectionPreparer, collectionName, query, fields, entityClass, null,
|
||||
protected <T> List<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, Class<T> entityClass) {
|
||||
return doFind(collectionName, collectionPreparer, query, fields, entityClass, null,
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
@@ -2441,6 +2459,7 @@ public class MongoTemplate
|
||||
* specified as a standard Document and so is the fields specification.
|
||||
*
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
@@ -2448,14 +2467,15 @@ public class MongoTemplate
|
||||
* (apply limits, skips and so on).
|
||||
* @return the {@link List} of converted objects.
|
||||
*/
|
||||
protected <T> List<T> doFind(CollectionPreparer collectionPreparer, String collectionName, Document query,
|
||||
Document fields, Class<T> entityClass, CursorPreparer preparer) {
|
||||
return doFind(collectionPreparer, collectionName, query, fields, entityClass, preparer,
|
||||
protected <T> List<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, Class<T> entityClass, CursorPreparer preparer) {
|
||||
return doFind(collectionName, collectionPreparer, query, fields, entityClass, preparer,
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
protected <S, T> List<T> doFind(CollectionPreparer collectionPreparer, String collectionName, Document query,
|
||||
Document fields, Class<S> entityClass, @Nullable CursorPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
protected <S, T> List<T> doFind(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, Document fields,
|
||||
Class<S> entityClass, @Nullable CursorPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
@@ -2478,8 +2498,8 @@ public class MongoTemplate
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
<S, T> List<T> doFind(CollectionPreparer collectionPreparer, String collectionName, Document query, Document fields,
|
||||
Class<S> sourceClass, Class<T> targetClass, CursorPreparer preparer) {
|
||||
<S, T> List<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPreparer, String collectionName,
|
||||
Document query, Document fields, Class<S> sourceClass, Class<T> targetClass, CursorPreparer preparer) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(sourceClass);
|
||||
EntityProjection<T, S> projection = operations.introspectProjection(targetClass, sourceClass);
|
||||
@@ -2900,8 +2920,7 @@ public class MongoTemplate
|
||||
private final @Nullable com.mongodb.client.model.Collation collation;
|
||||
|
||||
public FindCallback(CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query,
|
||||
Document fields,
|
||||
@Nullable com.mongodb.client.model.Collation collation) {
|
||||
Document fields, @Nullable com.mongodb.client.model.Collation collation) {
|
||||
|
||||
Assert.notNull(query, "Query must not be null");
|
||||
Assert.notNull(fields, "Fields must not be null");
|
||||
@@ -2970,8 +2989,7 @@ public class MongoTemplate
|
||||
private final Optional<Collation> collation;
|
||||
|
||||
FindAndRemoveCallback(CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query,
|
||||
Document fields, Document sort,
|
||||
@Nullable Collation collation) {
|
||||
Document fields, Document sort, @Nullable Collation collation) {
|
||||
this.collectionPreparer = collectionPreparer;
|
||||
|
||||
this.query = query;
|
||||
@@ -3001,8 +3019,7 @@ public class MongoTemplate
|
||||
private final FindAndModifyOptions options;
|
||||
|
||||
FindAndModifyCallback(CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query,
|
||||
Document fields, Document sort,
|
||||
Object update, List<Document> arrayFilters, FindAndModifyOptions options) {
|
||||
Document fields, Document sort, Object update, List<Document> arrayFilters, FindAndModifyOptions options) {
|
||||
|
||||
this.collectionPreparer = collectionPreparer;
|
||||
this.query = query;
|
||||
@@ -3060,8 +3077,8 @@ public class MongoTemplate
|
||||
private final FindAndReplaceOptions options;
|
||||
|
||||
FindAndReplaceCallback(CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query,
|
||||
Document fields, Document sort,
|
||||
Document update, @Nullable com.mongodb.client.model.Collation collation, FindAndReplaceOptions options) {
|
||||
Document fields, Document sort, Document update, @Nullable com.mongodb.client.model.Collation collation,
|
||||
FindAndReplaceOptions options) {
|
||||
this.collectionPreparer = collectionPreparer;
|
||||
this.query = query;
|
||||
this.fields = fields;
|
||||
|
||||
@@ -170,7 +170,7 @@ class ReactiveFindOperationSupport implements ReactiveFindOperation {
|
||||
Document queryObject = query.getQueryObject();
|
||||
Document fieldsObject = query.getFieldsObject();
|
||||
|
||||
return template.doFind(ReactiveCollectionPreparerDelegate.of(query), getCollectionName(), queryObject,
|
||||
return template.doFind(getCollectionName(), ReactiveCollectionPreparerDelegate.of(query), queryObject,
|
||||
fieldsObject, domainType, returnType, preparer != null ? preparer : getCursorPreparer(query));
|
||||
}
|
||||
|
||||
|
||||
@@ -147,9 +147,18 @@ import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
* extract results. This class executes BSON queries or updates, initiating iteration over {@link FindPublisher} and
|
||||
* catching MongoDB exceptions and translating them to the generic, more informative exception hierarchy defined in the
|
||||
* org.springframework.dao package. Can be used within a service implementation via direct instantiation with a
|
||||
* {@link SimpleReactiveMongoDatabaseFactory} reference, or get prepared in an application context and given to services
|
||||
* as bean reference. Note: The {@link SimpleReactiveMongoDatabaseFactory} should always be configured as a bean in the
|
||||
* application context, in the first case given to the service directly, in the second case to the prepared template.
|
||||
* {@link ReactiveMongoDatabaseFactory} reference, or get prepared in an application context and given to services as
|
||||
* bean reference.
|
||||
* <p>
|
||||
* Note: The {@link ReactiveMongoDatabaseFactory} should always be configured as a bean in the application context, in
|
||||
* the first case given to the service directly, in the second case to the prepared template.
|
||||
* <h3>{@link ReadPreference} and {@link com.mongodb.ReadConcern}</h3>
|
||||
* <p>
|
||||
* {@code ReadPreference} and {@code ReadConcern} are generally considered from {@link Query} and
|
||||
* {@link AggregationOptions} objects for the action to be executed on a particular {@link MongoCollection}.
|
||||
* <p>
|
||||
* You can also set the default {@link #setReadPreference(ReadPreference) ReadPreference} on the template level to
|
||||
* generally apply a {@link ReadPreference}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
@@ -756,7 +765,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
public <T> Mono<T> findOne(Query query, Class<T> entityClass, String collectionName) {
|
||||
|
||||
if (ObjectUtils.isEmpty(query.getSortObject())) {
|
||||
return doFindOne(ReactiveCollectionPreparerDelegate.of(query), collectionName, query.getQueryObject(),
|
||||
return doFindOne(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
|
||||
query.getFieldsObject(), entityClass, new QueryFindPublisherPreparer(query, entityClass));
|
||||
}
|
||||
|
||||
@@ -812,7 +821,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
return findAll(entityClass, collectionName);
|
||||
}
|
||||
|
||||
return doFind(ReactiveCollectionPreparerDelegate.of(query), collectionName, query.getQueryObject(),
|
||||
return doFind(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
|
||||
query.getFieldsObject(), entityClass, new QueryFindPublisherPreparer(query, entityClass));
|
||||
}
|
||||
|
||||
@@ -826,7 +835,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
|
||||
String idKey = operations.getIdPropertyName(entityClass);
|
||||
|
||||
return doFindOne(CollectionPreparer.identity(), collectionName, new Document(idKey, id), null, entityClass,
|
||||
return doFindOne(collectionName, CollectionPreparer.identity(), new Document(idKey, id), null, entityClass,
|
||||
(Collation) null);
|
||||
}
|
||||
|
||||
@@ -1030,7 +1039,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
operations.forType(entityClass).getCollation(query).ifPresent(optionsToUse::collation);
|
||||
}
|
||||
|
||||
return doFindAndModify(ReactiveCollectionPreparerDelegate.of(query), collectionName, query.getQueryObject(),
|
||||
return doFindAndModify(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
|
||||
query.getFieldsObject(), getMappedSortObject(query, entityClass), entityClass, update, optionsToUse);
|
||||
}
|
||||
|
||||
@@ -1073,7 +1082,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
mapped.getCollection()));
|
||||
}).flatMap(it -> {
|
||||
|
||||
Mono<T> afterFindAndReplace = doFindAndReplace(collectionPreparer, it.getCollection(), mappedQuery,
|
||||
Mono<T> afterFindAndReplace = doFindAndReplace(it.getCollection(), collectionPreparer, mappedQuery,
|
||||
mappedFields, mappedSort, queryContext.getCollation(entityType).orElse(null), entityType, it.getTarget(),
|
||||
options, projection);
|
||||
return afterFindAndReplace.flatMap(saved -> {
|
||||
@@ -1093,7 +1102,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
public <T> Mono<T> findAndRemove(Query query, Class<T> entityClass, String collectionName) {
|
||||
|
||||
operations.forType(entityClass).getCollation(query);
|
||||
return doFindAndRemove(ReactiveCollectionPreparerDelegate.of(query), collectionName, query.getQueryObject(),
|
||||
return doFindAndRemove(collectionName, ReactiveCollectionPreparerDelegate.of(query), query.getQueryObject(),
|
||||
query.getFieldsObject(), getMappedSortObject(query, entityClass),
|
||||
operations.forType(entityClass).getCollation(query).orElse(null), entityClass);
|
||||
}
|
||||
@@ -1886,7 +1895,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
collectionName);
|
||||
}
|
||||
|
||||
return doFind(collectionPreparer, collectionName, query.getQueryObject(), query.getFieldsObject(), entityClass,
|
||||
return doFind(collectionName, collectionPreparer, query.getQueryObject(), query.getFieldsObject(), entityClass,
|
||||
new TailingQueryFindPublisherPreparer(query, entityClass));
|
||||
}
|
||||
|
||||
@@ -2144,17 +2153,18 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* The query document is specified as a standard {@link Document} and so is the fields specification.
|
||||
*
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @param collation can be {@literal null}.
|
||||
* @return the {@link List} of converted objects.
|
||||
*/
|
||||
protected <T> Mono<T> doFindOne(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document query, @Nullable Document fields, Class<T> entityClass,
|
||||
@Nullable Collation collation) {
|
||||
protected <T> Mono<T> doFindOne(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, @Nullable Document fields,
|
||||
Class<T> entityClass, @Nullable Collation collation) {
|
||||
|
||||
return doFindOne(collectionPreparer, collectionName, query, fields, entityClass,
|
||||
return doFindOne(collectionName, collectionPreparer, query, fields, entityClass,
|
||||
findPublisher -> collation != null ? findPublisher.collation(collation.toMongoCollation()) : findPublisher);
|
||||
}
|
||||
|
||||
@@ -2163,6 +2173,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* The query document is specified as a standard {@link Document} and so is the fields specification.
|
||||
*
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
@@ -2170,9 +2181,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* @return the {@link List} of converted objects.
|
||||
* @since 2.2
|
||||
*/
|
||||
protected <T> Mono<T> doFindOne(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document query, @Nullable Document fields, Class<T> entityClass,
|
||||
FindPublisherPreparer preparer) {
|
||||
protected <T> Mono<T> doFindOne(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, @Nullable Document fields,
|
||||
Class<T> entityClass, FindPublisherPreparer preparer) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
@@ -2195,14 +2206,15 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* 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
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record
|
||||
* @param fields the document that specifies the fields to be returned
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @return the List of converted objects.
|
||||
*/
|
||||
protected <T> Flux<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPreparer, String collectionName,
|
||||
protected <T> Flux<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, Class<T> entityClass) {
|
||||
return doFind(collectionPreparer, collectionName, query, fields, entityClass, null,
|
||||
return doFind(collectionName, collectionPreparer, query, fields, entityClass, null,
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
@@ -2212,6 +2224,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* specified as a standard Document and so is the fields specification.
|
||||
*
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param fields the document that specifies the fields to be returned.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
@@ -2219,15 +2232,15 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* the result set, (apply limits, skips and so on).
|
||||
* @return the {@link List} of converted objects.
|
||||
*/
|
||||
protected <T> Flux<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPreparer, String collectionName,
|
||||
protected <T> Flux<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, Class<T> entityClass, FindPublisherPreparer preparer) {
|
||||
return doFind(collectionPreparer, collectionName, query, fields, entityClass, preparer,
|
||||
return doFind(collectionName, collectionPreparer, query, fields, entityClass, preparer,
|
||||
new ReadDocumentCallback<>(mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
protected <S, T> Flux<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document query, Document fields, Class<S> entityClass,
|
||||
@Nullable FindPublisherPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
protected <S, T> Flux<T> doFind(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, Document fields,
|
||||
Class<S> entityClass, @Nullable FindPublisherPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
@@ -2250,7 +2263,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
<S, T> Flux<T> doFind(CollectionPreparer<MongoCollection<Document>> collectionPreparer, String collectionName,
|
||||
<S, T> Flux<T> doFind(String collectionName, CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
Document query, Document fields, Class<S> sourceClass, Class<T> targetClass, FindPublisherPreparer preparer) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(sourceClass);
|
||||
@@ -2283,15 +2296,16 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* The first document that matches the query is returned and also removed from the collection in the database. <br />
|
||||
* 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
|
||||
* @param query the query document that specifies the criteria used to find a record
|
||||
* @param collation collation
|
||||
* @param collectionName name of the collection to retrieve the objects from.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param query the query document that specifies the criteria used to find a record.
|
||||
* @param collation collation.
|
||||
* @param entityClass the parameterized type of the returned list.
|
||||
* @return the List of converted objects.
|
||||
*/
|
||||
protected <T> Mono<T> doFindAndRemove(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document query, Document fields, Document sort, @Nullable Collation collation,
|
||||
Class<T> entityClass) {
|
||||
protected <T> Mono<T> doFindAndRemove(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, Document fields, Document sort,
|
||||
@Nullable Collation collation, Class<T> entityClass) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug(String.format("findAndRemove using query: %s fields: %s sort: %s for class: %s in collection: %s",
|
||||
@@ -2305,9 +2319,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
new ReadDocumentCallback<>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
protected <T> Mono<T> doFindAndModify(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document query, Document fields, Document sort, Class<T> entityClass,
|
||||
UpdateDefinition update, FindAndModifyOptions options) {
|
||||
protected <T> Mono<T> doFindAndModify(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document query, Document fields, Document sort,
|
||||
Class<T> entityClass, UpdateDefinition update, FindAndModifyOptions options) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
UpdateContext updateContext = queryOperations.updateSingleContext(update, query, false);
|
||||
@@ -2337,6 +2351,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* Customize this part for findAndReplace.
|
||||
*
|
||||
* @param collectionName The name of the collection to perform the operation in.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param mappedQuery the query to look up documents.
|
||||
* @param mappedFields the fields to project the result to.
|
||||
* @param mappedSort the sort to be applied when executing the query.
|
||||
@@ -2349,14 +2364,14 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* {@literal false} and {@link FindAndReplaceOptions#isUpsert() upsert} is {@literal false}.
|
||||
* @since 2.1
|
||||
*/
|
||||
protected <T> Mono<T> doFindAndReplace(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document mappedQuery, Document mappedFields, Document mappedSort,
|
||||
com.mongodb.client.model.Collation collation, Class<?> entityType, Document replacement,
|
||||
protected <T> Mono<T> doFindAndReplace(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document mappedQuery, Document mappedFields,
|
||||
Document mappedSort, com.mongodb.client.model.Collation collation, Class<?> entityType, Document replacement,
|
||||
FindAndReplaceOptions options, Class<T> resultType) {
|
||||
|
||||
EntityProjection<T, ?> projection = operations.introspectProjection(resultType, entityType);
|
||||
|
||||
return doFindAndReplace(collectionPreparer, collectionName, mappedQuery, mappedFields, mappedSort, collation,
|
||||
return doFindAndReplace(collectionName, collectionPreparer, mappedQuery, mappedFields, mappedSort, collation,
|
||||
entityType, replacement, options, projection);
|
||||
}
|
||||
|
||||
@@ -2364,6 +2379,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* Customize this part for findAndReplace.
|
||||
*
|
||||
* @param collectionName The name of the collection to perform the operation in.
|
||||
* @param collectionPreparer the preparer to prepare the collection for the actual use.
|
||||
* @param mappedQuery the query to look up documents.
|
||||
* @param mappedFields the fields to project the result to.
|
||||
* @param mappedSort the sort to be applied when executing the query.
|
||||
@@ -2376,9 +2392,9 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
|
||||
* {@literal false} and {@link FindAndReplaceOptions#isUpsert() upsert} is {@literal false}.
|
||||
* @since 3.4
|
||||
*/
|
||||
private <T> Mono<T> doFindAndReplace(CollectionPreparer<MongoCollection<Document>> collectionPreparer,
|
||||
String collectionName, Document mappedQuery, Document mappedFields, Document mappedSort,
|
||||
com.mongodb.client.model.Collation collation, Class<?> entityType, Document replacement,
|
||||
private <T> Mono<T> doFindAndReplace(String collectionName,
|
||||
CollectionPreparer<MongoCollection<Document>> collectionPreparer, Document mappedQuery, Document mappedFields,
|
||||
Document mappedSort, com.mongodb.client.model.Collation collation, Class<?> entityType, Document replacement,
|
||||
FindAndReplaceOptions options, EntityProjection<T, ?> projection) {
|
||||
|
||||
return Mono.defer(() -> {
|
||||
|
||||
@@ -26,6 +26,8 @@ import com.mongodb.ReadConcern;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 4.1
|
||||
* @see org.springframework.data.mongodb.core.query.Query
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOptions
|
||||
*/
|
||||
public interface ReadConcernAware {
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ import com.mongodb.ReadPreference;
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
* @since 2.2
|
||||
* @see org.springframework.data.mongodb.core.query.Query
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOptions
|
||||
*/
|
||||
public interface ReadPreferenceAware {
|
||||
|
||||
|
||||
@@ -387,7 +387,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719
|
||||
void appliesFieldsWhenInterfaceProjectionIsClosedAndQueryDoesNotDefineFields() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document(), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document(), Person.class,
|
||||
PersonProjection.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher).projection(eq(new Document("firstname", 1)));
|
||||
@@ -396,7 +396,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719
|
||||
void doesNotApplyFieldsWhenInterfaceProjectionIsClosedAndQueryDefinesFields() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document("bar", 1), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document("bar", 1), Person.class,
|
||||
PersonProjection.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher).projection(eq(new Document("bar", 1)));
|
||||
@@ -405,7 +405,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719
|
||||
void doesNotApplyFieldsWhenInterfaceProjectionIsOpen() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document(), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document(), Person.class,
|
||||
PersonSpELProjection.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher, never()).projection(any());
|
||||
@@ -414,7 +414,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719, DATAMONGO-2041
|
||||
void appliesFieldsToDtoProjection() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document(), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document(), Person.class,
|
||||
Jedi.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher).projection(eq(new Document("firstname", 1)));
|
||||
@@ -423,7 +423,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719
|
||||
void doesNotApplyFieldsToDtoProjectionWhenQueryDefinesFields() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document("bar", 1), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document("bar", 1), Person.class,
|
||||
Jedi.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher).projection(eq(new Document("bar", 1)));
|
||||
@@ -432,7 +432,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719
|
||||
void doesNotApplyFieldsWhenTargetIsNotAProjection() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document(), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document(), Person.class,
|
||||
Person.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher, never()).projection(any());
|
||||
@@ -441,7 +441,7 @@ public class ReactiveMongoTemplateUnitTests {
|
||||
@Test // DATAMONGO-1719
|
||||
void doesNotApplyFieldsWhenTargetExtendsDomainType() {
|
||||
|
||||
template.doFind(CollectionPreparer.identity(), "star-wars", new Document(), new Document(), Person.class,
|
||||
template.doFind("star-wars", CollectionPreparer.identity(), new Document(), new Document(), Person.class,
|
||||
PersonExtended.class, FindPublisherPreparer.NO_OP_PREPARER).subscribe();
|
||||
|
||||
verify(findPublisher, never()).projection(any());
|
||||
|
||||
Reference in New Issue
Block a user