diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java index d0eb74c20..23dceb659 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobExecution.java @@ -138,7 +138,7 @@ public class JobExecution extends Entity { * Register a step execution with the current job execution. */ public StepExecution createStepExecution(Step step) { - StepExecution stepExecution = new StepExecution(step.getName(), this, null); + StepExecution stepExecution = new StepExecution(step.getName(), this); this.stepExecutions.add(stepExecution); return stepExecution; } @@ -213,4 +213,13 @@ public class JobExecution extends Entity { public void setCreateTime(Date createTime) { this.createTime = createTime; } + + /** + * Package private method for re-constituting the step executions from + * existing instances. + * @param stepExecution + */ + void addStepExecution(StepExecution stepExecution) { + stepExecutions.add(stepExecution); + } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java index d5e0527ae..c616d9740 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/StepExecution.java @@ -69,10 +69,11 @@ public class StepExecution extends Entity { * @param id the id of this execution */ public StepExecution(String stepName, JobExecution jobExecution, Long id) { - super(id); - Assert.hasLength(stepName); - this.stepName = stepName; - this.jobExecution = jobExecution; + this(stepName, jobExecution); + Assert.notNull(jobExecution, "JobExecution must be provided to re-hydrate an existing StepExecution"); + Assert.notNull(id, "The entity Id must be provided to re-hydrate an existing StepExecution"); + setId(id); + jobExecution.addStepExecution(this); } /** @@ -82,7 +83,10 @@ public class StepExecution extends Entity { * @param jobExecution the current job execution */ public StepExecution(String stepName, JobExecution jobExecution) { - this(stepName, jobExecution, null); + super(); + Assert.hasLength(stepName); + this.stepName = stepName; + this.jobExecution = jobExecution; } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java index ae4162f4b..36c3fc3a2 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobOperator.java @@ -15,15 +15,14 @@ */ package org.springframework.batch.core.launch; -import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import org.springframework.batch.core.repository.JobInstanceAlreadyExistsException; import org.springframework.batch.core.repository.JobRestartException; import org.springframework.batch.core.repository.NoSuchJobException; import org.springframework.batch.core.repository.NoSuchJobExecutionException; -import org.springframework.batch.core.repository.NoSuchJobInstanceException; /** * A really low level interface for inspecting and controlling jobs with access @@ -36,27 +35,28 @@ import org.springframework.batch.core.repository.NoSuchJobInstanceException; */ public interface JobOperator { - Long getLastExecution(String jobName) throws NoSuchJobException; - - List getLastExecutions(String jobName, int count) throws NoSuchJobException; - - String getParameters(Long executionId) throws NoSuchJobInstanceException; + List getExecutions(Long instanceId) throws NoSuchJobException; + + List getLastInstances(String jobName, int count) throws NoSuchJobException; + + Set getRunningExecutions(String jobName) throws NoSuchJobException; + + String getParameters(Long executionId) throws NoSuchJobExecutionException; Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobRestartException; - Long resume(Long executionId) throws JobExecutionNotFailedException, NoSuchJobExecutionException; + Long resume(Long executionId) throws JobExecutionNotFailedException, NoSuchJobExecutionException, + NoSuchJobException; Long startNextInstance(String jobName) throws NoSuchJobException, JobParametersIncrementerNotFoundException; boolean stop(Long executionId) throws NoSuchJobExecutionException; - + String getSummary(Long executionId) throws NoSuchJobExecutionException; Map getStepExecutionSummaries(Long executionId) throws NoSuchJobExecutionException; - Collection getRunningExecutions(String jobName) throws NoSuchJobException; - - Map getJobNamesAndRegistryStatuses(); + Set getJobNames(); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java index 3132ef733..8b33f39cf 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDao.java @@ -3,7 +3,9 @@ package org.springframework.batch.core.repository.dao; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; +import java.util.HashSet; import java.util.List; +import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -12,8 +14,7 @@ import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; -import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.jdbc.core.RowCallbackHandler; import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.util.Assert; @@ -51,14 +52,22 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements private static final String GET_LAST_EXECUTION = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME from %PREFIX%JOB_EXECUTION" + " where JOB_INSTANCE_ID = ? and CREATE_TIME = (SELECT max(CREATE_TIME) from %PREFIX%JOB_EXECUTION where JOB_INSTANCE_ID = ?)"; - private static final String FIND_EXECUTIONS_BY_NAME = "SELECT E.JOB_EXECUTION_ID, E.START_TIME, E.END_TIME, E.STATUS, E.CONTINUABLE, E.EXIT_CODE, E.EXIT_MESSAGE, E.CREATE_TIME, E.JOB_INSTANCE_ID " - + "from BATCH_JOB_EXECUTION E, BATCH_JOB_INSTANCE I " - + "where E.JOB_INSTANCE_ID = I.JOB_INSTANCE_ID and I.JOB_NAME=? ORDER by JOB_EXECUTION_ID desc"; + private static final String GET_INSTANCE_BY_EXECUTION_ID = "SELECT JOB_INSTANCE_ID from %PREFIX%JOB_EXECUTION where JOB_EXECUTION_ID = ?"; + + private static final String GET_EXECUTION_BY_ID = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME from %PREFIX%JOB_EXECUTION" + + " where JOB_EXECUTION_ID = ?"; + + private static final String GET_RUNNING_EXECUTIONS = "SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, JOB_INSTANCE_ID from %PREFIX%JOB_EXECUTION" + + " where END_TIME is NULL"; private int exitMessageLength = DEFAULT_EXIT_MESSAGE_LENGTH; private DataFieldMaxValueIncrementer jobExecutionIncrementer; + private JobInstanceDao jobInstanceDao; + + private StepExecutionDao stepExecutionDao; + /** * Public setter for the exit message length in database. Do not set this if * you haven't modified the schema. @@ -68,13 +77,45 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements this.exitMessageLength = exitMessageLength; } + /** + * Setter for {@link DataFieldMaxValueIncrementer} to be used when + * generating primary keys for {@link JobExecution} instances. + * + * @param jobExecutionIncrementer the {@link DataFieldMaxValueIncrementer} + */ + public void setJobExecutionIncrementer(DataFieldMaxValueIncrementer jobExecutionIncrementer) { + this.jobExecutionIncrementer = jobExecutionIncrementer; + } + + /** + * Public setter for the {@link JobInstanceDao}. + * @param jobInstanceDao the {@link JobInstanceDao} to set + */ + public void setJobInstanceDao(JobInstanceDao jobInstanceDao) { + this.jobInstanceDao = jobInstanceDao; + } + + /** + * Public setter for the {@link StepExecutionDao}. + * @param stepExecutionDao the {@link StepExecutionDao} to set + */ + public void setStepExecutionDao(StepExecutionDao stepExecutionDao) { + this.stepExecutionDao = stepExecutionDao; + } + + public void afterPropertiesSet() throws Exception { + super.afterPropertiesSet(); + Assert.notNull(jobExecutionIncrementer); + Assert.notNull(jobInstanceDao); + Assert.notNull(stepExecutionDao); + } + public List findJobExecutions(final JobInstance job) { Assert.notNull(job, "Job cannot be null."); Assert.notNull(job.getId(), "Job Id cannot be null."); - return getJdbcTemplate().query(getQuery(FIND_JOB_EXECUTIONS), - new JobExecutionRowMapper(job), job.getId()); + return getJdbcTemplate().query(getQuery(FIND_JOB_EXECUTIONS), new JobExecutionRowMapper(job), job.getId()); } /** @@ -164,21 +205,6 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements Types.INTEGER, Types.TIMESTAMP, Types.INTEGER }); } - /** - * Setter for {@link DataFieldMaxValueIncrementer} to be used when - * generating primary keys for {@link JobExecution} instances. - * - * @param jobExecutionIncrementer the {@link DataFieldMaxValueIncrementer} - */ - public void setJobExecutionIncrementer(DataFieldMaxValueIncrementer jobExecutionIncrementer) { - this.jobExecutionIncrementer = jobExecutionIncrementer; - } - - public void afterPropertiesSet() throws Exception { - super.afterPropertiesSet(); - Assert.notNull(jobExecutionIncrementer); - } - public JobExecution getLastJobExecution(JobInstance jobInstance) { Long id = jobInstance.getId(); @@ -200,17 +226,35 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements * (non-Javadoc) * @see org.springframework.batch.core.repository.dao.JobExecutionDao#getLastJobExecution(java.lang.String) */ - public JobExecution getLastJobExecution(String jobName) { - ResultSetExtractor extractor = new ResultSetExtractor() { - public Object extractData(ResultSet rs) throws SQLException, DataAccessException { - if (!rs.next()) { - return null; - } - // TODO use a real job instance (this will barf) - return new JobExecutionRowMapper(null).mapRow(rs, 1); + public JobExecution getJobExecution(Long executionId) { + Long instanceId = getJdbcTemplate().queryForLong(getQuery(GET_INSTANCE_BY_EXECUTION_ID), executionId); + JobInstance jobInstance = jobInstanceDao.getJobInstance(instanceId); + return getJdbcTemplate().queryForObject(getQuery(GET_EXECUTION_BY_ID), new JobExecutionRowMapper(jobInstance), + executionId); + } + + /* + * (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobExecutionDao#findRunningJobExecutions(java.lang.String) + */ + public Set findRunningJobExecutions(String jobName) { + + final Set result = new HashSet(); + RowCallbackHandler handler = new RowCallbackHandler() { + public void processRow(ResultSet rs) throws SQLException { + Long instanceId = rs.getLong("JOB_INSTANCE_ID"); + JobInstance jobInstance = jobInstanceDao.getJobInstance(instanceId); + JobExecutionRowMapper mapper = new JobExecutionRowMapper(jobInstance); + result.add(mapper.mapRow(rs, 0)); } }; - return (JobExecution) getJdbcTemplate().getJdbcOperations().query(getQuery(FIND_EXECUTIONS_BY_NAME), extractor); + getJdbcTemplate().getJdbcOperations().query(getQuery(GET_RUNNING_EXECUTIONS), handler); + + for (JobExecution jobExecution : result) { + stepExecutionDao.getStepExecutions(jobExecution); + } + + return result; } /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java index 22249c8bf..3a3294777 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcJobInstanceDao.java @@ -6,6 +6,7 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.Map.Entry; import org.springframework.batch.core.JobInstance; @@ -165,6 +166,30 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements } } + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobInstanceDao#getJobInstance(java.lang.Long) + */ + public JobInstance getJobInstance(Long instanceId) { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobInstanceDao#getJobNames() + */ + public Set getJobNames() { + // TODO Auto-generated method stub + return null; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobInstanceDao#getLastJobInstances(java.lang.String, int) + */ + public List getLastJobInstances(String jobName, int count) { + // TODO Auto-generated method stub + return null; + } + /** * Setter for {@link DataFieldMaxValueIncrementer} to be used when * generating primary keys for {@link JobInstance} instances. @@ -179,4 +204,5 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements super.afterPropertiesSet(); Assert.notNull(jobIncrementer); } + } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java index 36c6d7c46..e32f70633 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java @@ -9,7 +9,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; @@ -49,8 +48,12 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement + "STATUS = ?, COMMIT_COUNT = ?, ITEM_COUNT = ?, CONTINUABLE = ? , EXIT_CODE = ?, " + "EXIT_MESSAGE = ?, VERSION = ?, READ_SKIP_COUNT = ?, WRITE_SKIP_COUNT = ?, ROLLBACK_COUNT = ? where STEP_EXECUTION_ID = ? and VERSION = ?"; - private static final String GET_STEP_EXECUTION = "SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT," - + " ITEM_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, ROLLBACK_COUNT from %PREFIX%STEP_EXECUTION where STEP_NAME = ? and JOB_EXECUTION_ID = ?"; + private static final String GET_RAW_STEP_EXECUTIONS = "SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT," + + " ITEM_COUNT, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT, WRITE_SKIP_COUNT, ROLLBACK_COUNT from %PREFIX%STEP_EXECUTION where JOB_EXECUTION_ID = ?"; + + private static final String GET_STEP_EXECUTIONS = GET_RAW_STEP_EXECUTIONS + " oreder by STEP_EXECUTION_ID"; + + private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " and STEP_NAME = ?"; private static final String CURRENT_VERSION_STEP_EXECUTION = "SELECT VERSION FROM %PREFIX%STEP_EXECUTION WHERE STEP_EXECUTION_ID=?"; @@ -69,6 +72,15 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement this.exitMessageLength = exitMessageLength; } + public void setStepExecutionIncrementer(DataFieldMaxValueIncrementer stepExecutionIncrementer) { + this.stepExecutionIncrementer = stepExecutionIncrementer; + } + + public void afterPropertiesSet() throws Exception { + super.afterPropertiesSet(); + Assert.notNull(stepExecutionIncrementer, "StepExecutionIncrementer cannot be null."); + } + /** * Save a StepExecution. A unique id will be generated by the * stepExecutionIncrementor, and then set in the StepExecution. All values @@ -180,20 +192,36 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement } } + public StepExecution getStepExecution(JobExecution jobExecution, String stepName) { + List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION), + new StepExecutionRowMapper(jobExecution), jobExecution.getId(), stepName); + + Assert.state(executions.size() <= 1, + "There can be at most one step execution with given name for single job execution"); + if (executions.isEmpty()) { + return null; + } + else { + return (StepExecution) executions.get(0); + } + } + + public List getStepExecutions(JobExecution jobExecution) { + List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTIONS), + new StepExecutionRowMapper(jobExecution), jobExecution.getId()); + return executions; + } + private class StepExecutionRowMapper implements ParameterizedRowMapper { private final JobExecution jobExecution; - private final Step step; - - public StepExecutionRowMapper(JobExecution jobExecution, Step step) { + public StepExecutionRowMapper(JobExecution jobExecution) { this.jobExecution = jobExecution; - this.step = step; } public StepExecution mapRow(ResultSet rs, int rowNum) throws SQLException { - - StepExecution stepExecution = new StepExecution(step.getName(), jobExecution, new Long(rs.getLong(1))); + StepExecution stepExecution = new StepExecution(rs.getString(2), jobExecution, rs.getLong(1)); stepExecution.setStartTime(rs.getTimestamp(3)); stepExecution.setEndTime(rs.getTimestamp(4)); stepExecution.setStatus(BatchStatus.valueOf(rs.getString(5))); @@ -207,27 +235,5 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement } } - - public void setStepExecutionIncrementer(DataFieldMaxValueIncrementer stepExecutionIncrementer) { - this.stepExecutionIncrementer = stepExecutionIncrementer; - } - - public void afterPropertiesSet() throws Exception { - super.afterPropertiesSet(); - Assert.notNull(stepExecutionIncrementer, "StepExecutionIncrementer cannot be null."); - } - - public StepExecution getStepExecution(JobExecution jobExecution, Step step) { - List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION), - new StepExecutionRowMapper(jobExecution, step), step.getName(), jobExecution.getId()); - - Assert.state(executions.size() <= 1, - "There can be at most one step execution with given name for single job execution"); - if (executions.isEmpty()) { - return null; - } - else { - return (StepExecution) executions.get(0); - } - } + } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobExecutionDao.java index dd2b9e396..fc7f2dbc1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobExecutionDao.java @@ -1,6 +1,7 @@ package org.springframework.batch.core.repository.dao; import java.util.List; +import java.util.Set; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; @@ -16,7 +17,8 @@ public interface JobExecutionDao { /** * Save a new JobExecution. * - * Preconditions: jobInstance the jobExecution belongs to must have a jobInstanceId. + * Preconditions: jobInstance the jobExecution belongs to must have a + * jobInstanceId. * * @param jobExecution */ @@ -33,7 +35,8 @@ public interface JobExecutionDao { void updateJobExecution(JobExecution jobExecution); /** - * Return list of JobExecutions for given JobInstance. + * Return all {@link JobExecution} for given {@link JobInstance}, sorted + * backwards by creation order (so the first element is the most recent). * * @param jobInstance * @return list of jobExecutions. @@ -41,13 +44,21 @@ public interface JobExecutionDao { List findJobExecutions(JobInstance jobInstance); /** - * @return last JobExecution for given JobInstance. + * Find the last {@link JobExecution} to have been created for a given {@link JobInstance}. + * @param jobInstance the {@link JobInstance} + * @return the last {@link JobExecution} to execute for this instance */ JobExecution getLastJobExecution(JobInstance jobInstance); /** - * @return last JobExecution for given job name. + * @return all {@link JobExecution} that are still running (or indeterminate + * state), i.e. having null end date, for the specified job name. */ - JobExecution getLastJobExecution(String jobName); + Set findRunningJobExecutions(String jobName); + + /** + * @return the {@link JobExecution} for given identifier. + */ + JobExecution getJobExecution(Long executionId); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java index a3e6dbdae..d24d77ce6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java @@ -1,6 +1,8 @@ package org.springframework.batch.core.repository.dao; -import org.springframework.batch.core.Job; +import java.util.List; +import java.util.Set; + import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; @@ -16,10 +18,11 @@ public interface JobInstanceDao { /** * Create a JobInstance with given name and parameters. * - * PreConditions: JobInstance for given name and parameters must not already exist + * PreConditions: JobInstance for given name and parameters must not already + * exist * - * PostConditions: A valid job instance will be returned which has been persisted and - * contains an unique Id. + * PostConditions: A valid job instance will be returned which has been + * persisted and contains an unique Id. * * @param jobName * @param jobParameters @@ -28,15 +31,41 @@ public interface JobInstanceDao { JobInstance createJobInstance(String jobName, JobParameters jobParameters); /** - * Find all job instances that match the given name and parameters. If no - * matching job instances are found, then a list of size 0 will be - * returned. + * Find the job instance that matches the given name and parameters. If no + * matching job instances are found, then returns null. * - * @param jobName - * @param jobParameters - * @return {@link JobInstance} object matching - * {@link Job} and {@link JobParameters} + * @param jobName the name of the job + * @param jobParameters the parameters with which the job was executed + * @return {@link JobInstance} object matching the job name and + * {@link JobParameters} or null */ JobInstance getJobInstance(String jobName, JobParameters jobParameters); + /** + * Fetch the job instance with the provided identifier. + * + * @param instanceId the job identifier + * @return the job instance with this identifier or null if it doesn't + * exist + */ + JobInstance getJobInstance(Long instanceId); + + /** + * Fetch the last job instances with the provided name, sorted backwards by + * primary key. + * + * + * @param jobName the job name + * @param count the number of objects to return + * @return the job instances with this name or empty if none + */ + List getLastJobInstances(String jobName, int count); + + /** + * Retrieve the names of all job instances - i.e. jobs that have ever been + * executed. + * @return the names of all job instances + */ + Set getJobNames(); + } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java index b917df540..b38a067d6 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobExecutionDao.java @@ -1,8 +1,10 @@ package org.springframework.batch.core.repository.dao; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; @@ -83,4 +85,25 @@ public class MapJobExecutionDao implements JobExecutionDao { return lastExec; } + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobExecutionDao#findRunningJobExecutions(java.lang.String) + */ + public Set findRunningJobExecutions(String jobName) { + Set result = new HashSet(); + for (JobExecution exec : executionsById.values()) { + if (!exec.getJobInstance().getJobName().equals(jobName) || !exec.isRunning()) { + continue; + } + result.add(exec); + } + return result; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobExecutionDao#getJobExecution(java.lang.Long) + */ + public JobExecution getJobExecution(Long executionId) { + return executionsById.get(executionId); + } + } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java index 61901c23d..db7f10c08 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapJobInstanceDao.java @@ -1,6 +1,12 @@ package org.springframework.batch.core.repository.dao; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; @@ -42,4 +48,42 @@ public class MapJobInstanceDao implements JobInstanceDao { } + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobInstanceDao#getJobInstance(java.lang.Long) + */ + public JobInstance getJobInstance(Long instanceId) { + for (JobInstance instance : jobInstances) { + if (instance.getId().equals(instanceId)) { + return instance; + } + } + return null; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobInstanceDao#getJobNames() + */ + public Set getJobNames() { + Set result = new HashSet(); + for (JobInstance instance : jobInstances) { + result.add(instance.getJobName()); + } + return result; + } + + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobInstanceDao#getLastJobInstances(java.lang.String, int) + */ + public List getLastJobInstances(String jobName, int count) { + ArrayList list = new ArrayList(jobInstances); + Collections.sort(list, new Comparator() { + // sort by ID descending + public int compare(JobInstance o1, JobInstance o2) { + return Long.signum(o1.getId()-o2.getId()); + } + }); + int length = count>list.size() ? list.size() : count; + return list.subList(0, length-1); + } + } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java index a3e6624ce..0d0665e05 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/MapStepExecutionDao.java @@ -16,10 +16,14 @@ package org.springframework.batch.core.repository.dao; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; import java.util.Map; +import org.springframework.batch.core.Entity; import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; import org.springframework.dao.OptimisticLockingFailureException; @@ -76,13 +80,24 @@ public class MapStepExecutionDao implements StepExecutionDao { } } - public StepExecution getStepExecution(JobExecution jobExecution, Step step) { + public StepExecution getStepExecution(JobExecution jobExecution, String stepName) { Map executions = executionsByJobExecutionId.get(jobExecution.getId()); if (executions == null) { return null; } - return (StepExecution) executions.get(step.getName()); + return (StepExecution) executions.get(stepName); + } + + public List getStepExecutions(JobExecution jobExecution) { + Map executions = executionsByJobExecutionId.get(jobExecution.getId()); + List result = new ArrayList(executions.values()); + Collections.sort(result, new Comparator() { + public int compare(Entity o1, Entity o2) { + return Long.signum(o2.getId()-o1.getId()); + } + }); + return result; } } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java index 83f79dfa3..6726bbd58 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java @@ -1,7 +1,8 @@ package org.springframework.batch.core.repository.dao; +import java.util.List; + import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.Step; import org.springframework.batch.core.StepExecution; public interface StepExecutionDao { @@ -26,6 +27,22 @@ public interface StepExecutionDao { */ void updateStepExecution(StepExecution stepExecution); - StepExecution getStepExecution(JobExecution jobExecution, Step step); + /** + * Retrieve a {@link StepExecution} from its parent {@link JobExecution} and + * step name. + * + * @param jobExecution the parent job execution + * @param stepName the name of the step that was used to create the step execution + * @return a {@link StepExecution} + */ + StepExecution getStepExecution(JobExecution jobExecution, String stepName); + + /** + * Retrieve all the {@link StepExecution} for the parent {@link JobExecution}. + * + * @param jobExecution the parent job execution + * @return a list of {@link StepExecution} + */ + List getStepExecutions(JobExecution jobExecution); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java index 88fa90b84..c242b4a2d 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBean.java @@ -114,6 +114,8 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean { dao.setJdbcTemplate(jdbcTemplate); dao.setJobExecutionIncrementer(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")); + dao.setJobInstanceDao(createJobInstanceDao()); + dao.setStepExecutionDao(createStepExecutionDao()); dao.setTablePrefix(tablePrefix); dao.afterPropertiesSet(); return dao; diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java index c04b0495b..4ff91463f 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java @@ -267,7 +267,7 @@ public class SimpleJobRepository implements JobRepository { List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); List stepExecutions = new ArrayList(jobExecutions.size()); for (JobExecution jobExecution : jobExecutions) { - StepExecution stepExecution = stepExecutionDao.getStepExecution(jobExecution, step); + StepExecution stepExecution = stepExecutionDao.getStepExecution(jobExecution, step.getName()); if (stepExecution != null) { stepExecutions.add(stepExecution); } @@ -295,7 +295,7 @@ public class SimpleJobRepository implements JobRepository { int count = 0; List jobExecutions = jobExecutionDao.findJobExecutions(jobInstance); for (JobExecution jobExecution : jobExecutions) { - if (stepExecutionDao.getStepExecution(jobExecution, step) != null) { + if (stepExecutionDao.getStepExecution(jobExecution, step.getName()) != null) { count++; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java index b53d369d3..16b962bc6 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/job/SimpleJobTests.java @@ -126,8 +126,8 @@ public class SimpleJobTests extends TestCase { jobExecution = jobRepository.createJobExecution(job, jobParameters); jobInstance = jobExecution.getJobInstance(); - stepExecution1 = new StepExecution(step1.getName(), jobExecution, null); - stepExecution2 = new StepExecution(step2.getName(), jobExecution, null); + stepExecution1 = new StepExecution(step1.getName(), jobExecution); + stepExecution2 = new StepExecution(step2.getName(), jobExecution); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java index 24d6263fc..0907eb3a4 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractJobExecutionDaoTests.java @@ -6,11 +6,14 @@ import org.junit.Test; import java.util.Date; import java.util.List; +import java.util.Set; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.StepExecution; +import org.springframework.batch.core.step.StepSupport; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.transaction.annotation.Transactional; @@ -27,6 +30,13 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional */ protected abstract JobExecutionDao getJobExecutionDao(); + /** + * @return tested object ready for use + */ + protected StepExecutionDao getStepExecutionDao() { + return null; + } + @Before public void onSetUp() throws Exception { dao = getJobExecutionDao(); @@ -35,7 +45,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional /** * Save and find a job execution. */ - @Transactional @Test + @Transactional + @Test public void testSaveAndFind() { dao.saveJobExecution(execution); @@ -48,7 +59,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional /** * Saving sets id to the entity. */ - @Transactional @Test + @Transactional + @Test public void testSaveAddsIdAndVersion() { assertNull(execution.getId()); @@ -62,7 +74,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional * Update and retrieve job execution - check attributes have changed as * expected. */ - @Transactional @Test + @Transactional + @Test public void testUpdateExecution() { execution.setStatus(BatchStatus.STARTED); dao.saveJobExecution(execution); @@ -78,7 +91,8 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional /** * Check the execution with most recent start time is returned */ - @Transactional @Test + @Transactional + @Test public void testGetLastExecution() { JobExecution exec1 = new JobExecution(jobInstance); exec1.setCreateTime(new Date(0)); @@ -92,5 +106,47 @@ public abstract class AbstractJobExecutionDaoTests extends AbstractTransactional JobExecution last = dao.getLastJobExecution(jobInstance); assertEquals(exec2, last); } - + + /** + * Check the execution is returned + */ + @Transactional + @Test + public void testFindRunningExecutions() { + JobExecution exec = new JobExecution(jobInstance); + exec.setCreateTime(new Date(0)); + exec.setEndTime(new Date(0)); + dao.saveJobExecution(exec); + exec = new JobExecution(jobInstance); + exec.createStepExecution(new StepSupport("foo")); + dao.saveJobExecution(exec); + StepExecutionDao stepExecutionDao = getStepExecutionDao(); + if (stepExecutionDao != null) { + for (StepExecution stepExecution : exec.getStepExecutions()) { + stepExecutionDao.saveStepExecution(stepExecution); + } + } + Set values = dao.findRunningJobExecutions(exec.getJobInstance().getJobName()); + + assertEquals(1, values.size()); + JobExecution value = values.iterator().next(); + assertEquals(exec, value); + assertEquals(1, value.getStepExecutions().size()); + } + + /** + * Check the execution is returned + */ + @Transactional + @Test + public void testGetExecution() { + JobExecution exec = new JobExecution(jobInstance); + exec.setCreateTime(new Date(0)); + + dao.saveJobExecution(exec); + JobExecution value = dao.getJobExecution(exec.getId()); + + assertEquals(exec, value); + } + } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java index 92df02cb7..f6a5bf3e3 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/AbstractStepExecutionDaoTests.java @@ -16,10 +16,15 @@ package org.springframework.batch.core.repository.dao; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.List; + import org.junit.Before; import org.junit.Test; - import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; @@ -93,19 +98,32 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona stepExecution.setRollbackCount(3); dao.saveStepExecution(stepExecution); - StepExecution retrieved = dao.getStepExecution(jobExecution, step); + StepExecution retrieved = dao.getStepExecution(jobExecution, step.getName()); assertEquals(stepExecution, retrieved); assertEquals(BatchStatus.STARTED, retrieved.getStatus()); assertEquals(stepExecution.getReadSkipCount(), retrieved.getReadSkipCount()); assertEquals(stepExecution.getWriteSkipCount(), retrieved.getWriteSkipCount()); assertEquals(stepExecution.getRollbackCount(), retrieved.getRollbackCount()); - assertNull(dao.getStepExecution(jobExecution, new StepSupport("not-existing step"))); + assertNull(dao.getStepExecution(jobExecution, "not-existing step")); + } + + @Transactional @Test + public void testSaveAndGetExecution() { + + stepExecution.setStatus(BatchStatus.STARTED); + stepExecution.setReadSkipCount(7); + stepExecution.setWriteSkipCount(5); + stepExecution.setRollbackCount(3); + dao.saveStepExecution(stepExecution); + + List retrieved = dao.getStepExecutions(jobExecution); + assertEquals(stepExecution, retrieved.get(0)); } @Transactional @Test public void testGetForNotExistingJobExecution() { - assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777), step)); + assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777), step.getName())); } /** @@ -152,7 +170,7 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona dao.updateStepExecution(stepExecution); assertEquals(versionAfterSave + 1, stepExecution.getVersion().intValue()); - StepExecution retrieved = dao.getStepExecution(jobExecution, step); + StepExecution retrieved = dao.getStepExecution(jobExecution, step.getName()); assertEquals(stepExecution, retrieved); assertEquals(BatchStatus.STOPPED, retrieved.getStatus()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java index db6f49bad..c6e4dd348 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobExecutionDaoTests.java @@ -1,21 +1,36 @@ package org.springframework.batch.core.repository.dao; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.junit.runner.RunWith; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = {"sql-dao-test.xml"}) +@ContextConfiguration(locations = { "sql-dao-test.xml" }) public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests { + @Autowired + private StepExecutionDao stepExecutionDao; + + @Autowired + private JobExecutionDao jobExecutionDao; + + @Override protected JobExecutionDao getJobExecutionDao() { - deleteFromTables("BATCH_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", - "BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE"); + deleteFromTables("BATCH_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", + "BATCH_JOB_INSTANCE"); // job instance needs to exist before job execution can be created - simpleJdbcTemplate.getJdbcOperations().execute( - "insert into BATCH_JOB_INSTANCE (JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (1,'execTestJob', '', 0)"); - return (JobExecutionDao) applicationContext.getBean("jobExecutionDao"); + simpleJdbcTemplate + .getJdbcOperations() + .execute( + "insert into BATCH_JOB_INSTANCE (JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (1,'execTestJob', '', 0)"); + return jobExecutionDao; + } + + @Override + protected StepExecutionDao getStepExecutionDao() { + return stepExecutionDao; } } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java index 1c6d81a2a..2fa9ce0be 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDaoTests.java @@ -1,14 +1,14 @@ package org.springframework.batch.core.repository.dao; -import static org.junit.Assert.*; -import org.junit.runner.RunWith; -import org.junit.Test; +import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.repository.JobRepository; import org.springframework.batch.repeat.ExitStatus; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; @RunWith(SpringJUnit4ClassRunner.class) @@ -44,14 +44,14 @@ public class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests { ((JdbcStepExecutionDao) dao).setExitMessageLength(250); dao.saveStepExecution(stepExecution); - StepExecution retrievedAfterSave = dao.getStepExecution(jobExecution, step); + StepExecution retrievedAfterSave = dao.getStepExecution(jobExecution, step.getName()); assertTrue("Exit description should be truncated", retrievedAfterSave.getExitStatus().getExitDescription() .length() < stepExecution.getExitStatus().getExitDescription().length()); dao.updateStepExecution(stepExecution); - StepExecution retrievedAfterUpdate = dao.getStepExecution(jobExecution, step); + StepExecution retrievedAfterUpdate = dao.getStepExecution(jobExecution, step.getName()); assertTrue("Exit description should be truncated", retrievedAfterUpdate.getExitStatus().getExitDescription() .length() < stepExecution.getExitStatus().getExitDescription().length()); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java index 77c9ff0f7..994a37903 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/JobRepositoryFactoryBeanTests.java @@ -140,9 +140,9 @@ public class JobRepositoryFactoryBeanTests { expect(incrementerFactory.isSupportedIncrementerType("foo")).andReturn(true); expect(incrementerFactory.getSupportedIncrementerTypes()).andReturn(new String[0]); - expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer()); + expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_SEQ")).andReturn(new StubIncrementer()).times(2); expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "JOB_EXECUTION_SEQ")).andReturn(new StubIncrementer()); - expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer()); + expect(incrementerFactory.getIncrementer(databaseType, tablePrefix + "STEP_EXECUTION_SEQ")).andReturn(new StubIncrementer()).times(2); replay(incrementerFactory); factory.afterPropertiesSet(); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MockStepDao.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MockStepDao.java deleted file mode 100644 index 80c85497b..000000000 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/MockStepDao.java +++ /dev/null @@ -1,37 +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.core.repository.support; - -import org.springframework.batch.core.JobExecution; -import org.springframework.batch.core.Step; -import org.springframework.batch.core.StepExecution; -import org.springframework.batch.core.repository.dao.StepExecutionDao; - -public class MockStepDao implements StepExecutionDao { - - - public void saveStepExecution(StepExecution stepExecution) { - } - - public void updateStepExecution(StepExecution stepExecution) { - } - - public StepExecution getStepExecution(JobExecution jobExecution, Step step) { - return null; - } - -} diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java index 3a928c1d4..79101b14e 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java @@ -136,7 +136,7 @@ public class SimpleJobRepositoryTests extends TestCase { public void testSaveOrUpdateStepExecutionException() { - StepExecution stepExecution = new StepExecution("stepName", null, null); + StepExecution stepExecution = new StepExecution("stepName", null); // failure scenario -- no step id set. try { diff --git a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml index 30901ed1d..ece4ec636 100644 --- a/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml +++ b/spring-batch-core/src/test/resources/org/springframework/batch/core/repository/dao/sql-dao-test.xml @@ -1,37 +1,38 @@ - + - + - - + + - + - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file