@Override protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) { return getQuadTable().find(g, s, p, o) ; }
@Override protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) { return getQuadTable().find(Node.ANY, s, p, o) ; }
@Override protected void addToNamedGraph(Node g, Node s, Node p, Node o) { getQuadTable().add(g, s, p, o) ; }
@Override protected void deleteFromNamedGraph(Node g, Node s, Node p, Node o) { getQuadTable().delete(g, s, p, o) ; }
public static Set<NodeId> convertToNodeIds(Collection<Node> nodes, DatasetGraphTDB dataset) { Set<NodeId> graphIds = new HashSet<>() ; NodeTable nt = dataset.getQuadTable().getNodeTupleTable().getNodeTable() ; for ( Node n : nodes ) graphIds.add(nt.getNodeIdForNode(n)) ; return graphIds ; }
/** * Return the NodeId for a node. Returns NodeId.NodeDoesNotExist when the * node is not found. Returns null when not a TDB-backed dataset. */ public static NodeId getNodeId(DatasetGraphTDB dsg, Node node) { if ( dsg == null ) return null ; NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; NodeId nodeId = nodeTable.getNodeIdForNode(node) ; return nodeId ; }
/** * Return the node for a NodeId (if any). Returns null if the NodeId does * not exist in the dataset. */ public static Node getNode(DatasetGraphTDB dsg, NodeId nodeId) { if ( dsg == null ) return null ; NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; Node node = nodeTable.getNodeForNodeId(nodeId) ; return node ; }
@Override public void clear() { // Leave the node table alone. getTripleTable().clearTriples() ; getQuadTable().clearQuads() ; }
@Override public boolean isEmpty() { return getTripleTable().isEmpty() && getQuadTable().isEmpty() ; }
public NodeTupleTable chooseNodeTupleTable(Node graphNode) { if ( graphNode == null || Quad.isDefaultGraph(graphNode) ) return getTripleTable().getNodeTupleTable() ; else // Includes Node.ANY and union graph return getQuadTable().getNodeTupleTable() ; }
/** * Create a graph filter for a TDB1 {@link DatasetGraph}. The filter matches (returns * true) for Tuples where the graph slot in quad is in the collection or for triples in the default * graph according the boolean. */ public static GraphFilterTDB1 graphFilter(DatasetGraph dsg, Collection<Node> namedGraphs, boolean matchDefaultGraph) { if ( ! TDBInternal.isTDB1(dsg) ) throw new IllegalArgumentException("DatasetGraph is not TDB1-backed"); List<NodeId> x = Txn.calculateRead(dsg, ()->{ NodeTable nt = TDBInternal.getDatasetGraphTDB(dsg).getQuadTable().getNodeTupleTable().getNodeTable(); return ListUtils.toList( namedGraphs.stream() .map(n->nt.getNodeIdForNode(n)) .filter(Objects::nonNull) ); }); return new GraphFilterTDB1(x, matchDefaultGraph); } }
public static TupleIndex getIndex(String idxName, DatasetGraphTDB dsg) { System.out.println(idxName) ; TupleIndex[] indexes1 = dsg.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes() ; TupleIndex[] indexes2 = dsg.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes() ; TupleIndex idx = null ; for ( TupleIndex i : indexes1 ) { if ( i.getName().equals(idxName) ) return i ; } for ( TupleIndex i : indexes2 ) { if ( i.getName().equals(idxName) ) return i ; } return null ; }
static void forceSync(DatasetGraphTDB dsg) { // Force sync - we have been bypassing DSG tables. // THIS DOES NOT WORK IF modules check for SYNC necessity. dsg.getTripleTable().getNodeTupleTable().getNodeTable().sync() ; dsg.getQuadTable().getNodeTupleTable().getNodeTable().sync() ; dsg.getQuadTable().getNodeTupleTable().getNodeTable().sync() ; dsg.getPrefixes().getNodeTupleTable().getNodeTable().sync() ; // This is not enough -- modules check whether sync needed. dsg.sync() ; } }
public static void dumpInternals(DatasetGraphTDB dsg, boolean includeNamedGraphs) { dumpNodeTable("Nodes", dsg) ; TupleIndex[] indexes1 = dsg.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes() ; TupleIndex[] indexes2 = dsg.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes() ; for ( TupleIndex idx : indexes1 ) { System.out.println(idx.getName()) ; dumpIndex(idx) ; } if ( ! includeNamedGraphs ) return ; for ( TupleIndex idx : indexes2 ) { System.out.println(idx.getName()) ; dumpIndex(idx) ; } }
/** Find all the graph names in the quads table. */ public static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) { List<Abortable> killList = new ArrayList<>() ; Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny) ; if ( filter != null ) iter1 = Iter.filter(iter1, filter) ; Iterator<NodeId> iter2 = Iter.map(iter1, (t) -> t.get(0)) ; iter2 = makeAbortable(iter2, killList) ; Iterator<NodeId> iter3 = Iter.distinct(iter2) ; iter3 = makeAbortable(iter3, killList) ; Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3) ; final Var var = Var.alloc(graphNode) ; Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node)) ; // Not abortable. return new QueryIterTDB(iterBinding, killList, input, execCxt) ; }
DestinationDSG(final DatasetGraphTDB dsg, boolean showProgress, boolean collectStats) { this.dsg = dsg ; startedEmpty = dsg.isEmpty() ; monitor1 = createLoadMonitor(dsg, "triples", showProgress) ; monitor2 = createLoadMonitor(dsg, "quads", showProgress) ; loaderTriples = new LoaderNodeTupleTable(dsg.getTripleTable().getNodeTupleTable(), "triples", monitor1) ; loaderQuads = new LoaderNodeTupleTable(dsg.getQuadTable().getNodeTupleTable(), "quads", monitor2) ; this.showProgress = showProgress ; this.collectStats = collectStats ; }
DestinationGraph(final DatasetGraphTDB dsg, Node graphNode, boolean showProgress, boolean collectStats) { this.dsg = dsg ; this.graphName = graphNode ; this.collectStats = collectStats ; // Choose NodeTupleTable. NodeTupleTable nodeTupleTable ; if ( graphNode == null || Quad.isDefaultGraph(graphNode) ) nodeTupleTable = dsg.getTripleTable().getNodeTupleTable() ; else { NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable() ; nodeTupleTable = new NodeTupleTableView(ntt, graphName) ; } startedEmpty = dsg.isEmpty() ; monitor = createLoadMonitor(dsg, "triples", showProgress) ; loaderTriples = new LoaderNodeTupleTable(nodeTupleTable, "triples", monitor) ; }
@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) ; }
/** Create a filter to exclude the graph http://example/g2 */ private static Predicate<Tuple<NodeId>> createFilter(Dataset ds) { DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ; final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide)) ; return item -> !( item.len() == 4 && item.get(0).equals(target) ); }
/** Create a filter to exclude the graph http://example/g2 */ private static Predicate<Tuple<NodeId>> createFilter(Dataset ds) { DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ; final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ; final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide)) ; return item -> !( item.len() == 4 && item.get(0).equals(target) ); }