|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.data.document.mongodb.MongoTemplate
public class MongoTemplate
Primary implementation of MongoOperations
.
Nested Class Summary | |
---|---|
private static interface |
MongoTemplate.DbObjectCallback<T>
Simple internal callback to allow operations on a DBObject . |
private static class |
MongoTemplate.FindAndRemoveCallback
Simple CollectionCallback that takes a query DBObject plus an optional fields specification
DBObject and executes that against the DBCollection . |
private static class |
MongoTemplate.FindCallback
Simple CollectionCallback that takes a query DBObject plus an optional fields specification
DBObject and executes that against the DBCollection . |
private static class |
MongoTemplate.FindOneCallback
Simple CollectionCallback that takes a query DBObject plus an optional fields specification
DBObject and executes that against the DBCollection . |
private class |
MongoTemplate.ReadDbObjectCallback<T>
Simple MongoTemplate.DbObjectCallback that will transform DBObject into the given target type using the given
MongoReader . |
Field Summary | |
---|---|
private ApplicationEventPublisher |
eventPublisher
|
private MongoExceptionTranslator |
exceptionTranslator
|
private static java.lang.String |
ID
|
private MongoPersistentEntityIndexCreator |
indexCreator
|
private static Log |
LOGGER
|
private QueryMapper |
mapper
|
private |
mappingContext
|
private MongoConverter |
mongoConverter
|
private MongoDbFactory |
mongoDbFactory
|
private boolean |
slaveOk
|
private WriteConcern |
writeConcern
|
private WriteResultChecking |
writeResultChecking
|
Constructor Summary | |
---|---|
MongoTemplate(MongoDbFactory mongoDbFactory)
Constructor used for a basic template configuration |
|
MongoTemplate(MongoDbFactory mongoDbFactory,
MongoConverter mongoConverter)
Constructor used for a basic template configuration |
|
MongoTemplate(MongoDbFactory mongoDbFactory,
MongoConverter mongoConverter,
WriteConcern writeConcern,
WriteResultChecking writeResultChecking)
Constructor used for a template configuration with a custom MongoConverter and with a specific
com.mongodb.WriteConcern to be used for all database write operations |
|
MongoTemplate(Mongo mongo,
java.lang.String databaseName)
Constructor used for a basic template configuration |
|
MongoTemplate(Mongo mongo,
java.lang.String databaseName,
UserCredentials userCredentials)
Constructor used for a template configuration with user credentials in the form of org.springframework.data.authentication.UserCredentials |
Method Summary | ||
---|---|---|
boolean |
collectionExists(java.lang.String collectionName)
Check to see if a collection with a given name exists. |
|
private ObjectId |
convertIdValue(MongoConverter converter,
java.lang.Object value)
|
|
protected DBObject |
convertToDbObject(CollectionOptions collectionOptions)
|
|
DBCollection |
createCollection(java.lang.String collectionName)
Create an uncapped collection with the provided name. |
|
DBCollection |
createCollection(java.lang.String collectionName,
CollectionOptions collectionOptions)
Create a collect with the provided name and options. |
|
private java.lang.String |
determineCollectionName(java.lang.Class<?> clazz)
|
|
private
|
determineEntityCollectionName(T obj)
|
|
protected DBCollection |
doCreateCollection(java.lang.String collectionName,
DBObject collectionOptions)
Create the specified collection using the provided options |
|
protected
|
doFind(java.lang.String collectionName,
DBObject query,
DBObject fields,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter. |
|
protected
|
doFind(java.lang.String collectionName,
DBObject query,
DBObject fields,
java.lang.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
|
doFindAndRemove(java.lang.String collectionName,
DBObject query,
DBObject fields,
DBObject sort,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter. |
|
protected
|
doFindOne(java.lang.String collectionName,
DBObject query,
DBObject fields,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter The query document is specified as a standard DBObject and so is the fields specification. |
|
protected
|
doInsert(java.lang.String collectionName,
T objectToSave,
MongoWriter<T> writer)
|
|
protected
|
doInsertList(java.util.List<? extends T> listToSave,
MongoWriter<T> writer)
|
|
protected
|
doInsertList(java.lang.String collectionName,
java.util.List<? extends T> listToSave,
MongoWriter<T> writer)
|
|
protected
|
doSave(java.lang.String collectionName,
T objectToSave,
MongoWriter<T> writer)
|
|
protected WriteResult |
doUpdate(java.lang.String collectionName,
Query query,
Update update,
java.lang.Class<?> entityClass,
boolean upsert,
boolean multi)
|
|
void |
dropCollection(java.lang.String collectionName)
Drop the collection with the given name. |
|
void |
ensureIndex(java.lang.Class<?> entityClass,
IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists for the default collection. |
|
void |
ensureIndex(java.lang.String collectionName,
IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists. |
|
|
execute(java.lang.Class<?> entityClass,
CollectionCallback<T> callback)
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(java.lang.String collectionName,
CollectionCallback<T> callback)
Executes the given CollectionCallback on the collection of the given name. |
|
CommandResult |
executeCommand(DBObject command)
Execute the a MongoDB command expressed as a JSON string. |
|
CommandResult |
executeCommand(java.lang.String jsonCommand)
Execute the a MongoDB command expressed as a JSON string. |
|
private
|
executeFindMultiInternal(CollectionCallback<DBCursor> collectionCallback,
CursorPreparer preparer,
MongoTemplate.DbObjectCallback<T> objectCallback,
java.lang.String collectionName)
Internal method using callback to do queries against the datastore that requires reading a collection of objects. |
|
private
|
executeFindOneInternal(CollectionCallback<DBObject> collectionCallback,
MongoTemplate.DbObjectCallback<T> objectCallback,
java.lang.String collectionName)
Internal method using callbacks to do queries against the datastore that requires reading a single object from a collection of objects. |
|
|
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,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. |
|
|
find(java.lang.String collectionName,
Query query,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
find(java.lang.String collectionName,
Query query,
java.lang.Class<T> targetClass,
CursorPreparer preparer)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
findAndRemove(Query query,
java.lang.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(java.lang.String collectionName,
Query query,
java.lang.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. |
|
|
findById(java.lang.Object id,
java.lang.Class<T> targetClass)
Returns a document with the given id mapped onto the given class. |
|
|
findById(java.lang.String collectionName,
java.lang.Object id,
java.lang.Class<T> targetClass)
Returns the document with the given id from the given collection mapped onto the given target class. |
|
|
findOne(Query query,
java.lang.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(java.lang.String collectionName,
Query query,
java.lang.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. |
|
private DBCollection |
getAndPrepareCollection(DB db,
java.lang.String collectionName)
|
|
|
getCollection(java.lang.Class<T> targetClass)
Query for a list of objects of type T from the default collection. |
|
DBCollection |
getCollection(java.lang.String collectionName)
Get a collection by name, creating it if it doesn't exist. |
|
|
getCollection(java.lang.String collectionName,
java.lang.Class<T> targetClass)
Query for a list of objects of type T from the specified collection. |
|
java.lang.String |
getCollectionName(java.lang.Class<?> clazz)
The collection name used for the specified class by this template. |
|
java.util.Set<java.lang.String> |
getCollectionNames()
A set of collection names. |
|
MongoConverter |
getConverter()
Returns the default MongoConverter . |
|
DB |
getDb()
|
|
MongoDbFactory |
getDbFactory()
Returns the MongoDbFactory . |
|
private MongoConverter |
getDefaultMongoConverter()
|
|
private MongoPersistentProperty |
getIdPropertyFor(java.lang.Class<?> type)
|
|
protected java.lang.String |
getIdPropertyName(java.lang.Object object)
|
|
protected java.lang.Object |
getIdValue(java.lang.Object object)
|
|
|
getMappingContext()
|
|
private MongoPersistentEntity<?> |
getPersistentEntity(java.lang.Class<?> type)
|
|
private void |
handleAnyWriteResultErrors(WriteResult wr,
DBObject query,
java.lang.String operation)
Checks and handles any errors. |
|
void |
insert(java.lang.Object objectToSave)
Insert the object into the default collection. |
|
void |
insert(java.lang.String collectionName,
java.lang.Object objectToSave)
Insert the object into the specified collection. |
|
protected java.lang.Object |
insertDBObject(java.lang.String collectionName,
DBObject dbDoc)
|
|
protected java.util.List<ObjectId> |
insertDBObjectList(java.lang.String collectionName,
java.util.List<DBObject> dbDocList)
|
|
void |
insertList(java.util.List<? extends java.lang.Object> listToSave)
Insert a list of objects into the default collection in a single batch write to the database. |
|
void |
insertList(java.lang.String collectionName,
java.util.List<? extends java.lang.Object> listToSave)
Insert a list of objects into the specified collection in a single batch write to the database. |
|
protected
|
maybeEmitEvent(MongoMappingEvent<T> event)
|
|
protected void |
populateIdIfNecessary(java.lang.Object savedObject,
java.lang.Object id)
Populates the id property of the saved object, if it's not set already. |
|
private java.lang.RuntimeException |
potentiallyConvertRuntimeException(java.lang.RuntimeException ex)
Tries to convert the given RuntimeException into a DataAccessException but returns the original
exception if the conversation failed. |
|
protected void |
prepareCollection(DBCollection collection)
Prepare the collection before any processing is done using it. |
|
protected WriteConcern |
prepareWriteConcern(WriteConcern writeConcern)
Prepare the WriteConcern before any processing is done using it. |
|
void |
remove(java.lang.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,
java.lang.Class<T> targetClass)
Remove all documents from the default collection that match the provided query document criteria. |
|
void |
remove(java.lang.String collectionName,
Query query)
Remove all documents from the specified collection that match the provided query document criteria. |
|
|
remove(java.lang.String collectionName,
Query query,
java.lang.Class<T> targetClass)
Remove all documents from the specified collection that match the provided query document criteria. |
|
void |
save(java.lang.Object objectToSave)
Save the object to the default collection. |
|
void |
save(java.lang.String collectionName,
java.lang.Object objectToSave)
Save the object to the specified collection. |
|
protected java.lang.Object |
saveDBObject(java.lang.String collectionName,
DBObject dbDoc)
|
|
void |
setApplicationContext(ApplicationContext applicationContext)
|
|
void |
setSlaveOk(boolean slaveOk)
|
|
void |
setWriteConcern(WriteConcern writeConcern)
|
|
void |
setWriteResultChecking(WriteResultChecking resultChecking)
|
|
WriteResult |
updateFirst(java.lang.Class<?> entityClass,
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(java.lang.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(java.lang.Class<?> entityClass,
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(java.lang.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 |
Field Detail |
---|
private static final Log LOGGER
private static final java.lang.String ID
private WriteConcern writeConcern
private WriteResultChecking writeResultChecking
private boolean slaveOk
private MongoConverter mongoConverter
privatemappingContext
private MongoDbFactory mongoDbFactory
private MongoExceptionTranslator exceptionTranslator
private QueryMapper mapper
private ApplicationEventPublisher eventPublisher
private MongoPersistentEntityIndexCreator indexCreator
Constructor Detail |
---|
public MongoTemplate(Mongo mongo, java.lang.String databaseName)
mongo
- databaseName
- public MongoTemplate(Mongo mongo, java.lang.String databaseName, UserCredentials userCredentials)
org.springframework.data.authentication.UserCredentials
mongo
- databaseName
- userCredentials
- public MongoTemplate(MongoDbFactory mongoDbFactory)
mongoDbFactory
- public MongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter)
mongoDbFactory
- mongoConverter
- MongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter, WriteConcern writeConcern, WriteResultChecking writeResultChecking)
MongoConverter
and with a specific
com.mongodb.WriteConcern
to be used for all database write operations
mongoDbFactory
- mongoConverter
- writeConcern
- writeResultChecking
- Method Detail |
---|
private final MongoConverter getDefaultMongoConverter()
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
BeansException
public MongoConverter getConverter()
MongoConverter
.
public MongoDbFactory getDbFactory()
MongoDbFactory
.
publicgetMappingContext()
public java.lang.String getCollectionName(java.lang.Class<?> clazz)
MongoOperations
getCollectionName
in interface MongoOperations
public CommandResult executeCommand(java.lang.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 command expressed as a JSON string.public <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(java.lang.Class<?> entityClass, CollectionCallback<T> callback)
MongoOperations
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.
execute
in interface MongoOperations
T
- return typeentityClass
- class that determines the collection to usecallback
- callback object that specifies the MongoDB action
public <T> T execute(java.lang.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(java.lang.String collectionName)
MongoOperations
createCollection
in interface MongoOperations
collectionName
- name of the collection
public DBCollection createCollection(java.lang.String collectionName, CollectionOptions collectionOptions)
MongoOperations
createCollection
in interface MongoOperations
collectionName
- name of the collectioncollectionOptions
- options to use when creating the collection.
public DBCollection getCollection(java.lang.String collectionName)
MongoOperations
getCollection
in interface MongoOperations
collectionName
- name of the collection
public boolean collectionExists(java.lang.String collectionName)
MongoOperations
collectionExists
in interface MongoOperations
collectionName
- name of the collection
public void dropCollection(java.lang.String collectionName)
MongoOperations
dropCollection
in interface MongoOperations
collectionName
- name of the collection to drop/delete.public void ensureIndex(java.lang.Class<?> entityClass, IndexDefinition indexDefinition)
MongoOperations
IndexDefinition
exists for the default collection. If not it will be
created.
ensureIndex
in interface MongoOperations
entityClass
- class that determines the collection to usepublic void ensureIndex(java.lang.String collectionName, IndexDefinition indexDefinition)
MongoOperations
IndexDefinition
exists. If not it will be created.
ensureIndex
in interface MongoOperations
public <T> T findOne(Query query, java.lang.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(java.lang.String collectionName, Query query, java.lang.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> java.util.List<T> find(Query query, java.lang.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> java.util.List<T> find(java.lang.String collectionName, Query query, java.lang.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> java.util.List<T> find(java.lang.String collectionName, Query query, java.lang.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 findById(java.lang.Object id, java.lang.Class<T> targetClass)
MongoOperations
findById
in interface MongoOperations
id
- the id of the document to return.targetClass
- the type the document shall be converted into.
public <T> T findById(java.lang.String collectionName, java.lang.Object id, java.lang.Class<T> targetClass)
MongoOperations
findById
in interface MongoOperations
collectionName
- the collection to query for the documentid
- the id of the document to returntargetClass
- the type to convert the document to
public <T> T findAndRemove(Query query, java.lang.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(java.lang.String collectionName, Query query, java.lang.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 void insert(java.lang.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(java.lang.String collectionName, java.lang.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 collectionprotected void prepareCollection(DBCollection collection)
collection
- protected WriteConcern prepareWriteConcern(WriteConcern writeConcern)
writeConcern
- any WriteConcern already configured or null
protected <T> void doInsert(java.lang.String collectionName, T objectToSave, MongoWriter<T> writer)
public void insertList(java.util.List<? extends java.lang.Object> listToSave)
MongoOperations
insertList
in interface MongoOperations
listToSave
- the list of objects to save.public void insertList(java.lang.String collectionName, java.util.List<? extends java.lang.Object> listToSave)
MongoOperations
insertList
in interface MongoOperations
collectionName
- name of the collection to store the object inlistToSave
- the list of objects to save.protected <T> void doInsertList(java.util.List<? extends T> listToSave, MongoWriter<T> writer)
protected <T> void doInsertList(java.lang.String collectionName, java.util.List<? extends T> listToSave, MongoWriter<T> writer)
public void save(java.lang.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(java.lang.String collectionName, java.lang.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 collectionprotected <T> void doSave(java.lang.String collectionName, T objectToSave, MongoWriter<T> writer)
protected java.lang.Object insertDBObject(java.lang.String collectionName, DBObject dbDoc)
protected java.util.List<ObjectId> insertDBObjectList(java.lang.String collectionName, java.util.List<DBObject> dbDocList)
protected java.lang.Object saveDBObject(java.lang.String collectionName, DBObject dbDoc)
public WriteResult updateFirst(java.lang.Class<?> entityClass, Query query, Update update)
MongoOperations
updateFirst
in interface MongoOperations
entityClass
- class that determines the collection to usepublic WriteResult updateFirst(java.lang.String collectionName, Query query, Update update)
MongoOperations
updateFirst
in interface MongoOperations
collectionName
- name of the collection to update the object inpublic WriteResult updateMulti(java.lang.Class<?> entityClass, Query query, Update update)
MongoOperations
updateMulti
in interface MongoOperations
entityClass
- class that determines the collection to usepublic WriteResult updateMulti(java.lang.String collectionName, Query query, Update update)
MongoOperations
updateMulti
in interface MongoOperations
collectionName
- name of the collection to update the object inprotected WriteResult doUpdate(java.lang.String collectionName, Query query, Update update, java.lang.Class<?> entityClass, boolean upsert, boolean multi)
public void remove(Query query)
MongoOperations
remove
in interface MongoOperations
public void remove(java.lang.Object object)
MongoOperations
remove
in interface MongoOperations
public <T> void remove(Query query, java.lang.Class<T> targetClass)
MongoOperations
remove
in interface MongoOperations
public <T> void remove(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass)
MongoOperations
remove
in interface MongoOperations
public void remove(java.lang.String collectionName, Query query)
MongoOperations
remove
in interface MongoOperations
collectionName
- name of the collection where the objects will removedpublic <T> java.util.List<T> getCollection(java.lang.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> java.util.List<T> getCollection(java.lang.String collectionName, java.lang.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 java.util.Set<java.lang.String> getCollectionNames()
MongoOperations
getCollectionNames
in interface MongoOperations
public DB getDb()
protected <T> void maybeEmitEvent(MongoMappingEvent<T> event)
protected DBCollection doCreateCollection(java.lang.String collectionName, DBObject collectionOptions)
collectionName
- collectionOptions
-
protected <T> T doFindOne(java.lang.String collectionName, DBObject query, DBObject fields, java.lang.Class<T> targetClass)
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.
protected <T> java.util.List<T> doFind(java.lang.String collectionName, DBObject query, DBObject fields, java.lang.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> java.util.List<T> doFind(java.lang.String collectionName, DBObject query, DBObject fields, java.lang.Class<T> targetClass)
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.
protected DBObject convertToDbObject(CollectionOptions collectionOptions)
protected <T> T doFindAndRemove(java.lang.String collectionName, DBObject query, DBObject fields, DBObject sort, java.lang.Class<T> targetClass)
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.
protected java.lang.Object getIdValue(java.lang.Object object)
protected java.lang.String getIdPropertyName(java.lang.Object object)
protected void populateIdIfNecessary(java.lang.Object savedObject, java.lang.Object id)
savedObject
- id
- private DBCollection getAndPrepareCollection(DB db, java.lang.String collectionName)
private <T> T executeFindOneInternal(CollectionCallback<DBObject> collectionCallback, MongoTemplate.DbObjectCallback<T> objectCallback, java.lang.String collectionName)
ConnectionCallback
for a DBObject
.MongoTemplate.DbObjectCallback
to each of the DBObject
s to obtain the result.
T
- collectionCallback
- the callback to retrieve the DBObject
withobjectCallback
- the MongoTemplate.DbObjectCallback
to transform DBObject
s into the actual domain typecollectionName
- the collection to be queried
private <T> java.util.List<T> executeFindMultiInternal(CollectionCallback<DBCursor> collectionCallback, CursorPreparer preparer, MongoTemplate.DbObjectCallback<T> objectCallback, java.lang.String collectionName)
ConnectionCallback
for a DBCursor
.DBCursor
with the given CursorPreparer
(will be skipped if CursorPreparer
is nullDBCursor
and applies the given MongoTemplate.DbObjectCallback
to each of the
DBObject
s collecting the actual result List
.
T
- collectionCallback
- the callback to retrieve the DBCursor
withpreparer
- the CursorPreparer
to potentially modify the DBCursor
before ireating over itobjectCallback
- the MongoTemplate.DbObjectCallback
to transform DBObject
s into the actual domain typecollectionName
- the collection to be queried
private MongoPersistentEntity<?> getPersistentEntity(java.lang.Class<?> type)
private MongoPersistentProperty getIdPropertyFor(java.lang.Class<?> type)
private ObjectId convertIdValue(MongoConverter converter, java.lang.Object value)
private <T> java.lang.String determineEntityCollectionName(T obj)
private java.lang.String determineCollectionName(java.lang.Class<?> clazz)
private void handleAnyWriteResultErrors(WriteResult wr, DBObject query, java.lang.String operation)
private java.lang.RuntimeException potentiallyConvertRuntimeException(java.lang.RuntimeException ex)
RuntimeException
into a DataAccessException
but returns the original
exception if the conversation failed. Thus allows safe rethrowing of the return value.
ex
-
public void setWriteResultChecking(WriteResultChecking resultChecking)
public void setWriteConcern(WriteConcern writeConcern)
public void setSlaveOk(boolean slaveOk)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |