Skip to content

Commit 93d911e

Browse files
committed
Use lambdas and method references where appropriate
1 parent c5b4f1a commit 93d911e

File tree

115 files changed

+1254
-2494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+1254
-2494
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/SplitState.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
import java.util.ArrayList;
1919
import java.util.Collection;
20-
import java.util.concurrent.Callable;
2120
import java.util.concurrent.ExecutionException;
2221
import java.util.concurrent.Future;
2322
import java.util.concurrent.FutureTask;
@@ -89,12 +88,7 @@ public FlowExecutionStatus handle(final FlowExecutor executor) throws Exception
8988

9089
for (final Flow flow : flows) {
9190

92-
final FutureTask<FlowExecution> task = new FutureTask<>(new Callable<>() {
93-
@Override
94-
public FlowExecution call() throws Exception {
95-
return flow.start(executor);
96-
}
97-
});
91+
final FutureTask<FlowExecution> task = new FutureTask<>(() -> flow.start(executor));
9892

9993
tasks.add(task);
10094

spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandler.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.HashSet;
2020
import java.util.Set;
21-
import java.util.concurrent.Callable;
2221
import java.util.concurrent.Future;
2322
import java.util.concurrent.FutureTask;
2423

@@ -129,12 +128,9 @@ protected Set<StepExecution> doHandle(StepExecution managerStepExecution,
129128
* @return the task executing the given step
130129
*/
131130
protected FutureTask<StepExecution> createTask(final Step step, final StepExecution stepExecution) {
132-
return new FutureTask<>(new Callable<>() {
133-
@Override
134-
public StepExecution call() throws Exception {
135-
step.execute(stepExecution);
136-
return stepExecution;
137-
}
131+
return new FutureTask<>(() -> {
132+
step.execute(stepExecution);
133+
return stepExecution;
138134
});
139135
}
140136

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import org.springframework.batch.item.ExecutionContext;
3838
import org.springframework.core.serializer.Serializer;
3939
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
40-
import org.springframework.jdbc.core.PreparedStatementSetter;
4140
import org.springframework.jdbc.core.RowMapper;
4241
import org.springframework.jdbc.support.lob.DefaultLobHandler;
4342
import org.springframework.jdbc.support.lob.LobHandler;
@@ -289,18 +288,15 @@ private void persistSerializedContext(final Long executionId, String serializedC
289288
longContext = null;
290289
}
291290

292-
getJdbcTemplate().update(getQuery(sql), new PreparedStatementSetter() {
293-
@Override
294-
public void setValues(PreparedStatement ps) throws SQLException {
295-
ps.setString(1, shortContext);
296-
if (longContext != null) {
297-
lobHandler.getLobCreator().setClobAsString(ps, 2, longContext);
298-
}
299-
else {
300-
ps.setNull(2, getClobTypeToUse());
301-
}
302-
ps.setLong(3, executionId);
291+
getJdbcTemplate().update(getQuery(sql), ps -> {
292+
ps.setString(1, shortContext);
293+
if (longContext != null) {
294+
lobHandler.getLobCreator().setClobAsString(ps, 2, longContext);
295+
}
296+
else {
297+
ps.setNull(2, getClobTypeToUse());
303298
}
299+
ps.setLong(3, executionId);
304300
});
305301
}
306302

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -373,12 +373,9 @@ public JobExecution getJobExecution(Long executionId) {
373373
public Set<JobExecution> findRunningJobExecutions(String jobName) {
374374

375375
final Set<JobExecution> result = new HashSet<>();
376-
RowCallbackHandler handler = new RowCallbackHandler() {
377-
@Override
378-
public void processRow(ResultSet rs) throws SQLException {
379-
JobExecutionRowMapper mapper = new JobExecutionRowMapper();
380-
result.add(mapper.mapRow(rs, 0));
381-
}
376+
RowCallbackHandler handler = rs -> {
377+
JobExecutionRowMapper mapper = new JobExecutionRowMapper();
378+
result.add(mapper.mapRow(rs, 0));
382379
};
383380
getJdbcTemplate().query(getQuery(GET_RUNNING_EXECUTIONS), handler, jobName);
384381

@@ -455,27 +452,24 @@ private <T> void insertParameter(PreparedStatement preparedStatement, Long execu
455452
*/
456453
protected JobParameters getJobParameters(Long executionId) {
457454
final Map<String, JobParameter<?>> map = new HashMap<>();
458-
RowCallbackHandler handler = new RowCallbackHandler() {
459-
@Override
460-
public void processRow(ResultSet rs) throws SQLException {
461-
String parameterName = rs.getString("PARAMETER_NAME");
462-
463-
Class<?> parameterType = null;
464-
try {
465-
parameterType = Class.forName(rs.getString("PARAMETER_TYPE"));
466-
}
467-
catch (ClassNotFoundException e) {
468-
throw new RuntimeException(e);
469-
}
470-
String stringValue = rs.getString("PARAMETER_VALUE");
471-
Object typedValue = conversionService.convert(stringValue, parameterType);
455+
RowCallbackHandler handler = rs -> {
456+
String parameterName = rs.getString("PARAMETER_NAME");
472457

473-
boolean identifying = rs.getString("IDENTIFYING").equalsIgnoreCase("Y");
458+
Class<?> parameterType = null;
459+
try {
460+
parameterType = Class.forName(rs.getString("PARAMETER_TYPE"));
461+
}
462+
catch (ClassNotFoundException e) {
463+
throw new RuntimeException(e);
464+
}
465+
String stringValue = rs.getString("PARAMETER_VALUE");
466+
Object typedValue = conversionService.convert(stringValue, parameterType);
474467

475-
JobParameter<?> jobParameter = new JobParameter(typedValue, parameterType, identifying);
468+
boolean identifying = rs.getString("IDENTIFYING").equalsIgnoreCase("Y");
476469

477-
map.put(parameterName, jobParameter);
478-
}
470+
JobParameter<?> jobParameter = new JobParameter(typedValue, parameterType, identifying);
471+
472+
map.put(parameterName, jobParameter);
479473
};
480474

481475
getJdbcTemplate().query(getQuery(FIND_PARAMS_FROM_ID), handler, executionId);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,7 @@ public JobInstance getJobInstance(@Nullable Long instanceId) {
221221
*/
222222
@Override
223223
public List<String> getJobNames() {
224-
return getJdbcTemplate().query(getQuery(FIND_JOB_NAMES), new RowMapper<>() {
225-
@Override
226-
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
227-
return rs.getString(1);
228-
}
229-
});
224+
return getJdbcTemplate().query(getQuery(FIND_JOB_NAMES), (rs, rowNum) -> rs.getString(1));
230225
}
231226

232227
/*

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2022 the original author or authors.
2+
* Copyright 2006-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@
1919
import java.util.Properties;
2020

2121
import org.aopalliance.intercept.MethodInterceptor;
22-
import org.aopalliance.intercept.MethodInvocation;
2322
import org.springframework.aop.framework.ProxyFactory;
2423
import org.springframework.aop.support.DefaultPointcutAdvisor;
2524
import org.springframework.aop.support.NameMatchMethodPointcut;
@@ -197,15 +196,12 @@ public JobRepository getObject() throws Exception {
197196
TransactionInterceptor advice = new TransactionInterceptor((TransactionManager) this.transactionManager,
198197
this.transactionAttributeSource);
199198
if (this.validateTransactionState) {
200-
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(new MethodInterceptor() {
201-
@Override
202-
public Object invoke(MethodInvocation invocation) throws Throwable {
203-
if (TransactionSynchronizationManager.isActualTransactionActive()) {
204-
throw new IllegalStateException("Existing transaction detected in JobRepository. "
205-
+ "Please fix this and try again (e.g. remove @Transactional annotations from client).");
206-
}
207-
return invocation.proceed();
199+
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor((MethodInterceptor) invocation -> {
200+
if (TransactionSynchronizationManager.isActualTransactionActive()) {
201+
throw new IllegalStateException("Existing transaction detected in JobRepository. "
202+
+ "Please fix this and try again (e.g. remove @Transactional annotations from client).");
208203
}
204+
return invocation.proceed();
209205
});
210206
NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut();
211207
pointcut.addMethodName("create*");

spring-batch-core/src/main/java/org/springframework/batch/core/scope/BatchScopeSupport.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
2929
import org.springframework.core.Ordered;
3030
import org.springframework.util.Assert;
31-
import org.springframework.util.StringValueResolver;
3231

3332
/**
3433
* ScopeSupport.
@@ -174,12 +173,7 @@ protected static class Scopifier extends BeanDefinitionVisitor {
174173
private final boolean scoped;
175174

176175
public Scopifier(BeanDefinitionRegistry registry, String scope, boolean proxyTargetClass, boolean scoped) {
177-
super(new StringValueResolver() {
178-
@Override
179-
public String resolveStringValue(String value) {
180-
return value;
181-
}
182-
});
176+
super(value -> value);
183177
this.registry = registry;
184178
this.proxyTargetClass = proxyTargetClass;
185179
this.scope = scope;

0 commit comments

Comments
 (0)