org.springframework.batch.core.repository.dao
Class JdbcJobInstanceDao

java.lang.Object
  extended by org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
      extended by org.springframework.batch.core.repository.dao.JdbcJobInstanceDao
All Implemented Interfaces:
JobInstanceDao, InitializingBean

public class JdbcJobInstanceDao
extends AbstractJdbcBatchMetadataDao
implements JobInstanceDao, InitializingBean

Jdbc implementation of JobInstanceDao. Uses sequences (via Spring's DataFieldMaxValueIncrementer abstraction) to create all primary keys before inserting a new row. Objects are checked to ensure all mandatory 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.

Author:
Lucas Ward, Dave Syer, Robert Kasanicky

Field Summary
 
Fields inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
DEFAULT_EXIT_MESSAGE_LENGTH, DEFAULT_TABLE_PREFIX
 
Constructor Summary
JdbcJobInstanceDao()
           
 
Method Summary
 void afterPropertiesSet()
           
 JobInstance createJobInstance(String jobName, JobParameters jobParameters)
          In this jdbc implementation a job id is obtained by asking the jobIncrementer (which is likely a sequence) for the next long value, and then passing the Id and parameter values into an INSERT statement.
protected  String createJobKey(JobParameters jobParameters)
           
 JobInstance getJobInstance(JobExecution jobExecution)
          Fetch the JobInstance for the provided JobExecution.
 JobInstance getJobInstance(Long instanceId)
          Fetch the job instance with the provided identifier.
 JobInstance getJobInstance(String jobName, JobParameters jobParameters)
          The job table is queried for any jobs that match the given identifier, adding them to a list via the RowMapper callback.
 List<JobInstance> getJobInstances(String jobName, int start, int count)
          Fetch the last job instances with the provided name, sorted backwards by primary key.
 List<String> getJobNames()
          Retrieve the names of all job instances sorted alphabetically - i.e. jobs that have ever been executed.
 void setJobIncrementer(DataFieldMaxValueIncrementer jobIncrementer)
          Setter for DataFieldMaxValueIncrementer to be used when generating primary keys for JobInstance instances.
 
Methods inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
getClobTypeToUse, getJdbcTemplate, getQuery, getTablePrefix, setClobTypeToUse, setJdbcTemplate, setTablePrefix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcJobInstanceDao

public JdbcJobInstanceDao()
Method Detail

createJobInstance

public JobInstance createJobInstance(String jobName,
                                     JobParameters jobParameters)
In this jdbc implementation a job id is obtained by asking the jobIncrementer (which is likely a sequence) for the next long value, and then passing the Id and parameter values into an INSERT statement.

Specified by:
createJobInstance in interface JobInstanceDao
Returns:
JobInstance
Throws:
IllegalArgumentException - if any JobParameters fields are null.
See Also:
JobInstanceDao.createJobInstance(String, JobParameters)

createJobKey

protected String createJobKey(JobParameters jobParameters)

getJobInstance

public JobInstance getJobInstance(String jobName,
                                  JobParameters jobParameters)
The job table is queried for any jobs that match the given identifier, adding them to a list via the RowMapper callback.

Specified by:
getJobInstance in interface JobInstanceDao
Parameters:
jobName - the name of the job
jobParameters - the parameters with which the job was executed
Returns:
JobInstance object matching the job name and JobParameters or null
Throws:
IllegalArgumentException - if any JobParameters fields are null.
See Also:
JobInstanceDao.getJobInstance(String, JobParameters)

getJobInstance

public JobInstance getJobInstance(Long instanceId)
Description copied from interface: JobInstanceDao
Fetch the job instance with the provided identifier.

Specified by:
getJobInstance in interface JobInstanceDao
Parameters:
instanceId - the job identifier
Returns:
the job instance with this identifier or null if it doesn't exist

getJobNames

public List<String> getJobNames()
Description copied from interface: JobInstanceDao
Retrieve the names of all job instances sorted alphabetically - i.e. jobs that have ever been executed.

Specified by:
getJobNames in interface JobInstanceDao
Returns:
the names of all job instances

getJobInstances

public List<JobInstance> getJobInstances(String jobName,
                                         int start,
                                         int count)
Description copied from interface: JobInstanceDao
Fetch the last job instances with the provided name, sorted backwards by primary key.

Specified by:
getJobInstances in interface JobInstanceDao
Parameters:
jobName - the job name
start - the start index of the instances to return
count - the maximum number of objects to return
Returns:
the job instances with this name or empty if none

getJobInstance

public JobInstance getJobInstance(JobExecution jobExecution)
Description copied from interface: JobInstanceDao
Fetch the JobInstance for the provided JobExecution.

Specified by:
getJobInstance in interface JobInstanceDao
Parameters:
jobExecution - the JobExecution
Returns:
the JobInstance for the provided execution or null if it doesn't exist.

setJobIncrementer

public void setJobIncrementer(DataFieldMaxValueIncrementer jobIncrementer)
Setter for DataFieldMaxValueIncrementer to be used when generating primary keys for JobInstance instances.

Parameters:
jobIncrementer - the DataFieldMaxValueIncrementer

afterPropertiesSet

public void afterPropertiesSet()
                        throws Exception
Specified by:
afterPropertiesSet in interface InitializingBean
Overrides:
afterPropertiesSet in class AbstractJdbcBatchMetadataDao
Throws:
Exception


Copyright © 2013 SpringSource. All Rights Reserved.