From dfbc89c3b614215761b2edd64802b064bca72238 Mon Sep 17 00:00:00 2001 From: Thomas Risberg Date: Thu, 5 May 2011 13:59:29 -0400 Subject: [PATCH] DATADOC-118 removed methods that take a MongoWriter --- .../document/mongodb/MongoOperations.java | 79 ------------------- .../data/document/mongodb/MongoTemplate.java | 42 ++-------- .../mongodb/MongoOperationsUnitTests.java | 20 ----- 3 files changed, 8 insertions(+), 133 deletions(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java index 268dad9c0..e3d8a7a41 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoOperations.java @@ -378,37 +378,6 @@ public interface MongoOperations { */ 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 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 - */ - void insert(T objectToSave, MongoWriter writer); - - /** - * Insert the object into the specified 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 the type of the object to insert - * @param collectionName name of the collection to store the object in - * @param objectToSave the object to store in the collection - * @param writer the writer to convert the object to save into a DBObject - */ - void insert(String collectionName, T objectToSave, MongoWriter writer); - /** * Insert a list of objects into the default collection in a single batch write to the database. * @@ -424,25 +393,6 @@ public interface MongoOperations { */ void insertList(String collectionName, List listToSave); - /** - * Insert a list of objects into the default collection using the provided MongoWriter instance - * - * @param 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 - */ - void insertList(List listToSave, MongoWriter writer); - - /** - * Insert a list of objects into the specified collection using the provided MongoWriter instance - * - * @param the type of object being saved - * @param collectionName name of the collection to store the object in - * @param listToSave the list of objects to save. - * @param writer the writer to convert the object to save into a DBObject - */ - void insertList(String collectionName, List listToSave, MongoWriter writer); - /** * Save the object to the default collection. This will perform an insert if the object is not already * present, that is an 'upsert'. @@ -482,35 +432,6 @@ public interface MongoOperations { */ void save(String collectionName, Object objectToSave); - /** - * 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 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 - */ - void save(T objectToSave, MongoWriter 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'. - *

- * The object is converted to the MongoDB native representation using an instance of - * {@see MongoWriter} - * - * @param the type of the object to insert - * @param collectionName name of the collection to store the object in - * @param objectToSave the object to store in the collection - * @param writer the writer to convert the object to save into a DBObject - */ - void save(String collectionName, T objectToSave, MongoWriter writer); - /** * Updates the first object that is found in the default collection that matches the query document * with the provided updated document. diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java index 7f404b549..012278ffa 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/document/mongodb/MongoTemplate.java @@ -504,20 +504,10 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher * @see org.springframework.data.document.mongodb.MongoOperations#insert(java.lang.String, java.lang.Object) */ public void insert(String collectionName, Object objectToSave) { - insert(collectionName, objectToSave, this.mongoConverter); + doInsert(collectionName, objectToSave, this.mongoConverter); } - /* (non-Javadoc) - * @see org.springframework.data.document.mongodb.MongoOperations#insert(T, org.springframework.data.document.mongodb.MongoWriter) - */ - public void insert(T objectToSave, MongoWriter writer) { - insert(determineEntityCollectionName(objectToSave), objectToSave, writer); - } - - /* (non-Javadoc) - * @see org.springframework.data.document.mongodb.MongoOperations#insert(java.lang.String, T, org.springframework.data.document.mongodb.MongoWriter) - */ - public void insert(String collectionName, T objectToSave, MongoWriter writer) { + protected void doInsert(String collectionName, T objectToSave, MongoWriter writer) { BasicDBObject dbDoc = new BasicDBObject(); maybeEmitEvent(new BeforeConvertEvent(objectToSave)); @@ -534,20 +524,17 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher * @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.util.List) */ public void insertList(List listToSave) { - insertList(listToSave, mongoConverter); + doInsertList(listToSave, mongoConverter); } /* (non-Javadoc) * @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.lang.String, java.util.List) */ public void insertList(String collectionName, List listToSave) { - insertList(collectionName, listToSave, this.mongoConverter); + doInsertList(collectionName, listToSave, this.mongoConverter); } - /* (non-Javadoc) - * @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.util.List, org.springframework.data.document.mongodb.MongoWriter) - */ - public void insertList(List listToSave, MongoWriter writer) { + protected void doInsertList(List listToSave, MongoWriter writer) { Map> objs = new HashMap>(); for (Object o : listToSave) { @@ -573,10 +560,7 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher } } - /* (non-Javadoc) - * @see org.springframework.data.document.mongodb.MongoOperations#insertList(java.lang.String, java.util.List, org.springframework.data.document.mongodb.MongoWriter) - */ - public void insertList(String collectionName, List listToSave, MongoWriter writer) { + protected void doInsertList(String collectionName, List listToSave, MongoWriter writer) { Assert.notNull(writer); @@ -611,20 +595,10 @@ public class MongoTemplate implements MongoOperations, ApplicationEventPublisher * @see org.springframework.data.document.mongodb.MongoOperations#save(java.lang.String, java.lang.Object) */ public void save(String collectionName, Object objectToSave) { - save(collectionName, objectToSave, this.mongoConverter); + doSave(collectionName, objectToSave, this.mongoConverter); } - /* (non-Javadoc) - * @see org.springframework.data.document.mongodb.MongoOperations#save(T, org.springframework.data.document.mongodb.MongoWriter) - */ - public void save(T objectToSave, MongoWriter writer) { - save(determineEntityCollectionName(objectToSave), objectToSave, writer); - } - - /* (non-Javadoc) - * @see org.springframework.data.document.mongodb.MongoOperations#save(java.lang.String, T, org.springframework.data.document.mongodb.MongoWriter) - */ - public void save(String collectionName, T objectToSave, MongoWriter writer) { + protected void doSave(String collectionName, T objectToSave, MongoWriter writer) { BasicDBObject dbDoc = new BasicDBObject(); maybeEmitEvent(new BeforeConvertEvent(objectToSave)); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoOperationsUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoOperationsUnitTests.java index 1ca9842da..cf8ffe1f9 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoOperationsUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/document/mongodb/MongoOperationsUnitTests.java @@ -273,16 +273,6 @@ public abstract class MongoOperationsUnitTests { }.assertDataAccessException(); } - @Test - public void convertsExceptionForInsert3() { - new Execution() { - @Override - public void doWith(MongoOperations operations) { - operations.insert("collection", person, converter); - } - }.assertDataAccessException(); - } - @Test public void convertsExceptionForInsertList() throws Exception { new Execution() { @@ -303,16 +293,6 @@ public abstract class MongoOperationsUnitTests { }.assertDataAccessException(); } - @Test - public void convertsExceptionForGetInsertList3() throws Exception { - new Execution() { - @Override - public void doWith(MongoOperations operations) { - operations.insertList("collection", persons, converter); - } - }.assertDataAccessException(); - } - private abstract class Execution { public void assertDataAccessException() {