Package org.postgresql.xa
Class PGXAConnection
- java.lang.Object
-
- org.postgresql.ds.PGPooledConnection
-
- org.postgresql.xa.PGXAConnection
-
- All Implemented Interfaces:
PooledConnection,XAConnection,XAResource
public class PGXAConnection extends PGPooledConnection implements XAConnection, XAResource
The PostgreSQL implementation of
XAResource.This implementation doesn't support transaction interleaving (see JTA specification, section 3.4.4) and suspend/resume.
Two-phase commit requires PostgreSQL server version 8.1 or higher.
- Author:
- Heikki Linnakangas (heikki.linnakangas@iki.fi)
-
-
Field Summary
-
Fields inherited from interface javax.transaction.xa.XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
-
-
Constructor Summary
Constructors Constructor Description PGXAConnection(BaseConnection conn)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcommit(Xid xid, boolean onePhase)voidend(Xid xid, int flags)Preconditions:voidforget(Xid xid)Does nothing, since we don't do heuristics.ConnectiongetConnection()XAConnection interface.intgetTransactionTimeout()We don't do transaction timeouts.XAResourcegetXAResource()booleanisSameRM(XAResource xares)intprepare(Xid xid)Prepares transaction.Xid[]recover(int flag)Recovers transaction.voidrollback(Xid xid)Preconditions:booleansetTransactionTimeout(int seconds)We don't do transaction timeouts.voidstart(Xid xid, int flags)Preconditions:-
Methods inherited from class org.postgresql.ds.PGPooledConnection
addConnectionEventListener, addStatementEventListener, close, createConnectionEvent, removeConnectionEventListener, removeStatementEventListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.sql.PooledConnection
addConnectionEventListener, addStatementEventListener, close, removeConnectionEventListener, removeStatementEventListener
-
-
-
-
Constructor Detail
-
PGXAConnection
public PGXAConnection(BaseConnection conn) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
getConnection
public Connection getConnection() throws SQLException
XAConnection interface.- Specified by:
getConnectionin interfacePooledConnection- Overrides:
getConnectionin classPGPooledConnection- Throws:
SQLException
-
getXAResource
public XAResource getXAResource()
- Specified by:
getXAResourcein interfaceXAConnection
-
start
public void start(Xid xid, int flags) throws XAException
Preconditions:
- Flags must be one of TMNOFLAGS, TMRESUME or TMJOIN
- xid != null
- Connection must not be associated with a transaction
- The TM hasn't seen the xid before
Implementation deficiency preconditions:
- TMRESUME not supported.
- If flags is TMJOIN, we must be in ended state, and xid must be the current transaction
- Unless flags is TMJOIN, previous transaction using the connection must be committed or prepared or rolled back
Postconditions:
- Connection is associated with the transaction
- Specified by:
startin interfaceXAResource- Throws:
XAException
-
end
public void end(Xid xid, int flags) throws XAException
Preconditions:
- Flags is one of TMSUCCESS, TMFAIL, TMSUSPEND
- xid != null
- Connection is associated with transaction xid
Implementation deficiency preconditions:
- Flags is not TMSUSPEND
Postconditions:
- Connection is disassociated from the transaction.
- Specified by:
endin interfaceXAResource- Throws:
XAException
-
prepare
public int prepare(Xid xid) throws XAException
Prepares transaction. Preconditions:
- xid != null
- xid is in ended state
Implementation deficiency preconditions:
- xid was associated with this connection
Postconditions:
- Transaction is prepared
- Specified by:
preparein interfaceXAResource- Throws:
XAException
-
recover
public Xid[] recover(int flag) throws XAException
Recovers transaction. Preconditions:
- flag must be one of TMSTARTRSCAN, TMENDRSCAN, TMNOFLAGS or TMSTARTTRSCAN | TMENDRSCAN
- If flag isn't TMSTARTRSCAN or TMSTARTRSCAN | TMENDRSCAN, a recovery scan must be in progress
Postconditions:
- list of prepared xids is returned
- Specified by:
recoverin interfaceXAResource- Throws:
XAException
-
rollback
public void rollback(Xid xid) throws XAException
Preconditions:
- xid is known to the RM or it's in prepared state
Implementation deficiency preconditions:
- xid must be associated with this connection if it's not in prepared state.
Postconditions:
- Transaction is rolled back and disassociated from connection
- Specified by:
rollbackin interfaceXAResource- Throws:
XAException
-
commit
public void commit(Xid xid, boolean onePhase) throws XAException
- Specified by:
commitin interfaceXAResource- Throws:
XAException
-
isSameRM
public boolean isSameRM(XAResource xares) throws XAException
- Specified by:
isSameRMin interfaceXAResource- Throws:
XAException
-
forget
public void forget(Xid xid) throws XAException
Does nothing, since we don't do heuristics.- Specified by:
forgetin interfaceXAResource- Throws:
XAException
-
getTransactionTimeout
public int getTransactionTimeout()
We don't do transaction timeouts. Just returns 0.- Specified by:
getTransactionTimeoutin interfaceXAResource
-
setTransactionTimeout
public boolean setTransactionTimeout(int seconds)
We don't do transaction timeouts. Returns false.- Specified by:
setTransactionTimeoutin interfaceXAResource
-
-