Package org.apache.commons.dbcp.managed
Class LocalXAConnectionFactory.LocalXAResource
- java.lang.Object
-
- org.apache.commons.dbcp.managed.LocalXAConnectionFactory.LocalXAResource
-
- All Implemented Interfaces:
javax.transaction.xa.XAResource
- Enclosing class:
- LocalXAConnectionFactory
protected static class LocalXAConnectionFactory.LocalXAResource extends java.lang.Object implements javax.transaction.xa.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.
-
-
Constructor Summary
Constructors Constructor Description LocalXAResource(java.sql.Connection localTransaction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
commit(javax.transaction.xa.Xid xid, boolean flag)
Commits the transaction and restores the original auto commit setting.void
end(javax.transaction.xa.Xid xid, int flag)
This method does nothing.void
forget(javax.transaction.xa.Xid xid)
Clears the currently associated transaction if it is the specified xid.int
getTransactionTimeout()
Always returns 0 since we have no way to set a transaction timeout on a JDBC connection.javax.transaction.xa.Xid
getXid()
Gets the current xid of the transaction branch associated with this XAResource.boolean
isSameRM(javax.transaction.xa.XAResource xaResource)
Returns true if the specified XAResource == this XAResource.int
prepare(javax.transaction.xa.Xid xid)
This method does nothing since the LocalXAConnection does not support two-phase-commit.javax.transaction.xa.Xid[]
recover(int flag)
Always returns a zero length Xid array.void
rollback(javax.transaction.xa.Xid xid)
Rolls back the transaction and restores the original auto commit setting.boolean
setTransactionTimeout(int transactionTimeout)
Always returns false since we have no way to set a transaction timeout on a JDBC connection.void
start(javax.transaction.xa.Xid xid, int flag)
Signals that a the connection has been enrolled in a transaction.
-
-
-
Method Detail
-
getXid
public javax.transaction.xa.Xid getXid()
Gets the current xid of the transaction branch associated with this XAResource.- Returns:
- the current xid of the transaction branch associated with this XAResource.
-
start
public void start(javax.transaction.xa.Xid xid, int flag) throws javax.transaction.xa.XAException
Signals 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:
start
in interfacejavax.transaction.xa.XAResource
- Parameters:
xid
- the id of the transaction branch for this connectionflag
- either XAResource.TMNOFLAGS or XAResource.TMRESUME- Throws:
javax.transaction.xa.XAException
- if the connection is already enlisted in another transaction, or if auto-commit could not be disabled
-
end
public void end(javax.transaction.xa.Xid xid, int flag) throws javax.transaction.xa.XAException
This method does nothing.- Specified by:
end
in interfacejavax.transaction.xa.XAResource
- Parameters:
xid
- the id of the transaction branch for this connectionflag
- ignored- Throws:
javax.transaction.xa.XAException
- if the connection is already enlisted in another transaction
-
prepare
public int prepare(javax.transaction.xa.Xid xid)
This 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:
prepare
in interfacejavax.transaction.xa.XAResource
- Parameters:
xid
- the id of the transaction branch for this connection- Returns:
- XAResource.XA_RDONLY if the connection.isReadOnly(); XAResource.XA_OK otherwise
-
commit
public void commit(javax.transaction.xa.Xid xid, boolean flag) throws javax.transaction.xa.XAException
Commits the transaction and restores the original auto commit setting.- Specified by:
commit
in interfacejavax.transaction.xa.XAResource
- Parameters:
xid
- the id of the transaction branch for this connectionflag
- ignored- Throws:
javax.transaction.xa.XAException
- if connection.commit() throws a SQLException
-
rollback
public void rollback(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAException
Rolls back the transaction and restores the original auto commit setting.- Specified by:
rollback
in interfacejavax.transaction.xa.XAResource
- Parameters:
xid
- the id of the transaction branch for this connection- Throws:
javax.transaction.xa.XAException
- if connection.rollback() throws a SQLException
-
isSameRM
public boolean isSameRM(javax.transaction.xa.XAResource xaResource)
Returns true if the specified XAResource == this XAResource.- Specified by:
isSameRM
in interfacejavax.transaction.xa.XAResource
- Parameters:
xaResource
- the XAResource to test- Returns:
- true if the specified XAResource == this XAResource; false otherwise
-
forget
public void forget(javax.transaction.xa.Xid xid)
Clears the currently associated transaction if it is the specified xid.- Specified by:
forget
in interfacejavax.transaction.xa.XAResource
- Parameters:
xid
- the id of the transaction to forget
-
recover
public javax.transaction.xa.Xid[] recover(int flag)
Always returns a zero length Xid array. The LocalXAConnectionFactory can not support recovery, so no xids will ever be found.- Specified by:
recover
in interfacejavax.transaction.xa.XAResource
- Parameters:
flag
- ignored since recovery is not supported- Returns:
- always a zero length Xid array.
-
getTransactionTimeout
public int getTransactionTimeout()
Always returns 0 since we have no way to set a transaction timeout on a JDBC connection.- Specified by:
getTransactionTimeout
in interfacejavax.transaction.xa.XAResource
- Returns:
- always 0
-
setTransactionTimeout
public boolean setTransactionTimeout(int transactionTimeout)
Always returns false since we have no way to set a transaction timeout on a JDBC connection.- Specified by:
setTransactionTimeout
in interfacejavax.transaction.xa.XAResource
- Parameters:
transactionTimeout
- ignored since we have no way to set a transaction timeout on a JDBC connection- Returns:
- always false
-
-