use of com.developmentontheedge.sql.model.AstTableRef 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.AstTableRef 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.AstTableRef 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.AstTableRef 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.AstTableRef in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformSelect.
@Override
protected void transformSelect(AstSelect select) {
super.transformSelect(select);
AstLimit limit = select.getLimit();
if (limit != null) {
select.dropLimit();
SimpleNode parent = select.jjtGetParent();
int idx = parent.indexOf(select);
AstTableRef tableRef = new AstTableRef(select);
AstFrom from = new AstFrom(tableRef);
AstWhere where = new AstWhere();
AstFunNode less = parserContext.getFunction("<=").node(new AstIdentifierConstant("ROWNUM"), AstNumericConstant.of(limit.getLimit() + limit.getOffset()));
where.addChild(less);
if (limit.getOffset() == 0) {
AstSelect newSelect = new AstSelect(new AstSelectList(), from, where);
parent.jjtAddChild(newSelect, idx);
} else {
AstSelectList list = new AstSelectList();
list.addChild(new AstFieldReference(new AstIdentifierConstant("tmp"), new AstIdentifierConstant("*,")));
list.addChild(new AstIdentifierConstant("ROWNUM rn"));
tableRef.addChild(new AstIdentifierConstant("tmp"));
AstSelect innerSelect = new AstSelect(list, from, where);
AstWhere outerWhere = new AstWhere();
AstFunNode more = parserContext.getFunction(">").node(new AstIdentifierConstant("ROWNUM"), AstNumericConstant.of(limit.getOffset()));
outerWhere.addChild(more);
AstSelect outerSelect = new AstSelect(select.getSelectList(), new AstFrom(new AstTableRef(innerSelect)), outerWhere);
parent.jjtAddChild(outerSelect, idx);
}
}
}
Aggregations