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

@@ -18,6 +18,8 @@ package org.springframework.batch.core.domain;
import java.io.Serializable;
import org.springframework.util.Assert;
/**
* Typesafe enumeration representing the status of an artifact within the
* batch environment. See Effective Java Programming by Joshua Bloch for more
@@ -69,6 +71,7 @@ public class BatchStatus implements Serializable{
* @throws IllegalArgumentException if no status matches provided string.
*/
public static BatchStatus getStatus(String statusAsString) {
Assert.notNull(statusAsString, "Cannot match null to valid status.");
final String upperCaseStatusAsString = statusAsString.toUpperCase();
for (int i = 0; i < VALUES.length; i++) {
if (VALUES[i].toString().equals(upperCaseStatusAsString)) {

View File

@@ -36,11 +36,11 @@ public interface JobIdentifier {
public String getName();
/**
* A simple getter for the {@link JobInstanceProperties} that also identify
* A simple getter for the {@link JobParameters} that also identify
* this job.
*
* @return JobRuntimeParameters
*/
public JobInstanceProperties getJobInstanceProperties();
public JobParameters getJobInstanceProperties();
}

View File

@@ -35,7 +35,7 @@ public class JobInstance extends Entity {
private List stepInstances = new ArrayList();
private JobInstanceProperties jobInstanceProperties;
private JobParameters jobParameters;
private Job job;
@@ -44,14 +44,14 @@ public class JobInstance extends Entity {
private int jobExecutionCount;
public JobInstance(Long id, JobInstanceProperties jobInstanceProperties) {
public JobInstance(Long id, JobParameters jobParameters) {
super(id);
Assert.notNull(jobInstanceProperties, "JobInstanceProperties must not be null.");
this.jobInstanceProperties = jobInstanceProperties;
Assert.notNull(jobParameters, "JobInstanceProperties must not be null.");
this.jobParameters = jobParameters;
}
public JobInstance(Long id, JobInstanceProperties jobInstanceProperties, Job job){
this(id, jobInstanceProperties);
public JobInstance(Long id, JobParameters jobParameters, Job job){
this(id, jobParameters);
this.job = job;
}
@@ -86,8 +86,8 @@ public class JobInstance extends Entity {
/**
* @return JobInstanceProperties
*/
public JobInstanceProperties getJobInstanceProperties() {
return jobInstanceProperties;
public JobParameters getJobInstanceProperties() {
return jobParameters;
}
/**
@@ -102,7 +102,7 @@ public class JobInstance extends Entity {
}
public String toString() {
return super.toString()+", JobInstanceProperties=["+ jobInstanceProperties +"]" +
return super.toString()+", JobInstanceProperties=["+ jobParameters +"]" +
", Job=[" + job + "]";
}

View File

@@ -25,7 +25,7 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
* @author Lucas Ward
* @since 1.0
*/
public class JobInstanceProperties {
public class JobParameters {
private final Map stringMap;
@@ -38,7 +38,7 @@ public class JobInstanceProperties {
* that this constructor should only be used if an empty parameters is needed, since
* JobRuntimeParameters is immutable.
*/
public JobInstanceProperties(){
public JobParameters(){
this.stringMap = new LinkedHashMap();
this.longMap = new LinkedHashMap();
this.dateMap = new LinkedHashMap();
@@ -46,14 +46,14 @@ public class JobInstanceProperties {
/**
* Create a new parameters object based upon three maps for each of the three
* data types. See {@link JobInstancePropertiesBuilder} for an easier way to
* data types. See {@link JobParametersBuilder} for an easier way to
* create paramters.
*
* @param stringMap
* @param longMap
* @param dateMap
*/
public JobInstanceProperties(Map stringMap, Map longMap, Map dateMap){
public JobParameters(Map stringMap, Map longMap, Map dateMap){
super();
validateMap(stringMap, String.class);
@@ -168,13 +168,9 @@ public class JobInstanceProperties {
return tempMap;
}
public boolean isEmtpy(){
return dateMap.isEmpty() && longMap.isEmpty() && stringMap.isEmpty();
}
public boolean equals(Object obj) {
if(obj instanceof JobInstanceProperties == false){
if(obj instanceof JobParameters == false){
return false;
}
@@ -182,7 +178,7 @@ public class JobInstanceProperties {
return true;
}
JobInstanceProperties parameters = (JobInstanceProperties)obj;
JobParameters parameters = (JobParameters)obj;
//Since the type contained by each map is known, it's safe to call Map.equals()
if(getParameters().equals(parameters.getParameters())){

View File

@@ -10,33 +10,35 @@ import java.util.Map;
import org.springframework.util.Assert;
/**
* Helper class for creating JobRuntimeParameters. Useful because of all JobRuntimeParameters
* are immutable, and require 3 separate maps of the three supported types to ensure typesafety.
* Once created, it can be used in the same was a java.lang.StringBuilder (except, order is irrelevant),
* by adding various parameters types and creating a valid JobRuntimeParametres once finished.
* Helper class for creating {@link JobParameters}. Useful because of all
* {@link JobParameters} are immutable, and require 3 separate maps of the three
* supported types to ensure typesafety. Once created, it can be used in the
* same was a java.lang.StringBuilder (except, order is irrelevant), by adding
* various parameters types and creating a valid JobRuntimeParametres once
* finished.
*
* @author Lucas Ward
* @since 1.0
* @see JobInstanceProperties
* @see JobParameters
*/
public class JobInstancePropertiesBuilder {
public class JobParametersBuilder {
private final Map stringMap;
private final Map longMap;
private final Map dateMap;
/**
* Default constructor. Initializes the builder
* Default constructor. Initializes the builder
*/
public JobInstancePropertiesBuilder() {
public JobParametersBuilder() {
this.stringMap = new HashMap();
this.longMap = new HashMap();
this.dateMap = new HashMap();
}
/**
* Add a new String parameter for the given key.
*
@@ -44,12 +46,12 @@ public class JobInstancePropertiesBuilder {
* @param parameter - runtime parameter
* @return a refernece to this object.
*/
public JobInstancePropertiesBuilder addString(String key, String parameter){
public JobParametersBuilder addString(String key, String parameter) {
Assert.notNull(parameter, "Parameter must not be null.");
stringMap.put(key, parameter);
return this;
}
/**
* Add a new Date parameter for the given key.
*
@@ -57,12 +59,12 @@ public class JobInstancePropertiesBuilder {
* @param parameter - runtime parameter
* @return a refernece to this object.
*/
public JobInstancePropertiesBuilder addDate(String key, Date parameter){
public JobParametersBuilder addDate(String key, Date parameter) {
Assert.notNull(parameter, "Parameter must not be null.");
dateMap.put(key, new Date(parameter.getTime()));
return this;
}
/**
* Add a new Long parameter for the given key.
*
@@ -70,19 +72,19 @@ public class JobInstancePropertiesBuilder {
* @param parameter - runtime parameter
* @return a refernece to this object.
*/
public JobInstancePropertiesBuilder addLong(String key, Long parameter){
public JobParametersBuilder addLong(String key, Long parameter) {
Assert.notNull(parameter, "Parameter must not be null.");
longMap.put(key, parameter);
return this;
}
/**
* Conversion method that takes the current state of this builder and returns it as
* a JobruntimeParameters object.
* Conversion method that takes the current state of this builder and
* returns it as a JobruntimeParameters object.
*
* @return a valid JobRuntimeParameters object.
*/
public JobInstanceProperties toJobParameters(){
return new JobInstanceProperties(stringMap, longMap, dateMap);
public JobParameters toJobParameters() {
return new JobParameters(stringMap, longMap, dateMap);
}
}

View File

@@ -20,7 +20,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.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -53,7 +53,7 @@ public interface JobRepository {
* exists, its persisted values (including ID) will be returned in a new
* {@link JobInstance} object. If no previous run is found, a new job will
* be created and returned.
* @param jobInstanceProperties TODO
* @param jobParameters TODO
* @param jobConfiguration
* describes the configuration for this job
*
@@ -64,7 +64,7 @@ public interface JobRepository {
*
*/
public JobExecution createJobExecution(Job job,
JobInstanceProperties jobInstanceProperties)
JobParameters jobParameters)
throws JobExecutionAlreadyRunningException;
/**

View File

@@ -16,29 +16,31 @@
package org.springframework.batch.core.runtime;
import org.springframework.batch.core.domain.JobIdentifier;
import java.util.Properties;
import org.springframework.batch.core.domain.JobParameters;
/**
* A factory for {@link JobIdentifier} instances. A job can be
* A factory for {@link JobParameters} instances. A job can be
* executed with many possible runtime parameters, which identify the instance
* of the job. This factory allows job identifiers to be created with different
* properties according to the {@link JobIdentifier} strategy required. For
* properties according to the {@link JobParameters} strategy required. For
* example some projects or jobs need a schedule date as part of the
* {@link JobIdentifier} and some do not (e.g. for an ad-hoc execution a simple
* {@link JobParameters} and some do not (e.g. for an ad-hoc execution a simple
* label might be enough).
*
*
* @author Dave Syer
*
*/
public interface JobIdentifierFactory {
public interface JobParametersFactory {
/**
* Get a new {@link JobIdentifier} instance.
* Get a new {@link JobParameters} instance.
*
* @param name
* the name of the job.
* @return a {@link JobIdentifier} with the same name.
* @param properties
* the runtime parameters in the form of String literals.
* @return a {@link JobParameters} properties converted to the correct types.
*/
public JobIdentifier getJobIdentifier(String name);
public JobParameters getJobParameters(Properties properties);
}

View File

@@ -18,7 +18,7 @@ package org.springframework.batch.core.runtime;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.springframework.batch.core.domain.JobIdentifier;
import org.springframework.batch.core.domain.JobInstanceProperties;
import org.springframework.batch.core.domain.JobParameters;
import org.springframework.util.ClassUtils;
@@ -32,7 +32,7 @@ import org.springframework.util.ClassUtils;
public class SimpleJobIdentifier implements JobIdentifier {
private String name;
private JobInstanceProperties runtimeParameters;
private JobParameters runtimeParameters;
/**
* Default constructor. Since there it is required that the Identifier at least have a name,
@@ -47,10 +47,10 @@ public class SimpleJobIdentifier implements JobIdentifier {
* @param name
*/
public SimpleJobIdentifier(String name) {
this(name, new JobInstanceProperties());
this(name, new JobParameters());
}
public SimpleJobIdentifier(String name, JobInstanceProperties runtimeParameters){
public SimpleJobIdentifier(String name, JobParameters runtimeParameters){
this.name = name;
this.runtimeParameters = runtimeParameters;
}
@@ -62,7 +62,7 @@ public class SimpleJobIdentifier implements JobIdentifier {
return this.name;
}
public JobInstanceProperties getJobInstanceProperties() {
public JobParameters getJobInstanceProperties() {
return runtimeParameters;
}

View File

@@ -1,26 +0,0 @@
package org.springframework.batch.core.runtime;
import org.springframework.batch.core.domain.JobIdentifier;
/**
* Factory for {@link SimpleJobIdentifier} instances.
*
* @author Dave Syer
*
*/
public class SimpleJobIdentifierFactory implements JobIdentifierFactory {
/**
* Create a {@link JobIdentifier} with the given name.
*
* @param name the name for the {@link JobIdentifier}
* @return a {@link JobIdentifier} with the given name.
*
* @see org.springframework.batch.core.runtime.JobIdentifierFactory#getJobIdentifier(java.lang.String)
*/
public JobIdentifier getJobIdentifier(String name) {
return new SimpleJobIdentifier(name);
}
}