use of org.apache.jena.tdb.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();
}
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class NodeTupleTableConcrete method deleteRow.
@Override
public boolean 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 false;
n[i] = id;
}
Tuple<NodeId> t = TupleFactory.tuple(n);
return tupleTable.delete(t);
} finally {
finishWrite();
}
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class TupleIndexRecord method findWorker.
private Iterator<Tuple<NodeId>> findWorker(Tuple<NodeId> patternNaturalOrder, boolean partialScanAllowed, boolean fullScanAllowed) {
if (Check) {
if (tupleLength != patternNaturalOrder.len())
throw new TDBException(String.format("Mismatch: tuple length %d / index for length %d", patternNaturalOrder.len(), tupleLength));
}
// Convert to index order.
Tuple<NodeId> pattern = colMap.map(patternNaturalOrder);
// Canonical form.
int numSlots = 0;
// Index of last leading pattern NodeId. Start less
int leadingIdx = -2;
// than numSlots-1
boolean leading = true;
// Records.
Record minRec = factory.createKeyOnly();
Record maxRec = factory.createKeyOnly();
// Set the prefixes.
for (int i = 0; i < pattern.len(); i++) {
NodeId X = pattern.get(i);
if (NodeId.isAny(X)) {
X = null;
// No longer seting leading key slots.
leading = false;
continue;
}
numSlots++;
if (leading) {
leadingIdx = i;
Bytes.setLong(X.getId(), minRec.getKey(), i * SizeOfNodeId);
Bytes.setLong(X.getId(), maxRec.getKey(), i * SizeOfNodeId);
}
}
// Is it a simple existence test?
if (numSlots == pattern.len()) {
if (index.contains(minRec))
return new SingletonIterator<>(pattern);
else
return new NullIterator<>();
}
Iterator<Record> iter = null;
if (leadingIdx < 0) {
if (!fullScanAllowed)
return null;
// System.out.println("Full scan") ;
// Full scan necessary
iter = index.iterator();
} else {
// Adjust the maxRec.
NodeId X = pattern.get(leadingIdx);
// Set the max Record to the leading NodeIds, +1.
// Example, SP? inclusive to S(P+1)? exclusive where ? is zero.
Bytes.setLong(X.getId() + 1, maxRec.getKey(), leadingIdx * SizeOfNodeId);
iter = index.iterator(minRec, maxRec);
}
Iterator<Tuple<NodeId>> tuples = Iter.map(iter, item -> TupleLib.tuple(item, colMap));
if (leadingIdx < numSlots - 1) {
if (!partialScanAllowed)
return null;
// Didn't match all defined slots in request.
// Partial or full scan needed.
// pattern.unmap(colMap) ;
tuples = TupleIndex.scan(tuples, patternNaturalOrder);
}
return tuples;
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class ProcIndexCopy method tupleIndexCopy.
private static void tupleIndexCopy(TupleIndex index1, TupleIndex index2, String label) {
ProgressMonitor monitor = ProgressMonitor.create(log, label, tickQuantum, superTick);
monitor.start();
Iterator<Tuple<NodeId>> iter1 = index1.all();
long counter = 0;
for (; iter1.hasNext(); ) {
counter++;
Tuple<NodeId> tuple = iter1.next();
index2.add(tuple);
monitor.tick();
}
index2.sync();
long time = monitor.finish();
float elapsedSecs = time / 1000F;
float rate = (elapsedSecs != 0) ? counter / elapsedSecs : 0;
print("Total: %,d records : %,.2f seconds : %,.2f records/sec [%s]", counter, elapsedSecs, rate, DateTimeUtils.nowAsString());
}
use of org.apache.jena.tdb.store.NodeId in project jena by apache.
the class SolverLib method convToBinding.
public 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)
BindingMap b = BindingFactory.create();
for (Var v : bindingNodeIds) {
NodeId id = bindingNodeIds.get(v);
Node n = nodeTable.getNodeForNodeId(id);
b.add(v, n);
}
return b;
}
}
Aggregations