|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.data.mongodb.core.MongoTemplate
public class MongoTemplate
Primary implementation of MongoOperations
.
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(Mongo mongo,
String databaseName)
Constructor used for a basic template configuration |
|
MongoTemplate(Mongo mongo,
String databaseName,
org.springframework.data.authentication.UserCredentials userCredentials)
Constructor used for a template configuration with user credentials in the form of UserCredentials |
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. |
|
protected DBObject |
convertToDbObject(CollectionOptions collectionOptions)
|
|
|
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. |
|
protected DBCollection |
doCreateCollection(String collectionName,
DBObject collectionOptions)
Create the specified collection using the provided options |
|
protected
|
doFind(String collectionName,
DBObject query,
DBObject fields,
Class<S> entityClass,
CursorPreparer preparer,
org.springframework.data.mongodb.core.MongoTemplate.DbObjectCallback<T> objectCallback)
|
|
protected
|
doFind(String collectionName,
DBObject query,
DBObject fields,
Class<T> entityClass)
Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter. |
|
protected
|
doFind(String collectionName,
DBObject query,
DBObject fields,
Class<T> entityClass,
CursorPreparer preparer)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. |
|
protected
|
doFindAndRemove(String collectionName,
DBObject query,
DBObject fields,
DBObject sort,
Class<T> entityClass)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter. |
|
protected
|
doFindOne(String collectionName,
DBObject query,
DBObject fields,
Class<T> entityClass)
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(String collectionName,
T objectToSave,
MongoWriter<T> writer)
|
|
protected
|
doInsertAll(Collection<? extends T> listToSave,
MongoWriter<T> writer)
|
|
protected
|
doInsertBatch(String collectionName,
Collection<? extends T> batchToSave,
MongoWriter<T> writer)
|
|
protected
|
doRemove(String collectionName,
Query query,
Class<T> entityClass)
|
|
protected
|
doSave(String collectionName,
T objectToSave,
MongoWriter<T> writer)
|
|
protected WriteResult |
doUpdate(String collectionName,
Query query,
Update update,
Class<?> entityClass,
boolean upsert,
boolean multi)
|
|
|
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. |
|
protected void |
ensureNotIterable(Object o)
|
|
|
execute(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(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(DBObject command,
int options)
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. |
|
void |
executeQuery(Query query,
String collectionName,
DocumentCallbackHandler dch)
Execute a MongoDB query and iterate over the query results on a per-document basis with a DocumentCallbackHandler. |
|
void |
executeQuery(Query query,
String collectionName,
DocumentCallbackHandler dch,
CursorPreparer preparer)
Execute a MongoDB query and iterate over the query results on a per-document basis with a DocumentCallbackHandler using the provided CursorPreparer. |
|
|
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. |
|
|
geoNear(NearQuery near,
Class<T> entityClass)
Returns GeoResult for all entities matching the given NearQuery . |
|
|
geoNear(NearQuery near,
Class<T> entityClass,
String collectionName)
Returns GeoResult for all entities matching the given NearQuery . |
|
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. |
|
MongoConverter |
getConverter()
Returns the default org.springframework.data.mongodb.core.core.convert.MongoConverter . |
|
DB |
getDb()
|
|
protected String |
getIdPropertyName(Object object)
|
|
protected Object |
getIdValue(Object object)
|
|
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. |
|
protected Object |
insertDBObject(String collectionName,
DBObject dbDoc)
|
|
protected List<ObjectId> |
insertDBObjectList(String collectionName,
List<DBObject> dbDocList)
|
|
protected void |
logCommandExecutionError(DBObject command,
CommandResult result)
|
|
|
mapReduce(Query query,
String inputCollectionName,
String mapFunction,
String reduceFunction,
Class<T> entityClass)
Execute a map-reduce operation that takes a query. |
|
|
mapReduce(Query query,
String inputCollectionName,
String mapFunction,
String reduceFunction,
MapReduceOptions mapReduceOptions,
Class<T> entityClass)
Execute a map-reduce operation that takes a query and additional map-reduce options |
|
|
mapReduce(String inputCollectionName,
String mapFunction,
String reduceFunction,
Class<T> entityClass)
Execute a map-reduce operation. |
|
|
mapReduce(String inputCollectionName,
String mapFunction,
String reduceFunction,
MapReduceOptions mapReduceOptions,
Class<T> entityClass)
Execute a map-reduce operation that takes additional map-reduce options. |
|
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. |
|
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(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. |
|
protected String |
replaceWithResourceIfNecessary(String function)
|
|
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. |
|
protected Object |
saveDBObject(String collectionName,
DBObject dbDoc)
|
|
void |
setApplicationContext(ApplicationContext applicationContext)
|
|
void |
setSlaveOk(boolean slaveOk)
TODO: document properly |
|
void |
setWriteConcern(WriteConcern writeConcern)
Configures the WriteConcern to be used with the template. |
|
void |
setWriteResultChecking(WriteResultChecking resultChecking)
Configures the WriteResultChecking to be used with the template. |
|
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. |
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, org.springframework.data.authentication.UserCredentials userCredentials)
UserCredentials
mongo
- databaseName
- userCredentials
- public MongoTemplate(MongoDbFactory mongoDbFactory)
mongoDbFactory
- public MongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter)
mongoDbFactory
- mongoConverter
- Method Detail |
---|
public void setWriteResultChecking(WriteResultChecking resultChecking)
WriteResultChecking
to be used with the template. Setting null will reset the
default of .
resultChecking
- public void setWriteConcern(WriteConcern writeConcern)
WriteConcern
to be used with the template.
writeConcern
- public void setSlaveOk(boolean slaveOk)
slaveOk
- public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
public MongoConverter getConverter()
org.springframework.data.mongodb.core.core.convert.MongoConverter
.
getConverter
in interface MongoOperations
public String getCollectionName(Class<?> entityClass)
MongoOperations
getCollectionName
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 CommandResult executeCommand(DBObject command, int options)
MongoOperations
executeCommand
in interface MongoOperations
command
- a MongoDB commandoptions
- query options to useprotected void logCommandExecutionError(DBObject command, CommandResult result)
public void executeQuery(Query query, String collectionName, DocumentCallbackHandler dch)
MongoOperations
executeQuery
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationcollectionName
- name of the collection to retrieve the objects fromdch
- the handler that will extract results, one document at a timepublic void executeQuery(Query query, String collectionName, DocumentCallbackHandler dch, CursorPreparer preparer)
MongoOperations
executeQuery
in interface MongoOperations
query
- the query class that specifies the criteria used to find a record and also an optional fields
specificationcollectionName
- name of the collection to retrieve the objects fromdch
- the handler that will extract results, one document at a timepreparer
- allows for customization of the DBCursor used when iterating over the result set, (apply limits,
skips and so on).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(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(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 <T> DBCollection createCollection(Class<T> entityClass)
MongoOperations
createCollection
in interface MongoOperations
entityClass
- class that determines the collection to create
public <T> DBCollection createCollection(Class<T> entityClass, CollectionOptions collectionOptions)
MongoOperations
createCollection
in interface MongoOperations
entityClass
- class that determines the collection to createcollectionOptions
- options to use when creating the collection.
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 <T> boolean collectionExists(Class<T> entityClass)
MongoOperations
collectionExists
in interface MongoOperations
entityClass
- class that determines the name of the collection
public boolean collectionExists(String collectionName)
MongoOperations
collectionExists
in interface MongoOperations
collectionName
- name of the collection
public <T> void dropCollection(Class<T> entityClass)
MongoOperations
dropCollection
in interface MongoOperations
entityClass
- class that determines the collection to drop/delete.public void dropCollection(String collectionName)
MongoOperations
dropCollection
in interface MongoOperations
collectionName
- name of the collection to drop/delete.public void ensureIndex(IndexDefinition indexDefinition, Class<?> entityClass)
MongoOperations
IndexDefinition
exists for the collection indicated by the entity
class. If not it will be created.
ensureIndex
in interface MongoOperations
entityClass
- class that determines the collection to usepublic void ensureIndex(IndexDefinition indexDefinition, String collectionName)
MongoOperations
IndexDefinition
exists. If not it will be created.
ensureIndex
in interface MongoOperations
public <T> T findOne(Query query, Class<T> entityClass)
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
specificationentityClass
- the parameterized type of the returned list.
public <T> T findOne(Query query, Class<T> entityClass, String collectionName)
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
specificationentityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
public <T> List<T> find(Query query, Class<T> entityClass)
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
specificationentityClass
- the parameterized type of the returned list.
public <T> List<T> find(Query query, Class<T> entityClass, String collectionName)
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
specificationentityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
public <T> List<T> find(Query query, Class<T> entityClass, CursorPreparer preparer, String collectionName)
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
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
public <T> T findById(Object id, Class<T> entityClass)
MongoOperations
findById
in interface MongoOperations
id
- the id of the document to return.entityClass
- the type the document shall be converted into.
public <T> T findById(Object id, Class<T> entityClass, String collectionName)
MongoOperations
findById
in interface MongoOperations
id
- the id of the document to returnentityClass
- the type to convert the document tocollectionName
- the collection to query for the document
public <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass)
MongoOperations
GeoResult
for all entities matching the given NearQuery
. Will consider entity mapping
information to determine the collection the query is ran against.
geoNear
in interface MongoOperations
near
- must not be null.entityClass
- must not be null.
public <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass, String collectionName)
MongoOperations
GeoResult
for all entities matching the given NearQuery
.
geoNear
in interface MongoOperations
near
- must not be null.entityClass
- must not be null.collectionName
- the collection to trigger the query against. If no collection name is given the entity class
will be inspected.
public <T> T findAndRemove(Query query, Class<T> entityClass)
MongoOperations
MongoConverter
.
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
specificationentityClass
- the parameterized type of the returned list.
public <T> T findAndRemove(Query query, Class<T> entityClass, String collectionName)
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
specificationentityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
public void insert(Object objectToSave)
MongoOperations
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.
insert
in interface MongoOperations
objectToSave
- the object to store in the collection.public void insert(Object objectToSave, String collectionName)
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
objectToSave
- the object to store in the collectioncollectionName
- name of the collection to store the object inprotected void ensureNotIterable(Object o)
protected void prepareCollection(DBCollection collection)
collection
- protected WriteConcern prepareWriteConcern(WriteConcern writeConcern)
writeConcern
- any WriteConcern already configured or null
protected <T> void doInsert(String collectionName, T objectToSave, MongoWriter<T> writer)
public void insert(Collection<? extends Object> batchToSave, Class<?> entityClass)
MongoOperations
insert
in interface MongoOperations
batchToSave
- the list of objects to save.entityClass
- class that determines the collection to usepublic void insert(Collection<? extends Object> batchToSave, String collectionName)
MongoOperations
insert
in interface MongoOperations
batchToSave
- the list of objects to save.collectionName
- name of the collection to store the object inpublic void insertAll(Collection<? extends Object> objectsToSave)
MongoOperations
insertAll
in interface MongoOperations
protected <T> void doInsertAll(Collection<? extends T> listToSave, MongoWriter<T> writer)
protected <T> void doInsertBatch(String collectionName, Collection<? extends T> batchToSave, MongoWriter<T> writer)
public 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(Object objectToSave, String collectionName)
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
objectToSave
- the object to store in the collectioncollectionName
- name of the collection to store the object inprotected <T> void doSave(String collectionName, T objectToSave, MongoWriter<T> writer)
protected 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, Class<?> entityClass)
MongoOperations
updateFirst
in interface MongoOperations
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 usepublic WriteResult updateFirst(Query query, Update update, String collectionName)
MongoOperations
updateFirst
in interface MongoOperations
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 inpublic WriteResult updateMulti(Query query, Update update, Class<?> entityClass)
MongoOperations
updateMulti
in interface MongoOperations
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 usepublic WriteResult updateMulti(Query query, Update update, String collectionName)
MongoOperations
updateMulti
in interface MongoOperations
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 inprotected WriteResult doUpdate(String collectionName, Query query, Update update, Class<?> entityClass, boolean upsert, boolean multi)
public void remove(Object object)
MongoOperations
remove
in interface MongoOperations
public <T> void remove(Query query, Class<T> entityClass)
MongoOperations
remove
in interface MongoOperations
protected <T> void doRemove(String collectionName, Query query, Class<T> entityClass)
public void remove(Query query, String collectionName)
MongoOperations
remove
in interface MongoOperations
query
- the query document that specifies the criteria used to remove a recordcollectionName
- name of the collection where the objects will removedpublic <T> List<T> findAll(Class<T> entityClass)
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.
findAll
in interface MongoOperations
entityClass
- the parameterized type of the returned list
public <T> List<T> findAll(Class<T> entityClass, String collectionName)
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.
findAll
in interface MongoOperations
entityClass
- the parameterized type of the returned list.collectionName
- name of the collection to retrieve the objects from
public <T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction, Class<T> entityClass)
MongoOperations
mapReduce
in interface MongoOperations
inputCollectionName
- the collection where the map-reduce will read frommapFunction
- The JavaScript map functionreduceFunction
- The JavaScript reduce functionentityClass
- The parameterized type of the returned list
public <T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass)
MongoOperations
mapReduce
in interface MongoOperations
inputCollectionName
- the collection where the map-reduce will read frommapFunction
- The JavaScript map functionreduceFunction
- The JavaScript reduce functionmapReduceOptions
- Options that specify detailed map-reduce behaviorentityClass
- The parameterized type of the returned list
public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction, Class<T> entityClass)
MongoOperations
mapReduce
in interface MongoOperations
query
- The query to use to select the data for the map phaseinputCollectionName
- the collection where the map-reduce will read frommapFunction
- The JavaScript map functionreduceFunction
- The JavaScript reduce functionentityClass
- The parameterized type of the returned list
public <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass)
MongoOperations
mapReduce
in interface MongoOperations
query
- The query to use to select the data for the map phaseinputCollectionName
- the collection where the map-reduce will read frommapFunction
- The JavaScript map functionreduceFunction
- The JavaScript reduce functionmapReduceOptions
- Options that specify detailed map-reduce behaviorentityClass
- The parameterized type of the returned list
protected String replaceWithResourceIfNecessary(String function)
public Set<String> getCollectionNames()
MongoOperations
getCollectionNames
in interface MongoOperations
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> entityClass)
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 returnedentityClass
- the parameterized type of the returned list.
protected <T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<T> entityClass, 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 returnedentityClass
- 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 <S,T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<S> entityClass, CursorPreparer preparer, org.springframework.data.mongodb.core.MongoTemplate.DbObjectCallback<T> objectCallback)
protected <T> List<T> doFind(String collectionName, DBObject query, DBObject fields, Class<T> entityClass)
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 returnedentityClass
- the parameterized type of the returned list.
protected DBObject convertToDbObject(CollectionOptions collectionOptions)
protected <T> T doFindAndRemove(String collectionName, DBObject query, DBObject fields, DBObject sort, Class<T> entityClass)
collectionName
- name of the collection to retrieve the objects fromquery
- the query document that specifies the criteria used to find a recordentityClass
- the parameterized type of the returned list.
protected Object getIdValue(Object object)
protected String getIdPropertyName(Object object)
protected void populateIdIfNecessary(Object savedObject, Object id)
savedObject
- id
-
|
Spring Data Document | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |