diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePerformanceTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePerformanceTests.java index e24b20453..2002eadbc 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePerformanceTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/scope/StepScopePerformanceTests.java @@ -37,10 +37,10 @@ public class StepScopePerformanceTests implements ApplicationContextAware { public void start() throws Exception { int count = doTest("vanilla", "warmup"); logger.info("Item count: "+count); + StepSynchronizationManager.close(); StepSynchronizationManager.register(new StepExecution("step", new JobExecution(0L),1L)); } - @Before @After public void cleanup() { StepSynchronizationManager.close(); diff --git a/spring-batch-samples/src/main/resources/jobs/compositeItemWriterSampleJob.xml b/spring-batch-samples/src/main/resources/jobs/compositeItemWriterSampleJob.xml index 75c2deba7..f2124d8fe 100644 --- a/spring-batch-samples/src/main/resources/jobs/compositeItemWriterSampleJob.xml +++ b/spring-batch-samples/src/main/resources/jobs/compositeItemWriterSampleJob.xml @@ -20,11 +20,6 @@ - - - - - @@ -106,4 +101,4 @@ - \ No newline at end of file + diff --git a/src/site/docbook/reference/readersAndWriters.xml b/src/site/docbook/reference/readersAndWriters.xml index a60683888..ddee910c3 100644 --- a/src/site/docbook/reference/readersAndWriters.xml +++ b/src/site/docbook/reference/readersAndWriters.xml @@ -194,7 +194,7 @@ public class BarWriter implements ItemWriter<Bar>{ <job id="ioSampleJob"> <step name="step1"> <tasklet> - <chunk reader="fooReader" processor="fooProcessor" writer="barWriter" + <chunk reader="fooReader" processor="fooProcessor" writer="barWriter" commit-interval="2"/> </tasklet> </step> @@ -244,7 +244,7 @@ public class FoobarWriter implements ItemWriter<FooBar>{ BarProcessor can be 'chained' together to give the resultant Foobar: - CompositeItemProcessor<Foo,Foobar> compositeProcessor = + CompositeItemProcessor<Foo,Foobar> compositeProcessor = new CompositeItemProcessor<Foo,Foobar>(); List itemProcessors = new ArrayList(); itemProcessors.add(new FooTransformer()); @@ -257,13 +257,13 @@ compositeProcessor.setDelegates(itemProcessors); <job id="ioSampleJob"> <step name="step1"> <tasklet> - <chunk reader="fooReader" processor="compositeProcessor" writer="foobarWriter" + <chunk reader="fooReader" processor="compositeProcessor" writer="foobarWriter" commit-interval="2"/> </tasklet> </step> </job> -<bean id="compositeItemProcessor" +<bean id="compositeItemProcessor" class="org.springframework.batch.item.support.CompositeItemProcessor"> <property name="delegates"> <list> @@ -316,7 +316,7 @@ compositeProcessor.setDelegates(itemProcessors); void open(ExecutionContext executionContext) throws ItemStreamException; void update(ExecutionContext executionContext) throws ItemStreamException; - + void close() throws ItemStreamException; } @@ -355,8 +355,7 @@ compositeProcessor.setDelegates(itemProcessors); Note that the CompositeItemWriter is an example of the delegation pattern, which is common in Spring Batch. The - delegates themselves might implement callback interfaces like - ItemStream or StepListener. + delegates themselves might implement callback interfaces StepListener. If they do, and they are being used in conjunction with Spring Batch Core as part of a Step in a Job, then they almost certainly need to be registered manually with the @@ -370,7 +369,7 @@ compositeProcessor.setDelegates(itemProcessors); <job id="ioSampleJob"> <step name="step1"> <tasklet> - <chunk reader="fooReader" processor="fooProcessor" writer="compositeItemWriter" + <chunk reader="fooReader" processor="fooProcessor" writer="compositeItemWriter" commit-interval="2"> <streams> <stream ref="barWriter" /> @@ -380,7 +379,7 @@ compositeProcessor.setDelegates(itemProcessors); </step> </job> -<bean id="compositeItemWriter" class="...CompositeItemWriter"> +<bean id="compositeItemWriter" class="...CustomCompositeItemWriter"> <property name="delegate" ref="barWriter" /> </bean> @@ -600,7 +599,7 @@ boolean booleanValue = fs.readBoolean(2); the LineTokenizer: public interface LineTokenizer { - + FieldSet tokenize(String line); } @@ -649,7 +648,7 @@ boolean booleanValue = fs.readBoolean(2); a resource into an object of the desired type: public interface FieldSetMapper<T> { - + T mapFieldSet(FieldSet fieldSet); } @@ -709,7 +708,7 @@ boolean booleanValue = fs.readBoolean(2); this.tokenizer = tokenizer; } - public void setFieldSetMapper(FieldSetMapper<T> fieldSetMapper) { + public void setFieldSetMapper(FieldSetMapper<T> fieldSetMapper) { this.fieldSetMapper = fieldSetMapper; } } @@ -736,21 +735,21 @@ boolean booleanValue = fs.readBoolean(2); The contents of this file will be mapped to the following Player domain object: public class Player implements Serializable { - - private String ID; - private String lastName; - private String firstName; - private String position; - private int birthYear; + + private String ID; + private String lastName; + private String firstName; + private String position; + private int birthYear; private int debutYear; - + public String toString() { - return "PLAYER:ID=" + ID + ",Last Name=" + lastName + - ",First Name=" + firstName + ",Position=" + position + - ",Birth Year=" + birthYear + ",DebutYear=" + + return "PLAYER:ID=" + ID + ",Last Name=" + lastName + + ",First Name=" + firstName + ",Position=" + position + + ",Birth Year=" + birthYear + ",DebutYear=" + debutYear; } - + // setters and getters... } @@ -766,7 +765,7 @@ boolean booleanValue = fs.readBoolean(2); player.setID(fieldSet.readString(0)); player.setLastName(fieldSet.readString(1)); - player.setFirstName(fieldSet.readString(2)); + player.setFirstName(fieldSet.readString(2)); player.setPosition(fieldSet.readString(3)); player.setBirthYear(fieldSet.readInt(4)); player.setDebutYear(fieldSet.readInt(5)); @@ -813,11 +812,11 @@ Player player = itemReader.read(); public class PlayerMapper implements FieldSetMapper<Player> { public Player mapFieldSet(FieldSet fs) { - + if(fs == null){ return null; } - + Player player = new Player(); player.setID(fs.readString("ID")); player.setLastName(fs.readString("lastName")); @@ -825,7 +824,7 @@ Player player = itemReader.read(); player.setPosition(fs.readString("position")); player.setDebutYear(fs.readInt("debutYear")); player.setBirthYear(fs.readInt("birthYear")); - + return player; } } @@ -1041,7 +1040,7 @@ LINEB;2134776319DEF422.99M005LI expected: tokenizer.setNames(new String[] {"A", "B", "C", "D"}); - + try{ tokenizer.tokenize("a,b,c"); } @@ -1065,8 +1064,8 @@ catch(IncorrectTokenCountException e){ line length doesn't add up to the widest value of this column, an exception is thrown: - tokenizer.setColumns(new Range[] { new Range(1, 5), - new Range(6, 10), + tokenizer.setColumns(new Range[] { new Range(1, 5), + new Range(6, 10), new Range(11, 15) }); try { tokenizer.tokenize("12345"); @@ -1545,7 +1544,7 @@ assertEquals(born, values[2]); the map. In the configuration file we can use a Spring configuration utility to describe the required alias as follows: - <bean id="tradeMarshaller" + <bean id="tradeMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> <property name="aliases"> <util:map id="aliases"> @@ -1570,7 +1569,7 @@ assertEquals(born, values[2]); configuration: StaxEventItemReader xmlStaxEventItemReader = new StaxEventItemReader() -Resource resource = new ByteArrayResource(xmlResource.getBytes()) +Resource resource = new ByteArrayResource(xmlResource.getBytes()) Map aliases = new HashMap(); aliases.put("trade","org.springframework.batch.sample.domain.Trade"); @@ -1626,7 +1625,7 @@ while (hasNext) { should be noted the marshaller used for the writer is the exact same as the one used in the reading example from earlier in the chapter: - <bean id="customerCreditMarshaller" + <bean id="customerCreditMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> <property name="aliases"> <util:map id="aliases"> @@ -1660,7 +1659,7 @@ staxItemWriter.setOverwriteOutput(true); ExecutionContext executionContext = new ExecutionContext(); staxItemWriter.open(executionContext); CustomerCredit Credit = new CustomerCredit(); -trade.setPrice(11.39); +trade.setPrice(11.39); credit.setName("Customer1"); staxItemWriter.write(trade); @@ -1766,7 +1765,7 @@ staxItemWriter.write(trade); be used as an example: CREATE TABLE CUSTOMER ( - ID BIGINT IDENTITY PRIMARY KEY, + ID BIGINT IDENTITY PRIMARY KEY, NAME VARCHAR(45), CREDIT FLOAT ); @@ -1804,7 +1803,7 @@ staxItemWriter.write(trade); //For simplicity sake, assume a dataSource has already been obtained JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); -List customerCredits = jdbcTemplate.query("SELECT ID, NAME, CREDIT from CUSTOMER", +List customerCredits = jdbcTemplate.query("SELECT ID, NAME, CREDIT from CUSTOMER", new CustomerCreditRowMapper()); After running this code snippet the customerCredits list will @@ -2440,7 +2439,7 @@ itemReader.close(executionContext); number of frameworks: public interface Validator { - + void validate(Object value) throws ValidationException; } @@ -2463,13 +2462,13 @@ itemReader.close(executionContext); <value> <![CDATA[ { orderId : ? > 0 AND ? <= 9999999999 : 'Incorrect order ID' : 'error.order.id' } - { totalLines : ? = size(lineItems) : 'Bad count of order lines' + { totalLines : ? = size(lineItems) : 'Bad count of order lines' : 'error.order.lines.badcount'} - { customer.registered : customer.businessCustomer = FALSE OR ? = TRUE - : 'Business customer must be registered' + { customer.registered : customer.businessCustomer = FALSE OR ? = TRUE + : 'Business customer must be registered' : 'error.customer.registration'} - { customer.companyName : customer.businessCustomer = FALSE OR ? HAS TEXT - : 'Company name for business customer is mandatory' + { customer.companyName : customer.businessCustomer = FALSE OR ? HAS TEXT + : 'Company name for business customer is mandatory' :'error.customer.companyname'} ]]> </value> @@ -2619,7 +2618,7 @@ assertNull(itemReader.read()); if (currentIndex < items.size()) { return items.get(currentIndex++); } - + return null; }