strongduanmu commented on code in PR #18905:
URL: https://github.com/apache/shardingsphere/pull/18905#discussion_r925147197


##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ReadwriteSplittingPreparedStatementTest.java:
##########
@@ -92,4 +94,31 @@ public void assertGetGeneratedKeysWithPrimaryKeyIsNull() 
throws SQLException {
             assertFalse(generatedKeys.next());
         }
     }
+
+    @Test
+    public void assertGetGeneratedKeysWithPrimaryKeyIsNullInTransactional() 
throws SQLException {
+        try (
+                Connection connection = getReadwriteSplittingDataSource()
+                        .getConnection();
+                PreparedStatement preparedStatement = 
connection.prepareStatement("INSERT INTO t_config(id, status) VALUES(?, ?);", 
Statement.RETURN_GENERATED_KEYS)) {
+            connection.setAutoCommit(false);
+            Object lastIdObject = null;
+            Object idObject = null;
+            for (int i = 1; i <= 3; i++) {
+                preparedStatement.setObject(1, null);
+                preparedStatement.setString(2, "OK");
+                preparedStatement.executeUpdate();
+                ResultSet generatedKeys = preparedStatement.getGeneratedKeys();
+                assertTrue(generatedKeys.next());
+                int columnCount = generatedKeys.getMetaData().getColumnCount();
+                for (int index = 0; index < columnCount; index++) {

Review Comment:
   Can you remove this loop logic? Just call `generatedKeys.getObject(1)` once.



##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ReadwriteSplittingPreparedStatementTest.java:
##########
@@ -30,30 +31,31 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotEquals;
 
 public final class ReadwriteSplittingPreparedStatementTest extends 
AbstractShardingSphereDataSourceForReadwriteSplittingTest {
-    

Review Comment:
   Please execute `mvn spotless:apply` to format code on your local machine.



##########
shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/statement/ReadwriteSplittingPreparedStatementTest.java:
##########
@@ -92,4 +94,31 @@ public void assertGetGeneratedKeysWithPrimaryKeyIsNull() 
throws SQLException {
             assertFalse(generatedKeys.next());
         }
     }
+
+    @Test
+    public void assertGetGeneratedKeysWithPrimaryKeyIsNullInTransactional() 
throws SQLException {
+        try (
+                Connection connection = getReadwriteSplittingDataSource()
+                        .getConnection();
+                PreparedStatement preparedStatement = 
connection.prepareStatement("INSERT INTO t_config(id, status) VALUES(?, ?);", 
Statement.RETURN_GENERATED_KEYS)) {
+            connection.setAutoCommit(false);
+            Object lastIdObject = null;

Review Comment:
   Do you think `lastGeneratedId` and `generatedId` is better?



-- 
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]

Reply via email to