DATAKV-119 - Upgraded to Querydsl 4.
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -40,7 +40,7 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysema.querydsl</groupId>
|
||||
<groupId>com.querydsl</groupId>
|
||||
<artifactId>querydsl-collections</artifactId>
|
||||
<version>${querydsl}</version>
|
||||
<optional>true</optional>
|
||||
@@ -70,7 +70,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>${project.build.directory}/generated-sources/test-annotations</outputDirectory>
|
||||
<processor>com.mysema.query.apt.QuerydslAnnotationProcessor</processor>
|
||||
<processor>com.querydsl.apt.QuerydslAnnotationProcessor</processor>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
@@ -24,12 +24,12 @@ import org.springframework.data.mapping.PropertyPath;
|
||||
import org.springframework.data.querydsl.QSort;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.mysema.query.support.Expressions;
|
||||
import com.mysema.query.types.Expression;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.OrderSpecifier.NullHandling;
|
||||
import com.mysema.query.types.Path;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.OrderSpecifier.NullHandling;
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.dsl.Expressions;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
|
||||
/**
|
||||
* Utilities for Querydsl usage.
|
||||
@@ -76,9 +76,9 @@ abstract class KeyValueQuerydslUtils {
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private static OrderSpecifier<?> toOrderSpecifier(Order order, PathBuilder<?> builder) {
|
||||
return new OrderSpecifier(order.isAscending() ? com.mysema.query.types.Order.ASC
|
||||
: com.mysema.query.types.Order.DESC, buildOrderPropertyPathFrom(order, builder),
|
||||
toQueryDslNullHandling(order.getNullHandling()));
|
||||
return new OrderSpecifier(
|
||||
order.isAscending() ? com.querydsl.core.types.Order.ASC : com.querydsl.core.types.Order.DESC,
|
||||
buildOrderPropertyPathFrom(order, builder), toQueryDslNullHandling(order.getNullHandling()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,12 +32,12 @@ import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.mysema.query.collections.CollQuery;
|
||||
import com.mysema.query.support.ProjectableQuery;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.Predicate;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.querydsl.collections.AbstractCollQuery;
|
||||
import com.querydsl.collections.CollQuery;
|
||||
import com.querydsl.core.types.EntityPath;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
|
||||
/**
|
||||
* {@link KeyValueRepository} implementation capable of executing {@link Predicate}s using {@link CollQuery}.
|
||||
@@ -46,10 +46,10 @@ import com.mysema.query.types.path.PathBuilder;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @param <T> the domain type to manage
|
||||
* @param <ID> the identififer type of the domain type
|
||||
* @param <ID> the identifier type of the domain type
|
||||
*/
|
||||
public class QuerydslKeyValueRepository<T, ID extends Serializable> extends SimpleKeyValueRepository<T, ID> implements
|
||||
QueryDslPredicateExecutor<T> {
|
||||
public class QuerydslKeyValueRepository<T, ID extends Serializable> extends SimpleKeyValueRepository<T, ID>
|
||||
implements QueryDslPredicateExecutor<T> {
|
||||
|
||||
private static final EntityPathResolver DEFAULT_ENTITY_PATH_RESOLVER = SimpleEntityPathResolver.INSTANCE;
|
||||
|
||||
@@ -92,7 +92,7 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
*/
|
||||
@Override
|
||||
public T findOne(Predicate predicate) {
|
||||
return prepareQuery(predicate).uniqueResult(builder);
|
||||
return prepareQuery(predicate).fetchOne();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -101,7 +101,7 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
*/
|
||||
@Override
|
||||
public Iterable<T> findAll(Predicate predicate) {
|
||||
return prepareQuery(predicate).list(builder);
|
||||
return prepareQuery(predicate).fetchResults().getResults();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -111,10 +111,10 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
@Override
|
||||
public Iterable<T> findAll(Predicate predicate, OrderSpecifier<?>... orders) {
|
||||
|
||||
ProjectableQuery<?> query = prepareQuery(predicate);
|
||||
AbstractCollQuery<T, ?> query = prepareQuery(predicate);
|
||||
query.orderBy(orders);
|
||||
|
||||
return query.list(builder);
|
||||
return query.fetchResults().getResults();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -133,7 +133,7 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
@Override
|
||||
public Page<T> findAll(Predicate predicate, Pageable pageable) {
|
||||
|
||||
ProjectableQuery<?> query = prepareQuery(predicate);
|
||||
AbstractCollQuery<T, ?> query = prepareQuery(predicate);
|
||||
|
||||
if (pageable != null) {
|
||||
|
||||
@@ -145,7 +145,7 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
}
|
||||
}
|
||||
|
||||
return new PageImpl<T>(query.list(builder), pageable, count(predicate));
|
||||
return new PageImpl<T>(query.fetchResults().getResults(), pageable, count(predicate));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -159,10 +159,10 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
return findAll();
|
||||
}
|
||||
|
||||
ProjectableQuery<?> query = prepareQuery(null);
|
||||
AbstractCollQuery<T, ?> query = prepareQuery(null);
|
||||
query.orderBy(orders);
|
||||
|
||||
return query.list(builder);
|
||||
return query.fetchResults().getResults();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -171,7 +171,7 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
*/
|
||||
@Override
|
||||
public long count(Predicate predicate) {
|
||||
return prepareQuery(predicate).count();
|
||||
return prepareQuery(predicate).fetchCount();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -180,7 +180,7 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
*/
|
||||
@Override
|
||||
public boolean exists(Predicate predicate) {
|
||||
return prepareQuery(predicate).exists();
|
||||
return count(predicate) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -189,14 +189,11 @@ public class QuerydslKeyValueRepository<T, ID extends Serializable> extends Simp
|
||||
* @param predicate
|
||||
* @return
|
||||
*/
|
||||
protected ProjectableQuery<?> prepareQuery(Predicate predicate) {
|
||||
|
||||
CollQuery query = new CollQuery();
|
||||
protected AbstractCollQuery<T, ?> prepareQuery(Predicate predicate) {
|
||||
|
||||
CollQuery<T> query = new CollQuery<T>();
|
||||
query.from(builder, findAll());
|
||||
if (predicate != null) {
|
||||
query.where(predicate);
|
||||
}
|
||||
return query;
|
||||
|
||||
return predicate != null ? query.where(predicate) : query;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -20,7 +20,7 @@ import java.io.Serializable;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.mysema.query.annotations.QueryEntity;
|
||||
import com.querydsl.core.annotations.QueryEntity;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -28,6 +28,8 @@ import com.mysema.query.annotations.QueryEntity;
|
||||
@QueryEntity
|
||||
public class Person implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 4212763002445358314L;
|
||||
|
||||
private @Id String id;
|
||||
private String firstname;
|
||||
private int age;
|
||||
|
||||
@@ -29,9 +29,9 @@ import org.springframework.data.keyvalue.Person;
|
||||
import org.springframework.data.keyvalue.QPerson;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
|
||||
import com.mysema.query.types.EntityPath;
|
||||
import com.mysema.query.types.OrderSpecifier;
|
||||
import com.mysema.query.types.path.PathBuilder;
|
||||
import com.querydsl.core.types.EntityPath;
|
||||
import com.querydsl.core.types.OrderSpecifier;
|
||||
import com.querydsl.core.types.dsl.PathBuilder;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link KeyValueQuerydslUtils}.
|
||||
@@ -78,7 +78,8 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers, IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.asc()));
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.asc()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,8 +106,8 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers, IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(
|
||||
QPerson.person.firstname.desc(), QPerson.person.age.asc()));
|
||||
assertThat(specifiers, IsArrayContainingInOrder.<OrderSpecifier<?>> arrayContaining(QPerson.person.firstname.desc(),
|
||||
QPerson.person.age.asc()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ Bundle-Version: ${project.version}
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Import-Template:
|
||||
com.mysema.query.*;version="${querydsl:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
com.querydsl.*;version="${querydsl:[=.=.=,+1.0.0)}";resolution:=optional,
|
||||
org.springframework.*;version="${spring:[=.=.=,+1.0.0)}",
|
||||
org.springframework.data.*;version="${springdata.commons:[=.=.=,+1.0.0)}"
|
||||
DynamicImport-Package: *
|
||||
|
||||
Reference in New Issue
Block a user