From 485f0e7252d0776a5b0c14086650e8344e5e09b9 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 14 Dec 2015 21:13:33 +0100 Subject: [PATCH] DATAES-221 - Adapted to API changes in Spring Data Commons. Related ticket: DATACMNS-89. --- .../query/ElasticsearchQueryMethod.java | 20 +++++++++---------- .../ElasticsearchRepositoryFactory.java | 12 ++++++++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java index aa731d579..8cb1c3fa3 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/query/ElasticsearchQueryMethod.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ import java.lang.reflect.Method; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.elasticsearch.annotations.Query; +import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.repository.core.RepositoryMetadata; import org.springframework.data.repository.query.QueryMethod; import org.springframework.util.StringUtils; @@ -28,26 +29,23 @@ import org.springframework.util.StringUtils; * * @author Rizwan Idrees * @author Mohsin Husen + * @author Oliver Gierke */ public class ElasticsearchQueryMethod extends QueryMethod { - private Method method; + private final Query queryAnnotation; - public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata) { - super(method, metadata); - this.method = method; + public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) { + super(method, metadata, factory); + this.queryAnnotation = method.getAnnotation(Query.class); } public boolean hasAnnotatedQuery() { - return getQueryAnnotation() != null; + return this.queryAnnotation != null; } public String getAnnotatedQuery() { - String query = (String) AnnotationUtils.getValue(getQueryAnnotation(), "value"); + String query = (String) AnnotationUtils.getValue(queryAnnotation, "value"); return StringUtils.hasText(query) ? query : null; } - - private Query getQueryAnnotation() { - return this.method.getAnnotation(Query.class); - } } diff --git a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java index 547477678..9e1263022 100644 --- a/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java +++ b/src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java @@ -25,6 +25,7 @@ import org.springframework.data.elasticsearch.repository.ElasticsearchRepository import org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery; import org.springframework.data.elasticsearch.repository.query.ElasticsearchQueryMethod; import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery; +import org.springframework.data.projection.ProjectionFactory; import org.springframework.data.querydsl.QueryDslPredicateExecutor; import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.RepositoryInformation; @@ -90,11 +91,16 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport { } private class ElasticsearchQueryLookupStrategy implements QueryLookupStrategy { - + + /* + * (non-Javadoc) + * @see org.springframework.data.repository.query.QueryLookupStrategy#resolveQuery(java.lang.reflect.Method, org.springframework.data.repository.core.RepositoryMetadata, org.springframework.data.projection.ProjectionFactory, org.springframework.data.repository.core.NamedQueries) + */ @Override - public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, NamedQueries namedQueries) { + public RepositoryQuery resolveQuery(Method method, RepositoryMetadata metadata, ProjectionFactory factory, + NamedQueries namedQueries) { - ElasticsearchQueryMethod queryMethod = new ElasticsearchQueryMethod(method, metadata); + ElasticsearchQueryMethod queryMethod = new ElasticsearchQueryMethod(method, metadata, factory); String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) {