Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
spring-projects-issues opened this issue Jun 25, 2014 · 1 comment
Closed
4 tasks done

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

spring-projects-issues opened this issue Jun 25, 2014 · 1 comment
Assignees
Labels
in: test Issues in the test module type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jun 25, 2014

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 17, 2014

Sam Brannen commented

Completed as described in the comments for GitHub commit 2e75adb:

Improve transaction management for @Sql scripts

Prior to this commit, the support for SQL script execution via @Sql
provided 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.

This commit improves the transaction management support for @Sql so
that SQL scripts can be executed without a transaction if a transaction
manger is not present in the ApplicationContext. The updated algorithm
now supports the following use cases.

  • If a transaction manager and data source are both present (i.e.,
    explicitly specified via the transactionManager and dataSource
    attributes of @SqlConfig or implicitly discovered in the
    ApplicationContext based on conventions), both will be used.

  • If a transaction manager is not explicitly specified and not
    implicitly discovered based on conventions, SQL scripts will be
    executed without a transaction but requiring the presence of a data
    source. If a data source is not present, an exception will be thrown.

  • If a data source is not explicitly specified and not implicitly
    discovered based on conventions, an attempt will be made to retrieve
    it by using reflection to invoke a public method named
    getDataSource() on the transaction manager. If this attempt fails,
    an exception will be thrown.

  • If a data source can be retrieved from the resolved transaction
    manager using reflection, an exception will be thrown if the
    resolved data source is not the data source associated with the
    resolved transaction manager. This helps to avoid possibly
    unintended configuration errors.

  • If @SqlConfig.transactionMode is set to ISOLATED, an exception will
    be thrown if a transaction manager is not present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants