Skip to content

Commit f8a62d6

Browse files
author
trisberg
committed
BATCH-63:added commit-interval and fault tolerant attributes to; added restartable to job
1 parent 6c70842 commit f8a62d6

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/JobParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ protected AbstractBeanDefinition parseInternal(Element element, ParserContext pa
5555
}
5656
builder.addPropertyReference("jobRepository", repositoryAttribute);
5757

58+
String restartableAttribute = element.getAttribute("restartable");
59+
if (StringUtils.hasText(restartableAttribute)) {
60+
builder.addPropertyValue("restartable", restartableAttribute);
61+
}
62+
5863
FlowParser flowParser = new FlowParser();
5964
AbstractBeanDefinition flowDef = flowParser.parse(element, parserContext, jobName);
6065

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/StepParser.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.springframework.util.StringUtils;
3838
import org.springframework.util.xml.DomUtils;
3939
import org.w3c.dom.Element;
40+
import org.w3c.dom.NamedNodeMap;
41+
import org.w3c.dom.Node;
4042

4143
/**
4244
* Internal parser for the <step/> elements inside a job. A step element
@@ -198,10 +200,13 @@ public static RuntimeBeanReference getStateTransitionReference(ParserContext par
198200
protected RootBeanDefinition parseChunkOriented(Element element, ParserContext parserContext) {
199201

200202
RootBeanDefinition bd;
203+
204+
boolean isFaultTolerant = false;
201205

202206
String faultTolerant = element.getAttribute("fault-tolerant");
203207
if ("true".equals(faultTolerant)) {
204208
bd = new RootBeanDefinition("org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean", null, null);
209+
isFaultTolerant = true;
205210
}
206211
else {
207212
bd = new RootBeanDefinition("org.springframework.batch.core.step.item.SimpleStepFactoryBean", null, null);
@@ -233,6 +238,25 @@ protected RootBeanDefinition parseChunkOriented(Element element, ParserContext p
233238
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
234239
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
235240

241+
String commitInterval = element.getAttribute("commit-interval");
242+
if (StringUtils.hasText(commitInterval)) {
243+
bd.getPropertyValues().addPropertyValue("commitInterval", commitInterval);
244+
}
245+
246+
if (isFaultTolerant) {
247+
String skipLimit = element.getAttribute("skip-limit");
248+
if (StringUtils.hasText(skipLimit)) {
249+
bd.getPropertyValues().addPropertyValue("skipLimit", skipLimit);
250+
}
251+
}
252+
253+
if (isFaultTolerant) {
254+
String retryLimit = element.getAttribute("retry-limit");
255+
if (StringUtils.hasText(retryLimit)) {
256+
bd.getPropertyValues().addPropertyValue("retryLimit", retryLimit);
257+
}
258+
}
259+
236260
handleExceptionElement(element, bd, "skippable-exception-classes", "skippableExceptionClasses");
237261

238262
handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses");
@@ -276,7 +300,16 @@ private void handleListenersElement(Element element, RootBeanDefinition bd, Pars
276300
String className = listenerElement.getAttribute("class");
277301
if ((StringUtils.hasText(id) || StringUtils.hasText(className))
278302
&& StringUtils.hasText(listenerRef)) {
279-
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 + "\"" : ""));
303+
NamedNodeMap attributeNodes = listenerElement.getAttributes();
304+
StringBuilder attributes = new StringBuilder();
305+
for (int i = 0; i < attributeNodes.getLength(); i++) {
306+
if (i > 0) {
307+
attributes.append(" ");
308+
}
309+
attributes.append(attributeNodes.item(i));
310+
}
311+
throw new BeanCreationException("Both 'id' or 'ref' plus 'class' specified; use 'class' with an optional 'id' or just 'ref' for <" +
312+
listenerElement.getTagName() + "> element with attributes: " + attributes);
280313
}
281314
if (StringUtils.hasText(listenerRef)) {
282315
listenerRefs.add(listenerRef);

spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@
3737
</xsd:documentation>
3838
</xsd:annotation>
3939
</xsd:attribute>
40+
<xsd:attribute name="restartable" type="xsd:boolean" default="false" use="optional">
41+
<xsd:annotation>
42+
<xsd:documentation><![CDATA[
43+
Whether the job should be retartable or not in case of failure.
44+
]]></xsd:documentation>
45+
</xsd:annotation>
46+
</xsd:attribute>
4047
</xsd:extension>
4148
</xsd:complexContent>
4249
</xsd:complexType>
@@ -194,6 +201,13 @@
194201
<xsd:extension base="beans:identifiedType">
195202
<xsd:attributeGroup ref="jobRepository"/>
196203
<xsd:attributeGroup ref="transactionManager"/>
204+
<xsd:attribute name="commit-interval" type="xsd:integer" use="optional">
205+
<xsd:annotation>
206+
<xsd:documentation><![CDATA[
207+
The number of items that will be processed before commit is called for the transaction.
208+
]]></xsd:documentation>
209+
</xsd:annotation>
210+
</xsd:attribute>
197211
</xsd:extension>
198212
</xsd:complexContent>
199213
</xsd:complexType>
@@ -269,7 +283,14 @@
269283
</xsd:simpleType>
270284
</xsd:element>
271285
</xsd:sequence>
272-
<xsd:attribute name="fault-tolerant" type="xsd:boolean" default="false" use="optional"/>
286+
<xsd:attribute name="fault-tolerant" type="xsd:boolean" default="false" use="optional">
287+
<xsd:annotation>
288+
<xsd:documentation><![CDATA[
289+
Whether the step should provide fault tolerance with skip limit and skippable
290+
exception handling.
291+
]]></xsd:documentation>
292+
</xsd:annotation>
293+
</xsd:attribute>
273294
<xsd:attribute name="reader" type="xsd:string" use="required">
274295
<xsd:annotation>
275296
<xsd:documentation><![CDATA[
@@ -291,6 +312,20 @@
291312
]]></xsd:documentation>
292313
</xsd:annotation>
293314
</xsd:attribute>
315+
<xsd:attribute name="skip-limit" type="xsd:integer" use="optional">
316+
<xsd:annotation>
317+
<xsd:documentation><![CDATA[
318+
The maximum number of items that will be allowed to be skipped.
319+
]]></xsd:documentation>
320+
</xsd:annotation>
321+
</xsd:attribute>
322+
<xsd:attribute name="retry-limit" type="xsd:integer" use="optional">
323+
<xsd:annotation>
324+
<xsd:documentation><![CDATA[
325+
The maximum number of times the processing of an item will be retried.
326+
]]></xsd:documentation>
327+
</xsd:annotation>
328+
</xsd:attribute>
294329
</xsd:extension>
295330
</xsd:complexContent>
296331
</xsd:complexType>

spring-batch-core/src/test/java/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class StepWithChunkOrientedJobParserTests {
4747

4848
@Autowired
4949
private JobRepository jobRepository;
50-
50+
5151
@Autowired
5252
private TestReader reader;
5353

spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithChunkOrientedJobParserTests-context.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
<job id="job">
1010
<step name="step1">
11-
<chunk-oriented reader="reader" processor="processor" writer="writer">
11+
<chunk-oriented reader="reader" processor="processor" writer="writer"
12+
fault-tolerant="true" commit-interval="10" skip-limit="20" retry-limit="3">
1213
<listeners>
1314
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
1415
<listener ref="listener"/>

0 commit comments

Comments
 (0)