Skip to content

refactor(jdbc): extract generated-key state - #281

Merged
magnusp merged 1 commit into
mainfrom
refactor/generated-keys
Oct 31, 2026
Merged

magnusp merged 1 commit into
mainfrom
refactor/generated-keys

Conversation

@magnusp

@magnusp magnusp commented Oct 31, 2026

Copy link
Copy Markdown
Owner

What changed

Moved the generated-key state out of LibsqlStatement into a package-private GeneratedKeys. The statement keeps its three entry points (updateGeneratedKeys, clearGeneratedKeys, and getGeneratedKeys) and its stateLock. GeneratedKeys owns the insert detection, the single and batch result shaping, and the close-on-clear rule.

The batch call now runs directly under the stateLock that executeBatch already holds, so the private wrapper disappeared.

Behavior preserved

The generated-key column labels stay last_insert_rowid() and 1. Single and batch keys keep their order and values. A non-insert step contributes no key. Every exception type and message is unchanged. The public and protected statement methods are unchanged. The public API is unchanged.

Pins added

Test Behavior pinned
emptyGeneratedKeysUseTheXerialColumnName A statement without keys reports the empty result with column name 1.
mixedBatchReportsOnlyTheInsertStepKeys A batch with an insert then an update reports only the insert rowid.

Mutant kills

Probe Result
Rename the empty-key column from 1 to 0. 1 pin failed. Reverted.
Accept every batch rowid instead of only insert steps. 1 pin failed. Reverted.

Diff (file statistics)

 GeneratedKeys.java               | 114 +++++++++++++++++++++
 LibsqlStatement.java             |  99 +-----------------
 LibsqlGeneratedKeysTest.java     |  28 +++++
 3 files changed, 147 insertions(+), 94 deletions(-)

Line counts

File Before After
LibsqlStatement.java 703 614
GeneratedKeys.java 0 114

Probe

The first probe renamed the empty generated-key column, and the column-name pin failed. The second probe removed the insert-only filter from the batch path, and the mixed-batch pin failed. Both probes were reverted before the final lane run.

Lanes

Command Result
mise exec -- ./mvnw -pl libsql-jdbc -am test Pass, 1559 tests (baseline 1557 plus 2 pins).
mise exec -- ./mvnw spotless:check Pass.
mise exec -- ./mvnw -pl libsql-conformance -am verify Pass, 271 tests, 6 skipped.
DOCKER_CONFIG=... mise exec -- ./mvnw -pl libsql-itests -am verify Pass, 43 driver ITs and 192 itests. The first attempt hit a RootlessKit port collision for Toxiproxy; the retry passed.
  • My code follows the code style of this project (./mvnw spotless:check).
  • I have added tests that prove my fix is effective or that my feature works.
  • All new and existing tests passed (./mvnw clean verify).
  • I have updated documentation where appropriate.

Closes #280

@magnusp
magnusp force-pushed the refactor/generated-keys branch from 802e406 to cbadecd Compare October 31, 2026 10:47
@magnusp
magnusp merged commit c9e1097 into main Oct 31, 2026
6 checks passed
@magnusp
magnusp deleted the refactor/generated-keys branch October 31, 2026 10:55
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.

Extract generated-key state from LibsqlStatement

1 participant