RESOLVED - issue BATCH-371: FlatFileItemWriter no longer uses LineAggregator

http://jira.springframework.org/browse/BATCH-371
OPEN - issue BATCH-349: ItemStreamAdapter isn't an Adapter 
http://jira.springframework.org/browse/BATCH-349

Use *CReator instead of *Unmapper

Adapter -> Support
This commit is contained in:
dsyer
2008-02-25 17:08:31 +00:00
parent ad6511fb94
commit 59f884b832
18 changed files with 98 additions and 128 deletions

View File

@@ -29,7 +29,7 @@ import java.util.Properties;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.io.exception.BatchEnvironmentException;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetUnmapper;
import org.springframework.batch.io.file.mapping.FieldSetCreator;
import org.springframework.batch.io.file.transform.DelimitedLineAggregator;
import org.springframework.batch.io.file.transform.LineAggregator;
import org.springframework.batch.io.support.AbstractTransactionalIoSource;
@@ -84,7 +84,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
private LineAggregator lineAggregator = new DelimitedLineAggregator();
private FieldSetUnmapper fieldSetUnmapper;
private FieldSetCreator fieldSetCreator;
/**
* Assert that mandatory properties (resource) are set.
@@ -92,7 +92,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(resource, "The resource must be set");
Assert.notNull(fieldSetUnmapper, "A FieldSetUnmapper must be provided.");
Assert.notNull(fieldSetCreator, "A FieldSetUnmapper must be provided.");
File file = resource.getFile();
Assert.state(!file.exists() || file.canWrite(), "Resource is not writable: [" + resource + "]");
}
@@ -108,14 +108,14 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
}
/**
* Public setter for the {@link FieldSetUnmapper}. This will be used to
* Public setter for the {@link FieldSetCreator}. This will be used to
* transform the item into a {@link FieldSet} before it is aggregated by the
* {@link LineAggregator}.
*
* @param fieldSetUnmapper the {@link FieldSetUnmapper} to set
* @param fieldSetCreator the {@link FieldSetCreator} to set
*/
public void setFieldSetUnmapper(FieldSetUnmapper fieldSetUnmapper) {
this.fieldSetUnmapper = fieldSetUnmapper;
public void setFieldSetUnmapper(FieldSetCreator fieldSetCreator) {
this.fieldSetCreator = fieldSetCreator;
}
/**
@@ -141,7 +141,7 @@ public class FlatFileItemWriter extends AbstractTransactionalIoSource implements
* @throws Exception if the transformer or file output fail
*/
public void write(Object data) throws Exception {
FieldSet fieldSet = fieldSetUnmapper.unmapItem(data);
FieldSet fieldSet = fieldSetCreator.mapItem(data);
getOutputState().write(lineAggregator.aggregate(fieldSet) + LINE_SEPARATOR);
}

View File

@@ -15,17 +15,22 @@
*/
package org.springframework.batch.io.file.mapping;
import org.springframework.batch.io.file.transform.LineTokenizer;
/**
* Strategy interface for mapping between arbitrary objects and {@link FieldSet}.
* Similar to a {@link LineTokenizer}, but the input is generally a domain
* object, not a String.
*
* @author Dave Syer
*
*/
public interface FieldSetUnmapper {
public interface FieldSetCreator {
/**
* @param data an Object to convert.
* @return a {@link FieldSet} created from the input.
*/
FieldSet unmapItem(Object data);
FieldSet mapItem(Object data);
}

View File

@@ -23,7 +23,7 @@ package org.springframework.batch.io.file.mapping;
* @author Lucas Ward
*
*/
public class PassThroughFieldSetMapper implements FieldSetMapper, FieldSetUnmapper {
public class PassThroughFieldSetMapper implements FieldSetMapper, FieldSetCreator {
/*
* (non-Javadoc)
@@ -38,9 +38,9 @@ public class PassThroughFieldSetMapper implements FieldSetMapper, FieldSetUnmapp
* convert to a String with toString() and convert it to a single field
* {@link FieldSet}.
*
* @see org.springframework.batch.io.file.mapping.FieldSetUnmapper#unmapItem(java.lang.Object)
* @see org.springframework.batch.io.file.mapping.FieldSetCreator#mapItem(java.lang.Object)
*/
public FieldSet unmapItem(Object data) {
public FieldSet mapItem(Object data) {
if (data instanceof FieldSet) {
return (FieldSet) data;
}

View File

@@ -30,7 +30,7 @@ import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.MarkFailedException;
import org.springframework.batch.item.exception.ResetFailedException;
import org.springframework.batch.item.stream.ItemStreamAdapter;
import org.springframework.batch.item.stream.ItemStreamSupport;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
@@ -57,7 +57,7 @@ import org.springframework.util.Assert;
* @author Dave Syer
* @author Rob Harrop
*/
public class ResourceLineReader extends ItemStreamAdapter implements LineReader, ItemReader {
public class ResourceLineReader extends ItemStreamSupport implements LineReader, ItemReader {
private static final Collection DEFAULT_COMMENTS = Collections.singleton("#");

View File

@@ -1,49 +0,0 @@
/*
* 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.transform;
import org.springframework.batch.io.file.mapping.FieldSet;
import org.springframework.batch.io.file.mapping.FieldSetUnmapper;
import org.springframework.batch.item.writer.ItemTransformer;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
/**
* An {@link ItemTransformer} that delegates to a {@link FieldSetUnmapper}, so
* the result of the transformation is a {@link FieldSet}.
*
* @author Dave Syer
*
*/
public class FieldSetUnmapperItemTransformer implements ItemTransformer, InitializingBean {
private FieldSetUnmapper fieldSetUnmapper;
/**
* Assert that mandatory properties are set.
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
public void afterPropertiesSet() throws Exception {
Assert.notNull(fieldSetUnmapper, "A FieldSetUnmapper must be provided.");
}
/* (non-Javadoc)
* @see org.springframework.batch.item.writer.ItemTransformer#transform(java.lang.Object)
*/
public Object transform(Object item) throws Exception {
return fieldSetUnmapper.unmapItem(item);
}
}

View File

@@ -17,7 +17,7 @@ package org.springframework.batch.io.support;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.stream.ItemStreamAdapter;
import org.springframework.batch.item.stream.ItemStreamSupport;
/**
* <p>
@@ -31,7 +31,7 @@ import org.springframework.batch.item.stream.ItemStreamAdapter;
* @author Lucas Ward
* @since 1.0
*/
public abstract class AbstractTransactionalIoSource extends ItemStreamAdapter {
public abstract class AbstractTransactionalIoSource extends ItemStreamSupport {
/*
* Called when a transaction has been committed.

View File

@@ -17,13 +17,13 @@
package org.springframework.batch.item.reader;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.stream.ItemStreamAdapter;
import org.springframework.batch.item.stream.ItemStreamSupport;
/**
* Base class for {@link ItemReader} implementations.
* @author Dave Syer
*
*/
public abstract class AbstractItemStreamItemReader extends ItemStreamAdapter implements ItemReader {
public abstract class AbstractItemStreamItemReader extends ItemStreamSupport implements ItemReader {
}

View File

@@ -23,18 +23,19 @@ import org.springframework.batch.item.exception.StreamException;
import org.springframework.batch.support.AbstractMethodInvokingDelegator;
/**
* Invokes a custom method which provides an item.
* Invokes a custom method on a delegate plain old Java object which itself
* provides an item.
*
* @author Robert Kasanicky
*/
public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implements ItemReader {
/**
* @return return value of the target method.
*/
public Object read() throws Exception {
public Object read() throws Exception {
return invokeDelegateMethod();
}
}
/**
* Do nothing.
@@ -42,13 +43,12 @@ public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implement
* @see org.springframework.batch.item.ItemReader#close()
*/
public void close() throws StreamException {
}
public void mark() throws MarkFailedException {
}
public void reset() throws ResetFailedException {
}
}

View File

@@ -20,10 +20,12 @@ import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.exception.StreamException;
/**
* Empty method implementation of {@link ItemStream}.
*
* @author Dave Syer
*
*/
public class ItemStreamAdapter implements ItemStream {
public class ItemStreamSupport implements ItemStream {
/**
* No-op.

View File

@@ -20,7 +20,13 @@ import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatListener;
public class RepeatListenerAdapter implements RepeatListener {
/**
* Empty method implementation of {@link RepeatListener}.
*
* @author Dave Syer
*
*/
public class RepeatListenerSupport implements RepeatListener {
public void before(RepeatContext context) {
}

View File

@@ -20,7 +20,13 @@ import org.springframework.batch.retry.RetryCallback;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryListener;
public class RetryListenerAdapter implements RetryListener {
/**
* Empty method implementation of {@link RetryListener}.
*
* @author Dave Syer
*
*/
public class RetryListenerSupport implements RetryListener {
public void close(RetryContext context, RetryCallback callback, Throwable throwable) {
}