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 ; }
static Map<String, TupleIndex> indexMap(DatasetGraphTDB dsgtdb) { Map<String, TupleIndex> indexMap = new HashMap<>(); // All triple/quad indexes. Arrays.stream(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes()) .forEach(idx->indexMap.put(idx.getName(), idx)); Arrays.stream(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes()) .forEach(idx->indexMap.put(idx.getName(), idx)); return indexMap; }
@Override protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) { checkNotClosed(); return isolate(getQuadTable().find(Node.ANY, s, p, o)); }
@Override protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) { checkNotClosed(); return isolate(getQuadTable().find(g, s, p, o)); }
/** * 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 protected void addToNamedGraph(Node g, Node s, Node p, Node o) { checkNotClosed() ; requireWriteTxn() ; notifyAdd(g, s, p, o) ; getQuadTable().add(g, s, p, o) ; }
@Override protected void deleteFromNamedGraph(Node g, Node s, Node p, Node o) { checkNotClosed() ; requireWriteTxn() ; notifyDelete(g, s, p, o) ; getQuadTable().delete(g, s, p, o) ; }
@Override public boolean isEmpty() { checkNotClosed(); return getTripleTable().isEmpty() && getQuadTable().isEmpty(); }
@Override public void clear() { checkNotClosed() ; // Leave the node table alone. getTripleTable().clearTriples() ; getQuadTable().clearQuads() ; }
public NodeTupleTable chooseNodeTupleTable(Node graphNode) { checkNotClosed() ; if ( graphNode == null || Quad.isDefaultGraph(graphNode) ) return getTripleTable().getNodeTupleTable() ; else // Includes Node.ANY and union graph return getQuadTable().getNodeTupleTable() ; }
public DataToTuples(DatasetGraphTDB dsgtdb, Destination<Tuple<NodeId>> tuples3, Destination<Tuple<NodeId>> tuples4, MonitorOutput output) { this.dsgtdb = dsgtdb; this.dest3 = tuples3; this.dest4 = tuples4; this.input = new ArrayBlockingQueue<>(LoaderConst.QueueSizeData); this.nodeTable = dsgtdb.getQuadTable().getNodeTupleTable().getNodeTable(); this.prefixes = dsgtdb.getPrefixes(); this.output = output; NodeTable nodeTable2 = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable(); if ( nodeTable != nodeTable2 ) throw new BulkLoaderException("Different node tables"); }
public DataToTuplesInlineSingle(DatasetGraphTDB dsgtdb, Consumer<Tuple<NodeId>> dest3, Consumer<Tuple<NodeId>> dest4, MonitorOutput output) { this.dsgtdb = dsgtdb; this.dest3 = dest3; this.dest4 = dest4; this.output = output; this.nodeTable = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable(); this.prefixes = dsgtdb.getPrefixes(); NodeTable nodeTable2 = dsgtdb.getQuadTable().getNodeTupleTable().getNodeTable(); if ( nodeTable != nodeTable2 ) throw new BulkLoaderException("Different node tables"); }
public DataToTuplesInline(DatasetGraphTDB dsgtdb, Destination<Tuple<NodeId>> dest3, Destination<Tuple<NodeId>> dest4, MonitorOutput output) { this.dsgtdb = dsgtdb; this.dest3 = dest3; this.dest4 = dest4; this.output = output; this.nodeTable = dsgtdb.getTripleTable().getNodeTupleTable().getNodeTable(); this.prefixes = dsgtdb.getPrefixes(); NodeTable nodeTable2 = dsgtdb.getQuadTable().getNodeTupleTable().getNodeTable(); if ( nodeTable != nodeTable2 ) throw new BulkLoaderException("Different node tables"); }
/** 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)) ; // Project is cheap - don't brother wrapping iter1 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) ; }
protected static ExtendedIterator<Triple> graphBaseFindNG(DatasetGraphTDB dataset, Node graphNode, Triple m) { Node gn = graphNode ; // Explicitly named union graph. if ( isUnionGraph(gn) ) gn = Node.ANY ; Iterator<Quad> iter = dataset.getQuadTable().find(gn, m.getMatchSubject(), m.getMatchPredicate(), m.getMatchObject()) ; if ( iter == null ) return org.apache.jena.util.iterator.NullIterator.instance() ; Iterator<Triple> iterTriples = projectQuadsToTriples((gn == Node.ANY ? null : gn), iter) ; if ( gn == Node.ANY ) iterTriples = Iter.distinct(iterTriples) ; return WrappedIterator.createNoRemove(iterTriples) ; }
@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) ; }
public TDBDatasetDetails(DatasetGraphTDB dsg) { ntTop = dsg.getTripleTable().getNodeTupleTable().getNodeTable() ; tripleIndexes = ArrayUtils.copy(dsg.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes()) ; quadIndexes = ArrayUtils.copy(dsg.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes()) ; fillInNodeTableDetails() ; fillInIndexDetails() ; }
/** 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) ); }