枚举 SqlConfig.TransactionMode
- java.lang.Object
- java.lang.Enum<SqlConfig.TransactionMode>
- org.springframework.test.context.jdbc.SqlConfig.TransactionMode
- 所有已实现的接口:
Serializable
,Comparable<SqlConfig.TransactionMode>
- 封闭类:
- 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.
枚举常量概要
枚举常量 枚举常量 说明 DEFAULT
Indicates that the default transaction mode should be used.INFERRED
Indicates that the transaction mode to use when executing SQL scripts should be inferred using the rules listed below.ISOLATED
Indicates that SQL scripts should always be executed in a new, isolated transaction that will be immediately committed.
枚举常量详细资料
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 isINFERRED
. - If
@SqlConfig
is declared globally, the default transaction mode isINFERRED
. - If
@SqlConfig
is declared globally and locally, the default transaction mode for the local declaration is inherited from the global declaration.
- If
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. SeeTestContextTransactionUtils
for details on the conventions used to discover such beans in theApplicationContext
.Inference Rules
- If neither a transaction manager nor a data source is available, an exception will be thrown.
- 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.
- 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
.
- 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
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.
方法详细资料
values
public static SqlConfig.TransactionMode[] values()
按照声明该枚举类型的常量的顺序, 返回 包含这些常量的数组。该方法可用于迭代 常量, 如下所示:for (SqlConfig.TransactionMode c : SqlConfig.TransactionMode.values()) System.out.println(c);
- 返回:
- 按照声明该枚举类型的常量的顺序返回的包含这些常量的数组
valueOf
public static SqlConfig.TransactionMode valueOf(String name)
返回带有指定名称的该类型的枚举常量。 字符串必须与用于声明该类型的枚举常量的 标识符完全匹配。(不允许有多余 的空格字符。)- 参数:
name
- 要返回的枚举常量的名称。- 返回:
- 返回带有指定名称的枚举常量
- 抛出:
IllegalArgumentException
- 如果该枚举类型没有带有指定名称的常量NullPointerException
- 如果参数为空值