From b2a8c8be1ca524a9b87c21f94d2936555cb2090b Mon Sep 17 00:00:00 2001 From: ath0s <861482+ath0s@users.noreply.github.com> Date: Wed, 25 Jan 2023 20:10:41 +0100 Subject: [PATCH 1/2] Configure jOOQ with TransactionProvider bean when available See gh-33979 --- .../autoconfigure/jooq/JooqAutoConfiguration.java | 4 +++- .../jooq/JooqAutoConfigurationTests.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java index 4386044baf..72944ddf3f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java @@ -87,11 +87,13 @@ public class JooqAutoConfiguration { @Bean @ConditionalOnMissingBean(org.jooq.Configuration.class) public DefaultConfiguration jooqConfiguration(JooqProperties properties, ConnectionProvider connectionProvider, - DataSource dataSource, ObjectProvider executeListenerProviders, + DataSource dataSource, ObjectProvider transactionProvider, + ObjectProvider executeListenerProviders, ObjectProvider configurationCustomizers) { DefaultConfiguration configuration = new DefaultConfiguration(); configuration.set(properties.determineSqlDialect(dataSource)); configuration.set(connectionProvider); + transactionProvider.ifAvailable(configuration::set); configuration.set(executeListenerProviders.orderedStream().toArray(ExecuteListenerProvider[]::new)); configurationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(configuration)); return configuration; diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java index c2b722ec9a..a856218104 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java @@ -113,6 +113,17 @@ class JooqAutoConfigurationTests { }); } + @Test + void jooqWithDefaultTransactionProvider() { + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class) + .run((context) -> { + DSLContext dsl = context.getBean(DSLContext.class); + TransactionProvider expectedTransactionProvider = context.getBean(TransactionProvider.class); + TransactionProvider transactionProvider = dsl.configuration().transactionProvider(); + assertThat(transactionProvider).isSameAs(expectedTransactionProvider); + }); + } + @Test void jooqWithDefaultExecuteListenerProvider() { this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class).run((context) -> { From 56a1551c2de47350c3baada441f6e9b467c64668 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Wed, 1 Feb 2023 14:54:36 +0000 Subject: [PATCH 2/2] Polish "Configure jOOQ with TransactionProvider bean when available" See gh-33979 --- .../jooq/JooqAutoConfigurationTests.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java index a856218104..6d608d69af 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java @@ -175,6 +175,19 @@ class JooqAutoConfigurationTests { .run((context) -> { TransactionProvider transactionProvider = context.getBean(TransactionProvider.class); assertThat(transactionProvider).isInstanceOf(CustomTransactionProvider.class); + DSLContext dsl = context.getBean(DSLContext.class); + assertThat(dsl.configuration().transactionProvider()).isSameAs(transactionProvider); + }); + } + + @Test + void transactionProviderFromConfigurationCustomizerOverridesTransactionProviderBean() { + this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class, + CustomTransactionProviderFromCustomizerConfiguration.class).run((context) -> { + TransactionProvider transactionProvider = context.getBean(TransactionProvider.class); + assertThat(transactionProvider).isInstanceOf(SpringTransactionProvider.class); + DSLContext dsl = context.getBean(DSLContext.class); + assertThat(dsl.configuration().transactionProvider()).isInstanceOf(CustomTransactionProvider.class); }); } @@ -239,6 +252,16 @@ class JooqAutoConfigurationTests { } + @Configuration(proxyBeanMethods = false) + static class CustomTransactionProviderFromCustomizerConfiguration { + + @Bean + DefaultConfigurationCustomizer transactionProviderCustomizer() { + return (configuration) -> configuration.setTransactionProvider(new CustomTransactionProvider()); + } + + } + @Configuration(proxyBeanMethods = false) static class TxManagerConfiguration {