Search in sources :

Example 26 with NodeId

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)");
    }
}
Also used : Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 27 with NodeId

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

Example 28 with NodeId

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();
    }
}
Also used : NodeId(org.apache.jena.tdb2.store.NodeId)

Example 29 with NodeId

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();
    }
}
Also used : NodeId(org.apache.jena.tdb2.store.NodeId)

Example 30 with NodeId

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;
}
Also used : HashMap(java.util.HashMap) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Aggregations

NodeId (org.apache.jena.tdb2.store.NodeId)47 Node (org.apache.jena.graph.Node)24 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)16 TDBException (org.apache.jena.tdb2.TDBException)12 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)11 Quad (org.apache.jena.sparql.core.Quad)7 ArrayList (java.util.ArrayList)6 Var (org.apache.jena.sparql.core.Var)6 Triple (org.apache.jena.graph.Triple)5 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)5 Iterator (java.util.Iterator)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 StatsCollectorNodeId (org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)4 Predicate (java.util.function.Predicate)3 Iter (org.apache.jena.atlas.iterator.Iter)3 Record (org.apache.jena.dboe.base.record.Record)3 TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)3 Test (org.junit.Test)3 List (java.util.List)2 Function (java.util.function.Function)2