public class JDBCXAResource
extends java.lang.Object
implements javax.transaction.xa.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
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(javax.transaction.xa.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(javax.transaction.xa.Xid xid,
int flags) |
void |
forget(javax.transaction.xa.Xid xid)
The XAResource API spec indicates implies that this is only for 2-phase
transactions.
|
int |
getTransactionTimeout() |
boolean |
isSameRM(javax.transaction.xa.XAResource xares)
Stub.
|
int |
prepare(javax.transaction.xa.Xid xid)
Vote on whether to commit the global transaction.
|
int |
prepareThis() |
javax.transaction.xa.Xid[] |
recover(int flag)
Obtain a list of Xids of the current resource manager for
XAResources currently in the 'prepared' * state.
|
void |
rollback(javax.transaction.xa.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(javax.transaction.xa.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(javax.transaction.xa.Xid xid, boolean onePhase) throws javax.transaction.xa.XAException
commit
in interface javax.transaction.xa.XAResource
xid
- XidonePhase
- booleanjavax.transaction.xa.XAException
- on errorpublic void commitThis(boolean onePhase) throws javax.transaction.xa.XAException
onePhase
- booleanjavax.transaction.xa.XAException
- generically, since the more specific exceptions
require a JTA API to compile.public void end(javax.transaction.xa.Xid xid, int flags) throws javax.transaction.xa.XAException
end
in interface javax.transaction.xa.XAResource
javax.transaction.xa.XAException
public void forget(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAException
forget
in interface javax.transaction.xa.XAResource
xid
- Xidjavax.transaction.xa.XAException
- on errorXAResource.forget(Xid)
public int getTransactionTimeout() throws javax.transaction.xa.XAException
getTransactionTimeout
in interface javax.transaction.xa.XAResource
javax.transaction.xa.XAException
- on errorpublic boolean isSameRM(javax.transaction.xa.XAResource xares) throws javax.transaction.xa.XAException
isSameRM
in interface javax.transaction.xa.XAResource
xares
- XAResourcejavax.transaction.xa.XAException
- on errorpublic int prepare(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAException
prepare
in interface javax.transaction.xa.XAResource
xid
- Xidjavax.transaction.xa.XAException
- to vote negative.public int prepareThis() throws javax.transaction.xa.XAException
javax.transaction.xa.XAException
public javax.transaction.xa.Xid[] recover(int flag) throws javax.transaction.xa.XAException
recover
in interface javax.transaction.xa.XAResource
flag
- intjavax.transaction.xa.XAException
- on errorpublic void rollback(javax.transaction.xa.Xid xid) throws javax.transaction.xa.XAException
rollback
in interface javax.transaction.xa.XAResource
xid
- Xidjavax.transaction.xa.XAException
- on errorpublic void rollbackThis() throws javax.transaction.xa.XAException
javax.transaction.xa.XAException
- generically, since the more
specific exceptions require a JTA API to compile.public boolean setTransactionTimeout(int seconds) throws javax.transaction.xa.XAException
setTransactionTimeout
in interface javax.transaction.xa.XAResource
seconds
- intjavax.transaction.xa.XAException
- on errorpublic void start(javax.transaction.xa.Xid xid, int flags) throws javax.transaction.xa.XAException
start
in interface javax.transaction.xa.XAResource
javax.transaction.xa.XAException
Copyright © 2001 - 2017 HSQL Development Group.