From 620419f9e43c23acd9037f74553c70cfe8764514 Mon Sep 17 00:00:00 2001 From: davinkevin Date: Fri, 14 Sep 2018 14:08:13 +0200 Subject: [PATCH] Use ExecutorProvider bean if available when auto-configuring jOOQ See gh-14471 --- .../autoconfigure/jooq/JooqAutoConfiguration.java | 11 +++++++++-- .../jooq/JooqAutoConfigurationTests.java | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) 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 5a0507ca05..cf63b5ade2 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 @@ -21,6 +21,7 @@ import javax.sql.DataSource; import org.jooq.ConnectionProvider; import org.jooq.DSLContext; import org.jooq.ExecuteListenerProvider; +import org.jooq.ExecutorProvider; import org.jooq.RecordListenerProvider; import org.jooq.RecordMapperProvider; import org.jooq.RecordUnmapperProvider; @@ -32,7 +33,6 @@ import org.jooq.impl.DataSourceConnectionProvider; import org.jooq.impl.DefaultConfiguration; import org.jooq.impl.DefaultDSLContext; import org.jooq.impl.DefaultExecuteListenerProvider; - import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -109,6 +109,8 @@ public class JooqAutoConfiguration { private final TransactionListenerProvider[] transactionListenerProviders; + private final ExecutorProvider executorProvider; + public DslContextConfiguration(JooqProperties properties, ConnectionProvider connectionProvider, DataSource dataSource, ObjectProvider transactionProvider, @@ -118,7 +120,8 @@ public class JooqAutoConfiguration { ObjectProvider recordListenerProviders, ExecuteListenerProvider[] executeListenerProviders, ObjectProvider visitListenerProviders, - ObjectProvider transactionListenerProviders) { + ObjectProvider transactionListenerProviders, + ObjectProvider executorProvider) { this.properties = properties; this.connection = connectionProvider; this.dataSource = dataSource; @@ -131,6 +134,7 @@ public class JooqAutoConfiguration { this.visitListenerProviders = visitListenerProviders.getIfAvailable(); this.transactionListenerProviders = transactionListenerProviders .getIfAvailable(); + this.executorProvider = executorProvider.getIfAvailable(); } @Bean @@ -156,6 +160,9 @@ public class JooqAutoConfiguration { if (this.settings != null) { configuration.set(this.settings); } + if (this.executorProvider != null) { + configuration.set(this.executorProvider); + } configuration.set(this.recordListenerProviders); configuration.set(this.executeListenerProviders); configuration.set(this.visitListenerProviders); 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 e968651d36..ff4cd0ecef 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 @@ -17,10 +17,12 @@ package org.springframework.boot.autoconfigure.jooq; import javax.sql.DataSource; +import java.util.concurrent.Executor; import org.jooq.DSLContext; import org.jooq.ExecuteListener; import org.jooq.ExecuteListenerProvider; +import org.jooq.ExecutorProvider; import org.jooq.Record; import org.jooq.RecordListener; import org.jooq.RecordListenerProvider; @@ -141,12 +143,14 @@ public class JooqAutoConfigurationTests { TxManagerConfiguration.class, TestRecordMapperProvider.class, TestRecordUnmapperProvider.class, TestRecordListenerProvider.class, TestExecuteListenerProvider.class, TestVisitListenerProvider.class, - TestTransactionListenerProvider.class).run((context) -> { + TestTransactionListenerProvider.class, TestExecutorProvider.class).run((context) -> { DSLContext dsl = context.getBean(DSLContext.class); assertThat(dsl.configuration().recordMapperProvider().getClass()) .isEqualTo(TestRecordMapperProvider.class); assertThat(dsl.configuration().recordUnmapperProvider().getClass()) .isEqualTo(TestRecordUnmapperProvider.class); + assertThat(dsl.configuration().executorProvider().getClass()) + .isEqualTo(TestExecutorProvider.class); assertThat(dsl.configuration().recordListenerProviders().length) .isEqualTo(1); assertThat(dsl.configuration().executeListenerProviders().length) @@ -288,4 +292,13 @@ public class JooqAutoConfigurationTests { } + protected static class TestExecutorProvider implements ExecutorProvider { + + @Override + public Executor provide() { + return null; + } + + } + }