Skip to content

refactor(jdbc): extract ForeignKeyMetadata - #232

Merged
magnusp merged 1 commit into
mainfrom
refactor/i209-foreign-key-metadata
Oct 24, 2026
Merged

magnusp merged 1 commit into
mainfrom
refactor/i209-foreign-key-metadata

Conversation

@magnusp

@magnusp magnusp commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

Extracts foreign key shaping from LibsqlDatabaseMetaData into package-private ForeignKeyMetadata:

  • raw pragma row record (PragmaRow) with per-direction factories
  • fromImported / fromExported
  • JDBC row record (JdbcRow)
  • per-direction sort comparators (IMPORTED_ORDER, EXPORTED_ORDER)
  • key-name, key-rule, and ordering helpers

The two pragma SQL strings remain in MetadataSql.

Preservation

  • imported/exported index asymmetries, including the PK_FIRST_COLUMN fallback
  • KEY_SEQ remains the pragma sequence plus one
  • DEFERRABILITY remains importedKeyInitiallyDeferred
  • nameOrEmpty for FK/PK names; getPrimaryKeys keeps the primary key name null
  • primaryKeyName still matches only CONSTRAINT <name> PRIMARY KEY
  • foreignKeyName reverse index rule unchanged
  • exported primary key names stay blank unless the parent column set contains the column
  • per-direction sort keys unchanged
  • no SQL, value, order, message, test, or pom.xml change

Diff

ForeignKeyMetadata.java      | 291 ++++++++++++++++++++
LibsqlDatabaseMetaData.java  | 215 +--------------
2 files changed, 296 insertions(+), 210 deletions(-)

LibsqlDatabaseMetaData.java: 846 -> 641 lines.

Probe

Changed KEY_SEQ to the raw pragma value ((int) pragma.seq() instead of (int) pragma.seq() + 1) in both directions:

LibsqlDatabaseMetaDataTest.getImportedKeysMapsForeignKeyRowsAndNames:435 expected: 1 but was: 0
LibsqlDatabaseMetaDataTest.getExportedKeysMapsForeignKeyRowsAndNames:457 expected: 1 but was: 0
Tests run: 54, Failures: 2

Reverted; ForeignKeyMetadata.java hash matched the pre-probe value.

Lanes

Lane Command Result
Unit ./mvnw -pl libsql-jdbc -am test 398/398, 0 failures (codec 35/35)
Spotless ./mvnw spotless:check pass
Conformance ./mvnw -pl libsql-conformance -am verify 272 run, 0 failures, 7 skipped, BUILD SUCCESS

Fixes #209

Move the imported and exported foreign key mappers, the key-name helpers,
and the per-direction row ordering into a package-private ForeignKeyMetadata
class. The two pragma SQL strings stay in MetadataSql.
@magnusp
magnusp merged commit 8295875 into main Oct 24, 2026
6 checks passed
@magnusp
magnusp deleted the refactor/i209-foreign-key-metadata branch October 24, 2026 18:11
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 ForeignKeyMetadata from LibsqlDatabaseMetaData

1 participant