Skip to content

Change transaction manager type in default batch configuration #4127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.springframework.batch.core.launch.support.SimpleJobLauncher;
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.stereotype.Component;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.util.Assert;
Expand All @@ -48,11 +48,11 @@ public class DefaultBatchConfigurer implements BatchConfigurer {

/**
* Create a new {@link DefaultBatchConfigurer} with the passed datasource. This
* constructor will configure a default {@link DataSourceTransactionManager}.
* constructor will configure a default {@link JdbcTransactionManager}.
* @param dataSource to use for the job repository and job explorer
*/
public DefaultBatchConfigurer(DataSource dataSource) {
this(dataSource, new DataSourceTransactionManager(dataSource));
this(dataSource, new JdbcTransactionManager(dataSource));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
* </ul>
*
* The transaction manager provided by this annotation will be of type
* {@link org.springframework.jdbc.datasource.DataSourceTransactionManager} configured
* {@link org.springframework.jdbc.support.JdbcTransactionManager} configured
* with the {@link javax.sql.DataSource} provided within the context.
*
* In order to use a custom transaction manager, a custom {@link BatchConfigurer} should
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
Expand Down Expand Up @@ -50,8 +50,8 @@ public DataSource dataSource() {
}

@Bean
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
public JdbcTransactionManager transactionManager(DataSource dataSource) {
return new JdbcTransactionManager(dataSource);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.test.util.AopTestUtils;
import org.springframework.transaction.PlatformTransactionManager;

Expand All @@ -45,10 +45,10 @@ public void testConfigurationWithDataSourceAndNoTransactionManager() throws Exce
BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class);

PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager();
Assert.assertTrue(platformTransactionManager instanceof DataSourceTransactionManager);
DataSourceTransactionManager dataSourceTransactionManager = AopTestUtils
Assert.assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
JdbcTransactionManager JdbcTransactionManager = AopTestUtils
.getTargetObject(platformTransactionManager);
Assert.assertEquals(applicationContext.getBean(DataSource.class), dataSourceTransactionManager.getDataSource());
Assert.assertEquals(applicationContext.getBean(DataSource.class), JdbcTransactionManager.getDataSource());
Assert.assertSame(getTransactionManagerSetOnJobRepository(applicationContext.getBean(JobRepository.class)),
platformTransactionManager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.test.util.AopTestUtils;
import org.springframework.transaction.PlatformTransactionManager;

Expand Down Expand Up @@ -68,9 +68,9 @@ public void testConfigurationWithDataSourceAndNoTransactionManager() throws Exce
BatchConfigurationWithDataSourceAndNoTransactionManager.class);
PlatformTransactionManager platformTransactionManager = getTransactionManagerSetOnJobRepository(
applicationContext.getBean(JobRepository.class));
Assert.assertTrue(platformTransactionManager instanceof DataSourceTransactionManager);
DataSourceTransactionManager dataSourceTransactionManager = (DataSourceTransactionManager) platformTransactionManager;
Assert.assertEquals(applicationContext.getBean(DataSource.class), dataSourceTransactionManager.getDataSource());
Assert.assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
JdbcTransactionManager JdbcTransactionManager = (JdbcTransactionManager) platformTransactionManager;
Assert.assertEquals(applicationContext.getBean(DataSource.class), JdbcTransactionManager.getDataSource());
}

@Test
Expand All @@ -81,10 +81,10 @@ public void testConfigurationWithDataSourceAndOneTransactionManager() throws Exc
.getBean(PlatformTransactionManager.class);
Assert.assertSame(transactionManager, platformTransactionManager);
// In this case, the supplied transaction manager won't be used by batch and a
// DataSourceTransactionManager will be used instead.
// JdbcTransactionManager will be used instead.
// The user has to provide a custom BatchConfigurer.
Assert.assertTrue(getTransactionManagerSetOnJobRepository(
applicationContext.getBean(JobRepository.class)) instanceof DataSourceTransactionManager);
applicationContext.getBean(JobRepository.class)) instanceof JdbcTransactionManager);
}

@Test
Expand All @@ -95,10 +95,10 @@ public void testConfigurationWithDataSourceAndMultipleTransactionManagers() thro
.getBean(PlatformTransactionManager.class);
Assert.assertSame(transactionManager2, platformTransactionManager);
// In this case, the supplied primary transaction manager won't be used by batch
// and a DataSourceTransactionManager will be used instead.
// and a JdbcTransactionManager will be used instead.
// The user has to provide a custom BatchConfigurer.
Assert.assertTrue(getTransactionManagerSetOnJobRepository(
applicationContext.getBean(JobRepository.class)) instanceof DataSourceTransactionManager);
applicationContext.getBean(JobRepository.class)) instanceof JdbcTransactionManager);
}

@Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -53,7 +53,7 @@
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.retry.RetryListener;
import org.springframework.retry.listener.RetryListenerSupport;
import org.springframework.test.util.ReflectionTestUtils;
Expand Down Expand Up @@ -297,7 +297,7 @@ public void testJobRepositoryDefaults() throws Exception {
public void testTransactionManagerDefaults() throws Exception {
ApplicationContext ctx = stepParserParentAttributeTestsCtx;

assertTrue(getTransactionManager("defaultTxMgrStep", ctx) instanceof DataSourceTransactionManager);
assertTrue(getTransactionManager("defaultTxMgrStep", ctx) instanceof JdbcTransactionManager);

assertDummyTransactionManager("specifiedTxMgrStep", "dummyTxMgr", ctx);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -61,7 +61,7 @@ public void setUp() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
factory.afterPropertiesSet();
jobRepository = factory.getObject();
job = new StubJob("job", jobRepository);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2021 the original author or authors.
* Copyright 2008-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,7 +31,7 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

Expand All @@ -56,7 +56,7 @@ public void init() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
factory.afterPropertiesSet();
JobRepository jobRepository = factory.getObject();
job.setJobRepository(jobRepository);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

Expand Down Expand Up @@ -97,7 +97,7 @@ public void setUp() throws Exception {
EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder()
.addScript("/org/springframework/batch/core/schema-drop-hsqldb.sql")
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").generateUniqueName(true).build();
DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(embeddedDatabase);
JdbcTransactionManager transactionManager = new JdbcTransactionManager(embeddedDatabase);
JobRepositoryFactoryBean repositoryFactoryBean = new JobRepositoryFactoryBean();
repositoryFactoryBean.setDataSource(embeddedDatabase);
repositoryFactoryBean.setTransactionManager(transactionManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

Expand All @@ -53,7 +53,7 @@ public void setUp() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
factory.afterPropertiesSet();
jobRepository = factory.getObject();
jobExecution = jobRepository.createJobExecution("job", new JobParameters());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,7 +51,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -114,7 +114,7 @@ public void init() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
factory.afterPropertiesSet();
jobRepository = factory.getObject();
execution = jobRepository.createJobExecution("flow", new JobParameters());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2021 the original author or authors.
* Copyright 2010-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,7 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

Expand All @@ -61,7 +61,7 @@ public void init() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
factory.afterPropertiesSet();
JobRepository jobRepository = factory.getObject();
job.setJobRepository(jobRepository);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -78,7 +78,7 @@ public void setUp() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
factory.setDataSource(embeddedDatabase);
factory.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
factory.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
factory.afterPropertiesSet();
this.jobRepository = factory.getObject();
job.setJobRepository(this.jobRepository);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -37,7 +37,7 @@
import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.JobRepositoryFactoryBean;
import org.springframework.batch.core.step.StepSupport;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.support.JdbcTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;

Expand All @@ -59,7 +59,7 @@ public void setUp() throws Exception {
.addScript("/org/springframework/batch/core/schema-hsqldb.sql").build();
JobRepositoryFactoryBean jobRepositoryFactoryBean = new JobRepositoryFactoryBean();
jobRepositoryFactoryBean.setDataSource(embeddedDatabase);
jobRepositoryFactoryBean.setTransactionManager(new DataSourceTransactionManager(embeddedDatabase));
jobRepositoryFactoryBean.setTransactionManager(new JdbcTransactionManager(embeddedDatabase));
jobRepositoryFactoryBean.afterPropertiesSet();
jobRepository = jobRepositoryFactoryBean.getObject();
jobExecution = jobRepository.createJobExecution("job", new JobParameters());
Expand Down
Loading