Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Improve][Connector-v2] Release resource in closeStatements even exception occurred in executeBatch in jdbc #7533

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Improve][Connector-v2] Release resource in closeStatements even exce…
…ption occurred in executeBatch
dailai committed Aug 30, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 8cc6ac95a82277ffd1d06393489d1ba2c6ea22ab
Original file line number Diff line number Diff line change
@@ -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) {
Original file line number Diff line number Diff line change
@@ -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
@@ -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();
}
}
}
}