IN PROGRESS - issue BATCH-7: Remove transaction synchronization and state management from input/output sources (formerly buffering)

http://jira.springframework.org/browse/BATCH-7

More Statistics removal
This commit is contained in:
dsyer
2008-01-31 14:45:39 +00:00
parent 93639e1928
commit c2ccb7ed02
14 changed files with 69 additions and 93 deletions

View File

@@ -72,15 +72,11 @@ import org.springframework.util.StringUtils;
* </p>
*
* <p>
* Restart: This implementation contains basic, simple restart. The current row
* is returned as restart data, and when restored from that same data, the
* cursor is opened and the current row set to the value within the restart
* data.
* </p>
*
* <p>
* Statistics: There are two statistics returned by this input source: the
* current line being processed and the number of lines that have been skipped.
* {@link StreamContext}: The current row is returned as restart data, and when
* restored from that same data, the cursor is opened and the current row set to
* the value within the restart data. There are also two statistics returned by
* this input source: the current line being processed and the number of lines
* that have been skipped.
* </p>
*
* <p>
@@ -216,7 +212,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
}
}
Object mappedResult = mapper.mapRow(rs, (int)currentProcessedRow);
Object mappedResult = mapper.mapRow(rs, (int) currentProcessedRow);
verifyCursorPosition(currentProcessedRow);
@@ -251,7 +247,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
try {
currentProcessedRow = lastCommittedRow;
if (currentProcessedRow > 0) {
rs.absolute((int)currentProcessedRow);
rs.absolute((int) currentProcessedRow);
}
else {
rs.beforeFirst();
@@ -405,8 +401,8 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
return context;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.batch.item.ItemStream#restoreFrom(org.springframework.batch.item.StreamContext)
*/
public void restoreFrom(StreamContext data) {
@@ -424,7 +420,7 @@ public class JdbcCursorItemReader extends AbstractTransactionalIoSource implemen
try {
this.currentProcessedRow = data.getLong(CURRENT_PROCESSED_ROW);
rs.absolute((int)currentProcessedRow);
rs.absolute((int) currentProcessedRow);
}
catch (SQLException se) {
throw getExceptionTranslator().translate("Attempted to move ResultSet to last committed row", sql, se);

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.io.file;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -27,7 +26,6 @@ import org.springframework.batch.io.file.separator.LineReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.stream.GenericStreamContext;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
@@ -54,8 +52,6 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
private TransactionSynchronization transactionSynchronization = new ResourceLineReaderTransactionSynchronization();
private Properties statistics = new Properties();
/**
* Initialize the input source.
*/
@@ -104,19 +100,13 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
* case of restart.
*/
public StreamContext getStreamContext() {
return new GenericStreamContext(getStatistics());
}
/**
* @return statistics for input template
* @see org.springframework.batch.statistics.StatisticsProvider#getStatistics()
*/
public Properties getStatistics() {
if (reader==null) {
throw new StreamException("ItemStream not open or already closed.");
}
statistics.setProperty(READ_STATISTICS_NAME, String.valueOf(reader.getCurrentLineCount()));
return statistics;
StreamContext streamContext = new StreamContext();
streamContext.putLong(READ_STATISTICS_NAME, reader.getCurrentLineCount());
streamContext.putLong(SKIPPED_STATISTICS_NAME, skippedLines.size());
return streamContext;
}
/**

View File

@@ -34,6 +34,7 @@ import org.springframework.batch.io.support.AbstractTransactionalIoSource;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.StreamException;
import org.springframework.batch.item.stream.GenericStreamContext;
import org.springframework.batch.item.writer.ItemTransformer;
import org.springframework.beans.factory.DisposableBean;
@@ -71,11 +72,9 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
private Resource resource;
private Properties statistics = new Properties();
private StreamContext streamContext = new GenericStreamContext(new Properties());
private OutputState state = new OutputState();
private OutputState state = null;
private ItemTransformer transformer = new ItemTransformer() {
public Object transform(Object input) {
@@ -201,7 +200,10 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
* @see ResourceLifecycle#close()
*/
public void close() {
getOutputState().close();
if (state!=null) {
getOutputState().close();
state = null;
}
}
/**
@@ -240,27 +242,20 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
* @see ResourceLifecycle#open()
*/
public void open() {
getOutputState();
super.registerSynchronization();
}
/**
* @see StatisticsProvider
*/
public Properties getStatistics() {
final OutputState os = getOutputState();
statistics.setProperty(WRITTEN_STATISTICS_NAME, String.valueOf(os.linesWritten));
statistics.setProperty(RESTART_COUNT_STATISTICS_NAME, String.valueOf(os.restartCount));
return statistics;
}
/**
* @see ItemStream#getStreamContext()
*/
public StreamContext getStreamContext() {
final OutputState os = getOutputState();
streamContext.putString(RESTART_DATA_NAME, String.valueOf(os.position()));
if (state == null) {
throw new StreamException("ItemStream not open or already closed.");
}
streamContext.putLong(RESTART_DATA_NAME, state.position());
streamContext.putLong(WRITTEN_STATISTICS_NAME, state.linesWritten);
streamContext.putLong(RESTART_COUNT_STATISTICS_NAME, state.restartCount);
return streamContext;
}
@@ -277,6 +272,9 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
// Returns object representing state.
private OutputState getOutputState() {
if (state==null) {
state = new OutputState();
}
return (OutputState) state;
}

View File

@@ -99,6 +99,9 @@ public class StaxEventItemReader extends AbstractItemReader implements ItemReade
public void close() {
initialized = false;
if (fragmentReader==null && inputStream==null) {
return;
}
try {
fragmentReader.close();
inputStream.close();