use of com.developmentontheedge.sql.model.AstSelect 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);
}
use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.
the class EntityModelBase method getColumns.
@Override
public RecordModel getColumns(List<String> columns, Map<String, ? super Object> conditions) {
Objects.requireNonNull(conditions);
AstSelect sql = Ast.select(addPrimaryKeyColumnIfNotEmpty(columns)).from(entity.getName()).where(conditions);
DynamicPropertySet dps = db.select(sql.format(), rs -> {
DynamicPropertySet newDps = new DynamicPropertySetSupport();
dpsHelper.addDpWithoutTags(newDps, entity, rs);
return newDps;
}, conditions.values().toArray());
return dps == null ? null : new RecordModelBase(this, dps);
}
use of com.developmentontheedge.sql.model.AstSelect 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.AstSelect 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);
}
}
}
use of com.developmentontheedge.sql.model.AstSelect 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);
}
Aggregations