Clean up and improve Java DSL for JDBC

Follow up for: https://github.com/spring-projects/spring-integration/pull/10081

* Rename `StoredProcExecutorConfigurer` to `StoredProcExecutorSpec`
* Add `Jdbc.storedProcExecutorSpec()` factory
* Improve logic of `StoredProcExecutor`-based Java DSL classes to handle an external `StoredProcExecutor` as well
* Add `package-info.java` into the `jdbc/dsl` package
* Add `/jdbc/dsl.adoc` and respective `What's New` entry
This commit is contained in:
Artem Bilan
2025-06-06 14:11:34 -04:00
parent cd15675734
commit b8116d59a9
15 changed files with 508 additions and 270 deletions

View File

@@ -184,6 +184,7 @@
** xref:jdbc/outbound-gateway.adoc[]
** xref:jdbc/message-store.adoc[]
** xref:jdbc/stored-procedures.adoc[]
** xref:jdbc/dsl.adoc[]
** xref:jdbc/lock-registry.adoc[]
** xref:jdbc/metadata-store.adoc[]
* xref:jpa.adoc[]

View File

@@ -0,0 +1,61 @@
[[jdbc-dsl]]
= Java DSL for JDBC Components
Version 7.0 introduced the Java DSL API for channel adapters in JDBC module.
The central Java DSL class (and usually starting point) is a `org.springframework.integration.jdbc.dsl.Jdbc` factory.
It provides self-explanatory method to initiate configuration for target channel adapter or gateway.
The standard `IntegrationComponentSpec` implementations for out-of-the-box channel adapters are:
* `JdbcInboundChannelAdapterSpec extends MessageSourceSpec<JdbcInboundChannelAdapterSpec, JdbcPollingChannelAdapter>`
* `JdbcOutboundChannelAdapterSpec extends MessageHandlerSpec<JdbcOutboundChannelAdapterSpec, JdbcMessageHandler>`
* `JdbcOutboundGatewaySpec extends MessageHandlerSpec<JdbcOutboundGatewaySpec, JdbcOutboundGateway>`
* `JdbcStoredProcInboundChannelAdapterSpec extends MessageSourceSpec<JdbcStoredProcInboundChannelAdapterSpec, StoredProcPollingChannelAdapter>`
* `JdbcStoredProcOutboundChannelAdapterSpec extends MessageHandlerSpec<JdbcStoredProcOutboundChannelAdapterSpec, StoredProcMessageHandler>`
* `JdbcStoredProcOutboundGatewaySpec extends MessageHandlerSpec<JdbcStoredProcOutboundGatewaySpec, StoredProcOutboundGateway>`
In addition, the `StoredProcExecutorSpec`, a convenient, builder-like component is provided for a `StoredProcExecutor` creation and configuration.
Here are some examples how `Jdbc` factory can be used for configuration an `IntegrationFlow`:
[source, java]
----
@Bean
public DataSource h2DataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScripts("classpath:dsl-h2.sql", "classpath:h2-stored-procedures.sql")
.build();
}
@Bean
public IntegrationFlow outboundFlow(DataSource h2DataSource) {
return flow -> flow
.handle(Jdbc.outboundAdapter(h2DataSource,
"insert into outbound (id, status, name) values (1, 0, ?)")
.preparedStatementSetter((ps, requestMessage) ->
ps.setObject(1, requestMessage.getPayload()))
.usePayloadAsParameterSource(false)
.keysGenerated(false));
}
@Bean
public IntegrationFlow storedProcInboundFlow(DataSource h2DataSource) {
return IntegrationFlow.from(Jdbc.storedProcInboundAdapter(h2DataSource)
.expectSingleResult(true)
.configurerStoredProcExecutor(configurer -> configurer
.ignoreColumnMetaData(true)
.isFunction(false)
.storedProcedureName("GET_PRIME_NUMBERS")
.procedureParameter(new ProcedureParameter("beginRange", 1, null))
.procedureParameter(new ProcedureParameter("endRange", 10, null))
.sqlParameter(new SqlParameter("beginRange", Types.INTEGER))
.sqlParameter(new SqlParameter("endRange", Types.INTEGER))
.returningResultSetRowMapper("out", new PrimeMapper())
),
e -> e.poller(p -> p.trigger(new OnlyOnceTrigger())))
.channel(c -> c.queue("storedProcInboundPollerChannel"))
.get();
}
----
This Java DSL API can be used as is with the xref:kotlin-dsl.adoc[Kotlin] and xref:groovy-dsl.adoc[Groovy] DSLs.

View File

@@ -17,3 +17,8 @@ Java 17 is still baseline, but Java 24 is supported.
[[x7.0-general]]
== General Changes
[[x7.0-new-components]]
== New Components
The JDBC module now provides a Java DSL API via its dedicated `org.springframework.integration.jdbc.dsl.Jdbc` factory.
The xref:jdbc/dsl.adoc[] chapter provides more details.