Skip to content

Commit ff7a189

Browse files
committed
DATAMONGO-2296 - Polishing.
Use getCollectionName() in MongoTemplate.insert/save. Consistently use getCollectionName(Class) from ReactiveMongoTemplate and fluent API implementations. Original pull request: #768.
1 parent de144a6 commit ff7a189

13 files changed

+56
-90
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/EntityOperations.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,6 @@ public String determineCollectionName(@Nullable Class<?> entityClass) {
118118
return context.getRequiredPersistentEntity(entityClass).getCollection();
119119
}
120120

121-
/**
122-
* Returns the collection name to be used for the given entity.
123-
*
124-
* @param obj can be {@literal null}.
125-
* @return
126-
*/
127-
@Nullable
128-
public String determineEntityCollectionName(@Nullable Object obj) {
129-
return null == obj ? null : determineCollectionName(obj.getClass());
130-
}
131-
132121
public Query getByIdInQuery(Collection<?> entities) {
133122

134123
MultiValueMap<String, Object> byIds = new LinkedMultiValueMap<>();

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,7 +1199,7 @@ public <T> T insert(T objectToSave) {
11991199
Assert.notNull(objectToSave, "ObjectToSave must not be null!");
12001200

12011201
ensureNotIterable(objectToSave);
1202-
return insert(objectToSave, operations.determineEntityCollectionName(objectToSave));
1202+
return insert(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave)));
12031203
}
12041204

12051205
/*
@@ -1330,9 +1330,7 @@ protected <T> Collection<T> doInsertAll(Collection<? extends T> listToSave, Mong
13301330
continue;
13311331
}
13321332

1333-
MongoPersistentEntity<?> entity = mappingContext.getRequiredPersistentEntity(element.getClass());
1334-
1335-
String collection = entity.getCollection();
1333+
String collection = getCollectionName(ClassUtils.getUserClass(element));
13361334
List<T> collectionElements = elementsByCollection.get(collection);
13371335

13381336
if (null == collectionElements) {
@@ -1398,7 +1396,7 @@ protected <T> Collection<T> doInsertBatch(String collectionName, Collection<? ex
13981396
public <T> T save(T objectToSave) {
13991397

14001398
Assert.notNull(objectToSave, "Object to save must not be null!");
1401-
return save(objectToSave, operations.determineEntityCollectionName(objectToSave));
1399+
return save(objectToSave, getCollectionName(ClassUtils.getUserClass(objectToSave)));
14021400
}
14031401

14041402
@Override

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveAggregationOperationSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ private String getCollectionName(Aggregation aggregation) {
116116
TypedAggregation<?> typedAggregation = (TypedAggregation<?>) aggregation;
117117

118118
if (typedAggregation.getInputType() != null) {
119-
return template.determineCollectionName(typedAggregation.getInputType());
119+
return template.getCollectionName(typedAggregation.getInputType());
120120
}
121121
}
122122

123-
return template.determineCollectionName(domainType);
123+
return template.getCollectionName(domainType);
124124
}
125125
}
126126
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveFindOperationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private FindPublisherPreparer getCursorPreparer(Query query) {
238238
}
239239

240240
private String getCollectionName() {
241-
return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType);
241+
return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType);
242242
}
243243

244244
private String asString() {

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveInsertOperationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ReactiveInsert<T> inCollection(String collection) {
9696
}
9797

9898
private String getCollectionName() {
99-
return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType);
99+
return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType);
100100
}
101101
}
102102
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMapReduceOperationSupport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public ReactiveMapReduce<T> reduce(String reduceFunction) {
171171
}
172172

173173
private String getCollectionName() {
174-
return StringUtils.hasText(collection) ? collection : template.determineCollectionName(domainType);
174+
return StringUtils.hasText(collection) ? collection : template.getCollectionName(domainType);
175175
}
176176
}
177177
}

0 commit comments

Comments
 (0)