use of org.datanucleus.flush.FlushProcess in project datanucleus-core by datanucleus.
the class ExecutionContextImpl method flushInternal.
/**
* This method flushes all dirty, new, and deleted instances to the datastore.
* @param flushToDatastore Whether to ensure any changes reach the datastore
* Otherwise they will be flushed to the datastore manager and leave it to
* decide the opportune moment to actually flush them to the datastore
* @throws NucleusOptimisticException when optimistic locking error(s) occur
*/
public void flushInternal(boolean flushToDatastore) {
if (!flushToDatastore && dirtyOPs.isEmpty() && indirectDirtyOPs.isEmpty()) {
// Nothing to flush so abort now
return;
}
if (!tx.isActive()) {
// Non transactional flush, so store the ids for later
if (nontxProcessedOPs == null) {
nontxProcessedOPs = new HashSet<>();
}
nontxProcessedOPs.addAll(dirtyOPs);
nontxProcessedOPs.addAll(indirectDirtyOPs);
}
flushing++;
try {
if (flushToDatastore) {
// Make sure flushes its changes to the datastore
tx.preFlush();
}
// Retrieve the appropriate flush process, and execute it
FlushProcess flusher = getStoreManager().getFlushProcess();
List<NucleusOptimisticException> optimisticFailures = flusher.execute(this, dirtyOPs, indirectDirtyOPs, operationQueue);
if (flushToDatastore) {
// Make sure flushes its changes to the datastore
tx.flush();
}
if (optimisticFailures != null) {
// Throw a single NucleusOptimisticException containing all optimistic failures
throw new NucleusOptimisticException(Localiser.msg("010031"), optimisticFailures.toArray(new Throwable[optimisticFailures.size()]));
}
} finally {
if (NucleusLogger.PERSISTENCE.isDebugEnabled()) {
NucleusLogger.PERSISTENCE.debug(Localiser.msg("010004"));
}
flushing--;
}
}
Aggregations