|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface MongoOperations
Interface that specifies a basic set of MongoDB operations. Implemented by MongoTemplate
. Not often used but
a useful option for extensibility and testability (as it can be easily mocked, stubbed, or be the target of a JDK
proxy).
Method Summary | ||
---|---|---|
|
collectionExists(Class<T> entityClass)
Check to see if a collection with a name indicated by the entity class exists. |
|
boolean |
collectionExists(String collectionName)
Check to see if a collection with a given name exists. |
|
|
createCollection(Class<T> entityClass)
Create an uncapped collection with a name based on the provided entity class. |
|
|
createCollection(Class<T> entityClass,
CollectionOptions collectionOptions)
Create a collect with a name based on the provided entity class using the options. |
|
DBCollection |
createCollection(String collectionName)
Create an uncapped collection with the provided name. |
|
DBCollection |
createCollection(String collectionName,
CollectionOptions collectionOptions)
Create a collect with the provided name and options. |
|
|
dropCollection(Class<T> entityClass)
Drop the collection with the name indicated by the entity class. |
|
void |
dropCollection(String collectionName)
Drop the collection with the given name. |
|
void |
ensureIndex(IndexDefinition indexDefinition,
Class<?> entityClass)
Ensure that an index for the provided IndexDefinition exists for the collection indicated by the entity class. |
|
void |
ensureIndex(IndexDefinition indexDefinition,
String collectionName)
Ensure that an index for the provided IndexDefinition exists. |
|
|
execute(Class<?> entityClass,
CollectionCallback<T> action)
Executes the given CollectionCallback on the entity collection of the specified class. |
|
|
execute(DbCallback<T> action)
Executes a DbCallback translating any exceptions as necessary. |
|
|
execute(String collectionName,
CollectionCallback<T> action)
Executes the given CollectionCallback on the collection of the given name. |
|
CommandResult |
executeCommand(DBObject command)
Execute a MongoDB command. |
|
CommandResult |
executeCommand(String jsonCommand)
Execute the a MongoDB command expressed as a JSON string. |
|
|
executeInSession(DbCallback<T> action)
Executes the given DbCallback within the same connection to the database so as to ensure consistency in a
write heavy environment where you may read the data that you wrote. |
|
|
find(Query query,
Class<T> entityClass)
Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type. |
|
|
find(Query query,
Class<T> entityClass,
CursorPreparer preparer,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
find(Query query,
Class<T> entityClass,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
findAll(Class<T> entityClass)
Query for a list of objects of type T from the collection used by the entity class. |
|
|
findAll(Class<T> entityClass,
String collectionName)
Query for a list of objects of type T from the specified collection. |
|
|
findAndRemove(Query query,
Class<T> entityClass)
Map the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the specified type. |
|
|
findAndRemove(Query query,
Class<T> entityClass,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. |
|
|
findById(Object id,
Class<T> entityClass)
Returns a document with the given id mapped onto the given class. |
|
|
findById(Object id,
Class<T> entityClass,
String collectionName)
Returns the document with the given id from the given collection mapped onto the given target class. |
|
|
findOne(Query query,
Class<T> entityClass)
Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the specified type. |
|
|
findOne(Query query,
Class<T> entityClass,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. |
|
DBCollection |
getCollection(String collectionName)
Get a collection by name, creating it if it doesn't exist. |
|
String |
getCollectionName(Class<?> entityClass)
The collection name used for the specified class by this template. |
|
Set<String> |
getCollectionNames()
A set of collection names. |
|
void |
insert(Collection<? extends Object> batchToSave,
Class<?> entityClass)
Insert a Collection of objects into a collection in a single batch write to the database. |
|
void |
insert(Collection<? extends Object> batchToSave,
String collectionName)
Insert a list of objects into the specified collection in a single batch write to the database. |
|
void |
insert(Object objectToSave)
Insert the object into the collection for the entity type of the object to save. |
|
void |
insert(Object objectToSave,
String collectionName)
Insert the object into the specified collection. |
|
void |
insertAll(Collection<? extends Object> objectsToSave)
Insert a mixed Collection of objects into a database collection determining the collection name to use based on the class. |
|
void |
remove(Object object)
Remove the given object from the collection by Id |
|
|
remove(Query query,
Class<T> entityClass)
Remove all documents that match the provided query document criteria from the the collection used to store the entityClass. |
|
void |
remove(Query query,
String collectionName)
Remove all documents from the specified collection that match the provided query document criteria. |
|
void |
save(Object objectToSave)
Save the object to the collection for the entity type of the object to save. |
|
void |
save(Object objectToSave,
String collectionName)
Save the object to the specified collection. |
|
WriteResult |
updateFirst(Query query,
Update update,
Class<?> entityClass)
Updates the first object that is found in the collection of the entity class that matches the query document with the provided update document. |
|
WriteResult |
updateFirst(Query query,
Update update,
String collectionName)
Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document. |
|
WriteResult |
updateMulti(Query query,
Update update,
Class<?> entityClass)
Updates all objects that are found in the collection for the entity class that matches the query document criteria with the provided updated document. |
|
WriteResult |
updateMulti(Query query,
Update update,
String collectionName)
Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document. |
Method Detail |
---|
String getCollectionName(Class<?> entityClass)
CommandResult executeCommand(String jsonCommand)
jsonCommand
- a MongoDB command expressed as a JSON string.CommandResult executeCommand(DBObject command)
command
- a MongoDB command<T> T execute(DbCallback<T> action)
DbCallback
translating any exceptions as necessary.
Allows for returning a result object, that is a domain object or a collection of domain objects.
T
- return typeaction
- callback object that specifies the MongoDB actions to perform on the passed in DB instance.
<T> T execute(Class<?> entityClass, CollectionCallback<T> action)
CollectionCallback
on the entity collection of the specified class.
Allows for returning a result object, that is a domain object or a collection of domain objects.
T
- return typeentityClass
- class that determines the collection to useaction
- callback object that specifies the MongoDB action
<T> T execute(String collectionName, CollectionCallback<T> action)
CollectionCallback
on the collection of the given name.
Allows for returning a result object, that is a domain object or a collection of domain objects.
T
- return typecollectionName
- the name of the collection that specifies which DBCollection instance will be passed intoaction
- callback object that specifies the MongoDB action the callback action.
<T> T executeInSession(DbCallback<T> action)
DbCallback
within the same connection to the database so as to ensure consistency in a
write heavy environment where you may read the data that you wrote. See the comments on Java Driver Concurrency
Allows for returning a result object, that is a domain object or a collection of domain objects.
T
- return typeaction
- callback that specified the MongoDB actions to perform on the DB instance
<T> DBCollection createCollection(Class<T> entityClass)
entityClass
- class that determines the collection to create
<T> DBCollection createCollection(Class<T> entityClass, CollectionOptions collectionOptions)
entityClass
- class that determines the collection to createcollectionOptions
- options to use when creating the collection.
DBCollection createCollection(String collectionName)
collectionName
- name of the collection
DBCollection createCollection(String collectionName, CollectionOptions collectionOptions)
collectionName
- name of the collectioncollectionOptions
- options to use when creating the collection.
Set<String> getCollectionNames()
DBCollection getCollection(String collectionName)
collectionName
- name of the collection
<T> boolean collectionExists(Class<T> entityClass)
entityClass
- class that determines the name of the collection
boolean collectionExists(String collectionName)
collectionName
- name of the collection
<T> void dropCollection(Class<T> entityClass)
entityClass
- class that determines the collection to drop/delete.void dropCollection(String collectionName)
collectionName
- name of the collection to drop/delete.<T> List<T> findAll(Class<T> entityClass)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
to map objects since the test for class type is done in the client and not on the server.
entityClass
- the parameterized type of the returned list
<T> List<T> findAll(Class<T> entityClass, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
to map objects since the test for class type is done in the client and not on the server.
entityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
void ensureIndex(IndexDefinition indexDefinition, Class<?> entityClass)
IndexDefinition
exists for the collection indicated by the entity class.
If not it will be created.
indexDefinition
- entityClass
- class that determines the collection to usevoid ensureIndex(IndexDefinition indexDefinition, String collectionName)
IndexDefinition
exists. If not it will be created.
index
- collectionName
- <T> T findOne(Query query, Class<T> entityClass)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass
- the parameterized type of the returned list.
<T> T findOne(Query query, Class<T> entityClass, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
<T> List<T> find(Query query, Class<T> entityClass)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass
- the parameterized type of the returned list.
<T> List<T> find(Query query, Class<T> entityClass, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
<T> List<T> find(Query query, Class<T> entityClass, CursorPreparer preparer, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass
- the parameterized type of the returned list.preparer
- allows for customization of the DBCursor used when iterating over the result set, (apply limits, skips and
so on).collectionName
- name of the collection to retrieve the objects from
<T> T findById(Object id, Class<T> entityClass)
T
- id
- the id of the document to return.entityClass
- the type the document shall be converted into.
<T> T findById(Object id, Class<T> entityClass, String collectionName)
T
- id
- the id of the document to returnentityClass
- the type to convert the document tocollectionName
- the collection to query for the document
<T> T findAndRemove(Query query, Class<T> entityClass)
MongoConverter
.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a
record and also an optional fields specificationentityClass
- the parameterized type of the returned list.
<T> T findAndRemove(Query query, Class<T> entityClass, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
The query is specified as a Query
which can be created either using the BasicQuery
or the more
feature rich Query
.
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
void insert(Object objectToSave)
MongoConverter
.
If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's new Type Conversion API.
See Spring 3 Type
Conversion" for more details.
Insert is used to initially store the object into the database. To update an existing object use the save method.
objectToSave
- the object to store in the collection.void insert(Object objectToSave, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
Insert is used to initially store the object into the database. To update an existing object use the save method.
objectToSave
- the object to store in the collectioncollectionName
- name of the collection to store the object invoid insert(Collection<? extends Object> batchToSave, Class<?> entityClass)
batchToSave
- the list of objects to save.entityClass
- class that determines the collection to usevoid insert(Collection<? extends Object> batchToSave, String collectionName)
batchToSave
- the list of objects to save.collectionName
- name of the collection to store the object invoid insertAll(Collection<? extends Object> objectsToSave)
collectionToSave
- the list of objects to save.void save(Object objectToSave)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's new Type Conversion API.
See Spring 3 Type
Conversion" for more details.
objectToSave
- the object to store in the collectionvoid save(Object objectToSave, String collectionName)
MongoConverter
. Unless
configured otherwise, an instance of SimpleMongoConverter will be used.
If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
property type will be handled by Spring's BeanWrapper class that leverages Spring 3.0's new Type Cobnversion API.
See Spring 3 Type
Conversion" for more details.
objectToSave
- the object to store in the collectioncollectionName
- name of the collection to store the object inWriteResult updateFirst(Query query, Update update, Class<?> entityClass)
query
- the query document that specifies the criteria used to select a record to be updatedupdate
- the update document that contains the updated object or $ operators to manipulate the existing object.entityClass
- class that determines the collection to useWriteResult updateFirst(Query query, Update update, String collectionName)
query
- the query document that specifies the criteria used to select a record to be updatedupdate
- the update document that contains the updated object or $ operators to manipulate the existing object.collectionName
- name of the collection to update the object inWriteResult updateMulti(Query query, Update update, Class<?> entityClass)
query
- the query document that specifies the criteria used to select a record to be updatedupdate
- the update document that contains the updated object or $ operators to manipulate the existing object.entityClass
- class that determines the collection to useWriteResult updateMulti(Query query, Update update, String collectionName)
query
- the query document that specifies the criteria used to select a record to be updatedupdate
- the update document that contains the updated object or $ operators to manipulate the existing object.collectionName
- name of the collection to update the object invoid remove(Object object)
object
- <T> void remove(Query query, Class<T> entityClass)
T
- query
- entityClass
- void remove(Query query, String collectionName)
query
- the query document that specifies the criteria used to remove a recordcollectionName
- name of the collection where the objects will removed
|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |