|
||||||||||
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(MongoDbFactory mongoDbFactory)
Constructor used for a basic template configuration |
|
MongoTemplate(MongoDbFactory mongoDbFactory,
MongoConverter mongoConverter)
Constructor used for a basic template configuration |
|
MongoTemplate(com.mongodb.Mongo mongo,
java.lang.String databaseName)
Constructor used for a basic template configuration |
|
MongoTemplate(com.mongodb.Mongo mongo,
java.lang.String databaseName,
org.springframework.data.authentication.UserCredentials userCredentials)
Constructor used for a template configuration with user credentials in the form of UserCredentials |
Method Summary | ||
---|---|---|
boolean |
collectionExists(java.lang.String collectionName)
Check to see if a collection with a given name exists. |
|
protected com.mongodb.DBObject |
convertToDbObject(CollectionOptions collectionOptions)
|
|
com.mongodb.DBCollection |
createCollection(java.lang.String collectionName)
Create an uncapped collection with the provided name. |
|
com.mongodb.DBCollection |
createCollection(java.lang.String collectionName,
CollectionOptions collectionOptions)
Create a collect with the provided name and options. |
|
protected com.mongodb.DBCollection |
doCreateCollection(java.lang.String collectionName,
com.mongodb.DBObject collectionOptions)
Create the specified collection using the provided options |
|
protected
|
doFind(java.lang.String collectionName,
com.mongodb.DBObject query,
com.mongodb.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,
com.mongodb.DBObject query,
com.mongodb.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,
com.mongodb.DBObject query,
com.mongodb.DBObject fields,
com.mongodb.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,
com.mongodb.DBObject query,
com.mongodb.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 com.mongodb.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. |
|
com.mongodb.CommandResult |
executeCommand(com.mongodb.DBObject command)
Execute a MongoDB command. |
|
com.mongodb.CommandResult |
executeCommand(java.lang.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,
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. |
|
|
getCollection(java.lang.Class<T> targetClass)
Query for a list of objects of type T from the default collection. |
|
com.mongodb.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 . |
|
com.mongodb.DB |
getDb()
|
|
MongoDbFactory |
getDbFactory()
Returns the MongoDbFactory . |
|
protected java.lang.String |
getIdPropertyName(java.lang.Object object)
|
|
protected java.lang.Object |
getIdValue(java.lang.Object object)
|
|
org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> |
getMappingContext()
|
|
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,
com.mongodb.DBObject dbDoc)
|
|
protected java.util.List<org.bson.types.ObjectId> |
insertDBObjectList(java.lang.String collectionName,
java.util.List<com.mongodb.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. |
|
protected void |
prepareCollection(com.mongodb.DBCollection collection)
Prepare the collection before any processing is done using it. |
|
protected com.mongodb.WriteConcern |
prepareWriteConcern(com.mongodb.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,
com.mongodb.DBObject dbDoc)
|
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
|
|
void |
setSlaveOk(boolean slaveOk)
|
|
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
|
|
void |
setWriteResultChecking(WriteResultChecking resultChecking)
|
|
com.mongodb.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. |
|
com.mongodb.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. |
|
com.mongodb.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. |
|
com.mongodb.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 |
Constructor Detail |
---|
public MongoTemplate(com.mongodb.Mongo mongo, java.lang.String databaseName)
mongo
- databaseName
- public MongoTemplate(com.mongodb.Mongo mongo, java.lang.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 setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
public MongoConverter getConverter()
MongoConverter
.
public MongoDbFactory getDbFactory()
MongoDbFactory
.
public org.springframework.data.mapping.model.MappingContext<? extends MongoPersistentEntity<?>,MongoPersistentProperty> getMappingContext()
public java.lang.String getCollectionName(java.lang.Class<?> clazz)
MongoOperations
getCollectionName
in interface MongoOperations
public com.mongodb.CommandResult executeCommand(java.lang.String jsonCommand)
MongoOperations
executeCommand
in interface MongoOperations
jsonCommand
- a MongoDB command expressed as a JSON string.public com.mongodb.CommandResult executeCommand(com.mongodb.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(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 com.mongodb.DBCollection createCollection(java.lang.String collectionName)
MongoOperations
createCollection
in interface MongoOperations
collectionName
- name of the collection
public com.mongodb.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 com.mongodb.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(com.mongodb.DBCollection collection)
collection
- protected com.mongodb.WriteConcern prepareWriteConcern(com.mongodb.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, com.mongodb.DBObject dbDoc)
protected java.util.List<org.bson.types.ObjectId> insertDBObjectList(java.lang.String collectionName, java.util.List<com.mongodb.DBObject> dbDocList)
protected java.lang.Object saveDBObject(java.lang.String collectionName, com.mongodb.DBObject dbDoc)
public com.mongodb.WriteResult updateFirst(java.lang.Class<?> entityClass, Query query, Update update)
MongoOperations
updateFirst
in interface MongoOperations
entityClass
- class that determines the collection to usepublic com.mongodb.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 com.mongodb.WriteResult updateMulti(java.lang.Class<?> entityClass, Query query, Update update)
MongoOperations
updateMulti
in interface MongoOperations
entityClass
- class that determines the collection to usepublic com.mongodb.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 com.mongodb.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 com.mongodb.DB getDb()
protected <T> void maybeEmitEvent(MongoMappingEvent<T> event)
protected com.mongodb.DBCollection doCreateCollection(java.lang.String collectionName, com.mongodb.DBObject collectionOptions)
collectionName
- collectionOptions
-
protected <T> T doFindOne(java.lang.String collectionName, com.mongodb.DBObject query, com.mongodb.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, com.mongodb.DBObject query, com.mongodb.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, com.mongodb.DBObject query, com.mongodb.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 com.mongodb.DBObject convertToDbObject(CollectionOptions collectionOptions)
protected <T> T doFindAndRemove(java.lang.String collectionName, com.mongodb.DBObject query, com.mongodb.DBObject fields, com.mongodb.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
- public void setWriteResultChecking(WriteResultChecking resultChecking)
public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
public void setSlaveOk(boolean slaveOk)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |