remove a some ctors in mongo template

This commit is contained in:
Mark Pollack
2011-04-07 19:25:56 -04:00
parent d8ce9189f1
commit c21301f00b
2 changed files with 7 additions and 3 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.data.document.mongodb;
import com.mongodb.MongoException;
import com.mongodb.MongoException.CursorNotFound;
import com.mongodb.MongoException.DuplicateKey;
import com.mongodb.MongoException.Network;
import com.mongodb.MongoInternalException;
@@ -52,11 +53,14 @@ public class MongoExceptionTranslator implements PersistenceExceptionTranslator
// All other MongoExceptions
if (ex instanceof DuplicateKey) {
return new DataIntegrityViolationException(ex.getMessage(), ex);
return new DuplicateKeyException(ex.getMessage(), ex);
}
if (ex instanceof Network) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof CursorNotFound) {
return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof MongoException) {
int code = ((MongoException)ex).getCode();
if (code == 11000 || code == 11001) {

View File

@@ -96,8 +96,8 @@ public class MongoTemplateTests {
@Test
public void updateFailure() throws Exception {
MongoTemplate mongoTemplate = new MongoTemplate(template.getDb().getMongo(), "test", "people",
new WriteConcern(), WriteResultChecking.EXCEPTION);
MongoTemplate mongoTemplate = new MongoTemplate(template.getDb().getMongo(), "test", "people");
mongoTemplate.setWriteResultChecking(WriteResultChecking.EXCEPTION);
Person person = new Person("Oliver2");
person.setAge(25);