Class LocalXAConnectionFactory.LocalXAResource
java.lang.Object
org.apache.tomcat.dbcp.dbcp2.managed.LocalXAConnectionFactory.LocalXAResource
- All Implemented Interfaces:
- XAResource
- Enclosing class:
- LocalXAConnectionFactory
protected static class LocalXAConnectionFactory.LocalXAResource
extends Object
implements XAResource
LocalXAResource is a fake XAResource for non-XA connections. When a transaction is started the connection
 auto-commit is turned off. When the connection is committed or rolled back, the commit or rollback method is
 called on the connection and then the original auto-commit value is restored.
 
The LocalXAResource also respects the connection read-only setting. If the connection is read-only the commit method will not be called, and the prepare method returns the XA_RDONLY.
It is assumed that the wrapper around a managed connection disables the setAutoCommit(), commit(), rollback() and setReadOnly() methods while a transaction is in progress.
- Since:
- 2.0
- 
Field SummaryFields inherited from interface javax.transaction.xa.XAResourceTMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
- 
Constructor SummaryConstructorsConstructorDescriptionLocalXAResource(Connection localTransaction) Construct a new instance for a given connection.
- 
Method SummaryModifier and TypeMethodDescriptionvoidCommits the transaction and restores the original auto commit setting.voidThis method does nothing.voidClears the currently associated transaction if it is the specified xid.intAlways returns 0 since we have no way to set a transaction timeout on a JDBC connection.getXid()Gets the current xid of the transaction branch associated with this XAResource.booleanisSameRM(XAResource xaResource) Returns true if the specified XAResource == this XAResource.intThis method does nothing since the LocalXAConnection does not support two-phase-commit.Xid[]recover(int flag) Always returns a zero length Xid array.voidRolls back the transaction and restores the original auto commit setting.booleansetTransactionTimeout(int transactionTimeout) Always returns false since we have no way to set a transaction timeout on a JDBC connection.voidSignals that a the connection has been enrolled in a transaction.
- 
Constructor Details- 
LocalXAResourceConstruct a new instance for a given connection.- Parameters:
- localTransaction- A connection.
 
 
- 
- 
Method Details- 
commitCommits the transaction and restores the original auto commit setting.- Specified by:
- commitin interface- XAResource
- Parameters:
- xid- the id of the transaction branch for this connection
- flag- ignored
- Throws:
- XAException- if connection.commit() throws an SQLException
 
- 
endThis method does nothing.- Specified by:
- endin interface- XAResource
- Parameters:
- xid- the id of the transaction branch for this connection
- flag- ignored
- Throws:
- XAException- if the connection is already enlisted in another transaction
 
- 
forgetClears the currently associated transaction if it is the specified xid.- Specified by:
- forgetin interface- XAResource
- Parameters:
- xid- the id of the transaction to forget
 
- 
getTransactionTimeoutpublic int getTransactionTimeout()Always returns 0 since we have no way to set a transaction timeout on a JDBC connection.- Specified by:
- getTransactionTimeoutin interface- XAResource
- Returns:
- always 0
 
- 
getXidGets the current xid of the transaction branch associated with this XAResource.- Returns:
- the current xid of the transaction branch associated with this XAResource.
 
- 
isSameRMReturns true if the specified XAResource == this XAResource.- Specified by:
- isSameRMin interface- XAResource
- Parameters:
- xaResource- the XAResource to test
- Returns:
- true if the specified XAResource == this XAResource; false otherwise
 
- 
prepareThis method does nothing since the LocalXAConnection does not support two-phase-commit. This method will return XAResource.XA_RDONLY if the connection isReadOnly(). This assumes that the physical connection is wrapped with a proxy that prevents an application from changing the read-only flag while enrolled in a transaction.- Specified by:
- preparein interface- XAResource
- Parameters:
- xid- the id of the transaction branch for this connection
- Returns:
- XAResource.XA_RDONLY if the connection.isReadOnly(); XAResource.XA_OK otherwise
 
- 
recoverAlways returns a zero length Xid array. The LocalXAConnectionFactory can not support recovery, so no xids will ever be found.- Specified by:
- recoverin interface- XAResource
- Parameters:
- flag- ignored since recovery is not supported
- Returns:
- always a zero length Xid array.
 
- 
rollbackRolls back the transaction and restores the original auto commit setting.- Specified by:
- rollbackin interface- XAResource
- Parameters:
- xid- the id of the transaction branch for this connection
- Throws:
- XAException- if connection.rollback() throws an SQLException
 
- 
setTransactionTimeoutpublic boolean setTransactionTimeout(int transactionTimeout) Always returns false since we have no way to set a transaction timeout on a JDBC connection.- Specified by:
- setTransactionTimeoutin interface- XAResource
- Parameters:
- transactionTimeout- ignored since we have no way to set a transaction timeout on a JDBC connection
- Returns:
- always false
 
- 
startSignals that a the connection has been enrolled in a transaction. This method saves off the current auto commit flag, and then disables auto commit. The original auto commit setting is restored when the transaction completes.- Specified by:
- startin interface- XAResource
- Parameters:
- xid- the id of the transaction branch for this connection
- flag- either XAResource.TMNOFLAGS or XAResource.TMRESUME
- Throws:
- XAException- if the connection is already enlisted in another transaction, or if auto-commit could not be disabled
 
 
-