Skip to content

Commit

Permalink
Defer register XAResourceRecovery after recovery manager service is c…
Browse files Browse the repository at this point in the history
…reated
  • Loading branch information
zhfeng committed May 31, 2023
1 parent 9aaa021 commit 8b774e5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
package io.quarkus.narayana.jta.runtime;

import java.util.ArrayList;
import java.util.List;

import org.jboss.tm.XAResourceRecovery;

import com.arjuna.ats.jbossatx.jta.RecoveryManagerService;

public class QuarkusRecoveryService {
public class QuarkusRecoveryService extends RecoveryManagerService {
private static RecoveryManagerService recoveryManagerService;
private List<XAResourceRecovery> xaResources;
private boolean isCreated;

public static RecoveryManagerService getInstance() {
if (recoveryManagerService == null) {
recoveryManagerService = new RecoveryManagerService();
recoveryManagerService = new QuarkusRecoveryService();
}
return recoveryManagerService;
}

private QuarkusRecoveryService() {
xaResources = new ArrayList<>();
isCreated = false;
}

@Override
public void addXAResourceRecovery(XAResourceRecovery xares) {
if (isCreated) {
super.addXAResourceRecovery(xares);
} else {
xaResources.add(xares);
}
}

@Override
public void removeXAResourceRecovery(XAResourceRecovery xares) {
if (isCreated) {
super.removeXAResourceRecovery(xares);
} else {
xaResources.remove(xares);
}
}

@Override
public void create() {
super.create();
isCreated = true;
for (XAResourceRecovery xares : xaResources) {
super.addXAResourceRecovery(xares);
}
xaResources.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public Map<String, String> getConfigOverrides() {
props.put("quarkus.transaction-manager.object-store.type", "jdbc");
props.put("quarkus.transaction-manager.object-store.create-table", "true");
props.put("quarkus.transaction-manager.enable-recovery", "true");

props.put("quarkus.datasource.test.db-kind", "h2");
props.put("quarkus.datasource.test.jdbc.url", "jdbc:h2:mem:default");
props.put("quarkus.datasource.test.jdbc.transactions", "xa");

return props;
}
}

0 comments on commit 8b774e5

Please sign in to comment.