BATCH-968: refactored step/tasklet elements, removed simple-task
This commit is contained in:
@@ -65,18 +65,17 @@ public class StepParser {
|
||||
BeanDefinitionBuilder stateBuilder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition("org.springframework.batch.core.job.flow.support.state.StepState");
|
||||
String stepRef = element.getAttribute("name");
|
||||
String taskletRef = element.getAttribute("tasklet");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Element> simpleTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "simple-task");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Element> processTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "item-task");
|
||||
if (simpleTaskElements.size() > 0) {
|
||||
Object task = parseSimpleTask(simpleTaskElements.get(0), parserContext);
|
||||
List<Element> processTaskElements = (List<Element>) DomUtils.getChildElementsByTagName(element, "tasklet");
|
||||
if (StringUtils.hasText(taskletRef)) {
|
||||
Object task = handleTaskletStep(element, taskletRef, parserContext);
|
||||
stateBuilder.addConstructorArgValue(stepRef);
|
||||
stateBuilder.addConstructorArgValue(task);
|
||||
}
|
||||
else if (processTaskElements.size() > 0) {
|
||||
Object task = parseProcessTask(processTaskElements.get(0), parserContext);
|
||||
Object task = handleChunkOrientedTaskletStep(element, processTaskElements.get(0), parserContext);
|
||||
stateBuilder.addConstructorArgValue(stepRef);
|
||||
stateBuilder.addConstructorArgValue(task);
|
||||
}
|
||||
@@ -191,29 +190,29 @@ public class StepParser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param element
|
||||
* @param stepElement
|
||||
* @param taskletRef
|
||||
* @param parserContext
|
||||
* @return the TaskletStep bean
|
||||
*/
|
||||
protected RootBeanDefinition parseSimpleTask(Element element, ParserContext parserContext) {
|
||||
protected RootBeanDefinition handleTaskletStep(Element stepElement, String taskletRef, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd = new RootBeanDefinition("org.springframework.batch.core.step.tasklet.TaskletStep", null, null);
|
||||
|
||||
String taskletBeanId = element.getAttribute("tasklet");
|
||||
if (StringUtils.hasText(taskletBeanId)) {
|
||||
RuntimeBeanReference taskletRef = new RuntimeBeanReference(taskletBeanId);
|
||||
bd.getPropertyValues().addPropertyValue("tasklet", taskletRef);
|
||||
if (StringUtils.hasText(taskletRef)) {
|
||||
RuntimeBeanReference taskletBeanRef = new RuntimeBeanReference(taskletRef);
|
||||
bd.getPropertyValues().addPropertyValue("tasklet", taskletBeanRef);
|
||||
}
|
||||
|
||||
String jobRepository = element.getAttribute("job-repository");
|
||||
RuntimeBeanReference jobRepositoryRef = new RuntimeBeanReference(jobRepository);
|
||||
bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryRef);
|
||||
String jobRepositoryRef = stepElement.getAttribute("job-repository");
|
||||
RuntimeBeanReference jobRepositoryBeanRef = new RuntimeBeanReference(jobRepositoryRef);
|
||||
bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryBeanRef);
|
||||
|
||||
String transactionManager = element.getAttribute("transaction-manager");
|
||||
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
|
||||
String transactionManagerRef = stepElement.getAttribute("transaction-manager");
|
||||
RuntimeBeanReference transactionManagerBeanRef = new RuntimeBeanReference(transactionManagerRef);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", transactionManagerBeanRef);
|
||||
|
||||
handleListenersElement(element, bd, parserContext, "stepExecutionListeners");
|
||||
handleListenersElement(stepElement, bd, parserContext, "stepExecutionListeners");
|
||||
|
||||
bd.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
|
||||
@@ -226,7 +225,7 @@ public class StepParser {
|
||||
* @param parserContext
|
||||
* @return the TaskletStep bean
|
||||
*/
|
||||
protected RootBeanDefinition parseProcessTask(Element element, ParserContext parserContext) {
|
||||
protected RootBeanDefinition handleChunkOrientedTaskletStep(Element stepElement, Element element, ParserContext parserContext) {
|
||||
|
||||
RootBeanDefinition bd;
|
||||
|
||||
@@ -286,11 +285,11 @@ public class StepParser {
|
||||
bd.getPropertyValues().addPropertyValue("taskExecutor", taskExecutorRef);
|
||||
}
|
||||
|
||||
String jobRepository = element.getAttribute("job-repository");
|
||||
String jobRepository = stepElement.getAttribute("job-repository");
|
||||
RuntimeBeanReference jobRepositoryRef = new RuntimeBeanReference(jobRepository);
|
||||
bd.getPropertyValues().addPropertyValue("jobRepository", jobRepositoryRef);
|
||||
|
||||
String transactionManager = element.getAttribute("transaction-manager");
|
||||
String transactionManager = stepElement.getAttribute("transaction-manager");
|
||||
RuntimeBeanReference tx = new RuntimeBeanReference(transactionManager);
|
||||
bd.getPropertyValues().addPropertyValue("transactionManager", tx);
|
||||
|
||||
@@ -328,7 +327,7 @@ public class StepParser {
|
||||
|
||||
handleExceptionElement(element, parserContext, bd, "fatal-exception-classes", "fatalExceptionClasses", isFaultTolerant);
|
||||
|
||||
handleListenersElement(element, bd, parserContext, "listeners");
|
||||
handleListenersElement(stepElement, bd, parserContext, "listeners");
|
||||
|
||||
handleRetryListenersElement(element, bd, parserContext);
|
||||
|
||||
|
||||
@@ -133,6 +133,13 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="tasklet" type="xsd:string" use="optional" >
|
||||
<xsd:annotation>
|
||||
<xsd:documentation>
|
||||
The tasklet is a reference to another bean definition that defines implements the Tasklet interface.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
@@ -210,29 +217,10 @@
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="nextType">
|
||||
<xsd:sequence>
|
||||
<xsd:choice>
|
||||
<xsd:element name="item-task" type="itemTaskType" minOccurs="0" maxOccurs="1"/>
|
||||
<xsd:element name="simple-task" type="simpleTaskType" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:choice>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="tasklet" type="taskletType" minOccurs="0" maxOccurs="1"/>
|
||||
</xsd:sequence>
|
||||
<xsd:group ref="transitions"/>
|
||||
</xsd:sequence>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="stepDefType">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:attributeGroup ref="jobRepository"/>
|
||||
<xsd:attributeGroup ref="transactionManager"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="simpleTaskType">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="stepDefType">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="listeners" minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
@@ -242,25 +230,20 @@
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="listener" type="listenerType" minOccurs="1" maxOccurs="unbounded"/>
|
||||
<xsd:element name="listener" type="stepListenerType" minOccurs="1" maxOccurs="unbounded"/>
|
||||
</xsd:sequence>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="tasklet" type="xsd:string" use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The bean name of the tasklet that is to be used for the task.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attributeGroup ref="jobRepository"/>
|
||||
<xsd:attributeGroup ref="transactionManager"/>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:complexType name="itemTaskType">
|
||||
<xsd:complexType name="taskletType">
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="stepDefType">
|
||||
<xsd:extension base="beans:identifiedType">
|
||||
<xsd:sequence>
|
||||
<xsd:element name="listeners" minOccurs="0" maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
|
||||
@@ -7,9 +7,7 @@
|
||||
<beans:import resource="common-context.xml" />
|
||||
|
||||
<job id="job" incrementer="testIncrementer" repository="jobRepository">
|
||||
<step name="step1">
|
||||
<simple-task tasklet="tasklet"/>
|
||||
</step>
|
||||
<step name="step1" tasklet="tasklet"/>
|
||||
<listeners>
|
||||
<listener after-method="afterJob" ref="testListener"/>
|
||||
<listener after-method="afterJob" class="org.springframework.batch.core.configuration.xml.TestJobListener"/>
|
||||
|
||||
@@ -8,17 +8,17 @@
|
||||
|
||||
<job id="job">
|
||||
<step name="ft-step">
|
||||
<item-task reader="reader" processor="processor" writer="writer"
|
||||
<tasklet reader="reader" processor="processor" writer="writer"
|
||||
commit-interval="10">
|
||||
<listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestListener"
|
||||
after-step-method="destroy"/>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
<streams>
|
||||
<stream ref="reader"/>
|
||||
</streams>
|
||||
</item-task>
|
||||
</tasklet>
|
||||
<listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestListener"
|
||||
after-step-method="destroy"/>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
|
||||
@@ -8,16 +8,12 @@
|
||||
|
||||
<job id="job">
|
||||
<step name="step">
|
||||
<item-task reader="reader" processor="processor" writer="writer"
|
||||
<tasklet reader="reader" processor="processor" writer="writer"
|
||||
commit-interval="10" skip-limit="20"
|
||||
retry-limit="3" cache-capacity="100"
|
||||
transaction-attribute="PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_10,-org.springframework.dao.DataIntegrityViolationException"
|
||||
is-reader-transactional-queue="true"
|
||||
task-executor="taskExecutor">
|
||||
<listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
<retry-listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestRetryListener"/>
|
||||
</retry-listeners>
|
||||
@@ -27,7 +23,11 @@
|
||||
<skippable-exception-classes>
|
||||
org.springframework.dao.DataIntegrityViolationException,
|
||||
</skippable-exception-classes>
|
||||
</item-task>
|
||||
</tasklet>
|
||||
<listeners>
|
||||
<listener class="org.springframework.batch.core.configuration.xml.TestListener"/>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
|
||||
@@ -7,16 +7,13 @@
|
||||
<beans:import resource="common-context.xml" />
|
||||
|
||||
<job id="job">
|
||||
<step name="step1">
|
||||
<simple-task tasklet="tasklet"/>
|
||||
<step name="step1" tasklet="tasklet">
|
||||
<next on="*" to="step2" />
|
||||
</step>
|
||||
<step name="step2">
|
||||
<simple-task tasklet="tasklet">
|
||||
<listeners>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
</simple-task>
|
||||
<step name="step2" tasklet="tasklet">
|
||||
<listeners>
|
||||
<listener ref="listener"/>
|
||||
</listeners>
|
||||
</step>
|
||||
</job>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user