use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class JPQLNextExpressionVisitorImpl method visitOrPredicate.
@Override
public Expression visitOrPredicate(JPQLNextParser.OrPredicateContext ctx) {
List<JPQLNextParser.PredicateContext> predicate = ctx.predicate();
Predicate left = (Predicate) predicate.get(0).accept(this);
if (left instanceof CompoundPredicate && ((CompoundPredicate) left).getOperator() == CompoundPredicate.BooleanOperator.OR) {
((CompoundPredicate) left).getChildren().add((Predicate) predicate.get(1).accept(this));
return left;
} else {
List<Predicate> predicates = new ArrayList<>(2);
predicates.add(left);
predicates.add((Predicate) predicate.get(1).accept(this));
return new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, predicates);
}
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class GeneralParserTest method testNot3.
@Test
public void testNot3() {
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(not(new CompoundPredicate(CompoundPredicate.BooleanOperator.OR, new EqPredicate(path("x", "a"), path("y", "a")), 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 GeneralParserTest method testCaseWhenAndOr.
@Test
public void testCaseWhenAndOr() {
GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN 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")), 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 AbstractParserTest method wrapNot.
protected Predicate wrapNot(Predicate p) {
CompoundPredicate wrapper = new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, p);
wrapper.negate();
return wrapper;
}
use of com.blazebit.persistence.parser.predicate.CompoundPredicate in project blaze-persistence by Blazebit.
the class EqualityCheckingVisitor method visit.
@Override
public Boolean visit(CompoundPredicate predicate) {
if (referenceExpression.getClass() != predicate.getClass()) {
return Boolean.TRUE;
}
CompoundPredicate referencePredicate = (CompoundPredicate) referenceExpression;
if (referencePredicate.isNegated() != predicate.isNegated() || referencePredicate.getOperator() != predicate.getOperator()) {
return Boolean.TRUE;
}
List<Predicate> referencePredicateChildren = referencePredicate.getChildren();
List<Predicate> children = predicate.getChildren();
if (referencePredicateChildren.size() != children.size()) {
return Boolean.TRUE;
}
int size = children.size();
for (int i = 0; i < size; i++) {
referenceExpression = referencePredicateChildren.get(i);
if (children.get(i).accept(this)) {
return Boolean.TRUE;
}
}
return Boolean.FALSE;
}
Aggregations