use of org.apache.jena.query.SortCondition in project jena by apache.
the class TransformOrderByDistinctApplication method transform.
@Override
public Op transform(OpDistinct opDistinct, Op subOp) {
if (subOp instanceof OpProject) {
OpProject project = (OpProject) subOp;
// Inner operation must be an ORDER BY
if (project.getSubOp() instanceof OpOrder) {
List<Var> projectVars = project.getVars();
OpOrder order = (OpOrder) project.getSubOp();
// Everything we wish to order by must only use variables that
// appear in the project list
boolean ok = true;
for (SortCondition condition : order.getConditions()) {
if (!isValidSortCondition(condition, projectVars)) {
ok = false;
break;
}
}
// Everything checks out so we can make the change
if (ok) {
OpProject newProject = new OpProject(order.getSubOp(), project.getVars());
OpDistinct newDistinct = new OpDistinct(newProject);
return new OpOrder(newDistinct, order.getConditions());
}
}
}
// If we reach here then this transform is not applicable
return super.transform(opDistinct, subOp);
}
use of org.apache.jena.query.SortCondition in project jena by apache.
the class SolutionModifierHandler method setVars.
@Override
public void setVars(Map<Var, Node> values) {
if (values.isEmpty()) {
return;
}
ExprRewriter exprRewriter = new ExprRewriter(values);
ExprList having = exprRewriter.rewrite(new ExprList(query.getHavingExprs()));
List<SortCondition> orderBy = exprRewriter.rewriteSortConditionList(query.getOrderBy());
VarExprList groupBy = exprRewriter.rewrite(query.getGroupBy());
query.getHavingExprs().clear();
query.getHavingExprs().addAll(having.getList());
if (orderBy != null) {
if (query.getOrderBy() == null) {
for (SortCondition sc : orderBy) {
query.addOrderBy(sc);
}
} else {
query.getOrderBy().clear();
query.getOrderBy().addAll(orderBy);
}
}
query.getGroupBy().clear();
query.getGroupBy().addAll(groupBy);
}
use of org.apache.jena.query.SortCondition in project jena by apache.
the class SolutionModifierHandler method addAll.
/**
* Copy all the modifications from the Solution Modifier argument
* @param solutionModifier The solution modifier to copy from.
*/
public void addAll(SolutionModifierHandler solutionModifier) {
List<SortCondition> lst = solutionModifier.query.getOrderBy();
if (lst != null) {
for (SortCondition sc : lst) {
query.addOrderBy(sc);
}
}
query.getGroupBy().addAll(solutionModifier.query.getGroupBy());
query.getHavingExprs().addAll(solutionModifier.query.getHavingExprs());
query.setLimit(solutionModifier.query.getLimit());
query.setOffset(solutionModifier.query.getOffset());
}
Aggregations