OPEN - issue BATCH-404: FactoryBeans for step configuration
http://jira.springframework.org/browse/BATCH-404 Remove SimpleStepFactoryBean.
This commit is contained in:
@@ -15,27 +15,6 @@
|
||||
<config>src/test/resources/beanRefContext.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/bootstrap/support/job.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/bootstrap/support/test-environment.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoDb2.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoDerby.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoHsql.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoMissingDataSource.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoMySql.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoOk.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoOracle.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/JobRepoPostgres.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepMissingItemReader.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepMissingItemWriter.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepMissingTransactionManager.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepOk.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepRerunAlways.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepRerunIncomplete.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepRerunNever.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/StepSpecificTransactionManager.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/TaskletStepMissingTasklet.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/TaskletStepOk.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/TaskletStepRerunAlways.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/TaskletStepRerunIncomplete.xml</config>
|
||||
<config>src/test/resources/org/springframework/batch/execution/configuration/TaskletStepRerunNever.xml</config>
|
||||
</configs>
|
||||
<configSets>
|
||||
<configSet>
|
||||
|
||||
@@ -350,7 +350,7 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
catch (Exception e) {
|
||||
fatalException.setException(e);
|
||||
stepExecution.setStatus(BatchStatus.UNKNOWN);
|
||||
throw new CommitFailedException("Fatal error detected during commit", e);
|
||||
throw new CommitFailedException("Fatal error detected during save of step execution context", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,26 +23,52 @@ import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.repeat.exception.handler.SimpleLimitExceptionHandler;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
|
||||
/**
|
||||
* Adds listeners to {@link SimpleStepFactoryBean}.
|
||||
* Most common configuration options for simple steps should be found here. Use
|
||||
* this factory bean instead of creating a {@link Step} implementation manually.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class DefaultStepFactoryBean extends SimpleStepFactoryBean {
|
||||
public class DefaultStepFactoryBean extends AbstractStepFactoryBean {
|
||||
|
||||
private boolean alwaysSkip = false;
|
||||
|
||||
private int commitInterval = 0;
|
||||
|
||||
private ItemStream[] streams = new ItemStream[0];
|
||||
|
||||
private BatchListener[] listeners = new BatchListener[0];
|
||||
|
||||
private ListenerMulticaster listener = new ListenerMulticaster();
|
||||
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
/**
|
||||
* Set the commit interval.
|
||||
*
|
||||
* @param commitInterval
|
||||
*/
|
||||
public void setCommitInterval(int commitInterval) {
|
||||
this.commitInterval = commitInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* The streams to inject into the {@link Step}. Any instance of
|
||||
* {@link ItemStream} can be used, and will then receive callbacks at the
|
||||
* appropriate stage in the step.
|
||||
*
|
||||
* @param streams an array of listeners
|
||||
*/
|
||||
public void setStreams(ItemStream[] streams) {
|
||||
this.streams = streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for a flag that determines skip policy. If this flag is
|
||||
* true then an exception in chunk processing will cause the item to be
|
||||
@@ -83,6 +109,15 @@ public class DefaultStepFactoryBean extends SimpleStepFactoryBean {
|
||||
protected void applyConfiguration(ItemOrientedStep step) {
|
||||
|
||||
super.applyConfiguration(step);
|
||||
|
||||
step.setStreams(streams);
|
||||
|
||||
if (commitInterval > 0) {
|
||||
RepeatTemplate chunkOperations = new RepeatTemplate();
|
||||
chunkOperations.setCompletionPolicy(new SimpleCompletionPolicy(commitInterval));
|
||||
step.setChunkOperations(chunkOperations);
|
||||
}
|
||||
|
||||
for (int i = 0; i < listeners.length; i++) {
|
||||
BatchListener listener = listeners[i];
|
||||
if (listener instanceof StepListener) {
|
||||
|
||||
@@ -26,9 +26,9 @@ import org.springframework.batch.repeat.RepeatOperations;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
|
||||
/**
|
||||
* Extends a {@link SimpleStepFactoryBean} allowing registration of listeners
|
||||
* and also direct injection of the {@link RepeatOperations} needed at step and
|
||||
* chunk level.
|
||||
* Factory bean for {@link Step} implementations allowing registration of
|
||||
* listeners and also direct injection of the {@link RepeatOperations} needed at
|
||||
* step and chunk level.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.execution.step.support;
|
||||
|
||||
import org.springframework.batch.core.domain.Step;
|
||||
import org.springframework.batch.execution.step.ItemOrientedStep;
|
||||
import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStepFactoryBean extends AbstractStepFactoryBean {
|
||||
|
||||
private int commitInterval = 0;
|
||||
|
||||
private ItemStream[] streams = new ItemStream[0];
|
||||
|
||||
/**
|
||||
* Set the commit interval.
|
||||
*
|
||||
* @param commitInterval
|
||||
*/
|
||||
public void setCommitInterval(int commitInterval) {
|
||||
this.commitInterval = commitInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* The streams to inject into the {@link Step}. Any instance of
|
||||
* {@link ItemStream} can be used, and will then receive callbacks at the
|
||||
* appropriate stage in the step.
|
||||
*
|
||||
* @param streams an array of listeners
|
||||
*/
|
||||
public void setStreams(ItemStream[] streams) {
|
||||
this.streams = streams;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param step
|
||||
*
|
||||
*/
|
||||
protected void applyConfiguration(ItemOrientedStep step) {
|
||||
|
||||
super.applyConfiguration(step);
|
||||
|
||||
step.setStreams(streams);
|
||||
|
||||
if (commitInterval > 0) {
|
||||
RepeatTemplate chunkOperations = new RepeatTemplate();
|
||||
chunkOperations.setCompletionPolicy(new SimpleCompletionPolicy(commitInterval));
|
||||
step.setChunkOperations(chunkOperations);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import org.springframework.batch.core.domain.Step;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class SimpleStepFactoryBeanTests extends TestCase {
|
||||
public class StatefulRetryStepFactoryBeanTests extends TestCase {
|
||||
|
||||
private AbstractStepFactoryBean factory = new StatefulRetryStepFactoryBean();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
class="org.springframework.batch.execution.job.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1"
|
||||
class="org.springframework.batch.execution.step.support.SimpleStepFactoryBean">
|
||||
class="org.springframework.batch.execution.step.support.DefaultStepFactoryBean">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ListItemReader">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
class="org.springframework.batch.execution.job.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1"
|
||||
class="org.springframework.batch.execution.step.support.SimpleStepFactoryBean">
|
||||
class="org.springframework.batch.execution.step.support.DefaultStepFactoryBean">
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ListItemReader">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<bean id="test-job"
|
||||
class="org.springframework.batch.execution.job.JobSupport">
|
||||
<property name="steps">
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.support.SimpleStepFactoryBean">
|
||||
<bean id="step1" class="org.springframework.batch.execution.step.support.DefaultStepFactoryBean">
|
||||
<property name="itemReader" ref="itemReader" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<import resource="data-source-context-init.xml" />
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
class="org.apache.commons.dbcp.BasicDataSource">
|
||||
<property name="driverClassName" value="${batch.jdbc.driver}" />
|
||||
<property name="url" value="${batch.jdbc.url}" />
|
||||
<property name="username" value="${batch.jdbc.user}" />
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<!-- set restartable=false so that this job can be used by more than one test -->
|
||||
<property name="restartable" value="false" />
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="defaultStep">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="alwaysSkip" value="true" />
|
||||
<property name="itemReader" ref="hibernateItemReader" />
|
||||
<property name="itemWriter" ref="hibernateOutputSource" />
|
||||
|
||||
@@ -4,19 +4,19 @@
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<bean id="parallelJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="staging" parent="defaultStep">
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="streams" ref="fileInputTemplate" />
|
||||
<property name="itemReader">
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
|
||||
|
||||
<bean id="parallelJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="staging" parent="simpleStep">
|
||||
<property name="commitInterval" value="2" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="streams" ref="fileInputTemplate" />
|
||||
<property name="itemReader">
|
||||
<bean
|
||||
class="org.springframework.batch.item.reader.ValidatingItemReader">
|
||||
<property name="itemReader"
|
||||
@@ -41,7 +41,7 @@
|
||||
</bean>
|
||||
</property>
|
||||
</bean>
|
||||
<bean id="loading" parent="defaultStep">
|
||||
<bean id="loading" parent="simpleStep">
|
||||
<property name="taskExecutor">
|
||||
<bean
|
||||
class="org.springframework.core.task.SimpleAsyncTaskExecutor" />
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
<bean id="retrySample" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<bean id="step1" parent="defaultStep"
|
||||
<bean id="step1" parent="simpleStep"
|
||||
class="org.springframework.batch.execution.step.support.StatefulRetryStepFactoryBean">
|
||||
<property name="itemReader" ref="itemGenerator" />
|
||||
<property name="itemWriter" ref="itemWriter" />
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<bean id="tradeJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
<list>
|
||||
<bean id="step1" parent="defaultStep">
|
||||
<bean id="step1" parent="simpleStep">
|
||||
<property name="alwaysSkip" value="true" />
|
||||
<property name="streams" ref="fileInputTemplate" />
|
||||
<property name="itemReader">
|
||||
|
||||
@@ -23,12 +23,12 @@ log4j.rootLogger=info, stdout
|
||||
|
||||
### enable spring
|
||||
log4j.logger.org.springframework=error
|
||||
log4j.logger.org.springframework.batch.sample=debug
|
||||
#log4j.logger.org.springframework.transaction=debug
|
||||
#log4j.logger.org.springframework.jdbc.core=debug
|
||||
#log4j.logger.org.springframework.orm=debug
|
||||
|
||||
### debug your specific package or classes with the following example
|
||||
log4j.logger.org.springframework.batch=debug
|
||||
#log4j.logger.org.springframework.batch=debug
|
||||
log4j.logger.org.springframework.batch.sample=debug
|
||||
log4j.logger.org.springframework.batch.sample.module.OrderDataProvider=debug
|
||||
log4j.logger.org.springframework.batch.container.common.module.process.support.DefaultXmlDataProvider=debug
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
</bean>
|
||||
|
||||
<bean id="simpleStep"
|
||||
class="org.springframework.batch.execution.step.support.SimpleStepFactoryBean"
|
||||
class="org.springframework.batch.execution.step.support.DefaultStepFactoryBean"
|
||||
abstract="true">
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
<property name="jobRepository" ref="jobRepository" />
|
||||
@@ -103,10 +103,6 @@
|
||||
<property name="commitInterval" value="1" />
|
||||
</bean>
|
||||
|
||||
<bean id="defaultStep" parent="simpleStep"
|
||||
class="org.springframework.batch.execution.step.support.DefaultStepFactoryBean"
|
||||
abstract="true" />
|
||||
|
||||
<bean id="customEditorConfigurer"
|
||||
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
|
||||
Reference in New Issue
Block a user