Skip to content

fix(dataset): Add DTD-declared zero-row tables missing from flat XML body - #916

Merged
jeffjensen merged 1 commit into
mainfrom
496-flatxmlproducer-dtd-zero-row-tables
Aug 8, 2026
Merged

jeffjensen merged 1 commit into
mainfrom
496-flatxmlproducer-dtd-zero-row-tables

Conversation

@jeffjensen

@jeffjensen jeffjensen commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • FlatXmlProducer only registered a table inside startElement()'s new-table handling, so a table declared in the DTD but never used by a row element (a genuinely empty fixture table) was silently absent from the produced dataset.
  • CLEAN_INSERT/DELETE_ALL would then skip such a table entirely, risking a foreign-key violation against data a prior test left behind.
  • Add FlatXmlProducer#addMissingDtdTables(), called from endElement() right before endDataSet(): it cross-references every table name reported by the available metadata source (parsed DTD, or an explicitly-supplied metadata IDataSet) against the tables actually encountered in the XML body, and reports any still missing as an empty table via the consumer, using that source's column metadata.
  • No-op when no DTD/metadata dataset is available, so behavior for plain flat XML is unchanged.

Test plan

  • Added FlatXmlProducerTest#testProduce_withDtdTablesAbsentFromXmlBody_addsEmptyTablesInDtdOrder (DTD parsed via EntityResolver)
  • Added FlatXmlProducerTest#testProduceMetaDataSet_withTableAbsentFromXmlBody_addsEmptyTableFromMetaDataSet (explicit metaDataSet constructor)
  • Audited every existing DTD/XML test resource pair in the repo for one where the DTD declares a table its XML body never uses, to check for regressions; confirmed the one hit (sortedTableTest.xml) is unaffected
  • Full unit suite: 2027 tests, 0 failures
  • hsqldb-2-7 integration suite: 356 tests, 0 failures

Fixes #496

🤖 Generated with Claude Code

https://claude.ai/code/session_012gmZhDioasFdPtnqxs1ZuP

Summary by Sourcery

Ensure flat XML datasets include DTD-declared tables that have no rows so downstream operations see the full table set.

Bug Fixes:

  • Prevent CLEAN_INSERT/DELETE_ALL from skipping tables declared in DTD or metadata datasets when those tables have zero rows in the XML body.

Documentation:

Tests:

  • Add tests verifying FlatXmlProducer reports empty tables defined only in a metadata IDataSet.
  • Add tests verifying FlatXmlProducer reports empty tables defined in a DTD, preserving DTD declaration order.

Summary by CodeRabbit

  • Bug Fixes
    • Flat XML datasets now include empty tables declared in a DTD or supplied metadata, even when the XML contains no rows for those tables.
    • Preserves table metadata and declaration order while reporting zero rows.
    • Existing behavior remains unchanged when no table metadata is available.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

FlatXmlProducer now ensures that tables declared in DTD or an explicit metadata IDataSet but never referenced by any row element are still emitted as empty tables in the produced IDataSet, preventing CLEAN_INSERT/DELETE_ALL from skipping genuinely empty fixture tables; this is implemented by a new addMissingDtdTables() hook invoked at dataset end and covered by new unit tests plus a changelog entry.

Sequence diagram for FlatXmlProducer endElement with addMissingDtdTables

sequenceDiagram
    participant SaxParser
    participant FlatXmlProducer
    participant metaDataSet as IDataSet
    participant tableMap as OrderedTableNameMap
    participant consumer as IDataSetConsumer

    SaxParser->>FlatXmlProducer: endElement(uri, localName, qName)
    alt [end of dataset]
        FlatXmlProducer->>FlatXmlProducer: addMissingDtdTables()
        FlatXmlProducer->>metaDataSet: getTableNames()
        loop dtdTableNames
            FlatXmlProducer->>tableMap: containsTable(dtdTableName)
            alt [table missing]
                FlatXmlProducer->>metaDataSet: getTableMetaData(dtdTableName)
                FlatXmlProducer->>tableMap: add(tableName, metaData)
                FlatXmlProducer->>consumer: startTable(metaData)
                FlatXmlProducer->>consumer: endTable()
            end
        end
        FlatXmlProducer->>consumer: endDataSet()
    end
Loading

File-Level Changes

Change Details Files
Emit empty tables for DTD/metadata-declared tables that never appear in the flat XML body.
  • Introduce private addMissingDtdTables() that iterates over _metaDataSet.getTableNames(), checks _orderedTableNameMap for each, and for missing ones adds metadata and calls startTable()/endTable() to emit an empty table.
  • Guard addMissingDtdTables() with a null check on _metaDataSet so behavior is unchanged when no DTD/metadata dataset is provided.
  • Invoke addMissingDtdTables() from endElement() when finishing the root dataset element, just before calling _consumer.endDataSet().
src/main/java/org/dbunit/dataset/xml/FlatXmlProducer.java
Extend FlatXmlProducer tests to cover missing-table emission from both DTD and explicit metadata IDataSet.
  • Add testProduceMetaDataSet_withTableAbsentFromXmlBody_addsEmptyTableFromMetaDataSet() to verify that tables present only in a supplied DefaultDataSet are still emitted as empty tables in metadata order.
  • Add testProduce_withDtdTablesAbsentFromXmlBody_addsEmptyTablesInDtdOrder() to verify that DTD-declared tables never used in XML are emitted as empty tables, using DTD column metadata and preserving DTD declaration order.
  • Use MockDataSetConsumer expectations (startDataSet, startTable/row/endTable, addExpectedEmptyTable, endDataSet) to assert the exact table sequence and schemas including the missing tables.
src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java
Document the bug fix in the project changelog.
  • Add a entry describing the previous omission of zero-row DTD tables from produced IDataSet and the new cross-referencing behavior using DTD or metadata IDataSet.
  • Record that the change is a no-op when no DTD or metadata dataset is available.
src/changes/changes.xml

Assessment against linked issues

Issue Objective Addressed Explanation
#496 Ensure that when loading a flat XML dataset with an associated DTD/metadata, the produced IDataSet includes tables declared in the DTD even if they have no rows in the XML body, so cleaning operations (CLEAN_INSERT/DELETE_ALL) use the full DTD table list rather than only tables present in the XML.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jeffjensen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ba0282e7-0e72-4617-9822-197c661baf3c

📥 Commits

Reviewing files that changed from the base of the PR and between bf9de81 and 05f1b50.

📒 Files selected for processing (1)
  • src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java
📝 Walkthrough

Walkthrough

FlatXmlProducer now emits empty tables declared in a DTD or supplied metadata dataset. Tests verify zero rows, metadata, column definitions, and DTD declaration order.

Changes

Empty declared tables

Layer / File(s) Summary
Add missing tables
src/main/java/org/dbunit/dataset/xml/FlatXmlProducer.java
Dataset finalization scans DTD or metadata tables and emits missing tables with their metadata and zero rows.
Validate empty table output
src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java, src/changes/changes.xml
Tests cover metadata-declared and DTD-declared tables absent from the XML body. The changelog records the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • dbunit/dbunit-extension#880: Both PRs modify DTD handling in FlatXmlProducer, but this PR adds missing DTD-declared tables while that PR changes empty-dataset DTD generation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the fix for missing zero-row tables declared in a DTD.
Linked Issues check ✅ Passed The change adds DTD-declared tables as empty tables, addressing issue #496 and preventing cleanup failures caused by omitted XML tables.
Out of Scope Changes check ✅ Passed The changelog, implementation, and tests directly support issue #496 and the stated metadata-table handling objective.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 496-flatxmlproducer-dtd-zero-row-tables

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java`:
- Around line 169-175: Update the FlatXmlProducerTest cases at
src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java:169-175 and
243-255 to use distinct column metadata for each table: make MISSING_TABLE
differ from PRESENT_TABLE, and declare/expect different columns for
PRESENT_TABLE, MISSING_TABLE_A, and MISSING_TABLE_B. Preserve the existing
assertions while ensuring the unit tests detect columns being incorrectly reused
between tables.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b295539a-e566-4d6d-b68b-81f5b326f1a8

📥 Commits

Reviewing files that changed from the base of the PR and between 560b7ac and bf9de81.

📒 Files selected for processing (3)
  • src/changes/changes.xml
  • src/main/java/org/dbunit/dataset/xml/FlatXmlProducer.java
  • src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java

Comment thread src/test/java/org/dbunit/dataset/xml/FlatXmlProducerTest.java Outdated
…body

FlatXmlProducer only registered a table inside startElement()'s
new-table handling, so a table declared in the DTD but never used by a
row element (a genuinely empty fixture table) was silently absent from
the produced dataset. CLEAN_INSERT/DELETE_ALL would then skip it,
risking a foreign-key violation against data a prior test left behind.

* Add FlatXmlProducer#addMissingDtdTables(), called from endElement()
  right before endDataSet(); it cross-references every table name
  reported by the available metadata source (parsed DTD, or an
  explicitly-supplied metadata IDataSet) against the tables actually
  encountered in the XML body, and reports any still missing as an
  empty table via the consumer, using that source's column metadata.
* No-op when no DTD/metadata dataset is available, so behavior for
  plain flat XML is unchanged.

Refs: 496
@jeffjensen
jeffjensen force-pushed the 496-flatxmlproducer-dtd-zero-row-tables branch from bf9de81 to 05f1b50 Compare August 7, 2026 21:36
@jeffjensen
jeffjensen merged commit efe745d into main Aug 8, 2026
38 of 40 checks passed
@jeffjensen
jeffjensen deleted the 496-flatxmlproducer-dtd-zero-row-tables branch August 8, 2026 03:16
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.

List of table not taken from DTD

1 participant