Exemplo n.º 1
0
  /*
   * @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();
  }
Exemplo n.º 2
0
  public void start(Xid xid, int flags) throws XAException {

    // Comment out following debug statement before public release:
    System.err.println("STARTING NEW Xid: " + xid);

    if (state != XA_STATE_INITIAL && state != XA_STATE_DISPOSED) {
      throw new XAException("Invalid XAResource state");
    }

    if (xaDataSource == null) {
      throw new XAException("JDBCXAResource has not been associated with a XADataSource");
    }

    if (xid == null) {

      // This block asserts that all JDBCXAResources with state
      // >= XA_STATE_STARTED have a non-null xid.
      throw new XAException("Null Xid");
    }

    try {
      originalAutoCommitMode = connection.getAutoCommit(); // real/phys.

      connection.setAutoCommit(false); // real/phys.
    } catch (SQLException se) {
      throw new XAException(se.getMessage());
    }

    this.xid = xid;
    state = XA_STATE_STARTED;

    xaDataSource.addResource(this.xid, this);

    // N.b.  The DataSource does not have this XAResource in its list
    // until right here.  We can't tell DataSource before our start()
    // method, because we don't know our Xid before now.
  }
Exemplo n.º 3
0
  public void end(Xid xid, int flags) throws XAException {

    validateXid(xid);

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

    try {
      connection.setAutoCommit(originalAutoCommitMode); // real/phys.
    } catch (SQLException se) {
      throw new XAException(se.getMessage());
    }

    state = XA_STATE_ENDED;
  }
Exemplo n.º 4
0
  /* @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();
  }