Transaction (Java EE 5)

Java EE API


javax.transaction Interface Transaction


public interface Transaction


Transaction 接口允许针对目标 Transaction 对象中的事务执行操作。创建每个全局事务时,也会相应地创建一个 Transaction 对象。Transaction 对象可用于资源登记、同步注册、事务完成和状态查询操作。
英文文档:

The Transaction interface allows operations to be performed against the transaction in the target Transaction object. A Transaction object is created corresponding to each global transaction creation. The Transaction object can be used for resource enlistment, synchronization registration, transaction completion, and status query operations.


Method Summary
 void
 boolean
 boolean
 int
 void
 void
 void
 

Method Detail

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

commit

void commit()
            throws RollbackException,
                   HeuristicMixedException,
                   HeuristicRollbackException,
                   SecurityException,
                   IllegalStateException,
                   SystemException
Complete the transaction represented by this Transaction object.

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 transaction in the target object is inactive.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public boolean delistResource(XAResource xaRes, int flag) throws IllegalStateException, SystemException
取消指定的资源与目标 Transaction 对象关联的事务之间的关联。
xaRes 与资源关联的 XAResource 对象(连接)。
flag TMSUCCESS、TMSUSPEND 或 TMFAIL 值之一。
ThrowsIllegalStateException: 如果目标对象中的事务不是活动的,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
return 如果成功取消了资源的登记,则返回 true;否则返回 false
英文文档:

delistResource

boolean delistResource(XAResource xaRes,
                       int flag)
                       throws IllegalStateException,
                              SystemException
Disassociate the resource specified from the transaction associated with the target Transaction object.

Parameters:
xaRes - The XAResource object associated with the resource (connection).
flag - One of the values of TMSUCCESS, TMSUSPEND, or TMFAIL.
Returns:
true if the resource was delisted successfully; otherwise false.
Throws:
IllegalStateException - Thrown if the transaction in the target object is inactive.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public boolean enlistResource(XAResource xaRes) throws RollbackException, IllegalStateException, SystemException
登记与目标 Transaction 对象关联的事务指定的资源。
xaRes 与资源关联的 XAResource 对象(连接)。
return 如果成功登记了资源,则返回 true;否则返回 false
ThrowsRollbackException: 抛出该异常指示已将事务标记为只回滚。
ThrowsIllegalStateException: 如果目标对象中的事务处于准备状态或者非活动状态,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

enlistResource

boolean enlistResource(XAResource xaRes)
                       throws RollbackException,
                              IllegalStateException,
                              SystemException
Enlist the resource specified with the transaction associated with the target Transaction object.

Parameters:
xaRes - The XAResource object associated with the resource (connection).
Returns:
true if the resource was enlisted successfully; otherwise false.
Throws:
RollbackException - Thrown to indicate that the transaction has been marked for rollback only.
IllegalStateException - Thrown if the transaction in the target object is in the prepared state or the transaction is inactive.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

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

getStatus

int getStatus()
              throws SystemException
Obtain the status of the transaction associated with the target Transaction object.

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

public void registerSynchronization(Synchronization sync) throws RollbackException, IllegalStateException, SystemException
为当前与目标对象关联的事务注册一个同步对象。事务管理器在启动二阶段事务提交过程之前调用 beforeCompletion 方法。事务完成之后,事务管理器调用 afterCompletion 方法。
sync 与目标对象关联的事务的 Synchronization 对象。
ThrowsRollbackException: 抛出该异常指示已将事务标记为只回滚。
ThrowsIllegalStateException: 如果目标对象中的事务处于准备状态或者非活动状态,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

registerSynchronization

void registerSynchronization(Synchronization sync)
                             throws RollbackException,
                                    IllegalStateException,
                                    SystemException
Register a synchronization object for the transaction currently associated with the target object. The transction manager invokes the beforeCompletion method prior to starting the two-phase transaction commit process. After the transaction is completed, the transaction manager invokes the afterCompletion method.

Parameters:
sync - The Synchronization object for the transaction associated with the target object.
Throws:
RollbackException - Thrown to indicate that the transaction has been marked for rollback only.
IllegalStateException - Thrown if the transaction in the target object is in the prepared state or the transaction is inactive.
SystemException - Thrown if the transaction manager encounters an unexpected error condition.

public void rollback() throws IllegalStateException, SystemException
回滚此 Transaction 对象表示的事务。
ThrowsIllegalStateException: 如果目标对象中的事务处于准备状态或者非活动状态,则抛出该异常。
ThrowsSystemException: 如果事务管理器遇到不可预料的错误情况,则抛出该异常。
英文文档:

rollback

void rollback()
              throws IllegalStateException,
                     SystemException
Rollback the transaction represented by this Transaction object.

Throws:
IllegalStateException - Thrown if the transaction in the target object is in the prepared state or the transaction is inactive.
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 target object such that the only possible outcome of the transaction is to roll back the transaction.

Throws:
IllegalStateException - Thrown if the target object is not associated with any transaction.
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 : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!