private ResultSet execResultSet() { startQueryIterator(); return asResultSet(queryIterator); }
@Override public Iterator<JsonObject> execJsonItems() { checkNotClosed() ; if ( ! query.isJsonType() ) throw new QueryExecException("Attempt to get a JSON result from a " + labelForQuery(query)+" query") ; startQueryIterator() ; return new JsonIterator(queryIterator, query.getResultVars()) ; }
@Override public boolean execAsk() { checkNotClosed(); if ( !query.isAskType() ) throw new QueryExecException("Attempt to have boolean from a " + labelForQuery(query) + " query"); startQueryIterator(); boolean r; try { // Not has next because setting timeout1 which applies to getting // the first result, not testing for it. queryIterator.next(); r = true; } catch (NoSuchElementException ex) { r = false; } this.close(); return r; }
@Override public Iterator<Triple> execConstructTriples() { checkNotClosed(); if ( ! query.isConstructType() ) throw new QueryExecException("Attempt to get a CONSTRUCT model from a "+labelForQuery(query)+" query") ; // This causes there to be no PROJECT around the pattern. // That in turn, exposes the initial bindings. query.setQueryResultStar(true) ; startQueryIterator() ; Template template = query.getConstructTemplate() ; return TemplateLib.calcTriples(template.getTriples(), queryIterator); }
@Override public Iterator<Quad> execConstructQuads() { checkNotClosed(); if ( ! query.isConstructType() ) throw new QueryExecException("Attempt to get a CONSTRUCT model from a "+labelForQuery(query)+" query") ; // This causes there to be no PROJECT around the pattern. // That in turn, exposes the initial bindings. query.setQueryResultStar(true) ; startQueryIterator() ; Template template = query.getConstructTemplate() ; return TemplateLib.calcQuads(template.getQuads(), queryIterator); }
@Override public JsonArray execJson() { checkNotClosed() ; if ( ! query.isJsonType() ) throw new QueryExecException("Attempt to get a JSON result from a " + labelForQuery(query)+" query") ; startQueryIterator() ; JsonArray jsonArray = new JsonArray() ; List<String> resultVars = query.getResultVars() ; while (queryIterator.hasNext()) { Binding binding = queryIterator.next() ; JsonObject jsonObject = new JsonObject() ; for (String resultVar : resultVars) { Node n = binding.get(Var.alloc(resultVar)) ; JsonValue value = RDFTerm2Json.fromNode(n) ; jsonObject.put(resultVar, value) ; } jsonArray.add(jsonObject) ; } return jsonArray ; }