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
  • Constructor Details

    • JdbcJobInstanceDao

      public JdbcJobInstanceDao()
  • Method Details

    • createJobInstance

      public JobInstance createJobInstance(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.
      Specified by:
      createJobInstance in interface JobInstanceDao
      Parameters:
      jobName - String containing the name of the job.
      jobParameters - JobParameters containing the parameters for the JobInstance.
      Returns:
      JobInstance JobInstance instance that was created.
      Throws:
      IllegalArgumentException - if any JobParameters fields are null.
      See Also:
    • getJobInstance

      @Nullable 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:
    • getJobInstance

      @Nullable public JobInstance getJobInstance(@Nullable 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.

      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:
      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
    • getLastJobInstance

      @Nullable public JobInstance getLastJobInstance(String jobName)
      Description copied from interface: JobInstanceDao
      Fetch the last job instance by Id for the given job.
      Specified by:
      getLastJobInstance in interface JobInstanceDao
      Parameters:
      jobName - name of the job
      Returns:
      the last job instance by Id if any or null otherwise
    • getJobInstance

      @Nullable 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.
    • getJobInstanceCount

      public long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException
      Description copied from interface: JobInstanceDao
      Query the repository for the number of unique JobInstances associated with the supplied job name.
      Specified by:
      getJobInstanceCount in interface JobInstanceDao
      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

      public void deleteJobInstance(JobInstance jobInstance)
      Delete the job instance.
      Specified by:
      deleteJobInstance in interface JobInstanceDao
      Parameters:
      jobInstance - the job instance to delete
    • setJobIncrementer

      @Deprecated public void setJobIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer jobIncrementer)
      Setter for DataFieldMaxValueIncrementer to be used when generating primary keys for JobInstance instances.
      Parameters:
      jobIncrementer - the DataFieldMaxValueIncrementer
    • setJobInstanceIncrementer

      public void setJobInstanceIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer jobInstanceIncrementer)
      Setter for DataFieldMaxValueIncrementer to be used when generating primary keys for JobInstance instances.
      Parameters:
      jobInstanceIncrementer - the DataFieldMaxValueIncrementer
      Since:
      5.0
    • setJobKeyGenerator

      public void setJobKeyGenerator(JobKeyGenerator jobKeyGenerator)
      Setter for JobKeyGenerator to be used when generating unique identifiers for JobInstance objects.
      Parameters:
      jobKeyGenerator - the JobKeyGenerator
      Since:
      5.1
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Overrides:
      afterPropertiesSet in class AbstractJdbcBatchMetadataDao
      Throws:
      Exception
    • findJobInstancesByName

      public List<JobInstance> findJobInstancesByName(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, using a 'like' criteria
      Specified by:
      findJobInstancesByName in interface JobInstanceDao
      Parameters:
      jobName - String containing 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 JobInstance for the job name requested.