Repository navigation
Detect an unbatched statement executed after a JDBC batch - #290
Merged
jeanbisutti merged 1 commit intoOct 19, 2026
Merged
jeanbisutti merged 1 commit into
jeanbisutti merged 1 commit into
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.
Problem
@ExpectJdbcBatching(batchSize = N)did not report an INSERT, UPDATE or DELETE executed without JDBC batching after a batch. The same statements executed in the opposite order were reported.For example, with
@ExpectJdbcBatching(batchSize = 30), a batch of 30 inserts followed by anexecuteUpdate()insert passed. The unbatched insert executed first failed withExpected batch size <30> but is <0>.SqlStatementBatchRecorderrecords the different batch sizes and stops after the first unbatched execution, whose batch size is 0. With a batch executed first, the recorded sizes are[30, 0].SqlStatementBatchVerifiernever checked the last recorded size, to allow a last batch containing fewer statements, so the 0 was ignored.Changes
1. Check a last batch size of 0 (
SqlStatementBatchVerifier)The verifier now also checks the last recorded batch size when it is 0, so
[30, 0]fails withExpected batch size <30> but is <0>.A smaller last batch is still allowed:[30, 10]passes.2. Ignore empty batches (
SqlStatementBatchRecorder)Change 1 alone would have failed tests in which every statement is batched.
datasource-proxy gives a batch size of 0 in two cases:
isBatch()getBatchSize()executeUpdate(),execute()...false0executeBatch()on aPreparedStatementor aCallableStatementwith noaddBatch()since the last executiontrue0The recorder stored both as a 0 batch size. On a plain
Statement, an emptyexecuteBatch()was already not recorded.Before this PR, an empty batch at the end was harmless, because the last size was not checked. With change 1, a common JDBC pattern would fail: