Search in sources :

Example 16 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable 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 17 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class tdbstats method stats.

public 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 ? SolverLibTDB.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();
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb.solver.stats.StatsCollectorNodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb.solver.stats.StatsCollectorNodeId)

Example 18 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class AbstractTestNodeTable method testNodeBad.

protected void testNodeBad(Node badNode) {
    NodeTable nt = createEmptyNodeTable();
    writeBadNode(nt, badNode);
}
Also used : NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 19 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class AbstractTestNodeTableTrans method nodetrans_04.

@Test
public void nodetrans_04() {
    Transaction txn = createTxn(11);
    NodeTableTrans ntt = create(txn, node1);
    NodeTable nt0 = ntt.getBaseNodeTable();
    ntt.begin(txn);
    // Add a node
    NodeId nodeId = ntt.getAllocateNodeId(node2);
    // Not here
    assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node2));
    // Is here
    assertEquals(nodeId, ntt.getNodeIdForNode(node2));
    ntt.commitPrepare(txn);
    ntt.commitEnact(txn);
    assertEquals(nodeId, nt0.getNodeIdForNode(node2));
    ntt.commitClearup(txn);
}
Also used : NodeTableTrans(org.apache.jena.tdb.transaction.NodeTableTrans) Transaction(org.apache.jena.tdb.transaction.Transaction) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 20 with NodeTable

use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.

the class JournalControl method recoverNodeDat.

/** Recover a node data file (".dat").
     *  Node data files are append-only so recovering, then not using the data is safe.
     *  Node data file is a precursor for full recovery that works from the master journal.
     */
private static void recoverNodeDat(DatasetGraphTDB dsg, FileRef fileRef) {
    // See DatasetBuilderTxn - same name generation code.
    RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId);
    NodeTable baseNodeTable = dsg.getConfig().nodeTables.get(fileRef);
    String objFilename = fileRef.getFilename() + "-" + Names.extJournal;
    objFilename = dsg.getLocation().absolute(objFilename);
    File jrnlFile = new File(objFilename);
    if (jrnlFile.exists() && jrnlFile.length() > 0) {
        syslog.info("Recovering node data: " + fileRef.getFilename());
        ObjectFile dataJrnl = FileFactory.createObjectFileDisk(objFilename);
        NodeTableTrans ntt = new NodeTableTrans(null, objFilename, baseNodeTable, new IndexMap(recordFactory), dataJrnl);
        ntt.append();
        ntt.close();
        dataJrnl.close();
        baseNodeTable.sync();
    }
    if (jrnlFile.exists())
        FileOps.delete(objFilename);
}
Also used : RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) IndexMap(org.apache.jena.tdb.index.IndexMap) ObjectFile(org.apache.jena.tdb.base.objectfile.ObjectFile) BufferChannelFile(org.apache.jena.tdb.base.file.BufferChannelFile) File(java.io.File) ObjectFile(org.apache.jena.tdb.base.objectfile.ObjectFile) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Aggregations

NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)27 NodeId (org.apache.jena.tdb.store.NodeId)12 Node (org.apache.jena.graph.Node)8 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)5 NodeTupleTable (org.apache.jena.tdb.store.nodetupletable.NodeTupleTable)5 Triple (org.apache.jena.graph.Triple)4 Quad (org.apache.jena.sparql.core.Quad)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 Predicate (java.util.function.Predicate)3 BaseTest (org.apache.jena.atlas.junit.BaseTest)3 TDBException (org.apache.jena.tdb.TDBException)3 DatasetGraphTDB (org.apache.jena.tdb.store.DatasetGraphTDB)3 NodeTableTrans (org.apache.jena.tdb.transaction.NodeTableTrans)3 Transaction (org.apache.jena.tdb.transaction.Transaction)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2 Function (java.util.function.Function)2 Iter (org.apache.jena.atlas.iterator.Iter)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)2