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;
}
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());
}
}
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);
}
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);
}
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);
}
Aggregations