Package org.springframework.batch.core
Class JobExecution
- java.lang.Object
- org.springframework.batch.core.Entity
- org.springframework.batch.core.JobExecution
- All Implemented Interfaces:
java.io.Serializable
public class JobExecution extends Entity
Batch domain object representing the execution of a job.- Author:
- Lucas Ward, Michael Minella, Mahmoud Ben Hassine, Dimitrios Liapis
- See Also:
- Serialized Form
Constructor Summary
Constructors Constructor Description JobExecution(java.lang.Long id)JobExecution(java.lang.Long id, JobParameters jobParameters)JobExecution(java.lang.Long id, JobParameters jobParameters, java.lang.String jobConfigurationName)JobExecution(JobExecution original)JobExecution(JobInstance job, java.lang.Long id, JobParameters jobParameters, java.lang.String jobConfigurationName)Because a JobExecution isn't valid unless the job is set, this constructor is the only valid one from a modeling point of view.JobExecution(JobInstance job, JobParameters jobParameters)Constructor for transient (unsaved) instances.JobExecution(JobInstance job, JobParameters jobParameters, java.lang.String jobConfigurationName)
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFailureException(java.lang.Throwable t)Add the provided throwable to the failure exception list.voidaddStepExecutions(java.util.List<StepExecution> stepExecutions)Add some step executions.StepExecutioncreateStepExecution(java.lang.String stepName)Register a step execution with the current job execution.java.util.List<java.lang.Throwable>getAllFailureExceptions()Return all failure causing exceptions for this JobExecution, including step executions.java.util.DategetCreateTime()java.util.DategetEndTime()ExecutionContextgetExecutionContext()Returns theExecutionContextfor this execution.ExitStatusgetExitStatus()java.util.List<java.lang.Throwable>getFailureExceptions()java.lang.StringgetJobConfigurationName()java.lang.LonggetJobId()Convenience getter for for the id of the enclosing job.JobInstancegetJobInstance()JobParametersgetJobParameters()java.util.DategetLastUpdated()Get the date representing the last time this JobExecution was updated in the JobRepository.java.util.DategetStartTime()BatchStatusgetStatus()java.util.Collection<StepExecution>getStepExecutions()Accessor for the step executions.booleanisRunning()Test if thisJobExecutionindicates that it is running.booleanisStopping()Test if thisJobExecutionindicates that it has been signalled to stop.voidsetCreateTime(java.util.Date createTime)voidsetEndTime(java.util.Date endTime)voidsetExecutionContext(ExecutionContext executionContext)Sets theExecutionContextfor this executionvoidsetExitStatus(ExitStatus exitStatus)voidsetJobInstance(JobInstance jobInstance)voidsetLastUpdated(java.util.Date lastUpdated)Set the last time this JobExecution was updated.voidsetStartTime(java.util.Date startTime)voidsetStatus(BatchStatus status)Set the value of the status field.voidstop()Signal theJobExecutionto stop.java.lang.StringtoString()voidupgradeStatus(BatchStatus status)Upgrade the status field if the provided value is greater than the existing one.Methods inherited from class org.springframework.batch.core.Entity
equals, getId, getVersion, hashCode, incrementVersion, setId, setVersion
Constructor Detail
JobExecution
public JobExecution(JobExecution original)
JobExecution
public JobExecution(JobInstance job, java.lang.Long id, @Nullable JobParameters jobParameters, java.lang.String jobConfigurationName)
Because a JobExecution isn't valid unless the job is set, this constructor is the only valid one from a modeling point of view.- Parameters:
job- the job of which this execution is a partid-Longthat represents the id for the JobExecution.jobParameters-JobParametersinstance for this JobExecution.jobConfigurationName-Stringinstance that represents the job configuration name (used with JSR-352).
JobExecution
public JobExecution(JobInstance job, JobParameters jobParameters, java.lang.String jobConfigurationName)
JobExecution
public JobExecution(java.lang.Long id, JobParameters jobParameters, java.lang.String jobConfigurationName)
JobExecution
public JobExecution(JobInstance job, JobParameters jobParameters)
Constructor for transient (unsaved) instances.- Parameters:
job- the enclosingJobInstancejobParameters-JobParametersinstance for this JobExecution.
JobExecution
public JobExecution(java.lang.Long id, JobParameters jobParameters)
JobExecution
public JobExecution(java.lang.Long id)
Method Detail
getJobParameters
public JobParameters getJobParameters()
getEndTime
public java.util.Date getEndTime()
setJobInstance
public void setJobInstance(JobInstance jobInstance)
setEndTime
public void setEndTime(java.util.Date endTime)
getStartTime
public java.util.Date getStartTime()
setStartTime
public void setStartTime(java.util.Date startTime)
getStatus
public BatchStatus getStatus()
setStatus
public void setStatus(BatchStatus status)
Set the value of the status field.- Parameters:
status- the status to set
upgradeStatus
public void upgradeStatus(BatchStatus status)
Upgrade the status field if the provided value is greater than the existing one. Clients using this method to set the status can be sure that they don't overwrite a failed status with an successful one.- Parameters:
status- the new status value
getJobId
public java.lang.Long getJobId()
Convenience getter for for the id of the enclosing job. Useful for DAO implementations.- Returns:
- the id of the enclosing job
setExitStatus
public void setExitStatus(ExitStatus exitStatus)
- Parameters:
exitStatus-ExitStatusinstance to be used for job execution.
getExitStatus
public ExitStatus getExitStatus()
- Returns:
- the exitCode
getJobInstance
public JobInstance getJobInstance()
- Returns:
- the Job that is executing.
getStepExecutions
public java.util.Collection<StepExecution> getStepExecutions()
Accessor for the step executions.- Returns:
- the step executions that were registered
createStepExecution
public StepExecution createStepExecution(java.lang.String stepName)
Register a step execution with the current job execution.- Parameters:
stepName- the name of the step the new execution is associated with- Returns:
StepExecutionan emptyStepExecutionassociated with thisJobExecution.
isRunning
public boolean isRunning()
Test if thisJobExecutionindicates that it is running. It should be noted that this does not necessarily mean that it has been persisted as such yet.- Returns:
- true if the end time is null and the start time is not null
isStopping
public boolean isStopping()
Test if thisJobExecutionindicates that it has been signalled to stop.- Returns:
- true if the status is
BatchStatus.STOPPING
stop
public void stop()
Signal theJobExecutionto stop. Iterates through the associatedStepExecutions, callingStepExecution.setTerminateOnly().
setExecutionContext
public void setExecutionContext(ExecutionContext executionContext)
Sets theExecutionContextfor this execution- Parameters:
executionContext- the context
getExecutionContext
public ExecutionContext getExecutionContext()
Returns theExecutionContextfor this execution. The content is expected to be persisted after each step completion (successful or not).- Returns:
- the context
getCreateTime
public java.util.Date getCreateTime()
- Returns:
- the time when this execution was created.
setCreateTime
public void setCreateTime(java.util.Date createTime)
- Parameters:
createTime- creation time of this execution.
getJobConfigurationName
public java.lang.String getJobConfigurationName()
getLastUpdated
public java.util.Date getLastUpdated()
Get the date representing the last time this JobExecution was updated in the JobRepository.- Returns:
- Date representing the last time this JobExecution was updated.
setLastUpdated
public void setLastUpdated(java.util.Date lastUpdated)
Set the last time this JobExecution was updated.- Parameters:
lastUpdated-Dateinstance to mark job execution's lastUpdated attribute.
getFailureExceptions
public java.util.List<java.lang.Throwable> getFailureExceptions()
addFailureException
public void addFailureException(java.lang.Throwable t)
Add the provided throwable to the failure exception list.- Parameters:
t-Throwableinstance to be added failure exception list.
getAllFailureExceptions
public java.util.List<java.lang.Throwable> getAllFailureExceptions()
Return all failure causing exceptions for this JobExecution, including step executions.- Returns:
- List<Throwable> containing all exceptions causing failure for this JobExecution.
addStepExecutions
public void addStepExecutions(java.util.List<StepExecution> stepExecutions)
Add some step executions. For internal use only.- Parameters:
stepExecutions- step executions to add to the current list