DATAES-221 - Adapted to API changes in Spring Data Commons.

Related ticket: DATACMNS-89.
This commit is contained in:
Oliver Gierke 2015-12-14 21:13:33 +01:00
parent aa9c47516c
commit 485f0e7252
2 changed files with 18 additions and 14 deletions

View File

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.core.annotation.AnnotationUtils;
import org.springframework.data.elasticsearch.annotations.Query; 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.core.RepositoryMetadata;
import org.springframework.data.repository.query.QueryMethod; import org.springframework.data.repository.query.QueryMethod;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@ -28,26 +29,23 @@ import org.springframework.util.StringUtils;
* *
* @author Rizwan Idrees * @author Rizwan Idrees
* @author Mohsin Husen * @author Mohsin Husen
* @author Oliver Gierke
*/ */
public class ElasticsearchQueryMethod extends QueryMethod { public class ElasticsearchQueryMethod extends QueryMethod {
private Method method; private final Query queryAnnotation;
public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata) { public ElasticsearchQueryMethod(Method method, RepositoryMetadata metadata, ProjectionFactory factory) {
super(method, metadata); super(method, metadata, factory);
this.method = method; this.queryAnnotation = method.getAnnotation(Query.class);
} }
public boolean hasAnnotatedQuery() { public boolean hasAnnotatedQuery() {
return getQueryAnnotation() != null; return this.queryAnnotation != null;
} }
public String getAnnotatedQuery() { public String getAnnotatedQuery() {
String query = (String) AnnotationUtils.getValue(getQueryAnnotation(), "value"); String query = (String) AnnotationUtils.getValue(queryAnnotation, "value");
return StringUtils.hasText(query) ? query : null; return StringUtils.hasText(query) ? query : null;
} }
private Query getQueryAnnotation() {
return this.method.getAnnotation(Query.class);
}
} }

View File

@ -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.ElasticsearchPartQuery;
import org.springframework.data.elasticsearch.repository.query.ElasticsearchQueryMethod; import org.springframework.data.elasticsearch.repository.query.ElasticsearchQueryMethod;
import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery; import org.springframework.data.elasticsearch.repository.query.ElasticsearchStringQuery;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.querydsl.QueryDslPredicateExecutor; import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.core.NamedQueries; import org.springframework.data.repository.core.NamedQueries;
import org.springframework.data.repository.core.RepositoryInformation; import org.springframework.data.repository.core.RepositoryInformation;
@ -91,10 +92,15 @@ public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
private class ElasticsearchQueryLookupStrategy implements QueryLookupStrategy { 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 @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(); String namedQueryName = queryMethod.getNamedQueryName();
if (namedQueries.hasQuery(namedQueryName)) { if (namedQueries.hasQuery(namedQueryName)) {