Skip to content

Commit 566f9a8

Browse files
committed
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.
1 parent 89a42c5 commit 566f9a8

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

pom.xml

+31-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<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">
33

44
<modelVersion>4.0.0</modelVersion>
5-
5+
66
<groupId>org.springframework.data</groupId>
77
<artifactId>spring-data-mongodb-parent</artifactId>
88
<version>1.6.0.BUILD-SNAPSHOT</version>
@@ -31,8 +31,9 @@
3131
<dist.id>spring-data-mongodb</dist.id>
3232
<springdata.commons>1.9.0.BUILD-SNAPSHOT</springdata.commons>
3333
<mongo>2.12.1</mongo>
34+
<mongo.osgi>2.12.1</mongo.osgi>
3435
</properties>
35-
36+
3637
<developers>
3738
<developer>
3839
<id>ogierke</id>
@@ -104,10 +105,35 @@
104105

105106
<profiles>
106107
<profile>
108+
107109
<id>mongo-next</id>
108110
<properties>
109-
<mongo>2.12.0</mongo>
111+
<mongo>2.12.3-SNAPSHOT</mongo>
110112
</properties>
113+
114+
<repositories>
115+
<repository>
116+
<id>mongo-snapshots</id>
117+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
118+
</repository>
119+
</repositories>
120+
121+
</profile>
122+
123+
<profile>
124+
125+
<id>mongo-3-next</id>
126+
<properties>
127+
<mongo>3.0.0-SNAPSHOT</mongo>
128+
</properties>
129+
130+
<repositories>
131+
<repository>
132+
<id>mongo-snapshots</id>
133+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
134+
</repository>
135+
</repositories>
136+
111137
</profile>
112138
</profiles>
113139

@@ -119,14 +145,14 @@
119145
<version>${mongo}</version>
120146
</dependency>
121147
</dependencies>
122-
148+
123149
<repositories>
124150
<repository>
125151
<id>spring-libs-snapshot</id>
126152
<url>http://repo.spring.io/libs-snapshot</url>
127153
</repository>
128154
</repositories>
129-
155+
130156
<pluginRepositories>
131157
<pluginRepository>
132158
<id>spring-plugins-release</id>

spring-data-mongodb-cross-store/template.mf

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Import-Package:
77
Export-Template:
88
org.springframework.data.mongodb.crossstore.*;version="${project.version}"
99
Import-Template:
10-
com.mongodb.*;version="${mongo:[=.=.=,+1.0.0)}",
10+
com.mongodb.*;version="${mongo.osgi:[=.=.=,+1.0.0)}",
1111
javax.persistence.*;version="${jpa:[=.=.=,+1.0.0)}",
1212
org.aspectj.*;version="${aspectj:[1.0.0, 2.0.0)}",
1313
org.bson.*;version="0",

spring-data-mongodb-log4j/template.mf

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ Bundle-ManifestVersion: 2
55
Import-Package:
66
sun.reflect;version="0";resolution:=optional
77
Import-Template:
8-
com.mongodb.*;version="${mongo:[=.=.=,+1.0.0)}",
8+
com.mongodb.*;version="${mongo.osgi:[=.=.=,+1.0.0)}",
99
org.apache.log4j.*;version="${log4j:[=.=.=,+1.0.0)}"

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoExceptionTranslator.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
import org.springframework.dao.support.PersistenceExceptionTranslator;
2424
import org.springframework.data.mongodb.UncategorizedMongoDbException;
2525

26+
import com.mongodb.MongoCursorNotFoundException;
2627
import com.mongodb.MongoException;
2728
import com.mongodb.MongoException.CursorNotFound;
2829
import com.mongodb.MongoException.DuplicateKey;
2930
import com.mongodb.MongoException.Network;
3031
import com.mongodb.MongoInternalException;
32+
import com.mongodb.MongoServerSelectionException;
33+
import com.mongodb.MongoSocketException;
34+
import com.mongodb.MongoTimeoutException;
3135

3236
/**
3337
* Simple {@link PersistenceExceptionTranslator} for Mongo. Convert the given runtime exception to an appropriate
@@ -47,28 +51,31 @@ public DataAccessException translateExceptionIfPossible(RuntimeException ex) {
4751

4852
// Check for well-known MongoException subclasses.
4953

50-
// All other MongoExceptions
51-
if (ex instanceof DuplicateKey) {
54+
if (ex instanceof DuplicateKey || ex instanceof DuplicateKeyException) {
5255
return new DuplicateKeyException(ex.getMessage(), ex);
5356
}
5457

55-
if (ex instanceof Network) {
58+
if (ex instanceof Network || ex instanceof MongoSocketException) {
5659
return new DataAccessResourceFailureException(ex.getMessage(), ex);
5760
}
5861

59-
if (ex instanceof CursorNotFound) {
62+
if (ex instanceof CursorNotFound || ex instanceof MongoCursorNotFoundException) {
6063
return new DataAccessResourceFailureException(ex.getMessage(), ex);
6164
}
6265

63-
// Driver 2.12 throws this to indicate connection problems. String comparison to avoid hard dependency
64-
if (ex.getClass().getName().equals("com.mongodb.MongoServerSelectionException")) {
66+
if (ex instanceof MongoServerSelectionException) {
67+
return new DataAccessResourceFailureException(ex.getMessage(), ex);
68+
}
69+
70+
if (ex instanceof MongoTimeoutException) {
6571
return new DataAccessResourceFailureException(ex.getMessage(), ex);
6672
}
6773

6874
if (ex instanceof MongoInternalException) {
6975
return new InvalidDataAccessResourceUsageException(ex.getMessage(), ex);
7076
}
7177

78+
// All other MongoExceptions
7279
if (ex instanceof MongoException) {
7380

7481
int code = ((MongoException) ex).getCode();

spring-data-mongodb/template.mf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Export-Template:
88
org.springframework.data.mongodb.*;version="${project.version}"
99
Import-Template:
1010
com.google.common.base.*;version="[11.0.0,14.0.0)";resolution:=optional,
11-
com.mongodb.*;version="${mongo:[=.=.=,+1.0.0)}",
11+
com.mongodb.*;version="${mongo.osgi:[=.=.=,+1.0.0)}",
1212
com.mysema.query.*;version="[2.1.1, 3.0.0)";resolution:=optional,
1313
javax.annotation.processing.*;version="0",
1414
javax.enterprise.*;version="${cdi:[=.=.=,+1.0.0)}";resolution:=optional,

0 commit comments

Comments
 (0)