001/* 002 * Copyright 2006-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.core.repository.dao; 018 019import java.util.List; 020import java.util.Set; 021 022import org.springframework.batch.core.JobExecution; 023import org.springframework.batch.core.JobInstance; 024import org.springframework.lang.Nullable; 025 026/** 027 * Data Access Object for job executions. 028 * 029 * @author Lucas Ward 030 * @author Robert Kasanicky 031 * @author Mahmoud Ben Hassine 032 */ 033public interface JobExecutionDao { 034 035 /** 036 * Save a new JobExecution. 037 * 038 * Preconditions: jobInstance the jobExecution belongs to must have a 039 * jobInstanceId. 040 * 041 * @param jobExecution {@link JobExecution} instance to be saved. 042 */ 043 void saveJobExecution(JobExecution jobExecution); 044 045 /** 046 * Update and existing JobExecution. 047 * 048 * Preconditions: jobExecution must have an Id (which can be obtained by the 049 * save method) and a jobInstanceId. 050 * 051 * @param jobExecution {@link JobExecution} instance to be updated. 052 */ 053 void updateJobExecution(JobExecution jobExecution); 054 055 /** 056 * Return all {@link JobExecution}s for given {@link JobInstance}, sorted 057 * backwards by creation order (so the first element is the most recent). 058 * 059 * @param jobInstance parent {@link JobInstance} of the {@link JobExecution}s to find. 060 * @return {@link List} containing JobExecutions for the jobInstance. 061 */ 062 List<JobExecution> findJobExecutions(JobInstance jobInstance); 063 064 /** 065 * Find the last {@link JobExecution} to have been created for a given 066 * {@link JobInstance}. 067 * @param jobInstance the {@link JobInstance} 068 * @return the last {@link JobExecution} to execute for this instance or 069 * {@code null} if no job execution is found for the given job instance. 070 */ 071 @Nullable 072 JobExecution getLastJobExecution(JobInstance jobInstance); 073 074 /** 075 * @param jobName {@link String} containing the name of the job. 076 * @return all {@link JobExecution} that are still running (or indeterminate 077 * state), i.e. having null end date, for the specified job name. 078 */ 079 Set<JobExecution> findRunningJobExecutions(String jobName); 080 081 /** 082 * @param executionId {@link Long} containing the id of the execution. 083 * @return the {@link JobExecution} for given identifier. 084 */ 085 @Nullable 086 JobExecution getJobExecution(Long executionId); 087 088 /** 089 * Because it may be possible that the status of a JobExecution is updated 090 * while running, the following method will synchronize only the status and 091 * version fields. 092 * 093 * @param jobExecution to be updated. 094 */ 095 void synchronizeStatus(JobExecution jobExecution); 096 097}