Java Code Examples for org.apache.jena.query.Query#getHavingExprs()

The following examples show how to use org.apache.jena.query.Query#getHavingExprs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SelectQueryPartialCopyVisitor.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitHaving(final Query query) {
    if (query.hasHaving()) {
        for (Expr expr : query.getHavingExprs()) {
            output.addHavingCondition(expr);
        }
    }
}
 
Example 2
Source File: SelectExtractionVisitor.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitHaving(final Query query) {
    if (query.hasHaving()) {
    	isDummyQuery = false;
        for (Expr expr : query.getHavingExprs()) {
            output.addHavingCondition(expr);
        }
    }
}
 
Example 3
Source File: SPARQLExtQuerySerializer.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
@Override
public void visitHaving(Query query) {
    if (query.hasHaving()) {
        out.print("HAVING");
        for (Expr expr : query.getHavingExprs()) {
            out.print(" ");
            fmtExpr.format(expr);
        }
        out.println();
    }
}
 
Example 4
Source File: JenaUtil.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Temp patch for a bug in Jena's syntaxtransform, also applying substitutions on
 * HAVING clauses.
 * @param query  the Query to transform
 * @param substitutions  the variable bindings
 * @return a new Query with the bindings applied
 */
public static Query queryWithSubstitutions(Query query, final Map<Var, Node> substitutions) {
	Query result = QueryTransformOps.transform(query, substitutions);
	
	// TODO: Replace this hack once there is a Jena patch
	if(result.hasHaving()) {
		NodeTransform nodeTransform = new NodeTransform() {
		    @Override
		    public Node apply(Node node) {
		        Node n = substitutions.get(node) ;
		        if ( n == null ) {
		            return node ;
		        }
		        return n ;
		    }
		};
        ElementTransform eltrans = new ElementTransformSubst(substitutions) ;
        ExprTransform exprTrans = new ExprTransformNodeElement(nodeTransform, eltrans) ;
		List<Expr> havingExprs = result.getHavingExprs();
		for(int i = 0; i < havingExprs.size(); i++) {
			Expr old = havingExprs.get(i);
            Expr neo = ExprTransformer.transform(exprTrans, old) ;
            if ( neo != old ) {
            	havingExprs.set(i, neo);
            }
		}
	}
	return result;
}