Repository navigation
refactor(jdbc): split URL parsing into named steps - #229
Merged
Merged
Conversation
Fixes #213 `LibsqlUrlParser.parse` was a 98-line method that stripped the prefix, built the URI, resolved credentials, overrode TLS, validated the encoding, resolved timeouts, and rebuilt the endpoint. The precedence rules were invisible. Extract `normalizeUri`, `resolveAuthToken`, `resolveScheme`, `resolveEncoding`, `resolveDuration`, and `buildEndpoint`, leaving `parse` as a 16-line orchestrator. No behavior change: query parameters still beat `Properties`, `jwt` is still an alias for `authToken`, `password` is still the last resort, `tls`/`ssl` only upgrade and still run before the encoding check, unknown encodings still throw `SQLException`, and a null path is still empty with the port kept only when positive. `LibsqlDriver.connect` is untouched; the client-construction seam there is eight lines of codec selection, not the clean three-line seam the issue asked for.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #213
What
LibsqlUrlParser.parsewas a 98-line method doing prefix stripping, URIconstruction, credential resolution, TLS override, encoding validation,
timeout resolution, and endpoint rebuilding. The precedence rules were
invisible.
It is now a 16-line orchestrator (12 statements) over six named steps:
normalizeUrijdbc:libsql:/jdbc:sqlite:, default the scheme, build theURIresolveAuthTokenauthToken→ queryjwt→Properties.authToken→Properties.passwordresolveSchemetls/sslupgrade only,http→https,ws→wssresolveEncodingjson/protobuf/proto, ws-only checkresolveDurationPropertiesbeats default, for both timeoutsbuildEndpointLibsqlDriver.connectis untouched. The optional client-construction seamthere is eight lines of codec selection, not the clean three-line seam the
issue asked for.
Behavior preserved
No precedence rule, message, or exception type changed. In particular:
Properties;jwtaliasesauthToken;passwordis last resorttls/sslonly upgrade, and the upgrade still runs before the encoding check, sows+ TLS + protobuf stays legalSQLExceptionwith the same messagesocketTimeoutguard from socketTimeout alone in a JDBC URL throws NumberFormatException #196 is unchanged (queryconnectTimeoutonly)Tests and
pom.xmlare untouched.Probe (run, failed, reverted)
Reordered the steps so the TLS upgrade ran after the encoding check and the
endpoint was rebuilt from the pre-upgrade scheme:
Command:
./mvnw -pl libsql-jdbc -am -Dtest=LibsqlUrlParserTest -Dsurefire.failIfNoSpecifiedTests=false test. File restored, re-run green.Line counts
parse: 98 lines onmain→ 16 lines (signature + 12 statements + brace)LibsqlUrlParser.java: 142 → 146 lines, 63 insertions / 59 deletionsLanes
./mvnw test— BUILD SUCCESS;libsql-jdbc398 tests,libsql-hrana-codec35, 0 failures, 0 errors../mvnw spotless:check— BUILD SUCCESS../mvnw -pl libsql-conformance -am verify— BUILD SUCCESS; 272 tests, 0 failures, 0 errors, 7 skipped (pinnedsqldimage).