Skip to content

refactor(jdbc): collapse duplicated connection send paths - #227

Merged
magnusp merged 1 commit into
mainfrom
refactor/i214-connection-send-paths
Oct 24, 2026
Merged

magnusp merged 1 commit into
mainfrom
refactor/i214-connection-send-paths

Conversation

@magnusp

@magnusp magnusp commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Fixes #214

Collapses the five duplicated send/error-mapping blocks in LibsqlConnection into one send core plus two named wrappers, and removes the second update-count loop. The autoCommit dispatch stays in executeStatement and executeBatchResults.

What changed

  • Added sendOnStream(Stmt) and sendBatchOnStream(Batch), both delegating to one generic sending(Supplier) that owns the LibsqlException → SQLException mapping.
  • executeBatch(List) is now one line over steppedUpdateCounts(executeBatchResults(...)).
  • Deleted executeTransactionStatement; its four savepoint call sites now call sendOnStream.
  • beginTransaction, endTransaction, and the one-shot branches route through the same helpers.

Preserved

  • Failed BEGIN closes the fresh stream and leaves the begin pending.
  • Failed COMMIT/ROLLBACK leaves the stream open.
  • Empty batch returns an empty list and sends no request.
  • stateLock still held by every caller.
  • No message, request-order, or behavior change; no test files touched; pom.xml untouched.

Diff

 libsql-jdbc/src/main/java/com/github/magnusp/libsql/jdbc/LibsqlConnection.java | 111 +++++++++------------
 1 file changed, 48 insertions(+), 63 deletions(-)

LibsqlConnection.java: 763 → 748 lines (under the 750-line budget).

Probe

Removed the closeStreamQuietly() on a failed BEGIN:

[ERROR] Tests run: 36, Failures: 1, Errors: 1, Skipped: 0
[ERROR]   LibsqlConnectionTest.aFailedBeginLeavesTheBeginPendingAndNoStatementRuns:200
Expected size: 2 but was: 1
[ERROR]   LibsqlConnectionTest.aFailedBeginPinsTheLazyBeginStateUntilTheRetrySucceeds:234

Reverted; LibsqlConnectionTest green again.

Verification

Lane Result
./mvnw -pl libsql-jdbc -am test 396 JDBC tests (431 with codec), 0 failures
./mvnw spotless:check clean
./mvnw -pl libsql-conformance -am verify 272 tests, 0 failures, 7 skipped
DOCKER_CONFIG=... ./mvnw -pl libsql-itests -am verify 43 tests, 0 failures

@magnusp
magnusp merged commit 707deea into main Oct 24, 2026
6 checks passed
@magnusp
magnusp deleted the refactor/i214-connection-send-paths branch October 24, 2026 17:41
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.

Collapse the duplicated send and update-count paths in LibsqlConnection

1 participant