Enum Class SqlConfig.TransactionMode

java.lang.Object
java.lang.Enum<SqlConfig.TransactionMode>
org.springframework.test.context.jdbc.SqlConfig.TransactionMode
All Implemented Interfaces:
Serializable, Comparable<SqlConfig.TransactionMode>, Constable
Enclosing class:
SqlConfig

public static enum SqlConfig.TransactionMode extends Enum<SqlConfig.TransactionMode>
Enumeration of modes that dictate whether SQL scripts should be executed within a transaction and what the transaction propagation behavior should be.
  • Enum Constant Details

    • DEFAULT

      public static final SqlConfig.TransactionMode DEFAULT
      Indicates that the default transaction mode should be used.

      The meaning of default depends on the context in which @SqlConfig is declared:

      • If @SqlConfig is declared only locally, the default transaction mode is INFERRED.
      • If @SqlConfig is declared globally, the default transaction mode is INFERRED.
      • If @SqlConfig is declared globally and locally, the default transaction mode for the local declaration is inherited from the global declaration.
    • INFERRED

      public static final SqlConfig.TransactionMode INFERRED
      Indicates that the transaction mode to use when executing SQL scripts should be inferred using the rules listed below. In the context of these rules, the term "available" means that the bean for the data source or transaction manager is either explicitly specified via a corresponding annotation attribute in @SqlConfig or discoverable via conventions. See TestContextTransactionUtils for details on the conventions used to discover such beans in the ApplicationContext.

      Inference Rules

      1. If neither a transaction manager nor a data source is available, an exception will be thrown.
      2. If a transaction manager is not available but a data source is available, SQL scripts will be executed directly against the data source without a transaction.
      3. If a transaction manager is available:
        • If a data source is not available, an attempt will be made to retrieve it from the transaction manager by using reflection to invoke a public method named getDataSource() on the transaction manager. If the attempt fails, an exception will be thrown.
        • Using the resolved transaction manager and data source, SQL scripts will be executed within an existing transaction if present; otherwise, scripts will be executed in a new transaction that will be immediately committed. An existing transaction will typically be managed by the TransactionalTestExecutionListener.
      See Also:
    • ISOLATED

      public static final SqlConfig.TransactionMode ISOLATED
      Indicates that SQL scripts should always be executed in a new, isolated transaction that will be immediately committed.

      In contrast to INFERRED, this mode requires the presence of a transaction manager and a data source.

  • Method Details

    • values

      public static SqlConfig.TransactionMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SqlConfig.TransactionMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null