[BATCH-85] Polishing
This commit is contained in:
@@ -19,24 +19,22 @@ package org.springframework.batch.core.domain;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Typesafe enumeration representing the status of an artifact within the
|
||||
* batch environment. See Effective Java Programming by Joshua Bloch for more
|
||||
* details on the pattern used.
|
||||
* Typesafe enumeration representing the status of an artifact within the batch environment. See Effective Java
|
||||
* Programming by Joshua Bloch for more details on the pattern used.
|
||||
*
|
||||
* A BatchStatus can be safely serialized, however, it should be noted
|
||||
* that the pattern can break down if different class loaders load
|
||||
* the enumeration.
|
||||
* A BatchStatus can be safely serialized, however, it should be noted that the pattern can break down if different
|
||||
* class loaders load the enumeration.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Greg Kick
|
||||
*/
|
||||
|
||||
public class BatchStatus implements Serializable{
|
||||
public class BatchStatus implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1634960297477743037L;
|
||||
|
||||
private final String name;
|
||||
|
||||
|
||||
private BatchStatus(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@@ -64,12 +62,12 @@ public class BatchStatus implements Serializable{
|
||||
/**
|
||||
* Given a string representation of a status, return the appropriate BatchStatus.
|
||||
*
|
||||
* @param statusAsString: string representation of a status
|
||||
* @param statusAsString string representation of a status
|
||||
* @return a valid BatchStatus or null if the input is null
|
||||
* @throws IllegalArgumentException if no status matches provided string.
|
||||
*/
|
||||
public static BatchStatus getStatus(String statusAsString) {
|
||||
if (statusAsString==null) {
|
||||
if (statusAsString == null) {
|
||||
return null;
|
||||
}
|
||||
final String upperCaseStatusAsString = statusAsString.toUpperCase();
|
||||
|
||||
@@ -13,12 +13,10 @@ import java.util.Map.Entry;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
|
||||
/**
|
||||
* Value object representing runtime parameters to a batch job. Because
|
||||
* the parameters have no individual meaning outside of the JobIdentifier they
|
||||
* are contained within, it is a value object rather than an entity. It is also
|
||||
* extremely important that a parameters object can be reliably compared to another
|
||||
* for equality, in order to determine if one JobIdentifier equals another.
|
||||
* Furthermore, because these parameters will need to be persisted, it is vital
|
||||
* Value object representing runtime parameters to a batch job. Because the parameters have no individual meaning
|
||||
* outside of the JobIdentifier they are contained within, it is a value object rather than an entity. It is also
|
||||
* extremely important that a parameters object can be reliably compared to another for equality, in order to determine
|
||||
* if one JobIdentifier equals another. Furthermore, because these parameters will need to be persisted, it is vital
|
||||
* that the types added are restricted.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
@@ -27,34 +25,32 @@ import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
public class JobParameters {
|
||||
|
||||
private final Map stringMap;
|
||||
|
||||
|
||||
private final Map longMap;
|
||||
|
||||
|
||||
private final Map dateMap;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor. Creates a new empty JobRuntimeParameters. It should be noted
|
||||
* that this constructor should only be used if an empty parameters is needed, since
|
||||
* JobRuntimeParameters is immutable.
|
||||
* Default constructor. Creates a new empty JobRuntimeParameters. It should be noted that this constructor should
|
||||
* only be used if an empty parameters is needed, since JobRuntimeParameters is immutable.
|
||||
*/
|
||||
public JobParameters(){
|
||||
public JobParameters() {
|
||||
this.stringMap = new LinkedHashMap();
|
||||
this.longMap = new LinkedHashMap();
|
||||
this.dateMap = new LinkedHashMap();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a new parameters object based upon three maps for each of the three
|
||||
* data types. See {@link JobParametersBuilder} for an easier way to
|
||||
* create paramters.
|
||||
* Create a new parameters object based upon three maps for each of the three data types. See
|
||||
* {@link JobParametersBuilder} for an easier way to create parameters.
|
||||
*
|
||||
* @param stringMap
|
||||
* @param longMap
|
||||
* @param dateMap
|
||||
*/
|
||||
public JobParameters(Map stringMap, Map longMap, Map dateMap){
|
||||
public JobParameters(Map stringMap, Map longMap, Map dateMap) {
|
||||
super();
|
||||
|
||||
|
||||
validateMap(stringMap, String.class);
|
||||
validateMap(longMap, Long.class);
|
||||
validateMap(dateMap, Date.class);
|
||||
@@ -62,149 +58,143 @@ public class JobParameters {
|
||||
this.longMap = new LinkedHashMap(longMap);
|
||||
this.dateMap = copyDateMap(dateMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Typesafe Getter for the String represented by the provided key.
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
* @param key The key to get a value for
|
||||
* @return The <code>String</code> value
|
||||
*/
|
||||
public String getString(String key){
|
||||
return (String)stringMap.get(key);
|
||||
public String getString(String key) {
|
||||
return (String) stringMap.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Typesafe Getter for the Long represented by the provided key.
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
* @param key The key to get a value for
|
||||
* @return The <code>Long</code> value
|
||||
*/
|
||||
public Long getLong(String key){
|
||||
return (Long)longMap.get(key);
|
||||
public Long getLong(String key) {
|
||||
return (Long) longMap.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Typesafe Getter for the Date represented by the provided key.
|
||||
*
|
||||
* @param key
|
||||
* @return
|
||||
* @param key The key to get a value for
|
||||
* @return The <code>java.util.Date</code> value
|
||||
*/
|
||||
public Date getDate(String key){
|
||||
return (Date)dateMap.get(key);
|
||||
public Date getDate(String key) {
|
||||
return (Date) dateMap.get(key);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of all parameters, including string, long, and date. It should be noted
|
||||
* that a Collections$UnmodifiableMap is returned, ensuring immutability.
|
||||
* Get a map of all parameters, including string, long, and date. It should be noted that a
|
||||
* Collections$UnmodifiableMap is returned, ensuring immutability.
|
||||
*
|
||||
* @return an unmodifiable map containing all parameters.
|
||||
*/
|
||||
public Map getParameters(){
|
||||
public Map getParameters() {
|
||||
Map tempMap = new LinkedHashMap(stringMap);
|
||||
tempMap.putAll(longMap);
|
||||
tempMap.putAll(dateMap);
|
||||
return Collections.unmodifiableMap(tempMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of only string parameters.
|
||||
*
|
||||
* @return String parameters.
|
||||
*/
|
||||
public Map getStringParameters(){
|
||||
public Map getStringParameters() {
|
||||
return Collections.unmodifiableMap(stringMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of only Long parameters
|
||||
*
|
||||
* @return long parameters.
|
||||
*/
|
||||
public Map getLongParameters(){
|
||||
public Map getLongParameters() {
|
||||
return Collections.unmodifiableMap(longMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a map of only Date parameters
|
||||
*
|
||||
* @return date parameters.
|
||||
*/
|
||||
public Map getDateParameters(){
|
||||
public Map getDateParameters() {
|
||||
return Collections.unmodifiableMap(dateMap);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return true if the prameters is empty, false otherwise.
|
||||
*/
|
||||
public boolean isEmpty(){
|
||||
public boolean isEmpty() {
|
||||
return (dateMap.isEmpty() && longMap.isEmpty() && stringMap.isEmpty());
|
||||
}
|
||||
|
||||
/*
|
||||
* Convenience method for validating that a the provided map only contains a particular
|
||||
* type as a value, with only a String as a key.
|
||||
|
||||
/*
|
||||
* Convenience method for validating that a the provided map only contains a particular type as a value, with only a
|
||||
* String as a key.
|
||||
*/
|
||||
private void validateMap(Map map, Class type){
|
||||
|
||||
for(Iterator it = map.entrySet().iterator();it.hasNext();){
|
||||
|
||||
Entry entry = (Entry)it.next();
|
||||
if(entry.getKey() instanceof String == false){
|
||||
private void validateMap(Map map, Class type) {
|
||||
|
||||
for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
|
||||
|
||||
Entry entry = (Entry) it.next();
|
||||
if (entry.getKey() instanceof String == false) {
|
||||
throw new IllegalArgumentException("All parameter keys must be strings.");
|
||||
}
|
||||
if(entry.getValue().getClass() != type){
|
||||
throw new IllegalArgumentException("The values in this map must be of type:[" + type +
|
||||
"].");
|
||||
if (entry.getValue().getClass() != type) {
|
||||
throw new IllegalArgumentException("The values in this map must be of type:[" + type + "].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Convenience method for copying Date values to ensure immutability.
|
||||
*/
|
||||
private Map copyDateMap(Map dateMap){
|
||||
private Map copyDateMap(Map dateMap) {
|
||||
Map tempMap = new LinkedHashMap();
|
||||
|
||||
for(Iterator it = dateMap.entrySet().iterator();it.hasNext();){
|
||||
Entry entry = (Entry)it.next();
|
||||
Date date = (Date)entry.getValue();
|
||||
|
||||
for (Iterator it = dateMap.entrySet().iterator(); it.hasNext();) {
|
||||
Entry entry = (Entry) it.next();
|
||||
Date date = (Date) entry.getValue();
|
||||
tempMap.put(entry.getKey(), new Date(date.getTime()));
|
||||
}
|
||||
|
||||
|
||||
return tempMap;
|
||||
}
|
||||
|
||||
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if(obj instanceof JobParameters == false){
|
||||
|
||||
if (obj instanceof JobParameters == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(this == obj){
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
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())){
|
||||
|
||||
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())) {
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int hashCode() {
|
||||
return new HashCodeBuilder(7, 21).
|
||||
append(stringMap).
|
||||
append(longMap).
|
||||
append(dateMap).
|
||||
toHashCode();
|
||||
return new HashCodeBuilder(7, 21).append(stringMap).append(longMap).append(dateMap).toHashCode();
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
|
||||
return stringMap.toString() + longMap.toString() + dateMap.toString();
|
||||
|
||||
return stringMap.toString() + longMap.toString() + dateMap.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,81 +69,169 @@ public class StepExecution extends Entity {
|
||||
*
|
||||
* @param step the step to which this execution belongs
|
||||
* @param jobExecution the current job execution
|
||||
* @param id the id of this execution
|
||||
*/
|
||||
public StepExecution(StepInstance step, JobExecution jobExecution, Long id) {
|
||||
super(id);
|
||||
this.step = step;
|
||||
this.jobExecution = jobExecution;
|
||||
}
|
||||
|
||||
public StepExecution(StepInstance step, JobExecution jobExecution){
|
||||
|
||||
/**
|
||||
* Constructor that substitutes in null for the execution id
|
||||
*
|
||||
* @param step the step to which this execution belongs
|
||||
* @param jobExecution the current job execution
|
||||
*/
|
||||
public StepExecution(StepInstance step, JobExecution jobExecution) {
|
||||
this(step, jobExecution, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the number of commits in this execution
|
||||
*/
|
||||
public void incrementCommitCount() {
|
||||
commitCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the number of tasks in this execution
|
||||
*/
|
||||
public void incrementTaskCount() {
|
||||
taskCount++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ExecutionAttributes} for this execution
|
||||
*
|
||||
* @return the attributes
|
||||
*/
|
||||
public ExecutionAttributes getExecutionAttributes() {
|
||||
return executionAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link ExecutionAttributes} for this execution
|
||||
*
|
||||
* @param executionAttributes the attributes
|
||||
*/
|
||||
public void setExecutionAttributes(ExecutionAttributes executionAttributes) {
|
||||
this.executionAttributes = executionAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current number of commits for this execution
|
||||
*
|
||||
* @return the current number of commits
|
||||
*/
|
||||
public Integer getCommitCount() {
|
||||
return new Integer(commitCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current number of commits for this execution
|
||||
*
|
||||
* @param commitCount the current number of commits
|
||||
*/
|
||||
public void setCommitCount(int commitCount) {
|
||||
this.commitCount = commitCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time that this execution ended
|
||||
*
|
||||
* @return the time that this execution ended
|
||||
*/
|
||||
public Date getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time that this execution ended
|
||||
*
|
||||
* @param endTime the time that this execution ended
|
||||
*/
|
||||
public void setEndTime(Date endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current number of tasks for this execution
|
||||
*
|
||||
* @return the current number of tasks for this execution
|
||||
*/
|
||||
public Integer getTaskCount() {
|
||||
return new Integer(taskCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current number of tasks for this execution
|
||||
*
|
||||
* @param taskCount the current number of tasks for this execution
|
||||
*/
|
||||
public void setTaskCount(int taskCount) {
|
||||
this.taskCount = taskCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current number of rollbacks for this execution
|
||||
*
|
||||
* @param rollbackCount the current number of rollbacks for this execution
|
||||
*/
|
||||
public void setRollbackCount(int rollbackCount) {
|
||||
this.rollbackCount = rollbackCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current number of rollbacks for this execution
|
||||
*
|
||||
* @return the current number of rollbacks for this execution
|
||||
*/
|
||||
public Integer getRollbackCount() {
|
||||
return new Integer(rollbackCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time this execution started
|
||||
*
|
||||
* @return the time this execution started
|
||||
*/
|
||||
public Date getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time this execution started
|
||||
*
|
||||
* @param startTime the time this execution started
|
||||
*/
|
||||
public void setStartTime(Date startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current status of this step
|
||||
*
|
||||
* @return the current status of this step
|
||||
*/
|
||||
public BatchStatus getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current status of this step
|
||||
*
|
||||
* @param status the current status of this step
|
||||
*/
|
||||
public void setStatus(BatchStatus status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id for this step
|
||||
*
|
||||
* @return the id for this step
|
||||
*/
|
||||
public Long getStepId() {
|
||||
if (step != null) {
|
||||
return step.getId();
|
||||
@@ -153,6 +241,7 @@ public class StepExecution extends Entity {
|
||||
|
||||
/**
|
||||
* Accessor for the job execution id.
|
||||
*
|
||||
* @return the jobExecutionId
|
||||
*/
|
||||
public Long getJobExecutionId() {
|
||||
@@ -164,6 +253,7 @@ public class StepExecution extends Entity {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.container.common.domain.Entity#equals(java.lang.Object)
|
||||
*/
|
||||
public boolean equals(Object obj) {
|
||||
@@ -177,23 +267,24 @@ public class StepExecution extends Entity {
|
||||
return jobExecutionId.equals(other.getJobExecutionId());
|
||||
}
|
||||
return stepId.equals(other.getStepId())
|
||||
&& (jobExecutionId == null || jobExecutionId.equals(other.getJobExecutionId()));
|
||||
&& (jobExecutionId == null || jobExecutionId.equals(other.getJobExecutionId()));
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.container.common.domain.Entity#hashCode()
|
||||
*/
|
||||
public int hashCode() {
|
||||
Object stepId = getStepId();
|
||||
Object jobExecutionId = getJobExecutionId();
|
||||
return super.hashCode() + 31 * (stepId != null ? stepId.hashCode() : 0) + 91
|
||||
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0);
|
||||
* (jobExecutionId != null ? jobExecutionId.hashCode() : 0);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ", name=" + getName() + ", taskCount=" + taskCount + ", commitCount=" + commitCount
|
||||
+ ", rollbackCount=" + rollbackCount;
|
||||
+ ", rollbackCount=" + rollbackCount;
|
||||
}
|
||||
|
||||
private String getName() {
|
||||
@@ -216,6 +307,7 @@ public class StepExecution extends Entity {
|
||||
|
||||
/**
|
||||
* Accessor for the step governing this execution.
|
||||
*
|
||||
* @return the step
|
||||
*/
|
||||
public StepInstance getStep() {
|
||||
@@ -224,8 +316,9 @@ public class StepExecution extends Entity {
|
||||
|
||||
/**
|
||||
* Accessor for the execution context information of the enclosing job.
|
||||
* @return the {@link jobExecutionContext} that was used to start this step
|
||||
* execution.
|
||||
*
|
||||
* @return the {@link JobExecution} that was used to start this step
|
||||
* execution.
|
||||
*/
|
||||
public JobExecution getJobExecution() {
|
||||
return jobExecution;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.batch.core.domain;
|
||||
|
||||
import org.springframework.batch.item.ExecutionAttributes;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
||||
@@ -19,9 +19,8 @@ import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.beans.factory.BeanNameAware;
|
||||
|
||||
/**
|
||||
* Basic no-op support implementation for use as base class for {@link Step}.
|
||||
* Implements {@link BeanNameAware} so that if no name is provided explicitly it
|
||||
* will be inferred from the bean definition in Spring configuration.
|
||||
* Basic no-op support implementation for use as base class for {@link Step}. Implements {@link BeanNameAware} so that
|
||||
* if no name is provided explicitly it will be inferred from the bean definition in Spring configuration.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
@@ -51,21 +50,14 @@ public class StepSupport implements Step, BeanNameAware {
|
||||
this.name = string;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.core.configuration.StepConfiguration#getName()
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name property if it is not already set. Because of the order of
|
||||
* the callbacks in a Spring container the name property will be set first
|
||||
* if it is present. Care is needed with bean definition inheritance - if a
|
||||
* parent bean has a name, then its children need an explicit name as well,
|
||||
* otherwise they will not be unique.
|
||||
* Set the name property if it is not already set. Because of the order of the callbacks in a Spring container the
|
||||
* name property will be set first if it is present. Care is needed with bean definition inheritance - if a parent
|
||||
* bean has a name, then its children need an explicit name as well, otherwise they will not be unique.
|
||||
*
|
||||
* @see org.springframework.beans.factory.BeanNameAware#setBeanName(java.lang.String)
|
||||
*/
|
||||
@@ -76,8 +68,7 @@ public class StepSupport implements Step, BeanNameAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name property. Always overrides the default value if this object
|
||||
* is a Spring bean.
|
||||
* Set the name property. Always overrides the default value if this object is a Spring bean.
|
||||
*
|
||||
* @see #setBeanName(java.lang.String)
|
||||
*/
|
||||
@@ -85,11 +76,6 @@ public class StepSupport implements Step, BeanNameAware {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.core.configuration.StepConfiguration#getStartLimit()
|
||||
*/
|
||||
public int getStartLimit() {
|
||||
return this.startLimit;
|
||||
}
|
||||
@@ -103,11 +89,6 @@ public class StepSupport implements Step, BeanNameAware {
|
||||
this.startLimit = startLimit;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.batch.core.configuration.StepConfiguration#shouldAllowStartIfComplete()
|
||||
*/
|
||||
public boolean isAllowStartIfComplete() {
|
||||
return this.allowStartIfComplete;
|
||||
}
|
||||
@@ -136,9 +117,8 @@ public class StepSupport implements Step, BeanNameAware {
|
||||
*
|
||||
* @see org.springframework.batch.core.domain.Step#execute(org.springframework.batch.core.domain.StepExecution)
|
||||
*/
|
||||
public void execute(StepExecution stepExecution)
|
||||
throws StepInterruptedException, BatchCriticalException {
|
||||
public void execute(StepExecution stepExecution) throws StepInterruptedException, BatchCriticalException {
|
||||
throw new UnsupportedOperationException(
|
||||
"Cannot process a StepExecution. Use a smarter subclass of StepSupport.");
|
||||
"Cannot process a StepExecution. Use a smarter subclass of StepSupport.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user