use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class ExpressionModifierCollectingResultVisitorAdapter method visit.
@Override
public Boolean visit(CompoundPredicate predicate) {
List<Predicate> predicates = predicate.getChildren();
int size = predicates.size();
for (int i = 0; i < size; i++) {
if (Boolean.TRUE == predicates.get(i).accept(this)) {
onModifier(new ExpressionListModifier(predicates, i));
}
}
return Boolean.FALSE;
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class GeneralParserTest method testComplexCaseWhen.
@Test
public void testComplexCaseWhen() {
FunctionExpression result = (FunctionExpression) parse("" + "CONCAT(\n" + " COALESCE(\n" + " CONCAT(\n" + " NULLIF(\n" + " CONCAT(\n" + " CASE WHEN LENGTH(COALESCE(zip, '')) > 0 OR LENGTH(COALESCE(city, '')) > 0 THEN COALESCE(CONCAT(NULLIF(street, ''), ', '), '') ELSE COALESCE(street, '') END,\n" + " CASE WHEN LENGTH(COALESCE(city, '')) > 0 THEN COALESCE(CONCAT(NULLIF(zip, ''), ' '), '') ELSE COALESCE(zip, '') END,\n" + " COALESCE(city, '')\n" + " ),\n" + " ''\n" + " ),\n" + " ' - '\n" + " ),\n" + " ''\n" + " ),\n" + " 'test'" + ")");
FunctionExpression expected = function("CONCAT", function("COALESCE", function("CONCAT", function("NULLIF", function("CONCAT", new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new GtPredicate(function("LENGTH", function("COALESCE", path("zip"), _string(""))), _int("0")), new GtPredicate(function("LENGTH", function("COALESCE", path("city"), _string(""))), _int("0"))), function("COALESCE", function("CONCAT", function("NULLIF", path("street"), _string("")), _string(", ")), _string("")))), function("COALESCE", path("street"), _string(""))), new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new GtPredicate(function("LENGTH", function("COALESCE", path("city"), _string(""))), _int("0")), function("COALESCE", function("CONCAT", function("NULLIF", path("zip"), _string("")), _string(" ")), _string("")))), function("COALESCE", path("zip"), _string(""))), function("COALESCE", path("city"), _string(""))), _string("")), _string(" - ")), _string("")), _string("test"));
assertEquals(expected, result);
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class GeneralParserTest method testNot1.
@Test
public void testNot1() {
GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN NOT(x.a = y.a) OR c.a < 9 AND b - c = 2 THEN 0 ELSE 1 END");
GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new EqPredicate(path("x", "a"), path("y", "a"), true), new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new LtPredicate(path("c", "a"), _int("9")), new EqPredicate(subtract(path("b"), path("c")), _int("2")))), _int("0"))), _int("1"));
assertEquals(expected, result);
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class LogicOptimizationTest method testOptimizeNegationStructure2.
@Test
public void testOptimizeNegationStructure2() {
Predicate result = parsePredicateOptimized("NOT(NOT(a > b) OR a < x)", false);
Predicate expected = new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, new GtPredicate(path("a"), path("b")), new LtPredicate(path("a"), path("x"), true));
assertEquals(expected, result);
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class LogicOptimizationTest method testOptimizeNegationStructure3.
@Test
public void testOptimizeNegationStructure3() {
Predicate result = parsePredicateOptimized("NOT(NOT(a > b) AND a < x)", false);
Predicate expected = new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new GtPredicate(path("a"), path("b")), new LtPredicate(path("a"), path("x"), true));
assertEquals(expected, result);
}
Aggregations