use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class FilterApplier method addFilter.
public void addFilter(AstQuery query, Map<ColumnRef, Object> conditions) {
if (conditions.size() == 0)
return;
AstWhere where = new AstWhere();
if (query.jjtGetNumChildren() == 1) {
AstSelect select = (AstSelect) query.child(0);
if (select.getWhere() != null)
where = select.getWhere();
else
select.where(where);
} else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
select.where(where);
query.replaceWith(new AstQuery(select));
}
addWhere(where, conditions);
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class FilterApplier method setFilter.
public void setFilter(AstStart ast, Map<ColumnRef, Object> conditions) {
AstQuery query = ast.getQuery();
dropOldConditions(query);
if (conditions.size() == 0)
return;
AstWhere where = new AstWhere();
addWhere(where, conditions);
if (query.jjtGetNumChildren() == 1)
((AstSelect) query.child(0)).where(where);
else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
AstSelect select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
select.where(where);
query.replaceWith(new AstQuery(select));
}
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class ColumnAdder method addColumn.
/**
* Add a column to the main query with given alias. Do nothing if something with given alias already present
* (even if something else is in the columnName).
*
* @param ast AST to modify (clone it if necessary)
* @param tableName tableName to look for
* @param columnName column name to add to select list
* @param alias alias to use/search for
* @throws IllegalArgumentException if given AST has no such table in the FROM field
*/
public void addColumn(AstStart ast, String tableName, String columnName, String alias) {
AstQuery query = ast.getQuery();
AstSelect firstSelect = query.children().select(AstSelect.class).findFirst().get();
if (firstSelect.getSelectList().children().select(AstDerivedColumn.class).anyMatch(dc -> alias.equalsIgnoreCase(dc.getAlias())))
return;
query.children().select(AstSelect.class).forEach(select -> processSelect(select, tableName, columnName, alias));
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method countFromQuery.
private void countFromQuery(AstQuery query) {
AstSelect select = Ast.selectCount().from(AstTableRef.as(new AstParenthesis(query.clone()), new AstIdentifierConstant("data", true)));
query.replaceWith(new AstQuery(select));
}
use of com.developmentontheedge.sql.model.AstQuery in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method hasColumnWithLabel.
private boolean hasColumnWithLabel(AstStart ast, String idColumnLabel) {
AstQuery query = ast.getQuery();
Optional<AstSelect> selectOpt = query.children().select(AstSelect.class).collect(MoreCollectors.onlyOne());
if (!selectOpt.isPresent())
return false;
AstSelect select = selectOpt.get();
return select.getSelectList().children().select(AstDerivedColumn.class).map(AstDerivedColumn::getAlias).nonNull().map(alias -> alias.replaceFirst("^\"(.+)\"$", "$1")).has(idColumnLabel);
}
Aggregations