Skip to content
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

Add new providers to jOOQ auto-configuration #24485

Closed
wants to merge 1 commit into from
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 @@ -18,15 +18,19 @@

import javax.sql.DataSource;

import org.jooq.CharsetProvider;
import org.jooq.ConnectionProvider;
import org.jooq.ConverterProvider;
import org.jooq.DSLContext;
import org.jooq.DiagnosticsListenerProvider;
import org.jooq.ExecuteListenerProvider;
import org.jooq.ExecutorProvider;
import org.jooq.RecordListenerProvider;
import org.jooq.RecordMapperProvider;
import org.jooq.RecordUnmapperProvider;
import org.jooq.TransactionListenerProvider;
import org.jooq.TransactionProvider;
import org.jooq.UnwrapperProvider;
import org.jooq.VisitListenerProvider;
import org.jooq.conf.Settings;
import org.jooq.impl.DataSourceConnectionProvider;
Expand Down Expand Up @@ -101,7 +105,10 @@ public DefaultConfiguration jooqConfiguration(JooqProperties properties, Connect
ObjectProvider<ExecuteListenerProvider> executeListenerProviders,
ObjectProvider<VisitListenerProvider> visitListenerProviders,
ObjectProvider<TransactionListenerProvider> transactionListenerProviders,
ObjectProvider<ExecutorProvider> executorProvider) {
ObjectProvider<ExecutorProvider> executorProvider,
ObjectProvider<DiagnosticsListenerProvider> diagnosticsListenerProviders,
ObjectProvider<UnwrapperProvider> unwrapperProvider, ObjectProvider<CharsetProvider> charsetProvider,
ObjectProvider<ConverterProvider> converterProvider) {
DefaultConfiguration configuration = new DefaultConfiguration();
configuration.set(properties.determineSqlDialect(dataSource));
configuration.set(connectionProvider);
Expand All @@ -115,6 +122,10 @@ public DefaultConfiguration jooqConfiguration(JooqProperties properties, Connect
configuration.set(visitListenerProviders.orderedStream().toArray(VisitListenerProvider[]::new));
configuration.setTransactionListenerProvider(
transactionListenerProviders.orderedStream().toArray(TransactionListenerProvider[]::new));
configuration.set(diagnosticsListenerProviders.orderedStream().toArray(DiagnosticsListenerProvider[]::new));
unwrapperProvider.ifAvailable(configuration::set);
charsetProvider.ifAvailable(configuration::set);
converterProvider.ifAvailable(configuration::set);
return configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package org.springframework.boot.autoconfigure.jooq;

import java.nio.charset.Charset;
import java.util.concurrent.Executor;

import javax.sql.DataSource;

import org.jooq.CharsetProvider;
import org.jooq.Converter;
import org.jooq.ConverterProvider;
import org.jooq.DSLContext;
import org.jooq.DiagnosticsListener;
import org.jooq.DiagnosticsListenerProvider;
import org.jooq.ExecuteListener;
import org.jooq.ExecuteListenerProvider;
import org.jooq.ExecutorProvider;
Expand All @@ -36,6 +42,8 @@
import org.jooq.TransactionListener;
import org.jooq.TransactionListenerProvider;
import org.jooq.TransactionalRunnable;
import org.jooq.Unwrapper;
import org.jooq.UnwrapperProvider;
import org.jooq.VisitListener;
import org.jooq.VisitListenerProvider;
import org.jooq.impl.DefaultExecuteListenerProvider;
Expand Down Expand Up @@ -115,7 +123,9 @@ void customProvidersArePickedUp() {
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class,
TestRecordMapperProvider.class, TestRecordUnmapperProvider.class, TestRecordListenerProvider.class,
TestExecuteListenerProvider.class, TestVisitListenerProvider.class,
TestTransactionListenerProvider.class, TestExecutorProvider.class).run((context) -> {
TestTransactionListenerProvider.class, TestExecutorProvider.class,
TestDiagnosticsListenerProvider.class, TestUnwrapperProvider.class, TestCharsetProvider.class,
TestConverterProvider.class).run((context) -> {
DSLContext dsl = context.getBean(DSLContext.class);
assertThat(dsl.configuration().recordMapperProvider().getClass())
.isEqualTo(TestRecordMapperProvider.class);
Expand All @@ -129,6 +139,12 @@ void customProvidersArePickedUp() {
assertThat(executeListenerProviders[1]).isInstanceOf(TestExecuteListenerProvider.class);
assertThat(dsl.configuration().visitListenerProviders()).hasSize(1);
assertThat(dsl.configuration().transactionListenerProviders()).hasSize(1);
assertThat(dsl.configuration().diagnosticsListenerProviders()).hasSize(1);
assertThat(dsl.configuration().unwrapperProvider().getClass())
.isEqualTo(TestUnwrapperProvider.class);
assertThat(dsl.configuration().charsetProvider().getClass()).isEqualTo(TestCharsetProvider.class);
assertThat(dsl.configuration().converterProvider().getClass())
.isEqualTo(TestConverterProvider.class);
});
}

Expand Down Expand Up @@ -265,4 +281,40 @@ public Executor provide() {

}

static class TestDiagnosticsListenerProvider implements DiagnosticsListenerProvider {

@Override
public DiagnosticsListener provide() {
return null;
}

}

static class TestUnwrapperProvider implements UnwrapperProvider {

@Override
public Unwrapper provide() {
return null;
}

}

static class TestCharsetProvider implements CharsetProvider {

@Override
public Charset provide() {
return null;
}

}

static class TestConverterProvider implements ConverterProvider {

@Override
public <T, U> Converter<T, U> provide(Class<T> tType, Class<U> uType) {
return null;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4443,6 +4443,11 @@ You can define beans for the following jOOQ Types:
* `ExecuteListenerProvider`
* `VisitListenerProvider`
* `TransactionListenerProvider`
* `ExecutorProvider`
* `DiagnosticsListenerProvider`
* `UnwrapperProvider`
* `CharsetProvider`
* `ConverterProvider`

You can also create your own `org.jooq.Configuration` `@Bean` if you want to take complete control of the jOOQ configuration.

Expand Down