OPEN - issue BATCH-304: BatchCommandLineLauncher simplified and rename

http://jira.springframework.org/browse/BATCH-304

First part of JobParameters and retirement of JobIdentifier.  Tests are borken, but not by these changes so I figure I have to get them in!
This commit is contained in:
dsyer
2008-01-24 08:07:20 +00:00
parent 21f23e05d1
commit 5a8635a32e
65 changed files with 427 additions and 625 deletions

View File

@@ -1,65 +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.bootstrap.support;
import java.beans.PropertyEditorSupport;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.runtime.JobIdentifierFactory;
import org.springframework.batch.core.runtime.SimpleJobIdentifierFactory;
/**
* Simple adapter for a {@link JobIdentifierFactory} that can be used to convert
* from a {@link Job} name to a {@link JobIdentifier}.
*
* @author Dave Syer
*
*/
public class JobIdentifierPropertyEditor extends PropertyEditorSupport {
private JobIdentifierFactory jobIdentifierFactory = new SimpleJobIdentifierFactory();
/**
* Public setter for the {@link JobIdentifierFactory}.
* @param jobIdentifierFactory the jobIdentifierFactory to set
*/
public void setJobIdentifierFactory(JobIdentifierFactory jobIdentifierFactory) {
this.jobIdentifierFactory = jobIdentifierFactory;
}
/**
* Accept name of {@link Job} and create a {@link JobIdentifier}.
*
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
*/
public void setAsText(String text) throws IllegalArgumentException {
setValue(jobIdentifierFactory.getJobIdentifier(text));
}
/**
* Extract the name from the {@link JobIdentifier}.
*
* @see java.beans.PropertyEditorSupport#getAsText()
*/
public String getAsText() {
JobIdentifier identifier = (JobIdentifier) getValue();
if (identifier == null) {
return null;
}
return identifier.getName();
}
}

View File

@@ -0,0 +1,87 @@
/*
* 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.bootstrap.support;
import java.beans.PropertyEditorSupport;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.util.StringUtils;
/**
* Factory for {@link JobParameters} instances using a simple naming convention
* for property keys. Key names ending with "(<type>)" where type is one
* of string, date, long are converted to the corresponding type. The default
* type is string. E.g.
*
* <pre>
* schedule.date(date)=2007/12/11
* department.id(long)=2345
* </pre>
*
* The literal values are converted to the correct type using the default Spring
* strategies, augmented if necessary by the custom editors provided.
*
* TODO: finish this (only supports Strings so far).
*
* @author Dave Syer
*
*/
public class JobParametersPropertyEditor extends PropertyEditorSupport {
/**
* Accept properties in the form of name=value pairs, delimited by either
* comma or new line (or both) and create {@link JobParameters}.
*
* @see java.beans.PropertyEditorSupport#setAsText(java.lang.String)
*/
public void setAsText(String text) throws IllegalArgumentException {
JobParametersBuilder builder = new JobParametersBuilder();
Properties properties = StringUtils.splitArrayElementsIntoProperties(StringUtils.tokenizeToStringArray(text,
",\n"), "=");
for (Iterator iterator = properties.keySet().iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
key = StringUtils.tokenizeToStringArray(key, "(")[0];
builder.addString(key, properties.getProperty(key));
}
setValue(builder.toJobParameters());
}
/**
* Extract the name from the {@link JobIdentifier}.
*
* @see java.beans.PropertyEditorSupport#getAsText()
*/
public String getAsText() {
JobParameters params = (JobParameters) getValue();
if (params == null) {
return null;
}
List builder = new ArrayList();
Map map = params.getStringParameters();
for (Iterator iterator = map.keySet().iterator(); iterator.hasNext();) {
String key = (String) iterator.next();
builder.add(key+"="+map.get(key));
}
return StringUtils.collectionToCommaDelimitedString(builder);
}
}

View File

@@ -23,34 +23,32 @@ import java.util.Iterator;
import java.util.Properties;
import java.util.Map.Entry;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobInstancePropertiesBuilder;
import org.springframework.batch.core.domain.JobInstancePropertiesFactory;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.runtime.JobParametersFactory;
import org.springframework.util.Assert;
/**
* @author Lucas Ward
*
*/
public class ScheduledJobInstancePropertiesFactory implements
JobInstancePropertiesFactory {
public class ScheduledJobParametersFactory implements
JobParametersFactory {
public static String SCHEDULE_DATE_KEY = "schedule.date";
public static String JOB_KEY = "job.key";
private DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
/* (non-Javadoc)
* @see org.springframework.batch.core.domain.JobInstancePropertiesFactory#getProperties(java.lang.String[])
* @see org.springframework.batch.core.runtime.JobParametersFactory#getJobParameters(java.util.Properties)
*/
public JobInstanceProperties getProperties(String[] args) {
public JobParameters getJobParameters(Properties props) {
Assert.notNull(args, "Factory arguments must not be null.");
Assert.notNull(props, "Factory arguments must not be null.");
JobInstancePropertiesBuilder propertiesBuilder = new JobInstancePropertiesBuilder();
JobParametersBuilder propertiesBuilder = new JobParametersBuilder();
Properties props = parseArgs(args);
for(Iterator it = props.entrySet().iterator(); it.hasNext();){
Entry entry = (Entry)it.next();
if(entry.getKey().equals(SCHEDULE_DATE_KEY)){
@@ -71,23 +69,10 @@ public class ScheduledJobInstancePropertiesFactory implements
return propertiesBuilder.toJobParameters();
}
private Properties parseArgs(String[] args){
Properties props = new Properties();
for(int i = 0; i < args.length; i++){
String property = args[i];
int equalsIndex = property.indexOf('=');
if(equalsIndex == -1){
throw new IllegalArgumentException("JobInstacePropertes argument invalid: [" + property + "]");
}
String key = property.substring(0, equalsIndex);
props.put(key, property.substring(equalsIndex + 1));
}
return props;
}
/**
* Public setter for injecting a date format.
* @param dateFormat a {@link DateFormat}, defaults to "yyyy/MM/dd"
*/
public void setDateFormat(DateFormat dateFormat) {
this.dateFormat = dateFormat;
}

View File

@@ -19,11 +19,10 @@ package org.springframework.batch.execution.bootstrap.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobLocator;
import org.springframework.batch.core.domain.NoSuchJobException;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.runtime.JobIdentifierFactory;
import org.springframework.batch.execution.launch.JobLauncher;
import org.springframework.batch.execution.step.simple.SimpleExitCodeExceptionClassifier;
import org.springframework.batch.repeat.ExitStatus;
@@ -225,7 +224,7 @@ public class SimpleCommandLineJobRunner {
jobName = defaultJobName;
}
status = launcher.run(jobLocator.getJob(jobName), new JobInstanceProperties()).getExitStatus();
status = launcher.run(jobLocator.getJob(jobName), new JobParameters()).getExitStatus();
}
catch (NoSuchJobException e) {
logger.fatal("Could not locate JobConfiguration \"" + jobName + "\"", e);

View File

@@ -17,7 +17,7 @@ package org.springframework.batch.execution.launch;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
/**
@@ -44,7 +44,7 @@ public interface JobLauncher {
* by the properties already has an execution running. Throws
* IllegalArgumentException if the job or jobInstanceProperties are null.
*/
public JobExecution run(Job job, JobInstanceProperties jobParameters)
public JobExecution run(Job job, JobParameters jobParameters)
throws JobExecutionAlreadyRunningException;
}

View File

@@ -19,7 +19,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobRepository;
@@ -72,28 +72,28 @@ public class SimpleJobLauncher implements JobLauncher, InitializingBean{
* @return JobExecutionAlreadyRunningException if the JobInstance already exists and has
* an execution already running.
*/
public JobExecution run(final Job job, final JobInstanceProperties jobInstanceProperties)
public JobExecution run(final Job job, final JobParameters jobParameters)
throws JobExecutionAlreadyRunningException {
Assert.notNull(job, "The Job must not be null.");
Assert.notNull(jobInstanceProperties, "The JobInstanceProperties must not be null.");
Assert.notNull(jobParameters, "The JobInstanceProperties must not be null.");
final JobExecution jobExecution = jobRepository.createJobExecution(job, jobInstanceProperties);
final JobExecution jobExecution = jobRepository.createJobExecution(job, jobParameters);
taskExecutor.execute(new Runnable(){
public void run() {
try{
logger.info("Job: [" + job + "] launched with the following parameters: [" + jobInstanceProperties + "]");
logger.info("Job: [" + job + "] launched with the following parameters: [" + jobParameters + "]");
ExitStatus exitStatus = jobExecutor.run(job, jobExecution);
//shouldn't need to set the exit status like this, I'm leaving it to make the latest change easier
jobExecution.setExitStatus(exitStatus);
logger.info("Job: [" + job + "] completed successfully with the following parameters: ["
+ jobInstanceProperties + "]");
+ jobParameters + "]");
}
catch(Throwable t){
logger.info("Job: [" + job + "] failed with the following parameters: ["
+ jobInstanceProperties + "]", t);
+ jobParameters + "]", t);
rethrow(t);
}
}

View File

@@ -25,7 +25,7 @@ import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -125,7 +125,7 @@ public class SimpleJobRepository implements JobRepository {
* platform does not support the higher isolation levels).
* </p>
*
* @see JobRepository#createJobExecution(Job, JobInstanceProperties)
* @see JobRepository#createJobExecution(Job, JobParameters)
*
* @throws BatchRestartException if more than one JobInstance if found or if
* JobInstance.getJobExecutionCount() is greater than Job.getStartLimit()
@@ -133,11 +133,11 @@ public class SimpleJobRepository implements JobRepository {
* for the given {@link JobIdentifier} that is already running
*
*/
public JobExecution createJobExecution(Job job, JobInstanceProperties jobInstanceProperties)
public JobExecution createJobExecution(Job job, JobParameters jobParameters)
throws JobExecutionAlreadyRunningException {
Assert.notNull(job, "Job must not be null.");
Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null.");
Assert.notNull(jobParameters, "JobInstanceProperties must not be null.");
List jobs = new ArrayList();
JobInstance jobInstance;
@@ -154,7 +154,7 @@ public class SimpleJobRepository implements JobRepository {
* thread or process will block until this transaction has finished.
*/
jobs = jobDao.findJobInstances(job.getName(), jobInstanceProperties);
jobs = jobDao.findJobInstances(job.getName(), jobParameters);
}
if (jobs.size() == 1) {
@@ -176,7 +176,7 @@ public class SimpleJobRepository implements JobRepository {
}
else if (jobs.size() == 0) {
// no job found, create one
jobInstance = createJobInstance(job, jobInstanceProperties);
jobInstance = createJobInstance(job, jobParameters);
}
else {
// More than one job found, throw exception
@@ -284,9 +284,9 @@ public class SimpleJobRepository implements JobRepository {
* calling {@link JobDao#createJob(JobRuntimeInformation)} and then it's
* list of StepConfigurations is passed to the createSteps method.
*/
private JobInstance createJobInstance(Job job, JobInstanceProperties jobInstanceProperties) {
private JobInstance createJobInstance(Job job, JobParameters jobParameters) {
JobInstance jobInstance = jobDao.createJobInstance(job.getName(), jobInstanceProperties);
JobInstance jobInstance = jobDao.createJobInstance(job.getName(), jobParameters);
jobInstance.setStepInstances(createStepInstances(jobInstance, job.getSteps()));
return jobInstance;
}

View File

@@ -31,7 +31,7 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.InitializingBean;
@@ -120,25 +120,25 @@ public class JdbcJobDao implements JobDao, InitializingBean {
* @throws IllegalArgumentException
* if any {@link JobIdentifier} fields are null.
*/
public JobInstance createJobInstance(String jobName, JobInstanceProperties jobInstanceProperties) {
public JobInstance createJobInstance(String jobName, JobParameters jobParameters) {
Assert.notNull(jobName, "Job Name must not be null.");
Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null.");
Assert.notNull(jobParameters, "JobInstanceProperties must not be null.");
Long jobId = new Long(jobIncrementer.nextLongValue());
Object[] parameters = new Object[] { jobId, jobName, createJobKey(jobInstanceProperties) };
Object[] parameters = new Object[] { jobId, jobName, createJobKey(jobParameters) };
jdbcTemplate.update(getCreateJobQuery(), parameters, new int[] {
Types.INTEGER, Types.VARCHAR, Types.VARCHAR});
insertJobParameters(jobId, jobInstanceProperties);
insertJobParameters(jobId, jobParameters);
JobInstance jobInstance = new JobInstance(jobId, jobInstanceProperties);
JobInstance jobInstance = new JobInstance(jobId, jobParameters);
return jobInstance;
}
private String createJobKey(JobInstanceProperties jobInstanceProperties){
private String createJobKey(JobParameters jobParameters){
Map props = jobInstanceProperties.getParameters();
Map props = jobParameters.getParameters();
StringBuilder stringBuilder = new StringBuilder();
for(Iterator it = props.entrySet().iterator();it.hasNext();){
Entry entry = (Entry)it.next();
@@ -166,18 +166,18 @@ public class JdbcJobDao implements JobDao, InitializingBean {
* @throws IllegalArgumentException
* if any {@link JobIdentifier} fields are null.
*/
public List findJobInstances(final String jobName, final JobInstanceProperties jobInstanceProperties) {
public List findJobInstances(final String jobName, final JobParameters jobParameters) {
Assert.notNull(jobName, "Job Name must not be null.");
Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null.");
Assert.notNull(jobParameters, "JobInstanceProperties must not be null.");
Object[] parameters = new Object[] { jobName,
createJobKey(jobInstanceProperties) };
createJobKey(jobParameters) };
RowMapper rowMapper = new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
JobInstance job = new JobInstance(new Long(rs.getLong(1)), jobInstanceProperties);
JobInstance job = new JobInstance(new Long(rs.getLong(1)), jobParameters);
job.setStatus(BatchStatus.getStatus(rs.getString(2)));
return job;
@@ -242,7 +242,7 @@ public class JdbcJobDao implements JobDao, InitializingBean {
* Convenience method that inserts all parameters from the provided JobParameters.
*
*/
private void insertJobParameters(Long jobId, JobInstanceProperties jobParameters){
private void insertJobParameters(Long jobId, JobParameters jobParameters){
Map parameters = jobParameters.getStringParameters();

View File

@@ -21,7 +21,7 @@ import java.util.List;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
/**
* Data Access Object for jobs.
@@ -40,7 +40,7 @@ public interface JobDao {
* @param jobIdentifier
* @return Job
*/
public JobInstance createJobInstance(String jobName, JobInstanceProperties jobInstanceProperties);
public JobInstance createJobInstance(String jobName, JobParameters jobParameters);
/**
* Find all jobs that match the given JobIdentifier. If no jobs matching the
@@ -50,7 +50,7 @@ public interface JobDao {
* @return List of {@link JobInstance} objects matching
* {@link JobIdentifier}
*/
public List findJobInstances(String jobName, JobInstanceProperties jobInstanceProperties);
public List findJobInstances(String jobName, JobParameters jobParameters);
/**
* Update an existing Job.

View File

@@ -25,7 +25,7 @@ import java.util.Set;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.support.transaction.TransactionAwareProxyFactory;
public class MapJobDao implements JobDao {
@@ -45,19 +45,19 @@ public class MapJobDao implements JobDao {
executionsById.clear();
}
public JobInstance createJobInstance(String jobName, JobInstanceProperties jobInstanceProperties) {
JobInstance jobInstance = new JobInstance(new Long(currentId++), jobInstanceProperties);
public JobInstance createJobInstance(String jobName, JobParameters jobParameters) {
JobInstance jobInstance = new JobInstance(new Long(currentId++), jobParameters);
jobInstance.setJob(new Job(jobName));
jobsById.put(jobInstance.getId(), jobInstance);
return jobInstance;
}
public List findJobInstances(String jobName, JobInstanceProperties jobInstanceProperties) {
public List findJobInstances(String jobName, JobParameters jobParameters) {
List list = new ArrayList();
for (Iterator iter = jobsById.values().iterator(); iter.hasNext();) {
JobInstance jobInstance = (JobInstance) iter.next();
if (jobInstance.getJobName().equals(jobName) && jobInstance.getJobInstanceProperties().equals(jobInstanceProperties)) {
if (jobInstance.getJobName().equals(jobName) && jobInstance.getJobInstanceProperties().equals(jobParameters)) {
list.add(jobInstance);
}
}

View File

@@ -16,8 +16,8 @@
package org.springframework.batch.execution.runtime;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobInstancePropertiesBuilder;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
/**
@@ -48,10 +48,10 @@ public class DefaultJobIdentifier extends SimpleJobIdentifier implements
* @param name the name for the job
*/
public DefaultJobIdentifier(String name, String key) {
this(name, new JobInstancePropertiesBuilder().addString(JOB_KEY, key).toJobParameters());
this(name, new JobParametersBuilder().addString(JOB_KEY, key).toJobParameters());
}
public DefaultJobIdentifier(String name, JobInstanceProperties parameters){
public DefaultJobIdentifier(String name, JobParameters parameters){
super(name, parameters);
}

View File

@@ -1,43 +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.runtime;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.runtime.JobIdentifierFactory;
/**
* {@link JobIdentifierFactory} for creating {@link DefaultJobIdentifierFactory}
* instances.
*
* @author Dave Syer
*
*/
public class DefaultJobIdentifierFactory implements JobIdentifierFactory {
protected String key = "key";
public JobIdentifier getJobIdentifier(String name) {
DefaultJobIdentifier runtimeInformation = new DefaultJobIdentifier(name, key);
return runtimeInformation;
}
public void setJobKey(String key) {
this.key = key;
}
}

View File

@@ -19,7 +19,7 @@ package org.springframework.batch.execution.runtime;
import java.util.Date;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstancePropertiesBuilder;
import org.springframework.batch.core.domain.JobParametersBuilder;
/**
* Convenient {@link JobIdentifier} implementation that identifies itself by a
@@ -59,7 +59,7 @@ public class ScheduledJobIdentifier extends DefaultJobIdentifier implements JobI
* @param scheduleDate a timestamp
*/
public ScheduledJobIdentifier(String name, Date scheduleDate) {
super(name, new JobInstancePropertiesBuilder().addDate(SCHEDULE_DATE, scheduleDate).toJobParameters());
super(name, new JobParametersBuilder().addDate(SCHEDULE_DATE, scheduleDate).toJobParameters());
}
/**
@@ -70,7 +70,7 @@ public class ScheduledJobIdentifier extends DefaultJobIdentifier implements JobI
* @param scheduleDate a timestamp
*/
public ScheduledJobIdentifier(String name, String key, Date scheduleDate) {
super(name, new JobInstancePropertiesBuilder().addString(ScheduledJobIdentifier.JOB_KEY, key).addDate(
super(name, new JobParametersBuilder().addString(ScheduledJobIdentifier.JOB_KEY, key).addDate(
SCHEDULE_DATE, scheduleDate).toJobParameters());
}

View File

@@ -1,62 +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.runtime;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.runtime.JobIdentifierFactory;
/**
* {@link JobIdentifierFactory} for creating {@link ScheduledJobIdentifier}
* instances.
*
* @author Dave Syer
*
*/
public class ScheduledJobIdentifierFactory extends DefaultJobIdentifierFactory implements JobIdentifierFactory {
private Date scheduleDate;
private DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
public JobIdentifier getJobIdentifier(String name) {
initDate();
ScheduledJobIdentifier identifier = new ScheduledJobIdentifier(name, key, scheduleDate);
return identifier;
}
public void setScheduleDate(Date scheduleDate) {
this.scheduleDate = scheduleDate;
}
public void setDateFormat(DateFormat dateFormat){
this.dateFormat = dateFormat;
}
private void initDate() {
try {
scheduleDate = dateFormat.parse("19700101");
} catch (ParseException e) {
throw new IllegalStateException("Could not parse trivial date 19700101");
}
}
}

View File

@@ -1,62 +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.bootstrap.support;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.runtime.SimpleJobIdentifierFactory;
import junit.framework.TestCase;
/**
* @author Dave Syer
*
*/
public class JobIdentifierPropertyEditorTests extends TestCase {
private JobIdentifierPropertyEditor editor = new JobIdentifierPropertyEditor();
/**
* Test method for {@link org.springframework.batch.execution.bootstrap.support.JobIdentifierPropertyEditor#setJobIdentifierFactory(org.springframework.batch.core.runtime.JobIdentifierFactory)}.
*/
public void testSetJobIdentifierFactory() {
editor.setJobIdentifierFactory(new SimpleJobIdentifierFactory() {
public JobIdentifier getJobIdentifier(String name) {
return super.getJobIdentifier("test:"+name);
}
});
editor.setAsText("foo");
JobIdentifier identifier = (JobIdentifier) editor.getValue();
assertEquals("test:foo", identifier.getName());
}
/**
* Test method for {@link org.springframework.batch.execution.bootstrap.support.JobIdentifierPropertyEditor#setAsText(java.lang.String)}.
*/
public void testSetAsTextString() {
editor.setAsText("foo");
JobIdentifier identifier = (JobIdentifier) editor.getValue();
assertEquals("foo", identifier.getName());
}
/**
* Test method for {@link org.springframework.batch.execution.bootstrap.support.JobIdentifierPropertyEditor#getAsText()}.
*/
public void testGetAsText() {
editor.setAsText("foo");
assertEquals("foo", editor.getAsText());
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.bootstrap.support;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobParameters;
/**
* @author Dave Syer
*
*/
public class JobParametersPropertyEditorTests extends TestCase {
private JobParametersPropertyEditor editor = new JobParametersPropertyEditor();
/**
* Test method for
* {@link org.springframework.batch.execution.bootstrap.support.JobParametersPropertyEditor#setAsText(java.lang.String)}.
*/
public void testSetAsTextString() {
editor.setAsText("foo=bar");
JobParameters identifier = (JobParameters) editor.getValue();
assertEquals("bar", identifier.getString("foo"));
}
/**
* Test method for
* {@link org.springframework.batch.execution.bootstrap.support.JobParametersPropertyEditor#getAsText()}.
*/
public void testGetAsText() {
editor.setAsText("foo=bar,spam=bucket");
assertEquals("foo=bar,spam=bucket", editor.getAsText());
}
}

View File

@@ -18,62 +18,48 @@ package org.springframework.batch.execution.bootstrap.support;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.batch.core.domain.JobInstanceProperties;
import java.util.Properties;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.util.StringUtils;
/**
* @author Lucas Ward
*
*/
public class ScheduledJobInstancePropertiesFactoryTests extends TestCase {
ScheduledJobInstancePropertiesFactory factory;
ScheduledJobParametersFactory factory;
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
protected void setUp() throws Exception {
super.setUp();
factory = new ScheduledJobInstancePropertiesFactory();
factory = new ScheduledJobParametersFactory();
}
public void testGetProperties() throws Exception{
String jobKey = "job.key=myKey";
String scheduleDate = "schedule.date=01/23/2008";
String scheduleDate = "schedule.date=2008/01/23";
String vendorId = "vendor.id=33243243";
String[] args = new String[]{jobKey, scheduleDate, vendorId};
JobInstanceProperties props = factory.getProperties(args);
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
assertNotNull(props);
assertEquals("myKey", props.getString("job.key"));
assertEquals("33243243", props.getString("vendor.id"));
Date date = dateFormat.parse("01/23/2008");
assertEquals(date, props.getDate("schedule.date"));
}
public void testInvalidFormat(){
String jobKey = "job.key-myKey";
String[] args = new String[]{jobKey};
try{
factory.getProperties(args);
fail();
}
catch(IllegalArgumentException ex){
//expected
}
}
public void testEmptyArgs(){
String[] args = new String[]{};
JobInstanceProperties props = factory.getProperties(args);
assertTrue(props.isEmtpy());
JobParameters props = factory.getJobParameters(new Properties());
assertTrue(props.getParameters().isEmpty());
}
}

View File

@@ -20,7 +20,7 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.beans.factory.access.BeanFactoryLocator;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
@@ -158,7 +158,7 @@ public class SimpleCommandLineJobRunnerTests extends TestCase {
}
private void setReturnValue(ExitStatus status) {
JobExecution execution = new JobExecution(new JobInstance(new Long(1), new JobInstanceProperties(), new Job("foo")));
JobExecution execution = new JobExecution(new JobInstance(new Long(1), new JobParameters(), new Job("foo")));
execution.setExitStatus(status);
jobLauncher.setReturnValue(execution);

View File

@@ -2,7 +2,7 @@ package org.springframework.batch.execution.bootstrap.support;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.execution.launch.JobLauncher;
@@ -30,7 +30,7 @@ public class StubJobLauncher implements JobLauncher {
return isRunning;
}
public JobExecution run(Job job, JobInstanceProperties jobInstanceProperties)
public JobExecution run(Job job, JobParameters jobParameters)
throws JobExecutionAlreadyRunningException {
lastRunCalled = RUN_JOB_IDENTIFIER;
return returnValue;

View File

@@ -25,7 +25,7 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -97,7 +97,7 @@ public class DefaultJobExecutorTests extends TestCase {
private Job jobConfiguration;
private JobInstanceProperties jobInstanceProperties = new JobInstanceProperties();
private JobParameters jobParameters = new JobParameters();
private DefaultJobExecutor jobExecutor;
@@ -127,7 +127,7 @@ public class DefaultJobExecutorTests extends TestCase {
jobConfiguration.setName("testJob");
jobConfiguration.setSteps(stepConfigurations);
jobExecution = jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties);
jobExecution = jobRepository.createJobExecution(jobConfiguration, jobParameters);
job = jobExecution.getJobInstance();
List steps = job.getStepInstances();
@@ -282,7 +282,7 @@ public class DefaultJobExecutorTests extends TestCase {
* Check JobRepository to ensure status is being saved.
*/
private void checkRepository(BatchStatus status, ExitStatus exitStatus) {
assertEquals(job, jobDao.findJobInstances(job.getJobName(), jobInstanceProperties).get(0));
assertEquals(job, jobDao.findJobInstances(job.getJobName(), jobParameters).get(0));
// because map dao stores in memory, it can be checked directly
assertEquals(status, job.getStatus());
JobExecution jobExecution = (JobExecution) jobDao

View File

@@ -21,7 +21,7 @@ import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.repeat.ExitStatus;
@@ -41,7 +41,7 @@ public class SimpleJobLauncherTests extends TestCase {
private MockControl repositoryControl = MockControl.createControl(JobRepository.class);
private Job job = new Job("foo");
private JobInstanceProperties jobInstanceProperties = new JobInstanceProperties();
private JobParameters jobParameters = new JobParameters();
protected void setUp() throws Exception {
super.setUp();
@@ -62,7 +62,7 @@ public class SimpleJobLauncherTests extends TestCase {
JobExecution jobExecution = new JobExecution(null);
jobRepository.createJobExecution(job, jobInstanceProperties);
jobRepository.createJobExecution(job, jobParameters);
repositoryControl.setReturnValue(jobExecution);
jobExecutor.run(job, jobExecution);
executorControl.setDefaultReturnValue(ExitStatus.FINISHED);
@@ -70,7 +70,7 @@ public class SimpleJobLauncherTests extends TestCase {
repositoryControl.replay();
executorControl.replay();
jobLauncher.run(job, jobInstanceProperties);
jobLauncher.run(job, jobParameters);
assertEquals(ExitStatus.FINISHED, jobExecution.getExitStatus());
repositoryControl.verify();

View File

@@ -26,7 +26,7 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepExecutorFactory;
@@ -114,7 +114,7 @@ public class SimpleJobTests extends TestCase {
jobConfiguration.addStep(new SimpleStep(getTasklet("foo", "bar")));
jobConfiguration.addStep(new SimpleStep(getTasklet("spam")));
JobInstance job = repository.createJobExecution(jobConfiguration, new JobInstanceProperties()).getJobInstance();
JobInstance job = repository.createJobExecution(jobConfiguration, new JobParameters()).getJobInstance();
JobExecution jobExecutionContext = new JobExecution(job);
@@ -163,7 +163,7 @@ public class SimpleJobTests extends TestCase {
module.afterPropertiesSet();
jobConfiguration.addStep(step);
JobExecution jobExecution = repository.createJobExecution(jobConfiguration, new JobInstanceProperties());
JobExecution jobExecution = repository.createJobExecution(jobConfiguration, new JobParameters());
jobExecutor.run(jobConfiguration, jobExecution);
assertEquals(BatchStatus.COMPLETED, jobExecution.getJobInstance().getStatus());
@@ -186,7 +186,7 @@ public class SimpleJobTests extends TestCase {
module.afterPropertiesSet();
jobConfiguration.addStep(step);
JobExecution jobExecution = repository.createJobExecution(jobConfiguration, new JobInstanceProperties());
JobExecution jobExecution = repository.createJobExecution(jobConfiguration, new JobParameters());
JobInstance job = jobExecution.getJobInstance();
try {
jobExecutor.run(jobConfiguration, jobExecution);

View File

@@ -28,8 +28,8 @@ import org.easymock.MockControl;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobInstancePropertiesBuilder;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.domain.Step;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -53,7 +53,7 @@ public class SimpleJobRepositoryTests extends TestCase {
Job jobConfiguration;
JobInstanceProperties jobInstanceProperties;
JobParameters jobParameters;
Step stepConfiguration1;
@@ -86,7 +86,7 @@ public class SimpleJobRepositoryTests extends TestCase {
jobRepository = new SimpleJobRepository(jobDao, stepDao);
jobInstanceProperties = new JobInstancePropertiesBuilder().toJobParameters();
jobParameters = new JobParametersBuilder().toJobParameters();
jobConfiguration = new Job();
@@ -103,7 +103,7 @@ public class SimpleJobRepositoryTests extends TestCase {
jobConfiguration.setSteps(stepConfigurations);
databaseJob = new JobInstance(new Long(1), jobInstanceProperties) {
databaseJob = new JobInstance(new Long(1), jobParameters) {
public JobExecution createJobExecution() {
jobExecution = super.createJobExecution();
return jobExecution;
@@ -125,9 +125,9 @@ public class SimpleJobRepositoryTests extends TestCase {
List jobExecutions = new ArrayList();
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(jobExecutions);
jobDao.createJobInstance(jobConfiguration.getName(), jobInstanceProperties);
jobDao.createJobInstance(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(databaseJob);
stepDao.createStep(databaseJob, "TestStep1");
stepDaoControl.setReturnValue(databaseStep1);
@@ -144,7 +144,7 @@ public class SimpleJobRepositoryTests extends TestCase {
});
stepDaoControl.replay();
jobDaoControl.replay();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties).getJobInstance();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobParameters).getJobInstance();
assertTrue(job.equals(databaseJob));
List jobSteps = job.getStepInstances();
Iterator it = jobSteps.iterator();
@@ -156,7 +156,7 @@ public class SimpleJobRepositoryTests extends TestCase {
public void testRestartedJob() throws Exception{
List jobs = new ArrayList();
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobs.add(databaseJob);
jobDaoControl.setReturnValue(jobs);
stepDao.findStep(databaseJob, "TestStep1");
@@ -191,7 +191,7 @@ public class SimpleJobRepositoryTests extends TestCase {
});
jobDaoControl.setVoidCallable();
jobDaoControl.replay();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties).getJobInstance();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobParameters).getJobInstance();
assertTrue(job.equals(databaseJob));
List jobSteps = job.getStepInstances();
Iterator it = jobSteps.iterator();
@@ -208,13 +208,13 @@ public class SimpleJobRepositoryTests extends TestCase {
List jobs = new ArrayList();
jobs.add(databaseJob);
jobs.add(new JobInstance(new Long(127), jobInstanceProperties));
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobs.add(new JobInstance(new Long(127), jobParameters));
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(jobs);
jobDaoControl.replay();
try{
jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties);
jobRepository.createJobExecution(jobConfiguration, jobParameters);
fail("Expected BatchRestartException");
}catch(BatchRestartException e){
//expected
@@ -228,7 +228,7 @@ public class SimpleJobRepositoryTests extends TestCase {
jobConfiguration.setStartLimit(1);
List jobs = new ArrayList();
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobs.add(databaseJob);
jobDaoControl.setReturnValue(jobs);
stepDao.findStep(databaseJob, "TestStep1");
@@ -246,7 +246,7 @@ public class SimpleJobRepositoryTests extends TestCase {
jobDaoControl.replay();
try{
jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties);
jobRepository.createJobExecution(jobConfiguration, jobParameters);
fail();
}catch(BatchRestartException ex){
//expected
@@ -261,9 +261,9 @@ public class SimpleJobRepositoryTests extends TestCase {
List jobs = new ArrayList();
jobConfiguration.setRestartable(false);
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(jobs);
jobDao.createJobInstance(jobConfiguration.getName(), jobInstanceProperties);
jobDao.createJobInstance(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(databaseJob);
stepDao.createStep(databaseJob, "TestStep1");
stepDaoControl.setReturnValue(databaseStep1);
@@ -280,7 +280,7 @@ public class SimpleJobRepositoryTests extends TestCase {
});
stepDaoControl.replay();
jobDaoControl.replay();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties).getJobInstance();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobParameters).getJobInstance();
assertTrue(job.equals(databaseJob));
List jobSteps = job.getStepInstances();
Iterator it = jobSteps.iterator();
@@ -295,7 +295,7 @@ public class SimpleJobRepositoryTests extends TestCase {
// failure scenario - no ID
JobInstance updateJob;
try {
updateJob = new JobInstance(null, jobInstanceProperties);
updateJob = new JobInstance(null, jobParameters);
jobRepository.update(updateJob);
fail();
}
@@ -304,7 +304,7 @@ public class SimpleJobRepositoryTests extends TestCase {
}
// successful update
updateJob = new JobInstance(new Long(0L), jobInstanceProperties);
updateJob = new JobInstance(new Long(0L), jobParameters);
jobDao.update(updateJob);
jobDaoControl.replay();
jobRepository.update(updateJob);
@@ -326,7 +326,7 @@ public class SimpleJobRepositoryTests extends TestCase {
public void testSaveOrUpdateValidJobExecution() throws Exception {
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(1), jobInstanceProperties));
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(1), jobParameters));
// new execution - call save on job dao
jobDao.save(jobExecution);
@@ -401,9 +401,9 @@ public class SimpleJobRepositoryTests extends TestCase {
List jobs = new ArrayList();
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(jobs);
jobDao.createJobInstance(jobConfiguration.getName(), jobInstanceProperties);
jobDao.createJobInstance(jobConfiguration.getName(), jobParameters);
jobDaoControl.setReturnValue(databaseJob);
stepDao.createStep(databaseJob, "TestStep1");
databaseStep1.setRestartData(null);
@@ -422,7 +422,7 @@ public class SimpleJobRepositoryTests extends TestCase {
});
stepDaoControl.replay();
jobDaoControl.replay();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties).getJobInstance();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobParameters).getJobInstance();
List jobSteps = job.getStepInstances();
Iterator it = jobSteps.iterator();
StepInstance step = (StepInstance) it.next();
@@ -435,7 +435,7 @@ public class SimpleJobRepositoryTests extends TestCase {
public void testFindStepsFixesInvalidRestartData() throws Exception{
List jobs = new ArrayList();
jobDao.findJobInstances(jobConfiguration.getName(), jobInstanceProperties);
jobDao.findJobInstances(jobConfiguration.getName(), jobParameters);
jobs.add(databaseJob);
jobDaoControl.setReturnValue(jobs);
stepDao.findStep(databaseJob, "TestStep1");
@@ -465,7 +465,7 @@ public class SimpleJobRepositoryTests extends TestCase {
}
});
jobDaoControl.replay();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobInstanceProperties).getJobInstance();
JobInstance job = jobRepository.createJobExecution(jobConfiguration, jobParameters).getJobInstance();
assertTrue(job.equals(databaseJob));
List jobSteps = job.getStepInstances();
Iterator it = jobSteps.iterator();

View File

@@ -24,8 +24,8 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobInstancePropertiesBuilder;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.JobParametersBuilder;
import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
@@ -40,7 +40,7 @@ public abstract class AbstractJobDaoTests extends
protected JobDao jobDao;
protected JobInstanceProperties jobInstanceProperties = new JobInstancePropertiesBuilder().addString("job.key", "jobKey").toJobParameters();
protected JobParameters jobParameters = new JobParametersBuilder().addString("job.key", "jobKey").toJobParameters();
protected JobInstance jobInstance;
@@ -71,7 +71,7 @@ public abstract class AbstractJobDaoTests extends
job = new Job("Job1");
// Create job.
jobInstance = jobDao.createJobInstance(job.getName(), jobInstanceProperties);
jobInstance = jobDao.createJobInstance(job.getName(), jobParameters);
// Create an execution
jobExecutionStartTime = new Date(System.currentTimeMillis());
@@ -97,17 +97,17 @@ public abstract class AbstractJobDaoTests extends
public void testFindNonExistentJob() {
// No job should be found since it hasn't been created.
List jobs = jobDao.findJobInstances("nonexistentJob", jobInstanceProperties);
List jobs = jobDao.findJobInstances("nonexistentJob", jobParameters);
assertTrue(jobs.size() == 0);
}
public void testFindJob() {
List jobs = jobDao.findJobInstances(job.getName(), jobInstanceProperties);
List jobs = jobDao.findJobInstances(job.getName(), jobParameters);
assertTrue(jobs.size() == 1);
JobInstance tempJob = (JobInstance) jobs.get(0);
assertTrue(jobInstance.equals(tempJob));
assertEquals(jobInstanceProperties, tempJob.getJobInstanceProperties());
assertEquals(jobParameters, tempJob.getJobInstanceProperties());
}
public void testFindJobWithNullRuntime() {
@@ -127,18 +127,18 @@ public abstract class AbstractJobDaoTests extends
*/
public void testCreateJobWithExistingName() {
jobDao.createJobInstance("ScheduledJob", jobInstanceProperties);
jobDao.createJobInstance("ScheduledJob", jobParameters);
// Modifying the key should bring back a completely different
// JobInstance
JobInstanceProperties tempProps = new JobInstancePropertiesBuilder().addString("job.key", "testKey1")
JobParameters tempProps = new JobParametersBuilder().addString("job.key", "testKey1")
.toJobParameters();
List jobs;
jobs = jobDao.findJobInstances("ScheduledJob", jobInstanceProperties);
jobs = jobDao.findJobInstances("ScheduledJob", jobParameters);
assertEquals(1, jobs.size());
JobInstance jobInstance = (JobInstance) jobs.get(0);
assertEquals(jobInstanceProperties, jobInstance.getJobInstanceProperties());
assertEquals(jobParameters, jobInstance.getJobInstanceProperties());
jobs = jobDao.findJobInstances("ScheduledJob", tempProps);
assertEquals(0, jobs.size());
@@ -151,7 +151,7 @@ public abstract class AbstractJobDaoTests extends
jobDao.update(jobInstance);
// The job just updated should be found, with the saved status.
List jobs = jobDao.findJobInstances(job.getName(), jobInstanceProperties);
List jobs = jobDao.findJobInstances(job.getName(), jobParameters);
assertTrue(jobs.size() == 1);
JobInstance tempJob = (JobInstance) jobs.get(0);
assertTrue(jobInstance.equals(tempJob));
@@ -237,7 +237,7 @@ public abstract class AbstractJobDaoTests extends
public void testZeroExecutionCount() {
JobInstance testJob = jobDao.createJobInstance("test", new JobInstanceProperties());
JobInstance testJob = jobDao.createJobInstance("test", new JobParameters());
// no jobExecutions saved for new job, count should be 0
assertEquals(jobDao.getJobExecutionCount(testJob.getId()), 0);
}
@@ -245,7 +245,7 @@ public abstract class AbstractJobDaoTests extends
public void testJobWithSimpleJobIdentifier() throws Exception {
// Create job.
jobInstance = jobDao.createJobInstance("test", jobInstanceProperties);
jobInstance = jobDao.createJobInstance("test", jobParameters);
List jobs = jdbcTemplate.queryForList(
"SELECT * FROM BATCH_JOB_INSTANCE where ID=?", new Object[] { jobInstance
@@ -257,12 +257,12 @@ public abstract class AbstractJobDaoTests extends
public void testJobWithDefaultJobIdentifier() throws Exception {
// Create job.
jobInstance = jobDao.createJobInstance("testDefault", jobInstanceProperties);
jobInstance = jobDao.createJobInstance("testDefault", jobParameters);
List jobs = jobDao.findJobInstances("testDefault", jobInstanceProperties);
List jobs = jobDao.findJobInstances("testDefault", jobParameters);
assertEquals(1, jobs.size());
assertEquals(jobInstanceProperties.getString("job.key"), ((JobInstance) jobs.get(0))
assertEquals(jobParameters.getString("job.key"), ((JobInstance) jobs.get(0))
.getJobInstanceProperties().getString("job.key"));
}

View File

@@ -24,7 +24,7 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
@@ -59,7 +59,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
protected JobExecution jobExecution;
protected JobInstanceProperties jobInstanceProperties = new JobInstanceProperties();
protected JobParameters jobParameters = new JobParameters();
public void setJobDao(JobDao jobDao) {
this.jobDao = jobDao;
@@ -83,7 +83,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
*/
protected void onSetUpInTransaction() throws Exception {
Job job = new Job("TestJob");
jobInstance = jobDao.createJobInstance(job.getName(), jobInstanceProperties);
jobInstance = jobDao.createJobInstance(job.getName(), jobParameters);
step1 = stepDao.createStep(jobInstance, "TestStep1");
step2 = stepDao.createStep(jobInstance, "TestStep2");
jobExecution = new JobExecution(step2.getJobInstance());
@@ -127,7 +127,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
public void testFindStepsNotSaved(){
//no steps are saved for given id, empty list should be returned
List steps = stepDao.findSteps(new JobInstance(new Long(38922), jobInstanceProperties));
List steps = stepDao.findSteps(new JobInstance(new Long(38922), jobParameters));
assertEquals(steps.size(), 0);
}

View File

@@ -21,7 +21,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
@@ -67,7 +67,7 @@ public class JdbcJobDaoQueryTests extends TestCase {
return 1;
}
});
sqlDao.save(new JobInstance(new Long(11), new JobInstanceProperties()).createJobExecution());
sqlDao.save(new JobInstance(new Long(11), new JobParameters()).createJobExecution());
assertEquals(1, list.size());
String query = (String) list.get(0);
assertTrue("Query did not contain FOO_:" + query, query.indexOf("FOO_") >= 0);

View File

@@ -8,7 +8,7 @@ import org.easymock.MockControl;
import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.dao.DataAccessException;
@@ -31,7 +31,7 @@ public class JdbcStepDaoPrefixTests extends TestCase {
MockJdbcTemplate jdbcTemplate = new MockJdbcTemplate();
JobInstance job = new JobInstance(new Long(1), new JobInstanceProperties());
JobInstance job = new JobInstance(new Long(1), new JobParameters());
StepInstance step = new StepInstance(job, "foo", new Long(1));
StepExecution stepExecution = new StepExecution(step, new JobExecution(job), null);
@@ -97,7 +97,7 @@ public class JdbcStepDaoPrefixTests extends TestCase {
public void testModifiedFindSteps(){
stepDao.setTablePrefix("FOO_");
stepDao.findSteps(new JobInstance(new Long(1), new JobInstanceProperties()));
stepDao.findSteps(new JobInstance(new Long(1), new JobParameters()));
assertTrue(jdbcTemplate.getSqlStatement().indexOf("FOO_STEP") != -1);
}
@@ -128,7 +128,7 @@ public class JdbcStepDaoPrefixTests extends TestCase {
}
public void testDefaultFindSteps(){
stepDao.findSteps(new JobInstance(new Long(1), new JobInstanceProperties()));
stepDao.findSteps(new JobInstance(new Long(1), new JobParameters()));
assertTrue(jdbcTemplate.getSqlStatement().indexOf("BATCH_STEP") != -1);
}

View File

@@ -22,52 +22,52 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
public class MapJobDaoTests extends TestCase {
MapJobDao dao = new MapJobDao();
JobInstanceProperties jobInstanceProperties = new JobInstanceProperties();
JobParameters jobParameters = new JobParameters();
protected void setUp() throws Exception {
MapJobDao.clear();
}
public void testCreateAndRetrieveSingle() throws Exception {
JobInstance job = dao.createJobInstance("foo", jobInstanceProperties);
List result = dao.findJobInstances("foo", jobInstanceProperties);
JobInstance job = dao.createJobInstance("foo", jobParameters);
List result = dao.findJobInstances("foo", jobParameters);
assertTrue(result.contains(job));
}
public void testCreateAndRetrieveMultiple() throws Exception {
JobInstance job = dao.createJobInstance("foo", jobInstanceProperties);
job = dao.createJobInstance("bar", jobInstanceProperties);
List result = dao.findJobInstances("bar", jobInstanceProperties);
JobInstance job = dao.createJobInstance("foo", jobParameters);
job = dao.createJobInstance("bar", jobParameters);
List result = dao.findJobInstances("bar", jobParameters);
assertEquals(1, result.size());
assertTrue(result.contains(job));
}
public void testNoExecutionsForNewJob() throws Exception {
JobInstance job = dao.createJobInstance("foo", jobInstanceProperties);
JobInstance job = dao.createJobInstance("foo", jobParameters);
assertEquals(0, dao.getJobExecutionCount(job.getId()));
}
public void testSaveExecutionUpdatesId() throws Exception {
JobInstance job = dao.createJobInstance("foo", jobInstanceProperties);
JobInstance job = dao.createJobInstance("foo", jobParameters);
JobExecution execution = new JobExecution(job);
assertNull(execution.getId());
dao.save(execution);
assertNotNull(execution.getId());
}
public void testCorrectExecutionCountForExistingJob() throws Exception {
JobInstance job = dao.createJobInstance("foo", jobInstanceProperties);
JobInstance job = dao.createJobInstance("foo", jobParameters);
dao.save(new JobExecution(job));
assertEquals(1, dao.getJobExecutionCount(job.getId()));
}
public void testMultipleExecutionsPerExisting() throws Exception {
JobInstance job = dao.createJobInstance("foo", jobInstanceProperties);
JobInstance job = dao.createJobInstance("foo", jobParameters);
dao.save(new JobExecution(job));
Thread.sleep(50L); // Hack, hack, hackety, hack - job executions are not unique if created too close together!
dao.save(new JobExecution(job));

View File

@@ -23,7 +23,7 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.execution.repository.dao.MapStepDao;
@@ -41,7 +41,7 @@ public class MapStepDaoTests extends TestCase {
protected void setUp() throws Exception {
MapStepDao.clear();
job = new JobInstance(new Long(jobId++), new JobInstanceProperties());
job = new JobInstance(new Long(jobId++), new JobParameters());
step = dao.createStep(job, "foo");
}
@@ -75,12 +75,12 @@ public class MapStepDaoTests extends TestCase {
}
public void testFindWithEmptyResults() throws Exception {
List result = dao.findSteps(new JobInstance(new Long(22), new JobInstanceProperties()));
List result = dao.findSteps(new JobInstance(new Long(22), new JobParameters()));
assertEquals(0, result.size());
}
public void testFindSingleWithEmptyResults() throws Exception {
StepInstance result = dao.findStep(new JobInstance(new Long(22), new JobInstanceProperties()), "bar");
StepInstance result = dao.findStep(new JobInstance(new Long(22), new JobParameters()), "bar");
assertEquals(null, result);
}

View File

@@ -24,7 +24,7 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.execution.scope.SimpleStepContext;
@@ -64,7 +64,7 @@ public class BatchResourceFactoryBeanTests extends TestCase {
resourceFactory.setRootDirectory(rootDir);
SimpleStepContext context = new SimpleStepContext();
jobInstance = new JobInstance(new Long(0), new JobInstanceProperties());
jobInstance = new JobInstance(new Long(0), new JobParameters());
jobInstance.setJob(new Job("testJob"));
JobExecution jobExecution = new JobExecution(jobInstance);
StepInstance step = new StepInstance(jobInstance, "bar");

View File

@@ -1,14 +0,0 @@
package org.springframework.batch.execution.runtime;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobIdentifier;
public class DefaultJobIdentifierFactoryTests extends TestCase {
public void testGetJobIdentifier() {
JobIdentifier jobIdentifier = new ScheduledJobIdentifierFactory().getJobIdentifier("foo");
assertEquals("foo", jobIdentifier.getName());
}
}

View File

@@ -1,14 +0,0 @@
package org.springframework.batch.execution.runtime;
import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobIdentifier;
public class ScheduledJobIdentifierFactoryTests extends TestCase {
public void testGetJobIdentifier() {
JobIdentifier jobIdentifier = new DefaultJobIdentifierFactory().getJobIdentifier("foo");
assertEquals("foo", jobIdentifier.getName());
}
}

View File

@@ -25,7 +25,7 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepContribution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -105,7 +105,7 @@ public class DefaultStepExecutorTests extends TestCase {
template.setCompletionPolicy(new SimpleCompletionPolicy(1));
stepExecutor.setChunkOperations(template);
jobInstance = new JobInstance(new Long(0), new JobInstanceProperties());
jobInstance = new JobInstance(new Long(0), new JobParameters());
jobInstance.setJob(new Job("FOO"));
}

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.execution.step.simple;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.repository.JobRepository;
@@ -32,7 +32,7 @@ public class JobRepositorySupport implements JobRepository {
/* (non-Javadoc)
* @see org.springframework.batch.container.common.repository.JobRepository#findOrCreateJob(org.springframework.batch.container.common.domain.JobConfiguration)
*/
public JobExecution createJobExecution(Job jobConfiguration, JobInstanceProperties jobInstanceProperties) {
public JobExecution createJobExecution(Job jobConfiguration, JobParameters jobParameters) {
return null;
}

View File

@@ -22,7 +22,7 @@ import junit.framework.TestCase;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.domain.StepSupport;
@@ -66,7 +66,7 @@ public class SimpleStepExecutorFactoryTests extends TestCase {
SimpleStepExecutor executor = (SimpleStepExecutor) factory
.getExecutor(configuration);
StepExecution stepExecution = new StepExecution(new StepInstance(
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobInstanceProperties()),
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
try {
executor.process(configuration, stepExecution);
@@ -93,7 +93,7 @@ public class SimpleStepExecutorFactoryTests extends TestCase {
SimpleStepExecutor executor = (SimpleStepExecutor) factory
.getExecutor(configuration);
StepExecution stepExecution = new StepExecution(new StepInstance(
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobInstanceProperties()),
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
try {
executor.process(configuration, stepExecution);
@@ -131,7 +131,7 @@ public class SimpleStepExecutorFactoryTests extends TestCase {
SimpleStepExecutor executor = (SimpleStepExecutor) factory
.getExecutor(configuration);
StepExecution stepExecution = new StepExecution(new StepInstance(
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobInstanceProperties()),
new Long(11)), new JobExecution(new JobInstance(new Long(0L), new JobParameters()),
new Long(12)));
executor.process(configuration, stepExecution);
assertEquals(2, list.size());

View File

@@ -24,7 +24,7 @@ import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.Job;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.domain.StepSupport;
@@ -63,7 +63,7 @@ public class StepExecutorInterruptionTests extends TestCase {
stepConfiguration = new SimpleStep();
jobConfiguration.addStep(stepConfiguration);
jobConfiguration.setBeanName("testJob");
job = jobRepository.createJobExecution(jobConfiguration, new JobInstanceProperties()).getJobInstance();
job = jobRepository.createJobExecution(jobConfiguration, new JobParameters()).getJobInstance();
executor = new SimpleStepExecutor();
}
@@ -73,7 +73,7 @@ public class StepExecutorInterruptionTests extends TestCase {
List steps = job.getStepInstances();
final StepInstance step = (StepInstance) steps.get(0);
JobExecution jobExecutionContext = new JobExecution(new JobInstance(new Long(0L), new JobInstanceProperties()));
JobExecution jobExecutionContext = new JobExecution(new JobInstance(new Long(0L), new JobParameters()));
final StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
stepConfiguration.setTasklet(new Tasklet() {
public ExitStatus execute() throws Exception {

View File

@@ -72,12 +72,6 @@
class="org.springframework.batch.execution.repository.dao.MapStepDao" />
<!-- init-method="clear"/-->
<bean id="jobRuntimeInformationFactory"
class="org.springframework.batch.execution.runtime.ScheduledJobIdentifierFactory">
<property name="jobKey" value="TestStream" />
<property name="scheduleDate" value="20070505" />
</bean>
<bean
class="org.springframework.batch.execution.bootstrap.support.SimpleJvmExitCodeMapper" />