- restore WRITE_STATISTICS_NAME from execution context on restart

- don't assume output file is always present on restart (could be
deleted by previous execution if shouldDeleteIfEmpty flag was set)
This commit is contained in:
jpraet
2013-03-19 22:23:33 +01:00
committed by Michael Minella
parent 44d640990d
commit c65ec97474
4 changed files with 97 additions and 7 deletions

View File

@@ -469,7 +469,14 @@ InitializingBean {
*/
public void restoreFrom(ExecutionContext executionContext) {
lastMarkedByteOffsetPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME));
restarted = true;
linesWritten = executionContext.getLong(getExecutionContextKey(WRITTEN_STATISTICS_NAME));
if (shouldDeleteIfEmpty && linesWritten == 0) {
// previous execution deleted the output file because no items were written
restarted = false;
lastMarkedByteOffsetPosition = 0;
} else {
restarted = true;
}
}
/**
@@ -585,7 +592,6 @@ InitializingBean {
}
initialized = true;
linesWritten = 0;
}
public boolean isInitialized() {

View File

@@ -368,6 +368,13 @@ ResourceAwareItemWriterItemStream<T>, InitializingBean {
startAtPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME));
currentRecordCount = executionContext.getLong(getExecutionContextKey(WRITE_STATISTICS_NAME));
restarted = true;
if (shouldDeleteIfEmpty && currentRecordCount == 0) {
// previous execution deleted the output file because no items were written
restarted = false;
startAtPosition = 0;
} else {
restarted = true;
}
}
open(startAtPosition, restarted);