use of com.developmentontheedge.sql.model.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformSelect.
@Override
protected void transformSelect(AstSelect select) {
super.transformSelect(select);
AstLimit limit = select.getLimit();
if (limit != null) {
select.dropLimit();
SimpleNode parent = select.jjtGetParent();
int idx = parent.indexOf(select);
AstTableRef tableRef = new AstTableRef(select);
AstFrom from = new AstFrom(tableRef);
AstWhere where = new AstWhere();
AstFunNode less = parserContext.getFunction("<=").node(new AstIdentifierConstant("ROWNUM"), AstNumericConstant.of(limit.getLimit() + limit.getOffset()));
where.addChild(less);
if (limit.getOffset() == 0) {
AstSelect newSelect = new AstSelect(new AstSelectList(), from, where);
parent.jjtAddChild(newSelect, idx);
} else {
AstSelectList list = new AstSelectList();
list.addChild(new AstFieldReference(new AstIdentifierConstant("tmp"), new AstIdentifierConstant("*,")));
list.addChild(new AstIdentifierConstant("ROWNUM rn"));
tableRef.addChild(new AstIdentifierConstant("tmp"));
AstSelect innerSelect = new AstSelect(list, from, where);
AstWhere outerWhere = new AstWhere();
AstFunNode more = parserContext.getFunction(">").node(new AstIdentifierConstant("ROWNUM"), AstNumericConstant.of(limit.getOffset()));
outerWhere.addChild(more);
AstSelect outerSelect = new AstSelect(select.getSelectList(), new AstFrom(new AstTableRef(innerSelect)), outerWhere);
parent.jjtAddChild(outerSelect, idx);
}
}
}
use of com.developmentontheedge.sql.model.SimpleNode 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.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class PostgreSqlTransformer method transformLastDay.
@Override
protected void transformLastDay(AstFunNode node) {
Function opPlus = DefaultParserContext.FUNC_PLUS;
Function opMinus = DefaultParserContext.FUNC_MINUS;
SimpleNode dateTrunc = parserContext.getFunction("date_trunc").node(new AstStringConstant("MONTH"), node.child(0));
AstInterval monthInterval = new AstInterval(new AstStringConstant("1 MONTH"));
AstInterval dayInterval = new AstInterval(new AstStringConstant("1 DAY"));
SimpleNode expr = opPlus.node(dateTrunc, opMinus.node(monthInterval, dayInterval));
node.replaceWith(new AstCast(expr, "DATE"));
}
use of com.developmentontheedge.sql.model.SimpleNode 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.SimpleNode in project be5 by DevelopmentOnTheEdge.
the class Simplifier method simplifyNot.
private static void simplifyNot(AstBooleanNot node) {
node.children().toList().forEach(Simplifier::simplifyBoolean);
if (node.jjtGetNumChildren() == 1) {
SimpleNode child = node.child(0);
String childStr = child.format().trim();
if (childStr.equals("TRUE"))
child.replaceWith(new AstIdentifierConstant("FALSE"));
else if (childStr.equals("FALSE"))
child.replaceWith(new AstIdentifierConstant("TRUE"));
}
}
Aggregations