Skip to content

Commit

Permalink
Remove BatchConfigurer#getTransactionManager
Browse files Browse the repository at this point in the history
Before this commit, the transaction manager was configurable
by implementing `BatchConfigurer#getTransactionManager`.

The transaction manager being an implementation detail of the
`JobRepository`, it should not be configurable at the same level
as the `JobRepository` (ie in the same interface).

This commit removes the method `getTransactionManager` from
the `BatchConfigurer` interface. If needed, a custom transaction
manager could be supplied by implementing `getJobRepository`,
or via the constructor of `DefaultBatchConfigurer`.

Resolves spring-projects#4191
  • Loading branch information
fmbenhassine committed Sep 13, 2022
1 parent 6e443cb commit d11b5b2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ public JobRegistry jobRegistry() throws Exception {
return this.jobRegistry;
}

/**
* Establish the {@link PlatformTransactionManager} for the batch execution.
* @return The instance of the {@link PlatformTransactionManager}.
* @throws Exception The {@link Exception} thrown if an error occurs.
*/
public abstract PlatformTransactionManager transactionManager() throws Exception;

/**
* If a {@link BatchConfigurer} exists, return it. Otherwise, create a
* {@link DefaultBatchConfigurer}. If more than one configurer is present, an
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* a Batch system.
*
* @author Dave Syer
* @author Mahmoud Ben Hassine
*
*/
public interface BatchConfigurer {
Expand All @@ -35,12 +36,6 @@ public interface BatchConfigurer {
*/
JobRepository getJobRepository() throws Exception;

/**
* @return The {@link PlatformTransactionManager}.
* @throws Exception The {@link Exception} thrown if an error occurs.
*/
PlatformTransactionManager getTransactionManager() throws Exception;

/**
* @return The {@link JobLauncher}.
* @throws Exception The {@link Exception} thrown if an error occurs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,19 @@ public JobExplorer getJobExplorer() {
return this.jobExplorer;
}

@Override
public PlatformTransactionManager getTransactionManager() {
return this.transactionManager;
}

/**
* Set the transaction manager.
* @param transactionManager the transaction manager to use. Must not be {@code null}.
*/
public void setTransactionManager(PlatformTransactionManager transactionManager) {
Assert.notNull(transactionManager, "TransactionManager must not be null");
this.transactionManager = transactionManager;
}

@Override
public void afterPropertiesSet() throws Exception {
initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,4 @@ public JobExplorer jobExplorer() throws Exception {
return getOrCreateConfigurer().getJobExplorer();
}

@Override
public PlatformTransactionManager transactionManager() throws Exception {
return getOrCreateConfigurer().getTransactionManager();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class TransactionManagerConfigurationWithBatchConfigurerTests extends Transactio
void testConfigurationWithDataSourceAndNoTransactionManager() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndNoTransactionManager.class);
BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class);
DefaultBatchConfigurer batchConfigurer = applicationContext.getBean(DefaultBatchConfigurer.class);

PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager();
assertTrue(platformTransactionManager instanceof JdbcTransactionManager);
Expand All @@ -56,7 +56,7 @@ void testConfigurationWithDataSourceAndNoTransactionManager() throws Exception {
void testConfigurationWithDataSourceAndTransactionManager() throws Exception {
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(
BatchConfigurationWithDataSourceAndTransactionManager.class);
BatchConfigurer batchConfigurer = applicationContext.getBean(BatchConfigurer.class);
DefaultBatchConfigurer batchConfigurer = applicationContext.getBean(DefaultBatchConfigurer.class);

PlatformTransactionManager platformTransactionManager = batchConfigurer.getTransactionManager();
assertSame(transactionManager, platformTransactionManager);
Expand Down

0 comments on commit d11b5b2

Please sign in to comment.