use of com.developmentontheedge.sql.model.AstSelect 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.AstSelect in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method applySort.
private void applySort(DebugQueryLogger dql, AstStart ast) {
if (sortColumn >= 0) {
try {
DynamicProperty[] schema = getSchema(new Formatter().format(ast, context, parserContext));
int sortCol = getQuerySortingColumn(schema);
if (sortCol > 0) {
AstSelect sel = (AstSelect) ast.getQuery().jjtGetChild(ast.getQuery().jjtGetNumChildren() - 1);
AstOrderBy orderBy = sel.getOrderBy();
if (orderBy == null) {
orderBy = new AstOrderBy();
sel.addChild(orderBy);
AstLimit astLimit = sel.children().select(AstLimit.class).findFirst().orElse(null);
if (astLimit != null) {
sel.removeChild(astLimit);
sel.addChild(astLimit);
}
}
AstOrderingElement oe = new AstOrderingElement(AstNumericConstant.of(sortCol));
if (sortDesc) {
oe.setDirectionToken(new Token(0, "DESC"));
}
orderBy.addChild(oe);
orderBy.moveToFront(oe);
}
dql.log("With sort", ast);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.
the class EntityModelBase method count.
@Override
public long count(Map<String, ? super Object> conditions) {
Objects.requireNonNull(conditions);
AstSelect sql = Ast.selectCount().from(entity.getName()).where(conditions);
return db.getLong(sql.format(), conditions.values().toArray());
}
use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.
the class ProvincesRepository method findFirst.
@Override
public Provinces findFirst(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Provinces.class) Closure conditions) {
Map<String, Object> conditionsMap = toMap(conditions);
AstSelect sql = Ast.selectAll().from(entityName).where(conditionsMap);
return db.query(sql.format(), beanHandler, conditionsMap.values().toArray());
}
use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.
the class ProvincesRepository method count.
public Long count(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Provinces.class) final Closure conditions) {
Map<String, Object> conditionsMap = toMap(conditions);
AstSelect sql = Ast.selectCount().from(entityName).where(conditionsMap);
return db.getLong(sql.format(), conditionsMap.values().toArray());
}
Aggregations