在JTA中使用任意资源 [英] Using arbitrary resources with JTA

查看:81
本文介绍了在JTA中使用任意资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用JTA进行任何类型的自定义资源交易?让我们假设一个基本的例子,并采取一个文件夹创建,如果出现错误应该回滚。

Is it possible to make any type of custom resource transactioal with JTA? Let's assume a basic example and take a Folder creation that should be rolled back in case of an error.

可以处理这样的自定义资源吗?

Can such custom resources be handled?

推荐答案

是的。该资源需要提供 XAResource 的实现,该实现的实例需要使用事务。该资源可以从中获取当前的交易访问管理器,以便在访问时进行注册(我认为)。

Yes. That resource needs to provide an implementation of XAResource, and an instance of that implementation needs to be enlisted with the transaction when the resource is used. The resource can get the current transaction from the transaction manager in order to carry out the registration when it is accessed (i think).

您可以查看代码 XADisk ,显然是一个XA事务文件管理器,看看它是如何在那里完成的。

You could look at the code to XADisk, which is apparently an XA-transactional file manager, to see how it's done there.

但是,在J2EE世界中这样做的常用方法不是直接处理JTA,而是使用 JCA ,它使J2EE容器不仅可以处理事务,还可以处理池,命名和各种其他企业详细信息。然而,JCA API并不是那么简单,虽然很难实现,但却是由大量更难记录的文档进行辩护,其主要目的似乎是为了防止对它的理解!

However, a common approach to doing this in the J2EE world is not to deal with JTA directly, but to write a resource adapter using JCA, which lets the J2EE container handle not only transactions, but pooling, naming, and various other enterprisey details. However, the JCA API is not exactly straightforward, and as difficult as it is, it is defended by a mountain of even more difficult documentation, whose main purpose seems to be to prevent understanding of it!

这篇关于在JTA中使用任意资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆