Class JdbcJobInstanceDao
java.lang.Object
org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
org.springframework.batch.core.repository.dao.JdbcJobInstanceDao
- All Implemented Interfaces:
JobInstanceDao,org.springframework.beans.factory.InitializingBean
public class JdbcJobInstanceDao
extends AbstractJdbcBatchMetadataDao
implements JobInstanceDao, org.springframework.beans.factory.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, Michael Minella, Will Schipp, Mahmoud Ben Hassine, Parikshit Dutta
-
Field Summary
Fields inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
DEFAULT_EXIT_MESSAGE_LENGTH, DEFAULT_TABLE_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcreateJobInstance(String jobName, JobParameters jobParameters) In this JDBC implementation a job instance id is obtained by asking the jobInstanceIncrementer (which is likely a sequence) for the next long value, and then passing the Id and parameter values into an INSERT statement.voiddeleteJobInstance(JobInstance jobInstance) Delete the job instance.findJobInstancesByName(String jobName, int start, int count) Fetch the last job instances with the provided name, sorted backwards by primary key, using a 'like' criteriagetJobInstance(Long instanceId) Fetch the job instance with the provided identifier.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.getJobInstance(JobExecution jobExecution) Fetch the JobInstance for the provided JobExecution.longgetJobInstanceCount(String jobName) Query the repository for the number of uniqueJobInstances associated with the supplied job name.getJobInstances(String jobName, int start, int count) Fetch the last job instances with the provided name, sorted backwards by primary key.Retrieve the names of all job instances sorted alphabetically - i.e.getLastJobInstance(String jobName) Fetch the last job instance by Id for the given job.voidsetJobIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer jobIncrementer) Deprecated.voidsetJobInstanceIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer jobInstanceIncrementer) Setter forDataFieldMaxValueIncrementerto be used when generating primary keys forJobInstanceinstances.Methods inherited from class org.springframework.batch.core.repository.dao.AbstractJdbcBatchMetadataDao
getClobTypeToUse, getJdbcTemplate, getQuery, getTablePrefix, setClobTypeToUse, setJdbcTemplate, setTablePrefix
-
Constructor Details
-
JdbcJobInstanceDao
public JdbcJobInstanceDao()
-
-
Method Details
-
createJobInstance
In this JDBC implementation a job instance id is obtained by asking the jobInstanceIncrementer (which is likely a sequence) for the next long value, and then passing the Id and parameter values into an INSERT statement.- Specified by:
createJobInstancein interfaceJobInstanceDao- Parameters:
jobName-Stringcontaining the name of the job.jobParameters-JobParameterscontaining the parameters for the JobInstance.- Returns:
- JobInstance
JobInstanceinstance that was created. - Throws:
IllegalArgumentException- if anyJobParametersfields are null.- See Also:
-
getJobInstance
The job table is queried for any jobs that match the given identifier, adding them to a list via the RowMapper callback.- Specified by:
getJobInstancein interfaceJobInstanceDao- Parameters:
jobName- the name of the jobjobParameters- the parameters with which the job was executed- Returns:
JobInstanceobject matching the job name andJobParametersornull- Throws:
IllegalArgumentException- if anyJobParametersfields are null.- See Also:
-
getJobInstance
Description copied from interface:JobInstanceDaoFetch the job instance with the provided identifier.- Specified by:
getJobInstancein interfaceJobInstanceDao- Parameters:
instanceId- the job identifier- Returns:
- the job instance with this identifier or
nullif it doesn't exist
-
getJobNames
Description copied from interface:JobInstanceDaoRetrieve the names of all job instances sorted alphabetically - i.e. jobs that have ever been executed.- Specified by:
getJobNamesin interfaceJobInstanceDao- Returns:
- the names of all job instances
-
getJobInstances
Description copied from interface:JobInstanceDaoFetch the last job instances with the provided name, sorted backwards by primary key. if using the JdbcJobInstance, you can provide the jobName with a wildcard (e.g. *Job) to return 'like' job names. (e.g. *Job will return 'someJob' and 'otherJob')- Specified by:
getJobInstancesin interfaceJobInstanceDao- Parameters:
jobName- the job namestart- the start index of the instances to returncount- the maximum number of objects to return- Returns:
- the job instances with this name or empty if none
-
getLastJobInstance
Description copied from interface:JobInstanceDaoFetch the last job instance by Id for the given job.- Specified by:
getLastJobInstancein interfaceJobInstanceDao- Parameters:
jobName- name of the job- Returns:
- the last job instance by Id if any or null otherwise
-
getJobInstance
Description copied from interface:JobInstanceDaoFetch the JobInstance for the provided JobExecution.- Specified by:
getJobInstancein interfaceJobInstanceDao- Parameters:
jobExecution- the JobExecution- Returns:
- the JobInstance for the provided execution or
nullif it doesn't exist.
-
getJobInstanceCount
Description copied from interface:JobInstanceDaoQuery the repository for the number of uniqueJobInstances associated with the supplied job name.- Specified by:
getJobInstanceCountin interfaceJobInstanceDao- Parameters:
jobName- the name of the job to query for- Returns:
- the number of
JobInstances that exist within the associated job repository - Throws:
NoSuchJobException- thrown if no Job has the jobName specified.
-
deleteJobInstance
Delete the job instance.- Specified by:
deleteJobInstancein interfaceJobInstanceDao- Parameters:
jobInstance- the job instance to delete
-
setJobIncrementer
@Deprecated public void setJobIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer jobIncrementer) Deprecated.as of v5.0 in favor of using thesetJobInstanceIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer)Setter forDataFieldMaxValueIncrementerto be used when generating primary keys forJobInstanceinstances.- Parameters:
jobIncrementer- theDataFieldMaxValueIncrementer
-
setJobInstanceIncrementer
public void setJobInstanceIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer jobInstanceIncrementer) Setter forDataFieldMaxValueIncrementerto be used when generating primary keys forJobInstanceinstances.- Parameters:
jobInstanceIncrementer- theDataFieldMaxValueIncrementer- Since:
- 5.0
-
afterPropertiesSet
- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Overrides:
afterPropertiesSetin classAbstractJdbcBatchMetadataDao- Throws:
Exception
-
findJobInstancesByName
Description copied from interface:JobInstanceDaoFetch the last job instances with the provided name, sorted backwards by primary key, using a 'like' criteria- Specified by:
findJobInstancesByNamein interfaceJobInstanceDao- Parameters:
jobName-Stringcontaining the name of the job.start- int containing the offset of where list of job instances results should begin.count- int containing the number of job instances to return.- Returns:
- a list of
JobInstancefor the job name requested.
-
setJobInstanceIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer)