strongduanmu commented on code in PR #24405:
URL: https://github.com/apache/shardingsphere/pull/24405#discussion_r1127344939
##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java:
##########
@@ -653,7 +658,17 @@ public int[] executeBatch() throws SQLException {
try {
// TODO add raw SQL executor
initBatchPreparedStatementExecutor();
- return
batchPreparedStatementExecutor.executeBatch(executionContext.getSqlStatementContext());
+ int[] results =
batchPreparedStatementExecutor.executeBatch(executionContext.getSqlStatementContext());
+ if (statementOption.isReturnGeneratedKeys() &&
batchPreparedStatementExecutor.getStatements().size() == 1 &&
generatedValues.isEmpty()) {
Review Comment:
Please put constants on the left condition.
##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/statement/ShardingSpherePreparedStatement.java:
##########
@@ -653,7 +658,17 @@ public int[] executeBatch() throws SQLException {
try {
// TODO add raw SQL executor
initBatchPreparedStatementExecutor();
- return
batchPreparedStatementExecutor.executeBatch(executionContext.getSqlStatementContext());
+ int[] results =
batchPreparedStatementExecutor.executeBatch(executionContext.getSqlStatementContext());
+ if (statementOption.isReturnGeneratedKeys() &&
batchPreparedStatementExecutor.getStatements().size() == 1 &&
generatedValues.isEmpty()) {
+ ResultSet resultSet =
batchPreparedStatementExecutor.getStatements().get(0).getGeneratedKeys();
Review Comment:
Why only get the result generated by the first statement?
##########
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ReadwriteSplittingPreparedStatementTest.java:
##########
@@ -118,4 +118,65 @@ public void
assertGetGeneratedKeysWithPrimaryKeyIsNullInTransactional() throws S
connection.commit();
}
}
+
+ @Test
+ public void assertGetAutoGeneratedKeysAfterExecuteBatch() throws
SQLException {
Review Comment:
Can you move these case to e2e test case? We need to test different
scenarios such as sharding, read-write splitting, etc.
##########
jdbc/core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ReadwriteSplittingPreparedStatementTest.java:
##########
@@ -118,4 +118,65 @@ public void
assertGetGeneratedKeysWithPrimaryKeyIsNullInTransactional() throws S
connection.commit();
}
}
+
+ @Test
+ public void assertGetAutoGeneratedKeysAfterExecuteBatch() throws
SQLException {
Review Comment:
You can add test case in `cases/dml/dml-integration-insert.xml` file, and
then execute `BatchDMLE2EIT`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]