From ca91bbb375945a7e7ee612bf1425d237e956bb94 Mon Sep 17 00:00:00 2001 From: jpraet Date: Wed, 28 Aug 2013 17:49:43 +0200 Subject: [PATCH] BATCH-2086: default writer implementations need public setter for name --- .../batch/item/ItemStreamSupport.java | 11 +++++++++++ .../batch/item/file/FlatFileItemWriter.java | 11 ----------- .../AbstractItemCountingItemStreamItemReader.java | 10 ---------- .../batch/item/xml/StaxEventItemWriterTests.java | 13 +++++++++++++ 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamSupport.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamSupport.java index a52f9b336..5aae389d0 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamSupport.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamSupport.java @@ -51,6 +51,17 @@ public abstract class ItemStreamSupport implements ItemStream { @Override public void update(ExecutionContext executionContext) { } + + /** + * 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. + * + * @param name the name for the component + */ + public void setName(String name) { + this.setExecutionContextName(name); + } protected void setExecutionContextName(String name) { executionContextUserSupport.setName(name); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java index 2664c102c..1546fabbd 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/file/FlatFileItemWriter.java @@ -392,17 +392,6 @@ InitializingBean { 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. - * - * @param name the name for the component - */ - public void setName(String name) { - this.setExecutionContextName(name); - } - /** * Encapsulates the runtime state of the writer. All state changing * operations on the writer go through this class. diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java index 5c3e5c950..95233fedb 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/AbstractItemCountingItemStreamItemReader.java @@ -179,16 +179,6 @@ public abstract class AbstractItemCountingItemStreamItemReader extends Abstra } - /** - * 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. - * - * @param name the name for the component - */ - public void setName(String name) { - this.setExecutionContextName(name); - } /** * Set the flag that determines whether to save internal data for diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java index df60339e1..aa5a67c23 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java @@ -100,6 +100,19 @@ public class StaxEventItemWriterTests { jaxbMarshaller = new Jaxb2Marshaller(); jaxbMarshaller.setClassesToBeBound(JAXBItem.class); } + + /** + * Test setting writer name. + */ + @Test + public void testSetName() throws Exception { + writer.setName("test"); + writer.open(executionContext); + writer.write(items); + writer.update(executionContext); + writer.close(); + assertTrue("execution context keys should be prefixed with writer name", executionContext.containsKey("test.position")); + } /** * Item is written to the output file only after flush.