Skip to content

DATAES-219 Developments for querydsl-elasticsearch integration. #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@
<version>${springdata.commons}</version>
</dependency>

<dependency>
<groupId>com.querydsl.contrib</groupId>
<artifactId>querydsl-elasticsearch</artifactId>
<version>${querydsl}</version>
<optional>true</optional>
</dependency>

<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>

<!-- APACHE -->
<dependency>
<groupId>commons-lang</groupId>
Expand Down Expand Up @@ -139,6 +160,30 @@

<build>
<plugins>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>${apt}</version>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>generate-test-sources</phase>
<goals>
<goal>test-process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-test-sources</outputDirectory>
<processor>org.springframework.data.elasticsearch.repository.support.ElasticsearchAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.elasticsearch.core;

import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Client;
import org.springframework.data.domain.Page;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
Expand All @@ -41,6 +42,16 @@ public interface ElasticsearchOperations {
*/
ElasticsearchConverter getElasticsearchConverter();

/**
* @return Client in use
*/
Client getClient();

/**
* @return ResultsMapper in use
*/
ResultsMapper getResultsMapper();

/**
* Create an index for a class
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.action.suggest.SuggestRequest;
import org.elasticsearch.action.suggest.SuggestRequestBuilder;
import org.elasticsearch.action.suggest.SuggestResponse;
import org.elasticsearch.action.update.UpdateRequestBuilder;
Expand All @@ -64,6 +65,7 @@
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.collect.Maps;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.FilterBuilder;
import org.elasticsearch.index.query.QueryBuilder;
Expand Down Expand Up @@ -232,6 +234,16 @@ public ElasticsearchConverter getElasticsearchConverter() {
return elasticsearchConverter;
}

@Override
public Client getClient() {
return client;
}

@Override
public ResultsMapper getResultsMapper() {
return resultsMapper;
}

@Override
public <T> T queryForObject(GetQuery query, Class<T> clazz) {
return queryForObject(query, clazz, resultsMapper);
Expand Down Expand Up @@ -1151,10 +1163,6 @@ private static String[] toArray(List<String> values) {
return values.toArray(valuesAsArray);
}

protected ResultsMapper getResultsMapper() {
return resultsMapper;
}

private boolean isDocument(Class clazz) {
return clazz.isAnnotationPresent(Document.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.elasticsearch.repository.support;

import java.util.Collections;

import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.tools.Diagnostic;

import com.querydsl.core.annotations.QueryEmbeddable;
import com.querydsl.core.annotations.QueryEmbedded;
import com.querydsl.core.annotations.QueryEntities;
import com.querydsl.core.annotations.QuerySupertype;
import com.querydsl.core.annotations.QueryTransient;
import com.querydsl.apt.AbstractQuerydslProcessor;
import com.querydsl.apt.Configuration;
import com.querydsl.apt.DefaultConfiguration;

import org.springframework.data.elasticsearch.annotations.Document;

/**
* Annotation processor to create Querydsl query types for QueryDsl annotated classes.
*
* @author Kevin Leturc
*/
@SupportedAnnotationTypes({ "com.querydsl.core.annotations.*", "org.springframework.data.elasticsearch.annotations.*" })
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class ElasticsearchAnnotationProcessor extends AbstractQuerydslProcessor {

/*
* (non-Javadoc)
* @see com.querydsl.core.apt.AbstractQuerydslProcessor#createConfiguration(javax.annotation.processing.RoundEnvironment)
*/
@Override
protected Configuration createConfiguration(RoundEnvironment roundEnv) {

processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Running " + getClass().getSimpleName());

DefaultConfiguration configuration = new DefaultConfiguration(roundEnv, processingEnv.getOptions(),
Collections.<String> emptySet(), QueryEntities.class, Document.class, QuerySupertype.class,
QueryEmbeddable.class, QueryEmbedded.class, QueryTransient.class);
configuration.setUnknownAsEmbedded(true);

return configuration;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @author Rizwan Idrees
* @author Mohsin Husen
* @author Ryan Henszey
* @author Kevin Leturc
*/
public class ElasticsearchRepositoryFactory extends RepositoryFactorySupport {

Expand Down Expand Up @@ -68,9 +69,8 @@ protected Object getTargetRepository(RepositoryInformation metadata) {
@Override
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
if (isQueryDslRepository(metadata.getRepositoryInterface())) {
throw new IllegalArgumentException("QueryDsl Support has not been implemented yet.");
}
if (Integer.class.isAssignableFrom(metadata.getIdType())
return QueryDslElasticsearchRepository.class;
} else if (Integer.class.isAssignableFrom(metadata.getIdType())
|| Long.class.isAssignableFrom(metadata.getIdType())
|| Double.class.isAssignableFrom(metadata.getIdType())) {
return NumberKeyedRepository.class;
Expand Down
Loading