Skip to content

Commit ed55d48

Browse files
committed
DATAMONGO-858 - Polishing.
Moved to use the newly introduced geo types from Spring Data Commons. Adde deprecation warning suppression everywhere else. Adapted Sonargraph architecture description file and split up namespace registration into repository specific stuff and everything else.
1 parent d5ed4e0 commit ed55d48

40 files changed

+284
-147
lines changed

spring-data-mongodb/Spring Data MongoDB.sonargraph

+26-20
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@
55
<element type="IncludeTypePattern" name="org.springframework.data.mongodb.**"/>
66
</element>
77
<architecture>
8-
<element type="Layer" name="Config">
9-
<element type="TypeFilter" name="Assignment">
10-
<element type="WeakTypePattern" name="**.config.**"/>
11-
</element>
12-
<dependency toName="Project|spring-data-mongodb::Layer|Core" type="AllowedDependency"/>
13-
<dependency toName="Project|spring-data-mongodb::Layer|GridFS" type="AllowedDependency"/>
14-
<dependency toName="Project|spring-data-mongodb::Layer|Monitoring" type="AllowedDependency"/>
15-
<dependency toName="Project|spring-data-mongodb::Layer|Repositories" type="AllowedDependency"/>
16-
</element>
178
<element type="Layer" name="Repositories">
189
<element type="TypeFilter" name="Assignment">
1910
<element type="IncludeTypePattern" name="**.repository.**"/>
@@ -40,10 +31,20 @@
4031
<element type="TypeFilter" name="Assignment">
4132
<element type="IncludeTypePattern" name="**.config.**"/>
4233
</element>
34+
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping" type="AllowedDependency"/>
4335
<dependency toName="Project|spring-data-mongodb::Layer|Repositories::Subsystem|Implementation" type="AllowedDependency"/>
4436
</element>
37+
<dependency toName="Project|spring-data-mongodb::Layer|Config" type="AllowedDependency"/>
4538
<dependency toName="Project|spring-data-mongodb::Layer|Core" type="AllowedDependency"/>
4639
</element>
40+
<element type="Layer" name="Config">
41+
<element type="TypeFilter" name="Assignment">
42+
<element type="WeakTypePattern" name="**.config.**"/>
43+
</element>
44+
<dependency toName="Project|spring-data-mongodb::Layer|Core" type="AllowedDependency"/>
45+
<dependency toName="Project|spring-data-mongodb::Layer|GridFS" type="AllowedDependency"/>
46+
<dependency toName="Project|spring-data-mongodb::Layer|Monitoring" type="AllowedDependency"/>
47+
</element>
4748
<element type="Layer" name="Monitoring">
4849
<element type="TypeFilter" name="Assignment">
4950
<element type="IncludeTypePattern" name="**.monitor.**"/>
@@ -57,41 +58,39 @@
5758
<dependency toName="Project|spring-data-mongodb::Layer|Core" type="AllowedDependency"/>
5859
</element>
5960
<element type="Layer" name="Core">
60-
<element type="TypeFilter" name="Assignment">
61-
<element type="IncludeTypePattern" name="**.core.**"/>
62-
</element>
61+
<element type="TypeFilter" name="Assignment"/>
6362
<element type="Subsystem" name="Mapping">
6463
<element type="TypeFilter" name="Assignment">
65-
<element type="IncludeTypePattern" name="**.mapping.**"/>
64+
<element type="IncludeTypePattern" name="**.core.mapping.**"/>
6665
</element>
6766
</element>
6867
<element type="Subsystem" name="Geospatial">
6968
<element type="TypeFilter" name="Assignment">
70-
<element type="IncludeTypePattern" name="**.geo.**"/>
69+
<element type="IncludeTypePattern" name="**.core.geo.**"/>
7170
</element>
72-
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping" type="AllowedDependency"/>
7371
</element>
7472
<element type="Subsystem" name="Query">
7573
<element type="TypeFilter" name="Assignment">
76-
<element type="IncludeTypePattern" name="**.query.**"/>
74+
<element type="IncludeTypePattern" name="**.core.query.**"/>
7775
</element>
7876
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Geospatial" type="AllowedDependency"/>
7977
</element>
8078
<element type="Subsystem" name="Conversion">
8179
<element type="TypeFilter" name="Assignment">
82-
<element type="IncludeTypePattern" name="**.convert.**"/>
80+
<element type="IncludeTypePattern" name="**.core.convert.**"/>
8381
</element>
82+
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Geospatial" type="AllowedDependency"/>
8483
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping" type="AllowedDependency"/>
8584
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Query" type="AllowedDependency"/>
8685
</element>
8786
<element type="Subsystem" name="SpEL">
8887
<element type="TypeFilter" name="Assignment">
89-
<element type="IncludeTypePattern" name="**.spel.**"/>
88+
<element type="IncludeTypePattern" name="**.core.spel.**"/>
9089
</element>
9190
</element>
9291
<element type="Subsystem" name="Aggregation">
9392
<element type="TypeFilter" name="Assignment">
94-
<element type="IncludeTypePattern" name="**.aggregation.**"/>
93+
<element type="IncludeTypePattern" name="**.core.aggregation.**"/>
9594
</element>
9695
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Conversion" type="AllowedDependency"/>
9796
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping" type="AllowedDependency"/>
@@ -100,7 +99,7 @@
10099
</element>
101100
<element type="Subsystem" name="Index">
102101
<element type="TypeFilter" name="Assignment">
103-
<element type="IncludeTypePattern" name="**.index.**"/>
102+
<element type="IncludeTypePattern" name="**.core.index.**"/>
104103
</element>
105104
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping" type="AllowedDependency"/>
106105
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Query" type="AllowedDependency"/>
@@ -116,6 +115,13 @@
116115
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Mapping" type="AllowedDependency"/>
117116
<dependency toName="Project|spring-data-mongodb::Layer|Core::Subsystem|Query" type="AllowedDependency"/>
118117
</element>
118+
<element type="Subsystem" name="Util">
119+
<element type="TypeFilter" name="Assignment">
120+
<element type="IncludeTypePattern" name="**.util.**"/>
121+
</element>
122+
<stereotype name="Unrestricted"/>
123+
<stereotype name="Public"/>
124+
</element>
119125
</element>
120126
<element type="Subsystem" name="API">
121127
<element type="TypeFilter" name="Assignment">

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2011-2013 the original author or authors.
2+
* Copyright 2011-2014 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,9 +16,6 @@
1616
package org.springframework.data.mongodb.config;
1717

1818
import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
19-
import org.springframework.data.mongodb.repository.config.MongoRepositoryConfigurationExtension;
20-
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
21-
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
2219

2320
/**
2421
* {@link org.springframework.beans.factory.xml.NamespaceHandler} for Mongo DB configuration.
@@ -34,10 +31,6 @@ public class MongoNamespaceHandler extends NamespaceHandlerSupport {
3431
*/
3532
public void init() {
3633

37-
RepositoryConfigurationExtension extension = new MongoRepositoryConfigurationExtension();
38-
RepositoryBeanDefinitionParser repositoryBeanDefinitionParser = new RepositoryBeanDefinitionParser(extension);
39-
40-
registerBeanDefinitionParser("repositories", repositoryBeanDefinitionParser);
4134
registerBeanDefinitionParser("mapping-converter", new MappingMongoConverterParser());
4235
registerBeanDefinitionParser("mongo", new MongoParser());
4336
registerBeanDefinitionParser("db-factory", new MongoDbFactoryParser());

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* @author Christoph Strobl
5353
* @author Thomas Darimont
5454
*/
55+
@SuppressWarnings("deprecation")
5556
public interface MongoOperations {
5657

5758
/**
@@ -414,7 +415,7 @@ <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, Strin
414415
MapReduceOptions mapReduceOptions, Class<T> entityClass);
415416

416417
/**
417-
* Returns {@link GeoResult} for all entities matching the given {@link NearQuery}. Will consider entity mapping
418+
* Returns {@link GeoResults} for all entities matching the given {@link NearQuery}. Will consider entity mapping
418419
* information to determine the collection the query is ran against.
419420
*
420421
* @param near must not be {@literal null}.
@@ -424,7 +425,7 @@ <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, Strin
424425
<T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass);
425426

426427
/**
427-
* Returns {@link GeoResult} for all entities matching the given {@link NearQuery}.
428+
* Returns {@link GeoResults} for all entities matching the given {@link NearQuery}.
428429
*
429430
* @param near must not be {@literal null}.
430431
* @param entityClass must not be {@literal null}.

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

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
* @author Chuong Ngo
131131
* @author Christoph Strobl
132132
*/
133+
@SuppressWarnings("deprecation")
133134
public class MongoTemplate implements MongoOperations, ApplicationContextAware {
134135

135136
private static final Logger LOGGER = LoggerFactory.getLogger(MongoTemplate.class);

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public CustomConversions(List<?> converters) {
106106
toRegister.add(URLToStringConverter.INSTANCE);
107107
toRegister.add(StringToURLConverter.INSTANCE);
108108
toRegister.add(DBObjectToStringConverter.INSTANCE);
109+
109110
toRegister.addAll(JodaTimeConverters.getConvertersToRegister());
110-
111111
toRegister.addAll(GeoConverters.getConvertersToRegister());
112112

113113
for (Object c : toRegister) {

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

+1
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public BasicDBList convert(Polygon source) {
291291

292292
List<Point> points = source.getPoints();
293293
List<List<Double>> pointTuples = new ArrayList<List<Double>>(points.size());
294+
294295
for (Point point : points) {
295296
pointTuples.add(toList(point));
296297
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* @author Thomas Darimont
3131
* @since 1.5
3232
*/
33+
@SuppressWarnings("deprecation")
3334
public class Sphere implements Shape {
3435

3536
public static final String COMMAND = "$centerSphere";

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

+42-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
import java.util.regex.Pattern;
2626

2727
import org.bson.BSON;
28+
import org.springframework.data.geo.Box;
2829
import org.springframework.data.geo.Circle;
2930
import org.springframework.data.geo.Point;
31+
import org.springframework.data.geo.Polygon;
3032
import org.springframework.data.geo.Shape;
3133
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
32-
import org.springframework.data.mongodb.core.convert.GeoCommandUtils;
3334
import org.springframework.data.mongodb.core.geo.Sphere;
3435
import org.springframework.util.Assert;
3536
import org.springframework.util.ObjectUtils;
@@ -385,7 +386,7 @@ private Pattern toPattern(String regex, String options) {
385386
*/
386387
public Criteria withinSphere(Circle circle) {
387388
Assert.notNull(circle);
388-
criteria.put("$within", GeoCommandUtils.INSTANCE.wrapInCommand(new Sphere(circle)));
389+
criteria.put("$within", wrapInCommand(new Sphere(circle)));
389390
return this;
390391
}
391392

@@ -399,7 +400,7 @@ public Criteria withinSphere(Circle circle) {
399400
@Deprecated
400401
public Criteria withinSphere(org.springframework.data.mongodb.core.geo.Circle circle) {
401402
Assert.notNull(circle);
402-
criteria.put("$within", GeoCommandUtils.INSTANCE.wrapInCommand(new Sphere(circle)));
403+
criteria.put("$within", wrapInCommand(new Sphere(circle)));
403404
return this;
404405
}
405406

@@ -413,7 +414,7 @@ public Criteria withinSphere(org.springframework.data.mongodb.core.geo.Circle ci
413414
public Criteria within(Shape shape) {
414415

415416
Assert.notNull(shape);
416-
criteria.put("$within", GeoCommandUtils.INSTANCE.wrapInCommand(shape));
417+
criteria.put("$within", wrapInCommand(shape));
417418
return this;
418419
}
419420

@@ -659,6 +660,43 @@ private boolean isEqual(Object left, Object right) {
659660
return ObjectUtils.nullSafeEquals(left, right);
660661
}
661662

663+
/**
664+
* Wraps the given {@link Shape} in an appropriate MongoDB command.
665+
*
666+
* @param shape must not be {@literal null}.
667+
* @return
668+
*/
669+
private DBObject wrapInCommand(Shape shape) {
670+
671+
Assert.notNull(shape, "Shape must not be null!");
672+
673+
return new BasicDBObject(getCommand(shape), shape);
674+
}
675+
676+
/**
677+
* Returns the MongoDB command for the given {@link Shape}.
678+
*
679+
* @param shape must not be {@literal null}.
680+
* @return
681+
*/
682+
@SuppressWarnings("deprecation")
683+
private String getCommand(Shape shape) {
684+
685+
Assert.notNull(shape, "Shape must not be null!");
686+
687+
if (shape instanceof Box) {
688+
return org.springframework.data.mongodb.core.geo.Box.COMMAND;
689+
} else if (shape instanceof Circle || shape instanceof org.springframework.data.mongodb.core.geo.Circle) {
690+
return org.springframework.data.mongodb.core.geo.Circle.COMMAND;
691+
} else if (shape instanceof Polygon) {
692+
return org.springframework.data.mongodb.core.geo.Polygon.COMMAND;
693+
} else if (shape instanceof Sphere) {
694+
return org.springframework.data.mongodb.core.geo.Sphere.COMMAND;
695+
}
696+
697+
throw new IllegalArgumentException("Unknown shape: " + shape);
698+
}
699+
662700
/*
663701
* (non-Javadoc)
664702
* @see java.lang.Object#hashCode()

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

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ public Integer getSkip() {
343343
*
344344
* @return
345345
*/
346+
@SuppressWarnings("deprecation")
346347
public DBObject toDBObject() {
347348

348349
BasicDBObject dbObject = new BasicDBObject();

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/Near.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1+
/*
2+
* Copyright 2011-2014 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+
* http://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+
*/
116
package org.springframework.data.mongodb.repository;
217

318
import java.lang.annotation.Documented;
419
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
521
import java.lang.annotation.RetentionPolicy;
622
import java.lang.annotation.Target;
723

8-
import java.lang.annotation.Retention;
9-
10-
import org.springframework.data.mongodb.core.geo.Distance;
24+
import org.springframework.data.geo.Distance;
25+
import org.springframework.data.geo.Point;
1126

1227
/**
1328
* Annotation to be used for disambiguing method parameters that shall be used to trigger geo near queries. By default
@@ -20,5 +35,4 @@
2035
@Retention(RetentionPolicy.RUNTIME)
2136
@Target(ElementType.PARAMETER)
2237
public @interface Near {
23-
2438
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2014 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+
* http://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+
package org.springframework.data.mongodb.repository.config;
17+
18+
import org.springframework.beans.factory.xml.NamespaceHandler;
19+
import org.springframework.data.mongodb.config.MongoNamespaceHandler;
20+
import org.springframework.data.repository.config.RepositoryBeanDefinitionParser;
21+
import org.springframework.data.repository.config.RepositoryConfigurationExtension;
22+
23+
/**
24+
* {@link NamespaceHandler} to register repository configuration.
25+
*
26+
* @author Oliver Gierke
27+
*/
28+
public class MongoRepositoryConfigNamespaceHandler extends MongoNamespaceHandler {
29+
30+
/*
31+
* (non-Javadoc)
32+
* @see org.springframework.data.mongodb.config.MongoNamespaceHandler#init()
33+
*/
34+
@Override
35+
public void init() {
36+
37+
RepositoryConfigurationExtension extension = new MongoRepositoryConfigurationExtension();
38+
RepositoryBeanDefinitionParser repositoryBeanDefinitionParser = new RepositoryBeanDefinitionParser(extension);
39+
40+
registerBeanDefinitionParser("repositories", repositoryBeanDefinitionParser);
41+
42+
super.init();
43+
}
44+
}

0 commit comments

Comments
 (0)