RESOLVED - BATCH-832: DefaultTransactionAttribute is inappropriate for TaskletStep
always rollback by default
This commit is contained in:
@@ -202,7 +202,13 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
* @return the transactionAttribute
|
||||
*/
|
||||
protected TransactionAttribute getTransactionAttribute() {
|
||||
return transactionAttribute!=null?transactionAttribute:new DefaultTransactionAttribute();
|
||||
return transactionAttribute!=null?transactionAttribute:new DefaultTransactionAttribute() {
|
||||
|
||||
public boolean rollbackOn(Throwable ex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -79,7 +79,13 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute();
|
||||
private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute() {
|
||||
|
||||
public boolean rollbackOn(Throwable ex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
private ItemHandler itemHandler;
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
assertEquals(1, stepExecution.getItemCount().intValue());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,6 +330,38 @@ public class SkipLimitStepFactoryBeanTests extends TestCase {
|
||||
assertEquals(4, count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Both checked and unchecked exceptions should cause rollback by default
|
||||
* i.e. EJB-style {@link DefaultTransactionAttribute} is inappropriate.
|
||||
*/
|
||||
public void testRollback() throws Exception {
|
||||
|
||||
factory.setSkippableExceptionClasses(new Class[] { Exception.class });
|
||||
factory.setSkipLimit(2);
|
||||
factory.setItemReader(new SkipReaderStub(StringUtils.commaDelimitedListToStringArray("1,2,3"), Collections.EMPTY_SET));
|
||||
factory.setItemWriter(new ItemWriterAdapter() {
|
||||
int count = 0;
|
||||
public void write(Object item) throws Exception {
|
||||
count++;
|
||||
if (count == 1) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
if (count == 2) {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
AbstractStep step = (AbstractStep) factory.getObject();
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
step.execute(stepExecution);
|
||||
|
||||
assertEquals(2, stepExecution.getSkipCount());
|
||||
assertEquals(2, stepExecution.getRollbackCount().intValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple item reader that supports skip functionality.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user