use of org.apache.jena.sparql.syntax.ElementNamedGraph in project jena by apache.
the class UpdateEngineWorker method visit.
@Override
public void visit(UpdateModify update) {
Node withGraph = update.getWithIRI();
Element elt = update.getWherePattern();
// null or a dataset for USING clause.
// USING/USING NAMED
DatasetGraph dsg = processUsing(update);
// USING overrides WITH
if (dsg == null && withGraph != null) {
// Subtle difference : WITH <uri>... WHERE {}
// and an empty/unknown graph <uri>
// rewrite with GRAPH -> no match.
// redo as dataset with different default graph -> match
// SPARQL is unclear about what happens when the graph does not exist.
// but the rewrite with ElementNamedGraph is closer to SPARQL.
// Better, treat as
// WHERE { GRAPH <with> { ... } }
// This is the SPARQL wording (which is a bit loose).
elt = new ElementNamedGraph(withGraph, elt);
}
if (dsg == null)
dsg = datasetGraph;
Query query = elementToQuery(elt);
ThresholdPolicy<Binding> policy = ThresholdPolicyFactory.policyFromContext(datasetGraph.getContext());
DataBag<Binding> db = BagFactory.newDefaultBag(policy, SerializationFactoryFinder.bindingSerializationFactory());
try {
Iterator<Binding> bindings = evalBindings(query, dsg, inputBinding, context);
if (false) {
List<Binding> x = Iter.toList(bindings);
System.out.printf("====>> Bindings (%d)\n", x.size());
Iter.print(System.out, x.iterator());
System.out.println("====<<");
bindings = Iter.iter(x);
}
db.addAll(bindings);
Iter.close(bindings);
Iterator<Binding> it = db.iterator();
execDelete(datasetGraph, update.getDeleteQuads(), withGraph, it);
Iter.close(it);
Iterator<Binding> it2 = db.iterator();
execInsert(datasetGraph, update.getInsertQuads(), withGraph, it2);
Iter.close(it2);
} finally {
db.close();
}
}
use of org.apache.jena.sparql.syntax.ElementNamedGraph in project jena by apache.
the class UpdateEngineWorker method elementFromQuads.
protected Element elementFromQuads(List<Quad> quads) {
ElementGroup el = new ElementGroup();
ElementTriplesBlock x = new ElementTriplesBlock();
// Maybe empty??
el.addElement(x);
Node g = Quad.defaultGraphNodeGenerated;
for (Quad q : quads) {
if (q.getGraph() != g) {
g = q.getGraph();
x = new ElementTriplesBlock();
if (g == null || g == Quad.defaultGraphNodeGenerated)
el.addElement(x);
else {
ElementNamedGraph eng = new ElementNamedGraph(g, x);
el.addElement(eng);
}
}
x.addTriple(q.asTriple());
}
return el;
}
use of org.apache.jena.sparql.syntax.ElementNamedGraph in project jena by apache.
the class ARQParserBase method createQueryPattern.
protected ElementGroup createQueryPattern(Template t) {
ElementGroup elg = new ElementGroup();
Map<Node, BasicPattern> graphs = t.getGraphPattern();
for (Node n : graphs.keySet()) {
Element el = new ElementPathBlock(graphs.get(n));
if (!Quad.defaultGraphNodeGenerated.equals(n)) {
ElementGroup e = new ElementGroup();
e.addElement(el);
el = new ElementNamedGraph(n, e);
}
elg.addElement(el);
}
return elg;
}
Aggregations