Search in sources :

Example 1 with ColumnAdder

use of com.developmentontheedge.sql.format.ColumnAdder in project be5 by DevelopmentOnTheEdge.

the class Be5QueryExecutor method getFinalSql.

@Override
public String getFinalSql() {
    DebugQueryLogger dql = new DebugQueryLogger();
    dql.log("Orig", query.getQuery());
    String queryText = meta.getQueryCode(query, UserInfoHolder.getCurrentRoles());
    dql.log("After FreeMarker", queryText);
    if (queryText.isEmpty())
        return "";
    AstStart ast;
    try {
        ast = SqlQuery.parse(queryText);
    } catch (RuntimeException e) {
        log.log(Level.SEVERE, "SqlQuery.parse error: ", e);
        throw Be5Exception.internalInQuery(e, query);
    // ast = SqlQuery.parse("select 'error'");
    }
    dql.log("Compiled", ast);
    resolveTypeOfRefColumn(ast);
    // CONTEXT
    // FILTERS
    filterHelper.applyFilters(ast, query.getEntity().getName(), new HashMap<>(parametersMap));
    // CATEGORY
    // applyCategory( dql, ast );
    contextApplier.applyContext(ast);
    subQueryKeys = contextApplier.subQueryKeys().toSet();
    dql.log("With context", ast);
    // ID COLUMN
    if (query.getType() == QueryType.D1 && query.getEntity().findTableDefinition() != null && !hasColumnWithLabel(ast, DatabaseConstants.ID_COLUMN_LABEL)) {
        new ColumnAdder().addColumn(ast, query.getEntity().getName(), query.getEntity().getPrimaryKey(), DatabaseConstants.ID_COLUMN_LABEL);
        dql.log("With ID column", ast);
    } else {
        dql.log("Without ID column", ast);
    }
    // SIMPLIFY
    Simplifier.simplify(ast);
    dql.log("Simplified", ast);
    if (extraQuery == ExtraQuery.COUNT) {
        countFromQuery(ast.getQuery());
        dql.log("Count(1) from query", ast);
    }
    if (extraQuery == ExtraQuery.DEFAULT) {
        // SORT ORDER
        applySort(dql, ast);
        // LIMITS
        new LimitsApplier(offset, limit).transform(ast);
        dql.log("With limits", ast);
    }
    return new Formatter().format(ast, context, parserContext);
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ColumnAdder(com.developmentontheedge.sql.format.ColumnAdder) Formatter(com.developmentontheedge.sql.format.Formatter) LimitsApplier(com.developmentontheedge.sql.format.LimitsApplier)

Example 2 with ColumnAdder

use of com.developmentontheedge.sql.format.ColumnAdder in project be5 by DevelopmentOnTheEdge.

the class ColumnAdderTest method check.

protected void check(String tableName, String columnName, String query, String expected) {
    AstStart ast = parse(query);
    new ColumnAdder().addColumn(ast, tableName, columnName, "___ID");
    assertEquals(expected, ast.format());
}
Also used : AstStart(com.developmentontheedge.sql.model.AstStart) ColumnAdder(com.developmentontheedge.sql.format.ColumnAdder)

Aggregations

ColumnAdder (com.developmentontheedge.sql.format.ColumnAdder)2 AstStart (com.developmentontheedge.sql.model.AstStart)2 Formatter (com.developmentontheedge.sql.format.Formatter)1 LimitsApplier (com.developmentontheedge.sql.format.LimitsApplier)1