Search in sources :

Example 6 with CompoundPredicate

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;
}
Also used : ExpressionListModifier(com.blazebit.persistence.parser.expression.modifier.ExpressionListModifier) 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) BinaryExpressionPredicate(com.blazebit.persistence.parser.predicate.BinaryExpressionPredicate) 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) UnaryExpressionPredicate(com.blazebit.persistence.parser.predicate.UnaryExpressionPredicate) 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 7 with CompoundPredicate

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

Example 8 with CompoundPredicate

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);
}
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 9 with CompoundPredicate

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

Example 10 with CompoundPredicate

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

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