use of org.apache.jena.tdb2.store.nodetable.NodeTable 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.nodetable.NodeTable 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.nodetable.NodeTable in project jena by apache.
the class TDB2StorageBuilder method buildNodeTable.
private NodeTable buildNodeTable(String name, boolean isData) {
NodeTable nodeTable = buildBaseNodeTable(name);
nodeTable = addNodeTableCache(nodeTable, params, isData);
if (nodeTable instanceof NodeTableCache) {
NodeTableCache nodeTableCache = (NodeTableCache) nodeTable;
listeners.add(nodeTableCache);
}
nodeTable = NodeTableInline.create(nodeTable);
return nodeTable;
}
use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.
the class BindingTDB method get1.
@Override
public Node get1(Var var) {
try {
Node n = cacheGet(var);
if (n != null)
return n;
NodeId id = idBinding.get(var);
if (id == null)
return null;
if (NodeId.isDoesNotExist(id))
return null;
n = nodeTable.getNodeForNodeId(id);
if (n == null)
// But there was to put it in the BindingNodeId.
throw new TDBException("No node in NodeTable for NodeId " + id);
// Update cache.
cachePut(var, n);
return n;
} catch (Exception ex) {
Log.error(this, String.format("get1(%s)", var), ex);
return null;
}
}
use of org.apache.jena.tdb2.store.nodetable.NodeTable in project jena by apache.
the class SolverRX method accessData.
static Iterator<Quad> accessData(Tuple<Node> patternTuple, NodeTupleTable nodeTupleTable, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Function<Tuple<NodeId>, Quad> asQuad = asQuad(nodeTable, nodeTupleTable.getTupleLen(), anyGraph);
Tuple<NodeId> patternTupleId = TupleLib.tupleNodeIds(nodeTable, patternTuple);
if (patternTupleId.contains(NodeId.NodeDoesNotExist))
// Can not match.
return Iter.nullIterator();
// -- DRY/StageMatchTuple ??
Iterator<Tuple<NodeId>> iterMatches = nodeTupleTable.find(patternTupleId);
// Add filter
if (filter != null)
iterMatches = Iter.filter(iterMatches, filter);
// Add anyGraph
if (anyGraph) {
// See StageMatchTuple for discussion.
iterMatches = Iter.map(iterMatches, quadsToAnyTriples);
iterMatches = Iter.distinctAdjacent(iterMatches);
}
// -- DRY/StageMatchTuple
Iterator<Quad> qIter = Iter.map(iterMatches, asQuad);
return qIter;
}
Aggregations