Skip to content

Commit 13734f0

Browse files
author
trisberg
committed
BATCH-63: renamed chunk-oriented to chunk and commit-interval to chunk-size
1 parent cb738dc commit 13734f0

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ public Collection<RuntimeBeanReference> parse(Element element, ParserContext par
7272
@SuppressWarnings("unchecked")
7373
List<Element> taskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "task");
7474
@SuppressWarnings("unchecked")
75-
List<Element> chunkOrientedElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "chunk-oriented");
75+
List<Element> chunkElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "chunk");
7676
if (taskElements.size() > 0) {
7777
Object task = parseTask(taskElements.get(0), parserContext);
7878
stateBuilder.addConstructorArgValue(stepRef);
7979
stateBuilder.addConstructorArgValue(task);
8080
}
81-
else if (chunkOrientedElements.size() > 0) {
82-
Object task = parseChunkOriented(chunkOrientedElements.get(0), parserContext);
81+
else if (chunkElements.size() > 0) {
82+
Object task = parseChunk(chunkElements.get(0), parserContext);
8383
stateBuilder.addConstructorArgValue(stepRef);
8484
stateBuilder.addConstructorArgValue(task);
8585
}
@@ -196,7 +196,7 @@ public static RuntimeBeanReference getStateTransitionReference(ParserContext par
196196
* @param parserContext
197197
* @return the TaskletStep bean
198198
*/
199-
protected RootBeanDefinition parseChunkOriented(Element element, ParserContext parserContext) {
199+
protected RootBeanDefinition parseChunk(Element element, ParserContext parserContext) {
200200

201201
RootBeanDefinition bd;
202202

@@ -237,30 +237,32 @@ protected RootBeanDefinition parseChunkOriented(Element element, ParserContext p
237237
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
238238
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
239239

240-
String commitInterval = element.getAttribute("commit-interval");
240+
String commitInterval = element.getAttribute("chunk-size");
241241
if (StringUtils.hasText(commitInterval)) {
242242
bd.getPropertyValues().addPropertyValue("commitInterval", commitInterval);
243243
}
244244

245-
if (isFaultTolerant) {
246-
String skipLimit = element.getAttribute("skip-limit");
247-
if (StringUtils.hasText(skipLimit)) {
248-
bd.getPropertyValues().addPropertyValue("skipLimit", skipLimit);
249-
}
245+
String skipLimit = element.getAttribute("skip-limit");
246+
if (StringUtils.hasText(skipLimit)) {
247+
if (!isFaultTolerant) {
248+
throw new BeanCreationException("skip-limit can only be specified if fault-tolerant is set to 'true'");
249+
}
250+
bd.getPropertyValues().addPropertyValue("skipLimit", skipLimit);
250251
}
251252

252-
if (isFaultTolerant) {
253-
String retryLimit = element.getAttribute("retry-limit");
254-
if (StringUtils.hasText(retryLimit)) {
255-
bd.getPropertyValues().addPropertyValue("retryLimit", retryLimit);
256-
}
253+
String retryLimit = element.getAttribute("retry-limit");
254+
if (StringUtils.hasText(retryLimit)) {
255+
if (!isFaultTolerant) {
256+
throw new BeanCreationException("retry-limit can only be specified if fault-tolerant is set to 'true'");
257+
}
258+
bd.getPropertyValues().addPropertyValue("retryLimit", retryLimit);
257259
}
258260

259-
handleExceptionElement(element, bd, "skippable-exception-classes", "skippableExceptionClasses");
261+
handleExceptionElement(element, bd, "skippable-exception-classes", "skippableExceptionClasses", isFaultTolerant);
260262

261-
handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses");
263+
handleExceptionElement(element, bd, "retryable-exception-classes", "retryableExceptionClasses",isFaultTolerant);
262264

263-
handleExceptionElement(element, bd, "fatal-exception-classes", "fatalExceptionClasses");
265+
handleExceptionElement(element, bd, "fatal-exception-classes", "fatalExceptionClasses",isFaultTolerant);
264266

265267
handleListenersElement(element, bd, parserContext);
266268

@@ -271,10 +273,13 @@ protected RootBeanDefinition parseChunkOriented(Element element, ParserContext p
271273
}
272274

273275
private void handleExceptionElement(Element element, RootBeanDefinition bd,
274-
String attributeName, String propertyName) {
276+
String attributeName, String propertyName, boolean isFaultTolerant) {
275277
String exceptions =
276278
DomUtils.getChildElementValueByTagName(element, attributeName);
277279
if (StringUtils.hasLength(exceptions)) {
280+
if (!isFaultTolerant) {
281+
throw new BeanCreationException(attributeName + " can only be specified if fault-tolerant is set to 'true'");
282+
}
278283
String[] exceptionArray = StringUtils.tokenizeToStringArray(
279284
StringUtils.delete(exceptions, ","), "\n");
280285
if (exceptionArray.length > 0) {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@
175175
<xsd:extension base="nextType">
176176
<xsd:sequence>
177177
<xsd:choice>
178-
<xsd:element name="chunk-oriented" minOccurs="0" maxOccurs="1">
178+
<xsd:element name="chunk" minOccurs="0" maxOccurs="1">
179179
<xsd:complexType>
180180
<xsd:complexContent>
181-
<xsd:extension base="chunkOrientedType"/>
181+
<xsd:extension base="chunkType"/>
182182
</xsd:complexContent>
183183
</xsd:complexType>
184184
</xsd:element>
@@ -201,13 +201,6 @@
201201
<xsd:extension base="beans:identifiedType">
202202
<xsd:attributeGroup ref="jobRepository"/>
203203
<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>
211204
</xsd:extension>
212205
</xsd:complexContent>
213206
</xsd:complexType>
@@ -226,7 +219,7 @@
226219
</xsd:complexContent>
227220
</xsd:complexType>
228221

229-
<xsd:complexType name="chunkOrientedType">
222+
<xsd:complexType name="chunkType">
230223
<xsd:complexContent>
231224
<xsd:extension base="stepDefType">
232225
<xsd:sequence>
@@ -283,6 +276,13 @@
283276
</xsd:simpleType>
284277
</xsd:element>
285278
</xsd:sequence>
279+
<xsd:attribute name="chunk-size" type="xsd:integer" use="required">
280+
<xsd:annotation>
281+
<xsd:documentation><![CDATA[
282+
The number of items that will be processed before commit is called for the transaction.
283+
]]></xsd:documentation>
284+
</xsd:annotation>
285+
</xsd:attribute>
286286
<xsd:attribute name="fault-tolerant" type="xsd:boolean" default="false" use="optional">
287287
<xsd:annotation>
288288
<xsd:documentation><![CDATA[
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
@ContextConfiguration
4242
@RunWith(SpringJUnit4ClassRunner.class)
43-
public class StepWithChunkOrientedJobParserTests {
43+
public class StepWithChunkJobParserTests {
4444

4545
@Autowired
4646
private Job job;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
<job id="job">
1010
<step name="step1">
11-
<chunk-oriented reader="reader" processor="processor" writer="writer"
12-
fault-tolerant="true" commit-interval="10" skip-limit="20" retry-limit="3">
11+
<chunk reader="reader" processor="processor" writer="writer"
12+
fault-tolerant="true" chunk-size="10" skip-limit="20" retry-limit="3">
1313
<listeners>
1414
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
1515
<listener ref="listener"/>
1616
</listeners>
17-
</chunk-oriented>
17+
</chunk>
1818
</step>
1919
</job>
2020

0 commit comments

Comments
 (0)