From a9403b526f83f8d4770822c704f7a80548fdc64b Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Mon, 1 Jul 2019 16:35:48 +0200 Subject: [PATCH] DATAMONGO-2296 - Polishing. Use getCollectionName() in MongoTemplate.insert/save. Consistently use getCollectionName(Class) from ReactiveMongoTemplate and fluent API implementations. Original pull request: #768. --- .../data/mongodb/core/EntityOperations.java | 11 --- .../data/mongodb/core/MongoTemplate.java | 8 +- .../ReactiveAggregationOperationSupport.java | 4 +- .../core/ReactiveFindOperationSupport.java | 2 +- .../core/ReactiveInsertOperationSupport.java | 2 +- .../ReactiveMapReduceOperationSupport.java | 2 +- .../mongodb/core/ReactiveMongoTemplate.java | 87 +++++++------------ .../core/ReactiveRemoveOperationSupport.java | 2 +- .../core/ReactiveUpdateOperationSupport.java | 8 +- ...eAggregationOperationSupportUnitTests.java | 8 +- ...activeInsertOperationSupportUnitTests.java | 8 +- ...iveMapReduceOperationSupportUnitTests.java | 2 +- .../core/ReactiveMongoTemplateTests.java | 4 +- 13 files changed, 57 insertions(+), 91 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java index 9ad94b808..12f4b9d90 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java @@ -116,17 +116,6 @@ class EntityOperations { return context.getRequiredPersistentEntity(entityClass).getCollection(); } - /** - * Returns the collection name to be used for the given entity. - * - * @param obj can be {@literal null}. - * @return - */ - @Nullable - public String determineEntityCollectionName(@Nullable Object obj) { - return null == obj ? null : determineCollectionName(obj.getClass()); - } - public Query getByIdInQuery(Collection entities) { MultiValueMap byIds = new LinkedMultiValueMap<>(); 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 9d208993c..70f80f0d5 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 @@ -1160,7 +1160,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, Assert.notNull(objectToSave, "ObjectToSave must not be null!"); ensureNotIterable(objectToSave); - return insert(objectToSave, operations.determineEntityCollectionName(objectToSave)); + return insert(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave))); } /* @@ -1289,9 +1289,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, continue; } - MongoPersistentEntity entity = mappingContext.getRequiredPersistentEntity(element.getClass()); - - String collection = entity.getCollection(); + String collection = getCollectionName(ClassUtils.getUserClass(element)); List collectionElements = elementsByCollection.get(collection); if (null == collectionElements) { @@ -1355,7 +1353,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware, public T save(T objectToSave) { Assert.notNull(objectToSave, "Object to save must not be null!"); - return save(objectToSave, operations.determineEntityCollectionName(objectToSave)); + return save(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave))); } @Override diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupport.java index 231039b0e..1079a8b9f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupport.java @@ -116,11 +116,11 @@ class ReactiveAggregationOperationSupport implements ReactiveAggregationOperatio TypedAggregation typedAggregation = (TypedAggregation) aggregation; if (typedAggregation.getInputType() != null) { - return template.determineCollectionName(typedAggregation.getInputType()); + return template.getCollectionName(typedAggregation.getInputType()); } } - return template.determineCollectionName(domainType); + return template.getCollectionName(domainType); } } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java index 533a7ed8b..ecc59bc9f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java @@ -238,7 +238,7 @@ class ReactiveFindOperationSupport implements ReactiveFindOperation { } private String getCollectionName() { - return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType); + return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType); } private String asString() { diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupport.java index aeef8e5ab..85bb3766f 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupport.java @@ -96,7 +96,7 @@ class ReactiveInsertOperationSupport implements ReactiveInsertOperation { } private String getCollectionName() { - return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType); + return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType); } } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupport.java index aa51449b3..839aefcc4 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupport.java @@ -171,7 +171,7 @@ class ReactiveMapReduceOperationSupport implements ReactiveMapReduceOperation { } private String getCollectionName() { - return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType); + return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType); } } } 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 06aa1f59d..a14ee5959 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 @@ -375,12 +375,12 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#reactiveIndexOps(java.lang.Class) */ public ReactiveIndexOperations indexOps(Class entityClass) { - return new DefaultReactiveIndexOperations(this, determineCollectionName(entityClass), this.queryMapper, + return new DefaultReactiveIndexOperations(this, getCollectionName(entityClass), this.queryMapper, entityClass); } public String getCollectionName(Class entityClass) { - return this.determineCollectionName(entityClass); + return operations.determineCollectionName(entityClass); } /* @@ -420,7 +420,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ @Override public Flux execute(Class entityClass, ReactiveCollectionCallback action) { - return createFlux(determineCollectionName(entityClass), action); + return createFlux(getCollectionName(entityClass), action); } /* @@ -606,7 +606,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#createCollection(java.lang.Class) */ public Mono> createCollection(Class entityClass) { - return createCollection(determineCollectionName(entityClass)); + return createCollection(getCollectionName(entityClass)); } /* @@ -615,7 +615,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ public Mono> createCollection(Class entityClass, @Nullable CollectionOptions collectionOptions) { - return doCreateCollection(determineCollectionName(entityClass), + return doCreateCollection(getCollectionName(entityClass), convertToCreateCollectionOptions(collectionOptions, entityClass)); } @@ -649,7 +649,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#collectionExists(java.lang.Class) */ public Mono collectionExists(Class entityClass) { - return collectionExists(determineCollectionName(entityClass)); + return collectionExists(getCollectionName(entityClass)); } /* @@ -668,7 +668,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#dropCollection(java.lang.Class) */ public Mono dropCollection(Class entityClass) { - return dropCollection(determineCollectionName(entityClass)); + return dropCollection(getCollectionName(entityClass)); } /* @@ -705,7 +705,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findOne(org.springframework.data.mongodb.core.query.Query, java.lang.Class) */ public Mono findOne(Query query, Class entityClass) { - return findOne(query, entityClass, determineCollectionName(entityClass)); + return findOne(query, entityClass, getCollectionName(entityClass)); } /* @@ -728,7 +728,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#exists(org.springframework.data.mongodb.core.query.Query, java.lang.Class) */ public Mono exists(Query query, Class entityClass) { - return exists(query, entityClass, determineCollectionName(entityClass)); + return exists(query, entityClass, getCollectionName(entityClass)); } /* @@ -771,7 +771,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#find(org.springframework.data.mongodb.core.query.Query, java.lang.Class) */ public Flux find(Query query, Class entityClass) { - return find(query, entityClass, determineCollectionName(entityClass)); + return find(query, entityClass, getCollectionName(entityClass)); } /* @@ -793,7 +793,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findById(java.lang.Object, java.lang.Class) */ public Mono findById(Object id, Class entityClass) { - return findById(id, entityClass, determineCollectionName(entityClass)); + return findById(id, entityClass, getCollectionName(entityClass)); } /* @@ -812,7 +812,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findDistinct(org.springframework.data.mongodb.core.query.Query, java.lang.String, java.lang.Class, java.lang.Class) */ public Flux findDistinct(Query query, String field, Class entityClass, Class resultClass) { - return findDistinct(query, field, determineCollectionName(entityClass), entityClass, resultClass); + return findDistinct(query, field, getCollectionName(entityClass), entityClass, resultClass); } /* @@ -907,7 +907,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ @Override public Flux aggregate(TypedAggregation aggregation, Class outputType) { - return aggregate(aggregation, determineCollectionName(aggregation.getInputType()), outputType); + return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType); } /* @@ -917,7 +917,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati @Override public Flux aggregate(Aggregation aggregation, Class inputType, Class outputType) { - return aggregate(aggregation, determineCollectionName(inputType), outputType, + return aggregate(aggregation, getCollectionName(inputType), outputType, new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper)); } @@ -983,7 +983,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ @Override public Flux> geoNear(NearQuery near, Class entityClass) { - return geoNear(near, entityClass, determineCollectionName(entityClass)); + return geoNear(near, entityClass, getCollectionName(entityClass)); } /* @@ -1007,7 +1007,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati throw new InvalidDataAccessApiUsageException("Entity class must not be null!"); } - String collection = StringUtils.hasText(collectionName) ? collectionName : determineCollectionName(entityClass); + String collection = StringUtils.hasText(collectionName) ? collectionName : getCollectionName(entityClass); Document nearDocument = near.toDocument(); Document command = new Document("geoNear", collection); @@ -1043,7 +1043,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findAndModify(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.Class) */ public Mono findAndModify(Query query, Update update, Class entityClass) { - return findAndModify(query, update, new FindAndModifyOptions(), entityClass, determineCollectionName(entityClass)); + return findAndModify(query, update, new FindAndModifyOptions(), entityClass, getCollectionName(entityClass)); } /* @@ -1059,7 +1059,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findAndModify(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, org.springframework.data.mongodb.core.FindAndModifyOptions, java.lang.Class) */ public Mono findAndModify(Query query, Update update, FindAndModifyOptions options, Class entityClass) { - return findAndModify(query, update, options, entityClass, determineCollectionName(entityClass)); + return findAndModify(query, update, options, entityClass, getCollectionName(entityClass)); } /* @@ -1118,7 +1118,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findAndRemove(org.springframework.data.mongodb.core.query.Query, java.lang.Class) */ public Mono findAndRemove(Query query, Class entityClass) { - return findAndRemove(query, entityClass, determineCollectionName(entityClass)); + return findAndRemove(query, entityClass, getCollectionName(entityClass)); } /* @@ -1139,7 +1139,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati Assert.notNull(entityClass, "Entity class must not be null!"); - return count(query, entityClass, determineCollectionName(entityClass)); + return count(query, entityClass, getCollectionName(entityClass)); } /* @@ -1196,7 +1196,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ @Override public Flux insertAll(Mono> batchToSave, Class entityClass) { - return insertAll(batchToSave, determineCollectionName(entityClass)); + return insertAll(batchToSave, getCollectionName(entityClass)); } /* @@ -1220,7 +1220,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati Assert.notNull(objectToSave, "Object to insert must not be null!"); ensureNotIterable(objectToSave); - return insert(objectToSave, determineEntityCollectionName(objectToSave)); + return insert(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave))); } /* @@ -1266,7 +1266,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#insert(java.util.Collection, java.lang.Class) */ public Flux insert(Collection batchToSave, Class entityClass) { - return doInsertBatch(determineCollectionName(entityClass), batchToSave, this.mongoConverter); + return doInsertBatch(getCollectionName(entityClass), batchToSave, this.mongoConverter); } /* @@ -1300,9 +1300,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati listToSave.forEach(element -> { - MongoPersistentEntity entity = mappingContext.getRequiredPersistentEntity(element.getClass()); - - String collection = entity.getCollection(); + String collection = getCollectionName(element.getClass()); List collectionElements = elementsByCollection.computeIfAbsent(collection, k -> new ArrayList<>()); collectionElements.add(element); @@ -1382,7 +1380,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati public Mono save(T objectToSave) { Assert.notNull(objectToSave, "Object to save must not be null!"); - return save(objectToSave, determineEntityCollectionName(objectToSave)); + return save(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave))); } /* @@ -1546,7 +1544,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#upsert(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.Class) */ public Mono upsert(Query query, Update update, Class entityClass) { - return doUpdate(determineCollectionName(entityClass), query, update, entityClass, true, false); + return doUpdate(getCollectionName(entityClass), query, update, entityClass, true, false); } /* @@ -1570,7 +1568,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#updateFirst(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.Class) */ public Mono updateFirst(Query query, Update update, Class entityClass) { - return doUpdate(determineCollectionName(entityClass), query, update, entityClass, false, false); + return doUpdate(getCollectionName(entityClass), query, update, entityClass, false, false); } /* @@ -1594,7 +1592,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#updateMulti(org.springframework.data.mongodb.core.query.Query, org.springframework.data.mongodb.core.query.Update, java.lang.Class) */ public Mono updateMulti(Query query, Update update, Class entityClass) { - return doUpdate(determineCollectionName(entityClass), query, update, entityClass, false, true); + return doUpdate(getCollectionName(entityClass), query, update, entityClass, false, true); } /* @@ -1770,7 +1768,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#remove(org.springframework.data.mongodb.core.query.Query, java.lang.Class) */ public Mono remove(Query query, Class entityClass) { - return remove(query, entityClass, determineCollectionName(entityClass)); + return remove(query, entityClass, getCollectionName(entityClass)); } /* @@ -1838,7 +1836,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati * @see org.springframework.data.mongodb.core.ReactiveMongoOperations#findAll(java.lang.Class) */ public Flux findAll(Class entityClass) { - return findAll(entityClass, determineCollectionName(entityClass)); + return findAll(entityClass, getCollectionName(entityClass)); } /* @@ -1866,7 +1864,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ @Override public Flux findAllAndRemove(Query query, Class entityClass) { - return findAllAndRemove(query, entityClass, determineCollectionName(entityClass)); + return findAllAndRemove(query, entityClass, getCollectionName(entityClass)); } /* @@ -1884,7 +1882,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati */ @Override public Flux tail(Query query, Class entityClass) { - return tail(query, entityClass, determineCollectionName(entityClass)); + return tail(query, entityClass, getCollectionName(entityClass)); } /* @@ -1967,7 +1965,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati public Flux mapReduce(Query filterQuery, Class domainType, Class resultType, String mapFunction, String reduceFunction, MapReduceOptions options) { - return mapReduce(filterQuery, domainType, determineCollectionName(domainType), resultType, mapFunction, + return mapReduce(filterQuery, domainType, getCollectionName(domainType), resultType, mapFunction, reduceFunction, options); } @@ -2595,25 +2593,6 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati return type == null ? null : mappingContext.getPersistentEntity(type); } - private String determineEntityCollectionName(@Nullable T obj) { - - if (null != obj) { - return determineCollectionName(obj.getClass()); - } - - return null; - } - - String determineCollectionName(@Nullable Class entityClass) { - - if (entityClass == null) { - throw new InvalidDataAccessApiUsageException( - "No class parameter provided, entity collection can't be determined!"); - } - - return mappingContext.getRequiredPersistentEntity(entityClass).getCollection(); - } - private static MappingMongoConverter getDefaultMongoConverter() { MongoCustomConversions conversions = new MongoCustomConversions(Collections.emptyList()); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveRemoveOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveRemoveOperationSupport.java index ee992d0f8..23a1578a0 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveRemoveOperationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveRemoveOperationSupport.java @@ -112,7 +112,7 @@ class ReactiveRemoveOperationSupport implements ReactiveRemoveOperation { } private String getCollectionName() { - return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType); + return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveUpdateOperationSupport.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveUpdateOperationSupport.java index c4b507e38..9adcb3699 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveUpdateOperationSupport.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveUpdateOperationSupport.java @@ -126,7 +126,7 @@ class ReactiveUpdateOperationSupport implements ReactiveUpdateOperation { return template.findAndModify(query, update, findAndModifyOptions, targetType, collectionName); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.ReactiveUpdateOperation.TerminatingFindAndReplace#findAndReplace() */ @@ -172,7 +172,7 @@ class ReactiveUpdateOperationSupport implements ReactiveUpdateOperation { findAndReplaceOptions, replacement, targetType); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.ReactiveUpdateOperation.UpdateWithUpdate#replaceWith(java.lang.Object) */ @@ -185,7 +185,7 @@ class ReactiveUpdateOperationSupport implements ReactiveUpdateOperation { findAndReplaceOptions, replacement, targetType); } - /* + /* * (non-Javadoc) * @see org.springframework.data.mongodb.core.ReactiveUpdateOperation.FindAndReplaceWithOptions#withOptions(org.springframework.data.mongodb.core.FindAndReplaceOptions) */ @@ -216,7 +216,7 @@ class ReactiveUpdateOperationSupport implements ReactiveUpdateOperation { } private String getCollectionName() { - return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType); + return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType); } } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupportUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupportUnitTests.java index 73111dab7..b00ac7547 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupportUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupportUnitTests.java @@ -78,13 +78,13 @@ public class ReactiveAggregationOperationSupportUnitTests { @Test // DATAMONGO-1719 public void aggregateWithUntypedAggregation() { - when(template.determineCollectionName(any(Class.class))).thenReturn("person"); + when(template.getCollectionName(any(Class.class))).thenReturn("person"); opSupport.aggregateAndReturn(Person.class).by(newAggregation(project("foo"))).all(); ArgumentCaptor captor = ArgumentCaptor.forClass(Class.class); - verify(template).determineCollectionName(captor.capture()); + verify(template).getCollectionName(captor.capture()); verify(template).aggregate(any(Aggregation.class), eq("person"), captor.capture()); assertThat(captor.getAllValues()).containsExactly(Person.class, Person.class); @@ -93,13 +93,13 @@ public class ReactiveAggregationOperationSupportUnitTests { @Test // DATAMONGO-1719 public void aggregateWithTypeAggregation() { - when(template.determineCollectionName(any(Class.class))).thenReturn("person"); + when(template.getCollectionName(any(Class.class))).thenReturn("person"); opSupport.aggregateAndReturn(Jedi.class).by(newAggregation(Person.class, project("foo"))).all(); ArgumentCaptor captor = ArgumentCaptor.forClass(Class.class); - verify(template).determineCollectionName(captor.capture()); + verify(template).getCollectionName(captor.capture()); verify(template).aggregate(any(Aggregation.class), eq("person"), captor.capture()); assertThat(captor.getAllValues()).containsExactly(Person.class, Jedi.class); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupportUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupportUnitTests.java index e02c741f7..0bde222e1 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupportUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupportUnitTests.java @@ -52,7 +52,7 @@ public class ReactiveInsertOperationSupportUnitTests { @Before public void setUp() { - when(template.determineCollectionName(any(Class.class))).thenReturn(STAR_WARS); + when(template.getCollectionName(any(Class.class))).thenReturn(STAR_WARS); ops = new ReactiveInsertOperationSupport(template); @@ -77,7 +77,7 @@ public class ReactiveInsertOperationSupportUnitTests { ArgumentCaptor captor = ArgumentCaptor.forClass(Class.class); - verify(template).determineCollectionName(captor.capture()); + verify(template).getCollectionName(captor.capture()); verify(template).insert(eq(luke), eq(STAR_WARS)); assertThat(captor.getAllValues()).containsExactly(Person.class); @@ -88,7 +88,7 @@ public class ReactiveInsertOperationSupportUnitTests { ops.insert(Person.class).inCollection(STAR_WARS).one(luke); - verify(template, never()).determineCollectionName(any(Class.class)); + verify(template, never()).getCollectionName(any(Class.class)); verify(template).insert(eq(luke), eq(STAR_WARS)); } @@ -97,7 +97,7 @@ public class ReactiveInsertOperationSupportUnitTests { ops.insert(Person.class).all(Arrays.asList(luke, han)); - verify(template).determineCollectionName(any(Class.class)); + verify(template).getCollectionName(any(Class.class)); verify(template).insert(anyList(), eq(STAR_WARS)); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupportUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupportUnitTests.java index 388b09a31..96a5e3642 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupportUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupportUnitTests.java @@ -55,7 +55,7 @@ public class ReactiveMapReduceOperationSupportUnitTests { @Before public void setUp() { - when(template.determineCollectionName(eq(Person.class))).thenReturn(STAR_WARS); + when(template.getCollectionName(eq(Person.class))).thenReturn(STAR_WARS); mapReduceOpsSupport = new ReactiveMapReduceOperationSupport(template); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateTests.java index 360d09ca7..e2049a490 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveMongoTemplateTests.java @@ -708,7 +708,7 @@ public class ReactiveMongoTemplateTests { .expectNextCount(3) // .verifyComplete(); - StepVerifier.create(template.remove(Mono.just(spring), template.determineCollectionName(Sample.class))) + StepVerifier.create(template.remove(Mono.just(spring), template.getCollectionName(Sample.class))) .expectNextCount(1).verifyComplete(); StepVerifier.create(template.count(new Query(), Sample.class)).expectNext(2L).verifyComplete(); } @@ -756,7 +756,7 @@ public class ReactiveMongoTemplateTests { dbObject.put("firstName", "Oliver"); StepVerifier.create(template.insert(dbObject, // - template.determineCollectionName(PersonWithVersionPropertyOfTypeInteger.class))) // + template.getCollectionName(PersonWithVersionPropertyOfTypeInteger.class))) // .expectNextCount(1) // .verifyComplete(); }