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

Use a single transaction per batch #95

Merged
merged 1 commit into from
Oct 14, 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
16 changes: 13 additions & 3 deletions src/main/java/org/duckdb/DuckDBPreparedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ private void prepare(String sql) throws SQLException {

@Override
public boolean execute() throws SQLException {
return execute(true);
}

private boolean execute(boolean startTransaction) throws SQLException {
if (isClosed()) {
throw new SQLException("Statement was closed");
}
Expand All @@ -138,7 +142,9 @@ public boolean execute() throws SQLException {
select_result = null;

try {
startTransaction();
if (startTransaction) {
startTransaction();
}
result_ref = DuckDBNative.duckdb_jdbc_execute(stmt_ref, params);
DuckDBResultSetMetaData result_meta = DuckDBNative.duckdb_jdbc_query_result_meta(result_ref);
select_result = new DuckDBResultSet(this, result_meta, result_ref, conn.conn_ref);
Expand Down Expand Up @@ -476,19 +482,23 @@ public int[] executeBatch() throws SQLException {

private int[] executeBatchedPreparedStatement() throws SQLException {
int[] updateCounts = new int[this.batchedParams.size()];

startTransaction();
for (int i = 0; i < this.batchedParams.size(); i++) {
params = this.batchedParams.get(i);
execute();
execute(false);
updateCounts[i] = getUpdateCount();
}
return updateCounts;
}

private int[] executeBatchedStatements() throws SQLException {
int[] updateCounts = new int[this.batchedStatements.size()];

startTransaction();
for (int i = 0; i < this.batchedStatements.size(); i++) {
prepare(this.batchedStatements.get(i));
execute();
execute(false);
updateCounts[i] = getUpdateCount();
}
return updateCounts;
Expand Down
Loading