spring 的platformTrasactionoManager API讲解(翻译)

来源:互联网 发布:机构投资者持股数据 编辑:程序博客网 时间:2024/05/22 01:49

platformTrasactionoManagerSpring事务的基础的中心接口,应用程序可以直接使用它,但它并不是主要用来作API:典型的,应用程序将使用TransactionTemplate或通过AOP声明式事务划分

对于实现者,建议使用AbstractPlatformTransactionManager类,它预实现传播行为的定义和负责的事务同步处理,子类必须为特定的底层事务实现模板方法,例如: begin, suspend, resume, commit.

这种策略接口的默认实现JtaTransactionManagerDataSourceTransactionManager,这可以作为其他事务策略的实施指南

Method Summary

 void

commit(TransactionStatus status)
         
根据它的事务状态提交事务

 TransactionStatus

getTransaction(TransactionDefinition definition)
          
返回当前活动事务或创建一个新的,根据指定的传播行为.

 void

rollback(TransactionStatus status)
         
执行一个给定的事务回滚

Method Detail

getTransaction

TransactionStatus getTransaction(TransactionDefinition definition)

                                throwsTransactionException

s


commit

void commit(TransactionStatus status)

           throws TransactionException

  根据它的事务状态提交事务.如果事务被rollback-only编程方式,执行回滚。

如果没有一个新的事务,省略提交适当的参与周围的事务.如果前一个事务已经暂停能够创建一个新的,恢复以前的事务提交后新的.

注意,当提交调用完成后,无论如果正常或抛出异常,事务必须充分和清理完成.不回滚调用应该在这种情况下

如果这种方法除了TransactionException抛出异常,那么一些before-commit错误导致提交的尝试失败.例如,一个O / R映射工具可能试图变更刷新到数据库之前提交,与结果DataAccessException导致提交失败.原始异常将被传递到调用者提交的方法在这种情况下

Parameters:

status - object returned by thegetTransaction method

Throws:

UnexpectedRollbackException -在一个意想不到的回滚事务协调器初始化

HeuristicCompletionException - in case of atransaction failure caused by a heuristic decision on the side of thetransaction coordinator

TransactionSystemException - in case ofcommit or system errors (typically caused by fundamental resource failures)

IllegalTransactionStateException - if the giventransaction is already completed (that is, committed or rolled back)

TransactionException

See Also:

TransactionStatus.setRollbackOnly()


rollback

void rollback(TransactionStatus status)

              throws TransactionException

执行一个给定的事务回滚.

如果不是一个新的事务,只是将它设置为properparticipation rollback-only周围的事务.如果先前transactionhas被停职能够创建一个新的,恢复previoustransaction回滚新的事务后,不回滚事务如果commit抛出一个异常,commit返回时,事务应该已经完成和被清理,即使在一个 commitexception.因此,当提交失败是回滚将导致出现IllegalTransactionStateException.

Parameters:

status - object returned by thegetTransaction method

Throws:

TransactionSystemException - in case of rollback or systemerrors(typically caused by fundamental resource failures)

IllegalTransactionStateException - if the given transactionis alreadycompleted (that is, committed or rolled back)

TransactionException

0 0
原创粉丝点击