20260727225141
This commit is contained in:
1 parent
9dbaef7787
commit
63588bd217
97 files changed
+1309
-145
No files matched your search
@@ -347,7 +347,20 @@ public class DbUtils {
|
||||
Object keyValue = requiredKeyValue(normalizedRow, keyColumn, table.requestedName());
|
||||
String sql = "DELETE FROM " + table.quotedName()
|
||||
+ " WHERE " + quoteColumn(keyColumn) + " = ?";
|
||||
return executeWrite(connection, sql, List.of(keyValue), "删除");
|
||||
return executeDelete(connection, sql, List.of(keyValue));
|
||||
}
|
||||
|
||||
private int executeDelete(
|
||||
Connection connection,
|
||||
String sql,
|
||||
List<Object> parameters
|
||||
) throws SQLException {
|
||||
try (PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||
for (int index = 0; index < parameters.size(); index++) {
|
||||
statement.setObject(index + 1, parameters.get(index));
|
||||
}
|
||||
return statement.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> executeQuery(
|
||||
|
||||
@@ -84,6 +84,22 @@ class DataSaveServiceTests {
|
||||
verify(fixture.connection, org.mockito.Mockito.never()).commit();
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteAllowsMultipleAffectedRows() throws Exception {
|
||||
JdbcFixture fixture = new JdbcFixture("b_module_id", "b_name");
|
||||
DataSaveService service = fixture.createService();
|
||||
when(fixture.deleteStatement.executeUpdate()).thenReturn(3);
|
||||
|
||||
service.save(List.of(Map.of(
|
||||
"table", "b_user",
|
||||
"key_field", "b_module_id",
|
||||
"deletes", List.of(Map.of("b_module_id", "M001"))
|
||||
)));
|
||||
|
||||
verify(fixture.deleteStatement).setObject(1, "M001");
|
||||
verify(fixture.connection).commit();
|
||||
}
|
||||
|
||||
private static final class JdbcFixture {
|
||||
|
||||
private final DataSource dataSource = mock(DataSource.class);
|
||||
@@ -110,7 +126,7 @@ class DataSaveServiceTests {
|
||||
when(metadata.isAutoIncrement(1)).thenReturn(false);
|
||||
when(metadata.isAutoIncrement(2)).thenReturn(false);
|
||||
|
||||
when(connection.prepareStatement("DELETE FROM [b_user] WHERE [b_id] = ?"))
|
||||
when(connection.prepareStatement("DELETE FROM [b_user] WHERE [" + firstColumn + "] = ?"))
|
||||
.thenReturn(deleteStatement);
|
||||
when(connection.prepareStatement(
|
||||
"UPDATE [b_user] SET [" + secondColumn + "] = ? WHERE [b_id] = ?"
|
||||
|
||||
Reference in new issue
Block a user