Skip to content

Commit de144a6

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-2296 - Consistent use of getCollectionName(Class) throughout MongoTemplate.
Original pull request: #768.
1 parent bfe514a commit de144a6

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

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

+30-30
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ public MongoConverter getConverter() {
419419
@Override
420420
public <T> CloseableIterator<T> stream(final Query query, final Class<T> entityType) {
421421

422-
return stream(query, entityType, operations.determineCollectionName(entityType));
422+
return stream(query, entityType, getCollectionName(entityType));
423423
}
424424

425425
/*
@@ -565,7 +565,7 @@ public <T> T execute(DbCallback<T> action) {
565565
public <T> T execute(Class<?> entityClass, CollectionCallback<T> callback) {
566566

567567
Assert.notNull(entityClass, "EntityClass must not be null!");
568-
return execute(operations.determineCollectionName(entityClass), callback);
568+
return execute(getCollectionName(entityClass), callback);
569569
}
570570

571571
/*
@@ -643,7 +643,7 @@ public <T> MongoCollection<Document> createCollection(Class<T> entityClass,
643643
() -> operations.forType(entityClass).getCollation()) //
644644
.map(options::collation).orElse(options);
645645

646-
return doCreateCollection(operations.determineCollectionName(entityClass), convertToDocument(options, entityClass));
646+
return doCreateCollection(getCollectionName(entityClass), convertToDocument(options, entityClass));
647647
}
648648

649649
/*
@@ -685,7 +685,7 @@ public MongoCollection<Document> getCollection(final String collectionName) {
685685
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#getCollection(java.lang.Class)
686686
*/
687687
public <T> boolean collectionExists(Class<T> entityClass) {
688-
return collectionExists(operations.determineCollectionName(entityClass));
688+
return collectionExists(getCollectionName(entityClass));
689689
}
690690

691691
/*
@@ -713,7 +713,7 @@ public boolean collectionExists(final String collectionName) {
713713
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#dropCollection(java.lang.Class)
714714
*/
715715
public <T> void dropCollection(Class<T> entityClass) {
716-
dropCollection(operations.determineCollectionName(entityClass));
716+
dropCollection(getCollectionName(entityClass));
717717
}
718718

719719
/*
@@ -749,7 +749,7 @@ public IndexOperations indexOps(String collectionName) {
749749
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#indexOps(java.lang.Class)
750750
*/
751751
public IndexOperations indexOps(Class<?> entityClass) {
752-
return new DefaultIndexOperations(this, operations.determineCollectionName(entityClass), entityClass);
752+
return new DefaultIndexOperations(this, getCollectionName(entityClass), entityClass);
753753
}
754754

755755
/*
@@ -765,7 +765,7 @@ public BulkOperations bulkOps(BulkMode bulkMode, String collectionName) {
765765
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#bulkOps(org.springframework.data.mongodb.core.BulkMode, java.lang.Class)
766766
*/
767767
public BulkOperations bulkOps(BulkMode bulkMode, Class<?> entityClass) {
768-
return bulkOps(bulkMode, entityClass, operations.determineCollectionName(entityClass));
768+
return bulkOps(bulkMode, entityClass, getCollectionName(entityClass));
769769
}
770770

771771
/*
@@ -800,7 +800,7 @@ public ScriptOperations scriptOps() {
800800
@Nullable
801801
@Override
802802
public <T> T findOne(Query query, Class<T> entityClass) {
803-
return findOne(query, entityClass, operations.determineCollectionName(entityClass));
803+
return findOne(query, entityClass, getCollectionName(entityClass));
804804
}
805805

806806
@Nullable
@@ -825,7 +825,7 @@ public <T> T findOne(Query query, Class<T> entityClass, String collectionName) {
825825

826826
@Override
827827
public boolean exists(Query query, Class<?> entityClass) {
828-
return exists(query, entityClass, operations.determineCollectionName(entityClass));
828+
return exists(query, entityClass, getCollectionName(entityClass));
829829
}
830830

831831
@Override
@@ -856,7 +856,7 @@ public boolean exists(Query query, @Nullable Class<?> entityClass, String collec
856856
*/
857857
@Override
858858
public <T> List<T> find(Query query, Class<T> entityClass) {
859-
return find(query, entityClass, operations.determineCollectionName(entityClass));
859+
return find(query, entityClass, getCollectionName(entityClass));
860860
}
861861

862862
/*
@@ -877,7 +877,7 @@ public <T> List<T> find(Query query, Class<T> entityClass, String collectionName
877877
@Nullable
878878
@Override
879879
public <T> T findById(Object id, Class<T> entityClass) {
880-
return findById(id, entityClass, operations.determineCollectionName(entityClass));
880+
return findById(id, entityClass, getCollectionName(entityClass));
881881
}
882882

883883
@Nullable
@@ -899,7 +899,7 @@ public <T> T findById(Object id, Class<T> entityClass, String collectionName) {
899899
*/
900900
@Override
901901
public <T> List<T> findDistinct(Query query, String field, Class<?> entityClass, Class<T> resultClass) {
902-
return findDistinct(query, field, operations.determineCollectionName(entityClass), entityClass, resultClass);
902+
return findDistinct(query, field, getCollectionName(entityClass), entityClass, resultClass);
903903
}
904904

905905
/*
@@ -986,7 +986,7 @@ private static Class<?> getMostSpecificConversionTargetType(Class<?> userType, C
986986

987987
@Override
988988
public <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass) {
989-
return geoNear(near, entityClass, operations.determineCollectionName(entityClass));
989+
return geoNear(near, entityClass, getCollectionName(entityClass));
990990
}
991991

992992
@Override
@@ -1008,7 +1008,7 @@ public <T> GeoResults<T> geoNear(NearQuery near, Class<?> domainType, String col
10081008
Assert.notNull(returnType, "ReturnType must not be null!");
10091009

10101010
String collection = StringUtils.hasText(collectionName) ? collectionName
1011-
: operations.determineCollectionName(domainType);
1011+
: getCollectionName(domainType);
10121012
String distanceField = operations.nearQueryDistanceFieldName(domainType);
10131013

10141014
Aggregation $geoNear = TypedAggregation.newAggregation(domainType, Aggregation.geoNear(near, distanceField))
@@ -1040,7 +1040,7 @@ public <T> GeoResults<T> geoNear(NearQuery near, Class<?> domainType, String col
10401040
@Override
10411041
public <T> T findAndModify(Query query, Update update, Class<T> entityClass) {
10421042
return findAndModify(query, update, new FindAndModifyOptions(), entityClass,
1043-
operations.determineCollectionName(entityClass));
1043+
getCollectionName(entityClass));
10441044
}
10451045

10461046
@Nullable
@@ -1052,7 +1052,7 @@ public <T> T findAndModify(Query query, Update update, Class<T> entityClass, Str
10521052
@Nullable
10531053
@Override
10541054
public <T> T findAndModify(Query query, Update update, FindAndModifyOptions options, Class<T> entityClass) {
1055-
return findAndModify(query, update, options, entityClass, operations.determineCollectionName(entityClass));
1055+
return findAndModify(query, update, options, entityClass, getCollectionName(entityClass));
10561056
}
10571057

10581058
@Nullable
@@ -1122,7 +1122,7 @@ public <S, T> T findAndReplace(Query query, S replacement, FindAndReplaceOptions
11221122
@Nullable
11231123
@Override
11241124
public <T> T findAndRemove(Query query, Class<T> entityClass) {
1125-
return findAndRemove(query, entityClass, operations.determineCollectionName(entityClass));
1125+
return findAndRemove(query, entityClass, getCollectionName(entityClass));
11261126
}
11271127

11281128
@Nullable
@@ -1142,7 +1142,7 @@ public <T> T findAndRemove(Query query, Class<T> entityClass, String collectionN
11421142
public long count(Query query, Class<?> entityClass) {
11431143

11441144
Assert.notNull(entityClass, "Entity class must not be null!");
1145-
return count(query, entityClass, operations.determineCollectionName(entityClass));
1145+
return count(query, entityClass, getCollectionName(entityClass));
11461146
}
11471147

11481148
@Override
@@ -1296,7 +1296,7 @@ public <T> Collection<T> insert(Collection<? extends T> batchToSave, Class<?> en
12961296

12971297
Assert.notNull(batchToSave, "BatchToSave must not be null!");
12981298

1299-
return (Collection<T>) doInsertBatch(operations.determineCollectionName(entityClass), batchToSave,
1299+
return (Collection<T>) doInsertBatch(getCollectionName(entityClass), batchToSave,
13001300
this.mongoConverter);
13011301
}
13021302

@@ -1557,7 +1557,7 @@ public Object doInCollection(MongoCollection<Document> collection) throws MongoE
15571557

15581558
@Override
15591559
public UpdateResult upsert(Query query, Update update, Class<?> entityClass) {
1560-
return doUpdate(operations.determineCollectionName(entityClass), query, update, entityClass, true, false);
1560+
return doUpdate(getCollectionName(entityClass), query, update, entityClass, true, false);
15611561
}
15621562

15631563
@Override
@@ -1575,7 +1575,7 @@ public UpdateResult upsert(Query query, Update update, Class<?> entityClass, Str
15751575

15761576
@Override
15771577
public UpdateResult updateFirst(Query query, Update update, Class<?> entityClass) {
1578-
return doUpdate(operations.determineCollectionName(entityClass), query, update, entityClass, false, false);
1578+
return doUpdate(getCollectionName(entityClass), query, update, entityClass, false, false);
15791579
}
15801580

15811581
@Override
@@ -1593,7 +1593,7 @@ public UpdateResult updateFirst(Query query, Update update, Class<?> entityClass
15931593

15941594
@Override
15951595
public UpdateResult updateMulti(Query query, Update update, Class<?> entityClass) {
1596-
return doUpdate(operations.determineCollectionName(entityClass), query, update, entityClass, false, true);
1596+
return doUpdate(getCollectionName(entityClass), query, update, entityClass, false, true);
15971597
}
15981598

15991599
@Override
@@ -1692,7 +1692,7 @@ public DeleteResult remove(Object object) {
16921692

16931693
Assert.notNull(object, "Object must not be null!");
16941694

1695-
return remove(object, operations.determineCollectionName(object.getClass()));
1695+
return remove(object, getCollectionName(object.getClass()));
16961696
}
16971697

16981698
@Override
@@ -1713,7 +1713,7 @@ public DeleteResult remove(Query query, String collectionName) {
17131713

17141714
@Override
17151715
public DeleteResult remove(Query query, Class<?> entityClass) {
1716-
return remove(query, entityClass, operations.determineCollectionName(entityClass));
1716+
return remove(query, entityClass, getCollectionName(entityClass));
17171717
}
17181718

17191719
@Override
@@ -1785,7 +1785,7 @@ protected <T> DeleteResult doRemove(final String collectionName, final Query que
17851785

17861786
@Override
17871787
public <T> List<T> findAll(Class<T> entityClass) {
1788-
return findAll(entityClass, operations.determineCollectionName(entityClass));
1788+
return findAll(entityClass, getCollectionName(entityClass));
17891789
}
17901790

17911791
@Override
@@ -1988,7 +1988,7 @@ public <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputColl
19881988
*/
19891989
@Override
19901990
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) {
1991-
return aggregate(aggregation, operations.determineCollectionName(aggregation.getInputType()), outputType);
1991+
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
19921992
}
19931993

19941994
/* (non-Javadoc)
@@ -2011,7 +2011,7 @@ public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Stri
20112011
@Override
20122012
public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
20132013

2014-
return aggregate(aggregation, operations.determineCollectionName(inputType), outputType,
2014+
return aggregate(aggregation, getCollectionName(inputType), outputType,
20152015
new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper));
20162016
}
20172017

@@ -2042,7 +2042,7 @@ public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation,
20422042
*/
20432043
@Override
20442044
public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, Class<O> outputType) {
2045-
return aggregateStream(aggregation, operations.determineCollectionName(aggregation.getInputType()), outputType);
2045+
return aggregateStream(aggregation, getCollectionName(aggregation.getInputType()), outputType);
20462046
}
20472047

20482048
/* (non-Javadoc)
@@ -2051,7 +2051,7 @@ public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation,
20512051
@Override
20522052
public <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
20532053

2054-
return aggregateStream(aggregation, operations.determineCollectionName(inputType), outputType,
2054+
return aggregateStream(aggregation, getCollectionName(inputType), outputType,
20552055
new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper));
20562056
}
20572057

@@ -2077,7 +2077,7 @@ public <T> List<T> findAllAndRemove(Query query, String collectionName) {
20772077
*/
20782078
@Override
20792079
public <T> List<T> findAllAndRemove(Query query, Class<T> entityClass) {
2080-
return findAllAndRemove(query, entityClass, operations.determineCollectionName(entityClass));
2080+
return findAllAndRemove(query, entityClass, getCollectionName(entityClass));
20812081
}
20822082

20832083
/* (non-Javadoc)

0 commit comments

Comments
 (0)