Adapt to breaking changes in Batch's transaction management
See gh-32237
This commit is contained in:
parent
c6990a34f9
commit
6d2a1d3f3b
|
|
@ -47,10 +47,10 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean {
|
|||
|
||||
private final DataSource dataSource;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private final TransactionManagerCustomizers transactionManagerCustomizers;
|
||||
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
private JobRepository jobRepository;
|
||||
|
||||
private JobLauncher jobLauncher;
|
||||
|
|
@ -76,11 +76,6 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean {
|
|||
return this.jobRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlatformTransactionManager getTransactionManager() {
|
||||
return this.transactionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobLauncher getJobLauncher() {
|
||||
return this.jobLauncher;
|
||||
|
|
@ -98,7 +93,6 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean {
|
|||
|
||||
public void initialize() {
|
||||
try {
|
||||
this.transactionManager = buildTransactionManager();
|
||||
this.jobRepository = createJobRepository();
|
||||
this.jobLauncher = createJobLauncher();
|
||||
this.jobExplorer = createJobExplorer();
|
||||
|
|
@ -130,7 +124,7 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean {
|
|||
map.from(this.dataSource).to(factory::setDataSource);
|
||||
map.from(this::determineIsolationLevel).whenNonNull().to(factory::setIsolationLevelForCreate);
|
||||
map.from(this.properties.getJdbc()::getTablePrefix).whenHasText().to(factory::setTablePrefix);
|
||||
map.from(this::getTransactionManager).to(factory::setTransactionManager);
|
||||
map.from(this::buildTransactionManager).to(factory::setTransactionManager);
|
||||
factory.afterPropertiesSet();
|
||||
return factory.getObject();
|
||||
}
|
||||
|
|
@ -153,7 +147,12 @@ public class BasicBatchConfigurer implements BatchConfigurer, InitializingBean {
|
|||
if (this.transactionManagerCustomizers != null) {
|
||||
this.transactionManagerCustomizers.customize(transactionManager);
|
||||
}
|
||||
this.transactionManager = transactionManager;
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
PlatformTransactionManager getTransactionManager() {
|
||||
return this.transactionManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -309,7 +309,7 @@ class BatchAutoConfigurationTests {
|
|||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(BatchConfigurer.class);
|
||||
JpaTransactionManager transactionManager = JpaTransactionManager.class
|
||||
.cast(context.getBean(BatchConfigurer.class).getTransactionManager());
|
||||
.cast(context.getBean(BasicBatchConfigurer.class).getTransactionManager());
|
||||
assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30);
|
||||
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue();
|
||||
});
|
||||
|
|
@ -323,7 +323,7 @@ class BatchAutoConfigurationTests {
|
|||
.run((context) -> {
|
||||
assertThat(context).hasSingleBean(BatchConfigurer.class);
|
||||
DataSourceTransactionManager transactionManager = DataSourceTransactionManager.class
|
||||
.cast(context.getBean(BatchConfigurer.class).getTransactionManager());
|
||||
.cast(context.getBean(BasicBatchConfigurer.class).getTransactionManager());
|
||||
assertThat(transactionManager.getDefaultTimeout()).isEqualTo(30);
|
||||
assertThat(transactionManager.isRollbackOnCommitFailure()).isTrue();
|
||||
});
|
||||
|
|
@ -336,7 +336,7 @@ class BatchAutoConfigurationTests {
|
|||
assertThat(context).hasSingleBean(BatchConfigurer.class)
|
||||
.hasSingleBean(BatchDataSourceScriptDatabaseInitializer.class).hasBean("batchDataSource");
|
||||
DataSource batchDataSource = context.getBean("batchDataSource", DataSource.class);
|
||||
assertThat(context.getBean(BatchConfigurer.class)).hasFieldOrPropertyWithValue("dataSource",
|
||||
assertThat(context.getBean(BasicBatchConfigurer.class)).hasFieldOrPropertyWithValue("dataSource",
|
||||
batchDataSource);
|
||||
assertThat(context.getBean(BatchDataSourceScriptDatabaseInitializer.class))
|
||||
.hasFieldOrPropertyWithValue("dataSource", batchDataSource);
|
||||
|
|
|
|||
Loading…
Reference in New Issue