Skip to content

Commit 8a1eae3

Browse files
author
trisberg
committed
BATCH-63: added beginning of <chunk-oriented> element and parsing
1 parent 9fc06e5 commit 8a1eae3

File tree

6 files changed

+217
-92
lines changed

6 files changed

+217
-92
lines changed

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,21 +68,24 @@ public Collection<RuntimeBeanReference> parse(Element element, ParserContext par
6868

6969
@SuppressWarnings("unchecked")
7070
List<Element> taskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "task");
71+
@SuppressWarnings("unchecked")
72+
List<Element> chunkOrientedElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "chunk-oriented");
7173
if (taskElements.size() > 0) {
72-
//TaskParser taskParser = new TaskParser();
73-
// Object task = taskParser.parse(taskElements.get(0), parserContext);
7474
Object task = parseTask(taskElements.get(0), parserContext);
7575
stateBuilder.addConstructorArgValue(stepRef);
7676
stateBuilder.addConstructorArgValue(task);
7777
}
78-
else {
79-
if (StringUtils.hasText(stepRef)) {
78+
else if (chunkOrientedElements.size() > 0) {
79+
Object task = parseChunkOriented(chunkOrientedElements.get(0), parserContext);
80+
stateBuilder.addConstructorArgValue(stepRef);
81+
stateBuilder.addConstructorArgValue(task);
82+
}
83+
else if (StringUtils.hasText(stepRef)) {
8084
RuntimeBeanReference stateDef = new RuntimeBeanReference(stepRef);
8185
stateBuilder.addConstructorArgValue(stateDef);
82-
}
83-
else {
84-
throw new BeanCreationException("Error creating Step for " + element);
85-
}
86+
}
87+
else {
88+
throw new BeanCreationException("Error creating Step for " + element);
8689
}
8790
return getNextElements(parserContext, stateBuilder.getBeanDefinition(), element);
8891

@@ -185,6 +188,43 @@ public static RuntimeBeanReference getStateTransitionReference(ParserContext par
185188

186189
}
187190

191+
/**
192+
* @param element
193+
* @param parserContext
194+
* @return the TaskletStep bean
195+
*/
196+
protected RootBeanDefinition parseChunkOriented(Element element, ParserContext parserContext) {
197+
198+
System.out.println("PARSING PROCESS!!!");
199+
200+
RootBeanDefinition bd = new RootBeanDefinition("org.springframework.batch.core.step.item.SimpleStepFactoryBean", null, null);
201+
202+
String readerBeanId = element.getAttribute("reader");
203+
if (StringUtils.hasText(readerBeanId)) {
204+
RuntimeBeanReference taskletRef = new RuntimeBeanReference(readerBeanId);
205+
bd.getPropertyValues().addPropertyValue("itemReader", taskletRef);
206+
}
207+
208+
String writerBeanId = element.getAttribute("writer");
209+
if (StringUtils.hasText(writerBeanId)) {
210+
RuntimeBeanReference taskletRef = new RuntimeBeanReference(writerBeanId);
211+
bd.getPropertyValues().addPropertyValue("itemWriter", taskletRef);
212+
}
213+
214+
String jobRepository = element.getAttribute("job-repository");
215+
RuntimeBeanReference jobRepositoryRef = new RuntimeBeanReference(jobRepository);
216+
bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryRef);
217+
218+
String transactionManager = element.getAttribute("transaction-manager");
219+
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
220+
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
221+
222+
bd.setRole(BeanDefinition.ROLE_SUPPORT);
223+
224+
return bd;
225+
226+
}
227+
188228
/**
189229
* @param element
190230
* @param parserContext
@@ -199,6 +239,7 @@ protected RootBeanDefinition parseTask(Element element, ParserContext parserCont
199239
RuntimeBeanReference taskletRef = new RuntimeBeanReference(taskletBeanId);
200240
bd.getPropertyValues().addPropertyValue("tasklet", taskletRef);
201241
}
242+
202243
String jobRepository = element.getAttribute("job-repository");
203244
RuntimeBeanReference jobRepositoryRef = new RuntimeBeanReference(jobRepository);
204245
bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryRef);

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

Lines changed: 116 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@
2020
<xsd:documentation>
2121
Defines a job composed of a set of steps and
2222
transitions between steps. The job will be exposed
23-
in
24-
the enclosing
25-
bean factory as a component of type Job
26-
that can be
27-
launched using a
28-
JobLauncher.
23+
in the enclosing bean factory as a component of type Job
24+
that can be launched using a JobLauncher.
2925
</xsd:documentation>
3026
</xsd:annotation>
3127
<xsd:complexType>
@@ -70,23 +66,7 @@
7066
</xsd:appinfo>
7167
</xsd:annotation>
7268
</xsd:attribute>
73-
<xsd:attribute name="transaction-manager" type="xsd:string"
74-
default="transactionManager">
75-
<xsd:annotation>
76-
<xsd:documentation
77-
source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
78-
The bean name of the TransactionManager that is to be used. This attribute
79-
is not required, and only needs to be specified explicitly
80-
if the bean name of the desired TransactionManager is not 'transactionManager'.
81-
]]></xsd:documentation>
82-
<xsd:appinfo>
83-
<tool:annotation kind="ref">
84-
<tool:expected-type
85-
type="org.springframework.transaction.PlatformTransactionManager" />
86-
</tool:annotation>
87-
</xsd:appinfo>
88-
</xsd:annotation>
89-
</xsd:attribute>
69+
<xsd:attributeGroup ref="transactionManager"/>
9070
<xsd:attribute name="isolation-level-for-create"
9171
type="xsd:string">
9272
<xsd:annotation>
@@ -117,13 +97,9 @@
11797
<xsd:element name="step">
11898
<xsd:annotation>
11999
<xsd:documentation>
120-
Defines a stage in job processing backed by a
121-
Step. The name
122-
attribute has to match the id of a
123-
bean definition
124-
for
125-
a Step. The
126-
next attribute is a synonym for &lt;next on="*" .../&gt;
100+
Defines a stage in job processing backed by a Step. The name
101+
attribute has to match the id of a bean definition for a Step.
102+
The next attribute is a synonym for &lt;next on="*" .../&gt;
127103
</xsd:documentation>
128104
</xsd:annotation>
129105
<xsd:complexType>
@@ -191,65 +167,75 @@
191167
<xsd:complexContent>
192168
<xsd:extension base="nextType">
193169
<xsd:sequence>
194-
<xsd:element name="task" minOccurs="0" maxOccurs="1">
195-
<xsd:complexType>
196-
<xsd:complexContent>
197-
<xsd:extension base="beans:identifiedType">
198-
<xsd:attribute name="tasklet" type="xsd:string" use="required">
199-
<xsd:annotation>
200-
<xsd:documentation><![CDATA[
201-
The bean name of the tasklet that is to be used for the task.
202-
]]></xsd:documentation>
203-
</xsd:annotation>
204-
</xsd:attribute>
205-
<xsd:attribute name="job-repository" type="xsd:string"
206-
default="jobRepository">
207-
<xsd:annotation>
208-
<xsd:documentation
209-
source="java:org.springframework.batch.core.repository.JobRepository"><![CDATA[
210-
The bean name of the JobRepository that is to be used. This attribute
211-
is not required, and only needs to be specified explicitly
212-
if the bean name of the desired JobRepository is not 'jobRepository'.
213-
]]></xsd:documentation>
214-
<xsd:appinfo>
215-
<tool:annotation kind="ref">
216-
<tool:expected-type
217-
type="org.springframework.batch.core.repository.JobRepository" />
218-
</tool:annotation>
219-
</xsd:appinfo>
220-
</xsd:annotation>
221-
</xsd:attribute>
222-
<xsd:attribute name="transaction-manager" type="xsd:string"
223-
default="transactionManager">
224-
<xsd:annotation>
225-
<xsd:documentation
226-
source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
227-
The bean name of the TransactionManager that is to be used. This attribute
228-
is not required, and only needs to be specified explicitly
229-
if the bean name of the desired TransactionManager is not 'transactionManager'.
230-
]]></xsd:documentation>
231-
<xsd:appinfo>
232-
<tool:annotation kind="ref">
233-
<tool:expected-type
234-
type="org.springframework.transaction.PlatformTransactionManager" />
235-
</tool:annotation>
236-
</xsd:appinfo>
237-
</xsd:annotation>
238-
</xsd:attribute>
239-
</xsd:extension>
240-
</xsd:complexContent>
241-
</xsd:complexType>
242-
</xsd:element>
170+
<xsd:choice>
171+
<xsd:element name="chunk-oriented" minOccurs="0" maxOccurs="1">
172+
<xsd:complexType>
173+
<xsd:complexContent>
174+
<xsd:extension base="processType"/>
175+
</xsd:complexContent>
176+
</xsd:complexType>
177+
</xsd:element>
178+
<xsd:element name="task" minOccurs="0" maxOccurs="1">
179+
<xsd:complexType>
180+
<xsd:complexContent>
181+
<xsd:extension base="taskType"/>
182+
</xsd:complexContent>
183+
</xsd:complexType>
184+
</xsd:element>
185+
</xsd:choice>
243186
<xsd:group ref="transitions"/>
244187
</xsd:sequence>
245188
</xsd:extension>
246189
</xsd:complexContent>
247190
</xsd:complexType>
248191

249-
<xsd:complexType name="transitionWithNextType">
192+
<xsd:complexType name="stepDefType">
250193
<xsd:complexContent>
251-
<xsd:extension base="nextType">
252-
<xsd:group ref="transitions"/>
194+
<xsd:extension base="beans:identifiedType">
195+
<xsd:attributeGroup ref="jobRepository"/>
196+
<xsd:attributeGroup ref="transactionManager"/>
197+
</xsd:extension>
198+
</xsd:complexContent>
199+
</xsd:complexType>
200+
201+
<xsd:complexType name="taskType">
202+
<xsd:complexContent>
203+
<xsd:extension base="stepDefType">
204+
<xsd:attribute name="tasklet" type="xsd:string" use="required">
205+
<xsd:annotation>
206+
<xsd:documentation><![CDATA[
207+
The bean name of the tasklet that is to be used for the task.
208+
]]></xsd:documentation>
209+
</xsd:annotation>
210+
</xsd:attribute>
211+
</xsd:extension>
212+
</xsd:complexContent>
213+
</xsd:complexType>
214+
215+
<xsd:complexType name="processType">
216+
<xsd:complexContent>
217+
<xsd:extension base="stepDefType">
218+
<xsd:attribute name="reader" type="xsd:string" use="required">
219+
<xsd:annotation>
220+
<xsd:documentation><![CDATA[
221+
The bean name of the item reader that is to be used for the process.
222+
]]></xsd:documentation>
223+
</xsd:annotation>
224+
</xsd:attribute>
225+
<xsd:attribute name="processor" type="xsd:string" use="optional">
226+
<xsd:annotation>
227+
<xsd:documentation><![CDATA[
228+
The bean name of the item processor that is to be used for the process.
229+
]]></xsd:documentation>
230+
</xsd:annotation>
231+
</xsd:attribute>
232+
<xsd:attribute name="writer" type="xsd:string" use="required">
233+
<xsd:annotation>
234+
<xsd:documentation><![CDATA[
235+
The bean name of the item writer that is to be used for the process.
236+
]]></xsd:documentation>
237+
</xsd:annotation>
238+
</xsd:attribute>
253239
</xsd:extension>
254240
</xsd:complexContent>
255241
</xsd:complexType>
@@ -269,6 +255,14 @@
269255
<xsd:group ref="transitions"/>
270256
</xsd:complexType>
271257

258+
<xsd:complexType name="transitionWithNextType">
259+
<xsd:complexContent>
260+
<xsd:extension base="nextType">
261+
<xsd:group ref="transitions"/>
262+
</xsd:extension>
263+
</xsd:complexContent>
264+
</xsd:complexType>
265+
272266
<xsd:group name="transitions">
273267
<xsd:sequence>
274268
<xsd:choice minOccurs="0" maxOccurs="unbounded" >
@@ -350,5 +344,45 @@
350344
</xsd:choice>
351345
</xsd:sequence>
352346
</xsd:group>
347+
348+
<xsd:attributeGroup name="jobRepository">
349+
<xsd:attribute name="job-repository" type="xsd:string"
350+
default="jobRepository">
351+
<xsd:annotation>
352+
<xsd:documentation
353+
source="java:org.springframework.batch.core.repository.JobRepository"><![CDATA[
354+
The bean name of the JobRepository that is to be used. This attribute
355+
is not required, and only needs to be specified explicitly
356+
if the bean name of the desired JobRepository is not 'jobRepository'.
357+
]]></xsd:documentation>
358+
<xsd:appinfo>
359+
<tool:annotation kind="ref">
360+
<tool:expected-type
361+
type="org.springframework.batch.core.repository.JobRepository" />
362+
</tool:annotation>
363+
</xsd:appinfo>
364+
</xsd:annotation>
365+
</xsd:attribute>
366+
</xsd:attributeGroup>
367+
368+
<xsd:attributeGroup name="transactionManager">
369+
<xsd:attribute name="transaction-manager" type="xsd:string"
370+
default="transactionManager">
371+
<xsd:annotation>
372+
<xsd:documentation
373+
source="java:org.springframework.transaction.PlatformTransactionManager"><![CDATA[
374+
The bean name of the TransactionManager that is to be used. This attribute
375+
is not required, and only needs to be specified explicitly
376+
if the bean name of the desired TransactionManager is not 'transactionManager'.
377+
]]></xsd:documentation>
378+
<xsd:appinfo>
379+
`<tool:annotation kind="ref">
380+
<tool:expected-type
381+
type="org.springframework.transaction.PlatformTransactionManager" />
382+
</tool:annotation>
383+
</xsd:appinfo>
384+
</xsd:annotation>
385+
</xsd:attribute>
386+
</xsd:attributeGroup>
353387

354388
</xsd:schema>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public void testStepWithTask() throws Exception {
5757
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
5858
job.execute(jobExecution);
5959
assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
60-
assertEquals(2, jobExecution.getStepExecutions().size());
60+
assertEquals(3, jobExecution.getStepExecutions().size());
6161
}
6262
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.springframework.batch.core.configuration.xml;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
import org.springframework.batch.item.ItemReader;
8+
import org.springframework.batch.item.ParseException;
9+
import org.springframework.batch.item.UnexpectedInputException;
10+
11+
public class TestReader implements ItemReader<String> {
12+
13+
List<String> items = null;
14+
15+
{
16+
List<String> l = new ArrayList<String>();
17+
l.add("Item *** 1 ***");
18+
l.add("Item *** 2 ***");
19+
this.items = Collections.synchronizedList(l);
20+
}
21+
22+
public String read() throws Exception, UnexpectedInputException,
23+
ParseException {
24+
if (items.size() > 0) {
25+
String item = items.remove(0);
26+
return item;
27+
}
28+
return null;
29+
}
30+
31+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.springframework.batch.core.configuration.xml;
2+
3+
import java.util.List;
4+
5+
import org.springframework.batch.item.ItemWriter;
6+
7+
public class TestWriter implements ItemWriter<String> {
8+
9+
public void write(List<? extends String> items) throws Exception {
10+
}
11+
12+
}

0 commit comments

Comments
 (0)