public static XAConnection createXAConnection(Connection physicalConn) throws SQLException { return new PGXAConnection((BaseConnection) physicalConn); }
@Override public void commit(Xid xid, boolean onePhase) throws XAException { if (LOGGER.isLoggable(Level.FINEST)) { debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)")); } if (xid == null) { throw new PGXAException(GT.tr("xid must not be null"), XAException.XAER_INVAL); } if (onePhase) { commitOnePhase(xid); } else { commitPrepared(xid); } }
private int mapSQLStateToXAErrorCode(SQLException sqlException) { if (isPostgreSQLIntegrityConstraintViolation(sqlException)) { return XAException.XA_RBINTEGRITY; } return XAException.XAER_RMFAIL; }
/**** XAConnection interface ****/ public Connection getConnection() throws SQLException { if (logger.logDebug()) debug("PGXAConnection.getConnection called"); Connection conn = super.getConnection(); // When we're outside an XA transaction, autocommit // is supposed to be true, per usual JDBC convention. // When an XA transaction is in progress, it should be // false. if(state == STATE_IDLE) conn.setAutoCommit(true); /* * Wrap the connection in a proxy to forbid application from * fiddling with transaction state directly during an XA transaction */ ConnectionHandler handler = new ConnectionHandler(conn); return (Connection)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{Connection.class, PGConnection.class}, handler); }
public int prepare(Xid xid) throws XAException { if (LOGGER.isLoggable(Level.FINEST)) { debug("preparing transaction xid = " + xid); debug("Prepare xid " + xid + " but current connection is not attached to a transaction" + " while it was prepared in past with prepared xid " + preparedXid); debug("Error to prepare xid " + xid + ", the current connection already bound with xid " + currentXid); throw new PGXAException(GT.tr("Error preparing transaction. prepare xid={0}", xid), ex, mapSQLStateToXAErrorCode(ex));
conn.setAutoCommit(localAutoCommitMode); } catch (SQLException ex) { throw new PGXAException(GT.tr("Error during one-phase commit. commit xid={0}", xid), ex, mapSQLStateToXAErrorCode(ex));
public void rollback(Xid xid) throws XAException { if (LOGGER.isLoggable(Level.FINEST)) { debug("rolling back xid = " + xid); if (committedOrRolledBack || !xid.equals(preparedXid)) { if (LOGGER.isLoggable(Level.FINEST)) { debug("rolling back xid " + xid + " while the connection prepared xid is " + preparedXid + (committedOrRolledBack ? ", but the connection was already committed/rolled-back" : "")); debug("rollback connection failure (sql error code " + ex.getSQLState() + "), reconnection could be expected");
public void commit(Xid xid, boolean onePhase) throws XAException { if (logger.logDebug()) debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)")); if (xid == null) throw new PGXAException(GT.tr("xid must not be null"), XAException.XAER_INVAL); if (onePhase) commitOnePhase(xid); else commitPrepared(xid); }
if (committedOrRolledBack || !xid.equals(preparedXid)) { if (LOGGER.isLoggable(Level.FINEST)) { debug("committing xid " + xid + " while the connection prepared xid is " + preparedXid + (committedOrRolledBack ? ", but the connection was already committed/rolled-back" : "")); debug("commit connection failure (sql error code " + ex.getSQLState() + "), reconnection could be expected");
@SneakyThrows @Override public XAConnection wrap(final XADataSource xaDataSource, final Connection connection) { BaseConnection physicalConnection = (BaseConnection) connection.unwrap(Class.forName("org.postgresql.core.BaseConnection")); return new PGXAConnection(physicalConnection); } }
public void commit(Xid xid, boolean onePhase) throws XAException { if (logger.logDebug()) debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)")); if (xid == null) throw new PGXAException(GT.tr("xid must not be null"), XAException.XAER_INVAL); if (onePhase) commitOnePhase(xid); else commitPrepared(xid); }
debug("rolling back xid = " + xid);
/** * Gets a XA-enabled connection to the PostgreSQL database. The database is identified by the * DataSource properties serverName, databaseName, and portNumber. The user to connect as is * identified by the arguments user and password, which override the DataSource properties by the * same name. * * @return A valid database connection. * @throws SQLException Occurs when the database connection cannot be established. */ public XAConnection getXAConnection(String user, String password) throws SQLException { Connection con = super.getConnection(user, password); return new PGXAConnection((BaseConnection) con); }
public void commit(Xid xid, boolean onePhase) throws XAException { if (logger.logDebug()) debug("committing xid = " + xid + (onePhase ? " (one phase) " : " (two phase)")); if (xid == null) throw new PGXAException(GT.tr("xid must not be null"), XAException.XAER_INVAL); if (onePhase) commitOnePhase(xid); else commitPrepared(xid); }
public void end(Xid xid, int flags) throws XAException { if (LOGGER.isLoggable(Level.FINEST)) { debug("ending transaction xid = " + xid);
/** * Gets a XA-enabled connection to the PostgreSQL database. The database is identified by the * DataSource properties serverName, databaseName, and portNumber. The user to * connect as is identified by the arguments user and password, which override * the DataSource properties by the same name. * * @return A valid database connection. * @throws SQLException * Occurs when the database connection cannot be established. */ public XAConnection getXAConnection(String user, String password) throws SQLException { Connection con = super.getConnection(user, password); return new PGXAConnection((BaseConnection) con); }
/** * Preconditions: * 1. Flags is one of TMSUCCESS, TMFAIL, TMSUSPEND * 2. xid != null * 3. Connection is associated with transaction xid * * Implementation deficiency preconditions: * 1. Flags is not TMSUSPEND * * Postconditions: * 1. connection is disassociated from the transaction. */ public void end(Xid xid, int flags) throws XAException { if (logger.logDebug()) debug("ending transaction xid = " + xid); // Check preconditions if (flags != XAResource.TMSUSPEND && flags != XAResource.TMFAIL && flags != XAResource.TMSUCCESS) throw new PGXAException(GT.tr("Invalid flags"), XAException.XAER_INVAL); if (xid == null) throw new PGXAException(GT.tr("xid must not be null"), XAException.XAER_INVAL); if (state != STATE_ACTIVE || !currentXid.equals(xid)) throw new PGXAException(GT.tr("tried to call end without corresponding start call"), XAException.XAER_PROTO); // Check implementation deficiency preconditions if (flags == XAResource.TMSUSPEND) throw new PGXAException(GT.tr("suspend/resume not implemented"), XAException.XAER_RMERR); // We ignore TMFAIL. It's just a hint to the RM. We could roll back immediately // if TMFAIL was given. // All clear. We don't have any real work to do. state = STATE_ENDED; }
public static XAConnection createXAConnection(Connection physicalConn) throws SQLException { return new PGXAConnection((BaseConnection) physicalConn); }
debug("preparing transaction xid = " + xid);
/** * Gets a XA-enabled connection to the PostgreSQL database. The database is identified by the * DataSource properties serverName, databaseName, and portNumber. The user to * connect as is identified by the arguments user and password, which override * the DataSource properties by the same name. * * @return A valid database connection. * @throws SQLException * Occurs when the database connection cannot be established. */ public XAConnection getXAConnection(String user, String password) throws SQLException { Connection con = super.getConnection(user, password); return new PGXAConnection((BaseConnection) con); }