IN PROGRESS - BATCH-666: consolidate duplications in SimpleStepFactoryBean and RepeatOperationsStepFactoryBean

pulled up reader & writer registration
This commit is contained in:
robokaso
2008-06-13 09:10:21 +00:00
parent 09d681c8dc
commit d4a1e23b7e
3 changed files with 21 additions and 37 deletions

View File

@@ -16,6 +16,7 @@
package org.springframework.batch.core.step.item;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
@@ -187,6 +188,25 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
step.setAllowStartIfComplete(allowStartIfComplete);
step.setStreams(streams);
ItemReader itemReader = getItemReader();
ItemWriter itemWriter = getItemWriter();
// Since we are going to wrap these things with listener callbacks we
// need to register them here because the step will not know we did
// that.
if (itemReader instanceof ItemStream) {
step.registerStream((ItemStream) itemReader);
}
if (itemReader instanceof StepExecutionListener) {
step.registerStepExecutionListener((StepExecutionListener) itemReader);
}
if (itemWriter instanceof ItemStream) {
step.registerStream((ItemStream) itemWriter);
}
if (itemWriter instanceof StepExecutionListener) {
step.registerStepExecutionListener((StepExecutionListener) itemWriter);
}
}

View File

@@ -15,11 +15,10 @@
*/
package org.springframework.batch.core.step.item;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.support.RepeatTemplate;
@@ -85,24 +84,6 @@ public class RepeatOperationsStepFactoryBean extends AbstractStepFactoryBean {
ItemReader itemReader = getItemReader();
ItemWriter itemWriter = getItemWriter();
/*
* Since we are going to wrap these things with listener callbacks we
* need to register them here because the step will not know we did
* that.
*/
if (itemReader instanceof ItemStream) {
step.registerStream((ItemStream) itemReader);
}
if (itemReader instanceof StepExecutionListener) {
step.registerStepExecutionListener((StepExecutionListener) itemReader);
}
if (itemWriter instanceof ItemStream) {
step.registerStream((ItemStream) itemWriter);
}
if (itemWriter instanceof StepExecutionListener) {
step.registerStepExecutionListener((StepExecutionListener) itemWriter);
}
BatchListenerFactoryHelper helper = new BatchListenerFactoryHelper();
StepExecutionListener[] stepListeners = helper.getStepListeners(listeners);

View File

@@ -21,7 +21,6 @@ import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.exception.DefaultExceptionHandler;
@@ -178,22 +177,6 @@ public class SimpleStepFactoryBean extends AbstractStepFactoryBean {
ItemReader itemReader = getItemReader();
ItemWriter itemWriter = getItemWriter();
// Since we are going to wrap these things with listener callbacks we
// need to register them here because the step will not know we did
// that.
if (itemReader instanceof ItemStream) {
step.registerStream((ItemStream) itemReader);
}
if (itemReader instanceof StepExecutionListener) {
step.registerStepExecutionListener((StepExecutionListener) itemReader);
}
if (itemWriter instanceof ItemStream) {
step.registerStream((ItemStream) itemWriter);
}
if (itemWriter instanceof StepExecutionListener) {
step.registerStepExecutionListener((StepExecutionListener) itemWriter);
}
BatchListenerFactoryHelper helper = new BatchListenerFactoryHelper();
chunkOperations = new RepeatTemplate();