Skip to content

Commit b2ce170

Browse files
mp911deodrotbohm
authored andcommitted
DATAMONGO-1373 - Allow usage of @AliasFor with mapping and indexing annotations.
We now support @AliasFor to build composed annotations with: @document, @id, @field, @indexed, @CompoundIndex, @GeoSpatialIndexed, @TextIndexed, @query, and @meta. Added missing license header to @field. Original pull request: spring-projects#347. Related tickets: DATACMNS-825.
1 parent 0b634f8 commit b2ce170

File tree

11 files changed

+336
-13
lines changed

11 files changed

+336
-13
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2015 the original author or authors.
2+
* Copyright 2010-2016 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.
@@ -27,8 +27,9 @@
2727
* @author Laurent Canet
2828
* @author Thomas Darimont
2929
* @author Christoph Strobl
30+
* @author Mark Paluch
3031
*/
31-
@Target(ElementType.FIELD)
32+
@Target({ElementType.FIELD, ElementType.ANNOTATION_TYPE})
3233
@Retention(RetentionPolicy.RUNTIME)
3334
public @interface GeoSpatialIndexed {
3435

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2016 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,10 +26,11 @@
2626
* all fields marked with {@link TextIndexed} are combined into one single index. <br />
2727
*
2828
* @author Christoph Strobl
29+
* @author Mark Paluch
2930
* @since 1.6
3031
*/
3132
@Documented
32-
@Target({ ElementType.FIELD })
33+
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
3334
@Retention(RetentionPolicy.RUNTIME)
3435
public @interface TextIndexed {
3536

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

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2011-2015 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.core.mapping;
217

318
import java.lang.annotation.Documented;

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2016 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.
@@ -25,10 +25,11 @@
2525

2626
/**
2727
* @author Christoph Strobl
28+
* @author Mark Paluch
2829
* @since 1.6
2930
*/
3031
@Retention(RetentionPolicy.RUNTIME)
31-
@Target(ElementType.METHOD)
32+
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
3233
@Documented
3334
@QueryAnnotation
3435
public @interface Meta {

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

+3-2
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-2016 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.
@@ -30,9 +30,10 @@
3030
* @author Oliver Gierke
3131
* @author Thomas Darimont
3232
* @author Christoph Strobl
33+
* @author Mark Paluch
3334
*/
3435
@Retention(RetentionPolicy.RUNTIME)
35-
@Target(ElementType.METHOD)
36+
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
3637
@Documented
3738
@QueryAnnotation
3839
public @interface Query {

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

+5-3
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-2016 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.
@@ -20,6 +20,7 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.springframework.core.annotation.AnnotatedElementUtils;
2324
import org.springframework.core.annotation.AnnotationUtils;
2425
import org.springframework.data.geo.GeoPage;
2526
import org.springframework.data.geo.GeoResult;
@@ -43,6 +44,7 @@
4344
*
4445
* @author Oliver Gierke
4546
* @author Christoph Strobl
47+
* @author Mark Paluch
4648
*/
4749
public class MongoQueryMethod extends QueryMethod {
4850

@@ -191,7 +193,7 @@ private boolean isGeoNearQuery(Method method) {
191193
* @return
192194
*/
193195
Query getQueryAnnotation() {
194-
return method.getAnnotation(Query.class);
196+
return AnnotatedElementUtils.findMergedAnnotation(method, Query.class);
195197
}
196198

197199
TypeInformation<?> getReturnType() {
@@ -213,7 +215,7 @@ public boolean hasQueryMetaAttributes() {
213215
* @since 1.6
214216
*/
215217
Meta getMetaAnnotation() {
216-
return method.getAnnotation(Meta.class);
218+
return AnnotatedElementUtils.findMergedAnnotation(method, Meta.class);
217219
}
218220

219221
/**

0 commit comments

Comments
 (0)