use of com.developmentontheedge.sql.model.AstSelect 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.AstSelect 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.AstSelect 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.AstSelect in project be5 by DevelopmentOnTheEdge.
the class SqlServerTransformer method transformLeastGreatest.
@Override
protected void transformLeastGreatest(AstFunNode node) {
String name = node.getFunction().getName();
AstIdentifierConstant v = new AstIdentifierConstant("V");
Function func;
if ("LEAST".equals(name))
func = parserContext.getFunction("min");
else
func = parserContext.getFunction("max");
AstValues values = new AstValues(0);
for (SimpleNode child : node.children()) values.addChild(new AstParenthesis(child));
AstTableRef tableRef = new AstTableRef(new AstParenthesis(values), new AstIdentifierConstant(name), new AstColumnList(v));
node.replaceWith(new AstParenthesis(new AstSelect(new AstSelectList(func.node(v)), new AstFrom(tableRef))));
}
use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.
the class AstTest method selectCount.
@Test
public void selectCount() {
AstSelect users = Ast.selectCount().from("users");
assertEquals("SELECT COUNT(*) AS \"count\" FROM users", users.format());
}
Aggregations