DATAMONGO-982 - Added build profiles to build against next MongoDB driver versions.

Added build profile for MongoDB Java driver versions 2.12.3-SNAPSHOT and 3.0.0-SNAPSHOT. Added another property to be able to build manifests correctly as the snapshot versions aren't valid OSGi versions.

Adapted MongoExceptionTranslator to convert the new Exceptions being thrown for server timeouts and the deprecated values we currently handle.
This commit is contained in:
Oliver Gierke
2014-07-08 17:31:16 +02:00
parent 89a42c5648
commit 566f9a80c4
5 changed files with 47 additions and 14 deletions

36
pom.xml
View File

@@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.data</groupId> <groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId> <artifactId>spring-data-mongodb-parent</artifactId>
<version>1.6.0.BUILD-SNAPSHOT</version> <version>1.6.0.BUILD-SNAPSHOT</version>
@@ -31,8 +31,9 @@
<dist.id>spring-data-mongodb</dist.id> <dist.id>spring-data-mongodb</dist.id>
<springdata.commons>1.9.0.BUILD-SNAPSHOT</springdata.commons> <springdata.commons>1.9.0.BUILD-SNAPSHOT</springdata.commons>
<mongo>2.12.1</mongo> <mongo>2.12.1</mongo>
<mongo.osgi>2.12.1</mongo.osgi>
</properties> </properties>
<developers> <developers>
<developer> <developer>
<id>ogierke</id> <id>ogierke</id>
@@ -104,10 +105,35 @@
<profiles> <profiles>
<profile> <profile>
<id>mongo-next</id> <id>mongo-next</id>
<properties> <properties>
<mongo>2.12.0</mongo> <mongo>2.12.3-SNAPSHOT</mongo>
</properties> </properties>
<repositories>
<repository>
<id>mongo-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
</profile>
<profile>
<id>mongo-3-next</id>
<properties>
<mongo>3.0.0-SNAPSHOT</mongo>
</properties>
<repositories>
<repository>
<id>mongo-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
</profile> </profile>
</profiles> </profiles>
@@ -119,14 +145,14 @@
<version>${mongo}</version> <version>${mongo}</version>
</dependency> </dependency>
</dependencies> </dependencies>
<repositories> <repositories>
<repository> <repository>
<id>spring-libs-snapshot</id> <id>spring-libs-snapshot</id>
<url>http://repo.spring.io/libs-snapshot</url> <url>http://repo.spring.io/libs-snapshot</url>
</repository> </repository>
</repositories> </repositories>
<pluginRepositories> <pluginRepositories>
<pluginRepository> <pluginRepository>
<id>spring-plugins-release</id> <id>spring-plugins-release</id>

View File

@@ -7,7 +7,7 @@ Import-Package:
Export-Template: Export-Template:
org.springframework.data.mongodb.crossstore.*;version="${project.version}" org.springframework.data.mongodb.crossstore.*;version="${project.version}"
Import-Template: Import-Template:
com.mongodb.*;version="${mongo:[=.=.=,+1.0.0)}", com.mongodb.*;version="${mongo.osgi:[=.=.=,+1.0.0)}",
javax.persistence.*;version="${jpa:[=.=.=,+1.0.0)}", javax.persistence.*;version="${jpa:[=.=.=,+1.0.0)}",
org.aspectj.*;version="${aspectj:[1.0.0, 2.0.0)}", org.aspectj.*;version="${aspectj:[1.0.0, 2.0.0)}",
org.bson.*;version="0", org.bson.*;version="0",

View File

@@ -5,5 +5,5 @@ Bundle-ManifestVersion: 2
Import-Package: Import-Package:
sun.reflect;version="0";resolution:=optional sun.reflect;version="0";resolution:=optional
Import-Template: Import-Template:
com.mongodb.*;version="${mongo:[=.=.=,+1.0.0)}", com.mongodb.*;version="${mongo.osgi:[=.=.=,+1.0.0)}",
org.apache.log4j.*;version="${log4j:[=.=.=,+1.0.0)}" org.apache.log4j.*;version="${log4j:[=.=.=,+1.0.0)}"

View File

@@ -23,11 +23,15 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.mongodb.UncategorizedMongoDbException; import org.springframework.data.mongodb.UncategorizedMongoDbException;
import com.mongodb.MongoCursorNotFoundException;
import com.mongodb.MongoException; import com.mongodb.MongoException;
import com.mongodb.MongoException.CursorNotFound; import com.mongodb.MongoException.CursorNotFound;
import com.mongodb.MongoException.DuplicateKey; import com.mongodb.MongoException.DuplicateKey;
import com.mongodb.MongoException.Network; import com.mongodb.MongoException.Network;
import com.mongodb.MongoInternalException; import com.mongodb.MongoInternalException;
import com.mongodb.MongoServerSelectionException;
import com.mongodb.MongoSocketException;
import com.mongodb.MongoTimeoutException;
/** /**
* Simple {@link PersistenceExceptionTranslator} for Mongo. Convert the given runtime exception to an appropriate * Simple {@link PersistenceExceptionTranslator} for Mongo. Convert the given runtime exception to an appropriate
@@ -47,21 +51,23 @@ public class MongoExceptionTranslator implements PersistenceExceptionTranslator
// Check for well-known MongoException subclasses. // Check for well-known MongoException subclasses.
// All other MongoExceptions if (ex instanceof DuplicateKey || ex instanceof DuplicateKeyException) {
if (ex instanceof DuplicateKey) {
return new DuplicateKeyException(ex.getMessage(), ex); return new DuplicateKeyException(ex.getMessage(), ex);
} }
if (ex instanceof Network) { if (ex instanceof Network || ex instanceof MongoSocketException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex); return new DataAccessResourceFailureException(ex.getMessage(), ex);
} }
if (ex instanceof CursorNotFound) { if (ex instanceof CursorNotFound || ex instanceof MongoCursorNotFoundException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex); return new DataAccessResourceFailureException(ex.getMessage(), ex);
} }
// Driver 2.12 throws this to indicate connection problems. String comparison to avoid hard dependency if (ex instanceof MongoServerSelectionException) {
if (ex.getClass().getName().equals("com.mongodb.MongoServerSelectionException")) { return new DataAccessResourceFailureException(ex.getMessage(), ex);
}
if (ex instanceof MongoTimeoutException) {
return new DataAccessResourceFailureException(ex.getMessage(), ex); return new DataAccessResourceFailureException(ex.getMessage(), ex);
} }
@@ -69,6 +75,7 @@ public class MongoExceptionTranslator implements PersistenceExceptionTranslator
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex); return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
} }
// All other MongoExceptions
if (ex instanceof MongoException) { if (ex instanceof MongoException) {
int code = ((MongoException) ex).getCode(); int code = ((MongoException) ex).getCode();

View File

@@ -8,7 +8,7 @@ Export-Template:
org.springframework.data.mongodb.*;version="${project.version}" org.springframework.data.mongodb.*;version="${project.version}"
Import-Template: Import-Template:
com.google.common.base.*;version="[11.0.0,14.0.0)";resolution:=optional, com.google.common.base.*;version="[11.0.0,14.0.0)";resolution:=optional,
com.mongodb.*;version="${mongo:[=.=.=,+1.0.0)}", com.mongodb.*;version="${mongo.osgi:[=.=.=,+1.0.0)}",
com.mysema.query.*;version="[2.1.1, 3.0.0)";resolution:=optional, com.mysema.query.*;version="[2.1.1, 3.0.0)";resolution:=optional,
javax.annotation.processing.*;version="0", javax.annotation.processing.*;version="0",
javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional, javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional,