|
20 | 20 | import org.springframework.batch.core.job.JobExecution;
|
21 | 21 | import org.springframework.batch.core.job.JobInstance;
|
22 | 22 | import org.springframework.batch.core.job.parameters.JobParameters;
|
| 23 | +import org.springframework.batch.core.launch.NoSuchJobException; |
23 | 24 | import org.springframework.batch.core.step.Step;
|
24 | 25 | import org.springframework.batch.core.step.StepExecution;
|
25 | 26 | import org.springframework.batch.core.repository.explore.JobExplorer;
|
26 | 27 | import org.springframework.batch.core.repository.dao.JobExecutionDao;
|
27 | 28 | import org.springframework.batch.core.repository.dao.JobInstanceDao;
|
28 | 29 | import org.springframework.batch.item.ExecutionContext;
|
| 30 | +import org.springframework.lang.Nullable; |
29 | 31 | import org.springframework.transaction.annotation.Isolation;
|
30 | 32 |
|
31 | 33 | import java.util.Collection;
|
| 34 | +import java.util.Collections; |
| 35 | +import java.util.List; |
| 36 | +import java.util.Set; |
32 | 37 |
|
33 | 38 | /**
|
34 | 39 | * <p>
|
|
48 | 53 | */
|
49 | 54 | public interface JobRepository extends JobExplorer {
|
50 | 55 |
|
| 56 | + /* |
| 57 | + * =================================================================================== |
| 58 | + * Read operations |
| 59 | + * =================================================================================== |
| 60 | + */ |
| 61 | + |
| 62 | + /* |
| 63 | + * =================================================================================== |
| 64 | + * Job operations |
| 65 | + * =================================================================================== |
| 66 | + */ |
| 67 | + |
| 68 | + /** |
| 69 | + * Query the repository for all unique {@link JobInstance} names (sorted |
| 70 | + * alphabetically). |
| 71 | + * @return the list of job names that have been executed. |
| 72 | + */ |
| 73 | + default List<String> getJobNames() { |
| 74 | + return Collections.emptyList(); |
| 75 | + } |
| 76 | + |
| 77 | + /* |
| 78 | + * =================================================================================== |
| 79 | + * Job instance operations |
| 80 | + * =================================================================================== |
| 81 | + */ |
| 82 | + |
| 83 | + /** |
| 84 | + * Fetch {@link JobInstance} values in descending order of creation (and, therefore, |
| 85 | + * usually, of first execution). |
| 86 | + * @param jobName The name of the job to query. |
| 87 | + * @param start The start index of the instances to return. |
| 88 | + * @param count The maximum number of instances to return. |
| 89 | + * @return the {@link JobInstance} values up to a maximum of count values. |
| 90 | + */ |
| 91 | + default List<JobInstance> getJobInstances(String jobName, int start, int count) { |
| 92 | + return Collections.emptyList(); |
| 93 | + } |
| 94 | + |
| 95 | + /** |
| 96 | + * @param instanceId {@link Long} The ID for the {@link JobInstance} to obtain. |
| 97 | + * @return the {@code JobInstance} that has this ID, or {@code null} if not found. |
| 98 | + */ |
| 99 | + @Nullable |
| 100 | + default JobInstance getJobInstance(@Nullable Long instanceId) { |
| 101 | + throw new UnsupportedOperationException(); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Find the last job instance, by ID, for the given job. |
| 106 | + * @param jobName The name of the job. |
| 107 | + * @return the last job instance by Id if any or {@code null} otherwise. |
| 108 | + * |
| 109 | + * @since 4.2 |
| 110 | + */ |
| 111 | + @Nullable |
| 112 | + default JobInstance getLastJobInstance(String jobName) { |
| 113 | + throw new UnsupportedOperationException(); |
| 114 | + } |
| 115 | + |
| 116 | + /** |
| 117 | + * @param jobName {@link String} name of the job. |
| 118 | + * @param jobParameters {@link JobParameters} parameters for the job instance. |
| 119 | + * @return the {@link JobInstance} with the given name and parameters, or |
| 120 | + * {@code null}. |
| 121 | + * |
| 122 | + * @since 5.0 |
| 123 | + */ |
| 124 | + @Nullable |
| 125 | + default JobInstance getJobInstance(String jobName, JobParameters jobParameters) { |
| 126 | + throw new UnsupportedOperationException(); |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Query the repository for the number of unique {@link JobInstance} objects |
| 131 | + * associated with the supplied job name. |
| 132 | + * @param jobName The name of the job for which to query. |
| 133 | + * @return the number of {@link JobInstance}s that exist within the associated job |
| 134 | + * repository. |
| 135 | + * @throws NoSuchJobException thrown when there is no {@link JobInstance} for the |
| 136 | + * jobName specified. |
| 137 | + */ |
| 138 | + default long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { |
| 139 | + throw new UnsupportedOperationException(); |
| 140 | + } |
| 141 | + |
| 142 | + /* |
| 143 | + * =================================================================================== |
| 144 | + * Job execution operations |
| 145 | + * =================================================================================== |
| 146 | + */ |
| 147 | + |
| 148 | + /** |
| 149 | + * Retrieve a {@link JobExecution} by its ID. The complete object graph for this |
| 150 | + * execution should be returned (unless otherwise indicated), including the parent |
| 151 | + * {@link JobInstance} and associated {@link ExecutionContext} and |
| 152 | + * {@link StepExecution} instances (also including their execution contexts). |
| 153 | + * @param executionId The job execution ID. |
| 154 | + * @return the {@link JobExecution} that has this ID or {@code null} if not found. |
| 155 | + */ |
| 156 | + @Nullable |
| 157 | + default JobExecution getJobExecution(@Nullable Long executionId) { |
| 158 | + throw new UnsupportedOperationException(); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Retrieve job executions by their job instance. The corresponding step executions |
| 163 | + * may not be fully hydrated (for example, their execution context may be missing), |
| 164 | + * depending on the implementation. In that case, use |
| 165 | + * {@link #getStepExecution(Long, Long)} to hydrate them. |
| 166 | + * @param jobInstance The {@link JobInstance} to query. |
| 167 | + * @return the list of all executions for the specified {@link JobInstance}. |
| 168 | + */ |
| 169 | + default List<JobExecution> getJobExecutions(JobInstance jobInstance) { |
| 170 | + return Collections.emptyList(); |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Find the last {@link JobExecution} that has been created for a given |
| 175 | + * {@link JobInstance}. |
| 176 | + * @param jobInstance The {@code JobInstance} for which to find the last |
| 177 | + * {@code JobExecution}. |
| 178 | + * @return the last {@code JobExecution} that has been created for this instance or |
| 179 | + * {@code null} if no job execution is found for the given job instance. |
| 180 | + * |
| 181 | + * @since 4.2 |
| 182 | + */ |
| 183 | + @Nullable |
| 184 | + default JobExecution getLastJobExecution(JobInstance jobInstance) { |
| 185 | + throw new UnsupportedOperationException(); |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * @param jobName the name of the job that might have run |
| 190 | + * @param jobParameters parameters identifying the {@link JobInstance} |
| 191 | + * @return the last execution of job if exists, null otherwise |
| 192 | + */ |
| 193 | + @Nullable |
| 194 | + default JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) { |
| 195 | + throw new UnsupportedOperationException(); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Retrieve running job executions. The corresponding step executions may not be fully |
| 200 | + * hydrated (for example, their execution context may be missing), depending on the |
| 201 | + * implementation. In that case, use {@link #getStepExecution(Long, Long)} to hydrate |
| 202 | + * them. |
| 203 | + * @param jobName The name of the job. |
| 204 | + * @return the set of running executions for jobs with the specified name. |
| 205 | + */ |
| 206 | + default Set<JobExecution> findRunningJobExecutions(@Nullable String jobName) { |
| 207 | + return Collections.emptySet(); |
| 208 | + } |
| 209 | + |
| 210 | + /* |
| 211 | + * =================================================================================== |
| 212 | + * Step execution operations |
| 213 | + * =================================================================================== |
| 214 | + */ |
| 215 | + |
| 216 | + /** |
| 217 | + * Retrieve a {@link StepExecution} by its ID and parent {@link JobExecution} ID. The |
| 218 | + * execution context for the step should be available in the result, and the parent |
| 219 | + * job execution should have its primitive properties, but it may not contain the job |
| 220 | + * instance information. |
| 221 | + * @param jobExecutionId The parent job execution ID. |
| 222 | + * @param stepExecutionId The step execution ID. |
| 223 | + * @return the {@link StepExecution} that has this ID or {@code null} if not found. |
| 224 | + * |
| 225 | + * @see #getJobExecution(Long) |
| 226 | + */ |
| 227 | + @Nullable |
| 228 | + default StepExecution getStepExecution(@Nullable Long jobExecutionId, @Nullable Long stepExecutionId) { |
| 229 | + throw new UnsupportedOperationException(); |
| 230 | + } |
| 231 | + |
| 232 | + /** |
| 233 | + * @param jobInstance {@link JobInstance} instance containing the step executions. |
| 234 | + * @param stepName the name of the step execution that might have run. |
| 235 | + * @return the last execution of step for the given job instance. |
| 236 | + */ |
| 237 | + @Nullable |
| 238 | + default StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) { |
| 239 | + throw new UnsupportedOperationException(); |
| 240 | + } |
| 241 | + |
| 242 | + /** |
| 243 | + * @param jobInstance {@link JobInstance} instance containing the step executions. |
| 244 | + * @param stepName the name of the step execution that might have run. |
| 245 | + * @return the execution count of the step within the given job instance. |
| 246 | + */ |
| 247 | + default long getStepExecutionCount(JobInstance jobInstance, String stepName) { |
| 248 | + throw new UnsupportedOperationException(); |
| 249 | + } |
| 250 | + |
| 251 | + /* |
| 252 | + * =================================================================================== |
| 253 | + * Write operations |
| 254 | + * =================================================================================== |
| 255 | + */ |
| 256 | + |
51 | 257 | /**
|
52 | 258 | * Create a new {@link JobInstance} with the name and job parameters provided.
|
53 | 259 | * @param jobName logical name of the job
|
|
0 commit comments