Skip to content

Commit 724874b

Browse files
committed
Implement unsupported operations in ResourcelessJobRepository
1 parent c2d6477 commit 724874b

File tree

1 file changed

+107
-20
lines changed

1 file changed

+107
-20
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/ResourcelessJobRepository.java

Lines changed: 107 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.batch.core.step.StepExecution;
2828
import org.springframework.batch.core.repository.JobRepository;
2929
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
30+
import org.springframework.lang.Nullable;
3031

3132
/**
3233
* A {@link JobRepository} implementation that does not use or store batch meta-data. It
@@ -50,6 +51,12 @@ public class ResourcelessJobRepository implements JobRepository {
5051

5152
private JobExecution jobExecution;
5253

54+
/*
55+
* ===================================================================================
56+
* Job operations
57+
* ===================================================================================
58+
*/
59+
5360
@Override
5461
public List<String> getJobNames() {
5562
if (this.jobInstance == null) {
@@ -58,8 +65,41 @@ public List<String> getJobNames() {
5865
return Collections.singletonList(this.jobInstance.getJobName());
5966
}
6067

68+
/*
69+
* ===================================================================================
70+
* Job instance operations
71+
* ===================================================================================
72+
*/
73+
74+
@Override
75+
public List<JobInstance> getJobInstances(String jobName, int start, int count) {
76+
if (this.jobInstance == null) {
77+
return Collections.emptyList();
78+
}
79+
return Collections.singletonList(this.jobInstance);
80+
}
81+
82+
@Override
83+
@Nullable
84+
public JobInstance getJobInstance(@Nullable Long instanceId) {
85+
return this.jobInstance;
86+
}
87+
88+
@Override
89+
@Nullable
90+
public JobInstance getLastJobInstance(String jobName) {
91+
return this.jobInstance;
92+
}
93+
94+
@Override
95+
@Nullable
96+
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
97+
return this.jobInstance;
98+
}
99+
61100
@SuppressWarnings("removal")
62101
@Override
102+
@Deprecated(since = "6.0", forRemoval = true)
63103
public boolean isJobInstanceExists(String jobName, JobParameters jobParameters) {
64104
return false;
65105
}
@@ -75,50 +115,79 @@ public JobInstance createJobInstance(String jobName, JobParameters jobParameters
75115
return this.jobInstance;
76116
}
77117

118+
/*
119+
* ===================================================================================
120+
* Job execution operations
121+
* ===================================================================================
122+
*/
123+
78124
@Override
79-
public JobExecution createJobExecution(String jobName, JobParameters jobParameters) {
80-
if (this.jobInstance == null) {
81-
createJobInstance(jobName, jobParameters);
82-
}
83-
this.jobExecution = new JobExecution(this.jobInstance, 1L, jobParameters);
125+
@Nullable
126+
public JobExecution getJobExecution(Long executionId) {
84127
return this.jobExecution;
85128
}
86129

87130
@Override
88-
public void update(JobExecution jobExecution) {
89-
jobExecution.setLastUpdated(LocalDateTime.now());
90-
this.jobExecution = jobExecution;
131+
@Nullable
132+
public JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) {
133+
return this.jobExecution;
91134
}
92135

93136
@Override
94-
public void add(StepExecution stepExecution) {
95-
this.addAll(Collections.singletonList(stepExecution));
137+
@Nullable
138+
public JobExecution getLastJobExecution(JobInstance jobInstance) {
139+
return this.jobExecution;
96140
}
97141

98142
@Override
99-
public void addAll(Collection<StepExecution> stepExecutions) {
100-
this.jobExecution.addStepExecutions(new ArrayList<>(stepExecutions));
143+
public List<JobExecution> getJobExecutions(JobInstance jobInstance) {
144+
if (this.jobExecution == null) {
145+
return Collections.emptyList();
146+
}
147+
return Collections.singletonList(this.jobExecution);
101148
}
102149

103150
@Override
104-
public void update(StepExecution stepExecution) {
105-
stepExecution.setLastUpdated(LocalDateTime.now());
106-
if (this.jobExecution.isStopping()) {
107-
stepExecution.setTerminateOnly();
151+
public JobExecution createJobExecution(String jobName, JobParameters jobParameters) {
152+
if (this.jobInstance == null) {
153+
createJobInstance(jobName, jobParameters);
108154
}
155+
this.jobExecution = new JobExecution(this.jobInstance, 1L, jobParameters);
156+
return this.jobExecution;
109157
}
110158

111159
@Override
112-
public void updateExecutionContext(StepExecution stepExecution) {
113-
stepExecution.setLastUpdated(LocalDateTime.now());
160+
public void update(JobExecution jobExecution) {
161+
jobExecution.setLastUpdated(LocalDateTime.now());
162+
this.jobExecution = jobExecution;
114163
}
115164

116165
@Override
117166
public void updateExecutionContext(JobExecution jobExecution) {
118167
jobExecution.setLastUpdated(LocalDateTime.now());
119168
}
120169

170+
/*
171+
* ===================================================================================
172+
* Step execution operations
173+
* ===================================================================================
174+
*/
175+
121176
@Override
177+
@Nullable
178+
public StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId) {
179+
if (this.jobExecution == null || !this.jobExecution.getId().equals(jobExecutionId)) {
180+
return null;
181+
}
182+
return this.jobExecution.getStepExecutions()
183+
.stream()
184+
.filter(stepExecution -> stepExecution.getId().equals(stepExecutionId))
185+
.findFirst()
186+
.orElse(null);
187+
}
188+
189+
@Override
190+
@Nullable
122191
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
123192
return this.jobExecution.getStepExecutions()
124193
.stream()
@@ -136,8 +205,26 @@ public long getStepExecutionCount(JobInstance jobInstance, String stepName) {
136205
}
137206

138207
@Override
139-
public JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) {
140-
return this.jobExecution;
208+
public void add(StepExecution stepExecution) {
209+
this.addAll(Collections.singletonList(stepExecution));
210+
}
211+
212+
@Override
213+
public void addAll(Collection<StepExecution> stepExecutions) {
214+
this.jobExecution.addStepExecutions(new ArrayList<>(stepExecutions));
215+
}
216+
217+
@Override
218+
public void update(StepExecution stepExecution) {
219+
stepExecution.setLastUpdated(LocalDateTime.now());
220+
if (this.jobExecution.isStopping()) {
221+
stepExecution.setTerminateOnly();
222+
}
223+
}
224+
225+
@Override
226+
public void updateExecutionContext(StepExecution stepExecution) {
227+
stepExecution.setLastUpdated(LocalDateTime.now());
141228
}
142229

143230
}

0 commit comments

Comments
 (0)