use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class LimitsApplier method transformQuery.
public boolean transformQuery(AstQuery query) {
if (query.jjtGetNumChildren() == 1) {
AstSelect select = (AstSelect) query.child(0);
if (select.getLimit() != null)
return false;
AstLimit limit = new AstLimit();
limit.setLimit(offset, count);
select.addChild(limit);
} else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
AstLimit limit = new AstLimit();
limit.setLimit(offset, count);
select.addChild(limit);
query.replaceWith(new AstQuery(select));
}
// TODO: support offset, union, etc.
return true;
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class OrderByFilter method apply.
public void apply(AstQuery query, Map<String, String> columns) {
AstOrderBy orderBy = new AstOrderBy();
apply(columns, query, orderBy);
query.children().select(AstSelect.class).forEach(AstSelect::dropOrder);
AstSelect select;
if (query.jjtGetNumChildren() == 1)
select = (AstSelect) query.child(0);
else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
query.replaceWith(new AstQuery(select));
}
select.addChild(orderBy);
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class CountApplier method transform.
public void transform(ParserContext ctx, AstStart ast) {
AstQuery query = ast.getQuery();
query.children().select(AstSelect.class).forEach(AstSelect::dropOrder);
if (query.jjtGetNumChildren() > 1)
throw new UnsupportedOperationException("UNION queries are not supported for COUNT");
AstSelect select = query.children().select(AstSelect.class).findFirst().get();
AstSelectList selectList = select.getSelectList();
selectList.removeChildren();
AstCount countFn = new AstCount();
AstDerivedColumn countNode = new AstDerivedColumn(countFn, "CNT");
countNode.setAsToken(true);
selectList.addChild(countNode);
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class Formatter method format.
public String format(AstQuery start, Context context, ParserContext parserContext) {
DbmsTransformer dbmsTransformer = context.getDbmsTransformer();
dbmsTransformer.setParserContext(parserContext);
AstQuery clone = start.clone();
dbmsTransformer.transformQuery(clone);
return clone.format();
}
Aggregations