Search in sources :

Example 1 with Hash

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);
        }
    }
}
Also used : Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb.store.NodeId) Hash(org.apache.jena.tdb.store.Hash) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) DatasetGraphTDB(org.apache.jena.tdb.store.DatasetGraphTDB)

Example 2 with Hash

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;
    }
}
Also used : TDBException(org.apache.jena.tdb.TDBException) NodeId(org.apache.jena.tdb.store.NodeId) Record(org.apache.jena.tdb.base.record.Record) NodeLib.setHash(org.apache.jena.tdb.lib.NodeLib.setHash) Hash(org.apache.jena.tdb.store.Hash)

Example 3 with Hash

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;
}
Also used : LenNodeHash(org.apache.jena.tdb.sys.SystemTDB.LenNodeHash) Hash(org.apache.jena.tdb.store.Hash)

Aggregations

Hash (org.apache.jena.tdb.store.Hash)3 NodeId (org.apache.jena.tdb.store.NodeId)2 Node (org.apache.jena.graph.Node)1 TDBException (org.apache.jena.tdb.TDBException)1 Record (org.apache.jena.tdb.base.record.Record)1 NodeLib.setHash (org.apache.jena.tdb.lib.NodeLib.setHash)1 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)1 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)1 LenNodeHash (org.apache.jena.tdb.sys.SystemTDB.LenNodeHash)1