use of org.apache.jena.tdb.store.Hash in project jena by apache.
the class tdbnode method exec.
@Override
protected void exec() {
DatasetGraphTDB dsg = getDatasetGraphTDB();
NodeTable nodeTable = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
Iterator<String> iter = super.getPositional().iterator();
if (!iter.hasNext()) {
System.err.println("No node ids");
return;
}
for (; iter.hasNext(); ) {
String id = iter.next();
try {
long x = Long.parseLong(id);
NodeId nodeId = new NodeId(x);
Node n = nodeTable.getNodeForNodeId(nodeId);
// System.out.printf("%s [%d] => %s\n", id, x, n) ;
Hash h = new Hash(SystemTDB.LenNodeHash);
NodeLib.setHash(h, n);
String str = Bytes.asHex(h.getBytes());
System.out.printf("%s %08d 0x%s # %s\n", id, x, str, n);
} catch (Exception ex) {
System.out.println("Failed to decode: " + id);
}
}
}
use of org.apache.jena.tdb.store.Hash in project jena by apache.
the class NodeTableNative method accessIndex.
private 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;
}
}
use of org.apache.jena.tdb.store.Hash in project jena by apache.
the class NodeLib method hash.
public static Hash hash(Node n) {
Hash h = new Hash(LenNodeHash);
setHash(h, n);
return h;
}
Aggregations