|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.data.document.mongodb.MongoTemplate
public class MongoTemplate
Primary implementation of MongoOperations
.
Constructor Summary | |
---|---|
MongoTemplate(Mongo mongo,
String databaseName)
Constructor used for a basic template configuration |
|
MongoTemplate(Mongo mongo,
String databaseName,
String defaultCollectionName)
Constructor used for a basic template configuration with a default collection name |
|
MongoTemplate(Mongo mongo,
String databaseName,
String defaultCollectionName,
MongoConverter mongoConverter)
Constructor used for a template configuration with a default collection name and a custom MongoConverter |
Method Summary | ||
---|---|---|
void |
afterPropertiesSet()
|
|
boolean |
collectionExists(String collectionName)
Check to see if a collection with a given name exists. |
|
protected DBObject |
convertToDbObject(CollectionOptions collectionOptions)
|
|
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. |
|
protected DBCollection |
doCreateCollection(String collectionName,
DBObject collectionOptions)
Create the specified collection using the provided options |
|
protected
|
doFind(String collectionName,
DBObject query,
DBObject fields,
Class<T> targetClass,
CursorPreparer preparer)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. |
|
protected
|
doFind(String collectionName,
DBObject query,
DBObject fields,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB collection to a List using the provided MongoReader The query document is specified as a standard DBObject and so is the fields specification. |
|
protected
|
doFindAndRemove(String collectionName,
DBObject query,
DBObject fields,
DBObject sort,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader The first document that matches the query is returned and also removed from the collection in the database. |
|
protected
|
doFindOne(String collectionName,
DBObject query,
DBObject fields,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader The query document is specified as a standard DBObject and so is the fields specification. |
|
void |
dropCollection(String collectionName)
Drop the collection with the given name. |
|
void |
ensureIndex(IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists for the default collection. |
|
void |
ensureIndex(String collectionName,
IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists. |
|
|
execute(CollectionCallback<T> callback)
Executes the given CollectionCallback on the default collection. |
|
|
execute(DbCallback<T> action)
Executes a DbCallback translating any exceptions as necessary. |
|
|
execute(String collectionName,
CollectionCallback<T> callback)
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> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. |
|
|
find(Query query,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. |
|
|
find(String collectionName,
Query query,
Class<T> targetClass)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
find(String collectionName,
Query query,
Class<T> targetClass,
CursorPreparer preparer)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
find(String collectionName,
Query query,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
findAndRemove(Query query,
Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type. |
|
|
findAndRemove(Query query,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type. |
|
|
findAndRemove(String collectionName,
Query query,
Class<T> targetClass)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. |
|
|
findAndRemove(String collectionName,
Query query,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. |
|
|
findOne(Query query,
Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type. |
|
|
findOne(Query query,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type. |
|
|
findOne(String collectionName,
Query query,
Class<T> targetClass)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. |
|
|
findOne(String collectionName,
Query query,
Class<T> targetClass,
MongoReader<T> reader)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type. |
|
|
getCollection(Class<T> targetClass)
Query for a list of objects of type T from the default collection. |
|
DBCollection |
getCollection(String collectionName)
Get a collection by name, creating it if it doesn't exist. |
|
|
getCollection(String collectionName,
Class<T> targetClass)
Query for a list of objects of type T from the specified collection. |
|
|
getCollection(String collectionName,
Class<T> targetClass,
MongoReader<T> reader)
Query for a list of objects of type T from the specified collection, mapping the DBObject using the provided MongoReader. |
|
Set<String> |
getCollectionNames()
A set of collection names. |
|
MongoConverter |
getConverter()
Returns the default MongoConverter . |
|
DB |
getDb()
|
|
DBCollection |
getDefaultCollection()
The default collection used by this template. |
|
String |
getDefaultCollectionName()
The default collection name used by this template. |
|
protected Object |
getIdValue(Object object)
|
|
void |
insert(Object objectToSave)
Insert the object into the default collection. |
|
void |
insert(String collectionName,
Object objectToSave)
Insert the object into the specified collection. |
|
|
insert(String collectionName,
T objectToSave,
MongoWriter<T> writer)
Insert the object into the specified collection. |
|
|
insert(T objectToSave,
MongoWriter<T> writer)
Insert the object into the default collection. |
|
protected Object |
insertDBObject(String collectionName,
DBObject dbDoc)
|
|
protected List<ObjectId> |
insertDBObjectList(String collectionName,
List<DBObject> dbDocList)
|
|
void |
insertList(List<? extends Object> listToSave)
Insert a list of objects into the default collection in a single batch write to the database. |
|
|
insertList(List<? extends T> listToSave,
MongoWriter<T> writer)
Insert a list of objects into the default collection using the provided MongoWriter instance |
|
void |
insertList(String collectionName,
List<? extends Object> listToSave)
Insert a list of objects into the specified collection in a single batch write to the database. |
|
|
insertList(String collectionName,
List<? extends T> listToSave,
MongoWriter<T> writer)
Insert a list of objects into the specified collection using the provided MongoWriter instance |
|
protected
|
maybeEmitEvent(MongoMappingEvent<T> event)
|
|
protected void |
populateIdIfNecessary(Object savedObject,
Object id)
Populates the id property of the saved object, if it's not set already. |
|
void |
remove(Object object)
Remove the given object from the collection by Id |
|
void |
remove(Query query)
Remove all documents from the default collection that match the provided query document criteria. |
|
|
remove(Query query,
Class<T> targetClass)
Remove all documents from the default collection that match the provided query document criteria. |
|
void |
remove(String collectionName,
Query query)
Remove all documents from the specified collection that match the provided query document criteria. |
|
|
remove(String collectionName,
Query query,
Class<T> targetClass)
Remove all documents from the specified collection that match the provided query document criteria. |
|
void |
save(Object objectToSave)
Save the object to the default collection. |
|
void |
save(String collectionName,
Object objectToSave)
Save the object to the specified collection. |
|
|
save(String collectionName,
T objectToSave,
MongoWriter<T> writer)
Save the object into the specified collection using the provided writer. |
|
|
save(T objectToSave,
MongoWriter<T> writer)
Save the object into the default collection using the provided writer. |
|
protected Object |
saveDBObject(String collectionName,
DBObject dbDoc)
|
|
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
|
|
void |
setDatabaseName(String databaseName)
Sets the database name to be used. |
|
void |
setDefaultCollectionName(String defaultCollectionName)
Sets the name of the default collection to be used. |
|
void |
setMappingContext(org.springframework.data.mapping.model.MappingContext mappingContext)
|
|
void |
setMongoConverter(MongoConverter converter)
|
|
void |
setPassword(String password)
Sets the password to use to authenticate with the Mongo database. |
|
void |
setUsername(String username)
Sets the username to use to connect to the Mongo database |
|
void |
setWriteConcern(WriteConcern writeConcern)
|
|
void |
setWriteResultChecking(WriteResultChecking resultChecking)
|
|
protected void |
substituteMappedIdIfNecessary(DBObject query)
Substitutes the id key if it is found in he query. |
|
protected void |
substituteMappedIdIfNecessary(DBObject query,
Class<?> targetClass,
MongoReader<?> reader)
Substitutes the id key if it is found in he query. |
|
WriteResult |
updateFirst(Query query,
Update update)
Updates the first object that is found in the default collection that matches the query document with the provided updated document. |
|
WriteResult |
updateFirst(String collectionName,
Query query,
Update update)
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)
Updates all objects that are found in the default collection that matches the query document criteria with the provided updated document. |
|
WriteResult |
updateMulti(String collectionName,
Query query,
Update update)
Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MongoTemplate(Mongo mongo, String databaseName)
mongo
- databaseName
- public MongoTemplate(Mongo mongo, String databaseName, String defaultCollectionName)
mongo
- databaseName
- defaultCollectionName
- public MongoTemplate(Mongo mongo, String databaseName, String defaultCollectionName, MongoConverter mongoConverter)
MongoConverter
mongo
- databaseName
- defaultCollectionName
- mongoConverter
- Method Detail |
---|
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
public void setMappingContext(org.springframework.data.mapping.model.MappingContext mappingContext)
setMappingContext
in interface org.springframework.data.mapping.context.MappingContextAware
public void setUsername(String username)
username
- The username to usepublic void setPassword(String password)
password
- The password to usepublic void setDefaultCollectionName(String defaultCollectionName)
defaultCollectionName
- public void setDatabaseName(String databaseName)
databaseName
- public MongoConverter getConverter()
MongoConverter
.
public String getDefaultCollectionName()
MongoOperations
getDefaultCollectionName
in interface MongoOperations
public DBCollection getDefaultCollection()
MongoOperations
getDefaultCollection
in interface MongoOperations
public CommandResult executeCommand(String jsonCommand)
MongoOperations
executeCommand
in interface MongoOperations
jsonCommand
- a MongoDB command expressed as a JSON string.public CommandResult executeCommand(DBObject command)
MongoOperations
executeCommand
in interface MongoOperations
command
- a MongoDB commandpublic <T> T execute(DbCallback<T> action)
MongoOperations
DbCallback
translating any exceptions as necessary.
Allows for returning a result object, that is a domain object or a collection of domain objects.
execute
in interface MongoOperations
T
- return typeaction
- callback object that specifies the MongoDB actions to perform on the passed in DB instance.
public <T> T execute(CollectionCallback<T> callback)
MongoOperations
CollectionCallback
on the default collection.
Allows for returning a result object, that is a domain object or a collection of domain objects.
execute
in interface MongoOperations
T
- return typecallback
- callback object that specifies the MongoDB action
public <T> T execute(String collectionName, CollectionCallback<T> callback)
MongoOperations
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.
execute
in interface MongoOperations
T
- return typecollectionName
- the name of the collection that specifies which DBCollection instance will be passed intocallback
- callback object that specifies the MongoDB action
the callback action.
public <T> T executeInSession(DbCallback<T> action)
MongoOperations
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.
executeInSession
in interface MongoOperations
T
- return typeaction
- callback that specified the MongoDB actions to perform on the DB instance
public DBCollection createCollection(String collectionName)
MongoOperations
createCollection
in interface MongoOperations
collectionName
- name of the collection
public DBCollection createCollection(String collectionName, CollectionOptions collectionOptions)
MongoOperations
createCollection
in interface MongoOperations
collectionName
- name of the collectioncollectionOptions
- options to use when creating the collection.
public DBCollection getCollection(String collectionName)
MongoOperations
getCollection
in interface MongoOperations
collectionName
- name of the collection
public boolean collectionExists(String collectionName)
MongoOperations
collectionExists
in interface MongoOperations
collectionName
- name of the collection
public void dropCollection(String collectionName)
MongoOperations
dropCollection
in interface MongoOperations
collectionName
- name of the collection to drop/delete.public void ensureIndex(IndexDefinition indexDefinition)
MongoOperations
IndexDefinition
exists for the default collection.
If not it will be created.
ensureIndex
in interface MongoOperations
public void ensureIndex(String collectionName, IndexDefinition indexDefinition)
MongoOperations
IndexDefinition
exists. If not it will be
created.
ensureIndex
in interface MongoOperations
public <T> T findOne(Query query, Class<T> targetClass)
MongoOperations
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
.
findOne
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
public <T> T findOne(Query query, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
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
.
findOne
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public <T> T findOne(String collectionName, Query query, Class<T> targetClass)
MongoOperations
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
.
findOne
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
public <T> T findOne(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
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
.
findOne
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public <T> List<T> find(Query query, Class<T> targetClass)
MongoOperations
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
.
find
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
public <T> List<T> find(Query query, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
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
.
find
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public <T> List<T> find(String collectionName, Query query, Class<T> targetClass)
MongoOperations
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
.
find
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
public <T> List<T> find(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
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
.
find
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public <T> List<T> find(String collectionName, Query query, Class<T> targetClass, CursorPreparer preparer)
MongoOperations
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
.
find
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- 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).
public <T> T findAndRemove(Query query, Class<T> targetClass)
MongoOperations
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
.
findAndRemove
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
public <T> T findAndRemove(Query query, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
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
.
findAndRemove
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public <T> T findAndRemove(String collectionName, Query query, Class<T> targetClass)
MongoOperations
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
.
findAndRemove
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
public <T> T findAndRemove(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
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
.
findAndRemove
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public void insert(Object objectToSave)
MongoOperations
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.
Insert is used to initially store the object into the database.
To update an existing object use the save method.
insert
in interface MongoOperations
objectToSave
- the object to store in the collection.public void insert(String collectionName, Object objectToSave)
MongoOperations
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.
insert
in interface MongoOperations
collectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collectionpublic <T> void insert(T objectToSave, MongoWriter<T> writer)
MongoOperations
MongoWriter
Insert is used to initially store the object into the
database. To update an existing object use the save method.
insert
in interface MongoOperations
T
- the type of the object to insertobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObjectpublic <T> void insert(String collectionName, T objectToSave, MongoWriter<T> writer)
MongoOperations
MongoWriter
Insert is used to initially store the object into the
database. To update an existing object use the save method.
insert
in interface MongoOperations
T
- the type of the object to insertcollectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObjectpublic void insertList(List<? extends Object> listToSave)
MongoOperations
insertList
in interface MongoOperations
listToSave
- the list of objects to save.public void insertList(String collectionName, List<? extends Object> listToSave)
MongoOperations
insertList
in interface MongoOperations
collectionName
- name of the collection to store the object inlistToSave
- the list of objects to save.public <T> void insertList(List<? extends T> listToSave, MongoWriter<T> writer)
MongoOperations
insertList
in interface MongoOperations
T
- the type of object being savedlistToSave
- the list of objects to save.writer
- the writer to convert the object to save into a DBObjectpublic <T> void insertList(String collectionName, List<? extends T> listToSave, MongoWriter<T> writer)
MongoOperations
insertList
in interface MongoOperations
T
- the type of object being savedcollectionName
- name of the collection to store the object inlistToSave
- the list of objects to save.writer
- the writer to convert the object to save into a DBObjectpublic void save(Object objectToSave)
MongoOperations
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.
save
in interface MongoOperations
objectToSave
- the object to store in the collectionpublic void save(String collectionName, Object objectToSave)
MongoOperations
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.
save
in interface MongoOperations
collectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collectionpublic <T> void save(T objectToSave, MongoWriter<T> writer)
MongoOperations
MongoWriter
save
in interface MongoOperations
T
- the type of the object to insertobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObjectpublic <T> void save(String collectionName, T objectToSave, MongoWriter<T> writer)
MongoOperations
MongoWriter
save
in interface MongoOperations
T
- the type of the object to insertcollectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObjectprotected Object insertDBObject(String collectionName, DBObject dbDoc)
protected List<ObjectId> insertDBObjectList(String collectionName, List<DBObject> dbDocList)
protected Object saveDBObject(String collectionName, DBObject dbDoc)
public WriteResult updateFirst(Query query, Update update)
MongoOperations
updateFirst
in interface MongoOperations
public WriteResult updateFirst(String collectionName, Query query, Update update)
MongoOperations
updateFirst
in interface MongoOperations
collectionName
- name of the collection to update the object inpublic WriteResult updateMulti(Query query, Update update)
MongoOperations
updateMulti
in interface MongoOperations
public WriteResult updateMulti(String collectionName, Query query, Update update)
MongoOperations
updateMulti
in interface MongoOperations
collectionName
- name of the collection to update the object inpublic void remove(Query query)
MongoOperations
remove
in interface MongoOperations
public void remove(Object object)
MongoOperations
remove
in interface MongoOperations
public <T> void remove(Query query, Class<T> targetClass)
MongoOperations
remove
in interface MongoOperations
public <T> void remove(String collectionName, Query query, Class<T> targetClass)
MongoOperations
remove
in interface MongoOperations
public void remove(String collectionName, Query query)
MongoOperations
remove
in interface MongoOperations
collectionName
- name of the collection where the objects will removedpublic <T> List<T> getCollection(Class<T> targetClass)
MongoOperations
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.
getCollection
in interface MongoOperations
targetClass
- the parameterized type of the returned list
public <T> List<T> getCollection(String collectionName, Class<T> targetClass)
MongoOperations
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.
getCollection
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromtargetClass
- the parameterized type of the returned list.
public Set<String> getCollectionNames()
MongoOperations
getCollectionNames
in interface MongoOperations
public <T> List<T> getCollection(String collectionName, Class<T> targetClass, MongoReader<T> reader)
MongoOperations
getCollection
in interface MongoOperations
collectionName
- name of the collection to retrieve the objects fromtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
public DB getDb()
protected <T> void maybeEmitEvent(MongoMappingEvent<T> event)
protected DBCollection doCreateCollection(String collectionName, DBObject collectionOptions)
collectionName
- collectionOptions
-
protected <T> T doFindOne(String collectionName, DBObject query, DBObject fields, Class<T> targetClass, MongoReader<T> reader)
collectionName
- name of the collection to retrieve the objects fromquery
- the query document that specifies the criteria used to find a recordfields
- the document that specifies the fields to be returnedtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
protected <T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<T> targetClass, CursorPreparer preparer)
MongoConverter
. Unless configured otherwise, an
instance of SimpleMongoConverter will be used.
The query document is specified as a standard DBObject and so is the fields specification.
Can be overridden by subclasses.
collectionName
- name of the collection to retrieve the objects fromquery
- the query document that specifies the criteria used to find a recordfields
- the document that specifies the fields to be returnedtargetClass
- 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).
protected <T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<T> targetClass, MongoReader<T> reader)
collectionName
- name of the collection to retrieve the objects fromquery
- the query document that specifies the criteria used to find a recordfields
- the document that specifies the fields to be returnedtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
protected DBObject convertToDbObject(CollectionOptions collectionOptions)
protected <T> T doFindAndRemove(String collectionName, DBObject query, DBObject fields, DBObject sort, Class<T> targetClass, MongoReader<T> reader)
collectionName
- name of the collection to retrieve the objects fromquery
- the query document that specifies the criteria used to find a recordtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
protected Object getIdValue(Object object)
protected void populateIdIfNecessary(Object savedObject, Object id)
savedObject
- id
- protected void substituteMappedIdIfNecessary(DBObject query, Class<?> targetClass, MongoReader<?> reader)
query
- targetClass
- reader
- protected void substituteMappedIdIfNecessary(DBObject query)
query
- public void afterPropertiesSet()
afterPropertiesSet
in interface InitializingBean
public void setMongoConverter(MongoConverter converter)
public void setWriteResultChecking(WriteResultChecking resultChecking)
public void setWriteConcern(WriteConcern writeConcern)
|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |