BATCH-146: Changed my mind on the implementation, SimpleJobRepository (and DAOs) now throw Spring IncorrectResultSetSizeDataAccessException, rather than BatchRestartException.
This commit is contained in:
@@ -33,6 +33,7 @@ import org.springframework.batch.core.runtime.JobIdentifier;
|
||||
import org.springframework.batch.execution.repository.dao.JobDao;
|
||||
import org.springframework.batch.execution.repository.dao.StepDao;
|
||||
import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -116,8 +117,8 @@ public class SimpleJobRepository implements JobRepository {
|
||||
}
|
||||
else {
|
||||
// More than one job found, throw exception
|
||||
throw new BatchRestartException("Error restarting job, more than one JobInstance found for: "
|
||||
+ jobConfiguration.toString());
|
||||
throw new IncorrectResultSizeDataAccessException("Error restarting job, more than one JobInstance found for: "
|
||||
+ jobConfiguration.toString(), 1, jobs.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ import org.springframework.util.Assert;
|
||||
* Implementation of {@link JobDao} functionality based 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
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@ public class HibernateJobDao extends HibernateDaoSupport implements JobDao {
|
||||
|
||||
/**
|
||||
* @see JobDao#createJob(JobIdentifier)
|
||||
*
|
||||
*
|
||||
* In this Hibernate implementation a job is stored into the database. Id is
|
||||
* obtained from Hibernate.
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ public class HibernateJobDao extends HibernateDaoSupport implements JobDao {
|
||||
|
||||
/**
|
||||
* @see JobDao#findJobs(JobIdentifier)
|
||||
*
|
||||
*
|
||||
* Hibernate is asked to get all jobs that matches criteria. Afterwards,
|
||||
* result is mapped into domain objects.
|
||||
*/
|
||||
@@ -109,7 +109,7 @@ public class HibernateJobDao extends HibernateDaoSupport implements JobDao {
|
||||
|
||||
/**
|
||||
* @see JobDao#save(JobExecution)
|
||||
*
|
||||
*
|
||||
* Hibernate implementation persists JobExecution instance. Id is obtained
|
||||
* from Hibernate.
|
||||
*/
|
||||
@@ -168,7 +168,7 @@ public class HibernateJobDao extends HibernateDaoSupport implements JobDao {
|
||||
public Object doInHibernate(Session session) {
|
||||
Criteria criteria = session
|
||||
.createCriteria(JobExecution.class);
|
||||
criteria.add(Expression.eq("jobId", jobId));
|
||||
criteria.add(Expression.eq("job.id", jobId));
|
||||
return criteria.list();
|
||||
}
|
||||
});
|
||||
@@ -179,7 +179,7 @@ public class HibernateJobDao extends HibernateDaoSupport implements JobDao {
|
||||
/*
|
||||
* Validate JobExecution. At a minimum, JobId, StartTime, EndTime, and
|
||||
* Status cannot be null.
|
||||
*
|
||||
*
|
||||
* @param jobExecution @throws IllegalArgumentException
|
||||
*/
|
||||
private void validateJobExecution(JobExecution jobExecution) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.batch.restart.GenericRestartData;
|
||||
import org.springframework.batch.restart.RestartData;
|
||||
import org.springframework.batch.support.PropertiesConverter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer;
|
||||
@@ -41,18 +42,18 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* checked to ensure all fields to be stored are not null. If any are
|
||||
* found to be null, an IllegalArgumentException will be thrown. This
|
||||
* could be left to JdbcTemplate, however, the exception will be fairly
|
||||
* vague, and fails to highlight which field caused the exception.
|
||||
*
|
||||
*
|
||||
* TODO: JavaDoc should be geared more towards usability, the comments above are
|
||||
* useful information, and should be there, but needs usability stuff. Depends
|
||||
* on the step dao java docs as well.
|
||||
*
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @see StepDao
|
||||
*/
|
||||
@@ -97,7 +98,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
* Public setter for the table prefix property. This will be prefixed to all
|
||||
* the table names before queries are executed. Defaults to
|
||||
* {@value #DEFAULT_TABLE_PREFIX}.
|
||||
*
|
||||
*
|
||||
* @param tablePrefix
|
||||
* the tablePrefix to set
|
||||
*/
|
||||
@@ -121,11 +122,11 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
* row returned to a step object. If none are found, the list will be empty
|
||||
* and null will be returned. If one step is found, it will be returned. If
|
||||
* anymore than one step is found, an exception is thrown.
|
||||
*
|
||||
*
|
||||
* @see StepDao#findStep(Long, String)
|
||||
* @throws IllegalArgumentException
|
||||
* if job, stepName, or job.id is null.
|
||||
* @throws NoSuchBatchDomainObjectException
|
||||
* @throws IncorrectResultSizeDataAccessException
|
||||
* if more than one step is found.
|
||||
*/
|
||||
public StepInstance findStep(JobInstance job, String stepName) {
|
||||
@@ -162,19 +163,19 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
// This error will likely never be thrown, because there should
|
||||
// never be two steps with the same name and Job_ID due to database
|
||||
// constraints.
|
||||
throw new NoSuchBatchDomainObjectException(
|
||||
throw new IncorrectResultSizeDataAccessException(
|
||||
"Step Invalid, multiple steps found for StepName:"
|
||||
+ stepName + " and JobId:" + job.getId());
|
||||
+ stepName + " and JobId:" + job.getId(), 1, steps.size());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if jobId is null.
|
||||
*/
|
||||
@@ -205,7 +206,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
* Create a step with the given job's id, and the provided step name. A
|
||||
* unique id is created for the step using an incrementer. (@link
|
||||
* DataFieldMaxValueIncrementer)
|
||||
*
|
||||
*
|
||||
* @see StepDao#createStep(JobInstance, String)
|
||||
* @throws IllegalArgumentException
|
||||
* if job or stepName is null.
|
||||
@@ -251,7 +252,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
* Save a StepExecution. A unique id will be generated by the
|
||||
* stepExecutionIncrementor, and then set in the StepExecution. All values
|
||||
* will then be stored via an INSERT statement.
|
||||
*
|
||||
*
|
||||
* @see StepDao#save(StepExecution)
|
||||
*/
|
||||
public void save(StepExecution stepExecution) {
|
||||
@@ -333,12 +334,10 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
/**
|
||||
* Get StepExecution for the given step. Due to the nature of statistics,
|
||||
* they will not be returned with reconstituted object.
|
||||
*
|
||||
*
|
||||
* @see StepDao#getStepExecution(Long)
|
||||
* @throws IllegalArgumentException
|
||||
* if id is null.
|
||||
* @throws NoSuchBatchDomainObjectException
|
||||
* if more than one step execution is returned.
|
||||
*/
|
||||
public List findStepExecutions(final StepInstance step) {
|
||||
|
||||
@@ -400,7 +399,7 @@ public class SqlStepDao implements StepDao, InitializingBean {
|
||||
/*
|
||||
* Validate StepExecution. At a minimum, JobId, StartTime, and Status cannot
|
||||
* be null. EndTime can be null for an unfinished job.
|
||||
*
|
||||
*
|
||||
* @param jobExecution @throws IllegalArgumentException
|
||||
*/
|
||||
private void validateStepExecution(StepExecution stepExecution) {
|
||||
|
||||
Reference in New Issue
Block a user