Search in sources :

Example 1 with LikePredicate

use of com.blazebit.persistence.parser.predicate.LikePredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testLikeEscapeLiteral.

@Test
public void testLikeEscapeLiteral() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN a.x LIKE 'abc' ESCAPE 'x' THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new LikePredicate(path("a", "x"), _string("abc"), true, 'x'), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate) Test(org.junit.Test)

Example 2 with LikePredicate

use of com.blazebit.persistence.parser.predicate.LikePredicate in project blaze-persistence by Blazebit.

the class EqualityCheckingVisitor method visit.

@Override
public Boolean visit(LikePredicate predicate) {
    if (referenceExpression.getClass() != predicate.getClass()) {
        return Boolean.TRUE;
    }
    LikePredicate referencePredicate = (LikePredicate) referenceExpression;
    if (referencePredicate.isNegated() != predicate.isNegated()) {
        return Boolean.TRUE;
    }
    referenceExpression = referencePredicate.getLeft();
    if (predicate.getLeft().accept(this)) {
        return Boolean.TRUE;
    }
    referenceExpression = referencePredicate.getRight();
    if (predicate.getRight().accept(this)) {
        return Boolean.TRUE;
    }
    referenceExpression = referencePredicate.getEscapeCharacter();
    if (referenceExpression == null && predicate.getEscapeCharacter() == null) {
        return Boolean.TRUE;
    }
    return referenceExpression != null && predicate.getEscapeCharacter() != null && predicate.getEscapeCharacter().accept(this);
}
Also used : LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate)

Example 3 with LikePredicate

use of com.blazebit.persistence.parser.predicate.LikePredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testNotLike.

@Test
public void testNotLike() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN a.x NOT LIKE 'abc' THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new LikePredicate(path("a", "x"), _string("abc"), true, (Expression) null, true), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate) Test(org.junit.Test)

Example 4 with LikePredicate

use of com.blazebit.persistence.parser.predicate.LikePredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testLike.

@Test
public void testLike() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN a.x LIKE 'abc' THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new LikePredicate(path("a", "x"), _string("abc"), true, (Expression) null), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate) Test(org.junit.Test)

Example 5 with LikePredicate

use of com.blazebit.persistence.parser.predicate.LikePredicate in project blaze-persistence by Blazebit.

the class GeneralParserTest method testLikeEscapeParameter.

@Test
public void testLikeEscapeParameter() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN a.x LIKE 'abc' ESCAPE :x THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new LikePredicate(path("a", "x"), _string("abc"), true, parameter("x")), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : LikePredicate(com.blazebit.persistence.parser.predicate.LikePredicate) Test(org.junit.Test)

Aggregations

LikePredicate (com.blazebit.persistence.parser.predicate.LikePredicate)5 Test (org.junit.Test)4