Skip to content

Commit 5f6291e

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

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

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

+29-29
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public MongoConverter getConverter() {
378378
@Override
379379
public <T> CloseableIterator<T> stream(final Query query, final Class<T> entityType) {
380380

381-
return stream(query, entityType, operations.determineCollectionName(entityType));
381+
return stream(query, entityType, getCollectionName(entityType));
382382
}
383383

384384
/*
@@ -528,7 +528,7 @@ public <T> T execute(DbCallback<T> action) {
528528
public <T> T execute(Class<?> entityClass, CollectionCallback<T> callback) {
529529

530530
Assert.notNull(entityClass, "EntityClass must not be null!");
531-
return execute(operations.determineCollectionName(entityClass), callback);
531+
return execute(getCollectionName(entityClass), callback);
532532
}
533533

534534
/*
@@ -599,7 +599,7 @@ public <T> MongoCollection<Document> createCollection(Class<T> entityClass,
599599
@Nullable CollectionOptions collectionOptions) {
600600

601601
Assert.notNull(entityClass, "EntityClass must not be null!");
602-
return doCreateCollection(operations.determineCollectionName(entityClass),
602+
return doCreateCollection(getCollectionName(entityClass),
603603
convertToDocument(collectionOptions, entityClass));
604604
}
605605

@@ -645,7 +645,7 @@ public MongoCollection<Document> doInDB(MongoDatabase db) throws MongoException,
645645
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#getCollection(java.lang.Class)
646646
*/
647647
public <T> boolean collectionExists(Class<T> entityClass) {
648-
return collectionExists(operations.determineCollectionName(entityClass));
648+
return collectionExists(getCollectionName(entityClass));
649649
}
650650

651651
/*
@@ -674,7 +674,7 @@ public Boolean doInDB(MongoDatabase db) throws MongoException, DataAccessExcepti
674674
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#dropCollection(java.lang.Class)
675675
*/
676676
public <T> void dropCollection(Class<T> entityClass) {
677-
dropCollection(operations.determineCollectionName(entityClass));
677+
dropCollection(getCollectionName(entityClass));
678678
}
679679

680680
/*
@@ -710,7 +710,7 @@ public IndexOperations indexOps(String collectionName) {
710710
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#indexOps(java.lang.Class)
711711
*/
712712
public IndexOperations indexOps(Class<?> entityClass) {
713-
return new DefaultIndexOperations(this, operations.determineCollectionName(entityClass), entityClass);
713+
return new DefaultIndexOperations(this, getCollectionName(entityClass), entityClass);
714714
}
715715

716716
/*
@@ -726,7 +726,7 @@ public BulkOperations bulkOps(BulkMode bulkMode, String collectionName) {
726726
* @see org.springframework.data.mongodb.core.ExecutableInsertOperation#bulkOps(org.springframework.data.mongodb.core.BulkMode, java.lang.Class)
727727
*/
728728
public BulkOperations bulkOps(BulkMode bulkMode, Class<?> entityClass) {
729-
return bulkOps(bulkMode, entityClass, operations.determineCollectionName(entityClass));
729+
return bulkOps(bulkMode, entityClass, getCollectionName(entityClass));
730730
}
731731

732732
/*
@@ -761,7 +761,7 @@ public ScriptOperations scriptOps() {
761761
@Nullable
762762
@Override
763763
public <T> T findOne(Query query, Class<T> entityClass) {
764-
return findOne(query, entityClass, operations.determineCollectionName(entityClass));
764+
return findOne(query, entityClass, getCollectionName(entityClass));
765765
}
766766

767767
@Nullable
@@ -783,7 +783,7 @@ public <T> T findOne(Query query, Class<T> entityClass, String collectionName) {
783783

784784
@Override
785785
public boolean exists(Query query, Class<?> entityClass) {
786-
return exists(query, entityClass, operations.determineCollectionName(entityClass));
786+
return exists(query, entityClass, getCollectionName(entityClass));
787787
}
788788

789789
@Override
@@ -813,7 +813,7 @@ public boolean exists(Query query, @Nullable Class<?> entityClass, String collec
813813
*/
814814
@Override
815815
public <T> List<T> find(Query query, Class<T> entityClass) {
816-
return find(query, entityClass, operations.determineCollectionName(entityClass));
816+
return find(query, entityClass, getCollectionName(entityClass));
817817
}
818818

819819
/*
@@ -834,7 +834,7 @@ public <T> List<T> find(Query query, Class<T> entityClass, String collectionName
834834
@Nullable
835835
@Override
836836
public <T> T findById(Object id, Class<T> entityClass) {
837-
return findById(id, entityClass, operations.determineCollectionName(entityClass));
837+
return findById(id, entityClass, getCollectionName(entityClass));
838838
}
839839

840840
@Nullable
@@ -856,7 +856,7 @@ public <T> T findById(Object id, Class<T> entityClass, String collectionName) {
856856
*/
857857
@Override
858858
public <T> List<T> findDistinct(Query query, String field, Class<?> entityClass, Class<T> resultClass) {
859-
return findDistinct(query, field, operations.determineCollectionName(entityClass), entityClass, resultClass);
859+
return findDistinct(query, field, getCollectionName(entityClass), entityClass, resultClass);
860860
}
861861

862862
/*
@@ -939,7 +939,7 @@ private static Class<?> getMostSpecificConversionTargetType(Class<?> userType, C
939939

940940
@Override
941941
public <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass) {
942-
return geoNear(near, entityClass, operations.determineCollectionName(entityClass));
942+
return geoNear(near, entityClass, getCollectionName(entityClass));
943943
}
944944

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

964964
String collection = StringUtils.hasText(collectionName) ? collectionName
965-
: operations.determineCollectionName(domainType);
965+
: getCollectionName(domainType);
966966
Document nearDocument = near.toDocument();
967967

968968
Document command = new Document("geoNear", collection);
@@ -1016,7 +1016,7 @@ public <T> GeoResults<T> geoNear(NearQuery near, Class<?> domainType, String col
10161016
@Override
10171017
public <T> T findAndModify(Query query, Update update, Class<T> entityClass) {
10181018
return findAndModify(query, update, new FindAndModifyOptions(), entityClass,
1019-
operations.determineCollectionName(entityClass));
1019+
getCollectionName(entityClass));
10201020
}
10211021

10221022
@Nullable
@@ -1028,7 +1028,7 @@ public <T> T findAndModify(Query query, Update update, Class<T> entityClass, Str
10281028
@Nullable
10291029
@Override
10301030
public <T> T findAndModify(Query query, Update update, FindAndModifyOptions options, Class<T> entityClass) {
1031-
return findAndModify(query, update, options, entityClass, operations.determineCollectionName(entityClass));
1031+
return findAndModify(query, update, options, entityClass, getCollectionName(entityClass));
10321032
}
10331033

10341034
@Nullable
@@ -1092,7 +1092,7 @@ public <S, T> T findAndReplace(Query query, S replacement, FindAndReplaceOptions
10921092
@Nullable
10931093
@Override
10941094
public <T> T findAndRemove(Query query, Class<T> entityClass) {
1095-
return findAndRemove(query, entityClass, operations.determineCollectionName(entityClass));
1095+
return findAndRemove(query, entityClass, getCollectionName(entityClass));
10961096
}
10971097

10981098
@Nullable
@@ -1111,7 +1111,7 @@ public <T> T findAndRemove(Query query, Class<T> entityClass, String collectionN
11111111
public long count(Query query, Class<?> entityClass) {
11121112

11131113
Assert.notNull(entityClass, "Entity class must not be null!");
1114-
return count(query, entityClass, operations.determineCollectionName(entityClass));
1114+
return count(query, entityClass, getCollectionName(entityClass));
11151115
}
11161116

11171117
@Override
@@ -1255,7 +1255,7 @@ public <T> Collection<T> insert(Collection<? extends T> batchToSave, Class<?> en
12551255

12561256
Assert.notNull(batchToSave, "BatchToSave must not be null!");
12571257

1258-
return (Collection<T>) doInsertBatch(operations.determineCollectionName(entityClass), batchToSave,
1258+
return (Collection<T>) doInsertBatch(getCollectionName(entityClass), batchToSave,
12591259
this.mongoConverter);
12601260
}
12611261

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

15121512
@Override
15131513
public UpdateResult upsert(Query query, Update update, Class<?> entityClass) {
1514-
return doUpdate(operations.determineCollectionName(entityClass), query, update, entityClass, true, false);
1514+
return doUpdate(getCollectionName(entityClass), query, update, entityClass, true, false);
15151515
}
15161516

15171517
@Override
@@ -1529,7 +1529,7 @@ public UpdateResult upsert(Query query, Update update, Class<?> entityClass, Str
15291529

15301530
@Override
15311531
public UpdateResult updateFirst(Query query, Update update, Class<?> entityClass) {
1532-
return doUpdate(operations.determineCollectionName(entityClass), query, update, entityClass, false, false);
1532+
return doUpdate(getCollectionName(entityClass), query, update, entityClass, false, false);
15331533
}
15341534

15351535
@Override
@@ -1547,7 +1547,7 @@ public UpdateResult updateFirst(Query query, Update update, Class<?> entityClass
15471547

15481548
@Override
15491549
public UpdateResult updateMulti(Query query, Update update, Class<?> entityClass) {
1550-
return doUpdate(operations.determineCollectionName(entityClass), query, update, entityClass, false, true);
1550+
return doUpdate(getCollectionName(entityClass), query, update, entityClass, false, true);
15511551
}
15521552

15531553
@Override
@@ -1667,7 +1667,7 @@ public DeleteResult remove(Query query, String collectionName) {
16671667

16681668
@Override
16691669
public DeleteResult remove(Query query, Class<?> entityClass) {
1670-
return remove(query, entityClass, operations.determineCollectionName(entityClass));
1670+
return remove(query, entityClass, getCollectionName(entityClass));
16711671
}
16721672

16731673
@Override
@@ -1738,7 +1738,7 @@ public DeleteResult doInCollection(MongoCollection<Document> collection)
17381738

17391739
@Override
17401740
public <T> List<T> findAll(Class<T> entityClass) {
1741-
return findAll(entityClass, operations.determineCollectionName(entityClass));
1741+
return findAll(entityClass, getCollectionName(entityClass));
17421742
}
17431743

17441744
@Override
@@ -1935,7 +1935,7 @@ public <T> GroupByResults<T> group(@Nullable Criteria criteria, String inputColl
19351935
*/
19361936
@Override
19371937
public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType) {
1938-
return aggregate(aggregation, operations.determineCollectionName(aggregation.getInputType()), outputType);
1938+
return aggregate(aggregation, getCollectionName(aggregation.getInputType()), outputType);
19391939
}
19401940

19411941
/* (non-Javadoc)
@@ -1958,7 +1958,7 @@ public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Stri
19581958
@Override
19591959
public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
19601960

1961-
return aggregate(aggregation, operations.determineCollectionName(inputType), outputType,
1961+
return aggregate(aggregation, getCollectionName(inputType), outputType,
19621962
new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper));
19631963
}
19641964

@@ -1989,7 +1989,7 @@ public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation,
19891989
*/
19901990
@Override
19911991
public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, Class<O> outputType) {
1992-
return aggregateStream(aggregation, operations.determineCollectionName(aggregation.getInputType()), outputType);
1992+
return aggregateStream(aggregation, getCollectionName(aggregation.getInputType()), outputType);
19931993
}
19941994

19951995
/* (non-Javadoc)
@@ -1998,7 +1998,7 @@ public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation,
19981998
@Override
19991999
public <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, Class<?> inputType, Class<O> outputType) {
20002000

2001-
return aggregateStream(aggregation, operations.determineCollectionName(inputType), outputType,
2001+
return aggregateStream(aggregation, getCollectionName(inputType), outputType,
20022002
new TypeBasedAggregationOperationContext(inputType, mappingContext, queryMapper));
20032003
}
20042004

@@ -2024,7 +2024,7 @@ public <T> List<T> findAllAndRemove(Query query, String collectionName) {
20242024
*/
20252025
@Override
20262026
public <T> List<T> findAllAndRemove(Query query, Class<T> entityClass) {
2027-
return findAllAndRemove(query, entityClass, operations.determineCollectionName(entityClass));
2027+
return findAllAndRemove(query, entityClass, getCollectionName(entityClass));
20282028
}
20292029

20302030
/* (non-Javadoc)

0 commit comments

Comments
 (0)