Skip to content

Commit b2c0d1d

Browse files
committed
Merge pull request #19960 from christophstrobl
* pr/19960: Polish "Upgrade to MongoDB Java Driver 4.0 beta1" Upgrade to MongoDB Java Driver 4.0 beta1 Closes gh-19960
2 parents cf473ee + c4daff7 commit b2c0d1d

29 files changed

+340
-385
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ dependencies {
8383
optional("org.influxdb:influxdb-java")
8484
optional("org.jolokia:jolokia-core")
8585
optional("org.liquibase:liquibase-core")
86-
optional("org.mongodb:mongodb-driver-async")
8786
optional("org.mongodb:mongodb-driver-reactivestreams")
87+
optional("org.mongodb:mongodb-driver-sync")
8888
optional("org.springframework:spring-jdbc")
8989
optional("org.springframework:spring-jms")
9090
optional("org.springframework:spring-messaging")

spring-boot-project/spring-boot-actuator/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ dependencies {
4343
optional("org.hibernate.validator:hibernate-validator")
4444
optional("org.influxdb:influxdb-java")
4545
optional("org.liquibase:liquibase-core")
46-
optional("org.mongodb:mongodb-driver-async")
4746
optional("org.mongodb:mongodb-driver-reactivestreams")
47+
optional("org.mongodb:mongodb-driver-sync")
4848
optional("org.springframework:spring-jdbc")
4949
optional("org.springframework:spring-messaging")
5050
optional("org.springframework:spring-webflux")

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ dependencies {
9595
optional("org.jooq:jooq")
9696
optional("org.liquibase:liquibase-core")
9797
optional("org.messaginghub:pooled-jms")
98-
optional("org.mongodb:mongodb-driver-async")
9998
optional("org.mongodb:mongodb-driver-reactivestreams")
99+
optional("org.mongodb:mongodb-driver-sync")
100100
optional("org.quartz-scheduler:quartz")
101101
optional("org.springframework:spring-jdbc")
102102
optional("org.springframework.integration:spring-integration-core")

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoClientDependsOnBeanFactoryPostProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.data.mongo;
1818

19-
import com.mongodb.MongoClient;
19+
import com.mongodb.client.MongoClient;
2020

2121
import org.springframework.beans.factory.config.BeanDefinition;
2222
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.data.mongo;
1818

19-
import com.mongodb.MongoClient;
19+
import com.mongodb.client.MongoClient;
2020

2121
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2222
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -48,9 +48,10 @@
4848
* @since 1.1.0
4949
*/
5050
@Configuration(proxyBeanMethods = false)
51-
@ConditionalOnClass({ MongoClient.class, com.mongodb.client.MongoClient.class, MongoTemplate.class })
51+
@ConditionalOnClass({ MongoClient.class, MongoTemplate.class })
5252
@EnableConfigurationProperties(MongoProperties.class)
53-
@Import({ MongoDataConfiguration.class, MongoDbFactoryConfiguration.class, MongoDbFactoryDependentConfiguration.class })
53+
@Import({ MongoDataConfiguration.class, MongoDatabaseFactoryConfiguration.class,
54+
MongoDatabaseFactoryDependentConfiguration.class })
5455
@AutoConfigureAfter(MongoAutoConfiguration.class)
5556
public class MongoDataAutoConfiguration {
5657

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.data.mongo;
18+
19+
import com.mongodb.client.MongoClient;
20+
21+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
22+
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
23+
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
24+
import org.springframework.context.annotation.Bean;
25+
import org.springframework.context.annotation.Configuration;
26+
import org.springframework.data.mongodb.MongoDatabaseFactory;
27+
import org.springframework.data.mongodb.core.MongoDatabaseFactorySupport;
28+
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
29+
30+
/**
31+
* Configuration for a {@link MongoDatabaseFactory}.
32+
*
33+
* @author Andy Wilkinson
34+
* @author Stephane Nicoll
35+
*/
36+
@Configuration(proxyBeanMethods = false)
37+
@ConditionalOnMissingBean(MongoDatabaseFactory.class)
38+
@ConditionalOnSingleCandidate(MongoClient.class)
39+
class MongoDatabaseFactoryConfiguration {
40+
41+
@Bean
42+
MongoDatabaseFactorySupport<?> mongoDatabaseFactory(MongoClient mongoClient, MongoProperties properties) {
43+
return new SimpleMongoClientDatabaseFactory(mongoClient, properties.getMongoClientDatabase());
44+
}
45+
46+
}
Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.autoconfigure.data.mongo;
1818

1919
import com.mongodb.ClientSessionOptions;
20-
import com.mongodb.DB;
2120
import com.mongodb.client.ClientSession;
2221
import com.mongodb.client.MongoDatabase;
2322

@@ -28,7 +27,7 @@
2827
import org.springframework.context.annotation.Configuration;
2928
import org.springframework.dao.DataAccessException;
3029
import org.springframework.dao.support.PersistenceExceptionTranslator;
31-
import org.springframework.data.mongodb.MongoDbFactory;
30+
import org.springframework.data.mongodb.MongoDatabaseFactory;
3231
import org.springframework.data.mongodb.core.MongoOperations;
3332
import org.springframework.data.mongodb.core.MongoTemplate;
3433
import org.springframework.data.mongodb.core.convert.DbRefResolver;
@@ -43,29 +42,29 @@
4342
import org.springframework.util.StringUtils;
4443

4544
/**
46-
* Configuration for Mongo-related beans that depend on a {@link MongoDbFactory}.
45+
* Configuration for Mongo-related beans that depend on a {@link MongoDatabaseFactory}.
4746
*
4847
* @author Andy Wilkinson
4948
*/
5049
@Configuration(proxyBeanMethods = false)
51-
@ConditionalOnBean(MongoDbFactory.class)
52-
class MongoDbFactoryDependentConfiguration {
50+
@ConditionalOnBean(MongoDatabaseFactory.class)
51+
class MongoDatabaseFactoryDependentConfiguration {
5352

5453
private final MongoProperties properties;
5554

56-
MongoDbFactoryDependentConfiguration(MongoProperties properties) {
55+
MongoDatabaseFactoryDependentConfiguration(MongoProperties properties) {
5756
this.properties = properties;
5857
}
5958

6059
@Bean
6160
@ConditionalOnMissingBean(MongoOperations.class)
62-
MongoTemplate mongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter converter) {
63-
return new MongoTemplate(mongoDbFactory, converter);
61+
MongoTemplate mongoTemplate(MongoDatabaseFactory factory, MongoConverter converter) {
62+
return new MongoTemplate(factory, converter);
6463
}
6564

6665
@Bean
6766
@ConditionalOnMissingBean(MongoConverter.class)
68-
MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context,
67+
MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory factory, MongoMappingContext context,
6968
MongoCustomConversions conversions) {
7069
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
7170
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
@@ -75,61 +74,55 @@ MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMapping
7574

7675
@Bean
7776
@ConditionalOnMissingBean(GridFsOperations.class)
78-
GridFsTemplate gridFsTemplate(MongoDbFactory mongoDbFactory, MongoTemplate mongoTemplate) {
79-
return new GridFsTemplate(new GridFsMongoDbFactory(mongoDbFactory, this.properties),
77+
GridFsTemplate gridFsTemplate(MongoDatabaseFactory factory, MongoTemplate mongoTemplate) {
78+
return new GridFsTemplate(new GridFsMongoDatabaseFactory(factory, this.properties),
8079
mongoTemplate.getConverter());
8180
}
8281

8382
/**
84-
* {@link MongoDbFactory} decorator to respect
83+
* {@link MongoDatabaseFactory} decorator to respect
8584
* {@link MongoProperties#getGridFsDatabase()} if set.
8685
*/
87-
static class GridFsMongoDbFactory implements MongoDbFactory {
86+
static class GridFsMongoDatabaseFactory implements MongoDatabaseFactory {
8887

89-
private final MongoDbFactory mongoDbFactory;
88+
private final MongoDatabaseFactory mongoDatabaseFactory;
9089

9190
private final MongoProperties properties;
9291

93-
GridFsMongoDbFactory(MongoDbFactory mongoDbFactory, MongoProperties properties) {
94-
Assert.notNull(mongoDbFactory, "MongoDbFactory must not be null");
92+
GridFsMongoDatabaseFactory(MongoDatabaseFactory mongoDatabaseFactory, MongoProperties properties) {
93+
Assert.notNull(mongoDatabaseFactory, "MongoDatabaseFactory must not be null");
9594
Assert.notNull(properties, "Properties must not be null");
96-
this.mongoDbFactory = mongoDbFactory;
95+
this.mongoDatabaseFactory = mongoDatabaseFactory;
9796
this.properties = properties;
9897
}
9998

10099
@Override
101-
public MongoDatabase getDb() throws DataAccessException {
100+
public MongoDatabase getMongoDatabase() throws DataAccessException {
102101
String gridFsDatabase = this.properties.getGridFsDatabase();
103102
if (StringUtils.hasText(gridFsDatabase)) {
104-
return this.mongoDbFactory.getDb(gridFsDatabase);
103+
return this.mongoDatabaseFactory.getMongoDatabase(gridFsDatabase);
105104
}
106-
return this.mongoDbFactory.getDb();
105+
return this.mongoDatabaseFactory.getMongoDatabase();
107106
}
108107

109108
@Override
110-
public MongoDatabase getDb(String dbName) throws DataAccessException {
111-
return this.mongoDbFactory.getDb(dbName);
109+
public MongoDatabase getMongoDatabase(String dbName) throws DataAccessException {
110+
return this.mongoDatabaseFactory.getMongoDatabase(dbName);
112111
}
113112

114113
@Override
115114
public PersistenceExceptionTranslator getExceptionTranslator() {
116-
return this.mongoDbFactory.getExceptionTranslator();
117-
}
118-
119-
@Override
120-
@Deprecated
121-
public DB getLegacyDb() {
122-
return this.mongoDbFactory.getLegacyDb();
115+
return this.mongoDatabaseFactory.getExceptionTranslator();
123116
}
124117

125118
@Override
126119
public ClientSession getSession(ClientSessionOptions options) {
127-
return this.mongoDbFactory.getSession(options);
120+
return this.mongoDatabaseFactory.getSession(options);
128121
}
129122

130123
@Override
131-
public MongoDbFactory withSession(ClientSession session) {
132-
return this.mongoDbFactory.withSession(session);
124+
public MongoDatabaseFactory withSession(ClientSession session) {
125+
return this.mongoDatabaseFactory.withSession(session);
133126
}
134127

135128
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoDbFactoryConfiguration.java

Lines changed: 0 additions & 82 deletions
This file was deleted.

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ public DefaultDataBufferFactory dataBufferFactory() {
9797

9898
@Bean
9999
@ConditionalOnMissingBean(ReactiveGridFsOperations.class)
100-
public ReactiveGridFsTemplate reactiveGridFsTemplate(ReactiveMongoDatabaseFactory reactiveMongoDbFactory,
100+
public ReactiveGridFsTemplate reactiveGridFsTemplate(ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory,
101101
MappingMongoConverter mappingMongoConverter, DataBufferFactory dataBufferFactory) {
102-
return new ReactiveGridFsTemplate(dataBufferFactory, reactiveMongoDbFactory, mappingMongoConverter, null);
102+
return new ReactiveGridFsTemplate(dataBufferFactory, reactiveMongoDatabaseFactory, mappingMongoConverter, null);
103103
}
104104

105105
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoRepositoriesAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.data.mongo;
1818

19-
import com.mongodb.MongoClient;
19+
import com.mongodb.client.MongoClient;
2020

2121
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2222
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

0 commit comments

Comments
 (0)