diff --git a/infrastructure/src/main/java/org/springframework/batch/io/OutputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/ItemWriter.java similarity index 85% rename from infrastructure/src/main/java/org/springframework/batch/io/OutputSource.java rename to infrastructure/src/main/java/org/springframework/batch/io/ItemWriter.java index 0e96720ab..a291904d1 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/OutputSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/ItemWriter.java @@ -24,12 +24,12 @@ package org.springframework.batch.io; * * @author Dave Syer */ -public interface OutputSource { +public interface ItemWriter { /** - * Writes provided value object to an output stream or similar. + * Writes provided object to an output stream or similar. * - * @param output the value object + * @param item the object to write. */ - public void write(Object output); + public void write(Object item); } diff --git a/infrastructure/src/main/java/org/springframework/batch/io/file/support/FlatFileItemWriter.java b/infrastructure/src/main/java/org/springframework/batch/io/file/support/FlatFileItemWriter.java new file mode 100644 index 000000000..75a204216 --- /dev/null +++ b/infrastructure/src/main/java/org/springframework/batch/io/file/support/FlatFileItemWriter.java @@ -0,0 +1,547 @@ +/* + * 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.support; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.Channels; +import java.nio.channels.FileChannel; +import java.nio.charset.UnsupportedCharsetException; +import java.util.Collection; +import java.util.Iterator; +import java.util.Properties; + +import org.springframework.batch.io.ItemWriter; +import org.springframework.batch.io.exception.BatchCriticalException; +import org.springframework.batch.io.exception.BatchEnvironmentException; +import org.springframework.batch.io.file.support.transform.Converter; +import org.springframework.batch.io.support.AbstractTransactionalIoSource; +import org.springframework.batch.item.ResourceLifecycle; +import org.springframework.batch.restart.GenericRestartData; +import org.springframework.batch.restart.RestartData; +import org.springframework.batch.restart.Restartable; +import org.springframework.batch.statistics.StatisticsProvider; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.core.io.Resource; +import org.springframework.dao.DataAccessResourceFailureException; +import org.springframework.util.Assert; + +/** + * This class is an output target that writes data to a file or stream. The + * output source also provides restart, statistics and transaction features by + * implementing corresponding interfaces where possible (with a file). The + * location of the file is defined by a {@link Resource} and must represent a + * writable file.
+ * + * Uses buffered writer to improve performance.
+ * + * Use {@link #write(String)} method to output a line to an output source. + * + * @author Waseem Malik + * @author Tomas Slanina + * @author Robert Kasanicky + * @author Dave Syer + */ +public class FlatFileItemWriter extends AbstractTransactionalIoSource implements + ItemWriter, ResourceLifecycle, Restartable, StatisticsProvider, InitializingBean, + DisposableBean { + + /** + * @author dsyer + * + */ + public static class BooleanHolder { + + public boolean value; + + } + + private static final String LINE_SEPARATOR = System.getProperty("line.separator"); + + public static final String WRITTEN_STATISTICS_NAME = "Written"; + + public static final String RESTART_COUNT_STATISTICS_NAME = "Restart count"; + + public static final String RESTART_DATA_NAME = "flatfileoutputtemplate.currentLine"; + + private Resource resource; + + private Properties statistics = new Properties(); + + private RestartData restartData = new GenericRestartData(new Properties()); + + private OutputState state = new OutputState(); + + private Converter converter = new Converter() { + public Object convert(Object input) { + return "" + input; + } + }; + + public void afterPropertiesSet() throws Exception { + Assert.notNull(resource); + File file = resource.getFile(); + Assert.state(!file.exists() || file.canWrite(), "Resource is not writable: [" + resource + "]"); + } + + /** + * Public setter for the converter. If not-null this will be used to convert + * the input data before it is output. + * + * @param converter the converter to set + */ + public void setConverter(Converter converter) { + this.converter = converter; + } + + /** + * Setter for resource. Represents a file that can be written. + * + * @param resource + */ + public void setResource(Resource resource) { + this.resource = resource; + } + + /** + * Commit the transaction. + */ + protected void transactionCommitted() { + getOutputState().mark(); + } + + /** + * Rollback the transaction. + */ + protected void transactionRolledBack() { + getOutputState().checkFileSize(); + resetPositionForRestart(); + } + + // This method removes any information in the file before this reset point. + private void resetPositionForRestart() { + getOutputState().truncate(); + } + + /** + * Writes out a string followed by a "new line", where the format of the new + * line separator is determined by the underlying operating system. If the + * input is not a String and a converter is available the converter will be + * applied and then this method recursively called with the result. If the + * input is an array or collection each value will be written to a separate + * line (recursively calling this method for each value). If no converter is + * supplied the input object's toString method will be used.
+ * + * @param data Object (a String or Object that can be converted) to be + * written to output stream + */ + public void write(Object data) { + convertAndWrite(data, new BooleanHolder()); + } + + /** + * Convert the date to a format that can be output and then write it out. + * @param data + * @param converted + */ + private void convertAndWrite(Object data, BooleanHolder converted) { + + if (data instanceof Collection) { + converted.value = false; + for (Iterator iterator = ((Collection) data).iterator(); iterator.hasNext();) { + Object value = (Object) iterator.next(); + // (recursive) + write(value); + } + return; + } + if (data.getClass().isArray()) { + converted.value = false; + Object[] array = (Object[]) data; + for (int i = 0; i < array.length; i++) { + Object value = array[i]; + // (recursive) + write(value); + } + return; + } + if (data instanceof String) { + // This is where the output stream is actually written to + getOutputState().write(data + LINE_SEPARATOR); + } + else if (!converted.value) { + // (recursive) + converted.value = true; + convertAndWrite(converter.convert(data), converted); + return; + } + else { + // Should not happen... + throw new IllegalStateException( + "Infinite loop detected - converter did not convert to String or collection/array of objects convertible to String."); + } + } + + /** + * @see ResourceLifecycle#close() + */ + public void close() { + getOutputState().close(); + } + + /** + * Calls close to ensure that bean factories can close and always release + * resources. + * + * @see org.springframework.beans.factory.DisposableBean#destroy() + */ + public void destroy() throws Exception { + close(); + } + + /** + * Sets encoding for output template. + */ + public void setEncoding(String newEncoding) { + getOutputState().setEncoding(newEncoding); + } + + /** + * Sets buffer size for output template + */ + public void setBufferSize(int newSize) { + getOutputState().setBufferSize(newSize); + } + + /** + * @param shouldDeleteIfExists the shouldDeleteIfExists to set + */ + public void setShouldDeleteIfExists(boolean shouldDeleteIfExists) { + getOutputState().setShouldDeleteIfExists(shouldDeleteIfExists); + } + + /** + * Initialize the Output Template. + * @see ResourceLifecycle#open() + */ + public void open() { + 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 Restartable#getRestartData() + */ + public RestartData getRestartData() { + final OutputState os = getOutputState(); + + restartData.getProperties().setProperty(RESTART_DATA_NAME, String.valueOf(os.position())); + return restartData; + } + + /** + * @see Restartable#restoreFrom(RestartData) + */ + public void restoreFrom(RestartData data) { + if (data == null) + return; + + getOutputState().restoreFrom(data.getProperties()); + + } + + // Returns object representing state. + private OutputState getOutputState() { + return (OutputState) state; + } + + /** + * Encapsulates the runtime state of the output source. All state changing + * operations on the output source go through this class. + */ + private class OutputState { + // default encoding for writing to output files - set to UTF-8. + private static final String DEFAULT_CHARSET = "UTF-8"; + + private static final int DEFAULT_BUFFER_SIZE = 2048; + + // The bufferedWriter over the file channel that is actually written + BufferedWriter outputBufferedWriter; + + FileChannel fileChannel; + + // this represents the charset encoding (if any is needed) for the + // output file + String encoding = DEFAULT_CHARSET; + + // Optional write buffer size + int bufferSize = DEFAULT_BUFFER_SIZE; + + boolean restarted = false; + + boolean initialized = false; + + long lastMarkedByteOffsetPosition = 0; + + long linesWritten = 0; + + long restartCount = 0; + + boolean shouldDeleteIfExists = true; + + /** + * Return the byte offset position of the cursor in the output file as a + * long integer. + */ + public long position() { + long pos = 0; + + if (fileChannel == null) { + return 0; + } + + try { + outputBufferedWriter.flush(); + pos = fileChannel.position(); + } + catch (IOException e) { + throw new BatchCriticalException("An Error occured while trying to get filechannel position", e); + } + + return pos; + + } + + /** + * @param properties + */ + public void restoreFrom(Properties properties) { + lastMarkedByteOffsetPosition = Long.parseLong(properties.getProperty(RESTART_DATA_NAME)); + restarted = true; + } + + /** + * @param shouldDeleteIfExists2 + */ + public void setShouldDeleteIfExists(boolean shouldDeleteIfExists) { + this.shouldDeleteIfExists = shouldDeleteIfExists; + } + + /** + * @param newSize + */ + public void setBufferSize(int newSize) { + bufferSize = newSize; + } + + /** + * @param newEncoding + */ + public void setEncoding(String newEncoding) { + encoding = newEncoding; + } + + /** + * Close the open resource and reset counters. + */ + public void close() { + initialized = false; + restarted = false; + try { + if (outputBufferedWriter == null) { + return; + } + outputBufferedWriter.close(); + fileChannel.close(); + } + catch (IOException ioe) { + throw new BatchEnvironmentException("Unable to close the the Output Source", ioe); + } + } + + /** + * @param data + * @param offset + * @param length + */ + public void write(String line) { + if (!initialized) { + initializeBufferedWriter(); + } + + try { + outputBufferedWriter.write(line); + outputBufferedWriter.flush(); + linesWritten++; + } + catch (IOException e) { + throw new BatchCriticalException("An Error occured while trying to write to FileWriterOutputSource", e); + } + } + + /** + * Truncate the output at the last known good point. + */ + public void truncate() { + try { + fileChannel.truncate(lastMarkedByteOffsetPosition); + fileChannel.position(lastMarkedByteOffsetPosition); + } + catch (Exception e) { + throw new BatchCriticalException("An Error occured while reseting position in a file for restart", e); + } + } + + /** + * Mark the current position. + */ + public void mark() { + lastMarkedByteOffsetPosition = this.position(); + } + + /** + * Creates the buffered writer for the output file channel based on + * configuration information. + */ + private void initializeBufferedWriter() { + File file; + + try { + file = resource.getFile(); + + // If the output source was restarted, keep existing file. + // If the output source was not restarted, check following: + // - if the file should be deleted, delete it if it was exiting + // and create blank file, + // - if the file should not be deleted, if it already exists, + // throw an exception, + // - if the file was not existing, create new. + if (!restarted) { + if (file.exists()) { + if (shouldDeleteIfExists) { + file.delete(); + } + else { + throw new BatchEnvironmentException("Resource already exists: " + resource); + } + } + String parent = file.getParent(); + if (parent!=null) { + new File(parent).mkdirs(); + } + file.createNewFile(); + } + + } + catch (IOException ioe) { + throw new DataAccessResourceFailureException("Unable to write to file resource: [" + resource + "]", + ioe); + } + + try { + fileChannel = (new FileOutputStream(file.getAbsolutePath(), true)).getChannel(); + } + catch (FileNotFoundException fnfe) { + throw new BatchEnvironmentException("Bad filename property parameter " + file, fnfe); + } + + outputBufferedWriter = getBufferedWriter(fileChannel, encoding, bufferSize); + + // in case of restarting reset position to last commited point + if (restarted) { + this.resetPosition(); + } + + initialized = true; + linesWritten = 0; + } + + /** + * Returns the buffered writer opened to the beginning of the file + * specified by the absolute path name contained in absoluteFileName. + */ + private BufferedWriter getBufferedWriter(FileChannel fileChannel, String encoding, int bufferSize) { + try { + + BufferedWriter outputBufferedWriter = null; + + // If a buffer was requested, allocate. + if (bufferSize > 0) { + outputBufferedWriter = new BufferedWriter(Channels.newWriter(fileChannel, encoding), bufferSize); + } + else { + outputBufferedWriter = new BufferedWriter(Channels.newWriter(fileChannel, encoding)); + } + + return outputBufferedWriter; + } + catch (UnsupportedCharsetException ucse) { + throw new BatchEnvironmentException("Bad encoding configuration for output file " + fileChannel, ucse); + } + } + + /** + * Resets the file writer's current position to the point stored in the + * last marked byte offset position variable. It first checks to make + * sure the current size of the file is not less than the byte position + * to be moved to (if it is, throws an environment exception), then it + * truncates the file to that reset position, and set the cursor to + * start writing at that point. + */ + private void resetPosition() { + checkFileSize(); + resetPositionForRestart(); + } + + /** + * Checks (on setState) to make sure that the current output file's size + * is not smaller than the last saved commit point. If it is, then the + * file has been damaged in some way and whole task must be started over + * again from the beginning. + */ + public void checkFileSize() { + long size = -1; + + try { + outputBufferedWriter.flush(); + size = fileChannel.size(); + } + catch (Exception e) { + throw new BatchCriticalException("An Error occured while checking file size", e); + } + + if (size < lastMarkedByteOffsetPosition) { + throw new BatchCriticalException("Current file size is smaller than size at last commit"); + } + } + + } +} diff --git a/infrastructure/src/main/java/org/springframework/batch/io/file/support/StaxEventWriterOutputSource.java b/infrastructure/src/main/java/org/springframework/batch/io/file/support/StaxEventWriterItemWriter.java similarity index 94% rename from infrastructure/src/main/java/org/springframework/batch/io/file/support/StaxEventWriterOutputSource.java rename to infrastructure/src/main/java/org/springframework/batch/io/file/support/StaxEventWriterItemWriter.java index 45534bb53..96fa4b628 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/file/support/StaxEventWriterOutputSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/file/support/StaxEventWriterItemWriter.java @@ -14,7 +14,7 @@ import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.io.file.support.stax.NoStartEndDocumentStreamWriter; import org.springframework.batch.io.file.support.stax.ObjectToXmlSerializer; import org.springframework.batch.io.support.FileUtils; @@ -34,7 +34,7 @@ import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; /** - * StaxEventWriterOutputSource is implementation of {@link OutputSource} which uses + * StaxEventWriterOutputSource is implementation of {@link ItemWriter} which uses * StAX and {@link ObjectToXmlSerializer} for serializing object to XML. * * This output source also provides restart, statistics and transaction @@ -43,7 +43,7 @@ import org.springframework.util.CollectionUtils; * @author Peter Zozom * */ -public class StaxEventWriterOutputSource implements OutputSource, ResourceLifecycle, Restartable, +public class StaxEventWriterItemWriter implements ItemWriter, ResourceLifecycle, Restartable, StatisticsProvider, InitializingBean, DisposableBean { // default encoding @@ -367,7 +367,7 @@ public class StaxEventWriterOutputSource implements OutputSource, ResourceLifecy * Write the value object to XML stream. * * @param output the value object - * @see org.springframework.batch.io.OutputSource#write(java.lang.Object) + * @see org.springframework.batch.io.ItemWriter#write(java.lang.Object) */ public void write(Object output) { diff --git a/infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java b/infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java index 96ae95eff..eb0163e58 100644 --- a/infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java +++ b/infrastructure/src/main/java/org/springframework/batch/io/support/AbstractTransactionalIoSource.java @@ -16,7 +16,7 @@ package org.springframework.batch.io.support; import org.springframework.batch.io.InputSource; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.repeat.synch.BatchTransactionSynchronizationManager; import org.springframework.beans.factory.InitializingBean; import org.springframework.transaction.support.TransactionSynchronization; @@ -25,7 +25,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager /** *

Abstract class that abstracts away transaction handling from input and output sources. - * Since every {@link InputSource} or {@link OutputSource by nature wants to be notified of + * Since every {@link InputSource} or {@link ItemWriter by nature wants to be notified of * transaction events to maintain the contract that all calls to read or write will ensure * that correct ordering is maintained regardless of rollbacks.

* diff --git a/infrastructure/src/main/java/org/springframework/batch/item/processor/ItemWriterItemProcessor.java b/infrastructure/src/main/java/org/springframework/batch/item/processor/ItemWriterItemProcessor.java new file mode 100644 index 000000000..e37969566 --- /dev/null +++ b/infrastructure/src/main/java/org/springframework/batch/item/processor/ItemWriterItemProcessor.java @@ -0,0 +1,104 @@ +package org.springframework.batch.item.processor; + +import java.util.Properties; + +import org.springframework.batch.io.ItemWriter; +import org.springframework.batch.io.Skippable; +import org.springframework.batch.item.ItemProcessor; +import org.springframework.batch.restart.GenericRestartData; +import org.springframework.batch.restart.RestartData; +import org.springframework.batch.restart.Restartable; +import org.springframework.batch.statistics.StatisticsProvider; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +/** + * Simple wrapper around {@link ItemWriter} providing {@link Restartable} and + * {@link StatisticsProvider} where the {@link ItemWriter} does. + * + * @author Dave Syer + * @author Robert Kasanicky + */ +public class ItemWriterItemProcessor implements ItemProcessor, Restartable, Skippable, + StatisticsProvider, InitializingBean { + + private ItemWriter source; + + /** + * Calls {@link #doProcess(Object)} and then writes the result to the output source. + * + * @see org.springframework.batch.item.ItemProcessor#process(java.lang.Object) + */ + final public void process(Object item) throws Exception { + Object result = doProcess(item); + source.write(result); + } + + /** + * By default returns the argument. This method is an extension point + * meant to be overridden by subclasses that implement processing logic. + */ + protected Object doProcess(Object item) { + return item; + } + + /** + * Setter for output source. + */ + public void setOutputSource(ItemWriter source) { + this.source = source; + } + + /** + * @see Restartable#getRestartData() + */ + public RestartData getRestartData() { + + Assert.state(source != null, "Source must not be null."); + + if (source instanceof Restartable) { + return ((Restartable) source).getRestartData(); + } + else{ + return new GenericRestartData(new Properties()); + } + } + + /** + * @see Restartable#restoreFrom(RestartData) + */ + public void restoreFrom(RestartData data) { + + Assert.state(source != null, "Source must not be null."); + + if (source instanceof Restartable) { + ((Restartable) source).restoreFrom(data); + } + + } + + /** + * @return delegates to the parent template of it is a + * {@link StatisticsProvider}, otherwise returns an empty + * {@link Properties} instance. + * @see StatisticsProvider#getStatistics() + */ + public Properties getStatistics() { + if (!(source instanceof StatisticsProvider)) { + return new Properties(); + } + return ((StatisticsProvider) source).getStatistics(); + } + + public void skip() { + if (source instanceof Skippable) { + ((Skippable)source).skip(); + } + } + + + public void afterPropertiesSet() throws Exception { + Assert.notNull(source); + } + +} diff --git a/infrastructure/src/main/java/org/springframework/batch/item/processor/TransformerOutputSourceItemProcessor.java b/infrastructure/src/main/java/org/springframework/batch/item/processor/TransformerWriterItemProcessor.java similarity index 72% rename from infrastructure/src/main/java/org/springframework/batch/item/processor/TransformerOutputSourceItemProcessor.java rename to infrastructure/src/main/java/org/springframework/batch/item/processor/TransformerWriterItemProcessor.java index c0007336c..b76babc7f 100644 --- a/infrastructure/src/main/java/org/springframework/batch/item/processor/TransformerOutputSourceItemProcessor.java +++ b/infrastructure/src/main/java/org/springframework/batch/item/processor/TransformerWriterItemProcessor.java @@ -1,15 +1,15 @@ package org.springframework.batch.item.processor; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.util.Assert; /** * Transforms the item using injected {@link ItemTransformer} - * before it is written to output by {@link OutputSource}. + * before it is written to output by {@link ItemWriter}. * * @author Robert Kasanicky */ -public class TransformerOutputSourceItemProcessor extends OutputSourceItemProcessor { +public class TransformerWriterItemProcessor extends ItemWriterItemProcessor { private ItemTransformer itemTransformer; @@ -22,7 +22,7 @@ public class TransformerOutputSourceItemProcessor extends OutputSourceItemProces /** * @param itemTransformer will transform the item before - * it is passed to {@link OutputSource}. + * it is passed to {@link ItemWriter}. */ public void setItemTransformer(ItemTransformer itemTransformer) { this.itemTransformer = itemTransformer; diff --git a/infrastructure/src/test/java/org/springframework/batch/io/file/support/FlatFileOutputSourceTests.java b/infrastructure/src/test/java/org/springframework/batch/io/file/support/FlatFileItemWriterTests.java similarity index 97% rename from infrastructure/src/test/java/org/springframework/batch/io/file/support/FlatFileOutputSourceTests.java rename to infrastructure/src/test/java/org/springframework/batch/io/file/support/FlatFileItemWriterTests.java index 41f85d0f1..e0a2cdeb8 100644 --- a/infrastructure/src/test/java/org/springframework/batch/io/file/support/FlatFileOutputSourceTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/io/file/support/FlatFileItemWriterTests.java @@ -32,7 +32,7 @@ import org.springframework.transaction.support.TransactionSynchronizationManager import org.springframework.transaction.support.TransactionSynchronizationUtils; /** - * Tests of regular usage for {@link FlatFileOutputSource} Exception cases will + * Tests of regular usage for {@link FlatFileItemWriter} Exception cases will * be in separate TestCase classes with different setUp and * tearDown methods * @@ -40,10 +40,10 @@ import org.springframework.transaction.support.TransactionSynchronizationUtils; * @author Dave Syer * */ -public class FlatFileOutputSourceTests extends TestCase { +public class FlatFileItemWriterTests extends TestCase { // object under test - private FlatFileOutputSource inputSource = new FlatFileOutputSource(); + private FlatFileItemWriter inputSource = new FlatFileItemWriter(); // String to be written into file by the FlatFileInputTemplate private static final String TEST_STRING = "FlatFileOutputTemplateTest-OutputData"; @@ -351,7 +351,7 @@ public class FlatFileOutputSourceTests extends TestCase { } public void testAfterPropertiesSetChecksMandatory() throws Exception { - inputSource = new FlatFileOutputSource(); + inputSource = new FlatFileItemWriter(); try { inputSource.afterPropertiesSet(); fail("Expected IllegalArgumentException"); @@ -362,7 +362,7 @@ public class FlatFileOutputSourceTests extends TestCase { } public void testDefaultRestartData() throws Exception { - inputSource = new FlatFileOutputSource(); + inputSource = new FlatFileItemWriter(); RestartData restartData = inputSource.getRestartData(); assertNotNull(restartData); // TODO: assert the properties of the default restart data diff --git a/infrastructure/src/test/java/org/springframework/batch/io/file/support/StaxEventWriterOutputSourceTests.java b/infrastructure/src/test/java/org/springframework/batch/io/file/support/StaxEventWriterItemWriterTests.java similarity index 91% rename from infrastructure/src/test/java/org/springframework/batch/io/file/support/StaxEventWriterOutputSourceTests.java rename to infrastructure/src/test/java/org/springframework/batch/io/file/support/StaxEventWriterItemWriterTests.java index cbb6fd0ab..686cdc2db 100644 --- a/infrastructure/src/test/java/org/springframework/batch/io/file/support/StaxEventWriterOutputSourceTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/io/file/support/StaxEventWriterItemWriterTests.java @@ -11,7 +11,7 @@ import javax.xml.transform.Result; import junit.framework.TestCase; import org.apache.commons.io.FileUtils; -import org.springframework.batch.io.file.support.StaxEventWriterOutputSource; +import org.springframework.batch.io.file.support.StaxEventWriterItemWriter; import org.springframework.batch.io.file.support.oxm.MarshallingObjectToXmlSerializer; import org.springframework.batch.restart.RestartData; import org.springframework.core.io.FileSystemResource; @@ -25,10 +25,10 @@ import org.springframework.xml.transform.StaxResult; /** * Tests for {@link StaxStreamWriterOutputSource}. */ -public class StaxEventWriterOutputSourceTests extends TestCase { +public class StaxEventWriterItemWriterTests extends TestCase { // object under test - private StaxEventWriterOutputSource source; + private StaxEventWriterItemWriter source; // output file private Resource resource; @@ -119,7 +119,7 @@ public class StaxEventWriterOutputSourceTests extends TestCase { final int NUMBER_OF_RECORDS = 10; for (int i = 0; i < NUMBER_OF_RECORDS; i++) { String writeStatistics = - source.getStatistics().getProperty(StaxEventWriterOutputSource.WRITE_STATISTICS_NAME); + source.getStatistics().getProperty(StaxEventWriterItemWriter.WRITE_STATISTICS_NAME); assertEquals(String.valueOf(i), writeStatistics); source.write(record); @@ -188,8 +188,8 @@ public class StaxEventWriterOutputSourceTests extends TestCase { /** * @return new instance of fully configured output source */ - private StaxEventWriterOutputSource newOutputSource() throws Exception { - StaxEventWriterOutputSource source = new StaxEventWriterOutputSource(); + private StaxEventWriterItemWriter newOutputSource() throws Exception { + StaxEventWriterItemWriter source = new StaxEventWriterItemWriter(); source.setResource(resource); Marshaller marshaller = new SimpleMarshaller(); diff --git a/infrastructure/src/test/java/org/springframework/batch/item/processor/OutputSourceItemProcessorTests.java b/infrastructure/src/test/java/org/springframework/batch/item/processor/ItemWriterItemProcessorTests.java similarity index 88% rename from infrastructure/src/test/java/org/springframework/batch/item/processor/OutputSourceItemProcessorTests.java rename to infrastructure/src/test/java/org/springframework/batch/item/processor/ItemWriterItemProcessorTests.java index 295c2137d..55b781aa2 100644 --- a/infrastructure/src/test/java/org/springframework/batch/item/processor/OutputSourceItemProcessorTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/item/processor/ItemWriterItemProcessorTests.java @@ -21,9 +21,9 @@ import java.util.Properties; import junit.framework.TestCase; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.io.Skippable; -import org.springframework.batch.item.processor.OutputSourceItemProcessor; +import org.springframework.batch.item.processor.ItemWriterItemProcessor; import org.springframework.batch.restart.GenericRestartData; import org.springframework.batch.restart.RestartData; import org.springframework.batch.restart.Restartable; @@ -34,11 +34,11 @@ import org.springframework.batch.support.PropertiesConverter; * @author Dave Syer * */ -public class OutputSourceItemProcessorTests extends TestCase { +public class ItemWriterItemProcessorTests extends TestCase { - private OutputSourceItemProcessor processor = new OutputSourceItemProcessor(); + private ItemWriterItemProcessor processor = new ItemWriterItemProcessor(); - private OutputSource source; + private ItemWriter source; /* * (non-Javadoc) @@ -147,7 +147,7 @@ public class OutputSourceItemProcessorTests extends TestCase { * @author Dave Syer * */ - public class MockOutputSource implements OutputSource, StatisticsProvider, Restartable, Skippable { + public class MockOutputSource implements ItemWriter, StatisticsProvider, Restartable, Skippable { private String value; diff --git a/infrastructure/src/test/java/org/springframework/batch/item/processor/TransformerOutputSourceItemProcessorTests.java b/infrastructure/src/test/java/org/springframework/batch/item/processor/TransformerWriterItemProcessorTests.java similarity index 71% rename from infrastructure/src/test/java/org/springframework/batch/item/processor/TransformerOutputSourceItemProcessorTests.java rename to infrastructure/src/test/java/org/springframework/batch/item/processor/TransformerWriterItemProcessorTests.java index c727a90c9..1cdfe015f 100644 --- a/infrastructure/src/test/java/org/springframework/batch/item/processor/TransformerOutputSourceItemProcessorTests.java +++ b/infrastructure/src/test/java/org/springframework/batch/item/processor/TransformerWriterItemProcessorTests.java @@ -3,26 +3,26 @@ package org.springframework.batch.item.processor; import junit.framework.TestCase; import org.easymock.MockControl; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; /** - * Tests for {@link TransformerOutputSourceItemProcessor}. + * Tests for {@link TransformerWriterItemProcessor}. * * @author Robert Kasanicky */ -public class TransformerOutputSourceItemProcessorTests extends TestCase { +public class TransformerWriterItemProcessorTests extends TestCase { - private TransformerOutputSourceItemProcessor processor = new TransformerOutputSourceItemProcessor(); + private TransformerWriterItemProcessor processor = new TransformerWriterItemProcessor(); private ItemTransformer transformer; - private OutputSource outputSource; + private ItemWriter outputSource; private MockControl tControl = MockControl.createControl(ItemTransformer.class); - private MockControl outControl = MockControl.createControl(OutputSource.class); + private MockControl outControl = MockControl.createControl(ItemWriter.class); protected void setUp() throws Exception { transformer = (ItemTransformer) tControl.getMock(); - outputSource = (OutputSource) outControl.getMock(); + outputSource = (ItemWriter) outControl.getMock(); processor.setItemTransformer(transformer); processor.setOutputSource(outputSource); diff --git a/integration/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterOutputSourceTests.java b/integration/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterItemWriterTests.java similarity index 89% rename from integration/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterOutputSourceTests.java rename to integration/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterItemWriterTests.java index f88945318..355f23003 100644 --- a/integration/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterOutputSourceTests.java +++ b/integration/src/test/java/org/springframework/batch/io/oxm/AbstractStaxEventWriterItemWriterTests.java @@ -11,7 +11,7 @@ import junit.framework.TestCase; import org.custommonkey.xmlunit.XMLAssert; import org.custommonkey.xmlunit.XMLUnit; -import org.springframework.batch.io.file.support.StaxEventWriterOutputSource; +import org.springframework.batch.io.file.support.StaxEventWriterItemWriter; import org.springframework.batch.io.file.support.oxm.MarshallingObjectToXmlSerializer; import org.springframework.batch.io.oxm.domain.Trade; import org.springframework.core.io.ClassPathResource; @@ -19,9 +19,9 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; import org.springframework.oxm.Marshaller; -public abstract class AbstractStaxEventWriterOutputSourceTests extends TestCase { +public abstract class AbstractStaxEventWriterItemWriterTests extends TestCase { - private StaxEventWriterOutputSource source = new StaxEventWriterOutputSource(); + private StaxEventWriterItemWriter source = new StaxEventWriterItemWriter(); private Resource resource; diff --git a/integration/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java b/integration/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java index 3877246b3..f721458f4 100644 --- a/integration/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java +++ b/integration/src/test/java/org/springframework/batch/io/oxm/CastorMarshallingTests.java @@ -4,7 +4,7 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.oxm.Marshaller; import org.springframework.oxm.castor.CastorMarshaller; -public class CastorMarshallingTests extends AbstractStaxEventWriterOutputSourceTests { +public class CastorMarshallingTests extends AbstractStaxEventWriterItemWriterTests { protected Marshaller getMarshaller() throws Exception { diff --git a/integration/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java b/integration/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java index 6e8827b4a..fc649cea7 100644 --- a/integration/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java +++ b/integration/src/test/java/org/springframework/batch/io/oxm/XStreamMarshallingTests.java @@ -5,7 +5,7 @@ import org.springframework.oxm.Marshaller; import org.springframework.oxm.xstream.XStreamMarshaller; public class XStreamMarshallingTests extends - AbstractStaxEventWriterOutputSourceTests { + AbstractStaxEventWriterItemWriterTests { protected Marshaller getMarshaller() throws Exception { XStreamMarshaller marshaller = new XStreamMarshaller(); diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/CustomerCreditWriter.java b/samples/src/main/java/org/springframework/batch/sample/dao/CustomerCreditWriter.java index 4b17bfd7b..22a6fe2ce 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/CustomerCreditWriter.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/CustomerCreditWriter.java @@ -16,7 +16,7 @@ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.sample.domain.CustomerCredit; /** @@ -24,7 +24,7 @@ import org.springframework.batch.sample.domain.CustomerCredit; * * @author Robert Kasanicky */ -public interface CustomerCreditWriter extends OutputSource { +public interface CustomerCreditWriter extends ItemWriter { void write(CustomerCredit customerCredit); diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriter.java b/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriter.java index 1884e8c4d..7083023ad 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriter.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriter.java @@ -16,7 +16,7 @@ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.item.ResourceLifecycle; import org.springframework.batch.sample.domain.CustomerCredit; import org.springframework.beans.factory.DisposableBean; @@ -30,7 +30,7 @@ import org.springframework.beans.factory.DisposableBean; public class FlatFileCustomerCreditWriter implements CustomerCreditWriter, DisposableBean { - private OutputSource outputSource; + private ItemWriter outputSource; private String separator = "\t"; @@ -52,7 +52,7 @@ public class FlatFileCustomerCreditWriter implements CustomerCreditWriter, this.separator = separator; } - public void setOutputSource(OutputSource outputSource) { + public void setOutputSource(ItemWriter outputSource) { this.outputSource = outputSource; } diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileOrderWriter.java b/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileOrderWriter.java index abd7f4def..2bd141759 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileOrderWriter.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/FlatFileOrderWriter.java @@ -16,7 +16,7 @@ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.io.file.support.transform.Converter; import org.springframework.batch.sample.domain.Order; @@ -32,7 +32,7 @@ public class FlatFileOrderWriter implements OrderWriter { /** * Takes care of writing to a file */ - private OutputSource outputSource; + private ItemWriter outputSource; /** * Converter for order @@ -55,7 +55,7 @@ public class FlatFileOrderWriter implements OrderWriter { outputSource.write(converter.convert(data)); } - public void setOutputSource(OutputSource outputSource) { + public void setOutputSource(ItemWriter outputSource) { this.outputSource = outputSource; } diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/IbatisCustomerCreditWriter.java b/samples/src/main/java/org/springframework/batch/sample/dao/IbatisCustomerCreditWriter.java index b44c13a8d..6a5f4d862 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/IbatisCustomerCreditWriter.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/IbatisCustomerCreditWriter.java @@ -15,7 +15,7 @@ */ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.sample.domain.CustomerCredit; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; @@ -24,7 +24,7 @@ import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; * */ public class IbatisCustomerCreditWriter extends SqlMapClientDaoSupport - implements CustomerCreditWriter, OutputSource { + implements CustomerCreditWriter, ItemWriter { String statementId; diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflGameDao.java b/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflGameDao.java index 83442a127..fd3f634ff 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflGameDao.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflGameDao.java @@ -1,11 +1,11 @@ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.sample.domain.NflGame; import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.util.Assert; -public class SqlNflGameDao extends JdbcDaoSupport implements OutputSource { +public class SqlNflGameDao extends JdbcDaoSupport implements ItemWriter { private static final String INSERT_GAME = "INSERT into GAMES(player_id,year,team,week,opponent," + "completes,attempts,passing_yards,passing_td,interceptions,rushes,rush_yards," diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflPlayerSummaryDao.java b/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflPlayerSummaryDao.java index e16f51943..188d9c06f 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflPlayerSummaryDao.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/SqlNflPlayerSummaryDao.java @@ -1,11 +1,11 @@ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.sample.domain.NflPlayerSummary; import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.util.Assert; -public class SqlNflPlayerSummaryDao extends JdbcDaoSupport implements OutputSource { +public class SqlNflPlayerSummaryDao extends JdbcDaoSupport implements ItemWriter { private static final String INSERT_SUMMARY = "INSERT into PLAYER_SUMMARY(ID,YEAR,COMPLETES,ATTEMPTS," + "PASSING_YARDS,PASSING_TD,INTERCEPTIONS,RUSHES,RUSH_YARDS,RECEPTIONS,RECEPTIONS_YARDS," + diff --git a/samples/src/main/java/org/springframework/batch/sample/dao/TradeWriter.java b/samples/src/main/java/org/springframework/batch/sample/dao/TradeWriter.java index f57213b15..cfd7888d4 100644 --- a/samples/src/main/java/org/springframework/batch/sample/dao/TradeWriter.java +++ b/samples/src/main/java/org/springframework/batch/sample/dao/TradeWriter.java @@ -16,7 +16,7 @@ package org.springframework.batch.sample.dao; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.sample.domain.Trade; @@ -26,7 +26,7 @@ import org.springframework.batch.sample.domain.Trade; * * @author Robert Kasanicky */ -public interface TradeWriter extends OutputSource{ +public interface TradeWriter extends ItemWriter{ /** * Write a trade object to some kind of output, * different implementations can write to file, database etc. diff --git a/samples/src/main/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessor.java b/samples/src/main/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessor.java index ca1ebba06..a01b8e6b9 100644 --- a/samples/src/main/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessor.java +++ b/samples/src/main/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessor.java @@ -2,7 +2,7 @@ package org.springframework.batch.sample.item.processor; import java.math.BigDecimal; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.sample.domain.CustomerCredit; @@ -15,7 +15,7 @@ public class CustomerCreditIncreaseProcessor implements ItemProcessor{ public static final BigDecimal FIXED_AMOUNT = new BigDecimal(1000); - private OutputSource outputSource; + private ItemWriter outputSource; public void process(Object data) throws Exception { CustomerCredit customerCredit = (CustomerCredit) data; @@ -23,7 +23,7 @@ public class CustomerCreditIncreaseProcessor implements ItemProcessor{ outputSource.write(customerCredit); } - public void setOutputSource(OutputSource outputSource) { + public void setOutputSource(ItemWriter outputSource) { this.outputSource = outputSource; } diff --git a/samples/src/main/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessor.java b/samples/src/main/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessor.java index 36de65256..175febf15 100644 --- a/samples/src/main/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessor.java +++ b/samples/src/main/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessor.java @@ -1,18 +1,18 @@ package org.springframework.batch.sample.item.processor; -import org.springframework.batch.io.file.support.FlatFileOutputSource; +import org.springframework.batch.io.file.support.FlatFileItemWriter; import org.springframework.batch.item.ItemProcessor; public class DefaultFlatFileProcessor implements ItemProcessor{ - private FlatFileOutputSource flatFileOutputSource; + private FlatFileItemWriter flatFileItemWriter; public void process(Object data) throws Exception { - flatFileOutputSource.write(""+data); + flatFileItemWriter.write(""+data); } - public void setFlatFileOutputSource(FlatFileOutputSource flatFileOutputSource) { - this.flatFileOutputSource = flatFileOutputSource; + public void setFlatFileOutputSource(FlatFileItemWriter flatFileItemWriter) { + this.flatFileItemWriter = flatFileItemWriter; } } diff --git a/samples/src/main/resources/jobs/compositeProcessorSampleJob.xml b/samples/src/main/resources/jobs/compositeProcessorSampleJob.xml index e9c896e92..e5e3a2a75 100644 --- a/samples/src/main/resources/jobs/compositeProcessorSampleJob.xml +++ b/samples/src/main/resources/jobs/compositeProcessorSampleJob.xml @@ -31,7 +31,7 @@ - + @@ -83,7 +83,7 @@ - + diff --git a/samples/src/main/resources/jobs/multilineJob.xml b/samples/src/main/resources/jobs/multilineJob.xml index 4fe4e689a..115234332 100644 --- a/samples/src/main/resources/jobs/multilineJob.xml +++ b/samples/src/main/resources/jobs/multilineJob.xml @@ -28,7 +28,7 @@ class="org.springframework.batch.sample.item.processor.DefaultFlatFileProcessor"> - diff --git a/samples/src/main/resources/jobs/nflJob.xml b/samples/src/main/resources/jobs/nflJob.xml index f6384ba51..a1ad02cc3 100644 --- a/samples/src/main/resources/jobs/nflJob.xml +++ b/samples/src/main/resources/jobs/nflJob.xml @@ -66,7 +66,7 @@ + class="org.springframework.batch.item.processor.ItemWriterItemProcessor"> @@ -96,7 +96,7 @@ + class="org.springframework.batch.item.processor.ItemWriterItemProcessor"> diff --git a/samples/src/main/resources/jobs/tradeJobIo.xml b/samples/src/main/resources/jobs/tradeJobIo.xml index d4c906669..df86ead6f 100644 --- a/samples/src/main/resources/jobs/tradeJobIo.xml +++ b/samples/src/main/resources/jobs/tradeJobIo.xml @@ -28,7 +28,7 @@ diff --git a/samples/src/main/resources/jobs/xmlStaxJob.xml b/samples/src/main/resources/jobs/xmlStaxJob.xml index cd88b3bed..cdace8ff7 100644 --- a/samples/src/main/resources/jobs/xmlStaxJob.xml +++ b/samples/src/main/resources/jobs/xmlStaxJob.xml @@ -40,7 +40,7 @@ - @@ -49,7 +49,7 @@ - + diff --git a/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriterTests.java b/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriterTests.java index 86016db24..97ff9b088 100644 --- a/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriterTests.java +++ b/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileCustomerCreditWriterTests.java @@ -2,7 +2,7 @@ package org.springframework.batch.sample.dao; import java.math.BigDecimal; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.item.ResourceLifecycle; import org.springframework.batch.sample.domain.CustomerCredit; @@ -12,15 +12,15 @@ import junit.framework.TestCase; public class FlatFileCustomerCreditWriterTests extends TestCase { private MockControl outputControl; - private ResourceLifecycleOutputSource output; + private ResourceLifecycleItemWriter output; private FlatFileCustomerCreditWriter writer; public void setUp() throws Exception { super.setUp(); //create mock for OutputSource - outputControl = MockControl.createControl(ResourceLifecycleOutputSource.class); - output = (ResourceLifecycleOutputSource)outputControl.getMock(); + outputControl = MockControl.createControl(ResourceLifecycleItemWriter.class); + output = (ResourceLifecycleItemWriter)outputControl.getMock(); //create new writer writer = new FlatFileCustomerCreditWriter(); @@ -75,7 +75,7 @@ public class FlatFileCustomerCreditWriterTests extends TestCase { outputControl.verify(); } - private interface ResourceLifecycleOutputSource extends OutputSource, ResourceLifecycle { + private interface ResourceLifecycleItemWriter extends ItemWriter, ResourceLifecycle { } } diff --git a/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileOrderWriterTests.java b/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileOrderWriterTests.java index bab3d855c..df63ef4b2 100644 --- a/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileOrderWriterTests.java +++ b/samples/src/test/java/org/springframework/batch/sample/dao/FlatFileOrderWriterTests.java @@ -9,7 +9,7 @@ import java.util.Map; import junit.framework.TestCase; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.io.file.support.transform.LineAggregator; import org.springframework.batch.sample.LineAggregatorStub; import org.springframework.batch.sample.domain.Address; @@ -22,7 +22,7 @@ public class FlatFileOrderWriterTests extends TestCase { List list = new ArrayList(); - private OutputSource output = new OutputSource() { + private ItemWriter output = new ItemWriter() { public void write(Object output) { list.add(output); diff --git a/samples/src/test/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessorTests.java b/samples/src/test/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessorTests.java index f84a3a209..a2f9d9039 100644 --- a/samples/src/test/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessorTests.java +++ b/samples/src/test/java/org/springframework/batch/sample/item/processor/CustomerCreditIncreaseProcessorTests.java @@ -5,7 +5,7 @@ import java.math.BigDecimal; import junit.framework.TestCase; import org.easymock.MockControl; -import org.springframework.batch.io.OutputSource; +import org.springframework.batch.io.ItemWriter; import org.springframework.batch.sample.domain.CustomerCredit; /** @@ -17,8 +17,8 @@ public class CustomerCreditIncreaseProcessorTests extends TestCase{ private CustomerCreditIncreaseProcessor processor = new CustomerCreditIncreaseProcessor(); - private OutputSource outputSource; - private MockControl outputSourceControl = MockControl.createStrictControl(OutputSource.class); + private ItemWriter outputSource; + private MockControl outputSourceControl = MockControl.createStrictControl(ItemWriter.class); private CustomerCredit customerCredit = new CustomerCredit(); @@ -27,7 +27,7 @@ public class CustomerCreditIncreaseProcessorTests extends TestCase{ customerCredit.setId(1); customerCredit.setName("testCustomer"); - outputSource = (OutputSource) outputSourceControl.getMock(); + outputSource = (ItemWriter) outputSourceControl.getMock(); processor.setOutputSource(outputSource); } diff --git a/samples/src/test/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessorTests.java b/samples/src/test/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessorTests.java index 08a9d0f9b..4e03cf794 100644 --- a/samples/src/test/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessorTests.java +++ b/samples/src/test/java/org/springframework/batch/sample/item/processor/DefaultFlatFileProcessorTests.java @@ -2,7 +2,7 @@ package org.springframework.batch.sample.item.processor; import junit.framework.TestCase; -import org.springframework.batch.io.file.support.FlatFileOutputSource; +import org.springframework.batch.io.file.support.FlatFileItemWriter; import org.springframework.batch.sample.item.processor.DefaultFlatFileProcessor; public class DefaultFlatFileProcessorTests extends TestCase { @@ -12,7 +12,7 @@ public class DefaultFlatFileProcessorTests extends TestCase { final Object testLine = new Object(); //create output source - FlatFileOutputSource output = new FlatFileOutputSource() { + FlatFileItemWriter output = new FlatFileItemWriter() { public void write(Object line) { assertEquals(""+testLine, line); }