Merge pull request #24862 from izeye

* pr/24862:
  Polish contribution
  Polish

Closes gh-24862
pull/24867/head
Stephane Nicoll 4 years ago
commit 38cd1b4949

@ -95,22 +95,23 @@ public class JooqAutoConfiguration {
@Bean
@ConditionalOnMissingBean(org.jooq.Configuration.class)
public DefaultConfiguration jooqConfiguration(JooqProperties properties, ConnectionProvider connectionProvider,
DataSource dataSource, ObjectProvider<DefaultConfigurationCustomizer> configurationCustomizers) {
DataSource dataSource, ObjectProvider<ExecuteListenerProvider> executeListenerProviders,
ObjectProvider<DefaultConfigurationCustomizer> configurationCustomizers) {
DefaultConfiguration configuration = new DefaultConfiguration();
configuration.set(properties.determineSqlDialect(dataSource));
configuration.set(connectionProvider);
configuration.set(executeListenerProviders.orderedStream().toArray(ExecuteListenerProvider[]::new));
configurationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(configuration));
return configuration;
}
@Bean
@Deprecated
public DefaultConfigurationCustomizer jooQProviderDefaultConfigurationCustomizer(
public DefaultConfigurationCustomizer jooqProvidersDefaultConfigurationCustomizer(
ObjectProvider<TransactionProvider> transactionProvider,
ObjectProvider<RecordMapperProvider> recordMapperProvider,
ObjectProvider<RecordUnmapperProvider> recordUnmapperProvider, ObjectProvider<Settings> settings,
ObjectProvider<RecordListenerProvider> recordListenerProviders,
ObjectProvider<ExecuteListenerProvider> executeListenerProviders,
ObjectProvider<VisitListenerProvider> visitListenerProviders,
ObjectProvider<TransactionListenerProvider> transactionListenerProviders,
ObjectProvider<ExecutorProvider> executorProvider) {
@ -121,7 +122,6 @@ public class JooqAutoConfiguration {
settings.ifAvailable(configuration::set);
executorProvider.ifAvailable(configuration::set);
configuration.set(recordListenerProviders.orderedStream().toArray(RecordListenerProvider[]::new));
configuration.set(executeListenerProviders.orderedStream().toArray(ExecuteListenerProvider[]::new));
configuration.set(visitListenerProviders.orderedStream().toArray(VisitListenerProvider[]::new));
configuration.setTransactionListenerProvider(
transactionListenerProviders.orderedStream().toArray(TransactionListenerProvider[]::new));

@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.jooq;
import javax.sql.DataSource;
import org.jooq.CharsetProvider;
import org.jooq.ConnectionProvider;
import org.jooq.ConverterProvider;
import org.jooq.DSLContext;
import org.jooq.ExecuteListener;
@ -31,6 +32,7 @@ import org.jooq.SQLDialect;
import org.jooq.TransactionListenerProvider;
import org.jooq.TransactionalRunnable;
import org.jooq.VisitListenerProvider;
import org.jooq.impl.DataSourceConnectionProvider;
import org.jooq.impl.DefaultExecuteListenerProvider;
import org.junit.jupiter.api.Test;
@ -42,6 +44,7 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
import org.springframework.transaction.PlatformTransactionManager;
import static org.assertj.core.api.Assertions.assertThat;
@ -101,7 +104,37 @@ class JooqAutoConfigurationTests {
"insert into jooqtest (name) values ('foo');")));
dsl.transaction(new AssertFetch(dsl, "select count(*) as total from jooqtest_tx;", "1"));
});
}
@Test
void jooqWithDefaultConnectionProvider() {
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class).run((context) -> {
DSLContext dsl = context.getBean(DSLContext.class);
ConnectionProvider connectionProvider = dsl.configuration().connectionProvider();
assertThat(connectionProvider).isInstanceOf(DataSourceConnectionProvider.class);
DataSource connectionProviderDataSource = ((DataSourceConnectionProvider) connectionProvider).dataSource();
assertThat(connectionProviderDataSource).isInstanceOf(TransactionAwareDataSourceProxy.class);
});
}
@Test
void jooqWithDefaultExecuteListenerProvider() {
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class).run((context) -> {
DSLContext dsl = context.getBean(DSLContext.class);
assertThat(dsl.configuration().executeListenerProviders()).hasSize(1);
});
}
@Test
void jooqWithSeveralExecuteListenerProviders() {
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TestExecuteListenerProvider.class)
.run((context) -> {
DSLContext dsl = context.getBean(DSLContext.class);
ExecuteListenerProvider[] executeListenerProviders = dsl.configuration().executeListenerProviders();
assertThat(executeListenerProviders).hasSize(2);
assertThat(executeListenerProviders[0]).isInstanceOf(DefaultExecuteListenerProvider.class);
assertThat(executeListenerProviders[1]).isInstanceOf(TestExecuteListenerProvider.class);
});
}
@Test
@ -129,9 +162,7 @@ class JooqAutoConfigurationTests {
VisitListenerProvider visitListenerProvider = mock(VisitListenerProvider.class);
TransactionListenerProvider transactionListenerProvider = mock(TransactionListenerProvider.class);
ExecutorProvider executorProvider = mock(ExecutorProvider.class);
this.contextRunner
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class,
TestExecuteListenerProvider.class)
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class)
.withBean(RecordMapperProvider.class, () -> recordMapperProvider)
.withBean(RecordUnmapperProvider.class, () -> recordUnmapperProvider)
.withBean(RecordListenerProvider.class, () -> recordListenerProvider)
@ -143,10 +174,6 @@ class JooqAutoConfigurationTests {
assertThat(dsl.configuration().recordUnmapperProvider()).isSameAs(recordUnmapperProvider);
assertThat(dsl.configuration().executorProvider()).isSameAs(executorProvider);
assertThat(dsl.configuration().recordListenerProviders()).containsExactly(recordListenerProvider);
ExecuteListenerProvider[] executeListenerProviders = dsl.configuration().executeListenerProviders();
assertThat(executeListenerProviders).hasSize(2);
assertThat(executeListenerProviders[0]).isInstanceOf(DefaultExecuteListenerProvider.class);
assertThat(executeListenerProviders[1]).isInstanceOf(TestExecuteListenerProvider.class);
assertThat(dsl.configuration().visitListenerProviders()).containsExactly(visitListenerProvider);
assertThat(dsl.configuration().transactionListenerProviders())
.containsExactly(transactionListenerProvider);

Loading…
Cancel
Save