- All Implemented Interfaces:
XAResource
According to section 12.3 of the JDBC 3.0 spec, there is a 1:1 correspondence between XAConnection and XAResource, and A given XAConnection object may be associated with at most one transaction at a time. Therefore, there may be at any time at most one transaction managed by a XAResource object. One implication is, the XAResource can track the current transaction state with a scalar. Another implication is, the Xids for most of the XAResource interface methods just introduce unnecessary complexity and an unnecessary point of failure-- there can be only one transaction for this object, so why track another identifier for it. My strategy is to just "validate" that the Xid does not change within a transaction. Exceptions to this are the commit and rollback methods, which the JDBC spec says can operate against any XAResource instance from the same XADataSource. N.b. The JDBC Spec does not state whether the prepare and forget methods are XAResource-specific or XADataSource-specific.
- Since:
- 2.0.0
- Author:
- Blaine Simpson (blaine dot simpson at admc dot com)
- See Also:
-
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
ConstructorsConstructorDescriptionJDBCXAResource
(JDBCXADataSource xaDataSource, JDBCConnection connection) Constructs a resource using the given data source and connection. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Per the JDBC 3.0 spec, this commits the transaction for the specified Xid, not necessarily for the transaction associated with this XAResource object.void
commitThis
(boolean onePhase) This commits the connection associated with this XAResource.void
void
The XAResource API spec indicates implies that this is only for 2-phase transactions.int
boolean
isSameRM
(XAResource xares) Stub.int
Vote on whether to commit the global transaction.int
Xid[]
recover
(int flag) Obtain a list of Xids of the current resource manager for XAResources currently in the 'prepared' * state.void
Per the JDBC 3.0 spec, this rolls back the transaction for the specified Xid, not necessarily for the transaction associated with this XAResource object.void
This rolls back the connection associated with this XAResource.boolean
setTransactionTimeout
(int seconds) void
boolean
-
Constructor Details
-
JDBCXAResource
Constructs a resource using the given data source and connection.- Parameters:
xaDataSource
- JDBCXADataSourceconnection
- A non-wrapped JDBCConnection which we need in order to do real (non-wrapped) commits, rollbacks, etc. This is not for the end user. We need the real thing.
-
-
Method Details
-
withinGlobalTransaction
public boolean withinGlobalTransaction() -
commit
Per the JDBC 3.0 spec, this commits the transaction for the specified Xid, not necessarily for the transaction associated with this XAResource object.- Specified by:
commit
in interfaceXAResource
- Parameters:
xid
- XidonePhase
- boolean- Throws:
XAException
- on error
-
commitThis
This commits the connection associated with this XAResource.- Parameters:
onePhase
- boolean- Throws:
XAException
- generically, since the more specific exceptions require a JTA API to compile.
-
end
- Specified by:
end
in interfaceXAResource
- Throws:
XAException
-
forget
The XAResource API spec indicates implies that this is only for 2-phase transactions. I guess that one-phase transactions need to call rollback() to abort. I think we want this JDBCXAResource instance to be garbage-collectable after (a) this method is called, and (b) the tx manager releases its handle to it.- Specified by:
forget
in interfaceXAResource
- Parameters:
xid
- Xid- Throws:
XAException
- on error
-
getTransactionTimeout
- Specified by:
getTransactionTimeout
in interfaceXAResource
- Returns:
- int
- Throws:
XAException
- on error
-
isSameRM
Stub. See implementation comment in the method for why this is not implemented yet.- Specified by:
isSameRM
in interfaceXAResource
- Parameters:
xares
- XAResource- Returns:
- false.
- Throws:
XAException
- on error
-
prepare
Vote on whether to commit the global transaction. We assume Xid may be different from this, as in commit() method.- Specified by:
prepare
in interfaceXAResource
- Parameters:
xid
- Xid- Returns:
- commitType of XA_RDONLY or XA_OK. (Actually only XA_OK now).
- Throws:
XAException
- to vote negative.
-
prepareThis
- Throws:
XAException
-
recover
Obtain a list of Xids of the current resource manager for XAResources currently in the 'prepared' * state. According to the JDBC 3.0 spec, the Xids of a specific resource manager are those of the same XADataSource.- Specified by:
recover
in interfaceXAResource
- Parameters:
flag
- int- Returns:
- Xid[]
- Throws:
XAException
- on error
-
rollback
Per the JDBC 3.0 spec, this rolls back the transaction for the specified Xid, not necessarily for the transaction associated with this XAResource object.- Specified by:
rollback
in interfaceXAResource
- Parameters:
xid
- Xid- Throws:
XAException
- on error
-
rollbackThis
This rolls back the connection associated with this XAResource.- Throws:
XAException
- generically, since the more specific exceptions require a JTA API to compile.
-
setTransactionTimeout
- Specified by:
setTransactionTimeout
in interfaceXAResource
- Parameters:
seconds
- int- Returns:
- boolean
- Throws:
XAException
- on error
-
start
- Specified by:
start
in interfaceXAResource
- Throws:
XAException
-