Search in sources :

Example 11 with AstParenthesis

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))))));
}
Also used : AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 12 with AstParenthesis

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);
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) AstSelectList(com.developmentontheedge.sql.model.AstSelectList) AstQuery(com.developmentontheedge.sql.model.AstQuery) AstOrderBy(com.developmentontheedge.sql.model.AstOrderBy) AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant) AstFrom(com.developmentontheedge.sql.model.AstFrom) AstTableRef(com.developmentontheedge.sql.model.AstTableRef) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis)

Example 13 with AstParenthesis

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))));
}
Also used : PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) Function(com.developmentontheedge.sql.model.Function) AstStringConstant(com.developmentontheedge.sql.model.AstStringConstant) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) AstInterval(com.developmentontheedge.sql.model.AstInterval) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 14 with AstParenthesis

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))));
}
Also used : Function(com.developmentontheedge.sql.model.Function) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstWindowFunction(com.developmentontheedge.sql.model.AstWindowFunction) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstFirstDayOf(com.developmentontheedge.sql.model.AstFirstDayOf)

Example 15 with AstParenthesis

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);
}
Also used : AstBooleanExpression(com.developmentontheedge.sql.model.AstBooleanExpression) AstFunNode(com.developmentontheedge.sql.model.AstFunNode) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Aggregations

AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)17 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)10 AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)7 Function (com.developmentontheedge.sql.model.Function)7 PredefinedFunction (com.developmentontheedge.sql.model.PredefinedFunction)7 AstFrom (com.developmentontheedge.sql.model.AstFrom)6 AstSelect (com.developmentontheedge.sql.model.AstSelect)6 AstQuery (com.developmentontheedge.sql.model.AstQuery)5 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)5 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)5 AstFunNode (com.developmentontheedge.sql.model.AstFunNode)4 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)4 AstInterval (com.developmentontheedge.sql.model.AstInterval)3 AstWindowFunction (com.developmentontheedge.sql.model.AstWindowFunction)3 AstCast (com.developmentontheedge.sql.model.AstCast)2 AstDateAdd (com.developmentontheedge.sql.model.AstDateAdd)2 AstFirstDayOf (com.developmentontheedge.sql.model.AstFirstDayOf)2 AstOrderBy (com.developmentontheedge.sql.model.AstOrderBy)2 AstWhere (com.developmentontheedge.sql.model.AstWhere)2 AstBooleanExpression (com.developmentontheedge.sql.model.AstBooleanExpression)1