Search in sources :

Example 1 with ElementNamedGraph

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();
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) Query(org.apache.jena.query.Query) Node(org.apache.jena.graph.Node) Element(org.apache.jena.sparql.syntax.Element)

Example 2 with ElementNamedGraph

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;
}
Also used : ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) Node(org.apache.jena.graph.Node) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 3 with ElementNamedGraph

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;
}
Also used : ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) Node(org.apache.jena.graph.Node) Element(org.apache.jena.sparql.syntax.Element) BasicPattern(org.apache.jena.sparql.core.BasicPattern) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock)

Aggregations

Node (org.apache.jena.graph.Node)3 ElementNamedGraph (org.apache.jena.sparql.syntax.ElementNamedGraph)3 Element (org.apache.jena.sparql.syntax.Element)2 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)2 Query (org.apache.jena.query.Query)1 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)1 ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)1