Skip to content

Commit 2000348

Browse files
nosansnicoll
authored andcommitted
Auto-configure jOOQ with TransactionListenerProvider
Closes gh-13331
1 parent 0df37b9 commit 2000348

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfiguration.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.jooq.RecordListenerProvider;
2525
import org.jooq.RecordMapperProvider;
2626
import org.jooq.RecordUnmapperProvider;
27+
import org.jooq.TransactionListenerProvider;
2728
import org.jooq.TransactionProvider;
2829
import org.jooq.VisitListenerProvider;
2930
import org.jooq.conf.Settings;
@@ -51,6 +52,7 @@
5152
*
5253
* @author Andreas Ahlenstorf
5354
* @author Michael Simons
55+
* @author Dmytro Nosan
5456
* @since 1.3.0
5557
*/
5658
@Configuration
@@ -105,6 +107,8 @@ public static class DslContextConfiguration {
105107

106108
private final VisitListenerProvider[] visitListenerProviders;
107109

110+
private final TransactionListenerProvider[] transactionListenerProviders;
111+
108112
public DslContextConfiguration(JooqProperties properties,
109113
ConnectionProvider connectionProvider, DataSource dataSource,
110114
ObjectProvider<TransactionProvider> transactionProvider,
@@ -113,7 +117,8 @@ public DslContextConfiguration(JooqProperties properties,
113117
ObjectProvider<Settings> settings,
114118
ObjectProvider<RecordListenerProvider[]> recordListenerProviders,
115119
ExecuteListenerProvider[] executeListenerProviders,
116-
ObjectProvider<VisitListenerProvider[]> visitListenerProviders) {
120+
ObjectProvider<VisitListenerProvider[]> visitListenerProviders,
121+
ObjectProvider<TransactionListenerProvider[]> transactionListenerProviders) {
117122
this.properties = properties;
118123
this.connection = connectionProvider;
119124
this.dataSource = dataSource;
@@ -124,6 +129,8 @@ public DslContextConfiguration(JooqProperties properties,
124129
this.recordListenerProviders = recordListenerProviders.getIfAvailable();
125130
this.executeListenerProviders = executeListenerProviders;
126131
this.visitListenerProviders = visitListenerProviders.getIfAvailable();
132+
this.transactionListenerProviders = transactionListenerProviders
133+
.getIfAvailable();
127134
}
128135

129136
@Bean
@@ -152,6 +159,8 @@ public DefaultConfiguration jooqConfiguration() {
152159
configuration.set(this.recordListenerProviders);
153160
configuration.set(this.executeListenerProviders);
154161
configuration.set(this.visitListenerProviders);
162+
configuration
163+
.setTransactionListenerProvider(this.transactionListenerProviders);
155164
return configuration;
156165
}
157166

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jooq/JooqAutoConfigurationTests.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import org.jooq.RecordUnmapper;
3131
import org.jooq.RecordUnmapperProvider;
3232
import org.jooq.SQLDialect;
33+
import org.jooq.TransactionListener;
34+
import org.jooq.TransactionListenerProvider;
3335
import org.jooq.TransactionalRunnable;
3436
import org.jooq.VisitListener;
3537
import org.jooq.VisitListenerProvider;
@@ -56,6 +58,7 @@
5658
* @author Phillip Webb
5759
* @author Andy Wilkinson
5860
* @author Stephane Nicoll
61+
* @author Dmytro Nosan
5962
*/
6063
public class JooqAutoConfigurationTests {
6164

@@ -137,8 +140,8 @@ public void customProvidersArePickedUp() {
137140
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
138141
TxManagerConfiguration.class, TestRecordMapperProvider.class,
139142
TestRecordUnmapperProvider.class, TestRecordListenerProvider.class,
140-
TestExecuteListenerProvider.class, TestVisitListenerProvider.class)
141-
.run((context) -> {
143+
TestExecuteListenerProvider.class, TestVisitListenerProvider.class,
144+
TestTransactionListenerProvider.class).run((context) -> {
142145
DSLContext dsl = context.getBean(DSLContext.class);
143146
assertThat(dsl.configuration().recordMapperProvider().getClass())
144147
.isEqualTo(TestRecordMapperProvider.class);
@@ -150,6 +153,8 @@ public void customProvidersArePickedUp() {
150153
.isEqualTo(2);
151154
assertThat(dsl.configuration().visitListenerProviders().length)
152155
.isEqualTo(1);
156+
assertThat(dsl.configuration().transactionListenerProviders().length)
157+
.isEqualTo(1);
153158
});
154159
}
155160

@@ -273,4 +278,14 @@ public VisitListener provide() {
273278

274279
}
275280

281+
protected static class TestTransactionListenerProvider
282+
implements TransactionListenerProvider {
283+
284+
@Override
285+
public TransactionListener provide() {
286+
return null;
287+
}
288+
289+
}
290+
276291
}

spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,6 +3777,7 @@ following jOOQ Types:
37773777
* `RecordListenerProvider`
37783778
* `ExecuteListenerProvider`
37793779
* `VisitListenerProvider`
3780+
* `TransactionListenerProvider`
37803781

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

0 commit comments

Comments
 (0)