Skip to content

Commit db9934c

Browse files
christophstroblmp911de
authored andcommitted
DATAMONGO-1643 - Replace references to Mongo by MongoClient.
Remove and replace usage of "mongo" by "mongoClient". This involves xsd schema, bean names, constructor and parameter types. This required some API changes as some server commands are no longer directly available through the api, but have to be invoked via runCommand. Also remove references to outdated API using Credentials and an authentication DB instead of MongoCredentials for authentication. Updated and removed (unused) tests; Altered documentation. Original pull request: spring-projects#451.
1 parent b567974 commit db9934c

File tree

86 files changed

+330
-2811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+330
-2811
lines changed

spring-data-mongodb-cross-store/src/test/resources/META-INF/spring/applicationContext.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
<mongo:mapping-converter/>
2121

2222
<!-- Mongo config -->
23-
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoClientFactoryBean">
23+
<bean id="mongoClient" class="org.springframework.data.mongodb.core.MongoClientFactoryBean">
2424
<property name="host" value="localhost"/>
2525
<property name="port" value="27017"/>
2626
</bean>
2727

2828
<bean id="mongoDbFactory" class="org.springframework.data.mongodb.core.SimpleMongoDbFactory">
29-
<constructor-arg name="mongo" ref="mongo"/>
29+
<constructor-arg name="mongoClient" ref="mongoClient"/>
3030
<constructor-arg name="databaseName" value="database"/>
3131
</bean>
3232

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/AbstractMongoConfiguration.java

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2016 the original author or authors.
2+
* Copyright 2011-2017 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

1818
import org.springframework.context.annotation.Bean;
1919
import org.springframework.context.annotation.Configuration;
20-
import org.springframework.data.authentication.UserCredentials;
2120
import org.springframework.data.mongodb.MongoDbFactory;
2221
import org.springframework.data.mongodb.core.MongoTemplate;
2322
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
@@ -26,7 +25,6 @@
2625
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
2726
import org.springframework.data.mongodb.core.mapping.Document;
2827

29-
import com.mongodb.Mongo;
3028
import com.mongodb.MongoClient;
3129

3230
/**
@@ -44,26 +42,13 @@
4442
public abstract class AbstractMongoConfiguration extends MongoConfigurationSupport {
4543

4644
/**
47-
* Return the name of the authentication database to use. Defaults to {@literal null} and will turn into the value
48-
* returned by {@link #getDatabaseName()} later on effectively.
49-
*
50-
* @return
51-
* @deprecated since 1.7. {@link MongoClient} should hold authentication data within
52-
* {@link MongoClient#getCredentialsList()}
53-
*/
54-
@Deprecated
55-
protected String getAuthenticationDatabaseName() {
56-
return null;
57-
}
58-
59-
/**
60-
* Return the {@link Mongo} instance to connect to. Annotate with {@link Bean} in case you want to expose a
61-
* {@link Mongo} instance to the {@link org.springframework.context.ApplicationContext}.
45+
* Return the {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
46+
* {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}.
6247
*
6348
* @return
6449
* @throws Exception
6550
*/
66-
public abstract Mongo mongo() throws Exception;
51+
public abstract MongoClient mongoClient() throws Exception;
6752

6853
/**
6954
* Creates a {@link MongoTemplate}.
@@ -77,8 +62,8 @@ public MongoTemplate mongoTemplate() throws Exception {
7762
}
7863

7964
/**
80-
* Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link Mongo} instance
81-
* configured in {@link #mongo()}.
65+
* Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link MongoClient}
66+
* instance configured in {@link #mongo()}.
8267
*
8368
* @see #mongo()
8469
* @see #mongoTemplate()
@@ -87,7 +72,7 @@ public MongoTemplate mongoTemplate() throws Exception {
8772
*/
8873
@Bean
8974
public MongoDbFactory mongoDbFactory() throws Exception {
90-
return new SimpleMongoDbFactory(mongo(), getDatabaseName(), getUserCredentials(), getAuthenticationDatabaseName());
75+
return new SimpleMongoDbFactory(mongoClient(), getDatabaseName());
9176
}
9277

9378
/**
@@ -107,19 +92,6 @@ protected String getMappingBasePackage() {
10792
return mappingBasePackage == null ? null : mappingBasePackage.getName();
10893
}
10994

110-
/**
111-
* Return {@link UserCredentials} to be used when connecting to the MongoDB instance or {@literal null} if none shall
112-
* be used.
113-
*
114-
* @return
115-
* @deprecated since 1.7. {@link MongoClient} should hold authentication data within
116-
* {@link MongoClient#getCredentialsList()}
117-
*/
118-
@Deprecated
119-
protected UserCredentials getUserCredentials() {
120-
return null;
121-
}
122-
12395
/**
12496
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
12597
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/BeanNames.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2014 the original author or authors.
2+
* Copyright 2011-2017 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.
@@ -21,13 +21,14 @@
2121
* @author Jon Brisbin
2222
* @author Oliver Gierke
2323
* @author Martin Baumgartner
24+
* @author Christoph Strobl
2425
*/
2526
public abstract class BeanNames {
2627

2728
public static final String MAPPING_CONTEXT_BEAN_NAME = "mongoMappingContext";
2829

2930
static final String INDEX_HELPER_BEAN_NAME = "indexCreationHelper";
30-
static final String MONGO_BEAN_NAME = "mongo";
31+
static final String MONGO_BEAN_NAME = "mongoClient";
3132
static final String DB_FACTORY_BEAN_NAME = "mongoDbFactory";
3233
static final String VALIDATING_EVENT_LISTENER_BEAN_NAME = "validatingMongoEventListener";
3334
static final String IS_NEW_STRATEGY_FACTORY_BEAN_NAME = "isNewStrategyFactory";

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoDbFactoryParser.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2015 by the original author(s).
2+
* Copyright 2011-2017 by the original author(s).
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.
@@ -30,7 +30,6 @@
3030
import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser;
3131
import org.springframework.beans.factory.xml.BeanDefinitionParser;
3232
import org.springframework.beans.factory.xml.ParserContext;
33-
import org.springframework.data.authentication.UserCredentials;
3433
import org.springframework.data.config.BeanComponentDefinitionBuilder;
3534
import org.springframework.data.mongodb.core.MongoClientFactoryBean;
3635
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
@@ -99,8 +98,6 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
9998
String mongoRef = element.getAttribute("mongo-ref");
10099
String dbname = element.getAttribute("dbname");
101100

102-
BeanDefinition userCredentials = getUserCredentialsBeanDefinition(element, parserContext);
103-
104101
// Defaulting
105102
if (StringUtils.hasText(mongoRef)) {
106103
dbFactoryBuilder.addConstructorArgReference(mongoRef);
@@ -109,8 +106,6 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
109106
}
110107

111108
dbFactoryBuilder.addConstructorArgValue(StringUtils.hasText(dbname) ? dbname : "db");
112-
dbFactoryBuilder.addConstructorArgValue(userCredentials);
113-
dbFactoryBuilder.addConstructorArgValue(element.getAttribute("authentication-dbname"));
114109

115110
BeanDefinitionBuilder writeConcernPropertyEditorBuilder = getWriteConcernPropertyEditorBuilder();
116111

@@ -138,28 +133,6 @@ private BeanDefinition registerMongoBeanDefinition(Element element, ParserContex
138133
return getSourceBeanDefinition(mongoBuilder, parserContext, element);
139134
}
140135

141-
/**
142-
* Returns a {@link BeanDefinition} for a {@link UserCredentials} object.
143-
*
144-
* @param element
145-
* @return the {@link BeanDefinition} or {@literal null} if neither username nor password given.
146-
*/
147-
private BeanDefinition getUserCredentialsBeanDefinition(Element element, ParserContext context) {
148-
149-
String username = element.getAttribute("username");
150-
String password = element.getAttribute("password");
151-
152-
if (!StringUtils.hasText(username) && !StringUtils.hasText(password)) {
153-
return null;
154-
}
155-
156-
BeanDefinitionBuilder userCredentialsBuilder = BeanDefinitionBuilder.genericBeanDefinition(UserCredentials.class);
157-
userCredentialsBuilder.addConstructorArgValue(StringUtils.hasText(username) ? username : null);
158-
userCredentialsBuilder.addConstructorArgValue(StringUtils.hasText(password) ? password : null);
159-
160-
return getSourceBeanDefinition(userCredentialsBuilder, context, element);
161-
}
162-
163136
/**
164137
* Creates a {@link BeanDefinition} for a {@link MongoURI} or {@link MongoClientURI} depending on configured
165138
* attributes. <br />
@@ -193,7 +166,7 @@ private BeanDefinition getMongoUri(Element element, ParserContext parserContext)
193166
parserContext.extractSource(element));
194167
}
195168

196-
Class<?> type = hasClientUri ? MongoClientURI.class : MongoURI.class;
169+
Class<?> type = MongoClientURI.class;
197170
String uri = hasClientUri ? element.getAttribute("client-uri") : element.getAttribute("uri");
198171

199172
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(type);

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoJmxParser.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011 the original author or authors.
2+
* Copyright 2011-2017 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.
@@ -26,12 +26,19 @@
2626
import org.springframework.util.StringUtils;
2727
import org.w3c.dom.Element;
2828

29+
/**
30+
* @author Mark Pollack
31+
* @author Thomas Risberg
32+
* @author John Brisbin
33+
* @author Oliver Gierke
34+
* @author Christoph Strobl
35+
*/
2936
public class MongoJmxParser implements BeanDefinitionParser {
3037

3138
public BeanDefinition parse(Element element, ParserContext parserContext) {
3239
String name = element.getAttribute("mongo-ref");
3340
if (!StringUtils.hasText(name)) {
34-
name = "mongo";
41+
name = BeanNames.MONGO_BEAN_NAME;
3542
}
3643
registerJmxComponents(name, element, parserContext);
3744
return null;

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoNamespaceHandler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2015 the original author or authors.
2+
* Copyright 2011-2017 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.
@@ -33,7 +33,6 @@ public class MongoNamespaceHandler extends NamespaceHandlerSupport {
3333
public void init() {
3434

3535
registerBeanDefinitionParser("mapping-converter", new MappingMongoConverterParser());
36-
registerBeanDefinitionParser("mongo", new MongoParser());
3736
registerBeanDefinitionParser("mongo-client", new MongoClientParser());
3837
registerBeanDefinitionParser("db-factory", new MongoDbFactoryParser());
3938
registerBeanDefinitionParser("jmx", new MongoJmxParser());

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoParser.java

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

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/config/MongoParsingUtils.java

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.beans.factory.support.ManagedMap;
2626
import org.springframework.beans.factory.xml.BeanDefinitionParser;
2727
import org.springframework.data.mongodb.core.MongoClientOptionsFactoryBean;
28-
import org.springframework.data.mongodb.core.MongoOptionsFactoryBean;
2928
import org.springframework.util.xml.DomUtils;
3029
import org.w3c.dom.Element;
3130

@@ -54,42 +53,6 @@ static void parseReplicaSet(Element element, BeanDefinitionBuilder mongoBuilder)
5453
setPropertyValue(mongoBuilder, element, "replica-set", "replicaSetSeeds");
5554
}
5655

57-
/**
58-
* Parses the {@code mongo:options} sub-element. Populates the given attribute factory with the proper attributes.
59-
*
60-
* @return true if parsing actually occured, {@literal false} otherwise
61-
*/
62-
static boolean parseMongoOptions(Element element, BeanDefinitionBuilder mongoBuilder) {
63-
64-
Element optionsElement = DomUtils.getChildElementByTagName(element, "options");
65-
66-
if (optionsElement == null) {
67-
return false;
68-
}
69-
70-
BeanDefinitionBuilder optionsDefBuilder = BeanDefinitionBuilder
71-
.genericBeanDefinition(MongoOptionsFactoryBean.class);
72-
73-
setPropertyValue(optionsDefBuilder, optionsElement, "connections-per-host", "connectionsPerHost");
74-
setPropertyValue(optionsDefBuilder, optionsElement, "threads-allowed-to-block-for-connection-multiplier",
75-
"threadsAllowedToBlockForConnectionMultiplier");
76-
setPropertyValue(optionsDefBuilder, optionsElement, "max-wait-time", "maxWaitTime");
77-
setPropertyValue(optionsDefBuilder, optionsElement, "connect-timeout", "connectTimeout");
78-
setPropertyValue(optionsDefBuilder, optionsElement, "socket-timeout", "socketTimeout");
79-
setPropertyValue(optionsDefBuilder, optionsElement, "socket-keep-alive", "socketKeepAlive");
80-
setPropertyValue(optionsDefBuilder, optionsElement, "auto-connect-retry", "autoConnectRetry");
81-
setPropertyValue(optionsDefBuilder, optionsElement, "max-auto-connect-retry-time", "maxAutoConnectRetryTime");
82-
setPropertyValue(optionsDefBuilder, optionsElement, "write-number", "writeNumber");
83-
setPropertyValue(optionsDefBuilder, optionsElement, "write-timeout", "writeTimeout");
84-
setPropertyValue(optionsDefBuilder, optionsElement, "write-fsync", "writeFsync");
85-
setPropertyValue(optionsDefBuilder, optionsElement, "slave-ok", "slaveOk");
86-
setPropertyValue(optionsDefBuilder, optionsElement, "ssl", "ssl");
87-
setPropertyReference(optionsDefBuilder, optionsElement, "ssl-socket-factory-ref", "sslSocketFactory");
88-
89-
mongoBuilder.addPropertyValue("mongoOptions", optionsDefBuilder.getBeanDefinition());
90-
return true;
91-
}
92-
9356
/**
9457
* Parses the {@code mongo:client-options} sub-element. Populates the given attribute factory with the proper
9558
* attributes.

0 commit comments

Comments
 (0)