Skip to content

Commit 19c8788

Browse files
committed
DATAMONGO-1643 - Polishing.
Fix documentation for namespace types. Remove unused ReflectiveDBCollectionInvoker. Simplify tests, align bean name to mongoClient. Remove injection of Mongo in favor of injecting MongoTemplate. Remove throws declaration from AbstractMongoConfiguration.mongoClient(). MongoClient creation does not throw checked exceptions so throwing an Exception is no longer required. Replace Mongo by MongoClient in reference documentation. Original pull request: spring-projects#451.
1 parent db9934c commit 19c8788

28 files changed

+127
-239
lines changed

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
/**
3131
* Base class for Spring Data MongoDB configuration using JavaConfig.
32-
*
32+
*
3333
* @author Mark Pollack
3434
* @author Oliver Gierke
3535
* @author Thomas Darimont
@@ -39,22 +39,21 @@
3939
* @see MongoConfigurationSupport
4040
*/
4141
@Configuration
42-
public abstract class AbstractMongoConfiguration extends MongoConfigurationSupport {
42+
public abstract class
43+
AbstractMongoConfiguration extends MongoConfigurationSupport {
4344

4445
/**
4546
* Return the {@link MongoClient} instance to connect to. Annotate with {@link Bean} in case you want to expose a
4647
* {@link MongoClient} instance to the {@link org.springframework.context.ApplicationContext}.
47-
*
48+
*
4849
* @return
49-
* @throws Exception
5050
*/
51-
public abstract MongoClient mongoClient() throws Exception;
51+
public abstract MongoClient mongoClient();
5252

5353
/**
5454
* Creates a {@link MongoTemplate}.
55-
*
55+
*
5656
* @return
57-
* @throws Exception
5857
*/
5958
@Bean
6059
public MongoTemplate mongoTemplate() throws Exception {
@@ -64,14 +63,13 @@ public MongoTemplate mongoTemplate() throws Exception {
6463
/**
6564
* Creates a {@link SimpleMongoDbFactory} to be used by the {@link MongoTemplate}. Will use the {@link MongoClient}
6665
* instance configured in {@link #mongo()}.
67-
*
68-
* @see #mongo()
66+
*
67+
* @see #mongoClient()
6968
* @see #mongoTemplate()
7069
* @return
71-
* @throws Exception
7270
*/
7371
@Bean
74-
public MongoDbFactory mongoDbFactory() throws Exception {
72+
public MongoDbFactory mongoDbFactory() {
7573
return new SimpleMongoDbFactory(mongoClient(), getDatabaseName());
7674
}
7775

@@ -95,7 +93,7 @@ protected String getMappingBasePackage() {
9593
/**
9694
* Creates a {@link MappingMongoConverter} using the configured {@link #mongoDbFactory()} and
9795
* {@link #mongoMappingContext()}. Will get {@link #customConversions()} applied.
98-
*
96+
*
9997
* @see #customConversions()
10098
* @see #mongoMappingContext()
10199
* @see #mongoDbFactory()

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-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.
@@ -62,7 +62,7 @@ public abstract class MongoConfigurationSupport {
6262

6363
/**
6464
* Return the name of the database to connect to.
65-
*
65+
*
6666
* @return must not be {@literal null}.
6767
*/
6868
protected abstract String getDatabaseName();
@@ -72,7 +72,7 @@ public abstract class MongoConfigurationSupport {
7272
* configuration class' (the concrete class, not this one here) by default. So if you have a
7373
* {@code com.acme.AppConfig} extending {@link MongoConfigurationSupport} the base package will be considered
7474
* {@code com.acme} unless the method is overridden to implement alternate behavior.
75-
*
75+
*
7676
* @return the base packages to scan for mapped {@link Document} classes or an empty collection to not enable scanning
7777
* for entities.
7878
* @since 1.10
@@ -85,8 +85,8 @@ protected Collection<String> getMappingBasePackages() {
8585

8686
/**
8787
* Creates a {@link MongoMappingContext} equipped with entity classes scanned from the mapping base package.
88-
*
89-
* @see #getMappingBasePackage()
88+
*
89+
* @see #getMappingBasePackages()
9090
* @return
9191
* @throws ClassNotFoundException
9292
*/

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

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

spring-data-mongodb/src/main/resources/org/springframework/data/mongodb/config/spring-mongo-2.0.xsd

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<xsd:schema xmlns="http://www.springframework.org/schema/data/mongo"
33
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
4-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54
xmlns:beans="http://www.springframework.org/schema/beans"
65
xmlns:tool="http://www.springframework.org/schema/tool"
7-
xmlns:context="http://www.springframework.org/schema/context"
86
xmlns:repository="http://www.springframework.org/schema/data/repository"
97
targetNamespace="http://www.springframework.org/schema/data/mongo"
108
elementFormDefault="qualified" attributeFormDefault="unqualified">
@@ -38,13 +36,13 @@ Defines a MongoDbFactory for connecting to a specific database
3836
<xsd:attribute name="id" type="xsd:string" use="optional">
3937
<xsd:annotation>
4038
<xsd:documentation><![CDATA[
41-
The name of the mongo definition (by default "mongoDbFactory").]]></xsd:documentation>
39+
The name of the MongoDbFactory definition (by default "mongoDbFactory").]]></xsd:documentation>
4240
</xsd:annotation>
4341
</xsd:attribute>
4442
<xsd:attribute name="mongo-ref" type="mongoRef" use="optional">
4543
<xsd:annotation>
4644
<xsd:documentation><![CDATA[
47-
The reference to a Mongo instance. If not configured a default com.mongodb.Mongo instance will be created.
45+
The reference to a MongoClient instance. If not configured a default com.mongodb.MongoClient instance will be created.
4846
]]>
4947
</xsd:documentation>
5048
</xsd:annotation>
@@ -120,7 +118,7 @@ The MongoClientURI string.]]></xsd:documentation>
120118
<xsd:annotation>
121119
<xsd:documentation><![CDATA[
122120
Top-level element that contains one or more custom converters to be used for mapping
123-
domain objects to and from Mongo's DBObject]]>
121+
domain objects to and from Mongo's Document]]>
124122
</xsd:documentation>
125123
</xsd:annotation>
126124
<xsd:complexType>
@@ -211,7 +209,7 @@ Defines a JMX Model MBeans for monitoring a MongoDB server'.
211209
<xsd:attribute name="mongo-ref" type="mongoRef" use="optional">
212210
<xsd:annotation>
213211
<xsd:documentation><![CDATA[
214-
The name of the Mongo object that determines what server to monitor. (by default "mongo").]]></xsd:documentation>
212+
The name of the MongoClient object that determines what server to monitor. (by default "mongoClient").]]></xsd:documentation>
215213
</xsd:annotation>
216214
</xsd:attribute>
217215
</xsd:complexType>
@@ -350,7 +348,7 @@ The Mongo driver options
350348
<xsd:attribute name="id" type="xsd:string" use="optional">
351349
<xsd:annotation>
352350
<xsd:documentation><![CDATA[
353-
The name of the mongo definition (by default "mongoClient").]]></xsd:documentation>
351+
The name of the MongoClient definition (by default "mongoClient").]]></xsd:documentation>
354352
</xsd:annotation>
355353
</xsd:attribute>
356354
<xsd:attribute name="port" type="xsd:string" use="optional">
@@ -406,7 +404,7 @@ The minimum number of connections per host.
406404
<xsd:attribute name="connections-per-host" type="xsd:string">
407405
<xsd:annotation>
408406
<xsd:documentation><![CDATA[
409-
The number of connections allowed per host. Will block if run out. Default is 10. System property MONGO.POOLSIZE can override.
407+
The number of connections allowed per host. Will block if run out. Default is 100.
410408
]]></xsd:documentation>
411409
</xsd:annotation>
412410
</xsd:attribute>
@@ -422,7 +420,7 @@ then 50 threads can block more than that and an exception will be thrown.
422420
<xsd:attribute name="max-wait-time" type="xsd:string">
423421
<xsd:annotation>
424422
<xsd:documentation><![CDATA[
425-
The max wait time of a blocking thread for a connection. Default is 12000 ms (2 minutes).
423+
The max wait time of a blocking thread for a connection. Default is 120000 ms (2 minutes).
426424
]]></xsd:documentation>
427425
</xsd:annotation>
428426
</xsd:attribute>
@@ -575,20 +573,20 @@ The SSLSocketFactory to use for the SSL connection. If none is configured here,
575573
<xsd:element name="template">
576574
<xsd:annotation>
577575
<xsd:documentation><![CDATA[
578-
Defines a MongoDbFactory for connecting to a specific database
576+
Defines a MongoTemplate.
579577
]]></xsd:documentation>
580578
</xsd:annotation>
581579
<xsd:complexType>
582580
<xsd:attribute name="id" type="xsd:string" use="optional">
583581
<xsd:annotation>
584582
<xsd:documentation><![CDATA[
585-
The name of the mongo definition (by default "mongoDbFactory").]]></xsd:documentation>
583+
The name of the MongoTemplate definition (by default "mongoTemplate").]]></xsd:documentation>
586584
</xsd:annotation>
587585
</xsd:attribute>
588586
<xsd:attribute name="converter-ref" type="converterRef" use="optional">
589587
<xsd:annotation>
590588
<xsd:documentation><![CDATA[
591-
The reference to a Mongoconverter instance.
589+
The reference to a MappingMongoConverter instance.
592590
]]>
593591
</xsd:documentation>
594592
<xsd:appinfo>
@@ -628,20 +626,20 @@ The reference to a Mongoconverter instance.
628626
<xsd:element name="gridFsTemplate">
629627
<xsd:annotation>
630628
<xsd:documentation><![CDATA[
631-
Defines a MongoDbFactory for connecting to a specific database
629+
Defines a GridFsTemplate.
632630
]]></xsd:documentation>
633631
</xsd:annotation>
634632
<xsd:complexType>
635633
<xsd:attribute name="id" type="xsd:string" use="optional">
636634
<xsd:annotation>
637635
<xsd:documentation><![CDATA[
638-
The name of the mongo definition (by default "mongoDbFactory").]]></xsd:documentation>
636+
The name of the GridFsTemplate definition (by default "gridFsTemplate").]]></xsd:documentation>
639637
</xsd:annotation>
640638
</xsd:attribute>
641639
<xsd:attribute name="converter-ref" type="converterRef" use="optional">
642640
<xsd:annotation>
643641
<xsd:documentation><![CDATA[
644-
The reference to a Mongoconverter instance.
642+
The reference to a MappingMongoConverter instance.
645643
]]>
646644
</xsd:documentation>
647645
<xsd:appinfo>

spring-data-mongodb/src/test/java/ConfigClassInDefaultPackage.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121

2222
/**
2323
* Sample configuration class in default package.
24-
*
24+
*
2525
* @author Oliver Gierke
2626
*/
2727
@Configuration
2828
public class ConfigClassInDefaultPackage extends AbstractMongoConfiguration {
2929

30-
/*
30+
/*
3131
* (non-Javadoc)
3232
* @see org.springframework.data.mongodb.config.AbstractMongoConfiguration#getDatabaseName()
3333
*/
@@ -36,12 +36,12 @@ protected String getDatabaseName() {
3636
return "default";
3737
}
3838

39-
/*
39+
/*
4040
* (non-Javadoc)
4141
* @see org.springframework.data.mongodb.config.AbstractMongoConfiguration#mongo()
4242
*/
4343
@Override
44-
public MongoClient mongoClient() throws Exception {
44+
public MongoClient mongoClient() {
4545
return new MongoClient();
4646
}
4747
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/AbstractIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected String getDatabaseName() {
5151
}
5252

5353
@Override
54-
public MongoClient mongoClient() throws Exception {
54+
public MongoClient mongoClient() {
5555
return new MongoClient();
5656
}
5757
}

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/AbstractMongoConfigurationUnitTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ protected String getDatabaseName() {
157157
}
158158

159159
@Override
160-
public MongoClient mongoClient() throws Exception {
160+
public MongoClient mongoClient() {
161161
return new MongoClient();
162162
}
163163

@@ -185,7 +185,7 @@ protected String getDatabaseName() {
185185
}
186186

187187
@Override
188-
public MongoClient mongoClient() throws Exception {
188+
public MongoClient mongoClient() {
189189
return new MongoClient();
190190
}
191191

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/config/AuditingViaJavaConfigRepositoriesTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected String getDatabaseName() {
6464
}
6565

6666
@Override
67-
public MongoClient mongoClient() throws Exception {
67+
public MongoClient mongoClient() {
6868
return new MongoClient();
6969
}
7070

@@ -119,7 +119,7 @@ static class SimpleConfigWithRepositories extends SimpleConfig {}
119119
static class SimpleConfig extends AbstractMongoConfiguration {
120120

121121
@Override
122-
public MongoClient mongoClient() throws Exception {
122+
public MongoClient mongoClient() {
123123
return new MongoClient();
124124
}
125125

0 commit comments

Comments
 (0)