Skip to content

Improve transaction management for @Sql [SPR-11911] #16530

@spring-projects-issues

Description

@spring-projects-issues

Sam Brannen opened SPR-11911 and commented

Status Quo

#12311 introduced support for executing SQL scripts declaratively in the TestContext framework via @Sql. This support provides an algorithm for looking up a required PlatformTransactionManager to use to drive transactions. However, a transaction manager is not actually required for all testing scenarios. We therefore need to revise the transaction management support for @Sql so that SQL scripts will be executed without a transaction if a transaction manger is not present in the ApplicationContext.


Deliverables

Revise transaction management in SqlScriptsTestExecutionListener using the following algorithm.

  1. if a transaction manager and data source are both specified via @SqlConfig, retain the current behavior.
  2. if a transaction manager is not specified, execute the SQL scripts directly without a transaction, requiring the presence of a data source.
  3. if a data source is not explicitly specified, infer it via the getResourceFactory() method provided by the ResourceTransactionManager interface, which the transaction manager may potentially implement.
    • otherwise, throw an IllegalStateException.
  4. if @SqlConfig.transactionMode is set to ISOLATED, throw an exception if a transaction manager is not specified or not present in the ApplicationContext.

Affects: 4.1 RC1

Issue Links:

Referenced from: commits 2e75adb

Metadata

Metadata

Assignees

Labels

in: testIssues in the test moduletype: taskA general task

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions