}
public Collection<Exception> flush() {
Collection<Exception> errors = null;
// skip past any delegating store managers.
StoreManager storeManager =
_broker.getStoreManager().getInnermostDelegate();
Collection<OpenJPAStateManager> sms = null;
if (_cache != null && !_cache.isEmpty()) {
// TODO lock or switch the cache
sms = _cache.getStateManagers();
_cache.clear();
}
if (sms != null && !sms.isEmpty()) {
storeManager.retainConnection();
storeManager.begin();
errors = storeManager.flush(sms);
if(errors != null && !errors.isEmpty() ) {
for(Exception e : errors) {
// TODO add error handling.
e.printStackTrace();
}
}
storeManager.commit();
storeManager.releaseConnection();
}
return errors;
}