通过 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。该资源需要提供 XAResource 的实现,并且该实现的实例需要是 随事务登记< /a> 当资源被使用时。该资源可以从事务管理器以便在访问时进行注册(我认为)。
您可以查看 XADisk 的代码,它显然是一个 XA 事务文件管理器,看看它是如何完成的那里。
然而,在 J2EE 世界中执行此操作的常见方法不是直接处理 JTA,而是使用 JCA,它让 J2EE 容器不仅可以处理事务,还可以处理池、命名和各种其他企业细节。然而,JCA API 并不完全简单,尽管它很困难,但它受到堆积如山的更困难的文档的保护,其主要目的似乎是阻止理解它!
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).
You could look at the code to XADisk, which is apparently an XA-transactional file manager, to see how it's done there.
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!