Package org.apache.derby.jdbc
Class XATransactionState
- java.lang.Object
-
- org.apache.derby.iapi.services.context.ContextImpl
-
- org.apache.derby.jdbc.XATransactionState
-
- All Implemented Interfaces:
Context
final class XATransactionState extends ContextImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classXATransactionState.CancelXATransactionTaskThe implementation of TimerTask to cancel a global transaction.private static classXATransactionState.CleanupOrCancelMonitorA class used to monitor if the transaction is in the middle of cancelling or cleaning up on an error.
-
Field Summary
Fields Modifier and Type Field Description private EmbedXAResourceassociatedResource(package private) intassociationStateAssociation state of the transaction.(package private) XATransactionState.CleanupOrCancelMonitorcleanupOrCancelMonitor(package private) EmbedConnectionconn(package private) EmbedXAResourcecreatingResource(package private) booleanisPreparedhas this transaction been prepared.(package private) booleanperformTimeoutRollbackIndicates whether this transaction is supposed to be rolled back by timeout.(package private) introllbackOnlyCode(package private) java.util.HashMap<EmbedXAResource,XATransactionState>suspendedListWhen an XAResource suspends a transaction (end(TMSUSPEND)) it must be resumed using the same XAConnection.(package private) static intT0_NOT_ASSOCIATED(package private) static intT1_ASSOCIATED(package private) static intTC_COMPLETED(package private) XATransactionState.CancelXATransactionTasktimeoutTaskA timer task scheduled for the time when the transaction will timeout.(package private) static intTRO_DEADLOCKRollback-only due to deadlock(package private) static intTRO_FAILRollback-only due to end(TMFAIL)(package private) static intTRO_TIMEOUTRollback-only due to timeout(package private) XAXactIdxid
-
Constructor Summary
Constructors Constructor Description XATransactionState(ContextManager cm, EmbedConnection conn, EmbedXAResource resource, XAXactId xid)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidcancel(java.lang.String messageId)This function is called from the timer task when the transaction times out.voidcleanupOnError(java.lang.Throwable t)Contexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action.(package private) booleanend(EmbedXAResource resource, int flags, boolean endingCurrentXid)private static ModuleFactorygetMonitor()Privileged Monitor lookup.private static TimerFactorygetTimerFactory()(package private) voidscheduleTimeoutTask(long timeoutMillis)Schedule a timeout task which will rollback the global transaction after the specified time will elapse.(package private) voidstart(EmbedXAResource resource, int flags)(package private) voidxa_commit(boolean onePhase)Commit the global transaction and cancel the timeout task.private voidxa_finalize()This method cancels timeoutTask and assigns 'performTimeoutRollback = false'.(package private) intxa_prepare()Prepare the global transaction for commit.(package private) voidxa_rollback()Rollback the global transaction and cancel the timeout task.-
Methods inherited from class org.apache.derby.iapi.services.context.ContextImpl
appendErrorInfo, getContextManager, getIdName, isLastHandler, popMe, pushMe
-
-
-
-
Field Detail
-
TRO_TIMEOUT
static final int TRO_TIMEOUT
Rollback-only due to timeout- See Also:
- Constant Field Values
-
TRO_DEADLOCK
static final int TRO_DEADLOCK
Rollback-only due to deadlock- See Also:
- Constant Field Values
-
TRO_FAIL
static final int TRO_FAIL
Rollback-only due to end(TMFAIL)- See Also:
- Constant Field Values
-
T0_NOT_ASSOCIATED
static final int T0_NOT_ASSOCIATED
- See Also:
- Constant Field Values
-
T1_ASSOCIATED
static final int T1_ASSOCIATED
- See Also:
- Constant Field Values
-
TC_COMPLETED
static final int TC_COMPLETED
- See Also:
- Constant Field Values
-
conn
final EmbedConnection conn
-
creatingResource
final EmbedXAResource creatingResource
-
associatedResource
private EmbedXAResource associatedResource
-
xid
final XAXactId xid
-
cleanupOrCancelMonitor
XATransactionState.CleanupOrCancelMonitor cleanupOrCancelMonitor
-
suspendedList
java.util.HashMap<EmbedXAResource,XATransactionState> suspendedList
When an XAResource suspends a transaction (end(TMSUSPEND)) it must be resumed using the same XAConnection. This has been the traditional Cloudscape/Derby behaviour, though there does not seem to be a specific reference to this behaviour in the JTA spec. Note that while the transaction is suspended by this XAResource, another XAResource may join the transaction and suspend it after the join.
-
associationState
int associationState
Association state of the transaction.
-
rollbackOnlyCode
int rollbackOnlyCode
-
isPrepared
boolean isPrepared
has this transaction been prepared.
-
performTimeoutRollback
boolean performTimeoutRollback
Indicates whether this transaction is supposed to be rolled back by timeout.
-
timeoutTask
XATransactionState.CancelXATransactionTask timeoutTask
A timer task scheduled for the time when the transaction will timeout.
-
-
Constructor Detail
-
XATransactionState
XATransactionState(ContextManager cm, EmbedConnection conn, EmbedXAResource resource, XAXactId xid)
-
-
Method Detail
-
getTimerFactory
private static TimerFactory getTimerFactory()
-
cleanupOnError
public void cleanupOnError(java.lang.Throwable t)
Description copied from interface:ContextContexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action. They will be told what the error is, so that they can react appropriately. Most of the time, the contexts will react by either doing nothing or by removing themselves from the context manager. If there are no other references to the context, removing itself from the manager equates to freeing it.
On an exception that is session severity or greater the Context must push itself off the stack. This is to ensure that after a session has been closed there are no Contexts on the stack that potentially hold references to objects, thus delaying their garbage collection.Contexts must release all their resources before removing themselves from their context manager.
The context manager will "unwind" the contexts during cleanup in the reverse order they were placed on its global stack.
If error is an instance of StandardException then an implementation of this method may throw a new exception if and only if the new exception is an instance of StandardException that is more severe than the original error or the new exception is a not an instance of StandardException (e.g java.lang.NullPointerException).
-
start
void start(EmbedXAResource resource, int flags) throws javax.transaction.xa.XAException
- Throws:
javax.transaction.xa.XAException
-
end
boolean end(EmbedXAResource resource, int flags, boolean endingCurrentXid) throws javax.transaction.xa.XAException
- Throws:
javax.transaction.xa.XAException
-
scheduleTimeoutTask
void scheduleTimeoutTask(long timeoutMillis)
Schedule a timeout task which will rollback the global transaction after the specified time will elapse.- Parameters:
timeoutMillis- The number of milliseconds to be elapsed before the transaction will be rolled back.
-
xa_rollback
void xa_rollback() throws java.sql.SQLExceptionRollback the global transaction and cancel the timeout task.- Throws:
java.sql.SQLException
-
xa_commit
void xa_commit(boolean onePhase) throws java.sql.SQLExceptionCommit the global transaction and cancel the timeout task.- Parameters:
onePhase- Indicates whether to use one phase commit protocol. Otherwise two phase commit protocol will be used.- Throws:
java.sql.SQLException
-
xa_prepare
int xa_prepare() throws java.sql.SQLExceptionPrepare the global transaction for commit.- Throws:
java.sql.SQLException
-
xa_finalize
private void xa_finalize()
This method cancels timeoutTask and assigns 'performTimeoutRollback = false'.
-
cancel
void cancel(java.lang.String messageId) throws javax.transaction.xa.XAExceptionThis function is called from the timer task when the transaction times out.- Throws:
javax.transaction.xa.XAException- See Also:
XATransactionState.CancelXATransactionTask
-
getMonitor
private static ModuleFactory getMonitor()
Privileged Monitor lookup. Must be private so that user code can't call this entry point.
-
-