Source:
<code>public Object execute() throws Exception { if (force) { System.out.println("testRecovery generate something to recovery"); if (tm == null) { System.out.println("Can not get transaction manager"); } else { DummyXAResource xa1 = new DummyXAResource(); DummyXAResource xa2 = new DummyXAResource(DummyXAResource.faultType.HALT); tm.begin(); Transaction transaction = tm.getTransaction(); transaction.enlistResource(xa1); transaction.enlistResource(xa2); tm.commit(); } } else { File file = new File("DummyXAResource/"); if (file.exists() && file.isDirectory() && file.listFiles().length > 0) { System.out.println("register the DummyXAResourceRecovery"); int currentCommits = DummyXAResource.getCommitRequests(); <START> context.registerService(XAResourceRecovery.class, new DummyXAResourceRecovery(), null); <END> System.out.println("testRecovery waiting ..."); while (DummyXAResource.getCommitRequests() == currentCommits) { Thread.sleep(1000); } System.out.println("testRecovery done"); } else { System.out.println("you should run this command with -f at first"); } } return null; }</code><technical_language>say, Oracle H2 do this? For DummyXAResourceRecovery I is a requirement</technical_language>

Target:
public Object execute() throws Exception { if (force) { System.out.println("testRecovery generate something to recovery"); if (tm == null) { System.out.println("Can not get transaction manager"); } else { DummyXAResource xa = new DummyXAResource(DummyXAResource.faultType.HALT); Context ctx = new InitialContext(); DataSource ds = (DataSource)ctx.lookup("osgi:service/test"); Connection conn = null; Statement stmt = null; try { tm.begin(); Transaction transaction = tm.getTransaction(); transaction.enlistResource(xa); conn = ds.getConnection(); stmt = conn.createStatement(); stmt.execute("CREATE TABLE IF NOT EXISTS example ( id varchar(10), name varchar(32) )"); stmt.execute("insert into example values (1, 'recovery')"); tm.commit(); } catch (SQLException e) { System.out.println(e); tm.rollback(); } finally { stmt.close(); conn.close(); } } } else { File file = new File("DummyXAResource/"); if (file.exists() && file.isDirectory() && file.listFiles().length > 0) { int currentCommits = DummyXAResource.getCommitRequests(); System.out.println("current commitRequests of the DummyXAResource is " + currentCommits); System.out.println("query the database before recovery"); queryH2Database("select * from example"); System.out.println("register the DummyXAResourceRecovery"); context.registerService(XAResourceRecovery.class, new DummyXAResourceRecovery(), null); System.out.println("testRecovery waiting ..."); while (DummyXAResource.getCommitRequests() == currentCommits) { Thread.sleep(1000); } System.out.println("testRecovery done"); System.out.println("commitRequests of the DummyXAResource after recovery is " + DummyXAResource.getCommitRequests()); if (DummyXAResource.getCommitRequests() != currentCommits + 1) { System.err.println("RECOVERY the DummyXAResource could be WRONG !"); } System.out.println("reopen the database"); reopenH2Database(); System.out.println("query the database after recovery"); queryH2Database("select * from example"); } else { System.out.println("you should run this command with -f at first"); } } return null; }