Skip to content

Fix rollback in auto-commit mode and handle numeric autocommit responses#1206

Open
vikrantpuppala wants to merge 2 commits intodatabricks:mainfrom
vikrantpuppala:vpuppala/transaction-rollback-autocommit-fix
Open

Fix rollback in auto-commit mode and handle numeric autocommit responses#1206
vikrantpuppala wants to merge 2 commits intodatabricks:mainfrom
vikrantpuppala:vpuppala/transaction-rollback-autocommit-fix

Conversation

@vikrantpuppala
Copy link
Collaborator

@vikrantpuppala vikrantpuppala commented Feb 11, 2026

Summary

  • rollback() now throws DatabricksTransactionException when called while the connection is in auto-commit mode (no active transaction), aligning behavior with the JDBC spec
  • fetchAutoCommitStateFromServer() now accepts both "1"/"0" and "true"/"false" responses from the SET AUTOCOMMIT query, since different server implementations return different formats
  • Updated E2E and unit tests to reflect the corrected behavior

Context

  1. connection.rollback() in auto-commit mode should throw an exception, not silently succeed
  2. SET AUTOCOMMIT query returns "1"/"0" rather than "true"/"false" depending on the server

Test plan

  • Unit tests pass: DatabricksConnectionTest (42/42 pass)
  • E2E tests: TransactionTests and ExplicitTransactionStatementTests against staging warehouse

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 11, 2026 16:44
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Aligns the driver’s transaction/autocommit behavior with JDBC spec by making rollback() invalid in auto-commit mode and by tolerating numeric ("1"/"0") autocommit state responses from SET AUTOCOMMIT.

Changes:

  • Make DatabricksConnection.rollback() throw in auto-commit mode (no active transaction).
  • Update server autocommit state parsing to accept "true"/"false" and "1"/"0".
  • Adjust unit + E2E tests for the updated rollback/autocommit behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/main/java/com/databricks/jdbc/api/impl/DatabricksConnection.java Update autocommit state parsing; change rollback behavior to throw in auto-commit mode.
src/test/java/com/databricks/jdbc/api/impl/DatabricksConnectionTest.java Update rollback tests; add unit tests for numeric autocommit server responses.
src/test/java/com/databricks/jdbc/integration/e2e/TransactionTests.java Update E2E rollback-without-transaction expectation to throwing behavior.
src/test/java/com/databricks/jdbc/integration/e2e/ExplicitTransactionStatementTests.java Update E2E assertion to accept numeric autocommit query results.
Comments suppressed due to low confidence (1)

src/main/java/com/databricks/jdbc/api/impl/DatabricksConnection.java:267

  • fetchAutoCommitStateFromServer() only closes the ResultSet in the rs.next() success path. If the query returns no rows (or throws after executeQuery succeeds), the ResultSet is never closed, which can leak server resources. Use try-with-resources for the ResultSet (and ideally the Statement) or ensure rs.close() happens in a finally.
      ResultSet rs = statement.executeQuery("SET AUTOCOMMIT");

      if (rs.next()) {
        // The result may contain "true"/"false" or "1"/"0" depending on the server
        String value = rs.getString(1); // Column 1: value

        LOGGER.debug(
            "Fetched autoCommit state from server: value={}. Updating session cache.", value);

        boolean autoCommitState = "true".equalsIgnoreCase(value) || "1".equals(value);

        // Update the session cache with the server value
        session.setAutoCommit(autoCommitState);

        rs.close();
        return autoCommitState;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 354 to 356
SQLException exception =
assertThrows(
SQLException.class,
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says rollback() should throw DatabricksTransactionException in auto-commit mode, but this test only asserts SQLException. Using the specific exception type here (like the COMMIT test does) would better lock in the intended contract and catch regressions where rollback starts throwing a different SQLException subclass.

Suggested change
SQLException exception =
assertThrows(
SQLException.class,
DatabricksTransactionException exception =
assertThrows(
DatabricksTransactionException.class,

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we update the javadoc now? In fact we should rely on JDBC spec javadoc.

"Fetched autoCommit state from server: value={}. Updating session cache.", value);

boolean autoCommitState = "true".equalsIgnoreCase(value);
boolean autoCommitState = "true".equalsIgnoreCase(value) || "1".equals(value);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means that even values like "yes" or "enabled" would result in false. I think, can we explicitly throw error in those cases instead of blindly treating those as false? Not blocker for this PR though

Copy link
Collaborator

@gopalldb gopalldb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG, some minor comments, at least fix javadoc comment before merge

vikrantpuppala added a commit to vikrantpuppala/databricks-jdbc that referenced this pull request Feb 13, 2026
- Update rollback() javadoc to document it throws in auto-commit mode
- Assert DatabricksTransactionException in unit and E2E tests
- Validate unexpected autocommit server values in fetchAutoCommitStateFromServer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…autocommit responses

- rollback() now throws DatabricksTransactionException when called in
  auto-commit mode (no active transaction), matching Simba driver behavior
- fetchAutoCommitStateFromServer() now accepts "1"/"0" in addition to
  "true"/"false" from SET AUTOCOMMIT query responses
- Updated E2E tests: rollback without transaction expects exception,
  SET AUTOCOMMIT value check accepts both string and numeric formats
- Added unit tests for new rollback guard and numeric autocommit parsing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
vikrantpuppala added a commit to vikrantpuppala/databricks-jdbc that referenced this pull request Feb 13, 2026
- Update rollback() javadoc to document it throws in auto-commit mode
- Assert DatabricksTransactionException in unit and E2E tests
- Validate unexpected autocommit server values in fetchAutoCommitStateFromServer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala vikrantpuppala force-pushed the vpuppala/transaction-rollback-autocommit-fix branch from 3477fbf to e459651 Compare February 13, 2026 16:23
- Update rollback() javadoc to document it throws in auto-commit mode
- Assert DatabricksTransactionException in unit and E2E tests
- Validate unexpected autocommit server values in fetchAutoCommitStateFromServer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
@vikrantpuppala vikrantpuppala force-pushed the vpuppala/transaction-rollback-autocommit-fix branch from e459651 to 3e35425 Compare February 13, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments