#383 - Fix Criteria mapping when composing a group from top-level criteria.
Using Criteria.from(…) with multiple Criteria objects now uses properly AND combination along with group nesting to render a correct criteria. Previously, the INITIAL combinator in groups caused a mapping exception.
This commit is contained in:
@@ -322,12 +322,14 @@ public class QueryMapper {
|
||||
|
||||
if (currentCondition == null) {
|
||||
currentCondition = nextCondition;
|
||||
} else if (combinator == CriteriaDefinition.Combinator.INITIAL) {
|
||||
currentCondition = currentCondition.and(Conditions.nest(nextCondition));
|
||||
} else if (combinator == CriteriaDefinition.Combinator.AND) {
|
||||
currentCondition = currentCondition.and(nextCondition);
|
||||
} else if (combinator == CriteriaDefinition.Combinator.OR) {
|
||||
currentCondition = currentCondition.or(nextCondition);
|
||||
} else {
|
||||
throw new IllegalStateException("Combinator " + criteria.getCombinator() + " not supported");
|
||||
throw new IllegalStateException("Combinator " + combinator + " not supported");
|
||||
}
|
||||
|
||||
return currentCondition;
|
||||
|
||||
@@ -126,6 +126,22 @@ public class QueryMapperUnitTests {
|
||||
.isEqualTo("person.name = ?[$1] AND (person.name = ?[$2] OR person.age < ?[$3])");
|
||||
}
|
||||
|
||||
@Test // gh-383
|
||||
public void shouldMapFromConcat() {
|
||||
|
||||
Criteria criteria = Criteria.from(Criteria.where("name").is("Foo"), Criteria.where("name").is("Bar") //
|
||||
.or("age").lessThan(49));
|
||||
|
||||
assertThat(map(criteria).getCondition().toString())
|
||||
.isEqualTo("(person.name = ?[$1] AND (person.name = ?[$2] OR person.age < ?[$3]))");
|
||||
|
||||
criteria = Criteria.from(Criteria.where("name").is("Foo"), Criteria.where("name").is("Bar") //
|
||||
.or("age").lessThan(49), Criteria.where("foo").is("bar"));
|
||||
|
||||
assertThat(map(criteria).getCondition().toString())
|
||||
.isEqualTo("(person.name = ?[$1] AND (person.name = ?[$2] OR person.age < ?[$3]) AND (person.foo = ?[$4]))");
|
||||
}
|
||||
|
||||
@Test // gh-64
|
||||
public void shouldMapSimpleCriteria() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user