private boolean _containsGraph(Node graphNode) { // Have to look explicitly, which is a bit of a nuisance. // But does not normally happen for GRAPH <g> because that's rewritten to quads. // Only pattern with complex paths go via GRAPH. Iterator<Tuple<NodeId>> x = storage.quadTable.getNodeTupleTable().findAsNodeIds(graphNode, null, null, null) ; if ( x == null ) return false ; boolean result = x.hasNext() ; return result ; }
public QuadTable buildQuadTable(NodeTable nodeTable) { String primary = params.getPrimaryIndexQuads(); String[] indexes = params.getQuadIndexes(); // Validation checks - common index forms. if ( indexes.length != 6 && indexes.length != 4 ) error(log(), "Wrong number of quad table indexes: "+String.join(",", indexes)); log().debug("Quad table: "+primary+" :: "+String.join(",", indexes)); TupleIndex quadIndexes[] = makeTupleIndexes(primary, indexes); if ( quadIndexes.length != indexes.length ) error(log(), "Wrong number of quad table tuples indexes: "+quadIndexes.length); QuadTable quadTable = new QuadTable(quadIndexes, nodeTable); return quadTable; }
/** * Add a quad (as graph node and triple) - return true if it was added, * false if it already existed */ public void add(Node gn, Triple triple) { add(gn, triple.getSubject(), triple.getPredicate(), triple.getObject()) ; }
@Override protected Iterator<Quad> findInAnyNamedGraphs(Node s, Node p, Node o) { checkNotClosed(); return isolate(getQuadTable().find(Node.ANY, s, p, o)); }
/** * Delete a quad (as graph node and triple) - return true if it was deleted, * false if it didn't exist */ public void delete(Node gn, Triple triple) { delete(gn, triple.getSubject(), triple.getPredicate(), triple.getObject()) ; }
@Override public void clear() { checkNotClosed() ; // Leave the node table alone. getTripleTable().clearTriples() ; getQuadTable().clearQuads() ; }
/** Release resources. * Do not call directly - this is called from StoreConnection. * Use {@link StoreConnection#release(Location)}. */ public void shutdown() { close(); storage.tripleTable.close() ; storage.quadTable.close() ; storage.prefixes.close(); txnSystem.getTxnMgr().shutdown(); }
@Override protected Iterator<Quad> findInSpecificNamedGraph(Node g, Node s, Node p, Node o) { checkNotClosed(); return isolate(getQuadTable().find(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) ; }
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 ; }
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) ; }
/** Add a quad - return true if it was added, false if it already existed */ public void add(Quad quad) { add(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; }
/** Delete a quad - return true if it was deleted, false if it didn't exist */ public void delete(Quad quad) { delete(quad.getGraph(), quad.getSubject(), quad.getPredicate(), quad.getObject()) ; }
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 void addToNamedGraph(Node g, Node s, Node p, Node o) { checkNotClosed() ; requireWriteTxn() ; notifyAdd(g, s, p, o) ; getQuadTable().add(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 public Iterator<Node> listGraphNodes() { checkNotClosed(); Iterator<Tuple<NodeId>> x = storage.quadTable.getNodeTupleTable().findAll(); Iterator<NodeId> z = Iter.iter(x).map(t -> t.get(0)).distinct(); return NodeLib.nodes(storage.quadTable.getNodeTupleTable().getNodeTable(), z); }
/** * Create a graph filter for a TDB2 {@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 GraphFilterTDB2 graphFilter(DatasetGraph dsg, Collection<Node> namedGraphs, boolean matchDefaultGraph) { if ( ! TDBInternal.isTDB2(dsg) ) throw new IllegalArgumentException("DatasetGraph is not TDB2-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 GraphFilterTDB2(x, matchDefaultGraph); } }
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() ; }