Repository navigation
refactor(jdbc): move parameter metadata behind a view - #234
Merged
Merged
Conversation
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 #212
What changed
LibsqlPreparedStatementnow holds one cachedParameterMetaDataView(package-private, new file) that owns the parameter count and the closed and index checks.getParameterMetaData()returns that view. The statement keepsimplements ParameterMetaDataand delegates the nine interface methods, soinstanceof ParameterMetaDatastill holds for a prepared statement. The parameter-metadata paragraph moved from the statement's javadoc to the view.Behavior preserved
getParameterMetaData()still throws after close, and metadata calls on a view taken before close still throw after close, because the view checks the owning statement.Parameter index out of range: N.SqlTokenizer.placeholderCount.ParameterMetaDataextendsWrapper, so the view delegatesunwrap/isWrapperForto the statement; unwrapping still reaches the statement.pom.xmluntouched.Pins added
A follow-up commit,
test(jdbc): pin parameter metadata invariants, adds seven characterization tests so the invariants above are enforced rather than asserted in prose. The class goes from 22 to 29 tests; the additions are pure insertions, with no existing assertion edited.getParameterMetaDataReturnsAViewWithThePlaceholderCountgetParameterCount()equals the placeholder count (2 for two?).getParameterMetaDataAfterCloseThrowsgetParameterMetaData()afterclose()throwsSQLException: Statement is closed.parameterMetadataViewTakenBeforeCloseStillThrowsAfterCloseclose()throws from bothgetParameterCount()andgetParameterType(1)afterwards.parameterMetadataRejectsAnOutOfRangeIndex0throwsSQLExceptionwith the exact messageParameter index out of range: 0.preparedStatementRemainsAParameterMetaDatastatement instanceof ParameterMetaDataholds.getParameterMetaDataReturnsTheSameCachedViewparameterMetadataUnwrapReachesTheStatementisWrapperFor(ParameterMetaData.class)istrueandunwrap(ParameterMetaData.class)returns the statement itself, because the view delegates to the statement's wrapper surface.Mutant kills
Each mutation was made as a scratch edit, the test class was run, and the edit was reverted to a clean tree before committing.
Parameter index out of range [N]parameterMetadataRejectsAnOutOfRangeIndexfailed: expectedParameter index out of range: 0, gotParameter index out of range [0].getParameterMetaData()and from the view'sgetParameterCount()/checkParameterIndex()getParameterMetaDataAfterCloseThrowsandparameterMetadataViewTakenBeforeCloseStillThrowsAfterCloseboth failed.Diff
Line counts
LibsqlPreparedStatement.java: 614 -> 559 lines (limit: under 560).ParameterMetaDataView.java: 98 lines (new).Probe
Inverted the closed check in
ParameterMetaDataView.getParameterCount()so it threw while the statement was open.LibsqlPreparedStatementTest.parameterCountComesFromThePlaceholdersfailed atLibsqlPreparedStatementTest.java:265withjava.sql.SQLException: Statement is closed. Reverted; the same class then ran 22/22 green.Lanes
./mvnw -pl libsql-jdbc -am test./mvnw spotless:apply./mvnw spotless:check./mvnw -pl libsql-conformance -am verifyDOCKER_CONFIG="$PWD/libsql-conformance/src/test/docker-config" ./mvnw -pl libsql-itests -am verify