use of com.developmentontheedge.sql.model.AstFunNode in project be5 by DevelopmentOnTheEdge.
the class GenericDbmsTransformer method transformInterval.
private void transformInterval(AstInterval interval) {
SimpleNode mul = interval.jjtGetParent();
if (AstFunNode.isFunction("*").test(mul)) {
String type = interval.getLiteral();
String fn;
switch(type) {
case "1 MONTH":
fn = "ADD_MONTHS";
break;
case "1 DAYS":
case "1 DAY":
fn = "ADD_DAYS";
break;
case "1 MILLISECOND":
fn = "ADD_MILLIS";
break;
default:
throw new IllegalStateException("Unsupported interval format: " + interval.format());
}
SimpleNode content = mul.other(interval);
if (content instanceof AstParenthesis)
content = ((AstParenthesis) content).child(0);
SimpleNode add = mul.jjtGetParent();
if (!AstFunNode.isFunction("+").test(add))
throw new IllegalStateException("Interval grandparent is " + add + ", expected addition");
SimpleNode date = add.other(mul);
AstFunNode addFunction = parserContext.getFunction(fn).node(date, content);
date.pullUpPrefix();
SimpleNode toReplace = add;
if (toReplace.jjtGetParent() instanceof AstParenthesis)
toReplace = toReplace.jjtGetParent();
toReplace.replaceWith(addFunction);
transformDateAdd(addFunction);
}
}
use of com.developmentontheedge.sql.model.AstFunNode in project be5 by DevelopmentOnTheEdge.
the class MacroExpander method expandMacros.
public void expandMacros(SimpleNode node) {
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
SimpleNode child = node.child(i);
expandMacros(child);
if ((child instanceof AstFunNode) && ((AstFunNode) child).getFunction() instanceof BeMacroFunction) {
transformMacroFunction((AstFunNode) child);
}
}
}
use of com.developmentontheedge.sql.model.AstFunNode in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformBitOr.
@Override
protected void transformBitOr(AstFunNode node) {
AstFunNode sum = DefaultParserContext.FUNC_PLUS.node(node.child(0), node.child(1));
node.replaceWith(DefaultParserContext.FUNC_MINUS.node(sum, BITAND.node(node.child(0), node.child(1))));
}
use of com.developmentontheedge.sql.model.AstFunNode in project be5 by DevelopmentOnTheEdge.
the class CategoryFilter method processTableRef.
private void processTableRef(AstTableRef ref) {
String alias = Optional.ofNullable(ref.getAlias()).orElse(entity);
AstFunNode categoryCondition = DefaultParserContext.FUNC_EQ.node(new AstFieldReference(identifier("classifications"), identifier("categoryID")), AstNumericConstant.of(categoryId));
AstFunNode recordCondition = DefaultParserContext.FUNC_EQ.node(new AstFieldReference(identifier("classifications"), identifier("recordID")), new AstFieldReference(identifier(alias), identifier(primaryKeyColumn)));
AstJoin join = JoinType.INNER.node("classifications", DefaultParserContext.FUNC_AND.node(categoryCondition, recordCondition));
ref.appendSibling(join);
}
use of com.developmentontheedge.sql.model.AstFunNode in project be5 by DevelopmentOnTheEdge.
the class MySqlTransformer method transformConcat.
@Override
protected void transformConcat(AstFunNode node) {
if (isConcat(node))
return;
node.setFunction(parserContext.getFunction("concat"));
List<SimpleNode> flatChildren = node.children().flatMap(child -> isConcat(child) ? child.children() : Stream.of(child)).toList();
node.removeChildren();
flatChildren.forEach(node::addChild);
SimpleNode parent = node.jjtGetParent();
if (parent instanceof AstParenthesis)
parent.replaceWith(node);
}
Aggregations