diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java index 4793bc085..6ba02ba0a 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/SimpleJobRepository.java @@ -177,13 +177,23 @@ public class SimpleJobRepository implements JobRepository { throw new BatchRestartException("Restart Max exceeded for Job: " + jobInstance.toString()); } List executions = jobExecutionDao.findJobExecutions(jobInstance); + JobExecution lastExecution = null; + // check for running executions and find the last started for (Iterator iterator = executions.iterator(); iterator.hasNext();) { JobExecution execution = (JobExecution) iterator.next(); + if (lastExecution == null) { + lastExecution = execution; + } + if (lastExecution.getStartTime().getTime() < execution.getStartTime().getTime()) { + lastExecution = execution; + } + if (execution.isRunning()) { throw new JobExecutionAlreadyRunningException("A job execution for this job is already running: " + jobInstance); } } + jobInstance.setLastExecution(lastExecution); } else if (jobs.size() == 0) { // no job found, create one @@ -242,12 +252,7 @@ public class SimpleJobRepository implements JobRepository { * @throws IllegalArgumentException if Job or it's Id is null. */ public void update(JobInstance job) { - - Assert.notNull(job, "Job cannot be null."); - Assert.notNull(job.getId(), "Job cannot be updated if it's ID is null. It must be obtained" - + "from SimpleJobRepository.findOrCreateJob to be considered valid."); - - jobInstanceDao.updateJobInstance(job); + //TODO no-op to be removed } /** diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobExecutionDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobExecutionDao.java index 506334658..c8254c316 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobExecutionDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobExecutionDao.java @@ -34,22 +34,22 @@ import org.springframework.util.Assert; public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean { private static final Log logger = LogFactory.getLog(JdbcJobExecutionDao.class); - + private static final int EXIT_MESSAGE_LENGTH = 250; - + private static final String GET_JOB_EXECUTION_COUNT = "SELECT count(JOB_EXECUTION_ID) from %PREFIX%JOB_EXECUTION " - + "where JOB_INSTANCE_ID = ?"; - + + "where JOB_INSTANCE_ID = ?"; + private static final String SAVE_JOB_EXECUTION = "INSERT into %PREFIX%JOB_EXECUTION(JOB_EXECUTION_ID, JOB_INSTANCE_ID, START_TIME, " - + "END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE) values (?, ?, ?, ?, ?, ?, ?, ?)"; + + "END_TIME, STATUS, CONTINUABLE, EXIT_CODE, EXIT_MESSAGE) values (?, ?, ?, ?, ?, ?, ?, ?)"; private static final String CHECK_JOB_EXECUTION_EXISTS = "SELECT COUNT(*) FROM %PREFIX%JOB_EXECUTION WHERE JOB_EXECUTION_ID = ?"; private static final String UPDATE_JOB_EXECUTION = "UPDATE %PREFIX%JOB_EXECUTION set START_TIME = ?, END_TIME = ?, " - + " STATUS = ?, CONTINUABLE = ?, EXIT_CODE = ?, EXIT_MESSAGE = ? where JOB_EXECUTION_ID = ?"; + + " STATUS = ?, CONTINUABLE = ?, EXIT_CODE = ?, EXIT_MESSAGE = ? where JOB_EXECUTION_ID = ?"; private DataFieldMaxValueIncrementer jobExecutionIncrementer; - + public List findJobExecutions(final JobInstance job) { Assert.notNull(job, "Job cannot be null."); @@ -83,8 +83,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements /** * @see JobDao#getJobExecutionCount(JobInstance) - * @throws IllegalArgumentException - * if jobId is null. + * @throws IllegalArgumentException if jobId is null. */ public int getJobExecutionCount(Long jobId) { @@ -92,8 +91,7 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements Object[] parameters = new Object[] { jobId }; - return getJdbcTemplate() - .queryForInt(getQuery(GET_JOB_EXECUTION_COUNT), parameters); + return getJdbcTemplate().queryForInt(getQuery(GET_JOB_EXECUTION_COUNT), parameters); } /** @@ -103,41 +101,38 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements * via a SQL INSERT statement. * * @see JobDao#saveJobExecution(JobExecution) - * @throws IllegalArgumentException - * if jobExecution is null, as well as any of it's fields to be - * persisted. + * @throws IllegalArgumentException if jobExecution is null, as well as any + * of it's fields to be persisted. */ public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.setId(new Long(jobExecutionIncrementer.nextLongValue())); - Object[] parameters = new Object[] { jobExecution.getId(), - jobExecution.getJobId(), jobExecution.getStartTime(), - jobExecution.getEndTime(), jobExecution.getStatus().toString(), - jobExecution.getExitStatus().isContinuable() ? "Y" : "N", - jobExecution.getExitStatus().getExitCode(), + Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), + jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), + jobExecution.getExitStatus().isContinuable() ? "Y" : "N", jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription() }; - getJdbcTemplate().update(getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { - Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, - Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR }); + getJdbcTemplate().update( + getQuery(SAVE_JOB_EXECUTION), + parameters, + new int[] { Types.INTEGER, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.CHAR, + Types.VARCHAR, Types.VARCHAR }); } - + /** * Validate JobExecution. At a minimum, JobId, StartTime, EndTime, and * Status cannot be null. * - * @param jobExecution @throws IllegalArgumentException + * @param jobExecution + * @throws IllegalArgumentException */ private void validateJobExecution(JobExecution jobExecution) { Assert.notNull(jobExecution); - Assert.notNull(jobExecution.getJobId(), - "JobExecution Job-Id cannot be null."); - Assert.notNull(jobExecution.getStartTime(), - "JobExecution start time cannot be null."); - Assert.notNull(jobExecution.getStatus(), - "JobExecution status cannot be null."); + Assert.notNull(jobExecution.getJobId(), "JobExecution Job-Id cannot be null."); + Assert.notNull(jobExecution.getStartTime(), "JobExecution start time cannot be null."); + Assert.notNull(jobExecution.getStatus(), "JobExecution status cannot be null."); } /** @@ -152,56 +147,45 @@ public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements validateJobExecution(jobExecution); - String exitDescription = jobExecution.getExitStatus() - .getExitDescription(); - if (exitDescription != null - && exitDescription.length() > EXIT_MESSAGE_LENGTH) { + String exitDescription = jobExecution.getExitStatus().getExitDescription(); + if (exitDescription != null && exitDescription.length() > EXIT_MESSAGE_LENGTH) { exitDescription = exitDescription.substring(0, EXIT_MESSAGE_LENGTH); - logger - .debug("Truncating long message before update of JobExecution: " - + jobExecution); + logger.debug("Truncating long message before update of JobExecution: " + jobExecution); } - Object[] parameters = new Object[] { jobExecution.getStartTime(), - jobExecution.getEndTime(), jobExecution.getStatus().toString(), - jobExecution.getExitStatus().isContinuable() ? "Y" : "N", - jobExecution.getExitStatus().getExitCode(), exitDescription, - jobExecution.getId() }; + Object[] parameters = new Object[] { jobExecution.getStartTime(), jobExecution.getEndTime(), + jobExecution.getStatus().toString(), jobExecution.getExitStatus().isContinuable() ? "Y" : "N", + jobExecution.getExitStatus().getExitCode(), exitDescription, jobExecution.getId() }; if (jobExecution.getId() == null) { - throw new IllegalArgumentException( - "JobExecution ID cannot be null. JobExecution must be saved " - + "before it can be updated."); + throw new IllegalArgumentException("JobExecution ID cannot be null. JobExecution must be saved " + + "before it can be updated."); } // Check if given JobExecution's Id already exists, if none is found it // is invalid and // an exception should be thrown. - if (getJdbcTemplate().queryForInt(getQuery(CHECK_JOB_EXECUTION_EXISTS), - new Object[] { jobExecution.getId() }) != 1) { - throw new NoSuchBatchDomainObjectException( - "Invalid JobExecution, ID " + jobExecution.getId() - + " not found."); + if (getJdbcTemplate().queryForInt(getQuery(CHECK_JOB_EXECUTION_EXISTS), new Object[] { jobExecution.getId() }) != 1) { + throw new NoSuchBatchDomainObjectException("Invalid JobExecution, ID " + jobExecution.getId() + + " not found."); } - getJdbcTemplate() - .update(getQuery(UPDATE_JOB_EXECUTION), parameters, - new int[] { Types.TIMESTAMP, Types.TIMESTAMP, - Types.VARCHAR, Types.CHAR, Types.VARCHAR, - Types.VARCHAR, Types.INTEGER }); + getJdbcTemplate().update( + getQuery(UPDATE_JOB_EXECUTION), + parameters, + new int[] { Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.CHAR, Types.VARCHAR, Types.VARCHAR, + Types.INTEGER }); } - + /** * Setter for {@link DataFieldMaxValueIncrementer} to be used when * generating primary keys for {@link JobExecution} instances. * - * @param jobExecutionIncrementer - * the {@link DataFieldMaxValueIncrementer} + * @param jobExecutionIncrementer the {@link DataFieldMaxValueIncrementer} */ - public void setJobExecutionIncrementer( - DataFieldMaxValueIncrementer jobExecutionIncrementer) { + public void setJobExecutionIncrementer(DataFieldMaxValueIncrementer jobExecutionIncrementer) { this.jobExecutionIncrementer = jobExecutionIncrementer; } - + public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); Assert.notNull(jobExecutionIncrementer); diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java index 58ce99281..542219cec 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcJobInstanceDao.java @@ -9,7 +9,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.beans.factory.InitializingBean; @@ -38,13 +37,9 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements private static final String CREATE_JOB_PARAMETERS = "INSERT into %PREFIX%JOB_PARAMS(JOB_INSTANCE_ID, KEY_NAME, TYPE_CD, " + "STRING_VAL, DATE_VAL, LONG_VAL) values (?, ?, ?, ?, ?, ?)"; - private static final String FIND_JOBS = "SELECT JOB_INSTANCE_ID, LAST_JOB_EXECUTION_ID from %PREFIX%JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?"; - - private static final String UPDATE_JOB = "UPDATE %PREFIX%JOB_INSTANCE set LAST_JOB_EXECUTION_ID = ? where JOB_INSTANCE_ID = ?"; + private static final String FIND_JOBS = "SELECT JOB_INSTANCE_ID from %PREFIX%JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?"; private DataFieldMaxValueIncrementer jobIncrementer; - - private JobExecutionDao jobExecutionDao; /** * In this jdbc implementation a job id is obtained by asking the @@ -146,27 +141,19 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements * given identifier, adding them to a list via the RowMapper callback. * * @see JobDao#findJobInstances(JobIdentifier) - * @throws IllegalArgumentException - * if any {@link JobIdentifier} fields are null. + * @throws IllegalArgumentException if any {@link JobIdentifier} fields are + * null. */ public List findJobInstances(final String jobName, final JobParameters jobParameters) { Assert.notNull(jobName, "Job Name must not be null."); Assert.notNull(jobParameters, "JobParameters must not be null."); - Object[] parameters = new Object[] { jobName, - createJobKey(jobParameters) }; + Object[] parameters = new Object[] { jobName, createJobKey(jobParameters) }; RowMapper rowMapper = new RowMapper() { public Object mapRow(ResultSet rs, int rowNum) throws SQLException { - JobInstance jobInstance = new JobInstance(new Long(rs.getLong(1)), jobParameters); - long lastExecutionId = rs.getLong(2); - JobExecution lastExecution = jobExecutionDao.getJobExecution(new Long(lastExecutionId)); - if(lastExecution != null){ - lastExecution.setJobInstance(jobInstance); - } - jobInstance.setLastExecution(lastExecution); return jobInstance; } }; @@ -174,22 +161,6 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements return getJdbcTemplate().query(getQuery(FIND_JOBS), parameters, rowMapper); } - /** - * @see JobDao#updateJobInstance(JobInstance) - * @throws IllegalArgumentException - * if Job, Job.status, or job.id is null - */ - public void updateJobInstance(JobInstance jobInstance) { - - Assert.notNull(jobInstance, "Job Cannot be Null"); - Assert.notNull(jobInstance.getId(), "Job ID cannot be null"); - - Long lastExecutionId = jobInstance.getLastExecution() == null ? null : jobInstance.getLastExecution().getId(); - Object[] parameters = new Object[] { lastExecutionId, jobInstance.getId() }; - getJdbcTemplate().update(getQuery(UPDATE_JOB), parameters, new int[] { - Types.INTEGER, Types.INTEGER}); - } - /** * Setter for {@link DataFieldMaxValueIncrementer} to be used when * generating primary keys for {@link JobInstance} instances. @@ -199,18 +170,12 @@ public class JdbcJobInstanceDao extends AbstractJdbcBatchMetadataDao implements public void setJobIncrementer(DataFieldMaxValueIncrementer jobIncrementer) { this.jobIncrementer = jobIncrementer; } - - public void setJobExecutionDao(JobExecutionDao jobExecutionDao) { - this.jobExecutionDao = jobExecutionDao; - } public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); - Assert.notNull(jobExecutionDao); Assert.notNull(jobIncrementer); } - private static class ParameterType { private final String type; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java index e81c4f961..81ea2d30c 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JdbcStepExecutionDao.java @@ -180,7 +180,7 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao List executions = getJdbcTemplate().query(getQuery(FIND_LAST_STEP_EXECUTION), new Object[] { stepInstanceId, stepInstanceId }, new StepExecutionRowMapper(stepInstance)); - Assert.state(executions.size() <= 1, "There must be at most one latest execution"); + Assert.state(executions.size() <= 1, "There must be at most one latest step execution"); if (executions.size() == 0) { return null; diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobExecutionDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobExecutionDao.java index 1de857560..c7e0aadfd 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobExecutionDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobExecutionDao.java @@ -58,4 +58,9 @@ public interface JobExecutionDao { * execution is found for the given id. */ JobExecution getJobExecution(Long jobExecutionId); + +// /** +// * @return return the last execution for the given instance +// */ +// JobExecution getLastJobExecution(JobInstance jobInstance); } diff --git a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java index 5e5ef7bbb..a0afe9b82 100644 --- a/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java +++ b/spring-batch-execution/src/main/java/org/springframework/batch/execution/repository/dao/JobInstanceDao.java @@ -38,12 +38,4 @@ public interface JobInstanceDao { */ List findJobInstances(String jobName, JobParameters jobParameters); - /** - * Update an existing JobInstance. - * - * Preconditions: jobInstance must have an ID. - * - * @param jobInstance - */ - void updateJobInstance(JobInstance jobInstance); } diff --git a/spring-batch-execution/src/main/resources/schema-db2.sql b/spring-batch-execution/src/main/resources/schema-db2.sql index 37665bd19..db7fe1745 100644 --- a/spring-batch-execution/src/main/resources/schema-db2.sql +++ b/spring-batch-execution/src/main/resources/schema-db2.sql @@ -16,8 +16,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT PRIMARY KEY , diff --git a/spring-batch-execution/src/main/resources/schema-derby.sql b/spring-batch-execution/src/main/resources/schema-derby.sql index df37702c5..1171d4358 100644 --- a/spring-batch-execution/src/main/resources/schema-derby.sql +++ b/spring-batch-execution/src/main/resources/schema-derby.sql @@ -16,8 +16,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, diff --git a/spring-batch-execution/src/main/resources/schema-hsqldb.sql b/spring-batch-execution/src/main/resources/schema-hsqldb.sql index 6ef6ca2e7..269abc738 100644 --- a/spring-batch-execution/src/main/resources/schema-hsqldb.sql +++ b/spring-batch-execution/src/main/resources/schema-hsqldb.sql @@ -16,8 +16,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT IDENTITY PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT IDENTITY PRIMARY KEY , diff --git a/spring-batch-execution/src/main/resources/schema-mysql.sql b/spring-batch-execution/src/main/resources/schema-mysql.sql index 79cd03e37..15fa7c74a 100644 --- a/spring-batch-execution/src/main/resources/schema-mysql.sql +++ b/spring-batch-execution/src/main/resources/schema-mysql.sql @@ -16,8 +16,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT unsigned PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT unsigned PRIMARY KEY , diff --git a/spring-batch-execution/src/main/resources/schema-oracle10g.sql b/spring-batch-execution/src/main/resources/schema-oracle10g.sql index 88f5ce1ed..1a6e0a481 100644 --- a/spring-batch-execution/src/main/resources/schema-oracle10g.sql +++ b/spring-batch-execution/src/main/resources/schema-oracle10g.sql @@ -16,8 +16,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID NUMBER(38) PRIMARY KEY , VERSION NUMBER(38), JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID NUMBER(38) PRIMARY KEY , diff --git a/spring-batch-execution/src/main/resources/schema-postgresql.sql b/spring-batch-execution/src/main/resources/schema-postgresql.sql index 37665bd19..db7fe1745 100644 --- a/spring-batch-execution/src/main/resources/schema-postgresql.sql +++ b/spring-batch-execution/src/main/resources/schema-postgresql.sql @@ -16,8 +16,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT PRIMARY KEY , diff --git a/spring-batch-execution/src/main/sql/init.sql.vpp b/spring-batch-execution/src/main/sql/init.sql.vpp index aafb9e134..789aa3bae 100644 --- a/spring-batch-execution/src/main/sql/init.sql.vpp +++ b/spring-batch-execution/src/main/sql/init.sql.vpp @@ -3,8 +3,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID ${BIGINT} $!{IDENTITY} PRIMARY KEY $!{GENERATED}, VERSION ${BIGINT}, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID ${BIGINT} $!{IDENTITY} PRIMARY KEY $!{GENERATED}, diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java index c5b73dafc..27a22ddae 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java @@ -197,7 +197,6 @@ public class SimpleJobRepositoryTests extends TestCase { jobDaoControl.setReturnValue(1); jobDao.findJobExecutions(databaseJob); jobDaoControl.setReturnValue(executions); - jobDao.updateJobInstance(databaseJob); jobDao.saveJobExecution(new JobExecution(databaseJob)); jobDaoControl.setMatcher(new ArgumentsMatcher() { public boolean matches(Object[] expected, Object[] actual) { @@ -326,26 +325,6 @@ public class SimpleJobRepositoryTests extends TestCase { assertTrue(step.equals(databaseStep2)); } - public void testUpdateJob() { - - // failure scenario - no ID - JobInstance updateJob; - try { - updateJob = new JobInstance(null, jobParameters); - jobRepository.update(updateJob); - fail(); - } - catch (Exception ex) { - // expected - } - - // successful update - updateJob = new JobInstance(new Long(0L), jobParameters); - jobDao.updateJobInstance(updateJob); - jobDaoControl.replay(); - jobRepository.update(updateJob); - - } public void testSaveOrUpdateInvalidJobExecution() { @@ -501,8 +480,6 @@ public class SimpleJobRepositoryTests extends TestCase { jobDaoControl.setReturnValue(1); jobDao.findJobExecutions(databaseJob); jobDaoControl.setReturnValue(new ArrayList()); - jobDao.updateJobInstance(databaseJob); - jobDaoControl.setVoidCallable(); jobDao.saveJobExecution(new JobExecution(databaseJob)); jobDaoControl.setMatcher(new ArgumentsMatcher() { public boolean matches(Object[] expected, Object[] actual) { diff --git a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java index e6cfb4d2f..ec2abc3fb 100644 --- a/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java +++ b/spring-batch-execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java @@ -22,11 +22,11 @@ import java.util.Map; import org.springframework.batch.core.domain.BatchStatus; import org.springframework.batch.core.domain.Job; -import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.domain.JobExecution; import org.springframework.batch.core.domain.JobInstance; import org.springframework.batch.core.domain.JobParameters; import org.springframework.batch.core.domain.JobParametersBuilder; +import org.springframework.batch.core.domain.JobSupport; import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException; import org.springframework.batch.repeat.ExitStatus; import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests; @@ -87,7 +87,6 @@ public abstract class AbstractJobDaoTests extends jobExecution.setStatus(BatchStatus.STARTED); jobExecutionDao.saveJobExecution(jobExecution); jobInstance.setLastExecution(jobExecution); - jobInstanceDao.updateJobInstance(jobInstance); } public void testVersionIsNotNullForJob() throws Exception { @@ -153,21 +152,6 @@ public abstract class AbstractJobDaoTests extends assertEquals(0, jobs.size()); } - - public void testUpdateJob() { - // Update the returned job with a new status - JobExecution newExecution = new JobExecution(jobInstance); - jobExecutionDao.saveJobExecution(newExecution); - jobInstance.setLastExecution(newExecution); - jobInstanceDao.updateJobInstance(jobInstance); - - // The job just updated should be found, with the saved status. - List jobs = jobInstanceDao.findJobInstances(job.getName(), jobParameters); - assertTrue(jobs.size() == 1); - JobInstance tempJob = (JobInstance) jobs.get(0); - assertTrue(jobInstance.equals(tempJob)); - assertEquals(newExecution, tempJob.getLastExecution()); - } public void testGetJobExecution(){ @@ -181,27 +165,6 @@ public abstract class AbstractJobDaoTests extends assertEquals(lastJobExecution, jobExecution); } - public void testUpdateJobWithNullId() { - - - try { - JobInstance testJob = new JobInstance(null, null); - jobInstanceDao.updateJobInstance(testJob); - fail(); - } catch (IllegalArgumentException ex) { - // expected - } - } - - public void testUpdateNullJob() { - - JobInstance testJob = null; - try { - jobInstanceDao.updateJobInstance(testJob); - } catch (IllegalArgumentException ex) { - // expected - } - } public void testUpdateJobExecution() { @@ -312,4 +275,14 @@ public abstract class AbstractJobDaoTests extends assertEquals(lhs.getExitStatus(), rhs.getExitStatus()); } +// public void testGetLastJobExecution() { +// JobExecution lastExecution = new JobExecution(jobInstance); +// lastExecution.setStatus(BatchStatus.STARTED); +// +// int JUMP_INTO_FUTURE = 1000; // makes sure start time is 'greatest' +// lastExecution.setStartTime(new Date(System.currentTimeMillis() + JUMP_INTO_FUTURE)); +// jobExecutionDao.saveJobExecution(lastExecution); +// +// assertEquals(lastExecution, jobExecutionDao.getLastJobExecution(jobInstance)); +// } } diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql index ae0d34d88..77736e63c 100644 --- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/init.sql @@ -3,8 +3,7 @@ CREATE TABLE BATCH_JOB_INSTANCE ( JOB_INSTANCE_ID BIGINT IDENTITY PRIMARY KEY , VERSION BIGINT, JOB_NAME VARCHAR(100) NOT NULL , - JOB_KEY VARCHAR(250) , - LAST_JOB_EXECUTION_ID BIGINT ); + JOB_KEY VARCHAR(250)); CREATE TABLE BATCH_JOB_EXECUTION ( JOB_EXECUTION_ID BIGINT IDENTITY PRIMARY KEY , diff --git a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml index cb41e9dbc..53f76ec9a 100644 --- a/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml +++ b/spring-batch-execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml @@ -7,8 +7,7 @@ - - + diff --git a/spring-batch-samples/src/main/resources/simple-container-definition.xml b/spring-batch-samples/src/main/resources/simple-container-definition.xml index f49668815..f0471f3ba 100644 --- a/spring-batch-samples/src/main/resources/simple-container-definition.xml +++ b/spring-batch-samples/src/main/resources/simple-container-definition.xml @@ -54,8 +54,7 @@ - - +