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; }
/** * 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; }
/** * Vote on whether to commit the global transaction. * * @throws XAException to vote negative. * @return commitType of XA_RDONLY or XA_OK. (Actually only XA_OK now). */ public int prepare(Xid xid) throws XAException { validateXid(xid); /** * @todo: This is where the real 2-phase work should be done to determine if a commit done here * would succeed or not. */ /** * @todo: May improve performance to return XA_RDONLY whenever possible, but I don't know. Could * determine this by checking if DB instance is in RO mode, or perhaps (with much * difficulty) to determine if there have been any modifications performed. */ if (state != XA_STATE_ENDED) { throw new XAException("Invalid XAResource state"); } // throw new XAException( // "Sorry. HSQLDB has not implemented 2-phase commits yet"); state = XA_STATE_PREPARED; return XA_OK; // As noted above, should check non-committed work. }