Top Inners Fields Constructors Methods
org.apache.derby.impl.jdbc

pack-priv final Class XATransactionState

extends ContextImpl
Class Inheritance
Imports
java.sql.SQLException, java.util.TimerTask, .HashMap, org.apache.derby.iapi.services.monitor.ModuleFactory, .Monitor, org.apache.derby.iapi.services.timer.TimerFactory, org.apache.derby.impl.jdbc.EmbedConnection, javax.transaction.xa.XAResource, .XAException, org.apache.derby.iapi.services.context.ContextImpl, .ContextManager, org.apache.derby.shared.common.error.ExceptionSeverity, .StandardException, .ExceptionUtil, org.apache.derby.iapi.store.access.XATransactionController, org.apache.derby.iapi.store.access.xa.XAXactId, org.apache.derby.shared.common.reference.SQLState, .MessageId

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
XATransactionState.CancelXATransactionTask

The implementation of TimerTask to cancel a global transaction.

private static class
XATransactionState.CleanupOrCancelMonitor

A class used to monitor if the transaction is in the middle of cancelling or cleaning up on an error.

Field Summary

Modifier and TypeField and Description
private EmbedXAResource
pack-priv int
associationState

Association state of the transaction.

pack-priv XATransactionState.CleanupOrCancelMonitor
pack-priv final EmbedConnection
pack-priv final EmbedXAResource
pack-priv boolean
isPrepared

has this transaction been prepared.

pack-priv boolean
performTimeoutRollback

Indicates whether this transaction is supposed to be rolled back by timeout.

pack-priv int
pack-priv HashMap<EmbedXAResource, XATransactionState>
suspendedList

When an XAResource suspends a transaction (end(TMSUSPEND)) it must be resumed using the same XAConnection.

pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv XATransactionState.CancelXATransactionTask
timeoutTask

A timer task scheduled for the time when the transaction will timeout.

pack-priv static final int
TRO_DEADLOCK

Rollback-only due to deadlock

pack-priv static final int
TRO_FAIL

Rollback-only due to end(TMFAIL)

pack-priv static final int
TRO_TIMEOUT

Rollback-only due to timeout

pack-priv final XAXactId

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv void
cancel(String messageId)

This function is called from the timer task when the transaction times out.

public void
cleanupOnError(Throwable
The original error
t
)

Implements org.apache.derby.iapi.services.context.Context.cleanupOnError.

Contexts will be passed errors that are caught by the outer system when they are serious enough to require corrective action.

pack-priv boolean
end(EmbedXAResource resource, int flags, boolean endingCurrentXid)

private static ModuleFactory
getMonitor()

Must be private so that user code can't call this entry point.

private static TimerFactory
pack-priv synchronized void
scheduleTimeoutTask(long
The number of milliseconds to be elapsed before the transaction will be rolled back.
timeoutMillis
)

Schedule a timeout task which will rollback the global transaction after the specified time will elapse.

pack-priv void
start(EmbedXAResource resource, int flags)

pack-priv synchronized void
xa_commit(boolean
Indicates whether to use one phase commit protocol. Otherwise two phase commit protocol will be used.
onePhase
)

Commit the global transaction and cancel the timeout task.

private void
xa_finalize()

This method cancels timeoutTask and assigns 'performTimeoutRollback = false'.

pack-priv synchronized int
xa_prepare()

Prepare the global transaction for commit.

pack-priv synchronized void
xa_rollback()

Rollback the global transaction and cancel the timeout task.

Inherited from org.apache.derby.iapi.services.context.ContextImpl:
appendErrorInfogetContextManagergetIdNameisLastHandlerpopMepushMe

Field Detail

associatedResourceback to summary
private EmbedXAResource associatedResource
associationStateback to summary
pack-priv int associationState

Association state of the transaction.

cleanupOrCancelMonitorback to summary
pack-priv XATransactionState.CleanupOrCancelMonitor cleanupOrCancelMonitor
connback to summary
pack-priv final EmbedConnection conn
creatingResourceback to summary
pack-priv final EmbedXAResource creatingResource
isPreparedback to summary
pack-priv boolean isPrepared

has this transaction been prepared.

performTimeoutRollbackback to summary
pack-priv boolean performTimeoutRollback

Indicates whether this transaction is supposed to be rolled back by timeout.

rollbackOnlyCodeback to summary
pack-priv int rollbackOnlyCode
suspendedListback to summary
pack-priv 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.

T0_NOT_ASSOCIATEDback to summary
pack-priv static final int T0_NOT_ASSOCIATED
T1_ASSOCIATEDback to summary
pack-priv static final int T1_ASSOCIATED
TC_COMPLETEDback to summary
pack-priv static final int TC_COMPLETED
timeoutTaskback to summary
pack-priv XATransactionState.CancelXATransactionTask timeoutTask

A timer task scheduled for the time when the transaction will timeout.

TRO_DEADLOCKback to summary
pack-priv static final int TRO_DEADLOCK

Rollback-only due to deadlock

TRO_FAILback to summary
pack-priv static final int TRO_FAIL

Rollback-only due to end(TMFAIL)

TRO_TIMEOUTback to summary
pack-priv static final int TRO_TIMEOUT

Rollback-only due to timeout

xidback to summary
pack-priv final XAXactId xid

Constructor Detail

XATransactionStateback to summary
pack-priv XATransactionState(ContextManager cm, EmbedConnection conn, EmbedXAResource resource, XAXactId xid)

Method Detail

cancelback to summary
pack-priv void cancel(String messageId) throws XAException

This function is called from the timer task when the transaction times out.

See Also
CancelXATransactionTask
cleanupOnErrorback to summary
public void cleanupOnError(Throwable t)

Implements org.apache.derby.iapi.services.context.Context.cleanupOnError.

Doc from org.apache.derby.iapi.services.context.Context.cleanupOnError.

Contexts 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).

Parameters
t:Throwable

The original error

endback to summary
pack-priv boolean end(EmbedXAResource resource, int flags, boolean endingCurrentXid) throws XAException
getMonitorback to summary
private static ModuleFactory getMonitor()

Must be private so that user code can't call this entry point.

getTimerFactoryback to summary
private static TimerFactory getTimerFactory()
scheduleTimeoutTaskback to summary
pack-priv synchronized void scheduleTimeoutTask(long timeoutMillis)

Schedule a timeout task which will rollback the global transaction after the specified time will elapse.

Parameters
timeoutMillis:long

The number of milliseconds to be elapsed before the transaction will be rolled back.

startback to summary
pack-priv void start(EmbedXAResource resource, int flags) throws XAException
xa_commitback to summary
pack-priv synchronized void xa_commit(boolean onePhase) throws SQLException

Commit the global transaction and cancel the timeout task.

Parameters
onePhase:boolean

Indicates whether to use one phase commit protocol. Otherwise two phase commit protocol will be used.

xa_finalizeback to summary
private void xa_finalize()

This method cancels timeoutTask and assigns 'performTimeoutRollback = false'.

xa_prepareback to summary
pack-priv synchronized int xa_prepare() throws SQLException

Prepare the global transaction for commit.

xa_rollbackback to summary
pack-priv synchronized void xa_rollback() throws SQLException

Rollback the global transaction and cancel the timeout task.

org.apache.derby.impl.jdbc back to summary

private Class XATransactionState.CancelXATransactionTask

extends TimerTask
Class Inheritance

The implementation of TimerTask to cancel a global transaction.

Field Summary

Modifier and TypeField and Description
private XATransactionState

Constructor Summary

AccessConstructor and Description
public
CancelXATransactionTask(XATransactionState
the XA state object for the transaction to cancel
xaState
)

Creates the cancellation task to be passed to a timer.

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean
cancel()

Overrides java.util.TimerTask.cancel.

Cancels this timer task.

public synchronized void
run()

Implements abstract java.util.TimerTask.run.

Implements java.lang.Runnable.run.

Runs the cancel task of the global transaction

Inherited from java.util.TimerTask:
scheduledExecutionTime

Field Detail

xaStateback to summary
private XATransactionState xaState

Constructor Detail

CancelXATransactionTaskback to summary
public CancelXATransactionTask(XATransactionState xaState)

Creates the cancellation task to be passed to a timer.

Parameters
xaState:XATransactionState

the XA state object for the transaction to cancel

Method Detail

cancelback to summary
public synchronized boolean cancel()

Overrides java.util.TimerTask.cancel.

Doc from java.util.TimerTask.cancel.

Cancels this timer task. If the task has been scheduled for one-time execution and has not yet run, or has not yet been scheduled, it will never run. If the task has been scheduled for repeated execution, it will never run again. (If the task is running when this call occurs, the task will run to completion, but will never run again.)

Note that calling this method from within the run method of a repeating timer task absolutely guarantees that the timer task will not run again.

This method may be called repeatedly; the second and subsequent calls have no effect.

Returns:boolean

true if this task is scheduled for one-time execution and has not yet run, or this task is scheduled for repeated execution. Returns false if the task was scheduled for one-time execution and has already run, or if the task was never scheduled, or if the task was already cancelled. (Loosely speaking, this method returns true if it prevents one or more scheduled executions from taking place.)

runback to summary
public synchronized void run()

Implements abstract java.util.TimerTask.run.

Implements java.lang.Runnable.run.

Runs the cancel task of the global transaction

org.apache.derby.impl.jdbc back to summary

private Class XATransactionState.CleanupOrCancelMonitor

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.derby.impl.jdbc.XATransactionState.CleanupOrCancelMonitor

A class used to monitor if the transaction is in the middle of cancelling or cleaning up on an error. See DERBY-6879

Field Summary

Modifier and TypeField and Description
private Long
private Long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public synchronized boolean

Returns:

true if it is okay to cancel.
okToCancel
()

See if it is ok to cancel.

private synchronized boolean

Returns:

true if it is okay to cleanup.
okToCleanup
()

See if it is ok to cleanup.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cancelThreadIdback to summary
private Long cancelThreadId
cleanupThreadIdback to summary
private Long cleanupThreadId

Constructor Detail

CleanupOrCancelMonitorback to summary
private CleanupOrCancelMonitor()

Method Detail

okToCancelback to summary
public synchronized boolean okToCancel()

See if it is ok to cancel. It is okay to cancel if the transaction is not cleaning up from an error. The assumption is that if the cleanUpOnError is/has been invoked, then there is no reason for the cancel to be processed as the transaction is going to end (ab)normally.

Returns:boolean

true if it is okay to cancel.

okToCleanupback to summary
private synchronized boolean okToCleanup()

See if it is ok to cleanup. It is okay to cleanup if the transaction is not cancelling. The assumption is that if the cancel is/has been invoked, then there is no reason to try to mark the transaction as being in error. The transaction will be cancelled in any case.

Returns:boolean

true if it is okay to cleanup.