@SuppressWarnings("unchecked")
@Override
protected CloseableIteration<? extends Resource, SailException> getContextIDsInternal()
throws SailException
{
Lock stLock = store.getStatementsReadLock();
try {
// Iterate over all MemURIs and MemBNodes
CloseableIteration<MemResource, SailException> iter;
iter = new UnionIteration<MemResource, SailException>(
new IteratorIteration<MemResource, SailException>(
store.getValueFactory().getMemURIs().iterator()),
new IteratorIteration<MemResource, SailException>(
store.getValueFactory().getMemBNodes().iterator()));
final int snapshot = transactionActive() ? store.getCurrentSnapshot() + 1
: store.getCurrentSnapshot();
final ReadMode readMode = transactionActive() ? ReadMode.TRANSACTION : ReadMode.COMMITTED;
iter = new FilterIteration<MemResource, SailException>(iter) {
@Override
protected boolean accept(MemResource memResource)
throws SailException
{
MemStatementList contextStatements = memResource.getContextStatementList();
// Filter resources that are not used as context identifier
if (contextStatements.size() == 0) {
return false;
}
// Filter more thoroughly by considering snapshot and read-mode
// parameters
MemStatementIterator<SailException> iter = new MemStatementIterator<SailException>(
contextStatements, null, null, null, false, snapshot, readMode);
try {
return iter.hasNext();
}
finally {
iter.close();
}
}
};
// Release query lock when iterator is closed
iter = new LockingIteration<MemResource, SailException>(stLock, iter);
return iter;
}
catch (RuntimeException e) {
stLock.release();
throw e;
}
}