diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParametersIncrementer.java similarity index 89% rename from spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementer.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/JobParametersIncrementer.java index 693df68d9..113697a84 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/JobParametersIncrementer.java @@ -13,9 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.batch.core.launch; +package org.springframework.batch.core; -import org.springframework.batch.core.JobParameters; /** * Interface for obtaining the next {@link JobParameters} in a sequence. diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/LastExecutionNotFailedException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobExecutionNotFailedException.java similarity index 84% rename from spring-batch-core/src/main/java/org/springframework/batch/core/launch/LastExecutionNotFailedException.java rename to spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobExecutionNotFailedException.java index 9a4159e6d..f972d7ce1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/LastExecutionNotFailedException.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobExecutionNotFailedException.java @@ -24,12 +24,12 @@ import org.springframework.batch.core.JobExecutionException; * @author Dave Syer * */ -public class LastExecutionNotFailedException extends JobExecutionException { +public class JobExecutionNotFailedException extends JobExecutionException { /** * Create an exception with the given message. */ - public LastExecutionNotFailedException(String msg) { + public JobExecutionNotFailedException(String msg) { super(msg); } @@ -37,7 +37,7 @@ public class LastExecutionNotFailedException extends JobExecutionException { * @param msg The message to send to caller * @param e the cause of the exception */ - public LastExecutionNotFailedException(String msg, Throwable e) { + public JobExecutionNotFailedException(String msg, Throwable e) { super(msg, e); } } 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 dae2c43f5..ae4162f4b 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 @@ -16,6 +16,7 @@ package org.springframework.batch.core.launch; import java.util.Collection; +import java.util.List; import java.util.Map; import org.springframework.batch.core.repository.JobInstanceAlreadyExistsException; @@ -35,23 +36,27 @@ import org.springframework.batch.core.repository.NoSuchJobInstanceException; */ public interface JobOperator { - String getParameters(Long instanceId) throws NoSuchJobInstanceException; - - Long getLastInstance(String jobName) throws NoSuchJobException; + Long getLastExecution(String jobName) throws NoSuchJobException; + + List getLastExecutions(String jobName, int count) throws NoSuchJobException; + + String getParameters(Long executionId) throws NoSuchJobInstanceException; Long start(String jobName, String parameters) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobRestartException; - Long resume(Long instanceId) throws LastExecutionNotFailedException, NoSuchJobInstanceException; + Long resume(Long executionId) throws JobExecutionNotFailedException, NoSuchJobExecutionException; Long startNextInstance(String jobName) throws NoSuchJobException, JobParametersIncrementerNotFoundException; boolean stop(Long executionId) throws NoSuchJobExecutionException; + + String getSummary(Long executionId) throws NoSuchJobExecutionException; - Map status(Long executionId) throws NoSuchJobExecutionException; + Map getStepExecutionSummaries(Long executionId) throws NoSuchJobExecutionException; Collection getRunningExecutions(String jobName) throws NoSuchJobException; - Collection getJobNames(); + Map getJobNamesAndRegistryStatuses(); } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java index 35135647d..022cddb09 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/launch/JobParametersIncrementerNotFoundException.java @@ -16,6 +16,7 @@ package org.springframework.batch.core.launch; import org.springframework.batch.core.JobExecutionException; +import org.springframework.batch.core.JobParametersIncrementer; /** diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java index 881c54492..3575ba106 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java @@ -1,7 +1,7 @@ package org.springframework.batch.core.repository.dao; import org.springframework.beans.factory.InitializingBean; -import org.springframework.jdbc.core.JdbcOperations; +import org.springframework.jdbc.core.simple.SimpleJdbcOperations; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -20,7 +20,7 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { private String tablePrefix = DEFAULT_TABLE_PREFIX; - private JdbcOperations jdbcTemplate; + private SimpleJdbcOperations jdbcTemplate; protected String getQuery(String base) { return StringUtils.replace(base, "%PREFIX%", tablePrefix); @@ -41,11 +41,11 @@ public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { this.tablePrefix = tablePrefix; } - public void setJdbcTemplate(JdbcOperations jdbcTemplate) { + public void setJdbcTemplate(SimpleJdbcOperations jdbcTemplate) { this.jdbcTemplate = jdbcTemplate; } - protected JdbcOperations getJdbcTemplate() { + protected SimpleJdbcOperations getJdbcTemplate() { return jdbcTemplate; } diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java index 552a9c977..6d565a6c1 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcExecutionContextDao.java @@ -56,7 +56,8 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem final ExecutionContext executionContext = new ExecutionContext(); - getJdbcTemplate().query(getQuery(FIND_EXECUTION_CONTEXT), new Object[] { executionId, JOB_DISCRIMINATOR }, + getJdbcTemplate().getJdbcOperations().query(getQuery(FIND_EXECUTION_CONTEXT), + new Object[] { executionId, JOB_DISCRIMINATOR }, new ExecutionContextRowCallbackHandler(executionContext)); return executionContext; @@ -72,7 +73,8 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem final ExecutionContext executionContext = new ExecutionContext(); - getJdbcTemplate().query(getQuery(FIND_EXECUTION_CONTEXT), new Object[] { executionId, STEP_DISCRIMINATOR }, + getJdbcTemplate().getJdbcOperations().query(getQuery(FIND_EXECUTION_CONTEXT), + new Object[] { executionId, STEP_DISCRIMINATOR }, new ExecutionContextRowCallbackHandler(executionContext)); return executionContext; @@ -114,7 +116,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem private void saveOrUpdateExecutionContext(ExecutionContext ctx, Long executionId, String discriminator) { for (Entry entry : ctx.entrySet()) { - + final String key = entry.getKey().toString(); final Object value = entry.getValue(); @@ -182,7 +184,8 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem // LobCreating callbacks always return the affect row count for SQL DML // statements, if less than 1 row // is affected, then this row is new and should be inserted. - Integer affectedRows = (Integer) getJdbcTemplate().execute(getQuery(UPDATE_STEP_EXECUTION_CONTEXT), callback); + Integer affectedRows = (Integer) getJdbcTemplate().getJdbcOperations().execute( + getQuery(UPDATE_STEP_EXECUTION_CONTEXT), callback); if (affectedRows.intValue() < 1) { insertExecutionAttribute(executionId, discriminator, key, value, type); } @@ -232,7 +235,7 @@ public class JdbcExecutionContextDao extends AbstractJdbcBatchMetadataDao implem } } }; - getJdbcTemplate().execute(getQuery(INSERT_STEP_EXECUTION_CONTEXT), callback); + getJdbcTemplate().getJdbcOperations().execute(getQuery(INSERT_STEP_EXECUTION_CONTEXT), callback); } public void setLobHandler(LobHandler lobHandler) { 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 12659df79..3132ef733 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 @@ -12,7 +12,9 @@ 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.jdbc.core.RowMapper; +import org.springframework.dao.DataAccessException; +import org.springframework.jdbc.core.ResultSetExtractor; +import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.util.Assert; @@ -49,6 +51,10 @@ 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 int exitMessageLength = DEFAULT_EXIT_MESSAGE_LENGTH; private DataFieldMaxValueIncrementer jobExecutionIncrementer; @@ -62,14 +68,13 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements this.exitMessageLength = exitMessageLength; } - @SuppressWarnings("unchecked") 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 Object[] { job.getId() }, - new JobExecutionRowMapper(job)); + return getJdbcTemplate().query(getQuery(FIND_JOB_EXECUTIONS), + new JobExecutionRowMapper(job), job.getId()); } /** @@ -94,7 +99,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements jobExecution.getExitStatus().isContinuable() ? "Y" : "N", jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime() }; - getJdbcTemplate().update( + getJdbcTemplate().getJdbcOperations().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.CHAR, @@ -152,7 +157,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements throw new NoSuchObjectException("Invalid JobExecution, ID " + jobExecution.getId() + " not found."); } - getJdbcTemplate().update( + getJdbcTemplate().getJdbcOperations().update( getQuery(UPDATE_JOB_EXECUTION), parameters, new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR, @@ -174,13 +179,47 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements Assert.notNull(jobExecutionIncrementer); } + public JobExecution getLastJobExecution(JobInstance jobInstance) { + + Long id = jobInstance.getId(); + + List executions = getJdbcTemplate().query(getQuery(GET_LAST_EXECUTION), + new JobExecutionRowMapper(jobInstance), id, id); + + Assert.state(executions.size() <= 1, "There must be at most one latest job execution"); + + if (executions.isEmpty()) { + return null; + } + else { + return (JobExecution) executions.get(0); + } + } + + /* + * (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); + } + }; + return (JobExecution) getJdbcTemplate().getJdbcOperations().query(getQuery(FIND_EXECUTIONS_BY_NAME), extractor); + } + /** * Re-usable mapper for {@link JobExecution} instances. * * @author Dave Syer * */ - private class JobExecutionRowMapper implements RowMapper { + private class JobExecutionRowMapper implements ParameterizedRowMapper { private JobInstance job; @@ -189,7 +228,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements this.job = job; } - public Object mapRow(ResultSet rs, int rowNum) throws SQLException { + public JobExecution mapRow(ResultSet rs, int rowNum) throws SQLException { JobExecution jobExecution = new JobExecution(job); jobExecution.setId(new Long(rs.getLong(1))); jobExecution.setStartTime(rs.getTimestamp(2)); @@ -202,22 +241,4 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements } - @SuppressWarnings("unchecked") - public JobExecution getLastJobExecution(JobInstance jobInstance) { - - Long id = jobInstance.getId(); - - List executions = getJdbcTemplate().query(getQuery(GET_LAST_EXECUTION), new Object[] { id, id }, - new JobExecutionRowMapper(jobInstance)); - - Assert.state(executions.size() <= 1, "There must be at most one latest job execution"); - - if (executions.isEmpty()) { - return null; - } - else { - return (JobExecution) executions.get(0); - } - } - } 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 845760dfe..22249c8bf 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 @@ -13,7 +13,7 @@ import org.springframework.batch.core.JobParameter; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParameter.ParameterType; import org.springframework.beans.factory.InitializingBean; -import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -68,7 +68,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements Object[] parameters = new Object[] { jobId, jobName, createJobKey(jobParameters), jobInstance.getVersion() }; - getJdbcTemplate().update(getQuery(CREATE_JOB_INSTANCE), parameters, + getJdbcTemplate().getJdbcOperations().update(getQuery(CREATE_JOB_INSTANCE), parameters, new int[] { Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER }); insertJobParameters(jobId, jobParameters); @@ -123,7 +123,7 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements args = new Object[] { jobId, key, type, "", value, new Long(0), new Double(0) }; } - getJdbcTemplate().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); + getJdbcTemplate().getJdbcOperations().update(getQuery(CREATE_JOB_PARAMETERS), args, argTypes); } /** @@ -134,7 +134,6 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements * @throws IllegalArgumentException if any {@link JobParameters} fields are * null. */ - @SuppressWarnings("unchecked") public JobInstance getJobInstance(final String jobName, final JobParameters jobParameters) { Assert.notNull(jobName, "Job name must not be null."); @@ -142,10 +141,8 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements String jobKey = createJobKey(jobParameters); - Object[] parameters = new Object[] { jobName, jobKey }; - - RowMapper rowMapper = new RowMapper() { - public Object mapRow(ResultSet rs, int rowNum) throws SQLException { + ParameterizedRowMapper rowMapper = new ParameterizedRowMapper() { + public JobInstance mapRow(ResultSet rs, int rowNum) throws SQLException { JobInstance jobInstance = new JobInstance(new Long(rs.getLong(1)), jobParameters, jobName); return jobInstance; } @@ -153,10 +150,10 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements List instances; if (StringUtils.hasLength(jobKey)) { - instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_KEY), parameters, rowMapper); + instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_KEY), rowMapper, jobName, jobKey); } else { - instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_EMPTY_KEY), parameters, rowMapper); + instances = getJdbcTemplate().query(getQuery(FIND_JOBS_WITH_EMPTY_KEY), rowMapper, jobName, jobKey); } if (instances.isEmpty()) { 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 c8bbbce40..36c6d7c46 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 @@ -14,7 +14,7 @@ import org.springframework.batch.core.StepExecution; import org.springframework.batch.repeat.ExitStatus; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.OptimisticLockingFailureException; -import org.springframework.jdbc.core.RowMapper; +import org.springframework.jdbc.core.simple.ParameterizedRowMapper; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; import org.springframework.util.Assert; @@ -95,7 +95,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement stepExecution.getItemCount(), stepExecution.getExitStatus().isContinuable() ? "Y" : "N", stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount() }; - getJdbcTemplate().update( + getJdbcTemplate().getJdbcOperations().update( getQuery(SAVE_STEP_EXECUTION), parameters, new int[] { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, @@ -143,7 +143,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement stepExecution.getExitStatus().getExitCode(), exitDescription, version, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), stepExecution.getId(), stepExecution.getVersion() }; - int count = getJdbcTemplate().update( + int count = getJdbcTemplate().getJdbcOperations().update( getQuery(UPDATE_STEP_EXECUTION), parameters, new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, @@ -180,7 +180,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement } } - private class StepExecutionRowMapper implements RowMapper { + private class StepExecutionRowMapper implements ParameterizedRowMapper { private final JobExecution jobExecution; @@ -191,7 +191,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement this.step = step; } - public Object mapRow(ResultSet rs, int rowNum) throws SQLException { + public StepExecution mapRow(ResultSet rs, int rowNum) throws SQLException { StepExecution stepExecution = new StepExecution(step.getName(), jobExecution, new Long(rs.getLong(1))); stepExecution.setStartTime(rs.getTimestamp(3)); @@ -217,10 +217,9 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement Assert.notNull(stepExecutionIncrementer, "StepExecutionIncrementer cannot be null."); } - @SuppressWarnings("unchecked") public StepExecution getStepExecution(JobExecution jobExecution, Step step) { List executions = getJdbcTemplate().query(getQuery(GET_STEP_EXECUTION), - new Object[] { step.getName(), jobExecution.getId() }, new StepExecutionRowMapper(jobExecution, step)); + 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"); @@ -231,5 +230,4 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement 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 c13b1517d..dd2b9e396 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 @@ -45,4 +45,9 @@ public interface JobExecutionDao { */ JobExecution getLastJobExecution(JobInstance jobInstance); + /** + * @return last JobExecution for given job name. + */ + JobExecution getLastJobExecution(String jobName); + } 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 e31bab7be..b917df540 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 @@ -64,4 +64,23 @@ public class MapJobExecutionDao implements JobExecutionDao { return lastExec; } + /* (non-Javadoc) + * @see org.springframework.batch.core.repository.dao.JobExecutionDao#getLastJobExecution(java.lang.String) + */ + public JobExecution getLastJobExecution(String jobName) { + JobExecution lastExec = null; + for (JobExecution exec : executionsById.values()) { + if (!exec.getJobInstance().getJobName().equals(jobName)) { + continue; + } + if (lastExec == null) { + lastExec = exec; + } + if (lastExec.getCreateTime().before(exec.getCreateTime())) { + lastExec = exec; + } + } + return lastExec; + } + } 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 9a3d90ac5..88fa90b84 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 @@ -30,8 +30,8 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao; import org.springframework.batch.item.database.support.DataFieldMaxValueIncrementerFactory; import org.springframework.batch.item.database.support.DefaultDataFieldMaxValueIncrementerFactory; import org.springframework.beans.factory.FactoryBean; -import org.springframework.jdbc.core.JdbcOperations; -import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.SimpleJdbcOperations; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -48,7 +48,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean { private DataSource dataSource; - private JdbcOperations jdbcTemplate; + private SimpleJdbcOperations jdbcTemplate; private String databaseType; @@ -87,7 +87,7 @@ public class JobRepositoryFactoryBean extends AbstractJobRepositoryFactoryBean { public void afterPropertiesSet() throws Exception { Assert.notNull(dataSource, "DataSource must not be null."); - jdbcTemplate = new JdbcTemplate(dataSource); + jdbcTemplate = new SimpleJdbcTemplate(dataSource); if (incrementerFactory == null) { incrementerFactory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java index 6bcf4f23c..7acf31d4b 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/repository/dao/JdbcJobDaoQueryTests.java @@ -25,6 +25,7 @@ import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParameters; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; /** @@ -63,12 +64,12 @@ public class JdbcJobDaoQueryTests extends TestCase { public void testTablePrefix() throws Exception { jobExecutionDao.setTablePrefix("FOO_"); - jobExecutionDao.setJdbcTemplate(new JdbcTemplate() { + jobExecutionDao.setJdbcTemplate(new SimpleJdbcTemplate(new JdbcTemplate() { public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException { list.add(sql); return 1; } - }); + })); JobExecution jobExecution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "testJob")); jobExecutionDao.saveJobExecution(jobExecution); 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 c55455ed7..30901ed1d 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 @@ -31,7 +31,7 @@ - - + + \ No newline at end of file