BATCH-1966: Some minor cleanup

This commit is contained in:
Michael Minella
2013-03-04 14:08:19 -06:00
parent 958d7c89a5
commit aedf03fad0
7 changed files with 91 additions and 81 deletions

View File

@@ -26,13 +26,13 @@ import org.springframework.batch.item.util.ExecutionContextUserSupport;
*/
public abstract class ItemStreamSupport implements ItemStream {
private final ExecutionContextUserSupport executionContextUserSupport = new ExecutionContextUserSupport();
private final ExecutionContextUserSupport executionContextUserSupport = new ExecutionContextUserSupport();
/**
* No-op.
* @see org.springframework.batch.item.ItemStream#close()
*/
@Override
@Override
public void close() {
}
@@ -40,7 +40,7 @@ public abstract class ItemStreamSupport implements ItemStream {
* No-op.
* @see org.springframework.batch.item.ItemStream#open(ExecutionContext)
*/
@Override
@Override
public void open(ExecutionContext executionContext) {
}
@@ -48,20 +48,16 @@ public abstract class ItemStreamSupport implements ItemStream {
* Return empty {@link ExecutionContext}.
* @see org.springframework.batch.item.ItemStream#update(ExecutionContext)
*/
@Override
@Override
public void update(ExecutionContext executionContext) {
}
private ExecutionContextUserSupport getExecutionContextUserSupport() {
return executionContextUserSupport;
}
protected void setExecutionContextName(String name) {
this.getExecutionContextUserSupport().setName(name);
}
protected void setExecutionContextName(String name) {
executionContextUserSupport.setName(name);
}
public String getExecutionContextKey(String key) {
return this.getExecutionContextUserSupport().getKey(key);
}
public String getExecutionContextKey(String key) {
return executionContextUserSupport.getKey(key);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2012 the original author or authors.
* Copyright 2006-2013 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.
@@ -222,7 +222,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
getParameterList(parameterValues, startAfterValues).toArray(), rowCallback);
}
}
Collection<T> result = (Collection<T>) query;
results.addAll(result);
}
@@ -240,12 +240,12 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
public void open(ExecutionContext executionContext) {
if (isSaveState()) {
startAfterValues = (Map<String, Object>) executionContext.get(getExecutionContextKey(START_AFTER_VALUE));
if(startAfterValues == null) {
startAfterValues = new LinkedHashMap<String, Object>();
}
}
super.open(executionContext);
}
@@ -266,7 +266,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
}
RowMapper startMapper = new RowMapper() {
@Override
@Override
public Object mapRow(ResultSet rs, int i) throws SQLException {
return rs.getObject(1);
}
@@ -316,7 +316,7 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
parameterList.add(keys.get(i).getValue());
}
}
if (logger.isDebugEnabled()) {
logger.debug("Using parameterList:" + parameterList);
}
@@ -325,13 +325,13 @@ public class JdbcPagingItemReader<T> extends AbstractPagingItemReader<T> impleme
@SuppressWarnings("rawtypes")
private class PagingRowMapper implements RowMapper {
@Override
@Override
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
startAfterValues = new LinkedHashMap<String, Object>();
for (Map.Entry<String, Order> sortKey : queryProvider.getSortKeys().entrySet()) {
startAfterValues.put(sortKey.getKey(), rs.getObject(sortKey.getKey()));
}
return rowMapper.mapRow(rs, rowNum);
}
}

View File

@@ -58,7 +58,7 @@ import org.springframework.util.ClassUtils;
* @author Michael Minella
*/
public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> implements ResourceAwareItemWriterItemStream<T>,
InitializingBean {
InitializingBean {
private static final boolean DEFAULT_TRANSACTIONAL = true;
@@ -97,7 +97,7 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
private boolean append = false;
public FlatFileItemWriter() {
this.setExecutionContextName(ClassUtils.getShortName(FlatFileItemWriter.class));
this.setExecutionContextName(ClassUtils.getShortName(FlatFileItemWriter.class));
}
/**
@@ -105,7 +105,7 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
*
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@Override
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(lineAggregator, "A LineAggregator must be provided.");
if (append) {
@@ -150,7 +150,7 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
*
* @param resource
*/
@Override
@Override
public void setResource(Resource resource) {
this.resource = resource;
}
@@ -248,7 +248,7 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
* @throws Exception if the transformer or file output fail,
* WriterNotOpenException if the writer has not been initialized.
*/
@Override
@Override
public void write(List<? extends T> items) throws Exception {
if (!getOutputState().isInitialized()) {
@@ -279,9 +279,9 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
/**
* @see ItemStream#close()
*/
@Override
@Override
public void close() {
super.close();
super.close();
if (state != null) {
try {
if (footerCallback != null && state.outputBufferedWriter != null) {
@@ -313,10 +313,10 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
*
* @see ItemStream#open(ExecutionContext)
*/
@Override
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
super.open(executionContext);
Assert.notNull(resource, "The resource must be set");
if (!getOutputState().isInitialized()) {
@@ -351,9 +351,9 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
/**
* @see ItemStream#update(ExecutionContext)
*/
@Override
@Override
public void update(ExecutionContext executionContext) {
super.update(executionContext);
super.update(executionContext);
if (state == null) {
throw new ItemStreamException("ItemStream not open or already closed.");
}
@@ -389,10 +389,10 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
state.setAppendAllowed(append);
state.setEncoding(encoding);
}
return (OutputState) state;
return state;
}
/**
/**
* The name of the component which will be used as a stem for keys in the
* {@link ExecutionContext}. Subclasses should provide a default value, e.g.
* the short form of the class name.
@@ -400,7 +400,7 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
* @param name the name for the component
*/
public void setName(String name) {
this.setExecutionContextName(name);
this.setExecutionContextName(name);
}
/**
@@ -601,12 +601,12 @@ public class FlatFileItemWriter<T> extends AbstractItemStreamItemWriter<T> imple
final FileChannel channel = fileChannel;
if (transactional) {
TransactionAwareBufferedWriter writer = new TransactionAwareBufferedWriter(channel, new Runnable() {
@Override
@Override
public void run() {
closeStream();
}
});
writer.setEncoding(encoding);
return writer;
}

View File

@@ -22,6 +22,7 @@ import java.util.Comparator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemStreamException;
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.ResourceAware;
@@ -75,7 +76,7 @@ public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
/**
* Compares resource filenames.
*/
@Override
@Override
public int compare(Resource r1, Resource r2) {
return r1.getFilename().compareTo(r2.getFilename());
}
@@ -83,13 +84,13 @@ public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
};
public MultiResourceItemReader() {
this.setExecutionContextName(ClassUtils.getShortName(MultiResourceItemReader.class));
this.setExecutionContextName(ClassUtils.getShortName(MultiResourceItemReader.class));
}
/**
* Reads the next item, jumping to next resource if necessary.
*/
@Override
@Override
public T read() throws Exception, UnexpectedInputException, ParseException {
if (noInput) {
@@ -129,26 +130,26 @@ public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
delegate.setResource(resources[currentResource]);
delegate.open(new ExecutionContext());
item = readFromDelegate();
}
item = readFromDelegate();
}
return item;
}
private T readFromDelegate() throws Exception {
T item = delegate.read();
if(item instanceof ResourceAware){
((ResourceAware) item).setResource(getCurrentResource());
}
return item;
}
private T readFromDelegate() throws Exception {
T item = delegate.read();
if(item instanceof ResourceAware){
((ResourceAware) item).setResource(getCurrentResource());
}
return item;
}
/**
/**
* Close the {@link #setDelegate(ResourceAwareItemReaderItemStream)} reader and reset instance variable values.
*/
@Override
@Override
public void close() throws ItemStreamException {
super.close();
super.close();
delegate.close();
noInput = false;
}
@@ -157,9 +158,9 @@ public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
* Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in
* the resource.
*/
@Override
@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
super.open(executionContext);
super.open(executionContext);
Assert.notNull(resources, "Resources must be set");
noInput = false;
@@ -196,9 +197,9 @@ public class MultiResourceItemReader<T> extends AbstractItemStreamItemReader<T>
/**
* Store the current resource index and position in the resource.
*/
@Override
@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
super.update(executionContext);
super.update(executionContext);
if (saveState) {
executionContext.putInt(getExecutionContextKey(RESOURCE_KEY), currentResource);
delegate.update(executionContext);

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.item.support;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.batch.item.ItemStreamSupport;
@@ -26,6 +25,6 @@ import org.springframework.batch.item.ItemStreamSupport;
* @author Dave Syer
*
*/
public abstract class AbstractItemStreamItemReader<T> extends ItemStreamSupport implements ItemStreamReader<T> {
public abstract class AbstractItemStreamItemReader<T> extends ItemStreamSupport implements ItemReader<T> {
}

View File

@@ -17,7 +17,6 @@
package org.springframework.batch.item.support;
import org.springframework.batch.item.ItemStreamSupport;
import org.springframework.batch.item.ItemStreamWriter;
import org.springframework.batch.item.ItemWriter;
@@ -26,6 +25,6 @@ import org.springframework.batch.item.ItemWriter;
* @author Dave Syer
*
*/
public abstract class AbstractItemStreamItemWriter<T> extends ItemStreamSupport implements ItemStreamWriter<T> {
public abstract class AbstractItemStreamItemWriter<T> extends ItemStreamSupport implements ItemWriter<T> {
}