private String graphNameStr() { if ( getGraphName() == null ) return DatasetPrefixesTDB.unnamedGraphURI; if ( getGraphName().isURI() ) return getGraphName().getURI(); if ( getGraphName().isBlank() ) return RiotLib.blankNodeToIri(getGraphName()).getURI(); throw new TDBException("Bad node for graph name: "+getGraphName()); }
private static void loadGraph$(GraphTDB graph, InputStream input, boolean showProgress, boolean collectStats) { DatasetGraphTDB dsgtdb = TDBInternal.getBaseDatasetGraphTDB(graph.getDatasetGraphTDB()); if ( graph.getGraphName() == null ) loadDefaultGraph$(dsgtdb, input, showProgress, collectStats) ; else loadNamedGraph$(dsgtdb, graph.getGraphName(), input, showProgress, collectStats) ; }
/** The NodeTupleTable for this graph - valid only inside the transaction or non-transactional. */ public NodeTupleTable getNodeTupleTable() { return getDatasetGraphTDB().chooseNodeTupleTable(getGraphName()) ; }
/** 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) ; }
private static void loadGraph$(GraphTDB graph, List<String> urls, boolean showProgress, boolean collectStats) { if ( graph.getGraphName() == null ) loadDefaultGraph$(graph.getDatasetGraphTDB(), urls, showProgress, collectStats) ; else loadNamedGraph$(graph.getDatasetGraphTDB(), graph.getGraphName(), urls, showProgress, collectStats) ; }
/** 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) { DatasetGraphTDB dsgtdb = graph.getDatasetGraphTDB() ; // 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. return optimizeExecuteQuads(dsgtdb, input, graph.getGraphName(), opBGP.getPattern(), exprs, execCxt) ; } // Execute a BGP on the real default graph return optimizeExecuteTriples(dsgtdb, input, opBGP.getPattern(), exprs, execCxt) ; }
@Override public void clear() { // Logically, this is "super.clear()" except the default implementation // is a loop that materializes nodes. We want to call the dataset directly // so that nodes don't get materialized, just deleted from indexes. getDataset().deleteAny(getGraphName(), Node.ANY, Node.ANY, Node.ANY) ; getEventManager().notifyEvent(this, GraphEvents.removeAll) ; }
@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 ; } getDatasetGraphTDB().deleteAny(getGraphName(), s, p, o) ; // We know no one is listening ... // getEventManager().notifyEvent(this, GraphEvents.remove(s, p, o) ) ; } }
private PrefixMapping createPrefixMapping$() { DatasetPrefixStorage dsgPrefixes = getDatasetGraphTDB().getPrefixes() ; if ( isDefaultGraph() ) return dsgPrefixes.getPrefixMapping() ; if ( isUnionGraph() ) return dsgPrefixes.getPrefixMapping() ; return dsgPrefixes.getPrefixMapping(getGraphName().getURI()) ; }
@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.getDatasetGraphTDB(), 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 ; QuadTable quadTable = getDatasetGraphTDB().getQuadTable() ; Iterator<Tuple<NodeId>> iter = quadTable.getNodeTupleTable().findAsNodeIds(gn, null, null, null) ; if ( unionGraph ) { iter = Iter.map(iter, project4TupleTo3Tuple) ; iter = Iter.distinctAdjacent(iter) ; } return (int)Iter.count(iter) ; }