RESOLVED - issue BATCH-680: Allow override of Transaction Definition in get transaction in Item Oriented Step
Added transactionAttribute to ItemOrientedStep and the factory bean
This commit is contained in:
@@ -19,6 +19,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
@@ -30,6 +31,7 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.repository.NoSuchJobException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -104,10 +106,10 @@ public class SimpleExportedJobLauncher implements ExportedJobLauncher, Initializ
|
||||
int i = 0;
|
||||
for (Iterator iterator = execution.getStepExecutions().iterator(); iterator.hasNext();) {
|
||||
StepExecution stepExecution = (StepExecution) iterator.next();
|
||||
Properties statistics = stepExecution.getExecutionContext().getProperties();
|
||||
for (Iterator iter = statistics.keySet().iterator(); iter.hasNext();) {
|
||||
String key = (String) iter.next();
|
||||
result.setProperty(prefix + "step" + i + "." + key, statistics.getProperty(key));
|
||||
ExecutionContext statistics = stepExecution.getExecutionContext();
|
||||
for (Iterator iter = statistics.entrySet().iterator(); iter.hasNext();) {
|
||||
Entry entry = (Entry) iter.next();
|
||||
result.setProperty(prefix + "step" + i + "." + entry.getKey(), ""+entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.springframework.batch.item.validator.Validator;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -53,6 +54,8 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
private ItemWriter itemWriter;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private TransactionAttribute transactionAttribute;
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
@@ -185,6 +188,14 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the {@link TransactionAttribute}.
|
||||
* @param transactionAttribute the {@link TransactionAttribute} to set
|
||||
*/
|
||||
public void setTransactionAttribute(TransactionAttribute transactionAttribute) {
|
||||
this.transactionAttribute = transactionAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link Step} from the configuration provided.
|
||||
*
|
||||
@@ -209,6 +220,9 @@ public abstract class AbstractStepFactoryBean implements FactoryBean, BeanNameAw
|
||||
|
||||
step.setItemHandler(new SimpleItemHandler(itemReader, itemWriter));
|
||||
step.setTransactionManager(transactionManager);
|
||||
if (transactionAttribute!=null) {
|
||||
step.setTransactionAttribute(transactionAttribute);
|
||||
}
|
||||
step.setJobRepository(jobRepository);
|
||||
step.setStartLimit(startLimit);
|
||||
step.setAllowStartIfComplete(allowStartIfComplete);
|
||||
|
||||
@@ -40,7 +40,8 @@ import org.springframework.batch.repeat.RepeatOperations;
|
||||
import org.springframework.batch.repeat.support.RepeatTemplate;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.transaction.interceptor.DefaultTransactionAttribute;
|
||||
import org.springframework.transaction.interceptor.TransactionAttribute;
|
||||
|
||||
/**
|
||||
* Simple implementation of executing the step as a set of chunks, each chunk
|
||||
@@ -78,6 +79,8 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private TransactionAttribute transactionAttribute = new DefaultTransactionAttribute();
|
||||
|
||||
private ItemHandler itemHandler;
|
||||
|
||||
private StepExecutionSynchronizer synchronizer;
|
||||
@@ -98,7 +101,15 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
public void setTransactionManager(PlatformTransactionManager transactionManager) {
|
||||
this.transactionManager = transactionManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Public setter for the {@link TransactionAttribute}.
|
||||
* @param transactionAttribute the {@link TransactionAttribute} to set
|
||||
*/
|
||||
public void setTransactionAttribute(TransactionAttribute transactionAttribute) {
|
||||
this.transactionAttribute = transactionAttribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Public setter for the {@link ItemHandler}.
|
||||
*
|
||||
@@ -230,7 +241,7 @@ public class ItemOrientedStep extends AbstractStep {
|
||||
|
||||
ExitStatus exitStatus = ExitStatus.CONTINUABLE;
|
||||
|
||||
TransactionStatus transaction = transactionManager.getTransaction(new DefaultTransactionDefinition());
|
||||
TransactionStatus transaction = transactionManager.getTransaction(transactionAttribute);
|
||||
|
||||
try {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user