Browse Source

DATAMONGO-1317 - Assert compatibility with mongo-java-driver 3.2.

We now do a defensive check against the actual WObject of WriteConcern to avoid the IllegalStateException raised by the new java-driver in case _w is null or not an Integer. This allows us to run against recent 2.13, 2.14, 3.0, 3.1 and the latest 3.2.0.

Original pull request: #337.
1.7.x
Christoph Strobl 10 years ago committed by Oliver Gierke
parent
commit
704c130d94
  1. 14
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

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

@ -774,11 +774,17 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware { @@ -774,11 +774,17 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
protected WriteConcern prepareWriteConcern(MongoAction mongoAction) {
WriteConcern wc = writeConcernResolver.resolve(mongoAction);
return potentiallyForceAcknowledgedWrite(wc);
}
private WriteConcern potentiallyForceAcknowledgedWrite(WriteConcern wc) {
if (MongoClientVersion.isMongo3Driver()
&& ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)
&& (wc == null || wc.getW() < 1)) {
return WriteConcern.ACKNOWLEDGED;
if (ObjectUtils.nullSafeEquals(WriteResultChecking.EXCEPTION, writeResultChecking)
&& MongoClientVersion.isMongo3Driver()) {
if (wc == null || wc.getWObject() == null
|| (wc.getWObject() instanceof Number && ((Number) wc.getWObject()).intValue() < 1)) {
return WriteConcern.ACKNOWLEDGED;
}
}
return wc;
}

Loading…
Cancel
Save