Skip to content

Commit

Permalink
Configure jOOQ with TransactionProvider bean when available
Browse files Browse the repository at this point in the history
  • Loading branch information
ath0s authored and wilkinsona committed Feb 1, 2023
1 parent b28369d commit b2a8c8b
Show file tree
Hide file tree
Showing 2 changed files with 14 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

0 comments on commit b2a8c8b

Please sign in to comment.