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();
}
}
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;
}
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;
}
}
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);
}
}
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;
}
}
Aggregations