免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1003 | 回复: 0
打印 上一主题 下一主题

EJB transaction [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-28 15:45 |只看该作者 |倒序浏览

Here are the definitions of the transaction attributes listed earlier. In a few of the definitions, the client transaction is described as suspended . This means the transaction is not propagated to the enterprise bean method being invoked; propagation of the transaction is temporarily halted until the enterprise bean method returns. To make things easier, we will talk about attribute types as if they were bean types: for example, we'll say "a Required EJB" as shorthand for "an enterprise bean with the Required transaction attribute." The attributes are:
NotSupported
Invoking a method on an EJB with this transaction attribute suspends the transaction until the method is completed. This means that the transaction scope is not propagated to the NotSupported EJB or to any of the EJBs it calls. Once the method on the NotSupported EJB is done, the original transaction resumes its execution.
Figure 16-1
shows that a NotSupported EJB does not propagate the client transaction when one of its methods is invoked.
Figure 16-1. The NotSupported attribute

Supports
This attribute means that the enterprise bean method will be included in the transaction scope if it is invoked within a transaction. In other words, if the EJB or client that invokes the Supports EJB is part of a transaction scope, the Supports EJB and all EJBs accessed by it become part of the original transaction. However, the Supports EJB doesn't have to be part of a transaction and can interact with clients and other EJBs that are not included in a transaction scope.
Figure 16-2a
shows the Supports EJB being invoked by a transactional client and propagating the transaction.
Figure 16-2b
shows the Supports EJB being invoked by a nontransactional client.
Figure 16-2. The Supports attribute

Required
This attribute means that the enterprise bean method must be invoked within the scope of a transaction. If the calling client or EJB is part of a transaction, the Required EJB is automatically included in its transaction scope. If, however, the calling client or EJB is not involved in a transaction, the Required EJB starts its own new transaction. The new transaction's scope covers only the Required EJB and all other EJBs accessed by it. Once the method invoked on the Required EJB is done, the new transaction's scope ends.
Figure 16-3a
shows the Required EJB being invoked by a transactional client and propagating the transaction.
Figure 16-3b
shows the Required EJB being invoked by a nontransactional client, which causes it to start its own transaction.
Figure 16-3. The Required attribute

RequiresNew
This attribute means that a new transaction is always started. Regardless of whether the calling client or EJB is part of a transaction, a method with the RequiresNew attribute begins a new transaction when invoked. If the calling client is already involved in a transaction, that transaction is suspended until the RequiresNew EJB's method call returns. The new transaction's scope covers only the RequiresNew EJB and all the EJBs accessed by it. Once the method invoked on the RequiresNew EJB is done, the new transaction's scope ends and the original transaction resumes.
Figure 16-4a
shows the RequiresNew EJB being invoked by a transactional client. The client's transaction is suspended while the EJB executes under its own transaction.
Figure 16-4b
shows the RequiresNew EJB being invoked by a nontransactional client; the RequiresNew EJB executes under its own transaction.
Figure 16-4. The RequiresNew attribute

Mandatory
This attribute means that the enterprise bean method must always be made part of the transaction scope of the calling client. The EJB may not start its own transaction; the transaction must be propagated from the client. If the calling client is not part of a transaction, the invocation will fail, throwing a javax.ejb.EJBTransactionRequiredException .
Figure 16-5a
shows the Mandatory EJB invoked by a transactional client and propagating the transaction.
Figure 16-5b
shows the Mandatory EJB invoked by a nontransactional client; the method throws an EJBTransactionRequiredException because there is no transaction scope.
Figure 16-5. The Mandatory attribute

Never
This attribute means that the enterprise bean method must not be invoked within the scope of a transaction. If the calling client or EJB is part of a transaction, the Never EJB will throw an EJBException. However, if the calling client or EJB is not involved in a transaction, the Never EJB will execute normally without a transaction.
Figure 16-6a
shows the Never EJB being invoked by a nontransactional client.
Figure 16-6b
shows the Never EJB being invoked by a transactional client; the method throws an EJBException to EJB clients because a client or EJB that is included in a transaction can never invoke the method.
Figure 16-6. The Never attribute



本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/4864/showart_311756.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP