Skip to content

Commit 290dadd

Browse files
format code
1 parent e82b72a commit 290dadd

File tree

8 files changed

+83
-76
lines changed

8 files changed

+83
-76
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/BatchStatus.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public enum BatchStatus {
7373
*/
7474
UNKNOWN;
7575

76-
public static final Set<BatchStatus> RUNNING_STATUSES = Set.of(STARTING, STARTED, STOPPING);
76+
public static final Set<BatchStatus> RUNNING_STATUSES = Set.of(STARTING, STARTED, STOPPING);
7777

7878
/**
7979
* Convenience method to return the higher value status of the statuses passed to the

spring-batch-core/src/main/java/org/springframework/batch/core/explore/JobExplorer.java

+16-14
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,13 @@ default JobInstance getLastJobInstance(String jobName) {
8484
@Nullable
8585
StepExecution getStepExecution(@Nullable Long jobExecutionId, @Nullable Long stepExecutionId);
8686

87-
/**
88-
* Find {@link StepExecution}s by IDs and parent {@link JobExecution} ID
89-
* @param jobExecutionId given job execution id
90-
* @param stepExecutionIds given step execution ids
91-
* @return collection of {@link StepExecution}
92-
*/
93-
Set<StepExecution> getStepExecutions(Long jobExecutionId, Set<Long> stepExecutionIds);
87+
/**
88+
* Find {@link StepExecution}s by IDs and parent {@link JobExecution} ID
89+
* @param jobExecutionId given job execution id
90+
* @param stepExecutionIds given step execution ids
91+
* @return collection of {@link StepExecution}
92+
*/
93+
Set<StepExecution> getStepExecutions(Long jobExecutionId, Set<Long> stepExecutionIds);
9494

9595
/**
9696
* @param instanceId {@link Long} The ID for the {@link JobInstance} to obtain.
@@ -175,11 +175,13 @@ default JobExecution getLastJobExecution(JobInstance jobInstance) {
175175
*/
176176
long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException;
177177

178-
/**
179-
* Retrieve number of step executions that match the step execution ids and the batch statuses
180-
* @param stepExecutionIds given step execution ids
181-
* @param matchingBatchStatuses given batch statuses to match against
182-
* @return number of {@link StepExecution} matching the criteria
183-
*/
184-
long getStepExecutionCount(Set<Long> stepExecutionIds, Set<BatchStatus> matchingBatchStatuses);
178+
/**
179+
* Retrieve number of step executions that match the step execution ids and the batch
180+
* statuses
181+
* @param stepExecutionIds given step execution ids
182+
* @param matchingBatchStatuses given batch statuses to match against
183+
* @return number of {@link StepExecution} matching the criteria
184+
*/
185+
long getStepExecutionCount(Set<Long> stepExecutionIds, Set<BatchStatus> matchingBatchStatuses);
186+
185187
}

spring-batch-core/src/main/java/org/springframework/batch/core/explore/support/SimpleJobExplorer.java

+21-21
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,20 @@ public StepExecution getStepExecution(@Nullable Long jobExecutionId, @Nullable L
144144
return stepExecution;
145145
}
146146

147-
@Nullable
148-
@Override
149-
public Set<StepExecution> getStepExecutions(Long jobExecutionId, Set<Long> stepExecutionIds) {
150-
JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
151-
if (jobExecution == null) {
152-
return null;
153-
}
154-
getJobExecutionDependencies(jobExecution);
155-
Set<StepExecution> stepExecutions = stepExecutionDao.getStepExecutions(jobExecution, stepExecutionIds);
156-
stepExecutions.forEach(this::getStepExecutionDependencies);
157-
return stepExecutions;
158-
}
159-
160-
@Nullable
147+
@Nullable
148+
@Override
149+
public Set<StepExecution> getStepExecutions(Long jobExecutionId, Set<Long> stepExecutionIds) {
150+
JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
151+
if (jobExecution == null) {
152+
return null;
153+
}
154+
getJobExecutionDependencies(jobExecution);
155+
Set<StepExecution> stepExecutions = stepExecutionDao.getStepExecutions(jobExecution, stepExecutionIds);
156+
stepExecutions.forEach(this::getStepExecutionDependencies);
157+
return stepExecutions;
158+
}
159+
160+
@Nullable
161161
@Override
162162
public JobInstance getJobInstance(@Nullable Long instanceId) {
163163
return jobInstanceDao.getJobInstance(instanceId);
@@ -190,13 +190,13 @@ public long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobExcept
190190
return jobInstanceDao.getJobInstanceCount(jobName);
191191
}
192192

193-
@Override
194-
public long getStepExecutionCount(Set<Long> stepExecutionIds, Set<BatchStatus> matchingBatchStatuses) {
195-
if (stepExecutionIds.isEmpty() || matchingBatchStatuses.isEmpty()) {
196-
return 0;
197-
}
198-
return stepExecutionDao.countStepExecutions(stepExecutionIds, matchingBatchStatuses);
199-
}
193+
@Override
194+
public long getStepExecutionCount(Set<Long> stepExecutionIds, Set<BatchStatus> matchingBatchStatuses) {
195+
if (stepExecutionIds.isEmpty() || matchingBatchStatuses.isEmpty()) {
196+
return 0;
197+
}
198+
return stepExecutionDao.countStepExecutions(stepExecutionIds, matchingBatchStatuses);
199+
}
200200

201201
/**
202202
* @return instance of {@link JobInstanceDao}.

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/AbstractJdbcBatchMetadataDao.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,14 @@ public void afterPropertiesSet() throws Exception {
9898

9999
/**
100100
* Replaces a given placeholder with a number of parameters (i.e. "?").
101-
*
102101
* @param sqlTemplate given sql template
103102
* @param placeholder placeholder that is being used for parameters
104103
* @param parameters collection of parameters with variable size
105-
*
106104
* @return sql query replaced with a number of parameters
107105
*/
108106
private static String createParameterizedQuery(String sqlTemplate, String placeholder, Collection<?> parameters) {
109107
String params = parameters.stream().map(p -> "?").collect(Collectors.joining(", "));
110108
return sqlTemplate.replace(placeholder, params);
111109
}
110+
112111
}

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JdbcStepExecutionDao.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,17 @@ public class JdbcStepExecutionDao extends AbstractJdbcBatchMetadataDao implement
9595

9696
private static final String GET_STEP_EXECUTION = GET_RAW_STEP_EXECUTIONS + " AND STEP_EXECUTION_ID = ?";
9797

98-
private static final String GET_STEP_EXECUTIONS_BY_IDS = GET_RAW_STEP_EXECUTIONS + " and STEP_EXECUTION_ID IN (%STEP_EXECUTION_IDS%)";
98+
private static final String GET_STEP_EXECUTIONS_BY_IDS = GET_RAW_STEP_EXECUTIONS
99+
+ " and STEP_EXECUTION_ID IN (%STEP_EXECUTION_IDS%)";
99100

100-
private static final String COUNT_STEP_EXECUTIONS_BY_IDS_AND_STATUSES = """
101+
private static final String COUNT_STEP_EXECUTIONS_BY_IDS_AND_STATUSES = """
101102
SELECT COUNT(*)
102-
FROM %PREFIX%STEP_EXECUTION SE
103-
WHERE SE.STEP_EXECUTION_ID IN (%STEP_EXECUTION_IDS%)
104-
AND SE.STATUS IN (%STEP_STATUSES%)
103+
FROM %PREFIX%STEP_EXECUTION SE
104+
WHERE SE.STEP_EXECUTION_ID IN (%STEP_EXECUTION_IDS%)
105+
AND SE.STATUS IN (%STEP_STATUSES%)
105106
""";
106107

107-
private static final String GET_LAST_STEP_EXECUTION = """
108+
private static final String GET_LAST_STEP_EXECUTION = """
108109
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
109110
FROM %PREFIX%JOB_EXECUTION JE
110111
JOIN %PREFIX%STEP_EXECUTION SE ON SE.JOB_EXECUTION_ID = JE.JOB_EXECUTION_ID
@@ -393,12 +394,11 @@ public long countStepExecutions(JobInstance jobInstance, String stepName) {
393394
@Override
394395
public long countStepExecutions(Collection<Long> stepExecutionIds, Collection<BatchStatus> matchingBatchStatuses) {
395396
return getJdbcTemplate().queryForObject(
396-
getQuery(
397-
COUNT_STEP_EXECUTIONS_BY_IDS_AND_STATUSES,
398-
Map.of("%STEP_EXECUTION_IDS%", stepExecutionIds, "%STEP_STATUSES%", matchingBatchStatuses)
399-
),
397+
getQuery(COUNT_STEP_EXECUTIONS_BY_IDS_AND_STATUSES,
398+
Map.of("%STEP_EXECUTION_IDS%", stepExecutionIds, "%STEP_STATUSES%", matchingBatchStatuses)),
400399
Long.class,
401-
Stream.concat(stepExecutionIds.stream(), matchingBatchStatuses.stream().map(BatchStatus::name)).toArray(Object[]::new));
400+
Stream.concat(stepExecutionIds.stream(), matchingBatchStatuses.stream().map(BatchStatus::name))
401+
.toArray(Object[]::new));
402402
}
403403

404404
/**

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java

+17-15
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,14 @@ public interface StepExecutionDao {
6464
@Nullable
6565
StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId);
6666

67-
/**
68-
* Get a collection of {@link StepExecution} matching job execution and step execution ids.
69-
* @param jobExecution the parent job execution
70-
* @param stepExecutionIds the step execution ids
71-
* @return collection of {@link StepExecution}
72-
*/
73-
Set<StepExecution> getStepExecutions(JobExecution jobExecution, Set<Long> stepExecutionIds);
67+
/**
68+
* Get a collection of {@link StepExecution} matching job execution and step execution
69+
* ids.
70+
* @param jobExecution the parent job execution
71+
* @param stepExecutionIds the step execution ids
72+
* @return collection of {@link StepExecution}
73+
*/
74+
Set<StepExecution> getStepExecutions(JobExecution jobExecution, Set<Long> stepExecutionIds);
7475

7576
/**
7677
* Retrieve the last {@link StepExecution} for a given {@link JobInstance} ordered by
@@ -101,15 +102,16 @@ default long countStepExecutions(JobInstance jobInstance, String stepName) {
101102
throw new UnsupportedOperationException();
102103
}
103104

104-
/**
105-
* Count {@link StepExecution} that match the ids and statuses of them - avoid loading them into memory
106-
* @param stepExecutionIds given step execution ids
107-
* @param matchingBatchStatuses
108-
* @return the count of matching steps
109-
*/
110-
long countStepExecutions(Collection<Long> stepExecutionIds, Collection<BatchStatus> matchingBatchStatuses);
105+
/**
106+
* Count {@link StepExecution} that match the ids and statuses of them - avoid loading
107+
* them into memory
108+
* @param stepExecutionIds given step execution ids
109+
* @param matchingBatchStatuses
110+
* @return the count of matching steps
111+
*/
112+
long countStepExecutions(Collection<Long> stepExecutionIds, Collection<BatchStatus> matchingBatchStatuses);
111113

112-
/**
114+
/**
113115
* Delete the given step execution.
114116
* @param stepExecution the step execution to delete
115117
* @since 5.0

spring-batch-core/src/test/java/org/springframework/batch/core/launch/support/CommandLineJobRunnerTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ public long getJobInstanceCount(@Nullable String jobName) throws NoSuchJobExcept
582582
public long getStepExecutionCount(Set<Long> stepExecutionIds, Set<BatchStatus> matchingBatchStatuses) {
583583
throw new UnsupportedOperationException();
584584
}
585+
585586
}
586587

587588
public static class StubJobParametersConverter implements JobParametersConverter {

spring-batch-integration/src/main/java/org/springframework/batch/integration/partition/MessageChannelPartitionHandler.java

+15-12
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,21 @@ protected Set<StepExecution> doHandle(StepExecution managerStepExecution,
251251

252252
private Set<StepExecution> pollReplies(final StepExecution managerStepExecution, final Set<StepExecution> split)
253253
throws Exception {
254-
Callable<Set<StepExecution>> callback = () -> {
255-
Set<Long> currentStepExecutionIds = split.stream().map(StepExecution::getId).collect(Collectors.toSet());
256-
long runningStepExecutions = jobExplorer.getStepExecutionCount(currentStepExecutionIds, BatchStatus.RUNNING_STATUSES);
257-
if(runningStepExecutions > 0 && !split.isEmpty()) {
258-
if(logger.isDebugEnabled()) {
259-
logger.debug(String.format("Currently waiting on %s out of %s partitions to finish", runningStepExecutions, split.size()));
260-
}
261-
return null;
262-
} else {
263-
return jobExplorer.getStepExecutions(managerStepExecution.getJobExecutionId(), currentStepExecutionIds);
264-
}
265-
};
254+
Callable<Set<StepExecution>> callback = () -> {
255+
Set<Long> currentStepExecutionIds = split.stream().map(StepExecution::getId).collect(Collectors.toSet());
256+
long runningStepExecutions = jobExplorer.getStepExecutionCount(currentStepExecutionIds,
257+
BatchStatus.RUNNING_STATUSES);
258+
if (runningStepExecutions > 0 && !split.isEmpty()) {
259+
if (logger.isDebugEnabled()) {
260+
logger.debug(String.format("Currently waiting on %s out of %s partitions to finish",
261+
runningStepExecutions, split.size()));
262+
}
263+
return null;
264+
}
265+
else {
266+
return jobExplorer.getStepExecutions(managerStepExecution.getJobExecutionId(), currentStepExecutionIds);
267+
}
268+
};
266269

267270
Poller<Set<StepExecution>> poller = new DirectPoller<>(pollInterval);
268271
Future<Set<StepExecution>> resultsFuture = poller.poll(callback);

0 commit comments

Comments
 (0)