/** Non-reordering execution of a basic graph pattern, given a iterator of bindings as input */ public static QueryIterator execute(GraphTDB graph, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) { // Maybe default graph or named graph. NodeTupleTable ntt = graph.getNodeTupleTable() ; return execute(ntt, graph.getGraphName(), pattern, input, filter, execCxt) ; }
/** The NodeTupleTable for this graph */ public NodeTupleTable getNodeTupleTable() { return getDSG().chooseNodeTupleTable(getGraphName()) ; }
@Override public void clear() { dataset.deleteAny(getGraphName(), Node.ANY, Node.ANY, Node.ANY) ; getEventManager().notifyEvent(this, GraphEvents.removeAll) ; }
/** Execute a BGP (and filters) on a TDB graph, which may be in default storage or it may be a named graph */ private static QueryIterator executeBGP(GraphTDB graph, OpBGP opBGP, QueryIterator input, ExprList exprs, ExecutionContext execCxt) { // Is it the real default graph (normal route or explicitly named)? if ( ! isDefaultGraphStorage(graph.getGraphName())) { // Not default storage - it's a named graph in storage. DatasetGraphTDB ds = graph.getDSG() ; return optimizeExecuteQuads(ds, input, graph.getGraphName(), opBGP.getPattern(), exprs, execCxt) ; } // Execute a BGP on the real default graph return optimizeExecuteTriples(graph, input, opBGP.getPattern(), exprs, execCxt) ; }
@Override public void remove(Node s, Node p, Node o) { if ( getEventManager().listening() ) { // Have to do it the hard way so that triple events happen. super.remove(s, p, o) ; return ; } dataset.deleteAny(getGraphName(), s, p, o) ; // We know no one is listening ... // getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ; } }
@Override public QueryIterator execute(OpBGP opBGP, QueryIterator input) { Graph g = execCxt.getActiveGraph() ; if ( g instanceof GraphTDB ) { BasicPattern bgp = opBGP.getPattern() ; Explain.explain("Execute", bgp, execCxt.getContext()) ; // Triple-backed (but may be named as explicit default graph). //return SolverLib.execute((GraphTDB)g, bgp, input, filter, execCxt) ; GraphTDB gtdb = (GraphTDB)g ; Node gn = decideGraphNode(gtdb.getGraphName(), execCxt) ; return SolverLib.execute(gtdb.getDSG(), gn, bgp, input, filter, execCxt) ; } Log.warn(this, "Non-GraphTDB passed to OpExecutorPlainTDB") ; return super.execute(opBGP, input) ; }
@Override protected final int graphBaseSize() { if ( isDefaultGraph() ) return (int)getNodeTupleTable().size() ; Node gn = getGraphName() ; boolean unionGraph = isUnionGraph(gn) ; gn = unionGraph ? Node.ANY : gn ; Iterator<Tuple<NodeId>> iter = getDSG().getQuadTable().getNodeTupleTable().findAsNodeIds(gn, null, null, null) ; if ( unionGraph ) { iter = Iter.map(iter, project4TupleTo3Tuple) ; iter = Iter.distinctAdjacent(iter) ; } return (int)Iter.count(iter) ; }
@Override protected PrefixMapping createPrefixMapping() { if ( isDefaultGraph() ) return getDSG().getPrefixes().getPrefixMapping() ; if ( isUnionGraph() ) return getDSG().getPrefixes().getPrefixMapping() ; return getDSG().getPrefixes().getPrefixMapping(getGraphName().getURI()) ; }