Skip to content

Commit cd15675

Browse files
authored
GH-8467: Add Java DSL support for JDBC module
Fixes: #8467 Signed-off-by: Jiandong Ma <[email protected]>
1 parent 66d76a3 commit cd15675

File tree

10 files changed

+1197
-0
lines changed

10 files changed

+1197
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.jdbc.dsl;
18+
19+
import javax.sql.DataSource;
20+
21+
import org.springframework.integration.jdbc.StoredProcExecutor;
22+
import org.springframework.jdbc.core.JdbcOperations;
23+
import org.springframework.jdbc.core.JdbcTemplate;
24+
25+
/**
26+
* Factory class for JDBC components.
27+
*
28+
* @author Jiandong Ma
29+
*
30+
* @since 7.0
31+
*/
32+
public final class Jdbc {
33+
34+
/**
35+
* The factory to produce a {@link JdbcInboundChannelAdapterSpec}.
36+
* @param dataSource the {@link DataSource} to build on
37+
* @param selectQuery the select query to build on
38+
* @return the {@link JdbcInboundChannelAdapterSpec} instance
39+
*/
40+
public static JdbcInboundChannelAdapterSpec inboundAdapter(DataSource dataSource, String selectQuery) {
41+
return inboundAdapter(new JdbcTemplate(dataSource), selectQuery);
42+
}
43+
44+
/**
45+
* The factory to produce a {@link JdbcInboundChannelAdapterSpec}.
46+
* @param jdbcOperations the {@link JdbcOperations} to build on
47+
* @param selectQuery the select query to build on
48+
* @return the {@link JdbcInboundChannelAdapterSpec} instance
49+
*/
50+
public static JdbcInboundChannelAdapterSpec inboundAdapter(JdbcOperations jdbcOperations, String selectQuery) {
51+
return new JdbcInboundChannelAdapterSpec(jdbcOperations, selectQuery);
52+
}
53+
54+
/**
55+
* The factory to produce a {@link JdbcOutboundChannelAdapterSpec}.
56+
* @param dataSource the {@link DataSource} to build on
57+
* @param updateQuery the update query to build on
58+
* @return the {@link JdbcOutboundChannelAdapterSpec} instance
59+
*/
60+
public static JdbcOutboundChannelAdapterSpec outboundAdapter(DataSource dataSource, String updateQuery) {
61+
return outboundAdapter(new JdbcTemplate(dataSource), updateQuery);
62+
}
63+
64+
/**
65+
* The factory to produce a {@link JdbcOutboundChannelAdapterSpec}.
66+
* @param jdbcOperations the {@link JdbcOperations} to build on
67+
* @param updateQuery the update query to build on
68+
* @return the {@link JdbcOutboundChannelAdapterSpec} instance
69+
*/
70+
public static JdbcOutboundChannelAdapterSpec outboundAdapter(JdbcOperations jdbcOperations, String updateQuery) {
71+
return new JdbcOutboundChannelAdapterSpec(jdbcOperations, updateQuery);
72+
}
73+
74+
/**
75+
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
76+
* @param dataSource the {@link DataSource} to build on
77+
* @param updateQuery the update query to build on
78+
* @return the {@link JdbcOutboundGatewaySpec} instance
79+
*/
80+
public static JdbcOutboundGatewaySpec outboundGateway(DataSource dataSource, String updateQuery) {
81+
return outboundGateway(new JdbcTemplate(dataSource), updateQuery);
82+
}
83+
84+
/**
85+
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
86+
* @param dataSource the {@link DataSource} to build on
87+
* @param updateQuery the update query to build on
88+
* @param selectQuery the select query to build on
89+
* @return the {@link JdbcOutboundGatewaySpec} instance
90+
*/
91+
public static JdbcOutboundGatewaySpec outboundGateway(DataSource dataSource, String updateQuery, String selectQuery) {
92+
return outboundGateway(new JdbcTemplate(dataSource), updateQuery, selectQuery);
93+
}
94+
95+
/**
96+
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
97+
* @param jdbcOperations the {@link JdbcOperations} to build on
98+
* @param updateQuery the update query to build on
99+
* @return the {@link JdbcOutboundGatewaySpec} instance
100+
*/
101+
public static JdbcOutboundGatewaySpec outboundGateway(JdbcOperations jdbcOperations, String updateQuery) {
102+
return outboundGateway(jdbcOperations, updateQuery, null);
103+
}
104+
105+
/**
106+
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
107+
* @param jdbcOperations the {@link JdbcOperations} to build on
108+
* @param updateQuery the update query to build on
109+
* @param selectQuery the select query to build on
110+
* @return the {@link JdbcOutboundGatewaySpec} instance
111+
*/
112+
public static JdbcOutboundGatewaySpec outboundGateway(JdbcOperations jdbcOperations, String updateQuery, String selectQuery) {
113+
return new JdbcOutboundGatewaySpec(jdbcOperations, updateQuery, selectQuery);
114+
}
115+
116+
/**
117+
* The factory to produce a {@link JdbcStoredProcInboundChannelAdapterSpec}.
118+
* @param dataSource the {@link DataSource} to build on
119+
* @return the {@link JdbcStoredProcInboundChannelAdapterSpec} instance
120+
*/
121+
public static JdbcStoredProcInboundChannelAdapterSpec storedProcInboundAdapter(DataSource dataSource) {
122+
return new JdbcStoredProcInboundChannelAdapterSpec(new StoredProcExecutor(dataSource));
123+
}
124+
125+
/**
126+
* The factory to produce a {@link JdbcStoredProcOutboundChannelAdapterSpec}.
127+
* @param dataSource the {@link DataSource} to build on
128+
* @return the {@link JdbcStoredProcOutboundChannelAdapterSpec} instance
129+
*/
130+
public static JdbcStoredProcOutboundChannelAdapterSpec storedProcOutboundAdapter(DataSource dataSource) {
131+
return new JdbcStoredProcOutboundChannelAdapterSpec(new StoredProcExecutor(dataSource));
132+
}
133+
134+
/**
135+
* The factory to produce a {@link JdbcStoredProcOutboundGatewaySpec}.
136+
* @param dataSource the {@link DataSource} to build on
137+
* @return the {@link JdbcStoredProcOutboundGatewaySpec} instance
138+
*/
139+
public static JdbcStoredProcOutboundGatewaySpec storedProcOutboundGateway(DataSource dataSource) {
140+
return new JdbcStoredProcOutboundGatewaySpec(new StoredProcExecutor(dataSource));
141+
}
142+
143+
private Jdbc() {
144+
}
145+
146+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.jdbc.dsl;
18+
19+
import org.springframework.integration.dsl.MessageSourceSpec;
20+
import org.springframework.integration.jdbc.JdbcPollingChannelAdapter;
21+
import org.springframework.integration.jdbc.SqlParameterSourceFactory;
22+
import org.springframework.jdbc.core.JdbcOperations;
23+
import org.springframework.jdbc.core.RowMapper;
24+
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
25+
26+
/**
27+
* A {@link MessageSourceSpec} for a {@link JdbcInboundChannelAdapterSpec}.
28+
*
29+
* @author Jiandong Ma
30+
*
31+
* @since 7.0
32+
*/
33+
public class JdbcInboundChannelAdapterSpec extends MessageSourceSpec<JdbcInboundChannelAdapterSpec, JdbcPollingChannelAdapter> {
34+
35+
protected JdbcInboundChannelAdapterSpec(JdbcOperations jdbcOperations, String selectQuery) {
36+
this.target = new JdbcPollingChannelAdapter(jdbcOperations, selectQuery);
37+
}
38+
39+
/**
40+
* @param rowMapper the rowMapper
41+
* @return the spec
42+
* @see JdbcPollingChannelAdapter#setRowMapper(RowMapper)
43+
*/
44+
public JdbcInboundChannelAdapterSpec rowMapper(RowMapper<?> rowMapper) {
45+
this.target.setRowMapper(rowMapper);
46+
return _this();
47+
}
48+
49+
/**
50+
* @param updateSql the updateSql
51+
* @return the spec
52+
* @see JdbcPollingChannelAdapter#setUpdateSql(String)
53+
*/
54+
public JdbcInboundChannelAdapterSpec updateSql(String updateSql) {
55+
this.target.setUpdateSql(updateSql);
56+
return _this();
57+
}
58+
59+
/**
60+
* @param updatePerRow the updatePerRow
61+
* @return the spec
62+
* @see JdbcPollingChannelAdapter#setUpdatePerRow(boolean)
63+
*/
64+
public JdbcInboundChannelAdapterSpec updatePerRow(boolean updatePerRow) {
65+
this.target.setUpdatePerRow(updatePerRow);
66+
return _this();
67+
}
68+
69+
/**
70+
* @param sqlParameterSourceFactory the sqlParameterSourceFactory
71+
* @return the spec
72+
* @see JdbcPollingChannelAdapter#setUpdateSqlParameterSourceFactory(SqlParameterSourceFactory)
73+
*/
74+
public JdbcInboundChannelAdapterSpec updateSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory) {
75+
this.target.setUpdateSqlParameterSourceFactory(sqlParameterSourceFactory);
76+
return _this();
77+
}
78+
79+
/**
80+
* @param sqlQueryParameterSource the sqlQueryParameterSource
81+
* @return the spec
82+
* @see JdbcPollingChannelAdapter#setSelectSqlParameterSource(SqlParameterSource)
83+
*/
84+
public JdbcInboundChannelAdapterSpec selectSqlParameterSource(SqlParameterSource sqlQueryParameterSource) {
85+
this.target.setSelectSqlParameterSource(sqlQueryParameterSource);
86+
return _this();
87+
}
88+
89+
/**
90+
* @param maxRows the maxRows
91+
* @return the spec
92+
* @see JdbcPollingChannelAdapter#setMaxRows(int)
93+
*/
94+
public JdbcInboundChannelAdapterSpec maxRows(int maxRows) {
95+
this.target.setMaxRows(maxRows);
96+
return _this();
97+
}
98+
99+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.jdbc.dsl;
18+
19+
import org.springframework.integration.dsl.MessageHandlerSpec;
20+
import org.springframework.integration.jdbc.JdbcMessageHandler;
21+
import org.springframework.integration.jdbc.MessagePreparedStatementSetter;
22+
import org.springframework.integration.jdbc.SqlParameterSourceFactory;
23+
import org.springframework.jdbc.core.JdbcOperations;
24+
25+
/**
26+
* A {@link MessageHandlerSpec} for a {@link JdbcOutboundChannelAdapterSpec}.
27+
*
28+
* @author Jiandong Ma
29+
*
30+
* @since 7.0
31+
*/
32+
public class JdbcOutboundChannelAdapterSpec extends MessageHandlerSpec<JdbcOutboundChannelAdapterSpec, JdbcMessageHandler> {
33+
34+
protected JdbcOutboundChannelAdapterSpec(JdbcOperations jdbcOperations, String updateQuery) {
35+
this.target = new JdbcMessageHandler(jdbcOperations, updateQuery);
36+
}
37+
38+
/**
39+
* @param keysGenerated the keysGenerated
40+
* @return the spec
41+
* @see JdbcMessageHandler#setKeysGenerated(boolean)
42+
*/
43+
public JdbcOutboundChannelAdapterSpec keysGenerated(boolean keysGenerated) {
44+
this.target.setKeysGenerated(keysGenerated);
45+
return _this();
46+
}
47+
48+
/**
49+
* @param sqlParameterSourceFactory the sqlParameterSourceFactory
50+
* @return the spec
51+
* @see JdbcMessageHandler#setSqlParameterSourceFactory(SqlParameterSourceFactory)
52+
*/
53+
public JdbcOutboundChannelAdapterSpec sqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory) {
54+
this.target.setSqlParameterSourceFactory(sqlParameterSourceFactory);
55+
return _this();
56+
}
57+
58+
/**
59+
* @param usePayloadAsParameterSource the usePayloadAsParameterSource
60+
* @return the spec
61+
* @see JdbcMessageHandler#setUsePayloadAsParameterSource(boolean)
62+
*/
63+
public JdbcOutboundChannelAdapterSpec usePayloadAsParameterSource(boolean usePayloadAsParameterSource) {
64+
this.target.setUsePayloadAsParameterSource(usePayloadAsParameterSource);
65+
return _this();
66+
}
67+
68+
/**
69+
* @param preparedStatementSetter the preparedStatementSetter
70+
* @return the spec
71+
* @see JdbcMessageHandler#setPreparedStatementSetter(MessagePreparedStatementSetter)
72+
*/
73+
public JdbcOutboundChannelAdapterSpec preparedStatementSetter(MessagePreparedStatementSetter preparedStatementSetter) {
74+
this.target.setPreparedStatementSetter(preparedStatementSetter);
75+
return _this();
76+
}
77+
78+
}

0 commit comments

Comments
 (0)