/** * Open a new XA connection using the current URL, user name and password. * * @return the connection */ @Override public XAConnection getXAConnection() throws SQLException { debugCodeCall("getXAConnection"); int id = getNextId(XA_DATA_SOURCE); return new JdbcXAConnection(factory, id, getJdbcConnection(userName, StringUtils.cloneCharArray(passwordChars))); }
debugCodeCall("recover", quoteFlags(flag)); checkOpen(); try (Statement stat = physicalConn.createStatement()) { ResultSet rs = stat.executeQuery("SELECT * FROM " + while (rs.next()) { String tid = rs.getString("TRANSACTION"); int id = getNextId(XID); Xid xid = new JdbcXid(factory, id, tid); list.add(xid);
/** * 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; }
/** * 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; }
/** * 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); } 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 */ //## Java 1.4 begin ## public void rollback(Xid xid) throws XAException { if (debug()) { debugCode("rollback("+quoteXid(xid)+");"); } try { conn.rollback(); } catch (SQLException e) { throw convertException(e); } getTrace().debug("rolled back"); currentTransaction = null; } //## Java 1.4 end ##
/** * 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; }
/** * Get the transaction timeout. * * @return 0 */ @Override public int getTransactionTimeout() { debugCodeCall("getTransactionTimeout"); return 0; }
/** * Checks if this is the same XAResource. * * @param xares the other object * @return true if this is the same object */ @Override public boolean isSameRM(XAResource xares) { debugCode("isSameRM(xares);"); return xares == this; }
JdbcXAConnection(JdbcDataSourceFactory factory, int id, String url, String user, String password) throws SQLException { this.factory = factory; setTrace(factory.getTrace(), TraceObject.XA_DATA_SOURCE, id); this.url = url; this.user = user; this.password = password; connSentinel = openConnection(); getConnection(); } //## Java 1.4 end ##
/** * INTERNAL */ @Override public String toString() { return getTraceObjectName() + ": " + physicalConn; }
/** * Get a new connection. This method is usually called by the connection * pool when there are no more connections in the pool. * * @return the connection */ //## Java 1.4 begin ## public Connection getConnection() throws SQLException { debugCodeCall("getConnection"); if (conn != null) { closeConnection(conn); conn = null; } conn = openConnection(); conn.setJdbcConnectionListener(this); return conn; } //## Java 1.4 end ##
JdbcXAConnection(JdbcDataSourceFactory factory, int id, JdbcConnection physicalConn) { this.factory = factory; setTrace(factory.getTrace(), TraceObject.XA_DATA_SOURCE, id); this.physicalConn = physicalConn; }
/** * Close the physical connection. * This method is usually called by the connection pool. */ //## Java 1.4 begin ## public void close() throws SQLException { debugCodeCall("close"); try { closeConnection(conn); closeConnection(connSentinel); } finally { conn = null; connSentinel = null; } } //## Java 1.4 end ##
/** * INTERNAL */ //## Java 1.4 begin ## public void fatalErrorOccurred(JdbcConnection conn, SQLException e) throws SQLException { debugCode("fatalErrorOccurred(conn, e);"); for (int i = 0; i < listeners.size(); i++) { ConnectionEventListener listener = (ConnectionEventListener) listeners.get(i); ConnectionEvent event = new ConnectionEvent(this, e); listener.connectionErrorOccurred(event); } close(); } //## Java 1.4 end ##
@Override public synchronized void close() throws SQLException { if (!isClosed) { try { rollback(); setAutoCommit(true); } catch (SQLException e) { // ignore } closedHandle(); isClosed = true; } }
/** * End a transaction. * * @param xid the transaction id * @param flags TMSUCCESS, TMFAIL, or TMSUSPEND */ //## Java 1.4 begin ## public void end(Xid xid, int flags) throws XAException { if (debug()) { debugCode("end("+quoteXid(xid)+", "+quoteFlags(flags)+");"); } // TODO transaction end: implement this method if (flags == TMSUSPEND) { return; } if (!currentTransaction.equals(xid)) { getTrace().debug("throw XAException.XAER_OUTSIDE"); throw new XAException(XAException.XAER_OUTSIDE); } } //## Java 1.4 end ##
/** * 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; }