SessionSynchronization (Java EE 5)

Java EE API


javax.ejb Interface SessionSynchronization


public interface SessionSynchronization


SessionSynchronization 接口允许会话 Bean 实例接收其容器关于事务边界的通知。

会话 Bean 类不需要实现此接口。只有在会话 Bean 类希望将其状态与事务同步时才应实现此接口。

英文文档:

The SessionSynchronization interface allows a session Bean instance to be notified by its container of transaction boundaries.

An session Bean class is not required to implement this interface. A session Bean class should implement this interface only if it wishes to synchronize its state with the transactions.


Method Summary
 void
 void
 void
 

Method Detail

public void afterBegin() throws EJBException, java.rmi.RemoteException
afterBegin 方法通知会话 Bean 实例新事务已开始,并且将在事务上下文中调用该实例的后续业务方法。

例如,实例可以使用此方法从数据库中读取数据并在实例字段中缓存数据。

在恰当的事务上下文中执行此方法。

ThrowsEJBException: 该方法抛出此异常指示由于系统级错误导致的失败。
Throwsjava.rmi.RemoteException: 此异常在方法签名中定义,以提供对根据 EJB 1.0 规范编写的企业 Bean 的向后兼容。根据 EJB 1.1 及更高规范编写的企业 Bean 应该抛出 javax.ejb.EJBException,而不是此异常。根据 EJB 2.0 及更高规范编写的企业 Bean 不得抛出 java.rmi.RemoteException。

英文文档:

afterBegin

void afterBegin()
                throws EJBException,
                       RemoteException
The afterBegin method notifies a session Bean instance that a new transaction has started, and that the subsequent business methods on the instance will be invoked in the context of the transaction.

The instance can use this method, for example, to read data from a database and cache the data in the instance fields.

This method executes in the proper transaction context.

Throws:
EJBException - Thrown by the method to indicate a failure caused by a system-level error.
RemoteException - This exception is defined in the method signature to provide backward compatibility for enterprise beans written for the EJB 1.0 specification. Enterprise beans written for the EJB 1.1 and higher specifications should throw the javax.ejb.EJBException instead of this exception. Enterprise beans written for the EJB 2.0 and higher specifications must not throw the java.rmi.RemoteException.

public void beforeCompletion() throws EJBException, java.rmi.RemoteException
beforeCompletion 方法通知会话 Bean 实例事务即将提交。例如,实例可以使用此方法将任何缓存数据写入数据库。

在恰当的事务上下文中执行此方法。

注:实例可能仍会通过在实例上下文中调用 setRollbackOnly() 方法或者通过抛出异常导致容器回滚事务。

ThrowsEJBException: 该方法抛出此异常指示由于系统级错误导致的失败。
Throwsjava.rmi.RemoteException: 此异常在方法签名中定义,以提供对根据 EJB 1.0 规范编写的企业 Bean 的向后兼容。根据 EJB 1.1 及更高规范编写的企业 Bean 应该抛出 javax.ejb.EJBException,而不是此异常。根据 EJB 2.0 及更高规范编写的企业 Bean 不得抛出 java.rmi.RemoteException。

英文文档:

beforeCompletion

void beforeCompletion()
                      throws EJBException,
                             RemoteException
The beforeCompletion method notifies a session Bean instance that a transaction is about to be committed. The instance can use this method, for example, to write any cached data to a database.

This method executes in the proper transaction context.

Note: The instance may still cause the container to rollback the transaction by invoking the setRollbackOnly() method on the instance context, or by throwing an exception.

Throws:
EJBException - Thrown by the method to indicate a failure caused by a system-level error.
RemoteException - This exception is defined in the method signature to provide backward compatibility for enterprise beans written for the EJB 1.0 specification. Enterprise beans written for the EJB 1.1 and higher specification should throw the javax.ejb.EJBException instead of this exception. Enterprise beans written for the EJB 2.0 and higher specifications must not throw the java.rmi.RemoteException.

public void afterCompletion(boolean committed) throws EJBException, java.rmi.RemoteException
afterCompletion 方法通知会话 Bean 实例事务提交协议已完成,并告知实例事务是已提交还是已回滚。

在无事务上下文的情况下执行此方法。

在无事务上下文的情况下执行此方法。

committed 如果事务已提交则返回 true,如果事务已回滚则返回 false。
ThrowsEJBException: 该方法抛出此异常指示由于系统级错误导致的失败。
Throwsjava.rmi.RemoteException: 此异常在方法签名中定义,以提供对根据 EJB 1.0 规范编写的企业 Bean 的向后兼容。根据 EJB 1.1 及更高规范编写的企业 Bean 应该抛出 javax.ejb.EJBException,而不是此异常。根据 EJB 2.0 及更高规范编写的企业 Bean 不得抛出 java.rmi.RemoteException。

英文文档:

afterCompletion

void afterCompletion(boolean committed)
                     throws EJBException,
                            RemoteException
The afterCompletion method notifies a session Bean instance that a transaction commit protocol has completed, and tells the instance whether the transaction has been committed or rolled back.

This method executes with no transaction context.

This method executes with no transaction context.

Parameters:
committed - True if the transaction has been committed, false if is has been rolled back.
Throws:
EJBException - Thrown by the method to indicate a failure caused by a system-level error.
RemoteException - This exception is defined in the method signature to provide backward compatibility for enterprise beans written for the EJB 1.0 specification. Enterprise beans written for the EJB 1.1 and higher specification should throw the javax.ejb.EJBException instead of this exception. Enterprise beans written for the EJB 2.0 and higher specifications must not throw the java.rmi.RemoteException.


Submit a bug or feature

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

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

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