IN PROGRESS - issue BATCH-267: Re-organise I/O (io) packages

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

Remove package cycles
This commit is contained in:
dsyer
2007-12-31 17:13:40 +00:00
parent 12d7203c03
commit 03ea1e3826
62 changed files with 194 additions and 143 deletions

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.io.file.transform;
package org.springframework.batch.io.file;
/**
* Generic converter interface for transforming an object into another form for

View File

@@ -23,6 +23,7 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.io.Skippable;
import org.springframework.batch.io.file.separator.LineReader;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
@@ -56,7 +57,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
private Properties statistics = new Properties();
/**
* Initialize the input source.
* Initialize the input source.
*/
public void open() {
registerSynchronization();
@@ -88,11 +89,11 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
int lineCount = Integer.parseInt(data.getProperties().getProperty(READ_STATISTICS_NAME));
ResourceLineReader reader = getReader();
LineReader reader = getReader();
Object record = "";
while (reader.getCurrentLineCount() < lineCount && record != null) {
record = reader.read();
record = readLine();
}
}
@@ -111,7 +112,7 @@ public class DefaultFlatFileItemReader extends SimpleFlatFileItemReader implemen
* @see org.springframework.batch.statistics.StatisticsProvider#getStatistics()
*/
public Properties getStatistics() {
ResourceLineReader is = getReader();
LineReader is = getReader();
statistics.setProperty(READ_STATISTICS_NAME, String.valueOf(is.getCurrentLineCount()));
return statistics;
}

View File

@@ -30,7 +30,6 @@ import java.util.Properties;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.io.file.transform.Converter;
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.ResourceLifecycle;

View File

@@ -19,7 +19,11 @@ package org.springframework.batch.io.file;
import java.io.IOException;
import org.springframework.batch.io.exception.FlatFileParsingException;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.io.file.separator.LineReader;
import org.springframework.batch.io.file.separator.RecordSeparatorPolicy;
import org.springframework.batch.io.file.separator.ResourceLineReader;
import org.springframework.batch.io.file.transform.AbstractLineTokenizer;
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.io.file.transform.LineTokenizer;
@@ -59,7 +63,7 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
* Encapsulates the state of the input source. If it is null then we are
* uninitialized.
*/
private ResourceLineReader reader;
private LineReader reader;
private RecordSeparatorPolicy recordSeparatorPolicy;
@@ -126,10 +130,11 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
/**
* Initialize the reader if necessary.
* @throws IllegalStateException if the resource cannot be opened
*/
public void open() {
if (reader == null) {
reader = new ResourceLineReader(resource, encoding);
public void open() throws IllegalStateException {
if (this.reader == null) {
ResourceLineReader reader = new ResourceLineReader(resource, encoding);
if (recordSeparatorPolicy != null) {
reader.setRecordSeparatorPolicy(recordSeparatorPolicy);
}
@@ -137,6 +142,7 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
reader.setComments(comments);
}
reader.open();
this.reader = reader;
}
for (int i = 0; i < linesToSkip; i++) {
@@ -182,16 +188,22 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
// Reads first valid line.
protected String readLine() {
return (String) getReader().read();
try {
return (String) getReader().read();
}
catch (Exception e) {
throw new IllegalStateException(e);
}
}
/**
* A wrapper for {@link #readFieldSet()} to make this into a real
* {@link ItemReader}.
* @throws Exception
*
* @see org.springframework.batch.io.ItemReader#read()
*/
public Object read() {
public Object read() throws Exception {
String line = readLine();
if (line != null) {
@@ -237,7 +249,7 @@ public class SimpleFlatFileItemReader extends AbstractItemReader implements Item
}
// Returns object representing state of the input template.
protected ResourceLineReader getReader() {
protected LineReader getReader() {
if (reader == null) {
open();
// reader is now not null, or else an exception is thrown

View File

@@ -26,8 +26,6 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.NotWritablePropertyException;
@@ -156,7 +154,7 @@ public class BeanWrapperFieldSetMapper implements FieldSetMapper, BeanFactoryAwa
* the {@link DataBinder} from {@link #createBinder(Object)} has errors
* after binding).
*
* @see org.springframework.batch.io.file.FieldSetMapper#mapLine(org.springframework.batch.io.file.FieldSet)
* @see org.springframework.batch.io.file.mapping.FieldSetMapper#mapLine(org.springframework.batch.io.file.mapping.FieldSet)
*/
public Object mapLine(FieldSet fs) {
Object copy = getBean();

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.io.file;
package org.springframework.batch.io.file.mapping;
import java.math.BigDecimal;
import java.text.ParseException;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.io.file;
package org.springframework.batch.io.file.mapping;
/**
@@ -26,16 +26,6 @@ package org.springframework.batch.io.file;
*/
public interface FieldSetMapper {
/**
* Marker for the beginning of a multi-object record.
*/
static Object BEGIN_RECORD = new Object();
/**
* Marker for the end of a multi-object record.
*/
static Object END_RECORD = new Object();
/**
* Method used to map data obtained from a file into an object.
*/

View File

@@ -0,0 +1,42 @@
/*
* Copyright 2006-2007 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.batch.io.file.separator;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ResourceLifecycle;
/**
* @author Dave Syer
*
*/
public interface LineReader extends ResourceLifecycle, ItemReader {
/**
* @return
*/
int getCurrentLineCount();
/**
*
*/
void mark();
/**
*
*/
void reset();
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.batch.io.file;
package org.springframework.batch.io.file.separator;
import java.io.BufferedReader;
import java.io.IOException;
@@ -26,8 +26,6 @@ import java.util.HashSet;
import java.util.Iterator;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.io.file.separator.DefaultRecordSeparatorPolicy;
import org.springframework.batch.io.file.separator.RecordSeparatorPolicy;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ResourceLifecycle;
import org.springframework.batch.item.provider.AbstractItemReader;
@@ -58,7 +56,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
* @author Rob Harrop
*/
class ResourceLineReader extends AbstractItemReader implements ResourceLifecycle, ItemReader,
public class ResourceLineReader extends AbstractItemReader implements LineReader, ResourceLifecycle, ItemReader,
DisposableBean {
private static final Collection DEFAULT_COMMENTS = Collections

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.io.file.transform;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
/**

View File

@@ -16,7 +16,8 @@
package org.springframework.batch.io.file.transform;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
/**
* Interface that is used by framework to split string obtained typically from a

View File

@@ -21,7 +21,7 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
public class PrefixMatchingCompositeLineTokenizer implements LineTokenizer {

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.io.xml.stax;
package org.springframework.batch.io.xml;
import javax.xml.stream.XMLEventReader;

View File

@@ -1,4 +1,4 @@
package org.springframework.batch.io.xml.stax;
package org.springframework.batch.io.xml;
import javax.xml.stream.XMLEventWriter;

View File

@@ -15,7 +15,6 @@ import javax.xml.stream.events.StartElement;
import org.springframework.batch.io.Skippable;
import org.springframework.batch.io.xml.stax.DefaultFragmentEventReader;
import org.springframework.batch.io.xml.stax.DefaultTransactionalEventReader;
import org.springframework.batch.io.xml.stax.FragmentDeserializer;
import org.springframework.batch.io.xml.stax.FragmentEventReader;
import org.springframework.batch.io.xml.stax.TransactionalEventReader;
import org.springframework.batch.item.ItemReader;
@@ -44,7 +43,7 @@ import org.springframework.util.Assert;
*
* @author Robert Kasanicky
*/
public class StaxEventReaderItemReader extends AbstractItemReader implements ItemReader, ResourceLifecycle,
public class StaxEventItemReader extends AbstractItemReader implements ItemReader, ResourceLifecycle,
Skippable, Restartable, StatisticsProvider, InitializingBean, DisposableBean {
public static final String READ_COUNT_STATISTICS_NAME = "StaxEventReaderItemReader.readCount";

View File

@@ -16,7 +16,6 @@ import javax.xml.stream.XMLStreamException;
import org.springframework.batch.io.support.FileUtils;
import org.springframework.batch.io.xml.stax.NoStartEndDocumentStreamWriter;
import org.springframework.batch.io.xml.stax.ObjectToXmlSerializer;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.ResourceLifecycle;
import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager;
@@ -43,7 +42,7 @@ import org.springframework.util.CollectionUtils;
* @author Peter Zozom
*
*/
public class StaxEventWriterItemWriter implements ItemWriter, ResourceLifecycle, Restartable,
public class StaxEventItemWriter implements ItemWriter, ResourceLifecycle, Restartable,
StatisticsProvider, InitializingBean, DisposableBean {
// default encoding

View File

@@ -5,7 +5,7 @@ import java.io.IOException;
import javax.xml.stream.XMLEventWriter;
import javax.xml.transform.Result;
import org.springframework.batch.io.xml.stax.ObjectToXmlSerializer;
import org.springframework.batch.io.xml.ObjectToXmlSerializer;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.oxm.Marshaller;
import org.springframework.xml.transform.StaxResult;

View File

@@ -4,7 +4,7 @@ import java.io.IOException;
import javax.xml.stream.XMLEventReader;
import org.springframework.batch.io.xml.stax.FragmentDeserializer;
import org.springframework.batch.io.xml.FragmentDeserializer;
import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.oxm.Unmarshaller;
import org.springframework.util.Assert;

View File

@@ -21,15 +21,15 @@ import java.util.Collection;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.ItemReader;
/**
* An {@link ItemReader} that delivers a list as its item, storing up objects
* from the injected {@link ItemReader} until they are ready to be packed out
* as a collection. The {@link ItemReader} should mark the beginning and end of
* records with the constant values in {@link FieldSetMapper} ({@link FieldSetMapper#BEGIN_RECORD}
* and {@link FieldSetMapper#END_RECORD}).<br/>
* records with the constant values in {@link FieldSetMapper} ({@link AggregateItemReader#BEGIN_RECORD}
* and {@link AggregateItemReader#END_RECORD}).<br/>
*
* This class is thread safe (it can be used concurrently by multiple threads)
* as long as the {@link ItemReader} is also thread safe.
@@ -44,6 +44,16 @@ public class AggregateItemReader extends AbstractItemReader {
private ItemReader inputSource;
/**
* Marker for the end of a multi-object record.
*/
public static final Object END_RECORD = new Object();
/**
* Marker for the beginning of a multi-object record.
*/
public static final Object BEGIN_RECORD = new Object();
/**
* Get the next list of records.
* @throws Exception
@@ -73,13 +83,13 @@ public class AggregateItemReader extends AbstractItemReader {
}
// start a new collection
if (value == FieldSetMapper.BEGIN_RECORD) {
if (value == AggregateItemReader.BEGIN_RECORD) {
log.debug("Start of new record detected");
return true;
}
// mark we are finished with current collection
if (value == FieldSetMapper.END_RECORD) {
if (value == AggregateItemReader.END_RECORD) {
log.debug("End of record detected");
return false;
}

View File

@@ -21,8 +21,8 @@ import java.io.IOException;
import junit.framework.TestCase;
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.restart.RestartData;
import org.springframework.core.io.ByteArrayResource;
@@ -87,7 +87,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
* Test skip and skipRollback functionality
* @throws IOException
*/
public void testSkip() throws IOException {
public void testSkip() throws Exception {
inputSource.close();
inputSource.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));
@@ -122,7 +122,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
* Test skip and skipRollback functionality
* @throws IOException
*/
public void testTransactionSynchronizationUnknown() throws IOException {
public void testTransactionSynchronizationUnknown() throws Exception {
inputSource.close();
inputSource.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));
@@ -164,7 +164,7 @@ public class DefaultFlatFileItemReaderTests extends TestCase {
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
}
public void testRestart() throws IOException {
public void testRestart() throws Exception {
inputSource.close();
inputSource.setResource(getInputResource("testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"));

View File

@@ -21,7 +21,7 @@ import java.text.ParseException;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
public class FieldSetTests extends TestCase {
FieldSet fieldSet;

View File

@@ -25,7 +25,6 @@ import java.util.Collections;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FlatFileItemWriter;
import org.springframework.batch.io.file.transform.Converter;
import org.springframework.batch.restart.RestartData;
import org.springframework.core.io.FileSystemResource;
import org.springframework.transaction.support.TransactionSynchronization;

View File

@@ -22,7 +22,7 @@ import java.io.InputStream;
import junit.framework.TestCase;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.io.file.ResourceLineReader;
import org.springframework.batch.io.file.separator.ResourceLineReader;
import org.springframework.batch.io.file.separator.SuffixRecordSeparatorPolicy;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;

View File

@@ -25,9 +25,9 @@ import junit.framework.TestCase;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.io.exception.FlatFileParsingException;
import org.springframework.batch.io.file.DefaultFlatFileItemReader;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.SimpleFlatFileItemReader;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.io.file.separator.DefaultRecordSeparatorPolicy;
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.io.file.transform.LineTokenizer;
@@ -90,14 +90,14 @@ public class SimpleFlatFileItemReaderTests extends TestCase {
/**
* Regular usage of <code>read</code> method
*/
public void testRead() throws IOException {
public void testRead() throws Exception {
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
}
/**
* Regular usage of <code>read</code> method
*/
public void testReadExhausted() throws IOException {
public void testReadExhausted() throws Exception {
assertEquals("[FlatFileInputTemplate-TestData]", inputSource.read().toString());
assertEquals(null, inputSource.read());
}
@@ -105,7 +105,7 @@ public class SimpleFlatFileItemReaderTests extends TestCase {
/**
* Regular usage of <code>read</code> method
*/
public void testReadWithTokenizerError() throws IOException {
public void testReadWithTokenizerError() throws Exception {
inputSource.setTokenizer(new LineTokenizer() {
public FieldSet tokenize(String line) {
throw new RuntimeException("foo");
@@ -120,7 +120,7 @@ public class SimpleFlatFileItemReaderTests extends TestCase {
}
}
public void testReadWithMapperError() throws IOException {
public void testReadWithMapperError() throws Exception {
inputSource.setFieldSetMapper(new FieldSetMapper(){
public Object mapLine(FieldSet fs) {
throw new RuntimeException("foo");

View File

@@ -24,7 +24,6 @@ import java.util.Properties;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.io.file.mapping.BindingException;
import org.springframework.batch.support.IntArrayPropertyEditor;

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.io.file.transform;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.transform.AbstractLineTokenizer;
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.io.file.transform;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.transform.FixedLengthTokenizer;
import org.springframework.batch.io.file.transform.Range;

View File

@@ -23,9 +23,8 @@ import java.util.Map;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.transform.DelimitedLineTokenizer;
import org.springframework.batch.io.file.transform.LineTokenizer;
import org.springframework.batch.io.file.transform.PrefixMatchingCompositeLineTokenizer;
public class PrefixMatchingCompositeLineTokenizerTests extends TestCase {

View File

@@ -15,8 +15,7 @@ import javax.xml.stream.events.XMLEvent;
import junit.framework.TestCase;
import org.springframework.batch.io.xml.StaxEventReaderItemReader;
import org.springframework.batch.io.xml.stax.FragmentDeserializer;
import org.springframework.batch.io.xml.StaxEventItemReader;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
import org.springframework.core.io.AbstractResource;
@@ -26,14 +25,14 @@ import org.springframework.dao.DataAccessResourceFailureException;
import org.springframework.transaction.support.TransactionSynchronization;
/**
* Tests for {@link StaxEventReaderItemReader}.
* Tests for {@link StaxEventItemReader}.
*
* @author Robert Kasanicky
*/
public class StaxEventReaderItemReaderTests extends TestCase {
// object under test
private StaxEventReaderItemReader source;
private StaxEventItemReader source;
// test xml input
private String xml = "<root> <fragment> <misc1/> </fragment> <misc2/> <fragment> testString </fragment> </root>";
@@ -258,13 +257,13 @@ public class StaxEventReaderItemReaderTests extends TestCase {
private int extractRecordCountFrom(Properties statistics) {
return Integer.valueOf(
source.getStatistics().getProperty(StaxEventReaderItemReader.READ_COUNT_STATISTICS_NAME)).intValue();
source.getStatistics().getProperty(StaxEventItemReader.READ_COUNT_STATISTICS_NAME)).intValue();
}
private StaxEventReaderItemReader createNewInputSouce() {
private StaxEventItemReader createNewInputSouce() {
Resource resource = new ByteArrayResource(xml.getBytes());
StaxEventReaderItemReader newSource = new StaxEventReaderItemReader();
StaxEventItemReader newSource = new StaxEventItemReader();
newSource.setResource(resource);
newSource.setFragmentRootElementName(FRAGMENT_ROOT_ELEMENT);
@@ -349,7 +348,7 @@ public class StaxEventReaderItemReaderTests extends TestCase {
}
private static class MockStaxEventReaderItemReader extends StaxEventReaderItemReader {
private static class MockStaxEventReaderItemReader extends StaxEventItemReader {
private boolean openCalled = false;

View File

@@ -11,7 +11,7 @@ import javax.xml.transform.Result;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.springframework.batch.io.xml.StaxEventWriterItemWriter;
import org.springframework.batch.io.xml.StaxEventItemWriter;
import org.springframework.batch.io.xml.oxm.MarshallingObjectToXmlSerializer;
import org.springframework.batch.restart.RestartData;
import org.springframework.core.io.FileSystemResource;
@@ -28,7 +28,7 @@ import org.springframework.xml.transform.StaxResult;
public class StaxEventWriterItemWriterTests extends TestCase {
// object under test
private StaxEventWriterItemWriter writer;
private StaxEventItemWriter writer;
// output file
private Resource resource;
@@ -119,7 +119,7 @@ public class StaxEventWriterItemWriterTests extends TestCase {
final int NUMBER_OF_RECORDS = 10;
for (int i = 0; i < NUMBER_OF_RECORDS; i++) {
String writeStatistics =
writer.getStatistics().getProperty(StaxEventWriterItemWriter.WRITE_STATISTICS_NAME);
writer.getStatistics().getProperty(StaxEventItemWriter.WRITE_STATISTICS_NAME);
assertEquals(String.valueOf(i), writeStatistics);
writer.write(record);
@@ -188,8 +188,8 @@ public class StaxEventWriterItemWriterTests extends TestCase {
/**
* @return new instance of fully configured writer
*/
private StaxEventWriterItemWriter createItemWriter() throws Exception {
StaxEventWriterItemWriter source = new StaxEventWriterItemWriter();
private StaxEventItemWriter createItemWriter() throws Exception {
StaxEventItemWriter source = new StaxEventItemWriter();
source.setResource(resource);
Marshaller marshaller = new SimpleMarshaller();

View File

@@ -12,7 +12,6 @@ import junit.framework.TestCase;
import org.springframework.batch.io.xml.EventHelper;
import org.springframework.batch.io.xml.stax.DefaultFragmentEventReader;
import org.springframework.batch.io.xml.stax.DefaultTransactionalEventReader;
import org.springframework.batch.io.xml.stax.FragmentEventReader;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;

View File

@@ -7,7 +7,6 @@ import junit.framework.TestCase;
import org.springframework.batch.io.xml.EventHelper;
import org.springframework.batch.io.xml.stax.DefaultTransactionalEventReader;
import org.springframework.batch.io.xml.stax.TransactionalEventReader;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;

View File

@@ -6,7 +6,6 @@ import java.util.Iterator;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.item.ItemReader;
public class AggregateItemReaderTests extends TestCase {
@@ -30,11 +29,11 @@ public class AggregateItemReaderTests extends TestCase {
//set-up mock input
input.read();
inputControl.setReturnValue(FieldSetMapper.BEGIN_RECORD);
inputControl.setReturnValue(AggregateItemReader.BEGIN_RECORD);
input.read();
inputControl.setReturnValue("line",3);
input.read();
inputControl.setReturnValue(FieldSetMapper.END_RECORD);
inputControl.setReturnValue(AggregateItemReader.END_RECORD);
input.read();
inputControl.setReturnValue(null);
inputControl.replay();

View File

@@ -18,9 +18,9 @@ package org.springframework.batch.repeat.support;
import junit.framework.TestCase;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.SimpleFlatFileItemReader;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.provider.DelegatingItemReader;
import org.springframework.core.io.ClassPathResource;

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.repeat.support;
import java.math.BigDecimal;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
/**
* @author Rob Harrop

View File

@@ -7,7 +7,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.io.oxm.domain.Trade;
import org.springframework.batch.io.xml.StaxEventReaderItemReader;
import org.springframework.batch.io.xml.StaxEventItemReader;
import org.springframework.batch.io.xml.oxm.UnmarshallingFragmentDeserializer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
@@ -15,7 +15,7 @@ import org.springframework.oxm.Unmarshaller;
public abstract class AbstractStaxEventReaderItemReaderTests extends TestCase {
private StaxEventReaderItemReader source = new StaxEventReaderItemReader();
private StaxEventItemReader source = new StaxEventItemReader();
protected Resource resource = new ClassPathResource(
"org/springframework/batch/io/oxm/input.xml");

View File

@@ -12,7 +12,7 @@ import junit.framework.TestCase;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.springframework.batch.io.oxm.domain.Trade;
import org.springframework.batch.io.xml.StaxEventWriterItemWriter;
import org.springframework.batch.io.xml.StaxEventItemWriter;
import org.springframework.batch.io.xml.oxm.MarshallingObjectToXmlSerializer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.FileSystemResource;
@@ -21,7 +21,7 @@ import org.springframework.oxm.Marshaller;
public abstract class AbstractStaxEventWriterItemWriterTests extends TestCase {
private StaxEventWriterItemWriter writer = new StaxEventWriterItemWriter();
private StaxEventItemWriter writer = new StaxEventItemWriter();
private Resource resource;

View File

@@ -22,7 +22,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSet;
/**
* ResultSetExtractor implementation that returns list of FieldSets

View File

@@ -16,7 +16,7 @@
package org.springframework.batch.sample.dao;
import org.springframework.batch.io.file.transform.Converter;
import org.springframework.batch.io.file.Converter;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.sample.domain.Order;

View File

@@ -21,7 +21,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.batch.io.file.transform.Converter;
import org.springframework.batch.io.file.Converter;
import org.springframework.batch.io.file.transform.LineAggregator;
import org.springframework.batch.sample.domain.Address;
import org.springframework.batch.sample.domain.BillingInfo;

View File

@@ -22,8 +22,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.provider.AbstractItemReader;
import org.springframework.batch.item.validator.Validator;

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Address;

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.BillingInfo;

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Customer;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Game;
public class GameMapper implements FieldSetMapper {

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Order;

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.LineItem;

View File

@@ -15,8 +15,8 @@
*/
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
/**
* Pass through {@link FieldSetMapper} useful for

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Player;
public class PlayerMapper implements FieldSetMapper {

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.ShippingInfo;

View File

@@ -16,8 +16,9 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.provider.AggregateItemReader;
import org.springframework.batch.sample.domain.Trade;
@@ -32,11 +33,11 @@ public class TradeFieldSetMapper implements FieldSetMapper {
public Object mapLine(FieldSet fieldSet) {
if ("BEGIN".equals(fieldSet.readString(0))) {
return FieldSetMapper.BEGIN_RECORD;
return AggregateItemReader.BEGIN_RECORD;
}
if ("END".equals(fieldSet.readString(0))) {
return FieldSetMapper.END_RECORD;
return AggregateItemReader.END_RECORD;
}
Trade trade = new Trade();

View File

@@ -22,7 +22,7 @@
class="org.springframework.batch.execution.tasklet.RestartableItemOrientedTasklet">
<property name="itemReader">
<bean
class="org.springframework.batch.io.xml.StaxEventReaderItemReader"
class="org.springframework.batch.io.xml.StaxEventItemReader"
scope="step">
<aop:scoped-proxy />
<property name="fragmentRootElementName"
@@ -56,7 +56,7 @@
</bean>
<bean
class="org.springframework.batch.io.xml.StaxEventWriterItemWriter"
class="org.springframework.batch.io.xml.StaxEventItemWriter"
id="tradeStaxWriter">
<property name="resource"
value="file:target/test-outputs/20070918.testStream.xmlFileStep.output.xml" />

View File

@@ -48,15 +48,22 @@ public class FixedLengthImportJobFunctionalTests extends AbstractValidatingBatch
/**
* check that records have been correctly written to database
* @throws Exception
*/
protected void validatePostConditions() {
protected void validatePostConditions() throws Exception {
inputSource.open();
jdbcTemplate.query("SELECT ID, ISIN, QUANTITY, PRICE, CUSTOMER FROM trade ORDER BY id", new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
Trade trade = (Trade)inputSource.read();
Trade trade;
try {
trade = (Trade)inputSource.read();
}
catch (Exception e) {
throw new IllegalStateException(e);
}
assertEquals(trade.getIsin(), rs.getString(2));
assertEquals(trade.getQuantity(),rs.getLong(3));
assertEquals(trade.getPrice(), rs.getBigDecimal(4));

View File

@@ -5,8 +5,8 @@ import java.util.Iterator;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.validator.Validator;
import org.springframework.batch.sample.domain.Address;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import junit.framework.TestCase;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Address;
import org.springframework.batch.sample.mapping.AddressFieldSetMapper;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.BillingInfo;
import org.springframework.batch.sample.mapping.BillingFieldSetMapper;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Customer;
import org.springframework.batch.sample.mapping.CustomerFieldSetMapper;

View File

@@ -2,8 +2,8 @@ package org.springframework.batch.sample.mapping;
import java.util.Calendar;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.Order;
import org.springframework.batch.sample.mapping.HeaderFieldSetMapper;

View File

@@ -2,8 +2,8 @@ package org.springframework.batch.sample.mapping;
import java.math.BigDecimal;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.LineItem;
import org.springframework.batch.sample.mapping.OrderItemFieldSetMapper;

View File

@@ -1,7 +1,7 @@
package org.springframework.batch.sample.mapping;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.sample.domain.ShippingInfo;
import org.springframework.batch.sample.mapping.ShippingFieldSetMapper;

View File

@@ -2,8 +2,9 @@ package org.springframework.batch.sample.mapping;
import java.math.BigDecimal;
import org.springframework.batch.io.file.FieldSet;
import org.springframework.batch.io.file.FieldSetMapper;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetMapper;
import org.springframework.batch.item.provider.AggregateItemReader;
import org.springframework.batch.sample.domain.Trade;
import org.springframework.batch.sample.mapping.TradeFieldSetMapper;
@@ -38,11 +39,11 @@ public class TradeFieldSetMapperTests extends AbstractFieldSetMapperTests{
}
public void testBeginRecord() throws Exception {
assertEquals(FieldSetMapper.BEGIN_RECORD, fieldSetMapper().mapLine(new FieldSet(new String[] {"BEGIN"})));
assertEquals(AggregateItemReader.BEGIN_RECORD, fieldSetMapper().mapLine(new FieldSet(new String[] {"BEGIN"})));
}
public void testEndRecord() throws Exception {
assertEquals(FieldSetMapper.END_RECORD, fieldSetMapper().mapLine(new FieldSet(new String[] {"END"})));
assertEquals(AggregateItemReader.END_RECORD, fieldSetMapper().mapLine(new FieldSet(new String[] {"END"})));
}
}