Fixed the way default java.util.Properteis are handled on restarts

This commit is contained in:
Michael Minella
2014-02-13 10:55:58 -06:00
parent a1ee097dd4
commit 6211c95d42
3 changed files with 34 additions and 4 deletions

View File

@@ -15,11 +15,13 @@
*/
package org.springframework.batch.core.jsr.configuration.xml;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.jsr.configuration.support.JsrExpressionParser;
@@ -121,7 +123,12 @@ public class JsrBeanDefinitionDocumentReader extends DefaultBeanDefinitionDocume
return new Properties();
}
jobParameters.putAll(properties);
Enumeration<?> propertyNames = properties.propertyNames();
while(propertyNames.hasMoreElements()) {
String curName = (String) propertyNames.nextElement();
jobParameters.put(curName, properties.getProperty(curName));
}
}
return jobParameters;

View File

@@ -18,6 +18,7 @@ package org.springframework.batch.core.jsr.launch;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -426,7 +427,6 @@ public class JsrJobOperator implements JobOperator, InitializingBean {
throws JobExecutionAlreadyCompleteException,
NoSuchJobExecutionException, JobExecutionNotMostRecentException,
JobRestartException, JobSecurityException {
org.springframework.batch.core.JobExecution previousJobExecution = jobExplorer.getJobExecution(executionId);
if (previousJobExecution == null) {
@@ -556,8 +556,13 @@ public class JsrJobOperator implements JobOperator, InitializingBean {
}
}
if (params != null && !params.isEmpty()) {
jobRestartProperties.putAll(params);
if (params != null) {
Enumeration<?> propertyNames = params.propertyNames();
while(propertyNames.hasMoreElements()) {
String curName = (String) propertyNames.nextElement();
jobRestartProperties.setProperty(curName, params.getProperty(curName));
}
}
return jobRestartProperties;

View File

@@ -468,6 +468,24 @@ public class JsrJobOperatorTests {
assertTrue(properties.getProperty("userKey1").equals("userVal1"));
}
@Test
public void testGetRestartJobParametersWithDefaults() {
JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator;
JobExecution jobExecution = new JobExecution(1L,
new JobParametersBuilder().addString("prevKey1", "prevVal1").addString("prevKey2", "prevVal2").toJobParameters());
Properties defaultProperties = new Properties();
defaultProperties.setProperty("prevKey2", "not value 2");
Properties userProperties = new Properties(defaultProperties);
Properties properties = jobOperator.getJobRestartProperties(userProperties, jobExecution);
assertTrue(properties.size() == 2);
assertTrue(properties.getProperty("prevKey1").equals("prevVal1"));
assertTrue("prevKey2 = " + properties.getProperty("prevKey2"), properties.getProperty("prevKey2").equals("not value 2"));
}
@Test
public void testNewJobParametersOverridePreviousRestartParameters() {
JsrJobOperator jobOperator = (JsrJobOperator) jsrJobOperator;