use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class StatsCollectorNodeId method convert.
@Override
protected Map<Node, Integer> convert(Map<NodeId, Integer> stats) {
Map<Node, Integer> statsNodes = new HashMap<>(1000);
for (NodeId p : stats.keySet()) {
Node n = nodeTable.getNodeForNodeId(p);
statsNodes.put(n, stats.get(p));
}
return statsNodes;
}
use of org.apache.jena.tdb.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.contains(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.contains(n))
throw new TDBException("Inconsistent: " + n + " in notPresent cache (2)");
}
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class NodeTableCache method _idForNode.
// Node ==> NodeId
private NodeId _idForNode(Node node, boolean allocate) {
if (node == Node.ANY)
return NodeId.NodeIdAny;
// Try once outside the synchronized
// (Cache access is thread-safe.)
NodeId nodeId = cacheLookup(node);
if (nodeId != null)
return nodeId;
synchronized (lock) {
// Update two caches inside synchronized.
// Check stil valid.
nodeId = cacheLookup(node);
if (nodeId != null)
return nodeId;
if (allocate)
nodeId = baseTable.getAllocateNodeId(node);
else
nodeId = baseTable.getNodeIdForNode(node);
// Ensure caches have it. Includes recording "no such node"
cacheUpdate(node, nodeId);
return nodeId;
}
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class NodeTableLogger method getNodeIdForNode.
@Override
public NodeId getNodeIdForNode(Node node) {
//info("getNodeIdForNode("+node+") =>") ;
NodeId nId = nodeTable.getNodeIdForNode(node);
info("getNodeIdForNode(" + node + ") => " + nId);
return nId;
}
use of org.apache.jena.tdb.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());
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 = NodeId.create(r2.getValue(), 0);
return id;
}
// Not found.
if (!create)
return NodeId.NodeDoesNotExist;
// Write the node, which allocates an id for it.
NodeId id = writeNodeToTable(node);
// Update the r record with the new id.
// r.value := id bytes ;
id.toBytes(r.getValue(), 0);
// Put in index - may appear because of concurrency
if (!nodeHashToId.add(r))
throw new TDBException("NodeTableBase::nodeToId - record mysteriously appeared");
return id;
}
}
Aggregations