DATACMNS-670 - Upgraded to Querydsl 4.

Switched to new Querydsl 4 artifacts and adapted to changed package names and API changes.

Cleaned up some JavaDoc and APIs in QuerydslBindingsFactory and QuerydslBinderCustomizer.
This commit is contained in:
Oliver Gierke
2015-05-22 17:27:00 +02:00
parent db2a09192b
commit c013c71e7a
29 changed files with 123 additions and 95 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-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.
@@ -15,7 +15,7 @@
*/
package org.springframework.data.querydsl;
import com.mysema.query.types.EntityPath;
import com.querydsl.core.types.EntityPath;
/**
* Strategy interface to abstract the ways to translate an plain domain class into a {@link EntityPath}.
@@ -25,4 +25,4 @@ import com.mysema.query.types.EntityPath;
public interface EntityPathResolver {
<T> EntityPath<T> createPath(Class<T> domainClass);
}
}

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");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,7 @@ package org.springframework.data.querydsl;
import org.springframework.data.domain.AbstractPageRequest;
import org.springframework.data.domain.Pageable;
import com.mysema.query.types.OrderSpecifier;
import com.querydsl.core.types.OrderSpecifier;
/**
* Basic Java Bean implementation of {@link Pageable} with support for QueryDSL.

View File

@@ -23,12 +23,12 @@ import java.util.List;
import org.springframework.data.domain.Sort;
import org.springframework.util.Assert;
import com.mysema.query.types.Expression;
import com.mysema.query.types.OrderSpecifier;
import com.mysema.query.types.Path;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Path;
/**
* Sort option for queries that wraps a querydsl {@link OrderSpecifier}.
* Sort option for queries that wraps a Querydsl {@link OrderSpecifier}.
*
* @author Thomas Darimont
* @author Christoph Strobl
@@ -42,7 +42,7 @@ public class QSort extends Sort implements Serializable {
/**
* Creates a new {@link QSort} instance with the given {@link OrderSpecifier}s.
*
* @param orderSpecifiers must not be {@literal null} or empty;
* @param orderSpecifiers must not be {@literal null} or empty.
*/
public QSort(OrderSpecifier<?>... orderSpecifiers) {
this(Arrays.asList(orderSpecifiers));
@@ -51,10 +51,12 @@ public class QSort extends Sort implements Serializable {
/**
* Creates a new {@link QSort} instance with the given {@link OrderSpecifier}s.
*
* @param orderSpecifiers must not be {@literal null} or empty;
* @param orderSpecifiers must not be {@literal null} or empty.
*/
public QSort(List<OrderSpecifier<?>> orderSpecifiers) {
super(toOrders(orderSpecifiers));
Assert.notEmpty(orderSpecifiers, "Order specifiers must not be null or empty!");
this.orderSpecifiers = orderSpecifiers;
}

View File

@@ -19,8 +19,8 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import com.mysema.query.types.OrderSpecifier;
import com.mysema.query.types.Predicate;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Predicate;
/**
* Interface to allow execution of QueryDsl {@link Predicate} instances.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-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.
@@ -22,8 +22,8 @@ package org.springframework.data.querydsl;
*/
public abstract class QueryDslUtils {
public static final boolean QUERY_DSL_PRESENT = org.springframework.util.ClassUtils.isPresent(
"com.mysema.query.types.Predicate", QueryDslUtils.class.getClassLoader());
public static final boolean QUERY_DSL_PRESENT = org.springframework.util.ClassUtils
.isPresent("com.querydsl.core.types.Predicate", QueryDslUtils.class.getClassLoader());
private QueryDslUtils() {

View File

@@ -25,7 +25,7 @@ import org.springframework.data.repository.support.RepositoryInvoker;
import org.springframework.util.Assert;
import org.springframework.util.MultiValueMap;
import com.mysema.query.types.Predicate;
import com.querydsl.core.types.Predicate;
/**
* {@link RepositoryInvoker} that is aware of a {@link QueryDslPredicateExecutor} and {@link Predicate} to be executed

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-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.
@@ -21,7 +21,7 @@ import java.lang.reflect.Modifier;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import com.mysema.query.types.EntityPath;
import com.querydsl.core.types.EntityPath;
/**
* Simple implementation of {@link EntityPathResolver} to lookup a query class by reflection and using the static field
@@ -116,4 +116,4 @@ public enum SimpleEntityPathResolver implements EntityPathResolver {
return parts[0] + "_";
}
}
}

View File

@@ -17,8 +17,8 @@ package org.springframework.data.querydsl.binding;
import java.util.Collection;
import com.mysema.query.types.Path;
import com.mysema.query.types.Predicate;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
/**
* {@link MultiValueBinding} creates a {@link Predicate} out of given {@link Path} and collection value. Used for
@@ -31,13 +31,14 @@ import com.mysema.query.types.Predicate;
public interface MultiValueBinding<T extends Path<? extends S>, S> {
/**
* Returns the predicate to be applied to the given {@link Path} for the given collection value, which will contain
* all values submitted for the path bind. If a single value was provided only the collection will consist of exactly
* one element.
* Returns the predicate to be applied to the given {@link Path} for the given collection value, which will contain
* all values submitted for the path bind. If a single value was provided only the collection will consist of exactly
* one element.
*
* @param path {@link Path} to the property. Will not be {@literal null}.
* @param value the value that should be bound. Will not be {@literal null} or empty.
* @return can be {@literal null}, in which case the binding will not be incorporated in the overall {@link Predicate}.
* @return can be {@literal null}, in which case the binding will not be incorporated in the overall {@link Predicate}
* .
*/
Predicate bind(T path, Collection<? extends S> value);
}

View File

@@ -15,14 +15,21 @@
*/
package org.springframework.data.querydsl.binding;
import com.mysema.query.types.EntityPath;
import com.querydsl.core.types.EntityPath;
/**
* A component that will customize {@link QuerydslBindings} for the given entity path.
*
* @author Oliver Gierke
* @since 1.11
*/
public interface QuerydslBinderCustomizer<T extends EntityPath<?>> {
/**
* Customize the {@link QuerydslBindings} for the given root.
*
* @param bindings the {@link QuerydslBindings} to customize, will never be {@literal null}.
* @param root the entity root, will never be {@literal null}.
*/
void customize(QuerydslBindings bindings, T root);
}

View File

@@ -28,9 +28,9 @@ import org.springframework.data.mapping.PropertyPath;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import com.mysema.query.types.Path;
import com.mysema.query.types.PathMetadata;
import com.mysema.query.types.Predicate;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.PathMetadata;
import com.querydsl.core.types.Predicate;
/**
* {@link QuerydslBindings} allows definition of path specific {@link SingleValueBinding}.
@@ -229,9 +229,9 @@ public class QuerydslBindings {
return "";
}
PathMetadata<?> metadata = path.getMetadata();
PathMetadata metadata = path.getMetadata();
return path.toString().substring(metadata.getRoot().getMetadata().getName().length() + 1);
return path.toString().substring(metadata.getRootPath().getMetadata().getName().length() + 1);
}
/**

View File

@@ -29,10 +29,13 @@ import org.springframework.data.util.TypeInformation;
import org.springframework.util.Assert;
import org.springframework.util.ConcurrentReferenceHashMap;
import com.mysema.query.types.EntityPath;
import com.querydsl.core.types.EntityPath;
/**
* Factory to create {@link QuerydslBindings} using an {@link EntityPathResolver}.
*
* @author Oliver Gierke
* @since 1.11
*/
public class QuerydslBindingsFactory implements ApplicationContextAware {
@@ -45,6 +48,8 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
private Repositories repositories;
/**
* Creates a new {@link QuerydslBindingsFactory} using the given {@link EntityPathResolver}.
*
* @param entityPathResolver must not be {@literal null}.
*/
public QuerydslBindingsFactory(EntityPathResolver entityPathResolver) {
@@ -61,6 +66,7 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
*/
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.beanFactory = applicationContext.getAutowireCapableBeanFactory();
this.repositories = new Repositories(applicationContext);
}
@@ -74,9 +80,20 @@ public class QuerydslBindingsFactory implements ApplicationContextAware {
return entityPathResolver;
}
public QuerydslBindings createBindingsFor(Class<? extends QuerydslBinderCustomizer> customizer,
/**
* Creates the {@link QuerydslBindings} to be used using for the given domain type and a pre-defined
* {@link QuerydslBinderCustomizer}. If no customizer is given, auto-detection will be applied.
*
* @param customizer the {@link QuerydslBinderCustomizer} to use. If {@literal null} is given customizer detection for
* the given domain type will be applied.
* @param domainType must not be {@literal null}.
* @return
*/
public QuerydslBindings createBindingsFor(Class<? extends QuerydslBinderCustomizer<?>> customizer,
TypeInformation<?> domainType) {
Assert.notNull(domainType, "Domain type must not be null!");
EntityPath<?> path = verifyEntityPathPresent(domainType);
QuerydslBindings bindings = new QuerydslBindings();

View File

@@ -19,11 +19,11 @@ import java.util.Collection;
import org.springframework.util.Assert;
import com.mysema.query.BooleanBuilder;
import com.mysema.query.types.Path;
import com.mysema.query.types.Predicate;
import com.mysema.query.types.expr.SimpleExpression;
import com.mysema.query.types.path.CollectionPathBase;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
import com.querydsl.core.types.dsl.CollectionPathBase;
import com.querydsl.core.types.dsl.SimpleExpression;
/**
* Default implementation of {@link MultiValueBinding} creating {@link Predicate} based on the {@link Path}s type.

View File

@@ -39,9 +39,9 @@ import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import com.mysema.query.BooleanBuilder;
import com.mysema.query.types.Path;
import com.mysema.query.types.Predicate;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
/**
* Builder assembling {@link Predicate} out of {@link PropertyValues}.

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.data.querydsl.binding;
import com.mysema.query.types.Path;
import com.mysema.query.types.Predicate;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.Predicate;
/**
* {@link SingleValueBinding} creates a {@link Predicate} out of given {@link Path} and value. Used for specific
@@ -30,12 +30,13 @@ import com.mysema.query.types.Predicate;
public interface SingleValueBinding<T extends Path<? extends S>, S> {
/**
* Returns the predicate to be applied to the given {@link Path} for the given value. The given value will be the first
* the first one provided for the given path and converted into the expected type.
* Returns the predicate to be applied to the given {@link Path} for the given value. The given value will be the
* first the first one provided for the given path and converted into the expected type.
*
* @param path {@link Path} to the property. Will not be {@literal null}.
* @param value the value that should be bound. Will not be {@literal null}.
* @return can be {@literal null}, in which case the binding will not be incorporated in the overall {@link Predicate}.
* @return can be {@literal null}, in which case the binding will not be incorporated in the overall {@link Predicate}
* .
*/
Predicate bind(T path, S value);
}