&& (flush || reason == FLUSH_COMMIT)) {
// fire events
mobjs = new ManagedObjectCollection(transactional);
if (reason == FLUSH_COMMIT
&& _transEventManager.hasEndListeners()) {
fireTransactionEvent(new TransactionEvent(this,
TransactionEvent.BEFORE_COMMIT, mobjs,
_persistedClss, _updatedClss, _deletedClss));
flushAdditions(transactional, reason);
flush = (_flags & FLAG_FLUSH_REQUIRED) != 0;
}
if (flush && _transEventManager.hasFlushListeners()) {
fireTransactionEvent(new TransactionEvent(this,
TransactionEvent.BEFORE_FLUSH, mobjs,
_persistedClss, _updatedClss, _deletedClss));
flushAdditions(transactional, reason);
}
}
}
}
finally {
_flags &= ~FLAG_PRESTORING;
_flags &= ~FLAG_DEREFDELETING;
_transAdditions = null;
_derefAdditions = null;
// also clear derefed set; the deletes have been recorded
if (_derefCache != null)
_derefCache = null;
}
// flush to store manager
List<Exception> exceps = null;
try {
if (flush && reason != FLUSH_LOGICAL) {
_flags |= FLAG_STORE_FLUSHING;
exceps = add(exceps,
newFlushException(_store.flush(transactional)));
}
} finally {
_flags &= ~FLAG_STORE_FLUSHING;
if (reason == FLUSH_ROLLBACK)
exceps = add(exceps, endStoreManagerTransaction(true));
else if (reason != FLUSH_LOGICAL)
_flags &= ~FLAG_FLUSH_REQUIRED;
// mark states as flushed
if (flush) {
StateManagerImpl sm;
for (Iterator itr = transactional.iterator(); itr.hasNext();) {
sm = (StateManagerImpl) itr.next();
try {
// the state may have become transient, such as if
// it is embedded and the owner has been deleted during
// this flush process; bug #1100
if (sm.getPCState() == PCState.TRANSIENT)
continue;
sm.afterFlush(reason);
if (reason == FLUSH_INC) {
// if not about to clear trans cache for commit
// anyway, re-cache dirty objects with default soft
// refs; we don't need hard refs now that the
// changes have been flushed
sm.proxyFields(true, false);
_transCache.flushed(sm);
}
} catch (Exception e) {
exceps = add(exceps, e);
}
}
}
}
// throw any exceptions to shortcut listeners on fail
throwNestedExceptions(exceps, true);
if (flush && reason != FLUSH_ROLLBACK && reason != FLUSH_LOGICAL
&& _transEventManager.hasFlushListeners()) {
fireTransactionEvent(new TransactionEvent(this,
TransactionEvent.AFTER_FLUSH, mobjs, _persistedClss,
_updatedClss, _deletedClss));
}
}