From f8a62d673ea4258affbaf232a7c633460a27cf87 Mon Sep 17 00:00:00 2001 From: trisberg Date: Sat, 8 Nov 2008 23:39:39 +0000 Subject: [PATCH] BATCH-63:added commit-interval and fault tolerant attributes to; added restartable to job --- .../core/configuration/xml/JobParser.java | 5 +++ .../core/configuration/xml/StepParser.java | 35 +++++++++++++++++- .../configuration/xml/spring-batch-2.0.xsd | 37 ++++++++++++++++++- .../StepWithChunkOrientedJobParserTests.java | 2 +- ...ithChunkOrientedJobParserTests-context.xml | 3 +- 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java index 0c5e75581..a475ae384 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java @@ -55,6 +55,11 @@ public class JobParser extends AbstractBeanDefinitionParser { } builder.addPropertyReference("jobRepository", repositoryAttribute); + String restartableAttribute = element.getAttribute("restartable"); + if (StringUtils.hasText(restartableAttribute)) { + builder.addPropertyValue("restartable", restartableAttribute); + } + FlowParser flowParser = new FlowParser(); AbstractBeanDefinition flowDef = flowParser.parse(element, parserContext, jobName); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java index 8722e68da..f4b445796 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java @@ -37,6 +37,8 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; /** * Internal parser for the <step/> elements inside a job. A step element @@ -198,10 +200,13 @@ public class StepParser { protected RootBeanDefinition parseChunkOriented(Element element, ParserContext parserContext) { RootBeanDefinition bd; + + boolean isFaultTolerant = false; String faultTolerant = element.getAttribute("fault-tolerant"); if ("true".equals(faultTolerant)) { bd = new RootBeanDefinition("org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean", null, null); + isFaultTolerant = true; } else { bd = new RootBeanDefinition("org.springframework.batch.core.step.item.SimpleStepFactoryBean", null, null); @@ -233,6 +238,25 @@ public class StepParser { RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager); bd.getPropertyValues().addPropertyValue("transactionManager", tx); + String commitInterval = element.getAttribute("commit-interval"); + if (StringUtils.hasText(commitInterval)) { + bd.getPropertyValues().addPropertyValue("commitInterval", commitInterval); + } + + if (isFaultTolerant) { + String skipLimit = element.getAttribute("skip-limit"); + if (StringUtils.hasText(skipLimit)) { + bd.getPropertyValues().addPropertyValue("skipLimit", skipLimit); + } + } + + if (isFaultTolerant) { + String retryLimit = element.getAttribute("retry-limit"); + if (StringUtils.hasText(retryLimit)) { + bd.getPropertyValues().addPropertyValue("retryLimit", retryLimit); + } + } + handleExceptionElement(element, bd, "skippable-exception-classes", "skippableExceptionClasses"); handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses"); @@ -276,7 +300,16 @@ public class StepParser { String className = listenerElement.getAttribute("class"); if ((StringUtils.hasText(id) || StringUtils.hasText(className)) && StringUtils.hasText(listenerRef)) { - throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" + listenerElement.getTagName() + "> element with" + (StringUtils.hasText(id) ? " id=\"" + id + "\"" : "" ) + (StringUtils.hasText(className) ? " class=\"" + className + "\"" : "") + (StringUtils.hasText(listenerRef) ? " ref=\"" + listenerRef + "\"" : "")); + NamedNodeMap attributeNodes = listenerElement.getAttributes(); + StringBuilder attributes = new StringBuilder(); + for (int i = 0; i < attributeNodes.getLength(); i++) { + if (i > 0) { + attributes.append(" "); + } + attributes.append(attributeNodes.item(i)); + } + throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" + + listenerElement.getTagName() + "> element with attributes: " + attributes); } if (StringUtils.hasText(listenerRef)) { listenerRefs.add(listenerRef); diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd index a1dd9da03..1b86334a0 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd @@ -37,6 +37,13 @@ + + + + + @@ -194,6 +201,13 @@ + + + + + @@ -269,7 +283,14 @@ - + + + + + + + + + + + + + + + diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests.java index 6dcc71787..004d96911 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests.java @@ -47,7 +47,7 @@ public class StepWithChunkOrientedJobParserTests { @Autowired private JobRepository jobRepository; - + @Autowired private TestReader reader; diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests-context.xml index 662599af5..196fe08cf 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests-context.xml @@ -8,7 +8,8 @@ - +