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.
javax.transaction.xa.XAResource
| Modifier and Type | Field and Description |
|---|---|
| private JDBCConnection | |
| private boolean | |
| pack-priv int | |
| pack-priv static int | |
| pack-priv static int | |
| pack-priv static int | |
| pack-priv static int | |
| pack-priv static int | |
| private JDBCXADataSource | |
| pack-priv Xid |
| Access | Constructor and Description |
|---|---|
| public | JDBCXAResource(JDBCXADataSource
JDBCXADataSource xaDataSource, JDBCConnection 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. connection)Constructs a resource using the given data source and connection. |
| Modifier and Type | Method and Description |
|---|---|
| public void | commit(Xid
Xid xid, boolean boolean onePhase)Implements javax. Per the JDBC 3.0 spec, this commits the transaction for the specified Xid, not necessarily for the transaction associated with this XAResource object. |
| public void | |
| private void | |
| public void | end(Xid xid, int flags)
Implements javax. Ends the work performed on behalf of a transaction branch. |
| public void | forget(Xid
Xid xid)Implements javax. The XAResource API spec indicates implies that this is only for 2-phase transactions. |
| pack-priv JDBCConnection | |
| public int | Returns: intImplements javax. Obtains the current transaction timeout value set for this XAResource instance. |
| pack-priv JDBCXADataSource | |
| public boolean | Returns: false.XAResource xares)Implements javax. Stub. |
| public int | Returns: commitType of XA_RDONLY or XA_OK. (Actually only XA_OK now).Xid xid)Implements javax. Vote on whether to commit the global transaction. |
| public int | |
| public Xid[] | Returns: Xid[]int flag)Implements javax. Obtain a list of Xids of the current resource manager for XAResources currently in the 'prepared' * state. |
| public void | rollback(Xid
Xid xid)Implements javax. 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. |
| public void | |
| pack-priv void | |
| public boolean | Returns: booleanint seconds)Implements javax. Sets the current transaction timeout value for this |
| public void | start(Xid xid, int flags)
Implements javax. Starts work on behalf of a transaction branch specified in
|
| private void | |
| public boolean |
| connection | back to summary |
|---|---|
| private JDBCConnection connection | |
| originalAutoCommitMode | back to summary |
|---|---|
| private boolean originalAutoCommitMode | |
| state | back to summary |
|---|---|
| pack-priv int state | |
| XA_STATE_DISPOSED | back to summary |
|---|---|
| pack-priv static int XA_STATE_DISPOSED | |
| XA_STATE_ENDED | back to summary |
|---|---|
| pack-priv static int XA_STATE_ENDED | |
| XA_STATE_INITIAL | back to summary |
|---|---|
| pack-priv static int XA_STATE_INITIAL | |
| XA_STATE_PREPARED | back to summary |
|---|---|
| pack-priv static int XA_STATE_PREPARED | |
| XA_STATE_STARTED | back to summary |
|---|---|
| pack-priv static int XA_STATE_STARTED | |
| xaDataSource | back to summary |
|---|---|
| private JDBCXADataSource xaDataSource | |
| xid | back to summary |
|---|---|
| pack-priv Xid xid | |
| JDBCXAResource | back to summary |
|---|---|
| public JDBCXAResource(JDBCXADataSource xaDataSource, JDBCConnection connection) Constructs a resource using the given data source and connection.
| |
| commit | back to summary |
|---|---|
| public void commit(Xid xid, boolean onePhase) throws XAException Implements javax. Per the JDBC 3.0 spec, this commits the transaction for the specified Xid, not necessarily for the transaction associated with this XAResource object.
| |
| commitThis | back to summary |
|---|---|
| public void commitThis(boolean onePhase) throws XAException This commits the connection associated with this XAResource.
| |
| dispose | back to summary |
|---|---|
| private void dispose() throws XAException | |
| end | back to summary |
|---|---|
| public void end(Xid xid, int flags) throws XAException Implements javax. Doc from javax. Ends the work performed on behalf of a transaction branch. The resource manager disassociates the XA resource from the transaction branch specified and lets the transaction complete. If TMSUSPEND is specified in the flags, the transaction branch
is temporarily suspended in an incomplete state. The transaction
context is in a suspended state and must be resumed via the
If TMFAIL is specified, the portion of work has failed. The resource manager may mark the transaction as rollback-only If TMSUCCESS is specified, the portion of work has completed successfully.
| |
| forget | back to summary |
|---|---|
| public void forget(Xid xid) throws XAException Implements javax. 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.
| |
| getConnection | back to summary |
|---|---|
| pack-priv JDBCConnection getConnection() | |
| getTransactionTimeout | back to summary |
|---|---|
| public int getTransactionTimeout() throws XAException Implements javax. Doc from javax. Obtains the current transaction timeout value set for this
XAResource instance. If
| |
| getXADataSource | back to summary |
|---|---|
| pack-priv JDBCXADataSource getXADataSource() | |
| isSameRM | back to summary |
|---|---|
| public boolean isSameRM(XAResource xares) throws XAException Implements javax. Stub. See implementation comment in the method for why this is not implemented yet.
| |
| prepare | back to summary |
|---|---|
| public int prepare(Xid xid) throws XAException Implements javax. Vote on whether to commit the global transaction. We assume Xid may be different from this, as in commit() method.
| |
| prepareThis | back to summary |
|---|---|
| public int prepareThis() throws XAException | |
| recover | back to summary |
|---|---|
| public Xid[] recover(int flag) throws XAException Implements javax. 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.
| |
| rollback | back to summary |
|---|---|
| public void rollback(Xid xid) throws XAException Implements javax. 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.
| |
| rollbackThis | back to summary |
|---|---|
| public void rollbackThis() throws XAException This rolls back the connection associated with this XAResource.
| |
| setConnection | back to summary |
|---|---|
| pack-priv void setConnection(JDBCConnection userConnection) | |
| setTransactionTimeout | back to summary |
|---|---|
| public boolean setTransactionTimeout(int seconds) throws XAException Implements javax. Doc from javax. Sets the current transaction timeout value for this
| |
| start | back to summary |
|---|---|
| public void start(Xid xid, int flags) throws XAException Implements javax. Doc from javax. Starts work on behalf of a transaction branch specified in
| |
| validateXid | back to summary |
|---|---|
private void validateXid(Xid xid) throws XAException
| |
| withinGlobalTransaction | back to summary |
|---|---|
| public boolean withinGlobalTransaction() | |