// statement is already present. Check this.
Cursor<MemStatement> stIter = createStatementIterator(memSubj, memPred, memObj, false,
currentSnapshot + 1, ReadMode.RAW, vf, memContext);
try {
MemStatement st = stIter.next();
if (st != null) {
// statement is already present, update its transaction
// status if appropriate
txnStatements.put(st, st);
TxnStatus txnStatus = st.getTxnStatus();
if (txnStatus == TxnStatus.NEUTRAL && !st.isExplicit() && explicit) {
// Implicit statement is now added explicitly
st.setTxnStatus(TxnStatus.EXPLICIT);
}
else if (txnStatus == TxnStatus.NEW && !st.isExplicit() && explicit) {
// Statement was first added implicitly and now
// explicitly
st.setExplicit(true);
}
else if (txnStatus == TxnStatus.DEPRECATED) {
if (st.isExplicit() == explicit) {
// Statement was removed but is now re-added
st.setTxnStatus(TxnStatus.NEUTRAL);
}
else if (explicit) {
// Implicit statement was removed but is now added
// explicitly
st.setTxnStatus(TxnStatus.EXPLICIT);
}
else {
// Explicit statement was removed but can still be
// inferred
st.setTxnStatus(TxnStatus.INFERRED);
}
return st;
}
else if (txnStatus == TxnStatus.INFERRED && st.isExplicit() && explicit) {
// Explicit statement was removed but is now re-added
st.setTxnStatus(TxnStatus.NEUTRAL);
}
else if (txnStatus == TxnStatus.ZOMBIE) {
// Restore zombie statement
st.setTxnStatus(TxnStatus.NEW);
st.setExplicit(explicit);
return st;
}
return null;
}
}
finally {
stIter.close();
}
}
// completely new statement
MemStatement st = new MemStatement(memSubj, memPred, memObj, memContext, explicit, currentSnapshot + 1,
TxnStatus.NEW);
statements.add(st);
st.addToComponentLists();
txnStatements.put(st, st);
assert hasStatement(memSubj, memPred, memObj, explicit, currentSnapshot + 1, ReadMode.TRANSACTION, vf, memContext);