public class JDBCXAResource extends Object implements 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.
XAResource
TMENDRSCAN, TMFAIL, TMJOIN, TMNOFLAGS, TMONEPHASE, TMRESUME, TMSTARTRSCAN, TMSUCCESS, TMSUSPEND, XA_OK, XA_RDONLY
Constructor and Description |
---|
JDBCXAResource(JDBCXADataSource xaDataSource,
JDBCConnection connection)
Constructs a resource using the given data source and connection.
|
Modifier and Type | Method and Description |
---|---|
void |
commit(Xid xid,
boolean onePhase)
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 |
end(Xid xid,
int flags) |
void |
forget(Xid xid)
The XAResource API spec indicates implies that this is only for 2-phase
transactions.
|
int |
getTransactionTimeout() |
boolean |
isSameRM(XAResource xares)
Stub.
|
int |
prepare(Xid xid)
Vote on whether to commit the global transaction.
|
int |
prepareThis() |
Xid[] |
recover(int flag)
Obtain a list of Xids of the current resource manager for
XAResources currently in the 'prepared' * state.
|
void |
rollback(Xid xid)
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 |
rollbackThis()
This rolls back the connection associated with this XAResource.
|
boolean |
setTransactionTimeout(int seconds) |
void |
start(Xid xid,
int flags) |
boolean |
withinGlobalTransaction() |
public JDBCXAResource(JDBCXADataSource xaDataSource, JDBCConnection connection)
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.public boolean withinGlobalTransaction()
public void commit(Xid xid, boolean onePhase) throws XAException
commit
in interface XAResource
xid
- XidonePhase
- booleanXAException
- on errorpublic void commitThis(boolean onePhase) throws XAException
onePhase
- booleanXAException
- generically, since the more specific exceptions
require a JTA API to compile.public void end(Xid xid, int flags) throws XAException
end
in interface XAResource
XAException
public void forget(Xid xid) throws XAException
forget
in interface XAResource
xid
- XidXAException
- on errorXAResource.forget(Xid)
public int getTransactionTimeout() throws XAException
getTransactionTimeout
in interface XAResource
XAException
- on errorpublic boolean isSameRM(XAResource xares) throws XAException
isSameRM
in interface XAResource
xares
- XAResourceXAException
- on errorpublic int prepare(Xid xid) throws XAException
prepare
in interface XAResource
xid
- XidXAException
- to vote negative.public int prepareThis() throws XAException
XAException
public Xid[] recover(int flag) throws XAException
recover
in interface XAResource
flag
- intXAException
- on errorpublic void rollback(Xid xid) throws XAException
rollback
in interface XAResource
xid
- XidXAException
- on errorpublic void rollbackThis() throws XAException
XAException
- generically, since the more
specific exceptions require a JTA API to compile.public boolean setTransactionTimeout(int seconds) throws XAException
setTransactionTimeout
in interface XAResource
seconds
- intXAException
- on errorpublic void start(Xid xid, int flags) throws XAException
start
in interface XAResource
XAException
Copyright © 2001 - 2017 HSQL Development Group.