Search in sources :

Example 1 with EqPredicate

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

the class JoinNode method getTreatedJoinNode.

public JoinNode getTreatedJoinNode(EntityType<?> type) {
    // Return this when the treat is an upcast
    if (type.getJavaType().isAssignableFrom(getJavaType())) {
        return this;
    }
    String typeName = type.getJavaType().getName();
    JoinNode treatedNode = treatedJoinNodes.get(typeName);
    if (treatedNode != null) {
        return treatedNode;
    }
    String alias = aliasInfo.getAliasOwner().generateRootAlias(aliasInfo.getAlias());
    TreatedJoinAliasInfo treatedJoinAliasInfo = new TreatedJoinAliasInfo(this, type, alias);
    aliasInfo.getAliasOwner().registerAliasInfo(treatedJoinAliasInfo);
    treatedNode = new JoinNode(treatedJoinAliasInfo);
    List<Predicate> predicates = new ArrayList<>(1);
    predicates.add(new EqPredicate(createExpression(null), treatedNode.createExpression(null)));
    treatedNode.onPredicate = new CompoundPredicate(CompoundPredicate.BooleanOperator.AND, predicates);
    treatedJoinAliasInfo.setJoinNode(treatedNode);
    treatedJoinNodes.put(typeName, treatedNode);
    return treatedNode;
}
Also used : ArrayList(java.util.ArrayList) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate)

Example 2 with EqPredicate

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

the class JoinManager method getArrayExpressionPredicate.

private Predicate getArrayExpressionPredicate(JoinNode joinNode, ArrayExpression arrayExpr) {
    if (arrayExpr.getIndex() instanceof Predicate) {
        return (Predicate) arrayExpr.getIndex();
    } else {
        PathExpression keyPath = new PathExpression(new ArrayList<PathElementExpression>(), true);
        keyPath.getExpressions().add(new PropertyExpression(joinNode.getAliasInfo().getAlias()));
        keyPath.setPathReference(new SimplePathReference(joinNode, null, joinNode.getNodeType()));
        Attribute<?, ?> arrayBaseAttribute = joinNode.getParentTreeNode().getAttribute();
        Expression keyExpression;
        if (arrayBaseAttribute instanceof ListAttribute<?, ?>) {
            keyExpression = new ListIndexExpression(keyPath);
        } else {
            keyExpression = new MapKeyExpression(keyPath);
        }
        return new EqPredicate(keyExpression, arrayExpr.getIndex());
    }
}
Also used : PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) MapKeyExpression(com.blazebit.persistence.parser.expression.MapKeyExpression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) ListIndexExpression(com.blazebit.persistence.parser.expression.ListIndexExpression) Expression(com.blazebit.persistence.parser.expression.Expression) QualifiedExpression(com.blazebit.persistence.parser.expression.QualifiedExpression) TreatExpression(com.blazebit.persistence.parser.expression.TreatExpression) ParameterExpression(com.blazebit.persistence.parser.expression.ParameterExpression) PathExpression(com.blazebit.persistence.parser.expression.PathExpression) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression) ArrayExpression(com.blazebit.persistence.parser.expression.ArrayExpression) FunctionExpression(com.blazebit.persistence.parser.expression.FunctionExpression) SubqueryExpression(com.blazebit.persistence.parser.expression.SubqueryExpression) PathElementExpression(com.blazebit.persistence.parser.expression.PathElementExpression) GeneralCaseExpression(com.blazebit.persistence.parser.expression.GeneralCaseExpression) MapEntryExpression(com.blazebit.persistence.parser.expression.MapEntryExpression) MapValueExpression(com.blazebit.persistence.parser.expression.MapValueExpression) MapKeyExpression(com.blazebit.persistence.parser.expression.MapKeyExpression) ListIndexExpression(com.blazebit.persistence.parser.expression.ListIndexExpression) PropertyExpression(com.blazebit.persistence.parser.expression.PropertyExpression) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) ListAttribute(javax.persistence.metamodel.ListAttribute) EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Predicate(com.blazebit.persistence.parser.predicate.Predicate) CompoundPredicate(com.blazebit.persistence.parser.predicate.CompoundPredicate)

Example 3 with EqPredicate

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

the class GeneralParserTest method testNot2.

@Test
public void testNot2() {
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN NOT(localized[:locale].name = localized[:locale].description) THEN 0 ELSE 1 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new EqPredicate(path("localized[:locale]", "name"), path("localized[:locale]", "description"), true), _int("0"))), _int("1"));
    assertEquals(expected, result);
}
Also used : EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 4 with EqPredicate

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

the class GeneralParserTest method testEnumCompare.

@Test
public void testEnumCompare() {
    enumTypes.put(TestEnum.class.getName(), (Class<Enum<?>>) (Class<?>) TestEnum.class);
    GeneralCaseExpression result = (GeneralCaseExpression) parse("CASE WHEN archived = " + TestEnum.class.getName() + ".ABC THEN 1 ELSE 2 END");
    GeneralCaseExpression expected = new GeneralCaseExpression(Arrays.asList(new WhenClauseExpression(new EqPredicate(path("archived"), _enum(TestEnum.ABC)), _int("1"))), _int("2"));
    assertEquals(expected, result);
}
Also used : EqPredicate(com.blazebit.persistence.parser.predicate.EqPredicate) Test(org.junit.Test)

Example 5 with EqPredicate

use of com.blazebit.persistence.parser.predicate.EqPredicate 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)

Aggregations

EqPredicate (com.blazebit.persistence.parser.predicate.EqPredicate)25 Test (org.junit.Test)20 CompoundPredicate (com.blazebit.persistence.parser.predicate.CompoundPredicate)8 GeneralCaseExpression (com.blazebit.persistence.parser.expression.GeneralCaseExpression)6 Predicate (com.blazebit.persistence.parser.predicate.Predicate)6 WhenClauseExpression (com.blazebit.persistence.parser.expression.WhenClauseExpression)5 PathExpression (com.blazebit.persistence.parser.expression.PathExpression)4 LtPredicate (com.blazebit.persistence.parser.predicate.LtPredicate)4 Expression (com.blazebit.persistence.parser.expression.Expression)3 FunctionExpression (com.blazebit.persistence.parser.expression.FunctionExpression)3 PathElementExpression (com.blazebit.persistence.parser.expression.PathElementExpression)3 PropertyExpression (com.blazebit.persistence.parser.expression.PropertyExpression)3 SubqueryExpression (com.blazebit.persistence.parser.expression.SubqueryExpression)3 ArrayList (java.util.ArrayList)3 ListIndexExpression (com.blazebit.persistence.parser.expression.ListIndexExpression)2 MapEntryExpression (com.blazebit.persistence.parser.expression.MapEntryExpression)2 MapKeyExpression (com.blazebit.persistence.parser.expression.MapKeyExpression)2 TreatExpression (com.blazebit.persistence.parser.expression.TreatExpression)2 GtPredicate (com.blazebit.persistence.parser.predicate.GtPredicate)2 InPredicate (com.blazebit.persistence.parser.predicate.InPredicate)2