diff --git a/execution/src/main/java/org/springframework/batch/execution/bootstrap/TaskExecutorJobLauncher.java b/execution/src/main/java/org/springframework/batch/execution/bootstrap/TaskExecutorJobLauncher.java
index a45304c57..17eb188fc 100644
--- a/execution/src/main/java/org/springframework/batch/execution/bootstrap/TaskExecutorJobLauncher.java
+++ b/execution/src/main/java/org/springframework/batch/execution/bootstrap/TaskExecutorJobLauncher.java
@@ -23,7 +23,6 @@ import javax.management.Notification;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.core.configuration.NoSuchJobConfigurationException;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.JobIdentifier;
import org.springframework.batch.execution.facade.JobExecutorFacade;
import org.springframework.batch.execution.facade.NoSuchJobExecutionException;
diff --git a/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java b/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java
index 66262174e..a1084b3ff 100644
--- a/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java
+++ b/execution/src/main/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacade.java
@@ -22,10 +22,10 @@ import java.util.Properties;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.core.configuration.JobConfigurationLocator;
import org.springframework.batch.core.configuration.NoSuchJobConfigurationException;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.JobExecutionRegistry;
import org.springframework.batch.core.runtime.JobIdentifier;
import org.springframework.batch.execution.job.DefaultJobExecutor;
@@ -127,7 +127,7 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, StatisticsPro
.getJobConfiguration(jobRuntimeInformation.getName());
final JobInstance job = jobRepository.findOrCreateJob(jobConfiguration, jobRuntimeInformation);
- JobExecutionContext jobExecutionContext = jobExecutionRegistry.register(job);
+ JobExecution jobExecutionContext = jobExecutionRegistry.register(job);
ExitStatus exitStatus = ExitStatus.FAILED;
try {
@@ -153,7 +153,7 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, StatisticsPro
* @see org.springframework.batch.container.BatchContainer#stop(org.springframework.batch.container.common.runtime.JobRuntimeInformation)
*/
public void stop(JobIdentifier runtimeInformation) throws NoSuchJobExecutionException {
- JobExecutionContext jobExecutionContext = (JobExecutionContext) jobExecutionRegistry.get(runtimeInformation);
+ JobExecution jobExecutionContext = jobExecutionRegistry.get(runtimeInformation);
if (jobExecutionContext == null) {
throw new NoSuchJobExecutionException("No such Job is executing: [" + runtimeInformation + "]");
}
@@ -193,7 +193,7 @@ public class SimpleJobExecutorFacade implements JobExecutorFacade, StatisticsPro
int i = 0;
Properties props = new Properties();
for (Iterator iter = jobExecutionRegistry.findAll().iterator(); iter.hasNext();) {
- JobExecutionContext element = (JobExecutionContext) iter.next();
+ JobExecution element = (JobExecution) iter.next();
i++;
String runtime = "job" + i;
props.setProperty(runtime, "" + element.getJobIdentifier());
diff --git a/execution/src/main/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistry.java b/execution/src/main/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistry.java
index 96bd1362b..8561b20ca 100644
--- a/execution/src/main/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistry.java
+++ b/execution/src/main/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistry.java
@@ -22,8 +22,8 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Set;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.JobExecutionRegistry;
import org.springframework.batch.core.runtime.JobIdentifier;
@@ -74,10 +74,10 @@ public class VolatileJobExecutionRegistry implements JobExecutionRegistry {
* (non-Javadoc)
* @see org.springframework.batch.container.common.executor.JobExecutionRegistry#findByRuntimeInformation(org.springframework.batch.container.common.runtime.JobRuntimeInformation)
*/
- public JobExecutionContext get(JobIdentifier runtimeInformation) {
+ public JobExecution get(JobIdentifier runtimeInformation) {
synchronized (this.contexts) {
- return (JobExecutionContext) contexts.get(runtimeInformation);
+ return (JobExecution) contexts.get(runtimeInformation);
}
}
@@ -98,14 +98,14 @@ public class VolatileJobExecutionRegistry implements JobExecutionRegistry {
* @see org.springframework.batch.container.common.executor.JobExecutionRegistry#register(org.springframework.batch.container.common.runtime.JobRuntimeInformation,
* org.springframework.batch.container.common.domain.JobExecution)
*/
- public JobExecutionContext register(JobInstance job) {
+ public JobExecution register(JobInstance job) {
JobIdentifier jobIdentifier = job.getIdentifier();
if (isRegistered(jobIdentifier)) {
return get(jobIdentifier);
}
- JobExecutionContext context = new JobExecutionContext(jobIdentifier, job);
+ JobExecution context = new JobExecution(job);
synchronized (this.contexts) {
contexts.put(jobIdentifier, context);
diff --git a/execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java b/execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java
index c8e9e1adf..4e4fe3f30 100644
--- a/execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java
+++ b/execution/src/main/java/org/springframework/batch/execution/job/DefaultJobExecutor.java
@@ -25,6 +25,7 @@ import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.JobExecutor;
@@ -32,8 +33,6 @@ import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepExecutorFactory;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.runtime.JobExecutionContext;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.execution.step.SimpleStepExecutorFactory;
import org.springframework.batch.execution.step.simple.SimpleExitCodeExceptionClassifier;
import org.springframework.batch.io.exception.BatchCriticalException;
@@ -57,12 +56,11 @@ public class DefaultJobExecutor implements JobExecutor {
private ExitCodeExceptionClassifier exceptionClassifier = new SimpleExitCodeExceptionClassifier();
- public ExitStatus run(JobConfiguration configuration, JobExecutionContext jobExecutionContext)
+ public ExitStatus run(JobConfiguration configuration, JobExecution jobExecution)
throws BatchCriticalException {
- JobInstance job = jobExecutionContext.getJob();
- JobExecution jobExecution = jobExecutionContext.getJobExecution();
- updateStatus(jobExecutionContext, BatchStatus.STARTING);
+ JobInstance job = jobExecution.getJob();
+ updateStatus(jobExecution, BatchStatus.STARTING);
List steps = job.getSteps();
@@ -74,22 +72,22 @@ public class DefaultJobExecutor implements JobExecutor {
StepInstance step = (StepInstance) i.next();
StepConfiguration stepConfiguration = (StepConfiguration) j.next();
if (shouldStart(step, stepConfiguration)) {
- updateStatus(jobExecutionContext, BatchStatus.STARTED);
+ updateStatus(jobExecution, BatchStatus.STARTED);
StepExecutor stepExecutor = stepExecutorFactory.getExecutor(stepConfiguration);
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
- status = stepExecutor.process(stepConfiguration, stepExecutionContext);
+ StepExecution stepExecution = new StepExecution(step, jobExecution);
+ status = stepExecutor.process(stepConfiguration, stepExecution);
}
}
- updateStatus(jobExecutionContext, BatchStatus.COMPLETED);
+ updateStatus(jobExecution, BatchStatus.COMPLETED);
}
catch (StepInterruptedException e) {
- updateStatus(jobExecutionContext, BatchStatus.STOPPED);
+ updateStatus(jobExecution, BatchStatus.STOPPED);
status = exceptionClassifier.classifyForExitCode(e);
rethrow(e);
}
catch (Throwable t) {
- updateStatus(jobExecutionContext, BatchStatus.FAILED);
+ updateStatus(jobExecution, BatchStatus.FAILED);
status = exceptionClassifier.classifyForExitCode(t);
rethrow(t);
}
@@ -102,14 +100,13 @@ public class DefaultJobExecutor implements JobExecutor {
return status;
}
- private void updateStatus(JobExecutionContext jobExecutionContext, BatchStatus status) {
- JobInstance job = jobExecutionContext.getJob();
- JobExecution jobExecution = jobExecutionContext.getJobExecution();
+ private void updateStatus(JobExecution jobExecution, BatchStatus status) {
+ JobInstance job = jobExecution.getJob();
jobExecution.setStatus(status);
job.setStatus(status);
jobRepository.update(job);
jobRepository.saveOrUpdate(jobExecution);
- for (Iterator iter = jobExecutionContext.getStepContexts().iterator(); iter.hasNext();) {
+ for (Iterator iter = jobExecution.getStepContexts().iterator(); iter.hasNext();) {
RepeatContext context = (RepeatContext) iter.next();
context.setAttribute("JOB_STATUS", status);
}
diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/HibernateStepDao.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/HibernateStepDao.java
index 5d1a720ee..62b64f999 100644
--- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/HibernateStepDao.java
+++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/HibernateStepDao.java
@@ -30,10 +30,11 @@ import org.springframework.util.Assert;
/**
* It represents an implementation of {@link StepDao} functionality based
- * on the Hibernate ORM framework. Its advantage is the independency of implementation
+ * on the Hibernate ORM framework. Its advantage is the independence of implementation
* on the underlying database.
*
- * @author tomas.slanina
+ * @author Tomas Slanina
+ * @author Dave Syer
*/
public class HibernateStepDao extends HibernateDaoSupport implements StepDao {
@@ -45,9 +46,7 @@ public class HibernateStepDao extends HibernateDaoSupport implements StepDao {
Assert.notNull(job, "Job cannot be null.");
Assert.notNull(stepName, "StepName cannot be null.");
- StepInstance step = new StepInstance();
- step.setName(stepName);
- step.setJob(job);
+ StepInstance step = new StepInstance(job, stepName);
Long stepId = (Long)getHibernateTemplate().save(step);
@@ -78,20 +77,20 @@ public class HibernateStepDao extends HibernateDaoSupport implements StepDao {
}
/**
- * @see StepDao#findSteps(Long)
+ * @see StepDao#findSteps(JobInstance)
*
* Hibernate is asked to get all jobs that matches criteria. Afterwards, result is mapped into domain objects.
* It should be noted that restart data must be requested separately.
*
*/
- public List findSteps(final Long jobId) {
+ public List findSteps(final JobInstance job) {
- Assert.notNull(jobId, "JobId cannot be null.");
+ Assert.notNull(job, "JobId cannot be null.");
List list = this.getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) {
Criteria criteria = session.createCriteria(StepInstance.class);
- criteria.add(Expression.eq("job.id", jobId));
+ criteria.add(Expression.eq("job.id", job.getId()));
return criteria.list();
}
});
@@ -105,7 +104,7 @@ public class HibernateStepDao extends HibernateDaoSupport implements StepDao {
public int getStepExecutionCount(final Long stepId) {
Long result = (Long) this.getHibernateTemplate().execute(new HibernateCallback() {
public Object doInHibernate(Session session) {
- return session.createQuery("select count(id) from StepExecution s where s.stepId = :stepId")
+ return session.createQuery("select count(id) from StepExecution s where s.step.id = :stepId")
.setLong("stepId", stepId.longValue())
.uniqueResult();
}
@@ -151,17 +150,14 @@ public class HibernateStepDao extends HibernateDaoSupport implements StepDao {
getHibernateTemplate().update(stepExecution);
}
- public List findStepExecutions(StepInstance step) {
+ public List findStepExecutions(final StepInstance step) {
Assert.notNull(step, "Step cannot be null.");
- Assert.notNull(step.getId(), "Step id cannot be null.");
-
- final Long stepId = step.getId();
-
+
List results = this.getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(Session session) {
Criteria criteria = session.createCriteria(StepExecution.class);
- criteria.add(Expression.eq("stepId", stepId));
+ criteria.add(Expression.eq("step.id", step.getId()));
return criteria.list();
}
});
diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java
index 78c13f8ef..04217b44f 100644
--- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java
+++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/MapStepDao.java
@@ -48,9 +48,7 @@ public class MapStepDao implements StepDao {
}
public StepInstance createStep(JobInstance job, String stepName) {
- StepInstance step = new StepInstance(new Long(currentId++));
- step.setName(stepName);
- step.setJob(job);
+ StepInstance step = new StepInstance(job, stepName, new Long(currentId++));
Set steps = (Set) stepsByJobId.get(job.getId());
if (steps==null) {
steps = TransactionAwareProxyFactory.createTransactionalSet();
@@ -74,8 +72,8 @@ public class MapStepDao implements StepDao {
return null;
}
- public List findSteps(Long jobId) {
- Set steps = (Set) stepsByJobId.get(jobId);
+ public List findSteps(JobInstance job) {
+ Set steps = (Set) stepsByJobId.get(job.getId());
if (steps==null) {
return new ArrayList();
}
diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java
index 6170ffcd1..01c5ebb7e 100644
--- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java
+++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlJobDao.java
@@ -71,14 +71,11 @@ public class SqlJobDao implements JobDao, InitializingBean {
private static final String UPDATE_JOB_EXECUTION = "UPDATE %PREFIX%JOB_EXECUTION set START_TIME = ?, END_TIME = ?, "
+ " STATUS = ?, EXIT_CODE = ? where ID = ?";
- private static final String SAVE_JOB_EXECUTION = "INSERT into %PREFIX%JOB_EXECUTION(ID, JOB_ID, START_TIME, " +
- "END_TIME, STATUS, EXIT_CODE) values (?, ?, ?, ?, ?, ?)";
+ private static final String SAVE_JOB_EXECUTION = "INSERT into %PREFIX%JOB_EXECUTION(ID, JOB_ID, START_TIME, "
+ + "END_TIME, STATUS, EXIT_CODE) values (?, ?, ?, ?, ?, ?)";
private static final String CHECK_JOB_EXECUTION_EXISTS = "SELECT COUNT(*) FROM %PREFIX%JOB_EXECUTION WHERE ID=?";
- private static final String FIND_JOB_EXECUTIONS = "SELECT ID, START_TIME, END_TIME, STATUS from %PREFIX%JOB_EXECUTION"
- + " where JOB_ID = ?";
-
private JdbcTemplate jdbcTemplate;
private DataFieldMaxValueIncrementer jobIncrementer;
@@ -144,7 +141,8 @@ public class SqlJobDao implements JobDao, InitializingBean {
RowMapper rowMapper = new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
- JobInstance job = new JobInstance(jobIdentifier, new Long(rs.getLong(1)));
+ JobInstance job = new JobInstance(jobIdentifier, new Long(rs
+ .getLong(1)));
job.setStatus(BatchStatus.getStatus(rs.getString(2)));
return job;
@@ -189,7 +187,7 @@ public class SqlJobDao implements JobDao, InitializingBean {
Object[] parameters = new Object[] { jobExecution.getId(),
jobExecution.getJobId(), jobExecution.getStartTime(),
jobExecution.getEndTime(), jobExecution.getStatus().toString(),
- jobExecution.getExitCode()};
+ jobExecution.getExitCode() };
jdbcTemplate.update(getSaveJobExecutionQuery(), parameters);
}
@@ -239,71 +237,51 @@ public class SqlJobDao implements JobDao, InitializingBean {
Object[] parameters = new Object[] { jobId };
- return jdbcTemplate.queryForInt(getJobExecutionCountQuery(), parameters);
+ return jdbcTemplate
+ .queryForInt(getJobExecutionCountQuery(), parameters);
}
- public List findJobExecutions(JobInstance job) {
+ public List findJobExecutions(final JobInstance job) {
Assert.notNull(job, "Job cannot be null.");
Assert.notNull(job.getId(), "Job Id cannot be null.");
- final Long jobId = job.getId();
-
- RowMapper rowMapper = new RowMapper() {
-
- public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
-
- JobExecution jobExecution = new JobExecution(jobId);
- jobExecution.setId(new Long(rs.getLong(1)));
- jobExecution.setStartTime(rs.getTimestamp(2));
- jobExecution.setEndTime(rs.getTimestamp(3));
- jobExecution.setStatus(BatchStatus.getStatus(rs.getString(4)));
-
- return jobExecution;
- }
-
- };
-
- return jdbcTemplate.query(getFindJobExecutionsQuery(), new Object[] { jobId },
- rowMapper);
+ return jdbcTemplate.query(getQuery(JobExecutionRowMapper.FIND_JOB_EXECUTIONS),
+ new Object[] { job.getId() }, new JobExecutionRowMapper(job));
}
private String getQuery(String base) {
return StringUtils.replace(base, "%PREFIX%", tablePrefix);
}
-
+
private String getCreateJobQuery() {
return getQuery(CREATE_JOB);
}
-
+
private String getFindJobsQuery() {
return getQuery(FIND_JOBS);
}
-
+
private String getUpdateJobQuery() {
return getQuery(UPDATE_JOB);
}
-
+
private String getSaveJobExecutionQuery() {
return getQuery(SAVE_JOB_EXECUTION);
}
-
+
private String getUpdateJobExecutionQuery() {
return getQuery(UPDATE_JOB_EXECUTION);
}
-
+
private String getCheckJobExecutionExistsQuery() {
return getQuery(CHECK_JOB_EXECUTION_EXISTS);
}
-
+
private String getJobExecutionCountQuery() {
return getQuery(GET_JOB_EXECUTION_COUNT);
}
- private String getFindJobExecutionsQuery() {
- return getQuery(FIND_JOB_EXECUTIONS);
- }
-
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
@@ -386,4 +364,35 @@ public class SqlJobDao implements JobDao, InitializingBean {
return new ScheduledJobIdentifier(jobIdentifier.getName());
}
+ /**
+ * Re-usable mapper for {@link JobExecution} instances.
+ * @author Dave Syer
+ *
+ */
+ public static class JobExecutionRowMapper implements RowMapper {
+
+ public static final String FIND_JOB_EXECUTIONS = "SELECT ID, START_TIME, END_TIME, STATUS from %PREFIX%JOB_EXECUTION"
+ + " where JOB_ID = ?";
+
+ public static final String GET_JOB_EXECUTION = "SELECT ID, START_TIME, END_TIME, STATUS from %PREFIX%JOB_EXECUTION"
+ + " where ID = ?";
+
+ private JobInstance job;
+
+ public JobExecutionRowMapper(JobInstance job) {
+ super();
+ this.job = job;
+ }
+
+ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
+ JobExecution jobExecution = new JobExecution(job);
+ jobExecution.setId(new Long(rs.getLong(1)));
+ jobExecution.setStartTime(rs.getTimestamp(2));
+ jobExecution.setEndTime(rs.getTimestamp(3));
+ jobExecution.setStatus(BatchStatus.getStatus(rs.getString(4)));
+ return jobExecution;
+ }
+
+ }
+
}
diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java
index c3ffcc835..0ac56dda9 100644
--- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java
+++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/SqlStepDao.java
@@ -22,10 +22,12 @@ import java.util.List;
import java.util.Properties;
import org.springframework.batch.core.domain.BatchStatus;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.repository.NoSuchBatchDomainObjectException;
+import org.springframework.batch.execution.repository.dao.SqlJobDao.JobExecutionRowMapper;
import org.springframework.batch.restart.GenericRestartData;
import org.springframework.batch.restart.RestartData;
import org.springframework.batch.support.PropertiesConverter;
@@ -37,7 +39,7 @@ import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
- * Sql implementation of StepDao. Uses Sequences (via Spring's
+ * Sql implementation of {@link StepDao}. Uses Sequences (via Spring's
*
* @link DataFieldMaxValueIncrementer abstraction) to create all Step and
* StepExecution primary keys before inserting a new row. All objects are
@@ -82,6 +84,8 @@ public class SqlStepDao implements StepDao, InitializingBean {
private JdbcOperations jdbcTemplate;
+ private JobDao jobDao;
+
private DataFieldMaxValueIncrementer stepIncrementer;
private DataFieldMaxValueIncrementer stepExecutionIncrementer;
@@ -100,6 +104,16 @@ public class SqlStepDao implements StepDao, InitializingBean {
this.tablePrefix = tablePrefix;
}
+ /**
+ * Injection setter for job dao. Used to save {@link JobExecution}
+ * instances.
+ *
+ * @param jobDao a {@link JobDao}
+ */
+ public void setJobDao(JobDao jobDao) {
+ this.jobDao = jobDao;
+ }
+
/**
* Find one step for given job and stepName. A RowMapper is used to map each
* row returned to a step object. If none are found, the list will be empty
@@ -141,7 +155,6 @@ public class SqlStepDao implements StepDao, InitializingBean {
return null;
} else if (steps.size() == 1) {
StepInstance step = (StepInstance) steps.get(0);
- step.setName(stepName);
return step;
} else {
// This error will likely never be thrown, because there should
@@ -155,7 +168,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
}
/**
- * @see StepDao#findSteps(Long)
+ * @see StepDao#findSteps(JobInstance)
*
* Sql implementation which uses a RowMapper to populate a list of all rows
* in the step table with the same JOB_ID.
@@ -163,18 +176,18 @@ public class SqlStepDao implements StepDao, InitializingBean {
* @throws IllegalArgumentException
* if jobId is null.
*/
- public List findSteps(Long jobId) {
+ public List findSteps(final JobInstance job) {
- Assert.notNull(jobId, "JobId cannot be null.");
+ Assert.notNull(job, "Job cannot be null.");
- Object[] parameters = new Object[] { jobId };
+ Object[] parameters = new Object[] { job.getId() };
RowMapper rowMapper = new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
- StepInstance step = new StepInstance(new Long(rs.getLong(1)));
- step.setName(rs.getString(2));
+ StepInstance step = new StepInstance(job, rs.getString(2),
+ new Long(rs.getLong(1)));
String status = rs.getString(3);
step.setStatus(BatchStatus.getStatus(status));
step.setRestartData(new GenericRestartData(PropertiesConverter
@@ -204,9 +217,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
Object[] parameters = new Object[] { stepId, job.getId(), stepName };
jdbcTemplate.update(getQuery(CREATE_STEP), parameters);
- StepInstance step = new StepInstance(stepId);
- step.setJob(job);
- step.setName(stepName);
+ StepInstance step = new StepInstance(job, stepName, stepId);
return step;
}
@@ -245,6 +256,8 @@ public class SqlStepDao implements StepDao, InitializingBean {
validateStepExecution(stepExecution);
+ cascadeJobExecution(stepExecution.getJobExecution());
+
stepExecution.setId(new Long(stepExecutionIncrementer.nextLongValue()));
Object[] parameters = new Object[] {
stepExecution.getId(),
@@ -263,6 +276,14 @@ public class SqlStepDao implements StepDao, InitializingBean {
}
+ private void cascadeJobExecution(JobExecution jobExecution) {
+ if (jobExecution.getId() != null) {
+ // assume already saved...
+ return;
+ }
+ jobDao.save(jobExecution);
+ }
+
/**
* @see StepDao#update(StepExecution)
*/
@@ -289,8 +310,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
stepExecution.getTaskCount(),
PropertiesConverter.propertiesToString(stepExecution
.getStatistics()), stepExecution.getExitCode(),
- stepExecution.getExitDescription(),
- stepExecution.getId() };
+ stepExecution.getExitDescription(), stepExecution.getId() };
jdbcTemplate.update(getQuery(UPDATE_STEP_EXECUTION), parameters);
}
@@ -313,19 +333,21 @@ public class SqlStepDao implements StepDao, InitializingBean {
* @throws NoSuchBatchDomainObjectException
* if more than one step execution is returned.
*/
- public List findStepExecutions(StepInstance step) {
+ public List findStepExecutions(final StepInstance step) {
Assert.notNull(step, "Step cannot be null.");
Assert.notNull(step.getId(), "Step id cannot be null.");
- final Long stepId = step.getId();
-
RowMapper rowMapper = new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
- StepExecution stepExecution = new StepExecution(stepId,
- new Long(rs.getLong(2)));
- stepExecution.setId(new Long(rs.getLong(1)));
+ JobExecution jobExecution = (JobExecution) jdbcTemplate
+ .queryForObject(
+ getQuery(JobExecutionRowMapper.GET_JOB_EXECUTION),
+ new Object[] { new Long(rs.getLong(2)) },
+ new JobExecutionRowMapper(step.getJob()));
+ StepExecution stepExecution = new StepExecution(step,
+ jobExecution, new Long(rs.getLong(1)));
stepExecution.setStartTime(rs.getTimestamp(3));
stepExecution.setEndTime(rs.getTimestamp(4));
stepExecution.setStatus(BatchStatus.getStatus(rs.getString(5)));
@@ -340,7 +362,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
};
return jdbcTemplate.query(getQuery(FIND_STEP_EXECUTIONS),
- new Object[] { stepId }, rowMapper);
+ new Object[] { step.getId() }, rowMapper);
}
diff --git a/execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java b/execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java
index 18f858083..0efd350c9 100644
--- a/execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java
+++ b/execution/src/main/java/org/springframework/batch/execution/repository/dao/StepDao.java
@@ -28,13 +28,13 @@ import org.springframework.batch.core.domain.StepInstance;
* TODO: Add java doc.
*
* @author Lucas Ward
- *
+ *
*/
public interface StepDao {
/**
- * Find a step with the given JobId and Step Name. Return null if none
- * are found.
+ * Find a step with the given JobId and Step Name. Return null if none are
+ * found.
*
* @param jobId
* @param stepName
@@ -43,15 +43,17 @@ public interface StepDao {
public StepInstance findStep(JobInstance job, String stepName);
/**
- * Find all steps with the given Job ID.
+ * Find all steps with the given Job.
*
- * @param jobId
- * @return
+ * @param job
+ * the job to use as a search key
+ * @return list of {@link StepInstance}
*/
- public List findSteps(Long jobId);
+ public List findSteps(JobInstance job);
/**
* Create a step for the given Step Name and Job Id.
+ *
* @param job
* @param stepName
*
@@ -91,15 +93,17 @@ public interface StepDao {
* Return the count of StepExecutions with the given StepId.
*
* @param stepId
- * @return
+ * @return the number of step executions for this step TODO: change
+ * signature to search by {@link StepInstance}
*/
public int getStepExecutionCount(Long stepId);
-
+
/**
- * Return all StepExecutions for the given step.
+ * Return all StepExecutions for the given step.
*
- * @param id
- * @return list of stepExecutions
+ * @param step
+ * the step to use as a search key
+ * @return list of stepExecutions
*/
public List findStepExecutions(StepInstance step);
}
diff --git a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java
index 694b81caa..c35110475 100644
--- a/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java
+++ b/execution/src/main/java/org/springframework/batch/execution/step/simple/SimpleStepExecutor.java
@@ -28,11 +28,9 @@ import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.runtime.JobExecutionContext;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.core.tasklet.Tasklet;
-import org.springframework.batch.execution.scope.StepScope;
import org.springframework.batch.execution.scope.SimpleStepContext;
+import org.springframework.batch.execution.scope.StepScope;
import org.springframework.batch.execution.scope.StepSynchronizationManager;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
@@ -75,7 +73,7 @@ public class SimpleStepExecutor implements StepExecutor {
/**
* Key placed in step scope context to identify the
- * {@link StepExecutionContext}.
+ * {@link StepExecution}.
*/
public static final String STEP_KEY = "STEP";
@@ -149,16 +147,15 @@ public class SimpleStepExecutor implements StepExecutor {
* @throws StepInterruptedException if the step or a chunk is interrupted
* @throws RuntimeException if there is an exception during a chunk
* execution
- * @see StepExecutor#process(StepConfiguration, StepExecutionContext)
+ * @see StepExecutor#process(StepConfiguration, StepExecution)
*/
- public ExitStatus process(final StepConfiguration configuration, final StepExecutionContext stepExecutionContext)
+ public ExitStatus process(final StepConfiguration configuration, final StepExecution stepExecution)
throws BatchCriticalException, StepInterruptedException {
- final StepInstance step = stepExecutionContext.getStep();
+ final StepInstance step = stepExecution.getStep();
boolean isRestart = step.getStepExecutionCount() > 0 ? true : false;
Assert.notNull(step);
- final StepExecution stepExecution = stepExecutionContext.getStepExecution();
final Tasklet module = configuration.getTasklet();
step.setStepExecution(stepExecution);
@@ -168,7 +165,7 @@ public class SimpleStepExecutor implements StepExecutor {
try {
stepExecution.setStartTime(new Timestamp(System.currentTimeMillis()));
- updateStatus(stepExecutionContext, BatchStatus.STARTED);
+ updateStatus(stepExecution, BatchStatus.STARTED);
final boolean saveRestartData = ((AbstractStepConfiguration) configuration).isSaveRestartData();
@@ -180,18 +177,18 @@ public class SimpleStepExecutor implements StepExecutor {
public ExitStatus doInIteration(final RepeatContext context) throws Exception {
- stepExecutionContext.getJobExecutionContext().registerStepContext(context);
+ stepExecution.getJobExecution().registerStepContext(context);
context.registerDestructionCallback("STEP_EXECUTION_CONTEXT_CALLBACK", new Runnable() {
public void run() {
- stepExecutionContext.getJobExecutionContext().unregisterStepContext(context);
+ stepExecution.getJobExecution().unregisterStepContext(context);
}
});
- stepScopeContext.setJobIdentifier(stepExecutionContext.getJobExecutionContext().getJobIdentifier());
- context.setAttribute(StepScope.ID_KEY, stepExecutionContext.getJobExecutionContext()
+ stepScopeContext.setJobIdentifier(stepExecution.getJobExecution().getJobIdentifier());
+ context.setAttribute(StepScope.ID_KEY, stepExecution.getJobExecution()
.getJobIdentifier());
// Mark the context as a step context as a hint to scope
// implementations.
- context.setAttribute(STEP_KEY, stepExecutionContext);
+ context.setAttribute(STEP_KEY, stepExecution);
// Add the step execution as an attribute so monitoring
// clients can see it.
context.setAttribute(STEP_EXECUTION_KEY, stepExecution);
@@ -208,7 +205,7 @@ public class SimpleStepExecutor implements StepExecutor {
ExitStatus result;
try {
- result = processChunk(configuration, stepExecutionContext);
+ result = processChunk(configuration, stepExecution);
}
catch (Throwable t) {
/*
@@ -250,7 +247,7 @@ public class SimpleStepExecutor implements StepExecutor {
});
- updateStatus(stepExecutionContext, BatchStatus.COMPLETED);
+ updateStatus(stepExecution, BatchStatus.COMPLETED);
return status;
}
catch (RuntimeException e) {
@@ -259,11 +256,11 @@ public class SimpleStepExecutor implements StepExecutor {
status = exceptionClassifier.classifyForExitCode(e);
stepExecution.setException(e);
if (e.getCause() instanceof StepInterruptedException) {
- updateStatus(stepExecutionContext, BatchStatus.STOPPED);
+ updateStatus(stepExecution, BatchStatus.STOPPED);
throw (StepInterruptedException) e.getCause();
}
else {
- updateStatus(stepExecutionContext, BatchStatus.FAILED);
+ updateStatus(stepExecution, BatchStatus.FAILED);
throw e;
}
@@ -294,14 +291,13 @@ public class SimpleStepExecutor implements StepExecutor {
* @param stepExecution the current stepExecution
* @param status the status to set
*/
- private void updateStatus(StepExecutionContext stepExecutionContext, BatchStatus status) {
- StepInstance step = stepExecutionContext.getStep();
- StepExecution stepExecution = stepExecutionContext.getStepExecution();
+ private void updateStatus(StepExecution stepExecution, BatchStatus status) {
+ StepInstance step = stepExecution.getStep();
stepExecution.setStatus(status);
step.setStatus(status);
jobRepository.update(step);
jobRepository.saveOrUpdate(stepExecution);
- for (Iterator iter = stepExecutionContext.getJobExecutionContext().getStepContexts().iterator(); iter.hasNext();) {
+ for (Iterator iter = stepExecution.getJobExecution().getStepContexts().iterator(); iter.hasNext();) {
RepeatContext context = (RepeatContext) iter.next();
context.setAttribute("JOB_STATUS", status);
}
@@ -314,24 +310,24 @@ public class SimpleStepExecutor implements StepExecutor {
* transaction.
*
* @param configuration the current step configuration
- * @param stepExecutionContext the current step, containing the
+ * @param stepExecution the current step, containing the
* {@link Tasklet} with the business logic.
* @return true if there is more data to process.
*/
protected final ExitStatus processChunk(final StepConfiguration configuration,
- final StepExecutionContext stepExecutionContext) {
+ final StepExecution stepExecution) {
return chunkOperations.iterate(new RepeatCallback() {
public ExitStatus doInIteration(final RepeatContext context) throws Exception {
- stepExecutionContext.getJobExecutionContext().registerChunkContext(context);
+ stepExecution.getJobExecution().registerChunkContext(context);
context.registerDestructionCallback("CHUNK_EXECUTION_CONTEXT_CALLBACK", new Runnable() {
public void run() {
- stepExecutionContext.getJobExecutionContext().unregisterStepContext(context);
+ stepExecution.getJobExecution().unregisterStepContext(context);
}
});
// check for interruption before each item as well
interruptionPolicy.checkInterrupted(context);
- ExitStatus exitStatus = doTaskletProcessing(configuration.getTasklet(), stepExecutionContext.getStep());
- stepExecutionContext.getStepExecution().incrementTaskCount();
+ ExitStatus exitStatus = doTaskletProcessing(configuration.getTasklet(), stepExecution.getStep());
+ stepExecution.incrementTaskCount();
// check for interruption after each item as well
interruptionPolicy.checkInterrupted(context);
return exitStatus;
diff --git a/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepExecution.hbm.xml b/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepExecution.hbm.xml
index 09caf4a9f..0c536cbd2 100644
--- a/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepExecution.hbm.xml
+++ b/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepExecution.hbm.xml
@@ -12,8 +12,8 @@
&step-execution-generator;
-
-
+
+
diff --git a/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepInstance.hbm.xml b/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepInstance.hbm.xml
index f5b3b0610..ffca30f2f 100644
--- a/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepInstance.hbm.xml
+++ b/execution/src/main/resources/org/springframework/batch/execution/repository/dao/StepInstance.hbm.xml
@@ -12,8 +12,8 @@
&step-generator;
-
-
+
+
diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacaderTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacaderTests.java
index 019882068..0da37fbca 100644
--- a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacaderTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobExecutorFacaderTests.java
@@ -26,14 +26,14 @@ import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.core.configuration.JobConfigurationLocator;
import org.springframework.batch.core.configuration.NoSuchJobConfigurationException;
import org.springframework.batch.core.configuration.StepConfiguration;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.executor.JobExecutor;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.JobExecutionRegistry;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.io.exception.BatchCriticalException;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.context.RepeatContextSupport;
@@ -59,7 +59,7 @@ public class SimpleJobExecutorFacaderTests extends TestCase {
JobConfiguration jobConfiguration = new JobConfiguration();
StepExecutor stepExecutor = new StepExecutor() {
- public ExitStatus process(StepConfiguration configuration, StepExecutionContext stepExecutionContext) throws BatchCriticalException {
+ public ExitStatus process(StepConfiguration configuration, StepExecution stepExecution) throws BatchCriticalException {
return ExitStatus.FINISHED;
}
};
@@ -79,12 +79,12 @@ public class SimpleJobExecutorFacaderTests extends TestCase {
final SimpleJobIdentifier jobRuntimeInformation = new SimpleJobIdentifier("bar");
jobRepository.findOrCreateJob(jobConfiguration, jobRuntimeInformation);
jobExecutor = new JobExecutor() {
- public ExitStatus run(JobConfiguration configuration, JobExecutionContext jobExecutionContext) throws BatchCriticalException {
+ public ExitStatus run(JobConfiguration configuration, JobExecution jobExecutionContext) throws BatchCriticalException {
return ExitStatus.FINISHED;
}
};
JobInstance job = new JobInstance(jobRuntimeInformation);
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobRuntimeInformation, job);
+ JobExecution jobExecutionContext = new JobExecution(job);
jobRepositoryControl.setReturnValue(job);
jobExecutor.run(jobConfiguration, jobExecutionContext);
jobRepositoryControl.replay();
@@ -103,7 +103,7 @@ public class SimpleJobExecutorFacaderTests extends TestCase {
public void testIsRunning() throws Exception {
simpleContainer.setJobExecutor(new JobExecutor() {
- public ExitStatus run(JobConfiguration configuration, JobExecutionContext jobExecutionContext)
+ public ExitStatus run(JobConfiguration configuration, JobExecution jobExecutionContext)
throws BatchCriticalException {
while (running) {
try {
@@ -187,7 +187,7 @@ public class SimpleJobExecutorFacaderTests extends TestCase {
JobExecutionRegistry jobExecutionRegistry = new VolatileJobExecutionRegistry();
simpleContainer.setJobExecutionRegistry(jobExecutionRegistry);
SimpleJobIdentifier runtimeInformation = new SimpleJobIdentifier("TestJob");
- JobExecutionContext context = jobExecutionRegistry.register(new JobInstance(runtimeInformation, new Long(0)));
+ JobExecution context = jobExecutionRegistry.register(new JobInstance(runtimeInformation, new Long(0)));
RepeatContextSupport stepContext = new RepeatContextSupport(null);
RepeatContextSupport chunkContext = new RepeatContextSupport(stepContext);
@@ -212,7 +212,7 @@ public class SimpleJobExecutorFacaderTests extends TestCase {
JobExecutionRegistry jobExecutionRegistry = (JobExecutionRegistry) control.getMock();
simpleContainer.setJobExecutionRegistry(jobExecutionRegistry);
SimpleJobIdentifier runtimeInformation = new SimpleJobIdentifier("TestJob");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(runtimeInformation, new JobInstance(runtimeInformation, new Long(0)));
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(runtimeInformation, new Long(0)));
jobExecutionContext.registerStepContext(new RepeatContextSupport(null));
jobExecutionContext.registerChunkContext(new RepeatContextSupport(null));
control.expectAndReturn(jobExecutionRegistry.findAll(), Collections.singleton(jobExecutionContext));
diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobTests.java
index 6743d84ea..19d7ee3f1 100644
--- a/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/facade/SimpleJobTests.java
@@ -26,10 +26,10 @@ import junit.framework.TestCase;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.domain.BatchStatus;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepExecutorFactory;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.JobIdentifier;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
import org.springframework.batch.core.tasklet.Tasklet;
@@ -123,7 +123,7 @@ public class SimpleJobTests extends TestCase {
assertEquals(job.getName(), "real.job");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(runtimeInformation, job);
+ JobExecution jobExecutionContext = new JobExecution(job);
jobLifecycle.run(jobConfiguration, jobExecutionContext);
assertEquals(BatchStatus.COMPLETED, job.getStatus());
@@ -170,7 +170,7 @@ public class SimpleJobTests extends TestCase {
jobConfiguration.addStep(step);
JobInstance job = repository.findOrCreateJob(jobConfiguration, runtimeInformation);
- JobExecutionContext jobExecutionContext = new JobExecutionContext(runtimeInformation, job);
+ JobExecution jobExecutionContext = new JobExecution(job);
jobLifecycle.run(jobConfiguration, jobExecutionContext);
assertEquals(BatchStatus.COMPLETED, job.getStatus());
@@ -194,7 +194,7 @@ public class SimpleJobTests extends TestCase {
jobConfiguration.addStep(step);
JobInstance job = repository.findOrCreateJob(jobConfiguration, runtimeInformation);
- JobExecutionContext jobExecutionContext = new JobExecutionContext(runtimeInformation, job);
+ JobExecution jobExecutionContext = new JobExecution(job);
try {
jobLifecycle.run(jobConfiguration, jobExecutionContext);
fail("Expected RuntimeException");
diff --git a/execution/src/test/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistryTests.java b/execution/src/test/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistryTests.java
index f1a99db9e..8651566ed 100644
--- a/execution/src/test/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistryTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/facade/VolatileJobExecutionRegistryTests.java
@@ -19,8 +19,8 @@ import java.util.Collection;
import junit.framework.TestCase;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
/**
@@ -35,20 +35,20 @@ public class VolatileJobExecutionRegistryTests extends TestCase {
private VolatileJobExecutionRegistry registry = new VolatileJobExecutionRegistry();
public void testAddAndRetrieveSingle() throws Exception {
- JobExecutionContext context = registry.register(job);
+ JobExecution context = registry.register(job);
assertEquals(context, registry.get(runtimeInformation));
}
public void testAddAndFindAll() throws Exception {
- JobExecutionContext context = registry.register(job);
+ JobExecution context = registry.register(job);
Collection list = registry.findAll();
assertEquals(1, list.size());
assertTrue(list.contains(context));
}
public void testAddAndFindAllMultiple() throws Exception {
- JobExecutionContext context1 = registry.register(job);
- JobExecutionContext context2 = registry.register(new JobInstance(new SimpleJobIdentifier("bar"), new Long(1)));
+ JobExecution context1 = registry.register(job);
+ JobExecution context2 = registry.register(new JobInstance(new SimpleJobIdentifier("bar"), new Long(1)));
Collection list = registry.findAll();
assertEquals(2, list.size());
assertTrue(list.contains(context1));
@@ -56,8 +56,8 @@ public class VolatileJobExecutionRegistryTests extends TestCase {
}
public void testRegisterSamejobTwice() throws Exception {
- JobExecutionContext context1 = registry.register(job);
- JobExecutionContext context2 = registry.register(job);
+ JobExecution context1 = registry.register(job);
+ JobExecution context2 = registry.register(job);
Collection list = registry.findAll();
assertEquals(1, list.size());
assertTrue(list.contains(context1));
@@ -65,7 +65,7 @@ public class VolatileJobExecutionRegistryTests extends TestCase {
}
public void testAddAndFindByName() throws Exception {
- JobExecutionContext context = registry.register(job);
+ JobExecution context = registry.register(job);
registry.register(job);
Collection list = registry.findByName(runtimeInformation.getName());
assertEquals(1, list.size());
diff --git a/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java b/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java
index 39236f127..171e765a0 100644
--- a/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/job/DefaultJobExecutorTests.java
@@ -26,15 +26,14 @@ import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.domain.BatchStatus;
import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
import org.springframework.batch.core.executor.StepExecutor;
import org.springframework.batch.core.executor.StepExecutorFactory;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobDao;
@@ -63,7 +62,7 @@ public class DefaultJobExecutorTests extends TestCase {
private List list = new ArrayList();
StepExecutor defaultStepLifecycle = new StepExecutor() {
- public ExitStatus process(StepConfiguration configuration, StepExecutionContext stepExecutionContext)
+ public ExitStatus process(StepConfiguration configuration, StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
list.add("default");
return ExitStatus.FINISHED;
@@ -71,7 +70,7 @@ public class DefaultJobExecutorTests extends TestCase {
};
StepExecutor configurationStepLifecycle = new StepExecutor() {
- public ExitStatus process(StepConfiguration configuration, StepExecutionContext stepExecutionContext)
+ public ExitStatus process(StepConfiguration configuration, StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
list.add("special");
return ExitStatus.FINISHED;
@@ -80,15 +79,15 @@ public class DefaultJobExecutorTests extends TestCase {
private JobInstance job;
- private JobExecutionContext jobExecutionContext;
+ private JobExecution jobExecution;
private StepInstance step1;
private StepInstance step2;
- private StepExecutionContext stepExecutionContext1;
+ private StepExecution stepExecution1;
- private StepExecutionContext stepExecutionContext2;
+ private StepExecution stepExecution2;
private AbstractStepConfiguration stepConfiguration1;
@@ -131,13 +130,13 @@ public class DefaultJobExecutorTests extends TestCase {
job = jobRepository.findOrCreateJob(jobConfiguration, jobIdentifer);
- jobExecutionContext = new JobExecutionContext(jobIdentifer, job);
+ jobExecution = new JobExecution(job);
List steps = job.getSteps();
step1 = (StepInstance) steps.get(0);
step2 = (StepInstance) steps.get(1);
- stepExecutionContext1 = new StepExecutionContext(jobExecutionContext, step1);
- stepExecutionContext2 = new StepExecutionContext(jobExecutionContext, step2);
+ stepExecution1 = new StepExecution(step1, jobExecution);
+ stepExecution2 = new StepExecution(step2, jobExecution);
}
@@ -149,7 +148,7 @@ public class DefaultJobExecutorTests extends TestCase {
stepConfiguration1.setStartLimit(5);
stepConfiguration2.setStartLimit(5);
- jobExecutor.run(jobConfiguration, jobExecutionContext);
+ jobExecutor.run(jobConfiguration, jobExecution);
assertEquals(2, list.size());
checkRepository(BatchStatus.COMPLETED);
}
@@ -173,7 +172,7 @@ public class DefaultJobExecutorTests extends TestCase {
return ExitStatus.FINISHED;
}
});
- jobExecutor.run(jobConfiguration, jobExecutionContext);
+ jobExecutor.run(jobConfiguration, jobExecution);
assertEquals(2, list.size());
checkRepository(BatchStatus.COMPLETED, ExitStatus.FINISHED.getExitCode());
}
@@ -182,9 +181,9 @@ public class DefaultJobExecutorTests extends TestCase {
public void testExecutionContextIsSet() throws Exception {
testRunNormally();
- assertEquals(job, jobExecutionContext.getJob());
- assertEquals(step1, stepExecutionContext1.getStep());
- assertEquals(step2, stepExecutionContext2.getStep());
+ assertEquals(job, jobExecution.getJob());
+ assertEquals(step1, stepExecution1.getStep());
+ assertEquals(step2, stepExecution2.getStep());
}
public void testRunWithNonDefaultExecutor() throws Exception {
@@ -197,7 +196,7 @@ public class DefaultJobExecutorTests extends TestCase {
stepConfiguration1.setStartLimit(5);
stepConfiguration2.setStartLimit(5);
- jobExecutor.run(jobConfiguration, jobExecutionContext);
+ jobExecutor.run(jobConfiguration, jobExecution);
assertEquals(2, list.size());
assertEquals("special", list.get(0));
@@ -210,13 +209,13 @@ public class DefaultJobExecutorTests extends TestCase {
stepConfiguration2.setStartLimit(5);
final StepInterruptedException exception = new StepInterruptedException("Interrupt!");
defaultStepLifecycle = new StepExecutor() {
- public ExitStatus process(StepConfiguration configuration, StepExecutionContext stepExecutionContext)
+ public ExitStatus process(StepConfiguration configuration, StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
throw exception;
}
};
try {
- jobExecutor.run(jobConfiguration, jobExecutionContext);
+ jobExecutor.run(jobConfiguration, jobExecution);
}
catch (BatchCriticalException e) {
assertEquals(exception, e.getCause());
@@ -230,13 +229,13 @@ public class DefaultJobExecutorTests extends TestCase {
stepConfiguration2.setStartLimit(5);
final RuntimeException exception = new RuntimeException("Foo!");
defaultStepLifecycle = new StepExecutor() {
- public ExitStatus process(StepConfiguration configuration, StepExecutionContext stepExecutionContext)
+ public ExitStatus process(StepConfiguration configuration, StepExecution stepExecution)
throws StepInterruptedException, BatchCriticalException {
throw exception;
}
};
try {
- jobExecutor.run(jobConfiguration, jobExecutionContext);
+ jobExecutor.run(jobConfiguration, jobExecution);
}
catch (RuntimeException e) {
assertEquals(exception, e);
@@ -250,7 +249,7 @@ public class DefaultJobExecutorTests extends TestCase {
stepConfiguration1.setStartLimit(0);
try{
- jobExecutor.run(jobConfiguration, jobExecutionContext);
+ jobExecutor.run(jobConfiguration, jobExecution);
fail();
}
catch( Exception ex ){
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java b/execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java
index 6976fa408..218fedf11 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/MockStepDao.java
@@ -33,18 +33,16 @@ public class MockStepDao implements StepDao {
public StepInstance createStep(JobInstance job, String stepName) {
StepInstance newStep = (StepInstance) newSteps.get(currentNewStep);
currentNewStep++;
- newStep.setName(stepName);
return newStep;
}
public StepInstance findStep(JobInstance job, String stepName) {
StepInstance newStep = (StepInstance) newSteps.get(currentNewStep);
currentNewStep++;
- newStep.setName(stepName);
return newStep;
}
- public List findSteps(Long jobId) {
+ public List findSteps(JobInstance job) {
return newSteps;
}
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java
index 3491a6c23..25d3e05ad 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/SimpleJobRepositoryTests.java
@@ -276,7 +276,7 @@ public class SimpleJobRepositoryTests extends TestCase {
public void testSaveOrUpdateValidJobExecution() throws Exception {
- JobExecution jobExecution = new JobExecution(new Long(1));
+ JobExecution jobExecution = new JobExecution(new JobInstance(null, new Long(1)));
// new execution - call save on job dao
jobDao.save(jobExecution);
@@ -312,7 +312,7 @@ public class SimpleJobRepositoryTests extends TestCase {
}
public void testUpdateStepExecution(){
- StepExecution stepExecution = new StepExecution(new Long(10), null);
+ StepExecution stepExecution = new StepExecution(new StepInstance(new Long(10L)), null);
stepExecution.setId(new Long(11));
stepDao.update(stepExecution);
stepDaoControl.replay();
@@ -321,7 +321,7 @@ public class SimpleJobRepositoryTests extends TestCase {
}
public void testSaveStepExecution(){
- StepExecution stepExecution = new StepExecution(new Long(10), null);
+ StepExecution stepExecution = new StepExecution(new StepInstance(new Long(10L)), null);
//TODO: Not sure why, but calling save on the EasyMock stepDao causes a NullPointerException
// stepDao.save(stepExecution);
// stepDaoControl.replay();
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java
index a85f19d11..1cd5a82e9 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractJobDaoTests.java
@@ -80,7 +80,7 @@ public abstract class AbstractJobDaoTests extends
// Create an execution
jobExecutionStartTime = new Timestamp(System.currentTimeMillis());
- jobExecution = new JobExecution(job.getId());
+ jobExecution = new JobExecution(new JobInstance(jobRuntimeInformation, job.getId()));
jobExecution.setStartTime(jobExecutionStartTime);
jobExecution.setStatus(BatchStatus.STARTED);
jobDao.save(jobExecution);
@@ -183,7 +183,7 @@ public abstract class AbstractJobDaoTests extends
public void testUpdateInvalidJobExecution() {
- JobExecution execution = new JobExecution(job.getId());
+ JobExecution execution = new JobExecution(job);
// id is invalid
execution.setId(new Long(29432));
try {
@@ -196,7 +196,7 @@ public abstract class AbstractJobDaoTests extends
public void testUpdateNullIdJobExection() {
- JobExecution execution = new JobExecution(job.getId());
+ JobExecution execution = new JobExecution(job);
try {
jobDao.update(execution);
fail();
@@ -211,7 +211,7 @@ public abstract class AbstractJobDaoTests extends
assertEquals(jobDao.getJobExecutionCount(job.getId()), 1);
// Save new JobExecution for same job
- JobExecution testJobExecution = new JobExecution(job.getId());
+ JobExecution testJobExecution = new JobExecution(job);
jobDao.save(testJobExecution);
// JobExecutionCount should be incremented by 1
assertEquals(jobDao.getJobExecutionCount(job.getId()), 2);
@@ -256,8 +256,8 @@ public abstract class AbstractJobDaoTests extends
RowMapper rowMapper = new RowMapper() {
public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
- JobExecution execution = new JobExecution(new Long(rs
- .getLong(1)));
+ JobExecution execution = new JobExecution(new JobInstance(jobRuntimeInformation, new Long(rs
+ .getLong(1))));
execution.setStartTime(rs.getTimestamp(2));
execution.setEndTime(rs.getTimestamp(3));
execution.setStatus(BatchStatus.getStatus(rs.getString(4)));
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java
index abc16b3e4..e14082ffa 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/AbstractStepDaoTests.java
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Properties;
import org.springframework.batch.core.domain.BatchStatus;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -54,6 +55,8 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
protected StepExecution stepExecution;
+ protected JobExecution jobExecution;
+
public void setJobDao(JobDao jobDao) {
this.jobDao = jobDao;
}
@@ -79,8 +82,9 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
job = jobDao.createJob(jobIdentifier);
step1 = stepDao.createStep(job, "TestStep1");
step2 = stepDao.createStep(job, "TestStep2");
+ jobExecution = new JobExecution(step2.getJob());
- stepExecution = new StepExecution(step1.getId(), new Long(23));
+ stepExecution = new StepExecution(step1, jobExecution);
stepExecution.setStatus(BatchStatus.STARTED);
stepExecution.setStartTime(new Timestamp(System.currentTimeMillis()));
stepDao.save(stepExecution);
@@ -110,7 +114,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
public void testFindSteps(){
- List steps = stepDao.findSteps(job.getId());
+ List steps = stepDao.findSteps(job);
assertEquals(steps.size(), 2);
assertTrue(steps.contains(step1));
assertTrue(steps.contains(step2));
@@ -119,7 +123,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
public void testFindStepsNotSaved(){
//no steps are saved for given id, empty list should be returned
- List steps = stepDao.findSteps(new Long(38922));
+ List steps = stepDao.findSteps(new JobInstance(null, new Long(38922)));
assertEquals(steps.size(), 0);
}
@@ -154,7 +158,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
public void testSaveStepExecution(){
- StepExecution execution = new StepExecution(step2.getId(), new Long(10));
+ StepExecution execution = new StepExecution(step2, jobExecution);
execution.setStatus(BatchStatus.STARTED);
execution.setStartTime(new Timestamp(System.currentTimeMillis()));
Properties statistics = new Properties();
@@ -210,7 +214,7 @@ public abstract class AbstractStepDaoTests extends AbstractTransactionalDataSour
public void testIncrementStepExecutionCount(){
assertEquals(1, stepDao.getStepExecutionCount(step1.getId()));
- StepExecution execution = new StepExecution(step1.getId(), new Long(9));
+ StepExecution execution = new StepExecution(step1, new JobExecution(step1.getJob(), new Long(123)));
stepDao.save(execution);
assertEquals(2, stepDao.getStepExecutionCount(step1.getId()));
}
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateStepDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateStepDaoTests.java
index f1d6bd23b..dc88ecb1f 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateStepDaoTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/HibernateStepDaoTests.java
@@ -19,6 +19,7 @@ package org.springframework.batch.execution.repository.dao;
import java.util.Properties;
import org.hibernate.SessionFactory;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.support.PropertiesConverter;
@@ -38,7 +39,7 @@ public class HibernateStepDaoTests extends AbstractStepDaoTests {
public void testSaveStatistics() throws Exception {
StepInstance step = stepDao.createStep(job, "foo");
- StepExecution stepExecution = new StepExecution(step.getId(), new Long(10));
+ StepExecution stepExecution = new StepExecution(step, new JobExecution(step.getJob()));
Properties statistics = new Properties();
statistics.setProperty("x", "y");
statistics.setProperty("a", "b");
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java
index 4b63d0056..754ba547f 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapJobDaoTests.java
@@ -53,22 +53,22 @@ public class MapJobDaoTests extends TestCase {
public void testSaveExecutionUpdatesId() throws Exception {
JobInstance job = dao.createJob(new SimpleJobIdentifier("foo"));
- JobExecution execution = new JobExecution(job.getId());
+ JobExecution execution = new JobExecution(job);
assertNull(execution.getId());
dao.save(execution);
assertNotNull(execution.getId());
}
public void testCorrectExecutionCountForExistingJob() throws Exception {
JobInstance job = dao.createJob(new SimpleJobIdentifier("foo"));
- dao.save(new JobExecution(job.getId()));
+ dao.save(new JobExecution(job));
assertEquals(1, dao.getJobExecutionCount(job.getId()));
}
public void testMultipleExecutionsPerExisting() throws Exception {
JobInstance job = dao.createJob(new SimpleJobIdentifier("foo"));
- dao.save(new JobExecution(job.getId()));
+ dao.save(new JobExecution(job));
Thread.sleep(50L); // Hack, hack, hackety, hack - job executions are not unique if created too close together!
- dao.save(new JobExecution(job.getId()));
+ dao.save(new JobExecution(job));
assertEquals(2, dao.getJobExecutionCount(job.getId()));
}
}
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java
index bf6d9f36e..04636569f 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/MapStepDaoTests.java
@@ -62,19 +62,19 @@ public class MapStepDaoTests extends TestCase {
}
public void testCreateAndRetrieveSingleFromList() throws Exception {
- List result = dao.findSteps(job.getId());
+ List result = dao.findSteps(job);
assertTrue(result.contains(step));
}
public void testCreateAndRetrieveMultiple() throws Exception {
step = dao.createStep(job, "bar");
- List result = dao.findSteps(job.getId());
+ List result = dao.findSteps(job);
assertEquals(2, result.size());
assertTrue(result.contains(step));
}
public void testFindWithEmptyResults() throws Exception {
- List result = dao.findSteps(new Long(22));
+ List result = dao.findSteps(new JobInstance(null, new Long(22)));
assertEquals(0, result.size());
}
@@ -88,20 +88,20 @@ public class MapStepDaoTests extends TestCase {
}
public void testSaveExecutionUpdatesId() throws Exception {
- StepExecution execution = new StepExecution(step.getId(), null);
+ StepExecution execution = new StepExecution(step, null);
assertNull(execution.getId());
dao.save(execution);
assertNotNull(execution.getId());
}
public void testCorrectExecutionCountForExisting() throws Exception {
- dao.save(new StepExecution(step.getId(), null));
+ dao.save(new StepExecution(step, null));
assertEquals(1, dao.getStepExecutionCount(step.getId()));
}
public void testOnlyOneExecutionPerStep() throws Exception {
- dao.save(new StepExecution(step.getId(), null));
- dao.save(new StepExecution(step.getId(), null));
+ dao.save(new StepExecution(step, null));
+ dao.save(new StepExecution(step, null));
assertEquals(2, dao.getStepExecutionCount(step.getId()));
}
diff --git a/execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java b/execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java
index 31f41a232..1c89cdcfb 100644
--- a/execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/repository/dao/SqlStepDaoPrefixTests.java
@@ -4,6 +4,7 @@ import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.batch.core.domain.BatchStatus;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
@@ -24,9 +25,9 @@ public class SqlStepDaoPrefixTests extends TestCase {
MockJdbcTemplate jdbcTemplate = new MockJdbcTemplate();
- StepExecution stepExecution = new StepExecution(new Long(1), new Long(2));
- StepInstance step = new StepInstance(new Long(1));
JobInstance job = new JobInstance(null, new Long(1));
+ StepInstance step = new StepInstance(job, "foo", new Long(1));
+ StepExecution stepExecution = new StepExecution(step, new JobExecution(job));
MockControl stepExecutionIncrementerControl = MockControl.createControl(DataFieldMaxValueIncrementer.class);
DataFieldMaxValueIncrementer stepExecutionIncrementer;
@@ -37,6 +38,7 @@ public class SqlStepDaoPrefixTests extends TestCase {
super.setUp();
stepDao = new SqlStepDao();
+ stepDao.setJobDao(new MapJobDao());
stepExecutionIncrementer = (DataFieldMaxValueIncrementer)stepExecutionIncrementerControl.getMock();
stepIncrementer = (DataFieldMaxValueIncrementer)stepIncrementerControl.getMock();
@@ -88,7 +90,7 @@ public class SqlStepDaoPrefixTests extends TestCase {
public void testModifiedFindSteps(){
stepDao.setTablePrefix("FOO_");
- stepDao.findSteps(new Long(1));
+ stepDao.findSteps(new JobInstance(null, new Long(1)));
assertTrue(jdbcTemplate.getSqlStatement().indexOf("FOO_STEP") != -1);
}
@@ -119,7 +121,7 @@ public class SqlStepDaoPrefixTests extends TestCase {
}
public void testDefaultFindSteps(){
- stepDao.findSteps(new Long(1));
+ stepDao.findSteps(new JobInstance(null, new Long(1)));
assertTrue(jdbcTemplate.getSqlStatement().indexOf("BATCH_STEP") != -1);
}
diff --git a/execution/src/test/java/org/springframework/batch/execution/step/DefaultStepExecutorFactoryTests.java b/execution/src/test/java/org/springframework/batch/execution/step/DefaultStepExecutorFactoryTests.java
index 01af94dcc..34661a138 100644
--- a/execution/src/test/java/org/springframework/batch/execution/step/DefaultStepExecutorFactoryTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/step/DefaultStepExecutorFactoryTests.java
@@ -19,8 +19,8 @@ import junit.framework.TestCase;
import org.springframework.batch.core.configuration.StepConfiguration;
import org.springframework.batch.core.configuration.StepConfigurationSupport;
+import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.executor.StepExecutor;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.execution.step.simple.SimpleStepConfiguration;
import org.springframework.batch.execution.step.simple.SimpleStepExecutor;
import org.springframework.batch.io.exception.BatchCriticalException;
@@ -90,7 +90,7 @@ public class DefaultStepExecutorFactoryTests extends TestCase {
public void testSuccessfulStepExecutorWithSimpleConfigurationAndNotSimpleExecutor() throws Exception {
StepExecutor executor = new StepExecutor() {
- public ExitStatus process(StepConfiguration configuration, StepExecutionContext stepExecutionContext) throws BatchCriticalException {
+ public ExitStatus process(StepConfiguration configuration, StepExecution stepExecution) throws BatchCriticalException {
return ExitStatus.FINISHED;
}
};
diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java
index 40e9ece31..127ad6083 100644
--- a/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/DefaultStepExecutorTests.java
@@ -21,13 +21,12 @@ import java.util.Arrays;
import junit.framework.TestCase;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.ExitCodeExceptionClassifier;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.MapJobDao;
@@ -95,10 +94,10 @@ public class DefaultStepExecutorTests extends TestCase {
StepInstance step = new StepInstance(new Long(9));
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
assertEquals(1, processed.size());
}
@@ -111,12 +110,12 @@ public class DefaultStepExecutorTests extends TestCase {
stepExecutor.setChunkOperations(template);
StepInstance step = new StepInstance(new Long(1));
- step.setStepExecution(new StepExecution(new Long(1), new Long(2)));
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(1)));
+ JobExecution jobExecution = new JobExecution(new JobInstance(jobIdentifier, new Long(1)));
+ step.setStepExecution(new StepExecution(step, jobExecution));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
- stepExecutor.processChunk(stepConfiguration, stepExecutionContext);
+ StepExecution stepExecution = new StepExecution(step, jobExecution);
+ stepExecutor.processChunk(stepConfiguration, stepExecution);
assertEquals(1, processed.size());
}
@@ -130,23 +129,23 @@ public class DefaultStepExecutorTests extends TestCase {
stepExecutor.setChunkOperations(template);
final StepInstance step = new StepInstance(new Long(1));
- step.setStepExecution(new StepExecution(new Long(1),new Long(1)));
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- final JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- final StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ final JobExecution jobExecution = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ step.setStepExecution(new StepExecution(step,jobExecution));
+ final StepExecution stepExecution = new StepExecution(step, jobExecution);
stepConfiguration.setTasklet(new Tasklet() {
public ExitStatus execute() throws Exception {
- assertEquals(step, stepExecutionContext.getStep());
- assertEquals(1, jobExecutionContext.getChunkContexts().size());
- assertEquals(1, jobExecutionContext.getStepContexts().size());
+ assertEquals(step, stepExecution.getStep());
+ assertEquals(1, jobExecution.getChunkContexts().size());
+ assertEquals(1, jobExecution.getStepContexts().size());
assertNotNull(StepSynchronizationManager.getContext().getJobIdentifier());
processed.add("foo");
return ExitStatus.CONTINUABLE;
}
});
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
assertEquals(1, processed.size());
}
@@ -158,10 +157,10 @@ public class DefaultStepExecutorTests extends TestCase {
StepInstance step = new StepInstance(new Long(1));
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
assertEquals(1, processed.size());
}
@@ -185,11 +184,11 @@ public class DefaultStepExecutorTests extends TestCase {
StepInstance step = new StepInstance(new Long(1));
stepConfiguration.setTasklet(tasklet);
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}
catch(Exception ex){
assertEquals(step.getStepExecution().getRollbackCount(), new Integer(1));
@@ -217,11 +216,11 @@ public class DefaultStepExecutorTests extends TestCase {
StepInstance step = new StepInstance(new Long(1));
stepConfiguration.setTasklet(tasklet);
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}
catch(Exception ex){
assertEquals(step.getStepExecution().getExitCode(), ExitCodeExceptionClassifier.FATAL_EXCEPTION);
@@ -240,11 +239,11 @@ public class DefaultStepExecutorTests extends TestCase {
stepConfiguration.setTasklet(tasklet);
stepConfiguration.setSaveRestartData(true);
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}catch(Throwable t){
fail();
}
@@ -264,11 +263,11 @@ public class DefaultStepExecutorTests extends TestCase {
stepConfiguration.setTasklet(tasklet);
stepConfiguration.setSaveRestartData(true);
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}catch(Throwable t){
fail();
}
@@ -288,11 +287,11 @@ public class DefaultStepExecutorTests extends TestCase {
stepConfiguration.setTasklet(tasklet);
stepConfiguration.setSaveRestartData(false);
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}catch(Throwable t){
fail();
}
@@ -315,11 +314,11 @@ public class DefaultStepExecutorTests extends TestCase {
}});
stepConfiguration.setSaveRestartData(true);
SimpleJobIdentifier jobIdentifier = new SimpleJobIdentifier("FOO");
- JobExecutionContext jobExecutionContext = new JobExecutionContext(jobIdentifier, new JobInstance(jobIdentifier, new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecution = new JobExecution(new JobInstance(jobIdentifier, new Long(3)));
+ StepExecution stepExecution = new StepExecution(step, jobExecution);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}catch(Throwable t){
fail();
}
@@ -388,10 +387,10 @@ public class DefaultStepExecutorTests extends TestCase {
StepInstance step = new StepInstance(new Long(1));
stepConfiguration.setTasklet(tasklet);
JobExecutionContext jobExecutionContext = new JobExecutionContext(new SimpleJobIdentifier("FOO"), new JobInstance(new Long(3)));
- StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
try{
- stepExecutor.process(stepConfiguration, stepExecutionContext);
+ stepExecutor.process(stepConfiguration, stepExecution);
}
catch(Exception ex){
assertEquals(ExitCodeExceptionClassifier.STEP_INTERRUPTED, step.getStepExecution().getExitCode() );
diff --git a/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java b/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java
index 607430191..4c73592b0 100644
--- a/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java
+++ b/execution/src/test/java/org/springframework/batch/execution/step/simple/StepExecutorInterruptionTests.java
@@ -22,14 +22,14 @@ import junit.framework.TestCase;
import org.springframework.batch.core.configuration.JobConfiguration;
import org.springframework.batch.core.domain.BatchStatus;
+import org.springframework.batch.core.domain.JobExecution;
import org.springframework.batch.core.domain.JobInstance;
+import org.springframework.batch.core.domain.StepExecution;
import org.springframework.batch.core.domain.StepInstance;
import org.springframework.batch.core.executor.StepInterruptedException;
import org.springframework.batch.core.repository.JobRepository;
-import org.springframework.batch.core.runtime.JobExecutionContext;
import org.springframework.batch.core.runtime.JobIdentifier;
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
-import org.springframework.batch.core.runtime.StepExecutionContext;
import org.springframework.batch.core.tasklet.Tasklet;
import org.springframework.batch.execution.repository.SimpleJobRepository;
import org.springframework.batch.execution.repository.dao.JobDao;
@@ -73,8 +73,8 @@ public class StepExecutorInterruptionTests extends TestCase {
List steps = job.getSteps();
final StepInstance step = (StepInstance) steps.get(0);
- JobExecutionContext jobExecutionContext = new JobExecutionContext(null, new JobInstance(null, new Long(0)));
- final StepExecutionContext stepExecutionContext = new StepExecutionContext(jobExecutionContext, step);
+ JobExecution jobExecutionContext = new JobExecution(new JobInstance(null, new Long(0)));
+ final StepExecution stepExecution = new StepExecution(step, jobExecutionContext);
stepConfiguration.setTasklet(new Tasklet() {
public ExitStatus execute() throws Exception {
// do something non-trivial (and not Thread.sleep())
@@ -90,7 +90,7 @@ public class StepExecutorInterruptionTests extends TestCase {
Thread processingThread = new Thread() {
public void run() {
try {
- executor.process(stepConfiguration, stepExecutionContext);
+ executor.process(stepConfiguration, stepExecution);
}
catch (StepInterruptedException e) {
// do nothing...
diff --git a/execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml b/execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml
index 22a06ea94..a76654e83 100644
--- a/execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml
+++ b/execution/src/test/resources/org/springframework/batch/execution/repository/dao/sql-dao-test.xml
@@ -14,7 +14,8 @@
-
+
+