Remove RepeatOperationsStep

This commit is contained in:
dsyer
2008-02-25 17:54:36 +00:00
parent 949324c751
commit 85806724a5
7 changed files with 9 additions and 208 deletions

View File

@@ -1,69 +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;
import org.springframework.batch.core.domain.JobInterruptedException;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.RepeatOperations;
/**
* A {@link Step} implementation that allows full configuration of the
* {@link RepeatOperations} that will be used in the chunk (inner loop).
* <br/>
*
* This class may be obsolete soon.
*
* @author Lucas Ward
* @author Dave Syer
* @author Ben Hale
*/
public class RepeatOperationsStep extends ItemOrientedStep {
private volatile RepeatOperations chunkOperations;
private volatile RepeatOperations stepOperations;
/**
* Public setter for the chunkOperations.
*
* @param chunkOperations the repeatOperations to set
*/
public void setChunkOperations(RepeatOperations chunkOperations) {
this.chunkOperations = chunkOperations;
}
/**
* Public setter for the {@link RepeatOperations} property.
*
* @param stepOperations the stepOperations to set
*/
public void setStepOperations(RepeatOperations stepOperations) {
this.stepOperations = stepOperations;
}
public void execute(StepExecution stepExecution) throws JobInterruptedException, BatchCriticalException {
if (stepOperations != null) {
super.setStepOperations(stepOperations);
}
if (chunkOperations != null) {
super.setChunkOperations(chunkOperations);
}
super.execute(stepExecution);
}
}

View File

@@ -33,7 +33,7 @@ import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.MapJobDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.step.AbstractStep;
import org.springframework.batch.execution.step.RepeatOperationsStep;
import org.springframework.batch.execution.step.ItemOrientedStep;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.batch.item.reader.ListItemReader;
@@ -75,8 +75,8 @@ public class SimpleJobTests extends TestCase {
return getStep(new String[] { arg0, arg1 });
}
private RepeatOperationsStep getStep(String[] args) throws Exception {
RepeatOperationsStep step = new RepeatOperationsStep();
private ItemOrientedStep getStep(String[] args) throws Exception {
ItemOrientedStep step = new ItemOrientedStep();
List items = TransactionAwareProxyFactory.createTransactionalList();
items.addAll(Arrays.asList(args));
provider = new ListItemReader(items);
@@ -132,7 +132,7 @@ public class SimpleJobTests extends TestCase {
* is recovered ("skipped") on the second attempt (see retry policy
* definition above)...
*/
RepeatOperationsStep step = getStep(new String[] { "foo", "bar", "spam" });
ItemOrientedStep step = getStep(new String[] { "foo", "bar", "spam" });
// Tasklet module = getTasklet(new String[] { "foo", "bar", "spam" });

View File

@@ -1,125 +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 java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobSupport;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepSupport;
import org.springframework.batch.execution.step.ItemOrientedStep;
import org.springframework.batch.execution.step.RepeatOperationsStep;
import org.springframework.batch.item.reader.AbstractItemReader;
import org.springframework.batch.item.reader.ItemReaderAdapter;
import org.springframework.batch.item.writer.AbstractItemWriter;
import org.springframework.batch.item.writer.ItemWriterAdapter;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.interceptor.RepeatListenerSupport;
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
import org.springframework.batch.repeat.support.RepeatTemplate;
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
/**
* @author Dave Syer
*
*/
public class RepeatOperationsStepTests extends TestCase {
RepeatOperationsStep repeatStep = new RepeatOperationsStep();
protected void setUp() throws Exception {
super.setUp();
repeatStep.setItemReader(new ItemReaderAdapter());
repeatStep.setItemWriter(new ItemWriterAdapter());
}
public void testSuccessfulRepeatOperationsHolder() throws Exception {
RepeatTemplate repeatTemplate = new RepeatTemplate();
final List list = new ArrayList();
repeatTemplate.setListener(new RepeatListenerSupport() {
public void onError(RepeatContext context, Throwable e) {
list.add(e);
}
});
repeatTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
ItemOrientedStep configuration = new ItemOrientedStep();
configuration.setItemReader(new AbstractItemReader(){
public Object read() throws Exception {
throw new NullPointerException();
}});
configuration.setItemWriter(new AbstractItemWriter(){
public void write(Object item) throws Exception {
}});
configuration.setChunkOperations(repeatTemplate);
configuration.setJobRepository(new JobRepositorySupport());
configuration.setTransactionManager(new ResourcelessTransactionManager());
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")),
new Long(12)));
configuration.afterPropertiesSet();
try {
configuration.execute(stepExecution);
fail("Expected RuntimeException");
} catch (NullPointerException e) {
// expected
}
assertEquals(1, list.size());
}
public void testSuccessfulRepeatOperationsHolderWithStepOperations() throws Exception {
RepeatTemplate chunkTemplate = new RepeatTemplate();
final List list = new ArrayList();
chunkTemplate.setListener(new RepeatListenerSupport() {
public void before(RepeatContext context) {
list.add(context);
}
});
chunkTemplate.setCompletionPolicy(new SimpleCompletionPolicy(2));
RepeatTemplate stepTemplate = new RepeatTemplate();
final List steps = new ArrayList();
stepTemplate.setListener(new RepeatListenerSupport() {
public void before(RepeatContext context) {
steps.add(context);
}
});
stepTemplate.setCompletionPolicy(new SimpleCompletionPolicy(1));
RepeatOperationsStep configuration = new RepeatOperationsStep();
configuration.setItemReader(new AbstractItemReader(){
public Object read() throws Exception {
return new Object();
}});
configuration.setItemWriter(new AbstractItemWriter(){
public void write(Object item) throws Exception {
}});
configuration.setChunkOperations(chunkTemplate);
configuration.setStepOperations(stepTemplate);
configuration.setJobRepository(new JobRepositorySupport());
configuration.setTransactionManager(new ResourcelessTransactionManager());
StepExecution stepExecution = new StepExecution(new StepSupport("stepName"), new JobExecution(new JobInstance(new Long(0L), new JobParameters(), new JobSupport("testJob")),
new Long(12)));
configuration.afterPropertiesSet();
configuration.execute(stepExecution);
assertEquals(2, list.size());
assertEquals(1, steps.size());
}
}

View File

@@ -32,7 +32,7 @@ import org.springframework.batch.execution.repository.dao.JobInstanceDao;
import org.springframework.batch.execution.repository.dao.MapJobDao;
import org.springframework.batch.execution.repository.dao.MapStepDao;
import org.springframework.batch.execution.repository.dao.StepExecutionDao;
import org.springframework.batch.execution.step.RepeatOperationsStep;
import org.springframework.batch.execution.step.ItemOrientedStep;
import org.springframework.batch.item.reader.AbstractItemReader;
import org.springframework.batch.item.reader.ItemReaderAdapter;
import org.springframework.batch.item.writer.AbstractItemWriter;
@@ -50,14 +50,14 @@ public class StepExecutorInterruptionTests extends TestCase {
private StepExecutionDao stepExecutionDao = new MapStepDao();
private RepeatOperationsStep step;
private ItemOrientedStep step;
public void setUp() throws Exception {
jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao);
JobSupport jobConfiguration = new JobSupport();
step = new RepeatOperationsStep();
step = new ItemOrientedStep();
step.setName("stepName");
jobConfiguration.addStep(step);
jobConfiguration.setBeanName("testJob");