added ExceptionTranslator inreface to factory bean for convenience during configuration and to be consistent with JPA configs
This commit is contained in:
@@ -22,6 +22,8 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.beans.factory.FactoryBean;
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import com.mongodb.Mongo;
|
import com.mongodb.Mongo;
|
||||||
@@ -36,7 +38,7 @@ import com.mongodb.ServerAddress;
|
|||||||
*
|
*
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean {
|
public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, PersistenceExceptionTranslator {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,6 +53,8 @@ public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean {
|
|||||||
private List<ServerAddress> replicaSetSeeds;
|
private List<ServerAddress> replicaSetSeeds;
|
||||||
private List<ServerAddress> replicaPair;
|
private List<ServerAddress> replicaPair;
|
||||||
|
|
||||||
|
private PersistenceExceptionTranslator exceptionTranslator = new MongoExceptionTranslator();
|
||||||
|
|
||||||
public void setMongoOptions(MongoOptions mongoOptions) {
|
public void setMongoOptions(MongoOptions mongoOptions) {
|
||||||
this.mongoOptions = mongoOptions;
|
this.mongoOptions = mongoOptions;
|
||||||
}
|
}
|
||||||
@@ -117,4 +121,8 @@ public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
|
||||||
|
return exceptionTranslator.translateExceptionIfPossible(ex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user