|
26 | 26 | import java.util.Collection;
|
27 | 27 | import java.util.Iterator;
|
28 | 28 | import java.util.List;
|
| 29 | +import java.util.Map; |
| 30 | +import java.util.Set; |
29 | 31 | import java.util.concurrent.locks.Lock;
|
30 | 32 | import java.util.concurrent.locks.ReentrantLock;
|
| 33 | +import java.util.stream.Stream; |
31 | 34 |
|
32 | 35 | import org.apache.commons.logging.Log;
|
33 | 36 | import org.apache.commons.logging.LogFactory;
|
@@ -92,6 +95,16 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
|
92 | 95 |
|
93 | 96 | private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " AND STEP_EXECUTION_ID = ?";
|
94 | 97 |
|
| 98 | + private static final String GET_STEP_EXECUTIONS_BY_IDS = GET_RAW_STEP_EXECUTIONS |
| 99 | + + " and STEP_EXECUTION_ID IN (%STEP_EXECUTION_IDS%)"; |
| 100 | + |
| 101 | + private static final String COUNT_STEP_EXECUTIONS_BY_IDS_AND_STATUSES = """ |
| 102 | + SELECT COUNT(*) |
| 103 | + FROM %PREFIX%STEP_EXECUTION SE |
| 104 | + WHERE SE.STEP_EXECUTION_ID IN (%STEP_EXECUTION_IDS%) |
| 105 | + AND SE.STATUS IN (%STEP_STATUSES%) |
| 106 | + """; |
| 107 | + |
95 | 108 | private static final String GET_LAST_STEP_EXECUTION = """
|
96 | 109 | SELECT SE.STEP_EXECUTION_ID, SE.STEP_NAME, SE.START_TIME, SE.END_TIME, SE.STATUS, SE.COMMIT_COUNT, SE.READ_COUNT, SE.FILTER_COUNT, SE.WRITE_COUNT, SE.EXIT_CODE, SE.EXIT_MESSAGE, SE.READ_SKIP_COUNT, SE.WRITE_SKIP_COUNT, SE.PROCESS_SKIP_COUNT, SE.ROLLBACK_COUNT, SE.LAST_UPDATED, SE.VERSION, SE.CREATE_TIME, JE.JOB_EXECUTION_ID, JE.START_TIME, JE.END_TIME, JE.STATUS, JE.EXIT_CODE, JE.EXIT_MESSAGE, JE.CREATE_TIME, JE.LAST_UPDATED, JE.VERSION
|
97 | 110 | FROM %PREFIX%JOB_EXECUTION JE
|
@@ -334,6 +347,16 @@ public StepExecution getStepExecution(JobExecution jobExecution, Long stepExecut
|
334 | 347 | }
|
335 | 348 | }
|
336 | 349 |
|
| 350 | + @Override |
| 351 | + @Nullable |
| 352 | + public Set<StepExecution> getStepExecutions(JobExecution jobExecution, Set<Long> stepExecutionIds) { |
| 353 | + List<StepExecution> executions = getJdbcTemplate().query( |
| 354 | + getQuery(GET_STEP_EXECUTIONS_BY_IDS, Map.of("%STEP_EXECUTION_IDS%", stepExecutionIds)), |
| 355 | + new StepExecutionRowMapper(jobExecution), |
| 356 | + Stream.concat(Stream.of(jobExecution.getId()), stepExecutionIds.stream()).toArray(Object[]::new)); |
| 357 | + return Set.copyOf(executions); |
| 358 | + } |
| 359 | + |
337 | 360 | @Override
|
338 | 361 | public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
|
339 | 362 | List<StepExecution> executions = getJdbcTemplate().query(getQuery(GET_LAST_STEP_EXECUTION), (rs, rowNum) -> {
|
@@ -368,6 +391,16 @@ public long countStepExecutions(JobInstance jobInstance, String stepName) {
|
368 | 391 | jobInstance.getInstanceId(), stepName);
|
369 | 392 | }
|
370 | 393 |
|
| 394 | + @Override |
| 395 | + public long countStepExecutions(Collection<Long> stepExecutionIds, Collection<BatchStatus> matchingBatchStatuses) { |
| 396 | + return getJdbcTemplate().queryForObject( |
| 397 | + getQuery(COUNT_STEP_EXECUTIONS_BY_IDS_AND_STATUSES, |
| 398 | + Map.of("%STEP_EXECUTION_IDS%", stepExecutionIds, "%STEP_STATUSES%", matchingBatchStatuses)), |
| 399 | + Long.class, |
| 400 | + Stream.concat(stepExecutionIds.stream(), matchingBatchStatuses.stream().map(BatchStatus::name)) |
| 401 | + .toArray(Object[]::new)); |
| 402 | + } |
| 403 | + |
371 | 404 | /**
|
372 | 405 | * Delete the given step execution.
|
373 | 406 | * @param stepExecution the step execution to delete
|
|
0 commit comments