/** * Forget a transaction. * This method does not have an effect for this database. * * @param xid the transaction id */ @Override public void forget(Xid xid) { if (isDebugEnabled()) { debugCode("forget("+JdbcXid.toString(xid)+");"); } prepared = false; }
/** * Prepare a transaction. * * @param xid the transaction id * @return XA_OK */ @Override public int prepare(Xid xid) throws XAException { if (isDebugEnabled()) { debugCode("prepare("+JdbcXid.toString(xid)+");"); } checkOpen(); if (!currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_INVAL); } try (Statement stat = physicalConn.createStatement()) { stat.execute("PREPARE COMMIT " + JdbcXid.toString(xid)); prepared = true; } catch (SQLException e) { throw convertException(e); } return XA_OK; }
/** * Roll back a transaction. * * @param xid the transaction id */ @Override public void rollback(Xid xid) throws XAException { if (isDebugEnabled()) { debugCode("rollback("+JdbcXid.toString(xid)+");"); } try { if (prepared) { try (Statement stat = physicalConn.createStatement()) { stat.execute("ROLLBACK TRANSACTION " + JdbcXid.toString(xid)); } prepared = false; } else { physicalConn.rollback(); } physicalConn.setAutoCommit(true); } catch (SQLException e) { throw convertException(e); } currentTransaction = null; }
/** * End a transaction. * * @param xid the transaction id * @param flags TMSUCCESS, TMFAIL, or TMSUSPEND */ @Override public void end(Xid xid, int flags) throws XAException { if (isDebugEnabled()) { debugCode("end("+JdbcXid.toString(xid)+", "+quoteFlags(flags)+");"); } // TODO transaction end: implement this method if (flags == TMSUSPEND) { return; } if (!currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_OUTSIDE); } prepared = false; }
/** * Commit a transaction. * * @param xid the transaction id * @param onePhase use a one-phase protocol if true */ @Override public void commit(Xid xid, boolean onePhase) throws XAException { if (isDebugEnabled()) { debugCode("commit("+JdbcXid.toString(xid)+", "+onePhase+");"); } try { if (onePhase) { physicalConn.commit(); } else { try (Statement stat = physicalConn.createStatement()) { stat.execute("COMMIT TRANSACTION " + JdbcXid.toString(xid)); prepared = false; } } physicalConn.setAutoCommit(true); } catch (SQLException e) { throw convertException(e); } currentTransaction = null; }
/** * Start or continue to work on a transaction. * * @param xid the transaction id * @param flags TMNOFLAGS, TMJOIN, or TMRESUME */ @Override public void start(Xid xid, int flags) throws XAException { if (isDebugEnabled()) { debugCode("start("+JdbcXid.toString(xid)+", "+quoteFlags(flags)+");"); } if (flags == TMRESUME) { return; } if (flags == TMJOIN) { if (currentTransaction != null && !currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_RMERR); } } else if (currentTransaction != null) { throw new XAException(XAException.XAER_NOTA); } try { physicalConn.setAutoCommit(false); } catch (SQLException e) { throw convertException(e); } currentTransaction = xid; prepared = false; }
/** * Forget a transaction. * This method does not have an effect for this database. * * @param xid the transaction id */ @Override public void forget(Xid xid) { if (isDebugEnabled()) { debugCode("forget("+JdbcXid.toString(xid)+");"); } prepared = false; }
/** * Forget a transaction. * This method does not have an effect for this database. * * @param xid the transaction id */ @Override public void forget(Xid xid) { if (isDebugEnabled()) { debugCode("forget("+JdbcXid.toString(xid)+");"); } prepared = false; }
/** * Prepare a transaction. * * @param xid the transaction id * @return XA_OK */ @Override public int prepare(Xid xid) throws XAException { if (isDebugEnabled()) { debugCode("prepare("+JdbcXid.toString(xid)+");"); } checkOpen(); if (!currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_INVAL); } try (Statement stat = physicalConn.createStatement()) { stat.execute("PREPARE COMMIT " + JdbcXid.toString(xid)); prepared = true; } catch (SQLException e) { throw convertException(e); } return XA_OK; }
/** * Roll back a transaction. * * @param xid the transaction id */ @Override public void rollback(Xid xid) throws XAException { if (isDebugEnabled()) { debugCode("rollback("+JdbcXid.toString(xid)+");"); } try { if (prepared) { try (Statement stat = physicalConn.createStatement()) { stat.execute("ROLLBACK TRANSACTION " + JdbcXid.toString(xid)); } prepared = false; } else { physicalConn.rollback(); } physicalConn.setAutoCommit(true); } catch (SQLException e) { throw convertException(e); } currentTransaction = null; }
/** * Commit a transaction. * * @param xid the transaction id * @param onePhase use a one-phase protocol if true */ @Override public void commit(Xid xid, boolean onePhase) throws XAException { if (isDebugEnabled()) { debugCode("commit("+JdbcXid.toString(xid)+", "+onePhase+");"); } try { if (onePhase) { physicalConn.commit(); } else { try (Statement stat = physicalConn.createStatement()) { stat.execute("COMMIT TRANSACTION " + JdbcXid.toString(xid)); prepared = false; } } physicalConn.setAutoCommit(true); } catch (SQLException e) { throw convertException(e); } currentTransaction = null; }
/** * End a transaction. * * @param xid the transaction id * @param flags TMSUCCESS, TMFAIL, or TMSUSPEND */ @Override public void end(Xid xid, int flags) throws XAException { if (isDebugEnabled()) { debugCode("end("+JdbcXid.toString(xid)+", "+quoteFlags(flags)+");"); } // TODO transaction end: implement this method if (flags == TMSUSPEND) { return; } if (!currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_OUTSIDE); } prepared = false; }
/** * End a transaction. * * @param xid the transaction id * @param flags TMSUCCESS, TMFAIL, or TMSUSPEND */ @Override public void end(Xid xid, int flags) throws XAException { if (isDebugEnabled()) { debugCode("end("+JdbcXid.toString(xid)+", "+quoteFlags(flags)+");"); } // TODO transaction end: implement this method if (flags == TMSUSPEND) { return; } if (!currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_OUTSIDE); } prepared = false; }
/** * Prepare a transaction. * * @param xid the transaction id * @return XA_OK */ @Override public int prepare(Xid xid) throws XAException { if (isDebugEnabled()) { debugCode("prepare("+JdbcXid.toString(xid)+");"); } checkOpen(); if (!currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_INVAL); } Statement stat = null; try { stat = physicalConn.createStatement(); stat.execute("PREPARE COMMIT " + JdbcXid.toString(xid)); prepared = true; } catch (SQLException e) { throw convertException(e); } finally { JdbcUtils.closeSilently(stat); } return XA_OK; }
/** * Roll back a transaction. * * @param xid the transaction id */ @Override public void rollback(Xid xid) throws XAException { if (isDebugEnabled()) { debugCode("rollback("+JdbcXid.toString(xid)+");"); } try { if (prepared) { Statement stat = null; try { stat = physicalConn.createStatement(); stat.execute("ROLLBACK TRANSACTION " + JdbcXid.toString(xid)); } finally { JdbcUtils.closeSilently(stat); } prepared = false; } else { physicalConn.rollback(); } physicalConn.setAutoCommit(true); } catch (SQLException e) { throw convertException(e); } currentTransaction = null; }
/** * Commit a transaction. * * @param xid the transaction id * @param onePhase use a one-phase protocol if true */ @Override public void commit(Xid xid, boolean onePhase) throws XAException { if (isDebugEnabled()) { debugCode("commit("+JdbcXid.toString(xid)+", "+onePhase+");"); } Statement stat = null; try { if (onePhase) { physicalConn.commit(); } else { stat = physicalConn.createStatement(); stat.execute("COMMIT TRANSACTION " + JdbcXid.toString(xid)); prepared = false; } physicalConn.setAutoCommit(true); } catch (SQLException e) { throw convertException(e); } finally { JdbcUtils.closeSilently(stat); } currentTransaction = null; }
/** * Start or continue to work on a transaction. * * @param xid the transaction id * @param flags TMNOFLAGS, TMJOIN, or TMRESUME */ @Override public void start(Xid xid, int flags) throws XAException { if (isDebugEnabled()) { debugCode("start("+JdbcXid.toString(xid)+", "+quoteFlags(flags)+");"); } if (flags == TMRESUME) { return; } if (flags == TMJOIN) { if (currentTransaction != null && !currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_RMERR); } } else if (currentTransaction != null) { throw new XAException(XAException.XAER_NOTA); } try { physicalConn.setAutoCommit(false); } catch (SQLException e) { throw convertException(e); } currentTransaction = xid; prepared = false; }
/** * Start or continue to work on a transaction. * * @param xid the transaction id * @param flags TMNOFLAGS, TMJOIN, or TMRESUME */ @Override public void start(Xid xid, int flags) throws XAException { if (isDebugEnabled()) { debugCode("start("+JdbcXid.toString(xid)+", "+quoteFlags(flags)+");"); } if (flags == TMRESUME) { return; } if (flags == TMJOIN) { if (currentTransaction != null && !currentTransaction.equals(xid)) { throw new XAException(XAException.XAER_RMERR); } } else if (currentTransaction != null) { throw new XAException(XAException.XAER_NOTA); } try { physicalConn.setAutoCommit(false); } catch (SQLException e) { throw convertException(e); } currentTransaction = xid; prepared = false; }