BATCH-325:Added close() to readers and writers.
This commit is contained in:
@@ -287,4 +287,8 @@ public class HibernateAwareItemWriter implements ItemWriter, RepeatInterceptor,
|
||||
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
delegate.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ package org.springframework.batch.item;
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Dave Syer
|
||||
* @author Lucas Ward
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface ItemReader {
|
||||
|
||||
@@ -56,4 +58,10 @@ public interface ItemReader {
|
||||
* @return a unique identifier.
|
||||
*/
|
||||
Object getKey(Object item);
|
||||
|
||||
/**
|
||||
* Close the reader, freeing any resources that may have been allocated
|
||||
* since the first call to read().
|
||||
*/
|
||||
void close() throws Exception;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ package org.springframework.batch.item;
|
||||
* technology to use for mapping and how it should be configured.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Lucas Ward
|
||||
*/
|
||||
public interface ItemWriter {
|
||||
|
||||
@@ -36,4 +37,11 @@ public interface ItemWriter {
|
||||
* rethrow it as appropriate.
|
||||
*/
|
||||
public void write(Object item) throws Exception;
|
||||
|
||||
/**
|
||||
* Close the writer, allowing all allocated resources to be cleaned up.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
void close() throws Exception;
|
||||
}
|
||||
|
||||
@@ -35,5 +35,8 @@ public abstract class AbstractItemReader implements ItemReader {
|
||||
public Object getKey(Object item) {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,5 +38,9 @@ public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implement
|
||||
return item;
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2006-2008 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.item.writer;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
* Abstract {@link ItemWriter} that allows for base classes to only
|
||||
* implement the close method if they need it.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractItemWriter implements ItemWriter{
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -125,5 +125,11 @@ public class CompositeItemWriter implements ItemWriter, Restartable {
|
||||
private interface PropertiesExtractor {
|
||||
Properties extractProperties(Object o);
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
for (Iterator iterator = delegates.listIterator(); iterator.hasNext();) {
|
||||
((ItemWriter) iterator.next()).close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,4 +87,8 @@ public class DelegatingItemWriter implements ItemWriter, Restartable, Skippable,
|
||||
Assert.notNull(writer);
|
||||
}
|
||||
|
||||
public void close() throws Exception {
|
||||
writer.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,16 @@ public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implement
|
||||
public void write(Object item) throws Exception {
|
||||
invokeDelegateMethodWithArgument(item);
|
||||
}
|
||||
|
||||
/*
|
||||
* No-op, can't call more than one method.
|
||||
*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.item.ItemWriter#close()
|
||||
*/
|
||||
public void close() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -65,4 +65,8 @@ public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvoki
|
||||
public void setFieldsUsedAsTargetMethodArguments(String[] fieldsUsedAsMethodArguments) {
|
||||
this.fieldsUsedAsTargetMethodArguments = fieldsUsedAsMethodArguments;
|
||||
}
|
||||
|
||||
|
||||
public void close() throws Exception {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user