DATACMNS-1057 - SingleValueBinding now returns a non-Optional again.
The binding is populated with a value so we can also expect a predicate to be returned.
This commit is contained in:
@@ -357,7 +357,7 @@ public class QuerydslBindings {
|
||||
public void first(SingleValueBinding<P, T> binding) {
|
||||
|
||||
Assert.notNull(binding, "Binding must not be null!");
|
||||
all((path, value) -> Optionals.next(value.iterator()).flatMap(t -> binding.bind(path, t)));
|
||||
all((path, value) -> Optionals.next(value.iterator()).map(t -> binding.bind(path, t)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,8 +476,7 @@ public class QuerydslBindings {
|
||||
public <P extends Path<T>> void first(SingleValueBinding<P, T> binding) {
|
||||
|
||||
Assert.notNull(binding, "Binding must not be null!");
|
||||
all((MultiValueBinding<P, T>) (path, value) -> Optionals.next(value.iterator())
|
||||
.flatMap(t -> binding.bind(path, t)));
|
||||
all((MultiValueBinding<P, T>) (path, value) -> Optionals.next(value.iterator()).map(t -> binding.bind(path, t)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl.binding;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
@@ -40,5 +38,5 @@ public interface SingleValueBinding<T extends Path<? extends S>, S> {
|
||||
* @return can be {@literal null}, in which case the binding will not be incorporated in the overall {@link Predicate}
|
||||
* .
|
||||
*/
|
||||
Optional<Predicate> bind(T path, S value);
|
||||
Predicate bind(T path, S value);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,7 @@ public class QuerydslBindingsUnitTests {
|
||||
QuerydslPredicateBuilder builder;
|
||||
QuerydslBindings bindings;
|
||||
|
||||
static final SingleValueBinding<StringPath, String> CONTAINS_BINDING = (path, value) -> Optional
|
||||
.of(path.contains(value));
|
||||
static final SingleValueBinding<StringPath, String> CONTAINS_BINDING = (path, value) -> path.contains(value);
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -266,13 +265,13 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
/*
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.querydsl.binding.SingleValueBinding#bind(com.querydsl.core.types.Path, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Optional<Predicate> bind(StringPath path, String value) {
|
||||
return Optional.of(path.contains(value));
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return path.contains(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,8 +97,8 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
request.addParameter("firstname", "rand");
|
||||
|
||||
Predicate predicate = resolver.resolveArgument(
|
||||
getMethodParameterFor("simpleFind", Predicate.class), null, new ServletWebRequest(request), null);
|
||||
Predicate predicate = resolver.resolveArgument(getMethodParameterFor("simpleFind", Predicate.class), null,
|
||||
new ServletWebRequest(request), null);
|
||||
|
||||
assertThat(predicate).isEqualTo((Predicate) QUser.user.firstname.eq("rand"));
|
||||
}
|
||||
@@ -157,8 +157,8 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
request.addParameter("inceptionYear", "978");
|
||||
|
||||
Predicate predicate = resolver.resolveArgument(
|
||||
getMethodParameterFor("specificFind", Predicate.class), null, new ServletWebRequest(request), null);
|
||||
Predicate predicate = resolver.resolveArgument(getMethodParameterFor("specificFind", Predicate.class), null,
|
||||
new ServletWebRequest(request), null);
|
||||
|
||||
assertThat(predicate).isEqualTo((Predicate) QUser.user.inceptionYear.eq(978L));
|
||||
}
|
||||
@@ -168,8 +168,8 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
request.addParameter("inceptionYear", new String[] { "978", "998" });
|
||||
|
||||
Predicate predicate = resolver.resolveArgument(
|
||||
getMethodParameterFor("specificFind", Predicate.class), null, new ServletWebRequest(request), null);
|
||||
Predicate predicate = resolver.resolveArgument(getMethodParameterFor("specificFind", Predicate.class), null,
|
||||
new ServletWebRequest(request), null);
|
||||
|
||||
assertThat(predicate).isEqualTo((Predicate) QUser.user.inceptionYear.in(978L, 998L));
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
public void customize(QuerydslBindings bindings, QUser user) {
|
||||
|
||||
bindings.bind(user.firstname).firstOptional((path, value) -> value.map(it -> path.eq(it.toUpperCase())));
|
||||
bindings.bind(user.lastname).first((path, value) -> Optional.of(path.toLowerCase().eq(value)));
|
||||
bindings.bind(user.lastname).first((path, value) -> path.toLowerCase().eq(value));
|
||||
|
||||
bindings.excluding(user.address);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
|
||||
|
||||
@Override
|
||||
public void customize(QuerydslBindings bindings, QUser user) {
|
||||
bindings.bind(QUser.user.firstname).first((path, value) -> Optional.of(path.contains(value)));
|
||||
bindings.bind(QUser.user.firstname).first((path, value) -> path.contains(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user