DATACMNS-1578 - Proper handling of null values in QuerydslDefaultBinding.
We now properly use an ….isNull() binding if the value to be compared to is null.
This commit is contained in:
committed by
Oliver Drotbohm
parent
3ebe74d018
commit
30dbac1bce
@@ -38,6 +38,9 @@ import com.querydsl.core.types.dsl.SimpleExpression;
|
|||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
* @since 1.11
|
* @since 1.11
|
||||||
|
*
|
||||||
|
* @author Colin Gao
|
||||||
|
* @since 2.1
|
||||||
*/
|
*/
|
||||||
class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>, Object> {
|
class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>, Object> {
|
||||||
|
|
||||||
@@ -73,7 +76,12 @@ class QuerydslDefaultBinding implements MultiValueBinding<Path<? extends Object>
|
|||||||
return Optional.of(((SimpleExpression) path).in(value));
|
return Optional.of(((SimpleExpression) path).in(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.of(((SimpleExpression) path).eq(value.iterator().next()));
|
Object object = value.iterator().next();
|
||||||
|
if (object == null) {
|
||||||
|
return Optional.of(((SimpleExpression) path).isNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.of(((SimpleExpression) path).eq(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import com.querydsl.core.types.Predicate;
|
|||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Colin Gao
|
||||||
*/
|
*/
|
||||||
public class QuerydslDefaultBindingUnitTests {
|
public class QuerydslDefaultBindingUnitTests {
|
||||||
|
|
||||||
@@ -76,4 +77,10 @@ public class QuerydslDefaultBindingUnitTests {
|
|||||||
public void testname() {
|
public void testname() {
|
||||||
assertThat(binding.bind(QUser.user.lastname, Collections.emptySet())).isNotPresent();
|
assertThat(binding.bind(QUser.user.lastname, Collections.emptySet())).isNotPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test //DATACMNS-1578
|
||||||
|
public void shouldCreatePredicateWithIsNullWhenPropertyIsAnNestedObjectAndValueIsNull() {
|
||||||
|
Optional<Predicate> predicate = binding.bind(QUser.user.address.city, Collections.singleton(null));
|
||||||
|
assertThat(predicate).hasValueSatisfying(it -> assertThat(it.toString()).isEqualTo(QUser.user.address.city.isNull().toString()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user