Skip to content

Commit 5299781

Browse files
committed
DATAES-219 Developments for querydsl-elasticsearch integration.
1 parent d5cdba0 commit 5299781

File tree

12 files changed

+1010
-7
lines changed

12 files changed

+1010
-7
lines changed

pom.xml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@
5454
<version>${springdata.commons}</version>
5555
</dependency>
5656

57+
<dependency>
58+
<groupId>com.querydsl.contrib</groupId>
59+
<artifactId>querydsl-elasticsearch</artifactId>
60+
<version>${querydsl}</version>
61+
<optional>true</optional>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.querydsl</groupId>
66+
<artifactId>querydsl-apt</artifactId>
67+
<version>${querydsl}</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>javax.annotation</groupId>
73+
<artifactId>jsr250-api</artifactId>
74+
<version>1.0</version>
75+
<optional>true</optional>
76+
</dependency>
77+
5778
<!-- APACHE -->
5879
<dependency>
5980
<groupId>commons-lang</groupId>
@@ -139,6 +160,30 @@
139160

140161
<build>
141162
<plugins>
163+
<plugin>
164+
<groupId>com.mysema.maven</groupId>
165+
<artifactId>apt-maven-plugin</artifactId>
166+
<version>${apt}</version>
167+
<dependencies>
168+
<dependency>
169+
<groupId>com.querydsl</groupId>
170+
<artifactId>querydsl-apt</artifactId>
171+
<version>${querydsl}</version>
172+
</dependency>
173+
</dependencies>
174+
<executions>
175+
<execution>
176+
<phase>generate-test-sources</phase>
177+
<goals>
178+
<goal>test-process</goal>
179+
</goals>
180+
<configuration>
181+
<outputDirectory>target/generated-test-sources</outputDirectory>
182+
<processor>org.springframework.data.elasticsearch.repository.support.ElasticsearchAnnotationProcessor</processor>
183+
</configuration>
184+
</execution>
185+
</executions>
186+
</plugin>
142187
<plugin>
143188
<groupId>org.apache.maven.plugins</groupId>
144189
<artifactId>maven-assembly-plugin</artifactId>

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchOperations.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.springframework.data.elasticsearch.core;
1717

1818
import org.elasticsearch.action.update.UpdateResponse;
19+
import org.elasticsearch.client.Client;
1920
import org.springframework.data.domain.Page;
2021
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
2122
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
@@ -41,6 +42,16 @@ public interface ElasticsearchOperations {
4142
*/
4243
ElasticsearchConverter getElasticsearchConverter();
4344

45+
/**
46+
* @return Client in use
47+
*/
48+
Client getClient();
49+
50+
/**
51+
* @return ResultsMapper in use
52+
*/
53+
ResultsMapper getResultsMapper();
54+
4455
/**
4556
* Create an index for a class
4657
*

src/main/java/org/springframework/data/elasticsearch/core/ElasticsearchTemplate.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import org.elasticsearch.action.search.SearchRequestBuilder;
5353
import org.elasticsearch.action.search.SearchResponse;
5454
import org.elasticsearch.action.search.SearchType;
55+
import org.elasticsearch.action.suggest.SuggestRequest;
5556
import org.elasticsearch.action.suggest.SuggestRequestBuilder;
5657
import org.elasticsearch.action.suggest.SuggestResponse;
5758
import org.elasticsearch.action.update.UpdateRequestBuilder;
@@ -64,6 +65,7 @@
6465
import org.elasticsearch.common.collect.MapBuilder;
6566
import org.elasticsearch.common.collect.Maps;
6667
import org.elasticsearch.common.unit.TimeValue;
68+
import org.elasticsearch.common.xcontent.ToXContent;
6769
import org.elasticsearch.common.xcontent.XContentBuilder;
6870
import org.elasticsearch.index.query.FilterBuilder;
6971
import org.elasticsearch.index.query.QueryBuilder;
@@ -232,6 +234,16 @@ public ElasticsearchConverter getElasticsearchConverter() {
232234
return elasticsearchConverter;
233235
}
234236

237+
@Override
238+
public Client getClient() {
239+
return client;
240+
}
241+
242+
@Override
243+
public ResultsMapper getResultsMapper() {
244+
return resultsMapper;
245+
}
246+
235247
@Override
236248
public <T> T queryForObject(GetQuery query, Class<T> clazz) {
237249
return queryForObject(query, clazz, resultsMapper);
@@ -1151,10 +1163,6 @@ private static String[] toArray(List<String> values) {
11511163
return values.toArray(valuesAsArray);
11521164
}
11531165

1154-
protected ResultsMapper getResultsMapper() {
1155-
return resultsMapper;
1156-
}
1157-
11581166
private boolean isDocument(Class clazz) {
11591167
return clazz.isAnnotationPresent(Document.class);
11601168
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 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+
*/
16+
package org.springframework.data.elasticsearch.repository.support;
17+
18+
import java.util.Collections;
19+
20+
import javax.annotation.processing.RoundEnvironment;
21+
import javax.annotation.processing.SupportedAnnotationTypes;
22+
import javax.annotation.processing.SupportedSourceVersion;
23+
import javax.lang.model.SourceVersion;
24+
import javax.tools.Diagnostic;
25+
26+
import com.querydsl.core.annotations.QueryEmbeddable;
27+
import com.querydsl.core.annotations.QueryEmbedded;
28+
import com.querydsl.core.annotations.QueryEntities;
29+
import com.querydsl.core.annotations.QuerySupertype;
30+
import com.querydsl.core.annotations.QueryTransient;
31+
import com.querydsl.apt.AbstractQuerydslProcessor;
32+
import com.querydsl.apt.Configuration;
33+
import com.querydsl.apt.DefaultConfiguration;
34+
35+
import org.springframework.data.elasticsearch.annotations.Document;
36+
37+
/**
38+
* Annotation processor to create Querydsl query types for QueryDsl annotated classes.
39+
*
40+
* @author Kevin Leturc
41+
*/
42+
@SupportedAnnotationTypes({ "com.querydsl.core.annotations.*", "org.springframework.data.elasticsearch.annotations.*" })
43+
@SupportedSourceVersion(SourceVersion.RELEASE_6)
44+
public class ElasticsearchAnnotationProcessor extends AbstractQuerydslProcessor {
45+
46+
/*
47+
* (non-Javadoc)
48+
* @see com.querydsl.core.apt.AbstractQuerydslProcessor#createConfiguration(javax.annotation.processing.RoundEnvironment)
49+
*/
50+
@Override
51+
protected Configuration createConfiguration(RoundEnvironment roundEnv) {
52+
53+
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName());
54+
55+
DefaultConfiguration configuration = new DefaultConfiguration(roundEnv, processingEnv.getOptions(),
56+
Collections.<String> emptySet(), QueryEntities.class, Document.class, QuerySupertype.class,
57+
QueryEmbeddable.class, QueryEmbedded.class, QueryTransient.class);
58+
configuration.setUnknownAsEmbedded(true);
59+
60+
return configuration;
61+
}
62+
63+
}

src/main/java/org/springframework/data/elasticsearch/repository/support/ElasticsearchRepositoryFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
* @author Rizwan Idrees
4242
* @author Mohsin Husen
4343
* @author Ryan Henszey
44+
* @author Kevin Leturc
4445
*/
4546
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {
4647

@@ -68,9 +69,8 @@ protected Object getTargetRepository(RepositoryInformation metadata) {
6869
@Override
6970
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
7071
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
71-
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
72-
}
73-
if (Integer.class.isAssignableFrom(metadata.getIdType())
72+
return QueryDslElasticsearchRepository.class;
73+
} else if (Integer.class.isAssignableFrom(metadata.getIdType())
7474
|| Long.class.isAssignableFrom(metadata.getIdType())
7575
|| Double.class.isAssignableFrom(metadata.getIdType())) {
7676
return NumberKeyedRepository.class;

0 commit comments

Comments
 (0)