This is an automated email from the ASF dual-hosted git repository.
zhonghongsheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 729e8221011 Refactor DataSourceExecuteUtils execute methods (#37880)
729e8221011 is described below
commit 729e8221011555c4a57dee0b4865ebd9acc838da
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Thu Jan 29 09:39:58 2026 +0800
Refactor DataSourceExecuteUtils execute methods (#37880)
* Rename DataSourceExecuteUtils.executeBatch
* Refactor DataSourceExecuteUtils.execute throws SQLException
---
.../e2e/operation/pipeline/cases/cdc/CDCE2EIT.java | 4 ++--
.../pipeline/cases/task/E2EIncrementalTask.java | 21 ++++++++++++++++-----
.../dao/order/large/IntPkLargeOrderDAO.java | 2 +-
.../dao/order/small/StringPkSmallOrderDAO.java | 2 +-
.../pipeline/dao/orderitem/IntPkOrderItemDAO.java | 2 +-
.../pipeline/util/DataSourceExecuteUtils.java | 11 +++--------
6 files changed, 24 insertions(+), 18 deletions(-)
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/cdc/CDCE2EIT.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/cdc/CDCE2EIT.java
index 28c308be402..f92b1c0e620 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/cdc/CDCE2EIT.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/cdc/CDCE2EIT.java
@@ -108,8 +108,8 @@ class CDCE2EIT {
log.info("init data begin: {}", LocalDateTime.now());
IntPkLargeOrderDAO orderDAO = new
IntPkLargeOrderDAO(jdbcDataSource, containerComposer.getDatabaseType(),
orderQualifiedTable);
orderDAO.batchInsert(PipelineContainerComposer.TABLE_INIT_ROW_COUNT);
- DataSourceExecuteUtils.execute(jdbcDataSource, "INSERT INTO
t_address(id, address_name) VALUES (?,?)", Arrays.asList(new Object[]{1, "a"},
new Object[]{2, "b"}));
- DataSourceExecuteUtils.execute(jdbcDataSource, "INSERT INTO
t_single(id) VALUES (?)", Arrays.asList(new Object[]{1}, new Object[]{2}, new
Object[]{3}));
+ DataSourceExecuteUtils.executeBatch(jdbcDataSource, "INSERT INTO
t_address(id, address_name) VALUES (?,?)", Arrays.asList(new Object[]{1, "a"},
new Object[]{2, "b"}));
+ DataSourceExecuteUtils.executeBatch(jdbcDataSource, "INSERT INTO
t_single(id) VALUES (?)", Arrays.asList(new Object[]{1}, new Object[]{2}, new
Object[]{3}));
log.info("init data end: {}", LocalDateTime.now());
PipelineDataSource targetDataSource =
DataSourceTestUtils.createStandardDataSource(containerComposer.getActualJdbcUrlTemplate(PipelineContainerComposer.DS_4,
false),
containerComposer.getUsername(),
containerComposer.getPassword());
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/task/E2EIncrementalTask.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/task/E2EIncrementalTask.java
index 64b9fe0d13f..db2e1168cac 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/task/E2EIncrementalTask.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/cases/task/E2EIncrementalTask.java
@@ -25,12 +25,14 @@ import
org.apache.shardingsphere.database.connector.mysql.type.MySQLDatabaseType
import
org.apache.shardingsphere.database.connector.opengauss.type.OpenGaussDatabaseType;
import
org.apache.shardingsphere.database.connector.postgresql.type.PostgreSQLDatabaseType;
import
org.apache.shardingsphere.infra.algorithm.keygen.spi.KeyGenerateAlgorithm;
+import
org.apache.shardingsphere.infra.exception.external.sql.type.wrapper.SQLWrapperException;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.framework.helper.PipelineCaseHelper;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.util.DataSourceExecuteUtils;
import
org.apache.shardingsphere.test.e2e.operation.pipeline.util.SQLBuilderUtils;
import javax.sql.DataSource;
import java.math.BigDecimal;
+import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
@@ -74,6 +76,15 @@ public final class E2EIncrementalTask implements Runnable {
@Override
public void run() {
+ try {
+ run0();
+ } catch (final SQLException ex) {
+ log.error("Increment task runnable execute failed.", ex);
+ throw new SQLWrapperException(ex);
+ }
+ }
+
+ private void run0() throws SQLException {
List<Object[]> orderInsertData =
PipelineCaseHelper.generateOrderInsertData(databaseType,
primaryKeyGenerateAlgorithm, loopCount);
List<Object> primaryKeys = new LinkedList<>();
for (Object[] each : orderInsertData) {
@@ -97,7 +108,7 @@ public final class E2EIncrementalTask implements Runnable {
log.info("increment task runnable execute successfully.");
}
- private void insertOrder(final Object[] orderInsertData) {
+ private void insertOrder(final Object[] orderInsertData) throws
SQLException {
String sql;
if (databaseType instanceof MySQLDatabaseType) {
sql = SQLBuilderUtils.buildInsertSQL(MYSQL_COLUMN_NAMES,
orderTableName);
@@ -111,7 +122,7 @@ public final class E2EIncrementalTask implements Runnable {
DataSourceExecuteUtils.execute(dataSource, sql, orderInsertData);
}
- private void doIncrementalChanges(final Object orderId, final
List<IncrementalAction> actions) {
+ private void doIncrementalChanges(final Object orderId, final
List<IncrementalAction> actions) throws SQLException {
for (IncrementalAction each : actions) {
switch (each) {
case PLAIN_UPDATE:
@@ -129,7 +140,7 @@ public final class E2EIncrementalTask implements Runnable {
}
}
- private void updateOrderById(final Object orderId) {
+ private void updateOrderById(final Object orderId) throws SQLException {
ThreadLocalRandom random = ThreadLocalRandom.current();
int randomInt = random.nextInt(-100, 100);
if (databaseType instanceof MySQLDatabaseType) {
@@ -171,13 +182,13 @@ public final class E2EIncrementalTask implements Runnable
{
return new ArrayList<>(columnNames.subList(2, columnNames.size()));
}
- private void deleteOrderById(final Object orderId) {
+ private void deleteOrderById(final Object orderId) throws SQLException {
String sql = SQLBuilderUtils.buildDeleteSQL(orderTableName,
"order_id");
log.info("delete sql: {}, params: {}", sql, orderId);
DataSourceExecuteUtils.execute(dataSource, sql, new Object[]{orderId});
}
- private void setNullToAllFields(final Object orderId) {
+ private void setNullToAllFields(final Object orderId) throws SQLException {
if (databaseType instanceof MySQLDatabaseType) {
String sql =
SQLBuilderUtils.buildUpdateSQL(ignoreShardingColumns(MYSQL_COLUMN_NAMES),
orderTableName, "null");
log.info("update sql: {}", sql);
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/large/IntPkLargeOrderDAO.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/large/IntPkLargeOrderDAO.java
index 63e03975967..b6efb3ad99c 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/large/IntPkLargeOrderDAO.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/large/IntPkLargeOrderDAO.java
@@ -72,7 +72,7 @@ public final class IntPkLargeOrderDAO {
List<Object[]> paramsList =
PipelineCaseHelper.generateOrderInsertData(databaseType, new
AutoIncrementKeyGenerateAlgorithm(), recordCount);
String sql = sqlBuilder.buildPreparedInsertSQL(qualifiedTableName);
log.info("Batch insert int pk large order SQL: {}, params list size:
{}", sql, paramsList.size());
- DataSourceExecuteUtils.execute(dataSource, sql, paramsList);
+ DataSourceExecuteUtils.executeBatch(dataSource, sql, paramsList);
}
/**
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/small/StringPkSmallOrderDAO.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/small/StringPkSmallOrderDAO.java
index 6fc64162bf6..6865d27deb4 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/small/StringPkSmallOrderDAO.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/order/small/StringPkSmallOrderDAO.java
@@ -69,7 +69,7 @@ public final class StringPkSmallOrderDAO {
List<Object[]> paramsList =
PipelineCaseHelper.generateSmallOrderInsertData(new UUIDKeyGenerateAlgorithm(),
recordCount);
String sql = sqlBuilder.buildPreparedInsertSQL(qualifiedTableName);
log.info("Batch insert string pk small order SQL: {}, params list
size: {}", sql, paramsList.size());
- DataSourceExecuteUtils.execute(dataSource, sql, paramsList);
+ DataSourceExecuteUtils.executeBatch(dataSource, sql, paramsList);
}
/**
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/orderitem/IntPkOrderItemDAO.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/orderitem/IntPkOrderItemDAO.java
index 5f1cd586a66..755504274a5 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/orderitem/IntPkOrderItemDAO.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/dao/orderitem/IntPkOrderItemDAO.java
@@ -65,7 +65,7 @@ public final class IntPkOrderItemDAO {
List<Object[]> paramsList =
PipelineCaseHelper.generateOrderItemInsertData(new
AutoIncrementKeyGenerateAlgorithm(), recordCount);
String sql = sqlBuilder.buildPreparedInsertSQL(schemaPrefix);
log.info("Batch insert order_item SQL: {}, params list size: {}", sql,
paramsList.size());
- DataSourceExecuteUtils.execute(dataSource, sql, paramsList);
+ DataSourceExecuteUtils.executeBatch(dataSource, sql, paramsList);
}
/**
diff --git
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/util/DataSourceExecuteUtils.java
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/util/DataSourceExecuteUtils.java
index fdb8cd91758..be141361671 100644
---
a/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/util/DataSourceExecuteUtils.java
+++
b/test/e2e/operation/pipeline/src/test/java/org/apache/shardingsphere/test/e2e/operation/pipeline/util/DataSourceExecuteUtils.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.test.e2e.operation.pipeline.util;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.infra.exception.external.sql.type.wrapper.SQLWrapperException;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -55,18 +54,15 @@ public final class DataSourceExecuteUtils {
* @param dataSource data source
* @param sql SQL
* @param params parameters
- * @throws SQLWrapperException SQL wrapper exception
+ * @throws SQLException SQL exception
*/
- // TODO Throw SQLException
- public static void execute(final DataSource dataSource, final String sql,
final Object[] params) {
+ public static void execute(final DataSource dataSource, final String sql,
final Object[] params) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
PreparedStatement preparedStatement =
connection.prepareStatement(sql);
for (int i = 0; i < params.length; i++) {
preparedStatement.setObject(i + 1, params[i]);
}
preparedStatement.execute();
- } catch (final SQLException ex) {
- throw new SQLWrapperException(ex);
}
}
@@ -78,8 +74,7 @@ public final class DataSourceExecuteUtils {
* @param paramsList parameters
* @throws SQLException SQL exception
*/
- // TODO Rename executeBatch
- public static void execute(final DataSource dataSource, final String sql,
final List<Object[]> paramsList) throws SQLException {
+ public static void executeBatch(final DataSource dataSource, final String
sql, final List<Object[]> paramsList) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
PreparedStatement preparedStatement =
connection.prepareStatement(sql);
int batchSize = 1000;