1 | package org.springframework.data.elasticsearch.repository.query; |
2 | |
3 | import org.springframework.core.annotation.AnnotationUtils; |
4 | import org.springframework.data.elasticsearch.annotations.Query; |
5 | import org.springframework.data.elasticsearch.repository.support.ElasticsearchEntityInformation; |
6 | import org.springframework.data.elasticsearch.repository.support.ElasticsearchEntityInformationCreator; |
7 | import org.springframework.data.repository.core.RepositoryMetadata; |
8 | import org.springframework.data.repository.query.QueryMethod; |
9 | import org.springframework.util.StringUtils; |
10 | |
11 | import java.lang.reflect.Method; |
12 | |
13 | |
14 | public class ElasticsearchQueryMethod extends QueryMethod { |
15 | |
16 | private final ElasticsearchEntityInformation<?, ?> entityInformation; |
17 | private Method method; |
18 | |
19 | public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ElasticsearchEntityInformationCreator elasticsearchEntityInformationCreator) { |
20 | super(method, metadata); |
21 | this.entityInformation = elasticsearchEntityInformationCreator.getEntityInformation(metadata.getReturnedDomainClass(method)); |
22 | this.method = method; |
23 | } |
24 | |
25 | public boolean hasAnnotatedQuery() { |
26 | return getQueryAnnotation() != null; |
27 | } |
28 | |
29 | public String getAnnotatedQuery() { |
30 | String query = (String) AnnotationUtils.getValue(getQueryAnnotation(), "value"); |
31 | return StringUtils.hasText(query) ? query : null; |
32 | } |
33 | |
34 | private Query getQueryAnnotation() { |
35 | return this.method.getAnnotation(Query.class); |
36 | } |
37 | |
38 | } |