Skip to content

Commit

Permalink
[Improve][Connector-v2] Release resource in closeStatements even exce…
Browse files Browse the repository at this point in the history
…ption occurred in executeBatch
  • Loading branch information
dailai committed Aug 30, 2024
1 parent 8ea9080 commit ee3c20a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ public void executeBatch() throws SQLException {

@Override
public void closeStatements() throws SQLException {
if (!buffer.isEmpty()) {
executeBatch();
try {
if (!buffer.isEmpty()) {
executeBatch();
}
} finally {
if (!buffer.isEmpty()) {
buffer.clear();
}
upsertExecutor.closeStatements();
deleteExecutor.closeStatements();
}
upsertExecutor.closeStatements();
deleteExecutor.closeStatements();
}

private boolean changeFlag(RowKind rowKind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ public void executeBatch() throws SQLException {

@Override
public void closeStatements() throws SQLException {
if (!buffer.isEmpty()) {
executeBatch();
try {
if (!buffer.isEmpty()) {
executeBatch();
}
} finally {
if (!buffer.isEmpty()) {
buffer.clear();
}
statementExecutor.closeStatements();
}
statementExecutor.closeStatements();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,16 @@ public void executeBatch() throws SQLException {

@Override
public void closeStatements() throws SQLException {
if (!submitted) {
executeBatch();
}
for (PreparedStatement statement :
Arrays.asList(existStatement, insertStatement, updateStatement)) {
if (statement != null) {
statement.close();
try {
if (!submitted) {
executeBatch();
}
} finally {
for (PreparedStatement statement :
Arrays.asList(existStatement, insertStatement, updateStatement)) {
if (statement != null) {
statement.close();
}
}
}
}
Expand Down

0 comments on commit ee3c20a

Please sign in to comment.