Search in sources :

Example 1 with AstBeParameterTag

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

the class ContextApplier method applyParameterTag.

private void applyParameterTag(SimpleNode newTree, int i, String key, Function<String, String> varResolver) {
    String value;
    SimpleNode replacement;
    AstBeParameterTag paramNode = (AstBeParameterTag) newTree.child(i);
    String multiple = paramNode.getMultiple();
    boolean tableRefAddend = newTree instanceof AstTableRef && i == 1;
    if (multiple == null) {
        value = context.getParameter(paramNode.getName());
        Map<String, String> propertyMap = getSubQueryPropertyMap(key, varResolver);
        if (value == null && propertyMap.containsKey(paramNode.getName())) {
            value = propertyMap.get(paramNode.getName());
        }
        replacement = applyParameters(paramNode, value, tableRefAddend);
    } else {
        if (newTree instanceof AstInValueList) {
            List<String> values = context.getListParameter(paramNode.getName());
            paramNode.replaceWith(StreamEx.of(values).map(val -> applyParameters(paramNode, val, tableRefAddend)).toArray(SimpleNode[]::new));
            return;
        }
        if (!(newTree instanceof AstInPredicate))
            throw new IllegalArgumentException("Parameter Multiple can only be put inside InPredicate");
        AstInValueList list = new AstInValueList(SqlParserTreeConstants.JJTINVALUELIST);
        List<String> values = context.getListParameter(paramNode.getName());
        if (values != null) {
            for (String val : values) {
                list.addChild(applyParameters(paramNode, val, tableRefAddend));
            }
        }
        replacement = list;
    }
    replacement.inheritFrom(paramNode);
    if (tableRefAddend) {
        AstTableRef tableRef = (AstTableRef) newTree;
        tableRef.setTable(tableRef.getTable() + replacement.format());
        tableRef.removeChild(i);
    } else {
        newTree.jjtAddChild(replacement, i);
    }
}
Also used : AstInValueList(com.developmentontheedge.sql.model.AstInValueList) AstInPredicate(com.developmentontheedge.sql.model.AstInPredicate) AstBeParameterTag(com.developmentontheedge.sql.model.AstBeParameterTag) AstTableRef(com.developmentontheedge.sql.model.AstTableRef) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 2 with AstBeParameterTag

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

the class ContextApplier method checkExpression.

private void checkExpression(SimpleNode newTree, String key, Function<String, String> varResolver) {
    for (int i = 0; i < newTree.jjtGetNumChildren(); i++) {
        SimpleNode child = newTree.child(i);
        checkExpression(child, key, varResolver);
        if (child instanceof AstBeCondition)
            i = applyConditions(newTree, i);
        if (child instanceof AstBeParameterTag)
            applyParameterTag(newTree, i, key, varResolver);
        else if (child instanceof AstBePlaceHolder)
            applyPlaceHolder((AstBePlaceHolder) child);
        else if (child instanceof AstBeSessionTag)
            applySessionTag((AstBeSessionTag) child);
        else if (child instanceof AstBeSqlSubQuery)
            applySubQuery((AstBeSqlSubQuery) child);
        else if (child instanceof AstBeSqlAuto)
            applyAutoQuery((AstBeSqlAuto) child);
        else if (child instanceof AstBeConditionChain) {
            applyConditionChain((AstBeConditionChain) child);
            i--;
        } else if (child instanceof AstBeSql)
            applySqlTag((AstBeSql) child);
        else if (child instanceof AstBeDictionary)
            applyDictionary((AstBeDictionary) child);
    }
}
Also used : AstBeCondition(com.developmentontheedge.sql.model.AstBeCondition) AstBePlaceHolder(com.developmentontheedge.sql.model.AstBePlaceHolder) AstBeSessionTag(com.developmentontheedge.sql.model.AstBeSessionTag) AstBeSql(com.developmentontheedge.sql.model.AstBeSql) AstBeConditionChain(com.developmentontheedge.sql.model.AstBeConditionChain) AstBeSqlSubQuery(com.developmentontheedge.sql.model.AstBeSqlSubQuery) AstBeParameterTag(com.developmentontheedge.sql.model.AstBeParameterTag) AstBeSqlAuto(com.developmentontheedge.sql.model.AstBeSqlAuto) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstBeDictionary(com.developmentontheedge.sql.model.AstBeDictionary)

Aggregations

AstBeParameterTag (com.developmentontheedge.sql.model.AstBeParameterTag)2 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)2 AstBeCondition (com.developmentontheedge.sql.model.AstBeCondition)1 AstBeConditionChain (com.developmentontheedge.sql.model.AstBeConditionChain)1 AstBeDictionary (com.developmentontheedge.sql.model.AstBeDictionary)1 AstBePlaceHolder (com.developmentontheedge.sql.model.AstBePlaceHolder)1 AstBeSessionTag (com.developmentontheedge.sql.model.AstBeSessionTag)1 AstBeSql (com.developmentontheedge.sql.model.AstBeSql)1 AstBeSqlAuto (com.developmentontheedge.sql.model.AstBeSqlAuto)1 AstBeSqlSubQuery (com.developmentontheedge.sql.model.AstBeSqlSubQuery)1 AstInPredicate (com.developmentontheedge.sql.model.AstInPredicate)1 AstInValueList (com.developmentontheedge.sql.model.AstInValueList)1 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)1