From e493bd5cebbabd19dad66376e8d524198c67688f Mon Sep 17 00:00:00 2001 From: dhgarrette Date: Fri, 13 Mar 2009 20:18:26 +0000 Subject: [PATCH] BATCH-1131: *Move "transaction-attribute" attribute from to as BATCH-1152: *Allow comma and newline as delimiters in exception lists in namespace --- .../configuration/xml/AbstractStepParser.java | 22 ++++++++-- .../xml/TaskletElementParser.java | 31 +++++++------- .../core/step/item/SimpleStepFactoryBean.java | 19 +++++++++ .../configuration/xml/spring-batch-2.0.xsd | 42 ++++++++++++------- ...tepParserBadRetryListenerTests-context.xml | 5 ++- ...epParserTaskletAttributesTests-context.xml | 5 ++- ...erantProcessTaskJobParserTests-context.xml | 9 +++- .../src/main/resources/jobs/tradeJob.xml | 9 ++-- 8 files changed, 99 insertions(+), 43 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java index 455e3b817..2767d6712 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/AbstractStepParser.java @@ -15,6 +15,7 @@ */ package org.springframework.batch.core.configuration.xml; +import java.util.Arrays; import java.util.List; import org.springframework.batch.core.step.tasklet.TaskletStep; @@ -76,7 +77,7 @@ public abstract class AbstractStepParser { setUpBeanDefinition(element, bd, parserContext, jobRepositoryRef); } return bd; - + } /** @@ -84,8 +85,8 @@ public abstract class AbstractStepParser { * @param taskletRef * @param parserContext */ - private AbstractBeanDefinition parseTaskletRef(Element stepElement, String taskletRef, - ParserContext parserContext, String jobRepositoryRef) { + private AbstractBeanDefinition parseTaskletRef(Element stepElement, String taskletRef, ParserContext parserContext, + String jobRepositoryRef) { GenericBeanDefinition bd = new GenericBeanDefinition(); bd.setBeanClass(TaskletStep.class); @@ -99,6 +100,7 @@ public abstract class AbstractStepParser { } + @SuppressWarnings("unchecked") protected void setUpBeanDefinition(Element stepElement, AbstractBeanDefinition bd, ParserContext parserContext, String jobRepositoryRef) { checkStepAttributes(stepElement, bd); @@ -110,6 +112,20 @@ public abstract class AbstractStepParser { RuntimeBeanReference transactionManagerBeanRef = new RuntimeBeanReference(transactionManagerRef); bd.getPropertyValues().addPropertyValue("transactionManager", transactionManagerBeanRef); + Element child = DomUtils.getChildElementByTagName(stepElement, "transaction-attributes"); + if (child != null) { + String attributes = DomUtils.getTextValue(child); + if (StringUtils.hasLength(attributes)) { + String[] attributesArray = StringUtils.tokenizeToStringArray(attributes, ",\n"); + if (attributesArray.length > 0) { + ManagedList managedList = new ManagedList(); + managedList.setMergeEnabled(Boolean.valueOf(child.getAttribute("merge"))); + managedList.addAll(Arrays.asList(attributesArray)); + bd.getPropertyValues().addPropertyValue("transactionAttributeList", managedList); + } + } + } + handleListenersElement(stepElement, bd, parserContext); bd.setRole(BeanDefinition.ROLE_SUPPORT); diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletElementParser.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletElementParser.java index af2a7a34d..8f1c0f978 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletElementParser.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/xml/TaskletElementParser.java @@ -146,11 +146,6 @@ public class TaskletElementParser { propertyValues.addPropertyValue("cacheCapacity", cacheCapacity); } - String transactionAttribute = element.getAttribute("transaction-attribute"); - if (StringUtils.hasText(transactionAttribute)) { - propertyValues.addPropertyValue("transactionAttribute", transactionAttribute); - } - if (StringUtils.hasText(isReaderTransactionalQueue)) { if (isFaultTolerant) { propertyValues.addPropertyValue("isReaderTransactionalQueue", isReaderTransactionalQueue); @@ -198,19 +193,21 @@ public class TaskletElementParser { Element child = DomUtils.getChildElementByTagName(element, subElementName); if (child != null) { String exceptions = DomUtils.getTextValue(child); - if (StringUtils.hasLength(exceptions) && (isFaultTolerant || isAbstract)) { - String[] exceptionArray = StringUtils.tokenizeToStringArray(StringUtils.delete(exceptions, ","), "\n"); - if (exceptionArray.length > 0) { - ManagedList managedList = new ManagedList(); - managedList.setMergeEnabled(Boolean.valueOf(child.getAttribute("merge"))); - managedList.addAll(Arrays.asList(exceptionArray)); - bd.getPropertyValues().addPropertyValue(propertyName, managedList); + if (StringUtils.hasLength(exceptions)) { + if (isFaultTolerant || isAbstract) { + String[] exceptionArray = StringUtils.tokenizeToStringArray(exceptions, ",\n"); + if (exceptionArray.length > 0) { + ManagedList managedList = new ManagedList(); + managedList.setMergeEnabled(Boolean.valueOf(child.getAttribute("merge"))); + managedList.addAll(Arrays.asList(exceptionArray)); + bd.getPropertyValues().addPropertyValue(propertyName, managedList); + } + } + else { + parserContext.getReaderContext().error( + subElementName + " can only be specified for fault-tolerant " + + "configurations providing skip-limit, retry-limit or cache-capacity", element); } - } - else { - parserContext.getReaderContext().error( - subElementName + " can only be specified for fault-tolerant " - + "configurations providing skip-limit, retry-limit or cache-capacity", element); } } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java index 1ed7524e5..4521449dd 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleStepFactoryBean.java @@ -15,6 +15,9 @@ */ package org.springframework.batch.core.step.item; +import java.beans.PropertyEditor; +import java.util.List; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.ChunkListener; @@ -45,7 +48,9 @@ import org.springframework.core.task.TaskExecutor; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.interceptor.DefaultTransactionAttribute; import org.springframework.transaction.interceptor.TransactionAttribute; +import org.springframework.transaction.interceptor.TransactionAttributeEditor; import org.springframework.util.Assert; +import org.springframework.util.StringUtils; /** * Most common configuration options for simple steps should be found here. Use @@ -269,6 +274,20 @@ public class SimpleStepFactoryBean implements FactoryBean, BeanNameAware { this.transactionManager = transactionManager; } + /** + * Public setter for the {@link TransactionAttribute}. + * + * @param transactionAttributeList A list of all the transaction attributes + * to set + */ + public void setTransactionAttributeList(List transactionAttributeList) { + String[] stringArray = transactionAttributeList.toArray(new String[0]); + String attributeString = StringUtils.arrayToCommaDelimitedString(stringArray); + PropertyEditor editor = new TransactionAttributeEditor(); + editor.setAsText(attributeString); + this.setTransactionAttribute((TransactionAttribute) editor.getValue()); + } + /** * Public setter for the {@link TransactionAttribute}. * @param transactionAttribute the {@link TransactionAttribute} to set diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd index 5676b58ab..3ea7b1a78 100644 --- a/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/configuration/xml/spring-batch-2.0.xsd @@ -181,8 +181,7 @@ Defines a stage in job processing backed by a Step. The id attribute must be specified and - can - match the id of a bean definition + can match the id of a bean definition for a Step. If it does not, then you must provide a tasklet definition or a reference to a Step defined elsewhere. @@ -255,8 +254,7 @@ The decider is a reference to a JobExecutionDecider that can produce a status to base - the - next transition on. + the next transition on. @@ -295,6 +293,7 @@ + @@ -305,6 +304,7 @@ + @@ -361,7 +361,8 @@ @@ -376,7 +377,8 @@ @@ -391,7 +393,8 @@ @@ -466,14 +469,6 @@ ]]> - - - - - + + + + + + + + + + + + If this attribute is specified, then there should be no nested transition elements]]> diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml index fd09e41e2..01026d37d 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserBadRetryListenerTests-context.xml @@ -11,7 +11,6 @@ @@ -24,6 +23,10 @@ org.springframework.dao.DataIntegrityViolationException, + + PROPAGATION_REQUIRED, ISOLATION_DEFAULT, timeout_10, + -org.springframework.dao.DataIntegrityViolationException + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml index 5a9d9b0fc..c9d4b95c6 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepParserTaskletAttributesTests-context.xml @@ -9,7 +9,6 @@ @@ -25,6 +24,10 @@ org.springframework.dao.DataIntegrityViolationException + + PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_10 + -org.springframework.dao.DataIntegrityViolationException + diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests-context.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests-context.xml index 30019d02f..bc3752a78 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests-context.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/configuration/xml/StepWithFaultTolerantProcessTaskJobParserTests-context.xml @@ -11,7 +11,6 @@ @@ -22,9 +21,15 @@ - org.springframework.dao.DataIntegrityViolationException, + org.springframework.dao.DataIntegrityViolationException + + PROPAGATION_REQUIRED + ISOLATION_DEFAULT + timeout_10 + -org.springframework.dao.DataIntegrityViolationException + diff --git a/spring-batch-samples/src/main/resources/jobs/tradeJob.xml b/spring-batch-samples/src/main/resources/jobs/tradeJob.xml index d4855f52d..c212cffff 100644 --- a/spring-batch-samples/src/main/resources/jobs/tradeJob.xml +++ b/spring-batch-samples/src/main/resources/jobs/tradeJob.xml @@ -17,12 +17,15 @@ + commit-interval="1"> - + + + PROPAGATION_REQUIRED + ISOLATION_READ_COMMITTED +