Use ExecutorProvider bean if available when auto-configuring jOOQ

See gh-14471
pull/14420/merge
davinkevin 6 years ago committed by Andy Wilkinson
parent 637f6979ba
commit 620419f9e4

@ -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> transactionProvider,
@ -118,7 +120,8 @@ public class JooqAutoConfiguration {
ObjectProvider<RecordListenerProvider[]> recordListenerProviders,
ExecuteListenerProvider[] executeListenerProviders,
ObjectProvider<VisitListenerProvider[]> visitListenerProviders,
ObjectProvider<TransactionListenerProvider[]> transactionListenerProviders) {
ObjectProvider<TransactionListenerProvider[]> transactionListenerProviders,
ObjectProvider<ExecutorProvider> 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);

@ -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;
}
}
}

Loading…
Cancel
Save