Search in sources :

Example 1 with AstIdentifierConstant

use of com.developmentontheedge.sql.model.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.

the class ContextApplier method applyDictionary.

private void applyDictionary(AstBeDictionary child) {
    String value = context.getDictionaryValue(child.getTagName(), child.getName(), child.getParameters());
    child.replaceWith(new AstIdentifierConstant(value));
}
Also used : AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant)

Example 2 with AstIdentifierConstant

use of com.developmentontheedge.sql.model.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.

the class FilterApplier method addFilter.

public void addFilter(AstQuery query, Map<ColumnRef, Object> conditions) {
    if (conditions.size() == 0)
        return;
    AstWhere where = new AstWhere();
    if (query.jjtGetNumChildren() == 1) {
        AstSelect select = (AstSelect) query.child(0);
        if (select.getWhere() != null)
            where = select.getWhere();
        else
            select.where(where);
    } else {
        AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
        AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
        select.where(where);
        query.replaceWith(new AstQuery(select));
    }
    addWhere(where, conditions);
}
Also used : AstWhere(com.developmentontheedge.sql.model.AstWhere) AstSelect(com.developmentontheedge.sql.model.AstSelect) AstSelectList(com.developmentontheedge.sql.model.AstSelectList) AstQuery(com.developmentontheedge.sql.model.AstQuery) 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 3 with AstIdentifierConstant

use of com.developmentontheedge.sql.model.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.

the class FilterApplier method setFilter.

public void setFilter(AstStart ast, Map<ColumnRef, Object> conditions) {
    AstQuery query = ast.getQuery();
    dropOldConditions(query);
    if (conditions.size() == 0)
        return;
    AstWhere where = new AstWhere();
    addWhere(where, conditions);
    if (query.jjtGetNumChildren() == 1)
        ((AstSelect) query.child(0)).where(where);
    else {
        AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
        AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
        select.where(where);
        query.replaceWith(new AstQuery(select));
    }
}
Also used : AstWhere(com.developmentontheedge.sql.model.AstWhere) AstSelect(com.developmentontheedge.sql.model.AstSelect) AstQuery(com.developmentontheedge.sql.model.AstQuery) AstSelectList(com.developmentontheedge.sql.model.AstSelectList) 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 4 with AstIdentifierConstant

use of com.developmentontheedge.sql.model.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.

the class SqlServerTransformer method transformDateAdd.

@Override
protected void transformDateAdd(AstFunNode node) {
    SimpleNode date = node.child(0);
    SimpleNode number = node.child(1);
    String name = node.getFunction().getName();
    String type = name.equalsIgnoreCase("add_months") ? "MONTH" : name.equalsIgnoreCase("add_days") ? "DAY" : "MILLISECOND";
    node.replaceWith(DATEADD.node(new AstIdentifierConstant(type), number, date));
}
Also used : AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 5 with AstIdentifierConstant

use of com.developmentontheedge.sql.model.AstIdentifierConstant in project be5 by DevelopmentOnTheEdge.

the class SqlServerTransformer method transformDateTrunc.

@Override
protected void transformDateTrunc(AstFunNode node) {
    AstStringConstant child = (AstStringConstant) node.child(0);
    String dateformat = child.getValueUnescaped();
    AstIdentifierConstant datepart = new AstIdentifierConstant(dateformat);
    AstNumericConstant date = AstNumericConstant.of(0);
    node.replaceWith(DATEADD.node(datepart, DATEDIFF.node(datepart, date, node.child(1)), date));
}
Also used : AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant) AstNumericConstant(com.developmentontheedge.sql.model.AstNumericConstant) AstStringConstant(com.developmentontheedge.sql.model.AstStringConstant)

Aggregations

AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)19 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)11 AstSelect (com.developmentontheedge.sql.model.AstSelect)10 AstFrom (com.developmentontheedge.sql.model.AstFrom)8 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)8 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)8 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)6 AstFunNode (com.developmentontheedge.sql.model.AstFunNode)5 AstQuery (com.developmentontheedge.sql.model.AstQuery)5 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)5 AstWhere (com.developmentontheedge.sql.model.AstWhere)5 AstLimit (com.developmentontheedge.sql.model.AstLimit)4 AstWindowFunction (com.developmentontheedge.sql.model.AstWindowFunction)4 AstFieldReference (com.developmentontheedge.sql.model.AstFieldReference)3 AstBetweenPredicate (com.developmentontheedge.sql.model.AstBetweenPredicate)2 AstDerivedColumn (com.developmentontheedge.sql.model.AstDerivedColumn)2 AstStringPart (com.developmentontheedge.sql.model.AstStringPart)2 AstWindowSpecification (com.developmentontheedge.sql.model.AstWindowSpecification)2 Function (com.developmentontheedge.sql.model.Function)2 PredefinedFunction (com.developmentontheedge.sql.model.PredefinedFunction)2