Fix rollback in auto-commit mode and handle numeric autocommit responses#1206
Fix rollback in auto-commit mode and handle numeric autocommit responses#1206vikrantpuppala wants to merge 2 commits intodatabricks:mainfrom
Conversation
There was a problem hiding this comment.
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 theResultSetin thers.next()success path. If the query returns no rows (or throws afterexecuteQuerysucceeds), theResultSetis never closed, which can leak server resources. Use try-with-resources for theResultSet(and ideally theStatement) or ensurers.close()happens in afinally.
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.
| SQLException exception = | ||
| assertThrows( | ||
| SQLException.class, |
There was a problem hiding this comment.
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.
| SQLException exception = | |
| assertThrows( | |
| SQLException.class, | |
| DatabricksTransactionException exception = | |
| assertThrows( | |
| DatabricksTransactionException.class, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
gopalldb
left a comment
There was a problem hiding this comment.
LG, some minor comments, at least fix javadoc comment before merge
- 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>
- 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>
3477fbf to
e459651
Compare
- 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>
e459651 to
3e35425
Compare
Summary
DatabricksTransactionExceptionwhen called while the connection is in auto-commit mode (no active transaction), aligning behavior with the JDBC spec"1"/"0"and"true"/"false"responses from theSET AUTOCOMMITquery, since different server implementations return different formatsContext
connection.rollback()in auto-commit mode should throw an exception, not silently succeedSET AUTOCOMMITquery returns"1"/"0"rather than"true"/"false"depending on the serverTest plan
DatabricksConnectionTest(42/42 pass)TransactionTestsandExplicitTransactionStatementTestsagainst staging warehouse🤖 Generated with Claude Code