Spring事务02事务管理器1PlatformTransactionManager
1、类方法概览
2、类接口解释,PlatformTransactionManager 这是Spring事务基础结构中的中心接口
/** * This is the central interface in Spring"s transaction infrastructure.
* Applications can use this directly, but it is not primarily meant as API:
* Typically, applications will work with either TransactionTemplate or
* declarative transaction demarcation through AOP.
*
* <p>For implementors, it is recommended to derive from the provided
* {@link org.springframework.transaction.support.AbstractPlatformTransactionManager}
* class, which pre-implements the defined propagation behavior and takes care
* of transaction synchronization handling. Subclasses have to implement
* template methods for specific states of the underlying transaction,
* for example: begin, suspend, resume, commit.
*
* <p>The default implementations of this strategy interface are
* {@link org.springframework.transaction.jta.JtaTransactionManager} and
* {@link org.springframework.jdbc.datasource.DataSourceTransactionManager},
* which can serve as an implementation guide for other transaction strategies.
*
*
* ------------------------ 翻译中文如下 ------------------------
*
* 这是Spring事务基础结构中的中心接口。
* 应用程序可以直接使用它,但它主要不是作为API:
* 通常,应用程序将使用TransactionTemplate或
* 通过AOP进行声明性事务界定。
*
* 对于实现者,建议从提供的
* {@link org.springframework.transaction.support.AbstractPlatformTransactionManager}
* 类,它预先实现了已定义的传播行为并小心处理
* 事务同步处理。子类必须实现
* 用于底层事务的特定状态的模板方法,
* 例如:begin(开始)、suspend(暂停)、resume(恢复)、commit(提交)。
*
* 此策略接口的默认实现为
* {@link org.springframework.transaction.jta.JtaTransactionManager},
* {@link org.springframework.jdbc.datasource.DataSourceTransactionManager},
* 可作为其他交易策略的执行指引。
*
* @since 16.05.2003
* @see org.springframework.transaction.support.TransactionTemplate
* @see org.springframework.transaction.interceptor.TransactionInterceptor
* @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
*/
public interface PlatformTransactionManager {}
3、类方法 getTransaction(),根据指定的传播行为,返回当前活动的事务或创建一个新的事务
/*** Return a currently active transaction or create a new one, according to
* the specified propagation behavior.
* <p>Note that parameters like isolation level or timeout will only be applied
* to new transactions, and thus be ignored when participating in active ones.
* <p>Furthermore, not all transaction definition settings will be supported
* by every transaction manager: A proper transaction manager implementation
* should throw an exception when unsupported settings are encountered.
* <p>An exception to the above rule is the read-only flag, which should be
* ignored if no explicit read-only mode is supported. Essentially, the
* read-only flag is just a hint for potential optimization.
* @param definition the TransactionDefinition instance (can be {@code null} for defaults),
* describing propagation behavior, isolation level, timeout etc.
*
* @return transaction status object representing the new or current transaction
* @throws TransactionException in case of lookup, creation, or system errors
* @throws IllegalTransactionStateException if the given transaction definition
* cannot be executed (for example, if a currently active transaction is in
* conflict with the specified propagation behavior)
*
* ------------------------ 翻译中文如下 ------------------------
*
* 根据指定的传播行为,返回当前活动的事务或创建一个新的事务。
*
* <p>注意,隔离级别或超时等参数只会被应用
* 到新事务,因此在参与活动事务时被忽略。
*
* <p>此外,不是所有的事务定义设置将被支持
* 每个事务管理器:一个合适的事务管理器实现
* 遇到不支持的设置时应该抛出异常。
*
* <p>上述规则的一个例外是只读标志,它应该是
* 如果不支持显式只读模式,则忽略。本质上讲,
* 只读标志只是潜在优化的一个提示。
* TransactionDefinition实例(默认值可以是{@code null}),
* 描述传播行为、隔离级别、超时等。
*
* @return表示新事务或当前事务的事务状态对象
* 在查找、创建或系统错误时抛出TransactionException
* 如果给定事务定义,@抛出IllegalTransactionStateException
* 无法执行(例如,如果当前活动的事务处于
* 与指定的传播行为冲突)
*
* @see TransactionDefinition#getPropagationBehavior
* @see TransactionDefinition#getIsolationLevel
* @see TransactionDefinition#getTimeout
* @see TransactionDefinition#isReadOnly
*/
TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException;
4、类方法 commit(),提交给定事务的状态
/*** Commit the given transaction, with regard to its status. If the transaction
* has been marked rollback-only programmatically, perform a rollback.
* <p>If the transaction wasn"t a new one, omit the commit for proper
* participation in the surrounding transaction. If a previous transaction
* has been suspended to be able to create a new one, resume the previous
* transaction after committing the new one.
* <p>Note that when the commit call completes, no matter if normally or
* throwing an exception, the transaction must be fully completed and
* cleaned up. No rollback call should be expected in such a case.
* <p>If this method throws an exception other than a TransactionException,
* then some before-commit error caused the commit attempt to fail. For
* example, an O/R Mapping tool might have tried to flush changes to the
* database right before commit, with the resulting DataAccessException
* causing the transaction to fail. The original exception will be
* propagated to the caller of this commit method in such a case.
*
* ------------------------ 翻译中文如下 ------------------------
*
* 提交给定事务的状态。如果事务
* 仅以编程方式标记回滚,请执行回滚。
*
* <p>如果事务不是新的,适当地忽略提交
* 参与周边交易。如果之前的交易
* 已经暂停可以创建一个新的,恢复以前的
* 提交新事务后的事务。
*
* <p>注意,当提交调用完成时,无论是否正常或
* 抛出异常时,事务必须完全完成
* 清理干净。在这种情况下不应该期望回滚调用。
*
* <p>如果这个方法抛出一个TransactionException之外的异常,
* 然后一些提交前的错误导致提交尝试失败。为
* 例如,O/R映射工具可能尝试将更改刷新到
* 提交之前的数据库,生成DataAccessException
* 导致事务失败。最初的例外是
* 在这种情况下传播到此提交方法的调用者。
*
* @param status object returned by the {@code getTransaction} method
* @throws UnexpectedRollbackException in case of an unexpected rollback
* that the transaction coordinator initiated
* @throws HeuristicCompletionException in case of a transaction failure
* caused by a heuristic decision on the side of the transaction coordinator
* @throws TransactionSystemException in case of commit or system errors
* (typically caused by fundamental resource failures)
* @throws IllegalTransactionStateException if the given transaction
* is already completed (that is, committed or rolled back)
* @see TransactionStatus#setRollbackOnly
*/
void commit(TransactionStatus status) throws TransactionException;
5、类方法 rollback(),执行给定事务的回滚
/*** Perform a rollback of the given transaction.
* <p>If the transaction wasn"t a new one, just set it rollback-only for proper
* participation in the surrounding transaction. If a previous transaction
* has been suspended to be able to create a new one, resume the previous
* transaction after rolling back the new one.
* <p><b>Do not call rollback on a transaction if commit threw an exception.</b>
* The transaction will already have been completed and cleaned up when commit
* returns, even in case of a commit exception. Consequently, a rollback call
* after commit failure will lead to an IllegalTransactionStateException.
*
* ------------------------ 翻译中文如下 ------------------------
*
* 执行给定事务的回滚。
*
* <p>如果事务不是一个新的,只是设置回滚-只有为正确
* 参与周边交易。如果之前的交易
* 已经暂停可以创建一个新的,恢复以前的吗
* 事务后回滚新的一个。
*
* <p><b>如果提交抛出异常,则不调用事务回滚。</b>
* 事务在提交时就已经完成并清理了
* 返回,即使在提交异常的情况下也是如此。因此,回滚调用
* 提交失败后将导致一个非法的事务状态异常。
*
* @param status object returned by the {@code getTransaction} method
* @throws TransactionSystemException in case of rollback or system errors
* (typically caused by fundamental resource failures)
* @throws IllegalTransactionStateException if the given transaction
* is already completed (that is, committed or rolled back)
*/
void rollback(TransactionStatus status) throws TransactionException;
以上是 Spring事务02事务管理器1PlatformTransactionManager 的全部内容, 来源链接: utcz.com/z/513323.html