use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.
the class AbstractTestNodeTableTrans method nodetrans_02.
@Test
public void nodetrans_02() {
Transaction txn = createTxn(11);
NodeTableTrans ntt = create(txn);
NodeTable nt0 = ntt.getBaseNodeTable();
ntt.begin(txn);
// Add a node
NodeId nodeId = ntt.getAllocateNodeId(node1);
// Check not in the base.
assertNull(nt0.getNodeForNodeId(nodeId));
// Check is in the transaction node table.
assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1));
assertEquals(node1, ntt.getNodeForNodeId(nodeId));
ntt.commitPrepare(txn);
ntt.commitEnact(txn);
// Check it is now in the base.
assertEquals(node1, nt0.getNodeForNodeId(nodeId));
assertEquals(nodeId, nt0.getNodeIdForNode(node1));
ntt.commitClearup(txn);
}
use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.
the class AbstractTestNodeTableTrans method nodetrans_03.
@Test
public void nodetrans_03() {
Transaction txn = createTxn(11);
NodeTableTrans ntt = create(txn);
NodeTable nt0 = ntt.getBaseNodeTable();
ntt.begin(txn);
// Add a node
NodeId nodeId = ntt.getAllocateNodeId(node1);
// Check not in the base.
assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1));
assertNull(nt0.getNodeForNodeId(nodeId));
// Check is in the transaction node table.
assertEquals(node1, ntt.getNodeForNodeId(nodeId));
ntt.abort(txn);
// Check it is not in the base.
assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1));
assertNull(nt0.getNodeForNodeId(nodeId));
ntt.commitClearup(txn);
}
use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.
the class PatternMatchTDB1 method execute.
// The worker. Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
if (Quad.isUnionGraph(graphNode))
graphNode = Node.ANY;
if (Quad.isDefaultGraph(graphNode))
graphNode = null;
List<Triple> triples = pattern.getList();
boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
if (graphNode == null) {
if (3 != tupleLen)
throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
} else {
if (4 != tupleLen)
throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
}
// Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
List<Abortable> killList = new ArrayList<>();
for (Triple triple : triples) {
Tuple<Node> patternTuple = null;
if (graphNode == null)
// 3-tuples
patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
else
// 4-tuples.
patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
// Plain RDF, no RDF-star
// chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
// ;
// RDF-star SA
chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
chain = makeAbortable(chain, killList);
}
Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
// "killList" will be aborted on timeout.
return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.
the class SolverRX method find.
private static Iterator<BindingNodeId> find(BindingNodeId bnid, NodeTupleTable nodeTupleTable, Node xGraphNode, Triple xPattern, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
NodeTable nodeTable = nodeTupleTable.getNodeTable();
Binding input = bnid.isEmpty() ? BindingFactory.empty() : new BindingTDB(bnid, nodeTable);
Triple tPattern = Substitute.substitute(xPattern, input);
Node graphNode = Substitute.substitute(xGraphNode, input);
Node tGraphNode = anyGraph ? Quad.unionGraph : graphNode;
// graphNode is ANY for union graph and null for default graph.
// Var to ANY, Triple Term to ANY.
Node g = (graphNode == null) ? null : nodeTopLevel(graphNode);
Node s = nodeTopLevel(tPattern.getSubject());
Node p = nodeTopLevel(tPattern.getPredicate());
Node o = nodeTopLevel(tPattern.getObject());
Tuple<Node> patternTuple = (g == null) ? TupleFactory.create3(s, p, o) : TupleFactory.create4(g, s, p, o);
Iterator<Quad> dsgIter = accessData(patternTuple, nodeTupleTable, anyGraph, filter, execCxt);
Iterator<Binding> matched = Iter.iter(dsgIter).map(dQuad -> SolverRX4.matchQuad(input, dQuad, tGraphNode, tPattern)).removeNulls();
return convFromBinding(matched, nodeTable);
}
use of org.apache.jena.tdb.store.nodetable.NodeTable in project jena by apache.
the class DatasetBuilderStd method buildWorker.
private synchronized DatasetGraphTDB buildWorker(Location location, boolean writeable, ReorderTransformation _transform, StoreParams params) {
recorder.start();
DatasetControl policy = createConcurrencyPolicy();
NodeTable nodeTable = makeNodeTable(location, params);
TripleTable tripleTable = makeTripleTable(location, nodeTable, policy, params);
QuadTable quadTable = makeQuadTable(location, nodeTable, policy, params);
DatasetPrefixesTDB prefixes = makePrefixTable(location, policy, params);
ReorderTransformation transform = (_transform == null) ? chooseReorderTransformation(location) : _transform;
StorageConfig storageConfig = new StorageConfig(location, params, writeable, recorder.blockMgrs, recorder.objectFiles, recorder.bufferChannels);
recorder.finish();
DatasetGraphTDB dsg = new DatasetGraphTDB(tripleTable, quadTable, prefixes, transform, storageConfig);
// TDB does filter placement on BGPs itself.
dsg.getContext().set(ARQ.optFilterPlacementBGP, false);
QC.setFactory(dsg.getContext(), OpExecutorTDB1.OpExecFactoryTDB);
return dsg;
}
Aggregations