Skip to content

Commit 13d2116

Browse files
committed
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. Original pull request: #347.
1 parent ee30fe1 commit 13d2116

File tree

13 files changed

+342
-16
lines changed

13 files changed

+342
-16
lines changed

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

Lines changed: 3 additions & 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-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.
@@ -29,8 +29,9 @@
2929
* @author Philipp Schneider
3030
* @author Johno Crawford
3131
* @author Christoph Strobl
32+
* @author Mark Paluch
3233
*/
33-
@Target({ ElementType.TYPE })
34+
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
3435
@Documented
3536
@Retention(RetentionPolicy.RUNTIME)
3637
public @interface CompoundIndex {

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

Lines changed: 3 additions & 2 deletions
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/Indexed.java

Lines changed: 2 additions & 1 deletion
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.
@@ -30,6 +30,7 @@
3030
* @author Thomas Darimont
3131
* @author Christoph Strobl
3232
* @author Jordi Llach
33+
* @author Mark Paluch
3334
*/
3435
@Target({ElementType.ANNOTATION_TYPE, ElementType.FIELD})
3536
@Retention(RetentionPolicy.RUNTIME)

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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 16 additions & 0 deletions
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;
@@ -8,6 +23,7 @@
823
* Annotation to define custom metadata for document fields.
924
*
1025
* @author Oliver Gierke
26+
* @author Mark Paluch
1127
*/
1228
@Documented
1329
@Retention(RetentionPolicy.RUNTIME)

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

Lines changed: 3 additions & 2 deletions
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

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-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

Lines changed: 5 additions & 3 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-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)