Search in sources :

Example 11 with CompoundPredicate

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);
    }
}
Also used : ArrayList(java.util.ArrayList) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) BetweenPredicate(com.blazebit.persistence.parser.predicate.BetweenPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) GePredicate(com.blazebit.persistence.parser.predicate.GePredicate) IsEmptyPredicate(com.blazebit.persistence.parser.predicate.IsEmptyPredicate) LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) LePredicate(com.blazebit.persistence.parser.predicate.LePredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) IsNullPredicate(com.blazebit.persistence.parser.predicate.IsNullPredicate) InPredicate(com.blazebit.persistence.parser.predicate.InPredicate) ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate) MemberOfPredicate(com.blazebit.persistence.parser.predicate.MemberOfPredicate)

Example 12 with CompoundPredicate

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);
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 13 with CompoundPredicate

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);
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 14 with CompoundPredicate

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;
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate)

Example 15 with CompoundPredicate

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;
}
Also used : CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) GePredicate(com.blazebit.persistence.parser.predicate.GePredicate) BinaryExpressionPredicate(com.blazebit.persistence.parser.predicate.BinaryExpressionPredicate) IsEmptyPredicate(com.blazebit.persistence.parser.predicate.IsEmptyPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) GtPredicate(com.blazebit.persistence.parser.predicate.GtPredicate) LePredicate(com.blazebit.persistence.parser.predicate.LePredicate) IsNullPredicate(com.blazebit.persistence.parser.predicate.IsNullPredicate) BetweenPredicate(com.blazebit.persistence.parser.predicate.BetweenPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate) LtPredicate(com.blazebit.persistence.parser.predicate.LtPredicate) InPredicate(com.blazebit.persistence.parser.predicate.InPredicate) ExistsPredicate(com.blazebit.persistence.parser.predicate.ExistsPredicate) MemberOfPredicate(com.blazebit.persistence.parser.predicate.MemberOfPredicate)

Aggregations

CompoundPredicate (com.blazebit.persistence.parser.predicate.CompoundPredicate)23 Predicate (com.blazebit.persistence.parser.predicate.Predicate)18 EqPredicate (com.blazebit.persistence.parser.predicate.EqPredicate)17 LtPredicate (com.blazebit.persistence.parser.predicate.LtPredicate)12 ExistsPredicate (com.blazebit.persistence.parser.predicate.ExistsPredicate)10 GtPredicate (com.blazebit.persistence.parser.predicate.GtPredicate)10 InPredicate (com.blazebit.persistence.parser.predicate.InPredicate)9 IsNullPredicate (com.blazebit.persistence.parser.predicate.IsNullPredicate)8 GePredicate (com.blazebit.persistence.parser.predicate.GePredicate)7 IsEmptyPredicate (com.blazebit.persistence.parser.predicate.IsEmptyPredicate)7 LePredicate (com.blazebit.persistence.parser.predicate.LePredicate)7 LikePredicate (com.blazebit.persistence.parser.predicate.LikePredicate)7 MemberOfPredicate (com.blazebit.persistence.parser.predicate.MemberOfPredicate)7 BetweenPredicate (com.blazebit.persistence.parser.predicate.BetweenPredicate)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 PathExpression (com.blazebit.persistence.parser.expression.PathExpression)3 PropertyExpression (com.blazebit.persistence.parser.expression.PropertyExpression)3 BinaryExpressionPredicate (com.blazebit.persistence.parser.predicate.BinaryExpressionPredicate)3 RootPredicate (com.blazebit.persistence.impl.builder.predicate.RootPredicate)2