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);
}
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());
}
Aggregations