|
| 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 | +} |
0 commit comments