23
23
import com .mongodb .DBObject ;
24
24
import com .mongodb .WriteResult ;
25
25
26
- import org .bson .types .ObjectId ;
27
26
import org .springframework .data .document .mongodb .index .IndexDefinition ;
28
27
import org .springframework .data .document .mongodb .query .Query ;
29
28
import org .springframework .data .document .mongodb .query .Update ;
40
39
public interface MongoOperations {
41
40
42
41
/**
43
- * The default collection name used by this template.
42
+ * The collection name used for the specified class by this template.
44
43
*
45
44
* @return
46
45
*/
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 );
55
47
56
48
/**
57
49
* Execute the a MongoDB command expressed as a JSON string. This will call the method
@@ -83,15 +75,16 @@ public interface MongoOperations {
83
75
<T > T execute (DbCallback <T > action );
84
76
85
77
/**
86
- * Executes the given {@link CollectionCallback} on the default collection.
78
+ * Executes the given {@link CollectionCallback} on the entity collection of the specified class .
87
79
* <p/>
88
80
* Allows for returning a result object, that is a domain object or a collection of domain objects.
89
81
*
82
+ * @param entityClass class that determines the collection to use
90
83
* @param <T> return type
91
84
* @param action callback object that specifies the MongoDB action
92
85
* @return a result object returned by the action or <tt>null</tt>
93
86
*/
94
- <T > T execute (CollectionCallback <T > action );
87
+ <T > T execute (Class <?> entityClass , CollectionCallback <T > action );
95
88
96
89
/**
97
90
* 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,
219
212
* Ensure that an index for the provided {@link IndexDefinition} exists for the default collection.
220
213
* If not it will be created.
221
214
*
222
- * @param index
215
+ * @param entityClass class that determines the collection to use
216
+ * @param indexDefinition
223
217
*/
224
- void ensureIndex (IndexDefinition indexDefinition );
218
+ void ensureIndex (Class <?> entityClass , IndexDefinition indexDefinition );
225
219
226
220
/**
227
221
* 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,
651
645
* Updates the first object that is found in the default collection that matches the query document
652
646
* with the provided updated document.
653
647
*
648
+ * @param entityClass class that determines the collection to use
654
649
* @param queryDoc the query document that specifies the criteria used to select a record to be updated
655
650
* @param updateDoc the update document that contains the updated object or $ operators to manipulate the
656
651
* existing object.
657
652
*/
658
- WriteResult updateFirst (Query query , Update update );
653
+ WriteResult updateFirst (Class <?> entityClass , Query query , Update update );
659
654
660
655
/**
661
656
* 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,
673
668
* Updates all objects that are found in the default collection that matches the query document criteria
674
669
* with the provided updated document.
675
670
*
671
+ * @param entityClass class that determines the collection to use
676
672
* @param queryDoc the query document that specifies the criteria used to select a record to be updated
677
673
* @param updateDoc the update document that contains the updated object or $ operators to manipulate the
678
674
* existing object.
679
675
*/
680
- WriteResult updateMulti (Query query , Update update );
676
+ WriteResult updateMulti (Class <?> entityClass , Query query , Update update );
681
677
682
678
/**
683
679
* Updates all objects that are found in the specified collection that matches the query document criteria
0 commit comments