public void commit()
throws IOException
{
if (txnRemovedTriples) {
RecordIterator iter = getTriples(-1, -1, -1, -1, REMOVED_FLAG, REMOVED_FLAG);
try {
discardTriples(iter);
}
finally {
txnRemovedTriples = false;
iter.close();
}
}
boolean validCache = updatedTriplesCache.isValid();
for (TripleIndex index : indexes) {
BTree btree = index.getBTree();
RecordIterator iter;
if (validCache) {
// Use the cached set of updated triples
iter = updatedTriplesCache.getRecords();
}
else {
// Cache is invalid; too much updates(?). Iterate over all triples
iter = btree.iterateAll();
}
try {
byte[] data = null;
while ((data = iter.next()) != null) {
byte flags = data[FLAG_IDX];
boolean added = (flags & ADDED_FLAG) != 0;
boolean removed = (flags & REMOVED_FLAG) != 0;
boolean toggled = (flags & TOGGLE_EXPLICIT_FLAG) != 0;
if (removed) {
// Record has been discarded earlier, do not put it back in!
continue;
}
if (added || toggled) {
if (toggled) {
data[FLAG_IDX] ^= EXPLICIT_FLAG;
}
if (added) {
data[FLAG_IDX] ^= ADDED_FLAG;
}
if (validCache) {
// We're iterating the cache
btree.insert(data);
}
else {
// We're iterating the BTree itself
iter.set(data);
}
}
}
}
finally {
iter.close();
}
}
updatedTriplesCache.discard();
updatedTriplesCache = null;