/*
   * @throws javax.transaction.HeuristicRollbackException
   *         if work was rolled back.
   *         since these specific exceptions require a JTA API.
   * @throws javax.transaction.HeuristicMixedException
   *         if some work was committed and some work was rolled back
   */
  public void commitThis(boolean onePhase) throws XAException {

    if (onePhase && state == XA_STATE_PREPARED) {
      throw new XAException("Transaction is in a 2-phase state when 1-phase is requested");
    }

    if ((!onePhase) && state != XA_STATE_PREPARED) {
      throw new XAException("Attempt to do a 2-phase commit when " + "transaction is not prepared");
    }

    // if (!onePhase) {
    //  throw new XAException(
    //   "Sorry.  HSQLDB has not implemented 2-phase commits yet");
    // }
    try {

      /**
       * @todo: Determine if work was committed, rolled back, or both, and return appropriate
       *     Heuristic*Exception. connection.commit(); Commits the real, physical conn.
       */
      connection.commit();
    } catch (SQLException se) {
      throw new XAException(se.getMessage());
    }

    dispose();
  }
  /**
   * The XAResource API spec indicates implies that this is only for 2-phase transactions. I guess
   * that one-phase transactions need to call rollback() to abort.
   *
   * <p>I think we want this JDBCXAResource instance to be garbage-collectable after (a) this method
   * is called, and (b) the tx manager releases its handle to it.
   *
   * @see javax.transaction.xa.XAResource#forget(Xid)
   */
  public void forget(Xid xid) throws XAException {

    /**
     * Should this method not attempt to clean up the aborted transaction by rolling back or
     * something? Maybe the tx manager will already have called rollback() if it were necessasry?
     */
    validateXid(xid);

    if (state != XA_STATE_PREPARED) {
      throw new XAException(
          "Attempted to forget a XAResource that " + "is not in a heuristically completed state");
    }

    dispose();

    state = XA_STATE_INITIAL;
  }
  /* @throws javax.transaction.HeuristicCommitException
   *         if work was committed.
   * @throws javax.transaction.HeuristicMixedException
   *         if some work was committed and some work was rolled back
   */
  public void rollbackThis() throws XAException {

    if (state != XA_STATE_PREPARED) {
      throw new XAException("Invalid XAResource state");
    }

    try {

      /**
       * @todo: Determine if work was committed, rolled back, or both, and return appropriate
       *     Heuristic Exception.
       */
      connection.rollback(); // real/phys.
    } catch (SQLException se) {
      throw new XAException(se.getMessage());
    }

    dispose();
  }