UserTransaction (Java EE 5)

Java EE API


javax.transaction Interface UserTransaction


public interface UserTransaction


UserTransaction 接口定义帮助应用程序显式管理事务邦定的方法。
英文文档:

The UserTransaction interface defines the methods that allow an application to explicitly manage transaction boundaries.


Method Summary
 void
 void
 int
 void
 void
 void
 

Method Detail

public void begin() throws NotSupportedException, SystemException
创建一个新事务,并将其与当前线程关联。
ThrowsNotSupportedException: 如果线程已经与事务关联,但 TransactionManager 实现不支持嵌套的事务。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

begin

void begin()
           throws NotSupportedException,
                  SystemException
Create a new transaction and associate it with the current thread.

Throws:
NotSupportedException - Thrown if the thread is already associated with a transaction and the Transaction Manager implementation does not support nested transactions.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, SecurityException, IllegalStateException, SystemException
完成与当前线程关联的事务。完成此方法时,线程不再与事务关联。
ThrowsRollbackException: 抛出该异常指示事务已经回滚,而不是提交。
ThrowsHeuristicMixedException: 抛出该异常指示做出了启发式决策,提交了一部分相关更新,同时回滚了另一部分。
ThrowsHeuristicRollbackException: 抛出该异常指示做出了启发式决策,回滚了所有相关更新。
ThrowsSecurityException: 抛出该异常指示不允许线程提交事务。
ThrowsIllegalStateException: 如果当前线程不与事务关联,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

commit

void commit()
            throws RollbackException,
                   HeuristicMixedException,
                   HeuristicRollbackException,
                   SecurityException,
                   IllegalStateException,
                   SystemException
Complete the transaction associated with the current thread. When this method completes, the thread is no longer associated with a transaction.

Throws:
RollbackException - Thrown to indicate that the transaction has been rolled back rather than committed.
HeuristicMixedException - Thrown to indicate that a heuristic decision was made and that some relevant updates have been committed while others have been rolled back.
HeuristicRollbackException - Thrown to indicate that a heuristic decision was made and that all relevant updates have been rolled back.
SecurityException - Thrown to indicate that the thread is not allowed to commit the transaction.
IllegalStateException - Thrown if the current thread is not associated with a transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public void rollback() throws IllegalStateException, SecurityException, SystemException
回滚与当前线程关联的事务。完成此方法时,线程不再与事务关联。
ThrowsSecurityException: 抛出该异常指示不允许线程回滚事务。
ThrowsIllegalStateException: 如果当前线程不与事务关联,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

rollback

void rollback()
              throws IllegalStateException,
                     SecurityException,
                     SystemException
Roll back the transaction associated with the current thread. When this method completes, the thread is no longer associated with a transaction.

Throws:
SecurityException - Thrown to indicate that the thread is not allowed to roll back the transaction.
IllegalStateException - Thrown if the current thread is not associated with a transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public void setRollbackOnly() throws IllegalStateException, SystemException
修改与当前线程关联的事务,从而使事务的唯一可能结果为回滚事务。
ThrowsIllegalStateException: 如果当前线程不与事务关联,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

setRollbackOnly

void setRollbackOnly()
                     throws IllegalStateException,
                            SystemException
Modify the transaction associated with the current thread such that the only possible outcome of the transaction is to roll back the transaction.

Throws:
IllegalStateException - Thrown if the current thread is not associated with a transaction.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public int getStatus() throws SystemException
获取与当前线程关联的事务状态。
return 事务状态。如果没有任何事务与当前线程关联,则此方法返回 Status.NoTransaction 值。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

getStatus

int getStatus()
              throws SystemException
Obtain the status of the transaction associated with the current thread.

Returns:
The transaction status. If no transaction is associated with the current thread, this method returns the Status.NoTransaction value.
Throws:
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public void setTransactionTimeout(int seconds) throws SystemException
修改与事务关联的超时值,这些事务由当前线程通过 begin 方法启动。

如果应用程序没有调用此方法,则事务服务对事务超时使用某个默认值。

seconds 超时值(以秒为单位)。如果值为 0,则事务服务恢复默认值。如果值为负,则抛出 SystemException。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。

英文文档:

setTransactionTimeout

void setTransactionTimeout(int seconds)
                           throws SystemException
Modify the timeout value that is associated with transactions started by the current thread with the begin method.

If an application has not called this method, the transaction service uses some default value for the transaction timeout.

Parameters:
seconds - The value of the timeout in seconds. If the value is zero, the transaction service restores the default value. If the value is negative a SystemException is thrown.
Throws:
SystemException - Thrown if the transaction manager encounters an unexpected error condition.


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!