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 15:15:28 +00:00
parent c82c930d4d
commit 36e1e658ae
2 changed files with 19 additions and 31 deletions

View File

@@ -7,7 +7,6 @@ import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import javax.xml.stream.XMLEventFactory; import javax.xml.stream.XMLEventFactory;
import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLEventWriter;
@@ -19,7 +18,7 @@ import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter;
import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamContext;
import org.springframework.batch.item.stream.GenericStreamContext; import org.springframework.batch.item.StreamException;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager; import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
@@ -52,10 +51,10 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
private static final String DEFAULT_ROOT_TAG_NAME = "root"; private static final String DEFAULT_ROOT_TAG_NAME = "root";
// restart data property name // restart data property name
private static final String RESTART_DATA_NAME = "staxstreamoutputsource.position"; public static final String RESTART_DATA_NAME = "staxstreamoutputsource.position";
// read statistics property name // restart data property name
public static final String WRITE_STATISTICS_NAME = "staxstreamoutputsource.processedrecordcount"; public static final String WRITE_STATISTICS_NAME = "staxstreamoutputsource.record.count";
// file system resource // file system resource
private Resource resource; private Resource resource;
@@ -379,12 +378,13 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
* @see org.springframework.batch.item.ItemStream#getStreamContext() * @see org.springframework.batch.item.ItemStream#getStreamContext()
*/ */
public StreamContext getStreamContext() { public StreamContext getStreamContext() {
if (!initialized) {
Properties properties = new Properties(); throw new StreamException("ItemStream is not open, or may have been closed. Cannot access context.");
}
properties.setProperty(RESTART_DATA_NAME, String.valueOf(getPosition())); StreamContext context = new StreamContext();
context.putLong(RESTART_DATA_NAME, getPosition());
return new GenericStreamContext(properties); context.putLong(WRITE_STATISTICS_NAME, currentRecordCount);
return context;
} }
/** /**
@@ -398,8 +398,8 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
// if restart data is provided, restart from provided offset // if restart data is provided, restart from provided offset
// otherwise start from beginning // otherwise start from beginning
if (data != null && data.getProperties() != null && data.getProperties().getProperty(RESTART_DATA_NAME) != null) { if (data != null && data.getProperties() != null && data.containsKey(RESTART_DATA_NAME)) {
startAtPosition = Long.parseLong(data.getProperties().getProperty(RESTART_DATA_NAME)); startAtPosition = data.getLong(RESTART_DATA_NAME);
restarted = true; restarted = true;
} }
@@ -409,17 +409,6 @@ public class StaxEventItemWriter implements ItemWriter, ItemStream, Initializing
} }
/**
* Get actual statistics for output source.
* @return
* @see org.springframework.batch.statistics.StatisticsProvider#getStatistics()
*/
public Properties getStatistics() {
Properties p = new Properties();
p.setProperty(WRITE_STATISTICS_NAME, String.valueOf(currentRecordCount));
return p;
}
/* /*
* Get the actual position in file channel. This method flushes any buffered * Get the actual position in file channel. This method flushes any buffered
* data before position is read. * data before position is read.

View File

@@ -11,7 +11,6 @@ import javax.xml.transform.Result;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.springframework.batch.io.xml.StaxEventItemWriter;
import org.springframework.batch.io.xml.oxm.MarshallingEventWriterSerializer; import org.springframework.batch.io.xml.oxm.MarshallingEventWriterSerializer;
import org.springframework.batch.item.StreamContext; import org.springframework.batch.item.StreamContext;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
@@ -115,14 +114,14 @@ public class StaxEventWriterItemWriterTests extends TestCase {
/** /**
* Count of 'records written so far' is returned as statistics. * Count of 'records written so far' is returned as statistics.
*/ */
public void testStatistics() throws Exception { public void testStreamContext() throws Exception {
final int NUMBER_OF_RECORDS = 10; final int NUMBER_OF_RECORDS = 10;
for (int i = 0; i < NUMBER_OF_RECORDS; i++) { for (int i = 1; i <= NUMBER_OF_RECORDS; i++) {
String writeStatistics =
writer.getStatistics().getProperty(StaxEventItemWriter.WRITE_STATISTICS_NAME);
assertEquals(String.valueOf(i), writeStatistics);
writer.write(record); writer.write(record);
long writeStatistics =
writer.getStreamContext().getLong(StaxEventItemWriter.WRITE_STATISTICS_NAME);
assertEquals(i, writeStatistics);
} }
} }