use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
SimpleNode date = node.child(0);
SimpleNode number = node.child(1);
String name = node.getFunction().getName();
if (name.equalsIgnoreCase("add_days"))
node.replaceWith(new AstParenthesis(DefaultParserContext.FUNC_PLUS.node(new AstParenthesis(date), new AstParenthesis(number))));
if (name.equalsIgnoreCase("add_millis"))
node.replaceWith(new AstParenthesis(DefaultParserContext.FUNC_PLUS.node(date, new AstParenthesis(DefaultParserContext.FUNC_DIVIDE.node(number, AstNumericConstant.of(86400000))))));
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class OrderByFilter method apply.
public void apply(AstQuery query, Map<String, String> columns) {
AstOrderBy orderBy = new AstOrderBy();
apply(columns, query, orderBy);
query.children().select(AstSelect.class).forEach(AstSelect::dropOrder);
AstSelect select;
if (query.jjtGetNumChildren() == 1)
select = (AstSelect) query.child(0);
else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
query.replaceWith(new AstQuery(select));
}
select.addChild(orderBy);
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class PostgreSqlTransformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
Function opPlus = DefaultParserContext.FUNC_PLUS;
Function opTimes = DefaultParserContext.FUNC_TIMES;
SimpleNode date = node.child(0);
SimpleNode number = new AstParenthesis(node.child(1));
String name = node.getFunction().getName();
String type = name.equalsIgnoreCase("add_months") ? "1 MONTH" : name.equalsIgnoreCase("add_days") ? "1 DAY" : "1 MILLISECOND";
AstInterval interval = new AstInterval(new AstStringConstant(type));
node.replaceWith(new AstParenthesis(opPlus.node(date, opTimes.node(interval, number))));
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method transformDateAdd.
@Override
protected void transformDateAdd(AstFunNode node) {
Function opPlus = DefaultParserContext.FUNC_PLUS;
Function opTimes = DefaultParserContext.FUNC_TIMES;
SimpleNode date = node.child(0);
SimpleNode number = node.child(1);
String name = node.getFunction().getName();
String type = name.equalsIgnoreCase("add_months") ? "MONTHS" : name.equalsIgnoreCase("add_days") ? "DAYS" : "MICROSECONDS";
if (type.equals("MICROSECONDS"))
number = new AstParenthesis(opTimes.node(number, AstNumericConstant.of(1000)));
node.replaceWith(new AstParenthesis(opPlus.node(date, new AstFirstDayOf(number, type))));
}
use of com.developmentontheedge.sql.model.AstParenthesis in project be5 by DevelopmentOnTheEdge.
the class FilterApplier method addWhere.
private void addWhere(AstWhere where, Map<ColumnRef, Object> conditions) {
if (where.jjtGetNumChildren() != 0) {
if (!AstFunNode.isFunction(DefaultParserContext.AND_LIT).test(where.child(0))) {
AstFunNode and = DefaultParserContext.FUNC_AND.node();
for (SimpleNode child : where.children()) and.addChild(child instanceof AstBooleanExpression ? new AstParenthesis(child) : child);
where.removeChildren();
where.addChild(and);
}
setConditions(where.child(0), conditions);
} else if (conditions.size() > 1) {
where.addChild(DefaultParserContext.FUNC_AND.node());
setConditions(where.child(0), conditions);
} else
setConditions(where, conditions);
}
Aggregations