use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class NodeTableCache method testForConsistency.
private void testForConsistency() {
Iterator<Node> iter1 = Iter.toList(node2id_Cache.keys()).iterator();
for (; iter1.hasNext(); ) {
Node n = iter1.next();
NodeId nId = node2id_Cache.getIfPresent(n);
if (!id2node_Cache.containsKey(nId))
throw new TDBException("Inconsistent: " + n + " => " + nId);
if (notPresent.containsKey(n))
throw new TDBException("Inconsistent: " + n + " in notPresent cache (1)");
}
Iterator<NodeId> iter2 = Iter.toList(id2node_Cache.keys()).iterator();
for (; iter2.hasNext(); ) {
NodeId nId = iter2.next();
Node n = id2node_Cache.getIfPresent(nId);
if (!node2id_Cache.containsKey(n))
throw new TDBException("Inconsistent: " + nId + " => " + n);
if (notPresent.containsKey(n))
throw new TDBException("Inconsistent: " + n + " in notPresent cache (2)");
}
}
use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class NodeTableNative method accessIndex.
protected final NodeId accessIndex(Node node, boolean create) {
Hash hash = new Hash(nodeHashToId.getRecordFactory().keyLength());
NodeLib.setHash(hash, node);
byte[] k = hash.getBytes();
// Key only.
Record r = nodeHashToId.getRecordFactory().create(k);
synchronized (// Pair to readNodeFromTable.
this) {
// Key and value, or null
Record r2 = nodeHashToId.find(r);
if (r2 != null) {
// Found. Get the NodeId.
NodeId id = NodeIdFactory.get(r2.getValue(), 0);
return id;
}
// Not found.
if (!create)
return NodeId.NodeDoesNotExist;
// Write the node, which allocates an id for it.
syncNeeded = true;
NodeId id = writeNodeToTable(node);
// Update the r record with the new id.
// r.value := id bytes;
NodeIdFactory.set(id, r.getValue(), 0);
// Put in index - may appear because of concurrency
if (!nodeHashToId.insert(r))
throw new TDBException("NodeTableBase::nodeToId - record mysteriously appeared");
return id;
}
}
use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class NodeTupleTableConcrete method deleteRow.
@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();
}
}
use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class NodeTupleTableConcrete method findAsNodeIds.
/**
* 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;
}
// **public call
return find(n);
} finally {
finishRead();
}
}
use of org.apache.jena.tdb2.store.NodeId in project jena by apache.
the class StatsCollectorNodeId method convert.
@Override
protected Map<Node, Long> convert(Map<NodeId, Long> stats) {
// Predicate -> Count
Map<Node, Long> statsNodes = new HashMap<>(1000);
for (NodeId p : stats.keySet()) {
Node n = nodeTable.getNodeForNodeId(p);
statsNodes.put(n, stats.get(p));
}
return statsNodes;
}
Aggregations