Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.jdbc.dsl;

import javax.sql.DataSource;

import org.springframework.integration.jdbc.StoredProcExecutor;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;

/**
* Factory class for JDBC components.
*
* @author Jiandong Ma
*
* @since 7.0
*/
public final class Jdbc {

/**
* The factory to produce a {@link JdbcInboundChannelAdapterSpec}.
* @param dataSource the {@link DataSource} to build on
* @param selectQuery the select query to build on
* @return the {@link JdbcInboundChannelAdapterSpec} instance
*/
public static JdbcInboundChannelAdapterSpec inboundAdapter(DataSource dataSource, String selectQuery) {
return inboundAdapter(new JdbcTemplate(dataSource), selectQuery);
}

/**
* The factory to produce a {@link JdbcInboundChannelAdapterSpec}.
* @param jdbcOperations the {@link JdbcOperations} to build on
* @param selectQuery the select query to build on
* @return the {@link JdbcInboundChannelAdapterSpec} instance
*/
public static JdbcInboundChannelAdapterSpec inboundAdapter(JdbcOperations jdbcOperations, String selectQuery) {
return new JdbcInboundChannelAdapterSpec(jdbcOperations, selectQuery);
}

/**
* The factory to produce a {@link JdbcOutboundChannelAdapterSpec}.
* @param dataSource the {@link DataSource} to build on
* @param updateQuery the update query to build on
* @return the {@link JdbcOutboundChannelAdapterSpec} instance
*/
public static JdbcOutboundChannelAdapterSpec outboundAdapter(DataSource dataSource, String updateQuery) {
return outboundAdapter(new JdbcTemplate(dataSource), updateQuery);
}

/**
* The factory to produce a {@link JdbcOutboundChannelAdapterSpec}.
* @param jdbcOperations the {@link JdbcOperations} to build on
* @param updateQuery the update query to build on
* @return the {@link JdbcOutboundChannelAdapterSpec} instance
*/
public static JdbcOutboundChannelAdapterSpec outboundAdapter(JdbcOperations jdbcOperations, String updateQuery) {
return new JdbcOutboundChannelAdapterSpec(jdbcOperations, updateQuery);
}

/**
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
* @param dataSource the {@link DataSource} to build on
* @param updateQuery the update query to build on
* @return the {@link JdbcOutboundGatewaySpec} instance
*/
public static JdbcOutboundGatewaySpec outboundGateway(DataSource dataSource, String updateQuery) {
return outboundGateway(new JdbcTemplate(dataSource), updateQuery);
}

/**
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
* @param dataSource the {@link DataSource} to build on
* @param updateQuery the update query to build on
* @param selectQuery the select query to build on
* @return the {@link JdbcOutboundGatewaySpec} instance
*/
public static JdbcOutboundGatewaySpec outboundGateway(DataSource dataSource, String updateQuery, String selectQuery) {
return outboundGateway(new JdbcTemplate(dataSource), updateQuery, selectQuery);
}

/**
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
* @param jdbcOperations the {@link JdbcOperations} to build on
* @param updateQuery the update query to build on
* @return the {@link JdbcOutboundGatewaySpec} instance
*/
public static JdbcOutboundGatewaySpec outboundGateway(JdbcOperations jdbcOperations, String updateQuery) {
return outboundGateway(jdbcOperations, updateQuery, null);
}

/**
* The factory to produce a {@link JdbcOutboundGatewaySpec}.
* @param jdbcOperations the {@link JdbcOperations} to build on
* @param updateQuery the update query to build on
* @param selectQuery the select query to build on
* @return the {@link JdbcOutboundGatewaySpec} instance
*/
public static JdbcOutboundGatewaySpec outboundGateway(JdbcOperations jdbcOperations, String updateQuery, String selectQuery) {
return new JdbcOutboundGatewaySpec(jdbcOperations, updateQuery, selectQuery);
}

/**
* The factory to produce a {@link JdbcStoredProcInboundChannelAdapterSpec}.
* @param dataSource the {@link DataSource} to build on
* @return the {@link JdbcStoredProcInboundChannelAdapterSpec} instance
*/
public static JdbcStoredProcInboundChannelAdapterSpec storedProcInboundAdapter(DataSource dataSource) {
return new JdbcStoredProcInboundChannelAdapterSpec(new StoredProcExecutor(dataSource));
}

/**
* The factory to produce a {@link JdbcStoredProcOutboundChannelAdapterSpec}.
* @param dataSource the {@link DataSource} to build on
* @return the {@link JdbcStoredProcOutboundChannelAdapterSpec} instance
*/
public static JdbcStoredProcOutboundChannelAdapterSpec storedProcOutboundAdapter(DataSource dataSource) {
return new JdbcStoredProcOutboundChannelAdapterSpec(new StoredProcExecutor(dataSource));
}

/**
* The factory to produce a {@link JdbcStoredProcOutboundGatewaySpec}.
* @param dataSource the {@link DataSource} to build on
* @return the {@link JdbcStoredProcOutboundGatewaySpec} instance
*/
public static JdbcStoredProcOutboundGatewaySpec storedProcOutboundGateway(DataSource dataSource) {
return new JdbcStoredProcOutboundGatewaySpec(new StoredProcExecutor(dataSource));
}

private Jdbc() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.jdbc.dsl;

import org.springframework.integration.dsl.MessageSourceSpec;
import org.springframework.integration.jdbc.JdbcPollingChannelAdapter;
import org.springframework.integration.jdbc.SqlParameterSourceFactory;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;

/**
* A {@link MessageSourceSpec} for a {@link JdbcInboundChannelAdapterSpec}.
*
* @author Jiandong Ma
*
* @since 7.0
*/
public class JdbcInboundChannelAdapterSpec extends MessageSourceSpec<JdbcInboundChannelAdapterSpec, JdbcPollingChannelAdapter> {

protected JdbcInboundChannelAdapterSpec(JdbcOperations jdbcOperations, String selectQuery) {
this.target = new JdbcPollingChannelAdapter(jdbcOperations, selectQuery);
}

/**
* @param rowMapper the rowMapper
* @return the spec
* @see JdbcPollingChannelAdapter#setRowMapper(RowMapper)
*/
public JdbcInboundChannelAdapterSpec rowMapper(RowMapper<?> rowMapper) {
this.target.setRowMapper(rowMapper);
return _this();
}

/**
* @param updateSql the updateSql
* @return the spec
* @see JdbcPollingChannelAdapter#setUpdateSql(String)
*/
public JdbcInboundChannelAdapterSpec updateSql(String updateSql) {
this.target.setUpdateSql(updateSql);
return _this();
}

/**
* @param updatePerRow the updatePerRow
* @return the spec
* @see JdbcPollingChannelAdapter#setUpdatePerRow(boolean)
*/
public JdbcInboundChannelAdapterSpec updatePerRow(boolean updatePerRow) {
this.target.setUpdatePerRow(updatePerRow);
return _this();
}

/**
* @param sqlParameterSourceFactory the sqlParameterSourceFactory
* @return the spec
* @see JdbcPollingChannelAdapter#setUpdateSqlParameterSourceFactory(SqlParameterSourceFactory)
*/
public JdbcInboundChannelAdapterSpec updateSqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory) {
this.target.setUpdateSqlParameterSourceFactory(sqlParameterSourceFactory);
return _this();
}

/**
* @param sqlQueryParameterSource the sqlQueryParameterSource
* @return the spec
* @see JdbcPollingChannelAdapter#setSelectSqlParameterSource(SqlParameterSource)
*/
public JdbcInboundChannelAdapterSpec selectSqlParameterSource(SqlParameterSource sqlQueryParameterSource) {
this.target.setSelectSqlParameterSource(sqlQueryParameterSource);
return _this();
}

/**
* @param maxRows the maxRows
* @return the spec
* @see JdbcPollingChannelAdapter#setMaxRows(int)
*/
public JdbcInboundChannelAdapterSpec maxRows(int maxRows) {
this.target.setMaxRows(maxRows);
return _this();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.springframework.integration.jdbc.dsl;

import org.springframework.integration.dsl.MessageHandlerSpec;
import org.springframework.integration.jdbc.JdbcMessageHandler;
import org.springframework.integration.jdbc.MessagePreparedStatementSetter;
import org.springframework.integration.jdbc.SqlParameterSourceFactory;
import org.springframework.jdbc.core.JdbcOperations;

/**
* A {@link MessageHandlerSpec} for a {@link JdbcOutboundChannelAdapterSpec}.
*
* @author Jiandong Ma
*
* @since 7.0
*/
public class JdbcOutboundChannelAdapterSpec extends MessageHandlerSpec<JdbcOutboundChannelAdapterSpec, JdbcMessageHandler> {

protected JdbcOutboundChannelAdapterSpec(JdbcOperations jdbcOperations, String updateQuery) {
this.target = new JdbcMessageHandler(jdbcOperations, updateQuery);
}

/**
* @param keysGenerated the keysGenerated
* @return the spec
* @see JdbcMessageHandler#setKeysGenerated(boolean)
*/
public JdbcOutboundChannelAdapterSpec keysGenerated(boolean keysGenerated) {
this.target.setKeysGenerated(keysGenerated);
return _this();
}

/**
* @param sqlParameterSourceFactory the sqlParameterSourceFactory
* @return the spec
* @see JdbcMessageHandler#setSqlParameterSourceFactory(SqlParameterSourceFactory)
*/
public JdbcOutboundChannelAdapterSpec sqlParameterSourceFactory(SqlParameterSourceFactory sqlParameterSourceFactory) {
this.target.setSqlParameterSourceFactory(sqlParameterSourceFactory);
return _this();
}

/**
* @param usePayloadAsParameterSource the usePayloadAsParameterSource
* @return the spec
* @see JdbcMessageHandler#setUsePayloadAsParameterSource(boolean)
*/
public JdbcOutboundChannelAdapterSpec usePayloadAsParameterSource(boolean usePayloadAsParameterSource) {
this.target.setUsePayloadAsParameterSource(usePayloadAsParameterSource);
return _this();
}

/**
* @param preparedStatementSetter the preparedStatementSetter
* @return the spec
* @see JdbcMessageHandler#setPreparedStatementSetter(MessagePreparedStatementSetter)
*/
public JdbcOutboundChannelAdapterSpec preparedStatementSetter(MessagePreparedStatementSetter preparedStatementSetter) {
this.target.setPreparedStatementSetter(preparedStatementSetter);
return _this();
}

}
Loading