Search in sources :

Example 1 with AstBeListPlaceHolder

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

the class ContextApplier method applyPlaceHolder.

private void applyPlaceHolder(AstBePlaceHolder placeholderNode) {
    String ph = placeholderNode.getPlaceHolder();
    SimpleNode replacement;
    if (placeholderNode instanceof AstBeListPlaceHolder) {
        AstInValueList list = new AstInValueList(SqlParserTreeConstants.JJTINVALUELIST);
        context.roles().map(AstStringConstant::new).forEach(list::addChild);
        replacement = list;
    } else {
        String rawResult;
        switch(ph) {
            case "username":
                rawResult = context.getUserName();
                break;
            case "timestamp":
                rawResult = String.valueOf(System.currentTimeMillis());
                break;
            default:
                throw new UnsupportedOperationException("Unsupported placeholder: " + ph);
        }
        replacement = new AstStringConstant(rawResult);
    }
    replacement.inheritFrom(placeholderNode);
    placeholderNode.replaceWith(replacement);
}
Also used : AstBeListPlaceHolder(com.developmentontheedge.sql.model.AstBeListPlaceHolder) AstInValueList(com.developmentontheedge.sql.model.AstInValueList) AstStringConstant(com.developmentontheedge.sql.model.AstStringConstant) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Aggregations

AstBeListPlaceHolder (com.developmentontheedge.sql.model.AstBeListPlaceHolder)1 AstInValueList (com.developmentontheedge.sql.model.AstInValueList)1 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)1 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)1