Skip to content

Commit e4fdabb

Browse files
author
Thomas Risberg
committed
DATADOC-117 removed defaultCollection on MongoTemplate/Operations; changed getDefaultCollectionName to getCollectionName(Class clazz) to determine collection name used for specific class; added a class parameter where necessary
1 parent 0c9ee0e commit e4fdabb

File tree

16 files changed

+146
-216
lines changed

16 files changed

+146
-216
lines changed

spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<bean id="mongoTemplate" class="org.springframework.data.document.mongodb.MongoTemplate">
2929
<constructor-arg name="mongo" ref="mongo"/>
3030
<constructor-arg name="databaseName" value="test"/>
31-
<constructor-arg name="defaultCollectionName" value="cross-store"/>
3231
<constructor-arg name="mongoConverter" ref="mappingConverter"/>
3332
</bean>
3433

spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java

+12-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import com.mongodb.DBObject;
2424
import com.mongodb.WriteResult;
2525

26-
import org.bson.types.ObjectId;
2726
import org.springframework.data.document.mongodb.index.IndexDefinition;
2827
import org.springframework.data.document.mongodb.query.Query;
2928
import org.springframework.data.document.mongodb.query.Update;
@@ -40,18 +39,11 @@
4039
public interface MongoOperations {
4140

4241
/**
43-
* The default collection name used by this template.
42+
* The collection name used for the specified class by this template.
4443
*
4544
* @return
4645
*/
47-
String getDefaultCollectionName();
48-
49-
/**
50-
* The default collection used by this template.
51-
*
52-
* @return The default collection used by this template
53-
*/
54-
DBCollection getDefaultCollection();
46+
String getCollectionName(Class<?> clazz);
5547

5648
/**
5749
* Execute the a MongoDB command expressed as a JSON string. This will call the method
@@ -83,15 +75,16 @@ public interface MongoOperations {
8375
<T> T execute(DbCallback<T> action);
8476

8577
/**
86-
* Executes the given {@link CollectionCallback} on the default collection.
78+
* Executes the given {@link CollectionCallback} on the entity collection of the specified class.
8779
* <p/>
8880
* Allows for returning a result object, that is a domain object or a collection of domain objects.
8981
*
82+
* @param entityClass class that determines the collection to use
9083
* @param <T> return type
9184
* @param action callback object that specifies the MongoDB action
9285
* @return a result object returned by the action or <tt>null</tt>
9386
*/
94-
<T> T execute(CollectionCallback<T> action);
87+
<T> T execute(Class<?> entityClass, CollectionCallback<T> action);
9588

9689
/**
9790
* Executes the given {@link CollectionCallback} on the collection of the given name.
@@ -219,9 +212,10 @@ <T> List<T> getCollection(String collectionName, Class<T> targetClass,
219212
* Ensure that an index for the provided {@link IndexDefinition} exists for the default collection.
220213
* If not it will be created.
221214
*
222-
* @param index
215+
* @param entityClass class that determines the collection to use
216+
* @param indexDefinition
223217
*/
224-
void ensureIndex(IndexDefinition indexDefinition);
218+
void ensureIndex(Class<?> entityClass, IndexDefinition indexDefinition);
225219

226220
/**
227221
* Ensure that an index for the provided {@link IndexDefinition} exists. If not it will be
@@ -651,11 +645,12 @@ <T> T findAndRemove(String collectionName, Query query,
651645
* Updates the first object that is found in the default collection that matches the query document
652646
* with the provided updated document.
653647
*
648+
* @param entityClass class that determines the collection to use
654649
* @param queryDoc the query document that specifies the criteria used to select a record to be updated
655650
* @param updateDoc the update document that contains the updated object or $ operators to manipulate the
656651
* existing object.
657652
*/
658-
WriteResult updateFirst(Query query, Update update);
653+
WriteResult updateFirst(Class<?> entityClass, Query query, Update update);
659654

660655
/**
661656
* Updates the first object that is found in the specified collection that matches the query document criteria
@@ -673,11 +668,12 @@ WriteResult updateFirst(String collectionName, Query query,
673668
* Updates all objects that are found in the default collection that matches the query document criteria
674669
* with the provided updated document.
675670
*
671+
* @param entityClass class that determines the collection to use
676672
* @param queryDoc the query document that specifies the criteria used to select a record to be updated
677673
* @param updateDoc the update document that contains the updated object or $ operators to manipulate the
678674
* existing object.
679675
*/
680-
WriteResult updateMulti(Query query, Update update);
676+
WriteResult updateMulti(Class<?> entityClass, Query query, Update update);
681677

682678
/**
683679
* Updates all objects that are found in the specified collection that matches the query document criteria

0 commit comments

Comments
 (0)