@Override
  public void commit(Xid xid, boolean onePhase) throws XAException {
    PseudoXATransaction tx = this.transactions.get(xid);

    if (tx == null) {
      throw new XAException("No such transaction: " + xid);
    }

    tx.commit(this.messageConduit);
  }
  @Override
  public void rollback(Xid xid) throws XAException {
    PseudoXATransaction tx = this.transactions.get(xid);

    if (tx == null) {
      throw new XAException("No such transaction: " + xid);
    }

    tx.rollback(this.messageConduit);
  }
  @Override
  public void end(Xid xid, int flags) throws XAException {
    PseudoXATransaction tx = this.transactions.get(xid);
    if (tx == null) {
      throw new XAException("No such transaction: " + xid);
    }

    if (flags == XAResource.TMFAIL) {
      tx.setRollbackOnly(true);
    }

    this.currentTransaction.remove();
  }
  @Override
  public int prepare(Xid xid) throws XAException {
    PseudoXATransaction tx = this.transactions.get(xid);

    if (tx == null) {
      throw new XAException("No such transaction: " + xid);
    }

    if (tx.isRollbackOnly()) {
      throw new XAException(XAException.XA_RBROLLBACK);
    }

    return XAResource.XA_OK;
  }