Skip to content

Commit

Permalink
commit any active transaction when switching to auto-commit mode
Browse files Browse the repository at this point in the history
  • Loading branch information
reugn committed Dec 5, 2024
1 parent a639590 commit ed41703
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/com/aerospike/jdbc/AerospikeConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ public boolean getAutoCommit() throws SQLException {
@Override
public void setAutoCommit(boolean autoCommit) throws SQLException {
checkClosed();
if (autoCommit) {
txn = null;
if (this.autoCommit == autoCommit) {
return;
}
if (!this.autoCommit) {
commit();
}
this.autoCommit = autoCommit;
logger.fine(() -> format("setAutoCommit = %b", autoCommit));
}

/**
Expand All @@ -107,7 +111,8 @@ public void commit() throws SQLException {
throw new SQLException("Connection is in auto-commit mode");
}
if (txn == null) {
throw new SQLException("txn is null");
logger.info("No active transaction to commit");
return;
}
try {
CommitStatus status = client.commit(txn);
Expand All @@ -131,7 +136,8 @@ public void rollback() throws SQLException {
throw new SQLException("Connection is in auto-commit mode");
}
if (txn == null) {
throw new SQLException("txn is null");
logger.info("No active transaction to rollback");
return;
}
try {
AbortStatus status = client.abort(txn);
Expand Down

0 comments on commit ed41703

Please sign in to comment.