Search in sources :

Example 1 with AstBeSqlVar

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

the class ContextApplier method applyVars.

/**
 * todo rename getSubQuery
 */
public AstBeSqlSubQuery applyVars(String key, Function<String, String> varResolver) {
    AstBeSqlSubQuery subQuery = context.getSubQueries().get(key);
    if (subQuery == null)
        return null;
    AstBeSqlSubQuery result = (AstBeSqlSubQuery) subQuery.clone();
    if (result.getLimit() != null)
        new LimitsApplier(0, result.getLimit()).transformQuery(result.getQuery());
    applyFirstLevelVars(1, result, (AstBeSqlVar node) -> applyVar(key, node, varResolver));
    // result.tree().select( AstBeSqlVar.class ).forEach( varNode -> {
    // String value = varResolver.apply( subQuery.translateVar( varNode.getName() ) );
    // if( value == null )
    // value = varNode.getDefault();
    // SimpleNode constant;
    // 
    // if(varNode.jjtGetParent() instanceof AstBeSqlSubQuery && value != null && !"".equals(value.trim()))
    // {
    // constant = SqlQuery.parse(value).getQuery();
    // }
    // else
    // {
    // if(value == null)
    // {
    // value = "null";
    // }
    // constant = varNode.jjtGetParent() instanceof AstStringConstant ? new AstStringPart(value)
    // : new AstIdentifierConstant(value);
    // }
    // 
    // varNode.replaceWith( constant );
    // } );
    checkExpression(result, key, varResolver);
    return result;
}
Also used : AstBeSqlSubQuery(com.developmentontheedge.sql.model.AstBeSqlSubQuery) AstBeSqlVar(com.developmentontheedge.sql.model.AstBeSqlVar)

Example 2 with AstBeSqlVar

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

the class FilterApplier method toNode.

private SimpleNode toNode(Object value) {
    if (SqlTypeUtils.isNumber(value.getClass()))
        return AstNumericConstant.of((Number) value);
    String strValue = value.toString();
    Matcher matcher = BeSqlVar_PATTERN.matcher(strValue);
    if (matcher.find()) {
        return new AstBeSqlVar(matcher.group(1));
    }
    return new AstStringConstant(strValue);
}
Also used : Matcher(java.util.regex.Matcher) AstStringConstant(com.developmentontheedge.sql.model.AstStringConstant) AstBeSqlVar(com.developmentontheedge.sql.model.AstBeSqlVar)

Aggregations

AstBeSqlVar (com.developmentontheedge.sql.model.AstBeSqlVar)2 AstBeSqlSubQuery (com.developmentontheedge.sql.model.AstBeSqlSubQuery)1 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)1 Matcher (java.util.regex.Matcher)1