@Override public boolean containsNode(Node node) { NodeId x = getNodeIdForNode(node) ; return NodeId.isDoesNotExist(x) ; }
@Override public boolean containsNode(Node node) { NodeId x = getNodeIdForNode(node) ; return NodeId.isDoesNotExist(x) ; }
private static NodeId findRDFType(NodeTable nodeTable) { // It may not exist. NodeId nodeId = nodeTable.getNodeIdForNode(NodeConst.nodeRDFType); if ( NodeId.isDoesNotExist(nodeId) ) return null; return nodeId; }
private Node _retrieveNodeByNodeId(NodeId id) { if ( NodeId.isDoesNotExist(id) ) return null ; if ( NodeId.isAny(id) ) return null ; synchronized (this) { Node n = readNodeFromTable(id) ; return n ; } }
public NodeId getNodeId(Var var) { NodeId id = idBinding.get(var) ; if ( id != null ) return id ; // In case we are inserting known missing nodes. if ( NodeId.isDoesNotExist(id) ) return null ; if ( parent == null ) return null ; if ( parent instanceof BindingTDB ) return ((BindingTDB)parent).getNodeId(var) ; return null ; }
private Node _retrieveNodeByNodeId(NodeId id) { if ( NodeId.isDoesNotExist(id) ) return null ; if ( NodeId.isAny(id) ) return null ; // Try once outside the synchronized // (Cache access is thread-safe) Node n = cacheLookup(id) ; if ( n != null ) return n ; synchronized (lock) { // Lock to update two caches consistently. // Verify cache miss n = cacheLookup(id) ; if ( n != null ) return n ; if ( baseTable == null ) System.err.println("" + this) ; n = baseTable.getNodeForNodeId(id) ; cacheUpdate(n, id) ; return n ; } }
/** Prepare a pattern (tuple of nodes), and an existing binding of NodeId, into NodeIds and Variables. * A variable in the pattern is replaced by its binding or null in the Nodeids. * A variable that is not bound by the binding is placed in the var array. * Return false if preparation detects the pattern can not match. */ public static boolean prepare(NodeTable nodeTable, Tuple<Node> patternTuple, BindingNodeId input, NodeId ids[], Var[] var) { // Process the Node to NodeId conversion ourselves because // we wish to abort if an unknown node is seen. for ( int i = 0 ; i < patternTuple.len() ; i++ ) { Node n = patternTuple.get(i) ; // Substitution and turning into NodeIds // Variables unsubstituted are null NodeIds NodeId nId = idFor(nodeTable, input, n) ; if ( NodeId.isDoesNotExist(nId) ) return false; ids[i] = nId ; if ( nId == null ) var[i] = asVar(n) ; } return true ; }
@Override public Node get1(Var var) { try { Node n = cacheGet(var) ; if ( n != null ) return n ; NodeId id = idBinding.get(var) ; if ( id == null ) return null ; if ( NodeId.isDoesNotExist(id) ) return null; n = nodeTable.getNodeForNodeId(id) ; if ( n == null ) // But there was to put it in the BindingNodeId. throw new TDBException("No node in NodeTable for NodeId "+id); // Update cache. cachePut(var, n) ; return n ; } catch (Exception ex) { Log.error(this, String.format("get1(%s)", var), ex) ; return null ; } }
@Override public void deleteRow(Node... nodes) { try { startWrite() ; NodeId n[] = new NodeId[nodes.length] ; for (int i = 0; i < nodes.length; i++) { NodeId id = idForNode(nodes[i]) ; if (NodeId.isDoesNotExist(id)) return ; n[i] = id ; } Tuple<NodeId> t = TupleFactory.create(n) ; tupleTable.delete(t) ; } finally { finishWrite() ; } }
/** * Find by node - return an iterator of NodeIds. * Can return "null" (when a node is known to be unknown) * for not found as well as NullIterator (when * no tuples are found (unknown unknown). */ @Override public Iterator<Tuple<NodeId>> findAsNodeIds(Node... nodes) { NodeId n[] = new NodeId[nodes.length] ; try { startRead() ; for (int i = 0; i < nodes.length; i++) { NodeId id = idForNode(nodes[i]) ; if (NodeId.isDoesNotExist(id)) return Iter.nullIterator() ; n[i] = id ; } return find(n) ; // **public call } finally { finishRead() ; } }
/** Find whether a specific graph name is in the quads table. */ public static QueryIterator testForGraphName(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) { NodeId nid = TDBInternal.getNodeId(ds, graphNode) ; boolean exists = !NodeId.isDoesNotExist(nid) ; if ( exists ) { // Node exists but is it used in the quad position? NodeTupleTable ntt = ds.getQuadTable().getNodeTupleTable() ; // Don't worry about abortable - this iterator should be fast // (with normal indexing - at least one G???). // Either it finds a starting point, or it doesn't. We are only // interested in the first .hasNext. Iterator<Tuple<NodeId>> iter1 = ntt.find(nid, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny) ; if ( filter != null ) iter1 = Iter.filter(iter1, filter) ; exists = iter1.hasNext() ; } if ( exists ) return input ; else { input.close() ; return QueryIterNullIterator.create(execCxt) ; } }
/** Update the Node->NodeId caches */ private void cacheUpdate(Node node, NodeId id) { if ( node == null ) return ; // synchronized is further out. // The "notPresent" cache is used to note whether a node // is known not to exist. // This must be specially handled later if the node is added. if ( NodeId.isDoesNotExist(id) ) { if ( notPresent != null ) notPresent.add(node) ; return ; } if ( id == NodeId.NodeIdAny ) { Log.warn(this, "Attempt to cache NodeIdAny - ignored") ; return ; } if ( node2id_Cache != null ) node2id_Cache.put(node, id) ; if ( id2node_Cache != null ) id2node_Cache.put(id, node) ; // Remove if previously marked "not present" if ( notPresent != null && notPresent.contains(node) ) notPresent.remove(node) ; }
if ( ! NodeId.isAny(x) ) numSlots++ ; if ( NodeId.isDoesNotExist(x)) return Iter.nullIterator();
private static StatsResults stats$(DatasetGraphTDB dsg, Node gn) { NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable(); StatsCollectorNodeId stats = new StatsCollectorNodeId(nt); if ( gn == null ) { Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll(); for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next(); stats.record(null, t.get(0), t.get(1), t.get(2)); } } else { // If the union graph, then we need to scan all quads but with uniqueness. boolean unionGraph = Quad.isUnionGraph(gn) ; NodeId gnid = null ; if ( !unionGraph ) { gnid = nt.getNodeIdForNode(gn); if ( NodeId.isDoesNotExist(gnid) ) Log.warn(tdbstats.class, "No such graph: " + gn); } NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable(); Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLib.unionGraph(ntt) : ntt.find(gnid, null, null, null) ; for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next(); stats.record(t.get(0), t.get(1), t.get(2), t.get(3)); } } return stats.results(); }
private static StatsResults stats$(DatasetGraphTDB dsg, Node gn) { NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable(); StatsCollectorNodeId stats = new StatsCollectorNodeId(nt); if ( gn == null ) { Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll(); for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next(); stats.record(null, t.get(0), t.get(1), t.get(2)); } } else { // If the union graph, then we need to scan all quads but with uniqueness. boolean unionGraph = Quad.isUnionGraph(gn) ; NodeId gnid = null ; if ( !unionGraph ) { gnid = nt.getNodeIdForNode(gn); if ( NodeId.isDoesNotExist(gnid) ) Log.warn(tdbstats.class, "No such graph: " + gn); } NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable(); Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLib.unionGraph(ntt) : ntt.find(gnid, null, null, null) ; for ( ; iter.hasNext() ; ) { Tuple<NodeId> t = iter.next(); stats.record(t.get(0), t.get(1), t.get(2), t.get(3)); } } return stats.results(); }