Skip to content

Commit 7242f8f

Browse files
hpoettkerfmbenhassine
authored andcommitted
Replace deprecated TransactionSynchronizationAdapter
Issue #3838
1 parent 3d0cb90 commit 7242f8f

File tree

6 files changed

+100
-152
lines changed

6 files changed

+100
-152
lines changed

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -46,7 +46,6 @@
4646
import org.springframework.transaction.interceptor.TransactionAttribute;
4747
import org.springframework.transaction.support.TransactionCallback;
4848
import org.springframework.transaction.support.TransactionSynchronization;
49-
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
5049
import org.springframework.transaction.support.TransactionSynchronizationManager;
5150
import org.springframework.transaction.support.TransactionTemplate;
5251
import org.springframework.util.Assert;
@@ -328,7 +327,7 @@ public Tasklet getTasklet() {
328327
* @author Dave Syer
329328
*
330329
*/
331-
private class ChunkTransactionCallback extends TransactionSynchronizationAdapter implements TransactionCallback<RepeatStatus> {
330+
private class ChunkTransactionCallback implements TransactionSynchronization, TransactionCallback<RepeatStatus> {
332331

333332
private final StepExecution stepExecution;
334333

spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/ChunkOrientedStepIntegrationTests.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2013 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -29,20 +29,18 @@
2929
import org.springframework.batch.core.repository.JobRepository;
3030
import org.springframework.batch.item.ExecutionContext;
3131
import org.springframework.batch.item.ItemReader;
32-
import org.springframework.batch.item.ItemWriter;
3332
import org.springframework.batch.item.support.ListItemReader;
3433
import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
3534
import org.springframework.batch.repeat.support.RepeatTemplate;
3635
import org.springframework.beans.factory.annotation.Autowired;
3736
import org.springframework.test.context.ContextConfiguration;
3837
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3938
import org.springframework.transaction.PlatformTransactionManager;
40-
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
39+
import org.springframework.transaction.support.TransactionSynchronization;
4140
import org.springframework.transaction.support.TransactionSynchronizationManager;
4241

4342
import java.util.Arrays;
4443
import java.util.Collections;
45-
import java.util.List;
4644

4745
import static org.junit.Assert.assertEquals;
4846
import static org.junit.Assert.assertFalse;
@@ -93,19 +91,15 @@ public void onSetUp() throws Exception {
9391
@Ignore
9492
public void testStatusForCommitFailedException() throws Exception {
9593

96-
step.setTasklet(new TestingChunkOrientedTasklet<>(getReader(new String[] { "a", "b", "c" }),
97-
new ItemWriter<String>() {
98-
@Override
99-
public void write(List<? extends String> data) throws Exception {
100-
TransactionSynchronizationManager
101-
.registerSynchronization(new TransactionSynchronizationAdapter() {
94+
step.setTasklet(new TestingChunkOrientedTasklet<>(
95+
getReader(new String[]{"a", "b", "c"}),
96+
data -> TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
10297
@Override
10398
public void beforeCommit(boolean readOnly) {
10499
throw new RuntimeException("Simulate commit failure");
105100
}
106-
});
107-
}
108-
}, chunkOperations));
101+
}),
102+
chunkOperations));
109103

110104
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters(Collections
111105
.singletonMap("run.id", new JobParameter(getClass().getName() + ".1"))));

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/data/MongoItemWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 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.
@@ -31,7 +31,7 @@
3131
import org.springframework.data.mongodb.core.convert.MongoConverter;
3232
import org.springframework.data.mongodb.core.query.Criteria;
3333
import org.springframework.data.mongodb.core.query.Query;
34-
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
34+
import org.springframework.transaction.support.TransactionSynchronization;
3535
import org.springframework.transaction.support.TransactionSynchronizationManager;
3636
import org.springframework.util.Assert;
3737
import org.springframework.util.ClassUtils;
@@ -191,7 +191,7 @@ private List<T> getCurrentBuffer() {
191191
if(!TransactionSynchronizationManager.hasResource(bufferKey)) {
192192
TransactionSynchronizationManager.bindResource(bufferKey, new ArrayList<T>());
193193

194-
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
194+
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
195195
@Override
196196
public void beforeCommit(boolean readOnly) {
197197
List<T> items = (List<T>) TransactionSynchronizationManager.getResource(bufferKey);

spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.nio.channels.FileChannel;
2323

2424
import org.springframework.batch.item.WriteFailedException;
25-
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
25+
import org.springframework.transaction.support.TransactionSynchronization;
2626
import org.springframework.transaction.support.TransactionSynchronizationManager;
2727

2828
/**
@@ -95,7 +95,7 @@ private StringBuilder getCurrentBuffer() {
9595

9696
TransactionSynchronizationManager.bindResource(bufferKey, new StringBuilder());
9797

98-
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronizationAdapter() {
98+
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
9999
@Override
100100
public void afterCompletion(int status) {
101101
clear();

spring-batch-infrastructure/src/main/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactory.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 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.
@@ -32,7 +32,6 @@
3232
import org.aopalliance.intercept.MethodInvocation;
3333
import org.springframework.aop.framework.ProxyFactory;
3434
import org.springframework.transaction.support.TransactionSynchronization;
35-
import org.springframework.transaction.support.TransactionSynchronizationAdapter;
3635
import org.springframework.transaction.support.TransactionSynchronizationManager;
3736

3837
/**
@@ -194,7 +193,7 @@ public static <T> List<T> createTransactionalList(List<T> list) {
194193
return new TransactionAwareProxyFactory<>(new CopyOnWriteArrayList<>(list)).createInstance();
195194
}
196195

197-
private class TargetSynchronization extends TransactionSynchronizationAdapter {
196+
private class TargetSynchronization implements TransactionSynchronization {
198197

199198
private final T cache;
200199

@@ -208,7 +207,6 @@ public TargetSynchronization(Object key, T cache) {
208207

209208
@Override
210209
public void afterCompletion(int status) {
211-
super.afterCompletion(status);
212210
if (status == TransactionSynchronization.STATUS_COMMITTED) {
213211
synchronized (target) {
214212
commit(cache, target);

0 commit comments

Comments
 (0)