public class StandardXAConnection extends StandardPooledConnection implements javax.sql.XAConnection, javax.transaction.xa.XAResource, javax.naming.Referenceable, java.lang.Runnable
To accomodate this, the StandardXADataSource class maintains a list of Connection objects. When the Transaction Manager associates an XID with a StandardXAConnection, it looks for a physical connection which is associated with that transaction.
The "current" connection (super.con and curCon) is the connection currently being used by the application (i.e. getConnection has been called, but not Connection.close()). The current connection is removed and handed to the data source if it becomes associated with a global transaction.
| Modifier and Type | Field and Description |
|---|---|
StandardXAConnectionHandle |
connectionHandle |
protected StandardXAStatefulConnection |
curCon |
boolean |
thisAutoCommit |
java.lang.Thread |
timerThread |
javax.transaction.TransactionManager |
transactionManager |
protected StandardXADataSource |
xaDataSource |
con, dataSource, log| Constructor and Description |
|---|
StandardXAConnection(StandardXADataSource dataSource,
java.lang.String user,
java.lang.String password)
Creates the first free connection.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addStatementEventListener(javax.sql.StatementEventListener listener) |
StandardXAStatefulConnection |
checkPreparedState(javax.transaction.xa.Xid xid)
Does most of the work of a generic prepare.
|
void |
close()
Close this XA connection.
|
void |
commit(javax.transaction.xa.Xid xid,
boolean onePhase)
Performs a commit on this resource manager's branch of
the global transaction.
|
void |
doStart(javax.transaction.xa.Xid xid,
int flags)
Does most of the work of the start() call (below).
|
void |
end(javax.transaction.xa.Xid xid,
int flags)
Ends a connection's association with a global transaction.
|
void |
forget(javax.transaction.xa.Xid xid)
This is called by a TM when the RM has reported a heuristic
completion.
|
boolean |
getCommitOnPrepare() |
java.sql.Connection |
getConnection()
Creates a new StandardXAConnectionHandle for use by an application.
|
javax.naming.Reference |
getReference() |
int |
getTransactionTimeout() |
javax.transaction.xa.XAResource |
getXAResource()
We are required to maintain a 1-1 mapping between an XAConnection
and its corresponding XAResource.
|
boolean |
isSameRM(javax.transaction.xa.XAResource xares) |
protected void |
newConnectionHandle() |
int |
prepare(javax.transaction.xa.Xid xid)
Prepares to perform a commit.
|
javax.transaction.xa.Xid[] |
recover(int flag)
Called by the transaction manager during recovery.
|
void |
removeStatementEventListener(javax.sql.StatementEventListener listener) |
void |
rollback(javax.transaction.xa.Xid xid)
PERFORMS a rollback on this resource manager's branch of
the global transaction.
|
void |
run()
Periodically checks for timed out connections.
|
void |
setCommitOnPrepare(boolean commitOnPrepare) |
void |
setTransactionManager(javax.transaction.TransactionManager tm) |
boolean |
setTransactionTimeout(int seconds)
Accessor methods for timeout.
|
void |
start(javax.transaction.xa.Xid xid,
int flags)
Associates this XAConnection with a global transaction.
|
java.lang.String |
toString() |
addConnectionEventListener, connectionErrorOccurred, getPhysicalConnection, removeConnectionEventListener, setLoggerprotected StandardXAStatefulConnection curCon
public java.lang.Thread timerThread
public javax.transaction.TransactionManager transactionManager
public StandardXAConnectionHandle connectionHandle
protected StandardXADataSource xaDataSource
public boolean thisAutoCommit
public StandardXAConnection(StandardXADataSource dataSource, java.lang.String user, java.lang.String password) throws java.sql.SQLException
java.sql.SQLExceptionpublic javax.transaction.xa.XAResource getXAResource()
getXAResource in interface javax.sql.XAConnectionpublic java.sql.Connection getConnection()
throws java.sql.SQLException
This method always returns a Connection in the free state (i.e. (not associated with an Xid). This is necessary since, unless Start (Xid, flags) gets called, the Connection must do local transaction processing.
getConnection in interface javax.sql.PooledConnectiongetConnection in class StandardPooledConnectionjava.sql.SQLExceptionprotected void newConnectionHandle()
newConnectionHandle in class StandardPooledConnectionpublic void setTransactionManager(javax.transaction.TransactionManager tm)
public void close()
throws java.sql.SQLException
close in interface javax.sql.PooledConnectionclose in class StandardPooledConnectionjava.sql.SQLExceptionpublic void doStart(javax.transaction.xa.Xid xid,
int flags)
throws javax.transaction.xa.XAException
javax.transaction.xa.XAExceptionpublic void start(javax.transaction.xa.Xid xid,
int flags)
throws javax.transaction.xa.XAException
start in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic void end(javax.transaction.xa.Xid xid,
int flags)
throws javax.transaction.xa.XAException
It need not act on the current transaction. There is an interval between being returned to the pool manager and being invoked by the transaction manager during which the current connection can change.
Note that the only effect is to change the connection state.
end in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic StandardXAStatefulConnection checkPreparedState(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAException
javax.transaction.xa.XAExceptionpublic int prepare(javax.transaction.xa.Xid xid)
throws javax.transaction.xa.XAException
prepare in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic void commit(javax.transaction.xa.Xid xid,
boolean onePhase)
throws javax.transaction.xa.XAException
commit in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic void rollback(javax.transaction.xa.Xid xid)
throws javax.transaction.xa.XAException
rollback in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic boolean isSameRM(javax.transaction.xa.XAResource xares)
throws javax.transaction.xa.XAException
isSameRM in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic void forget(javax.transaction.xa.Xid xid)
throws javax.transaction.xa.XAException
forget in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic javax.transaction.xa.Xid[] recover(int flag)
throws javax.transaction.xa.XAException
recover in interface javax.transaction.xa.XAResourcejavax.transaction.xa.XAExceptionpublic boolean setTransactionTimeout(int seconds)
setTransactionTimeout in interface javax.transaction.xa.XAResourcepublic int getTransactionTimeout()
getTransactionTimeout in interface javax.transaction.xa.XAResourcepublic void setCommitOnPrepare(boolean commitOnPrepare)
public boolean getCommitOnPrepare()
public void run()
run in interface java.lang.Runnablepublic javax.naming.Reference getReference()
throws javax.naming.NamingException
getReference in interface javax.naming.Referenceablejavax.naming.NamingExceptionpublic java.lang.String toString()
toString in class StandardPooledConnectionpublic void removeStatementEventListener(javax.sql.StatementEventListener listener)
removeStatementEventListener in interface javax.sql.PooledConnectionremoveStatementEventListener in class StandardPooledConnectionpublic void addStatementEventListener(javax.sql.StatementEventListener listener)
addStatementEventListener in interface javax.sql.PooledConnectionaddStatementEventListener in class StandardPooledConnection