Class JdbcTaskExecutionDao

java.lang.Object
org.springframework.cloud.task.repository.dao.JdbcTaskExecutionDao
All Implemented Interfaces:
TaskExecutionDao

public class JdbcTaskExecutionDao extends Object implements TaskExecutionDao
Stores Task Execution Information to a JDBC DataSource.
Author:
Glenn Renfro, Gunnar Hillert, David Turanski, Ilayaperumal Gopinathan, Michael Minella
  • Field Details

  • Constructor Details

    • JdbcTaskExecutionDao

      public JdbcTaskExecutionDao(DataSource dataSource, String tablePrefix)
      Initializes the JdbcTaskExecutionDao.
      Parameters:
      dataSource - used by the dao to execute queries and update the tables.
      tablePrefix - the table prefix to use for this dao.
    • JdbcTaskExecutionDao

      public JdbcTaskExecutionDao(DataSource dataSource)
      Initializes the JdbTaskExecutionDao and defaults the table prefix to TaskProperties.DEFAULT_TABLE_PREFIX.
      Parameters:
      dataSource - used by the dao to execute queries and update the tables.
  • Method Details

    • createTaskExecution

      public TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments, String externalExecutionId)
      Description copied from interface: TaskExecutionDao
      Save a new TaskExecution.
      Specified by:
      createTaskExecution in interface TaskExecutionDao
      Parameters:
      taskName - the name that associated with the task execution.
      startTime - the time task began.
      arguments - list of key/value pairs that configure the task.
      externalExecutionId - id assigned to the task by the platform
      Returns:
      A fully qualified TaskExecution instance.
    • createTaskExecution

      public TaskExecution createTaskExecution(String taskName, LocalDateTime startTime, List<String> arguments, String externalExecutionId, Long parentExecutionId)
      Description copied from interface: TaskExecutionDao
      Save a new TaskExecution.
      Specified by:
      createTaskExecution in interface TaskExecutionDao
      Parameters:
      taskName - the name that associated with the task execution.
      startTime - the time task began.
      arguments - list of key/value pairs that configure the task.
      externalExecutionId - id assigned to the task by the platform
      parentExecutionId - the parent task execution id.
      Returns:
      A fully qualified TaskExecution instance.
    • startTaskExecution

      public TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime, List<String> arguments, String externalExecutionId)
      Description copied from interface: TaskExecutionDao
      Update and existing TaskExecution to mark it as started.
      Specified by:
      startTaskExecution in interface TaskExecutionDao
      Parameters:
      executionId - the id of the taskExecution to be updated.
      taskName - the name that associated with the task execution.
      startTime - the time task began.
      arguments - list of key/value pairs that configure the task.
      externalExecutionId - id assigned to the task by the platform
      Returns:
      A TaskExecution containing the information available at task execution start.
    • startTaskExecution

      public TaskExecution startTaskExecution(long executionId, String taskName, LocalDateTime startTime, List<String> arguments, String externalExecutionId, Long parentExecutionId)
      Description copied from interface: TaskExecutionDao
      Update and existing TaskExecution to mark it as started.
      Specified by:
      startTaskExecution in interface TaskExecutionDao
      Parameters:
      executionId - the id of the taskExecution to be updated.
      taskName - the name that associated with the task execution.
      startTime - the time task began.
      arguments - list of key/value pairs that configure the task.
      externalExecutionId - id assigned to the task by the platform
      parentExecutionId - the parent task execution id.
      Returns:
      A TaskExecution containing the information available at task execution start.
    • completeTaskExecution

      public void completeTaskExecution(long taskExecutionId, Integer exitCode, LocalDateTime endTime, String exitMessage, String errorMessage)
      Description copied from interface: TaskExecutionDao
      Update and existing TaskExecution to mark it as completed.
      Specified by:
      completeTaskExecution in interface TaskExecutionDao
      Parameters:
      taskExecutionId - the id of the taskExecution to be updated.
      exitCode - the status of the task upon completion.
      endTime - the time the task completed.
      exitMessage - the message assigned to the task upon completion.
      errorMessage - error information available upon failure of a task.
    • completeTaskExecution

      public void completeTaskExecution(long taskExecutionId, Integer exitCode, LocalDateTime endTime, String exitMessage)
      Description copied from interface: TaskExecutionDao
      Update and existing TaskExecution.
      Specified by:
      completeTaskExecution in interface TaskExecutionDao
      Parameters:
      taskExecutionId - the id of the taskExecution to be updated.
      exitCode - the status of the task upon completion.
      endTime - the time the task completed.
      exitMessage - the message assigned to the task upon completion.
    • getTaskExecution

      public TaskExecution getTaskExecution(long executionId)
      Description copied from interface: TaskExecutionDao
      Retrieves a task execution from the task repository.
      Specified by:
      getTaskExecution in interface TaskExecutionDao
      Parameters:
      executionId - the id associated with the task execution.
      Returns:
      a fully qualified TaskExecution instance.
    • getTaskExecutionCountByTaskName

      public long getTaskExecutionCountByTaskName(String taskName)
      Description copied from interface: TaskExecutionDao
      Retrieves current number of task executions for a taskName.
      Specified by:
      getTaskExecutionCountByTaskName in interface TaskExecutionDao
      Parameters:
      taskName - the name of the task to search for in the repository.
      Returns:
      current number of task executions for the taskName.
    • getRunningTaskExecutionCountByTaskName

      public long getRunningTaskExecutionCountByTaskName(String taskName)
      Description copied from interface: TaskExecutionDao
      Retrieves current number of task executions for a taskName and with an endTime of null.
      Specified by:
      getRunningTaskExecutionCountByTaskName in interface TaskExecutionDao
      Parameters:
      taskName - the name of the task to search for in the repository.
      Returns:
      current number of task executions for the taskName.
    • getRunningTaskExecutionCount

      public long getRunningTaskExecutionCount()
      Description copied from interface: TaskExecutionDao
      Retrieves current number of task executions with an endTime of null.
      Specified by:
      getRunningTaskExecutionCount in interface TaskExecutionDao
      Returns:
      current number of task executions.
    • getLatestTaskExecutionsByTaskNames

      public List<TaskExecution> getLatestTaskExecutionsByTaskNames(String... taskNames)
      Description copied from interface: TaskExecutionDao
      Returns a List of the latest TaskExecution for 1 or more task names. Latest is defined by the most recent start time. A TaskExecution does not have to be finished (The results may including pending TaskExecutions). It is theoretically possible that a TaskExecution with the same name to have more than 1 TaskExecution for the exact same start time. In that case the TaskExecution with the highest Task Execution ID is returned. This method will not consider end times in its calculations. Thus, when a task execution A starts after task execution B but finishes BEFORE task execution A, then task execution B is being returned.
      Specified by:
      getLatestTaskExecutionsByTaskNames in interface TaskExecutionDao
      Parameters:
      taskNames - At least 1 task name must be provided
      Returns:
      List of TaskExecutions. May be empty but never null.
    • getLatestTaskExecutionForTaskName

      public TaskExecution getLatestTaskExecutionForTaskName(String taskName)
      Description copied from interface: TaskExecutionDao
      Returns the latest task execution for a given task name. Will ultimately apply the same algorithm underneath as TaskExecutionDao.getLatestTaskExecutionsByTaskNames(String...) but will only return a single result.
      Specified by:
      getLatestTaskExecutionForTaskName in interface TaskExecutionDao
      Parameters:
      taskName - Must not be null or empty
      Returns:
      The latest Task Execution or null
      See Also:
    • getTaskExecutionCount

      public long getTaskExecutionCount()
      Description copied from interface: TaskExecutionDao
      Retrieves current number of task executions.
      Specified by:
      getTaskExecutionCount in interface TaskExecutionDao
      Returns:
      current number of task executions.
    • findRunningTaskExecutions

      public org.springframework.data.domain.Page<TaskExecution> findRunningTaskExecutions(String taskName, org.springframework.data.domain.Pageable pageable)
      Description copied from interface: TaskExecutionDao
      Retrieves a set of task executions that are running for a taskName.
      Specified by:
      findRunningTaskExecutions in interface TaskExecutionDao
      Parameters:
      taskName - the name of the task to search for in the repository.
      pageable - the constraints for the search.
      Returns:
      set of running task executions.
    • findTaskExecutionsByName

      public org.springframework.data.domain.Page<TaskExecution> findTaskExecutionsByName(String taskName, org.springframework.data.domain.Pageable pageable)
      Description copied from interface: TaskExecutionDao
      Retrieves a subset of task executions by task name, start location and size.
      Specified by:
      findTaskExecutionsByName in interface TaskExecutionDao
      Parameters:
      taskName - the name of the task to search for in the repository.
      pageable - the constraints for the search.
      Returns:
      a list that contains task executions from the query bound by the start position and count specified by the user.
    • getTaskNames

      public List<String> getTaskNames()
      Description copied from interface: TaskExecutionDao
      Retrieves a sorted list of distinct task names for the task executions.
      Specified by:
      getTaskNames in interface TaskExecutionDao
      Returns:
      a list of distinct task names from the task repository..
    • findAll

      public org.springframework.data.domain.Page<TaskExecution> findAll(org.springframework.data.domain.Pageable pageable)
      Description copied from interface: TaskExecutionDao
      Retrieves all the task executions within the pageable constraints.
      Specified by:
      findAll in interface TaskExecutionDao
      Parameters:
      pageable - the constraints for the search
      Returns:
      page containing the results from the search
    • setTaskIncrementer

      public void setTaskIncrementer(org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer taskIncrementer)
    • getNextExecutionId

      public long getNextExecutionId()
      Description copied from interface: TaskExecutionDao
      Retrieves the next available execution id for a task execution.
      Specified by:
      getNextExecutionId in interface TaskExecutionDao
      Returns:
      long containing the executionId.
    • getTaskExecutionIdByJobExecutionId

      public Long getTaskExecutionIdByJobExecutionId(long jobExecutionId)
      Description copied from interface: TaskExecutionDao
      Returns the id of the TaskExecution that the requested Spring Batch job execution was executed within the context of. Returns null if non were found.
      Specified by:
      getTaskExecutionIdByJobExecutionId in interface TaskExecutionDao
      Parameters:
      jobExecutionId - the id of the JobExecution
      Returns:
      the id of the TaskExecution
    • getJobExecutionIdsByTaskExecutionId

      public Set<Long> getJobExecutionIdsByTaskExecutionId(long taskExecutionId)
      Description copied from interface: TaskExecutionDao
      Returns the job execution ids associated with a task execution id.
      Specified by:
      getJobExecutionIdsByTaskExecutionId in interface TaskExecutionDao
      Parameters:
      taskExecutionId - id of the TaskExecution
      Returns:
      a Set of the ids of the job executions executed within the task.
    • updateExternalExecutionId

      public void updateExternalExecutionId(long taskExecutionId, String externalExecutionId)
      Description copied from interface: TaskExecutionDao
      Updates the externalExecutionId for the execution id specified.
      Specified by:
      updateExternalExecutionId in interface TaskExecutionDao
      Parameters:
      taskExecutionId - the execution id for the task to be updated.
      externalExecutionId - the new externalExecutionId.