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:
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
@@ -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.
|
||||
*/
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.io.xml.stax;
|
||||
package org.springframework.batch.io.xml;
|
||||
|
||||
import javax.xml.stream.XMLEventReader;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.springframework.batch.io.xml.stax;
|
||||
package org.springframework.batch.io.xml;
|
||||
|
||||
import javax.xml.stream.XMLEventWriter;
|
||||
|
||||
@@ -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";
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user