简体   繁体   English

是否有支持 XA 分布式事务的内存中 JDBC 数据库?

[英]Are there any in-memory JDBC databases that support XA distributed transactions?

I want to use an in-memory database to test my application, but it needs to support XA distributed transactions .我想使用内存数据库来测试我的应用程序,但它需要支持XA 分布式事务 My first idea for an in-memory database was HSQLDB , but it appears not to support XA.我对内存数据库的第一个想法是HSQLDB ,但它似乎不支持 XA。 Are there any?有吗?

看起来H2支持这一点。

Both H2 database and HSQLDB support it, couldn't find any other java embedded databases even in 2019. But it's not correctly implemented in either of them: the transaction is rolled back as soon as the client disconnects. H2数据库HSQLDB都支持它,即使在2019年也找不到任何其他Java嵌入式数据库。但它们都没有正确实现:一旦客户端断开连接,事务就会回滚。 According to the X/Open spec, when a database prepares a transaction, its data should be persistently stored and must be available to be committed later.根据 X/Open 规范,当数据库准备一个事务时,它的数据应该被持久存储并且必须可以在以后提交。

In H2 the XA code is unmaintained .在 H2 中,XA 代码未维护

If you want an XA-supporting database for your tests, you can use Postgres using the TestContainers project:如果你想要一个支持 XA 的数据库用于你的测试,你可以通过TestContainers项目使用 Postgres:

@ClassRule
public static PostgreSQLContainer container = new PostgreSQLContainer<>("postgres:12.1")
        .withCommand("postgres -c max_prepared_transactions=10");

Then create a datasource like this:然后创建一个这样的数据源:

PGXADataSource dataSource = new PGXADataSource();
dataSource.setURL(container.getJdbcUrl());
dataSource.setUser(container.getUsername());
dataSource.setPassword(container.getPassword());
dataSource.setDatabaseName(container.getDatabaseName());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM