Search in sources :

Example 36 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class SolverLibTDB method convToBinding.

static Binding convToBinding(BindingNodeId bindingNodeIds, NodeTable nodeTable) {
    if (true)
        return new BindingTDB(bindingNodeIds, nodeTable);
    else {
        // Makes nodes immediately. Causing unnecessary NodeTable accesses
        // (e.g. project)
        BindingBuilder builder = Binding.builder();
        for (Var v : bindingNodeIds) {
            NodeId id = bindingNodeIds.get(v);
            Node n = nodeTable.getNodeForNodeId(id);
            builder.add(v, n);
        }
        return builder.build();
    }
}
Also used : BindingBuilder(org.apache.jena.sparql.engine.binding.BindingBuilder) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 37 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class SolverLibTDB method convert.

/**
 * Binding {@literal ->} BindingNodeId, given a NodeTable
 */
static BindingNodeId convert(Binding binding, NodeTable nodeTable) {
    if (binding instanceof BindingTDB)
        return ((BindingTDB) binding).getBindingId();
    BindingNodeId b = new BindingNodeId(binding);
    // and copy over, getting NodeIds.
    Iterator<Var> vars = binding.vars();
    for (; vars.hasNext(); ) {
        Var v = vars.next();
        Node n = binding.get(v);
        if (n == null)
            // Can occur with BindingProject
            continue;
        // Rely on the node table cache for efficency - we will likely be
        // repeatedly looking up the same node in different bindings.
        NodeId id = nodeTable.getNodeIdForNode(n);
        // Even put in "does not exist" for a node now known not to be in the DB.
        // Optional: whether to put in "known missing"
        // Currently, we do. The rest of the code should work with either choice.
        // if ( ! NodeId.isDoesNotExist(id) )
        b.put(v, id);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 38 with NodeId

use of org.apache.jena.tdb2.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 still valid.
        nodeId = cacheLookup(node);
        if (nodeId != null)
            return nodeId;
        if (allocate)
            nodeId = baseTable.getAllocateNodeId(node);
        else {
            if (notPresent(node))
                // Known not be in the baseTable.
                return NodeId.NodeDoesNotExist;
            else
                nodeId = baseTable.getNodeIdForNode(node);
        }
        // Ensure caches have it. Includes recording "no such node"
        cacheUpdate(node, nodeId);
        return nodeId;
    }
}
Also used : NodeId(org.apache.jena.tdb2.store.NodeId)

Example 39 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class NodeTableTRDF method writeNodeToTable.

@Override
protected NodeId writeNodeToTable(Node node) {
    RDF_Term term = ThriftConvert.convert(node, true);
    try {
        long x = diskFile.length();
        // Paired : [*]
        NodeId nid = NodeIdFactory.createPtr(x);
        term.write(protocol);
        // transport.flush();
        return nid;
    } catch (TransactionException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new TDBException("NodeTableThrift/Write", ex);
    }
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term) RiotThriftException(org.apache.jena.riot.thrift.RiotThriftException) TDBException(org.apache.jena.tdb2.TDBException) TException(org.apache.thrift.TException) TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException)

Example 40 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class NodeTableTRDF method readNodeFromTable.

@Override
protected Node readNodeFromTable(NodeId id) {
    try {
        // Paired : [*]
        long x = id.getPtrLocation();
        transport.readPosition(x);
        RDF_Term term = new RDF_Term();
        term.read(protocol);
        Node n = ThriftConvert.convert(term);
        return n;
    } catch (TException ex) {
        throw new TDBException("NodeTableTRDF/Read", ex);
    } catch (RiotThriftException ex) {
        Log.error(this, "Bad encoding: NodeId = " + id);
        throw ex;
    }
}
Also used : TException(org.apache.thrift.TException) RiotThriftException(org.apache.jena.riot.thrift.RiotThriftException) Node(org.apache.jena.graph.Node) TDBException(org.apache.jena.tdb2.TDBException) RDF_Term(org.apache.jena.riot.thrift.wire.RDF_Term)

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