Skip to content

Commit

Permalink
Merge pull request #33979 from ath0s
Browse files Browse the repository at this point in the history
* gh-33979:
  Polish "Configure jOOQ with TransactionProvider bean when available"
  Configure jOOQ with TransactionProvider bean when available

Closes gh-33979
  • Loading branch information
wilkinsona committed Feb 1, 2023
2 parents b28369d + 56a1551 commit f2361dd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public DefaultDSLContext dslContext(org.jooq.Configuration configuration) {
@Bean
@ConditionalOnMissingBean(org.jooq.Configuration.class)
public DefaultConfiguration jooqConfiguration(JooqProperties properties, ConnectionProvider connectionProvider,
DataSource dataSource, ObjectProvider<ExecuteListenerProvider> executeListenerProviders,
DataSource dataSource, ObjectProvider<TransactionProvider> transactionProvider,
ObjectProvider<ExecuteListenerProvider> executeListenerProviders,
ObjectProvider<DefaultConfigurationCustomizer> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ void jooqWithDefaultConnectionProvider() {
});
}

@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) -> {
Expand Down Expand Up @@ -164,6 +175,19 @@ void transactionProviderBacksOffOnExistingTransactionProvider() {
.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);
});
}

Expand Down Expand Up @@ -228,6 +252,16 @@ TransactionProvider transactionProvider() {

}

@Configuration(proxyBeanMethods = false)
static class CustomTransactionProviderFromCustomizerConfiguration {

@Bean
DefaultConfigurationCustomizer transactionProviderCustomizer() {
return (configuration) -> configuration.setTransactionProvider(new CustomTransactionProvider());
}

}

@Configuration(proxyBeanMethods = false)
static class TxManagerConfiguration {

Expand Down

0 comments on commit f2361dd

Please sign in to comment.