tweaking the line-up of methods in MongoOperations; make return value consistent for createCollection methods
This commit is contained in:
@@ -126,8 +126,9 @@ public interface MongoOperations {
|
|||||||
* Create a collect with the provided name and options.
|
* Create a collect with the provided name and options.
|
||||||
* @param collectionName name of the collection
|
* @param collectionName name of the collection
|
||||||
* @param collectionOptions options to use when creating the collection.
|
* @param collectionOptions options to use when creating the collection.
|
||||||
|
* @return the created collection
|
||||||
*/
|
*/
|
||||||
void createCollection(String collectionName, CollectionOptions collectionOptions);
|
DBCollection createCollection(String collectionName, CollectionOptions collectionOptions);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of collection names.
|
* A set of collection names.
|
||||||
@@ -426,6 +427,21 @@ public interface MongoOperations {
|
|||||||
*/
|
*/
|
||||||
void insert(String collectionName, Object objectToSave);
|
void insert(String collectionName, Object objectToSave);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert the object into the default collection.
|
||||||
|
*
|
||||||
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
|
* {@see MongoWriter}
|
||||||
|
*
|
||||||
|
* Insert is used to initially store the object into the
|
||||||
|
* database. To update an existing object use the save method.
|
||||||
|
*
|
||||||
|
* @param <T> the type of the object to insert
|
||||||
|
* @param objectToSave the object to store in the collection
|
||||||
|
* @param writer the writer to convert the object to save into a DBObject
|
||||||
|
*/
|
||||||
|
<T> void insert(T objectToSave, MongoWriter<T> writer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert the object into the specified collection.
|
* Insert the object into the specified collection.
|
||||||
*
|
*
|
||||||
@@ -456,6 +472,15 @@ public interface MongoOperations {
|
|||||||
*/
|
*/
|
||||||
void insertList(String collectionName, List<? extends Object> listToSave);
|
void insertList(String collectionName, List<? extends Object> listToSave);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a list of objects into the default collection using the provided MongoWriter instance
|
||||||
|
*
|
||||||
|
* @param <T> the type of object being saved
|
||||||
|
* @param listToSave the list of objects to save.
|
||||||
|
* @param writer the writer to convert the object to save into a DBObject
|
||||||
|
*/
|
||||||
|
<T> void insertList(List<? extends T> listToSave, MongoWriter<T> writer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert a list of objects into the specified collection using the provided MongoWriter instance
|
* Insert a list of objects into the specified collection using the provided MongoWriter instance
|
||||||
*
|
*
|
||||||
@@ -506,7 +531,22 @@ public interface MongoOperations {
|
|||||||
void save(String collectionName, Object objectToSave);
|
void save(String collectionName, Object objectToSave);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the object into the specified collection. This will perform an insert if the object is not already
|
* Save the object into the default collection using the provided writer.
|
||||||
|
* This will perform an insert if the object is not already
|
||||||
|
* present, that is an 'upsert'.
|
||||||
|
*
|
||||||
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
|
* {@see MongoWriter}
|
||||||
|
*
|
||||||
|
* @param <T> the type of the object to insert
|
||||||
|
* @param objectToSave the object to store in the collection
|
||||||
|
* @param writer the writer to convert the object to save into a DBObject
|
||||||
|
*/
|
||||||
|
<T> void save(T objectToSave, MongoWriter<T> writer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save the object into the specified collection using the provided writer.
|
||||||
|
* This will perform an insert if the object is not already
|
||||||
* present, that is an 'upsert'.
|
* present, that is an 'upsert'.
|
||||||
*
|
*
|
||||||
* The object is converted to the MongoDB native representation using an instance of
|
* The object is converted to the MongoDB native representation using an instance of
|
||||||
@@ -564,13 +604,13 @@ public interface MongoOperations {
|
|||||||
Update update);
|
Update update);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all documents from the default collection that match the provide query document criteria.
|
* Remove all documents from the default collection that match the provided query document criteria.
|
||||||
* @param queryDoc the query document that specifies the criteria used to remove a record
|
* @param queryDoc the query document that specifies the criteria used to remove a record
|
||||||
*/
|
*/
|
||||||
void remove(Query query);
|
void remove(Query query);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all documents from the specified collection that match the provide query document criteria.
|
* Remove all documents from the specified collection that match the provided query document criteria.
|
||||||
* @param collectionName name of the collection where the objects will removed
|
* @param collectionName name of the collection where the objects will removed
|
||||||
* @param queryDoc the query document that specifies the criteria used to remove a record
|
* @param queryDoc the query document that specifies the criteria used to remove a record
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -378,23 +378,14 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
* @see org.springframework.data.document.mongodb.MongoOperations#createCollection(java.lang.String)
|
* @see org.springframework.data.document.mongodb.MongoOperations#createCollection(java.lang.String)
|
||||||
*/
|
*/
|
||||||
public DBCollection createCollection(final String collectionName) {
|
public DBCollection createCollection(final String collectionName) {
|
||||||
return execute(new DbCallback<DBCollection>() {
|
return doCreateCollection(collectionName, new BasicDBObject());
|
||||||
public DBCollection doInDB(DB db) throws MongoException, DataAccessException {
|
|
||||||
return db.createCollection(collectionName, new BasicDBObject());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.springframework.data.document.mongodb.MongoOperations#createCollection(java.lang.String, org.springframework.data.document.mongodb.CollectionOptions)
|
* @see org.springframework.data.document.mongodb.MongoOperations#createCollection(java.lang.String, org.springframework.data.document.mongodb.CollectionOptions)
|
||||||
*/
|
*/
|
||||||
public void createCollection(final String collectionName, final CollectionOptions collectionOptions) {
|
public DBCollection createCollection(final String collectionName, final CollectionOptions collectionOptions) {
|
||||||
execute(new DbCallback<Void>() {
|
return doCreateCollection(collectionName, convertToDbObject(collectionOptions));
|
||||||
public Void doInDB(DB db) throws MongoException, DataAccessException {
|
|
||||||
db.createCollection(collectionName, convertToDbObject(collectionOptions));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
@@ -535,6 +526,13 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
insert(collectionName, objectToSave, this.mongoConverter);
|
insert(collectionName, objectToSave, this.mongoConverter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.document.mongodb.MongoOperations#insert(T, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
|
*/
|
||||||
|
public <T> void insert(T objectToSave, MongoWriter<T> writer) {
|
||||||
|
insert(getDefaultCollectionName(), objectToSave, writer);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.springframework.data.document.mongodb.MongoOperations#insert(java.lang.String, T, org.springframework.data.document.mongodb.MongoWriter)
|
* @see org.springframework.data.document.mongodb.MongoOperations#insert(java.lang.String, T, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
*/
|
*/
|
||||||
@@ -559,6 +557,13 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
insertList(collectionName, listToSave, this.mongoConverter);
|
insertList(collectionName, listToSave, this.mongoConverter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.util.List, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
|
*/
|
||||||
|
public <T> void insertList(List<? extends T> listToSave, MongoWriter<T> writer) {
|
||||||
|
insertList(getDefaultCollectionName(), listToSave, writer);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.lang.String, java.util.List, org.springframework.data.document.mongodb.MongoWriter)
|
* @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.lang.String, java.util.List, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
*/
|
*/
|
||||||
@@ -594,6 +599,13 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
save(collectionName, objectToSave, this.mongoConverter);
|
save(collectionName, objectToSave, this.mongoConverter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.springframework.data.document.mongodb.MongoOperations#save(T, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
|
*/
|
||||||
|
public <T> void save(T objectToSave, MongoWriter<T> writer) {
|
||||||
|
save(getDefaultCollectionName(), objectToSave, writer);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.springframework.data.document.mongodb.MongoOperations#save(java.lang.String, T, org.springframework.data.document.mongodb.MongoWriter)
|
* @see org.springframework.data.document.mongodb.MongoOperations#save(java.lang.String, T, org.springframework.data.document.mongodb.MongoWriter)
|
||||||
*/
|
*/
|
||||||
@@ -624,9 +636,6 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
}, collectionName);
|
}, collectionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected List<ObjectId> insertDBObjectList(String collectionName, final List<DBObject> dbDocList) {
|
protected List<ObjectId> insertDBObjectList(String collectionName, final List<DBObject> dbDocList) {
|
||||||
|
|
||||||
if (dbDocList.isEmpty()) {
|
if (dbDocList.isEmpty()) {
|
||||||
@@ -787,6 +796,20 @@ public class MongoTemplate implements InitializingBean, MongoOperations {
|
|||||||
return MongoDbUtils.getDB(mongo, databaseName, username, password == null ? null : password.toCharArray());
|
return MongoDbUtils.getDB(mongo, databaseName, username, password == null ? null : password.toCharArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the specified collection using the provided options
|
||||||
|
* @param collectionName
|
||||||
|
* @param collectionOptions
|
||||||
|
* @return the collection that was created
|
||||||
|
*/
|
||||||
|
protected DBCollection doCreateCollection(final String collectionName, final DBObject collectionOptions) {
|
||||||
|
return execute(new DbCallback<DBCollection>() {
|
||||||
|
public DBCollection doInDB(DB db) throws MongoException, DataAccessException {
|
||||||
|
return db.createCollection(collectionName, collectionOptions);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader
|
* Map the results of an ad-hoc query on the default MongoDB collection to an object using the provided MongoReader
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user