Skip to content

Fix #20: implement Connection.isValid() and track close state#51

Open
IceboxDev wants to merge 1 commit intodbeaver:develfrom
IceboxDev:fix/issue-20-connection-isvalid
Open

Fix #20: implement Connection.isValid() and track close state#51
IceboxDev wants to merge 1 commit intodbeaver:develfrom
IceboxDev:fix/issue-20-connection-isvalid

Conversation

@IceboxDev
Copy link
Copy Markdown

Fixes #20.

LibSqlConnection previously inherited the no-op isValid() from AbstractJdbcConnection, which throws SQLFeatureNotSupportedException. This breaks HikariCP / Spring Boot pool validation and causes JetBrains DataGrip / PyCharm to hang for ~50 s after every query while waiting for the unanswered validation call.

Three coupled changes, all in LibSqlConnection:

  1. closed state field. isClosed() previously returned hardcoded false and close() didn't track state. A correct isValid() must short-circuit when the connection is closed, so the close flag has to come along.
  2. isValid(int timeout) override. Runs SELECT 1 via the same LibSqlUtils.executeQuery path the constructor already uses to verify the connection. Wrapped in a CompletableFuture so the spec-mandated timeout actually applies (get(timeout, SECONDS) for timeout > 0, blocking get() for timeout == 0). Returns false (does not throw) on any HTTP / SQL failure, per the JDBC contract that isValid() is a predicate.
  3. timeout < 0 ? SQLException per the JDBC spec.

Verified

mvn -f aggregate/pom.xml package and ... test both pass.

Manual integration run against Turso:

  • isValid(5) ? true
  • isValid(0) ? true
  • isValid(-1) ? throws SQLException("Invalid timeout value: -1")
  • isClosed() ? false before close, true after
  • isValid(5) after close ? false

LibSqlDriverTest.main() was extended with two of those assertions.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 9 complexity · 0 duplication

Metric Results
Complexity 9
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@IceboxDev
Copy link
Copy Markdown
Author

Related (independent) fixes opened in #52 (auth header on /version), #53 (fallback when /version is unavailable), #54 (getUpdateCount -1 for SELECT). All four together unblock JetBrains IDEs against Turso.

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.

libsql/turso with spring jpa ending up with : "Failed to execute isValid() for connection, configure connection test query (null)"

1 participant