org.apache.jackrabbit.core
Class TransactionContext

java.lang.Object
  extended by java.util.TimerTask
      extended by org.apache.jackrabbit.util.Timer.Task
          extended by org.apache.jackrabbit.core.TransactionContext
All Implemented Interfaces:
Runnable

public class TransactionContext
extends Timer.Task

Represents the transaction on behalf of the component that wants to explicitly demarcate transaction boundaries. After having been prepared, schedules a task that rolls back the transaction if some time passes without any further action. This will guarantee that global objects locked by one of the resources' InternalXAResource.prepare(org.apache.jackrabbit.core.TransactionContext) method, are eventually unlocked.


Constructor Summary
TransactionContext(Xid xid, InternalXAResource[] resources, int timeout)
          Create a new instance of this class.
 
Method Summary
 void commit()
          Commit the transaction identified by this context.
 Object getAttribute(String name)
          Return an attribute value on this transaction.
static Object getCurrentThreadId()
          Returns the current thread identifier.
static Xid getCurrentXid()
          Returns the Xid bind to the CURRENT_XID ThreadLocal
static boolean isSameThreadId(Object a, Object b)
          Compares the given thread identifiers for equality.
 boolean isSuspended()
          Return a flag indicating whether the association is suspended.
 void prepare()
          Prepare the transaction identified by this context.
 void removeAttribute(String name)
          Remove an attribute on this transaction.
 void rollback()
          Rollback the transaction identified by this context.
 void run()
          Rolls back the transaction if still prepared and marks the transaction rolled back.
 void setAttribute(String name, Object value)
          Set an attribute on this transaction.
 void setSuspended(boolean suspended)
          Set a flag indicating whether the association is suspended.
 
Methods inherited from class org.apache.jackrabbit.util.Timer.Task
cancel
 
Methods inherited from class java.util.TimerTask
scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionContext

public TransactionContext(Xid xid,
                          InternalXAResource[] resources,
                          int timeout)
Create a new instance of this class.

Parameters:
xid - associated xid
resources - transactional resources
timeout - timeout, in seconds
Method Detail

setAttribute

public void setAttribute(String name,
                         Object value)
Set an attribute on this transaction. If the value specified is null, it is semantically equivalent to removeAttribute(java.lang.String).

Parameters:
name - attribute name
value - attribute value

getAttribute

public Object getAttribute(String name)
Return an attribute value on this transaction.

Parameters:
name - attribute name
Returns:
attribute value, null if no attribute with that name exists

removeAttribute

public void removeAttribute(String name)
Remove an attribute on this transaction.

Parameters:
name - attribute name

prepare

public void prepare()
             throws XAException
Prepare the transaction identified by this context. Prepares changes on all resources. If some resource reports an error on prepare, automatically rollback changes on all other resources. Throw exception at the end if errors were found.

Throws:
XAException - if an error occurs

commit

public void commit()
            throws XAException
Commit the transaction identified by this context. Commits changes on all resources. If some resource reports an error on commit, automatically rollback changes on all other resources. Throw exception at the end if some commit failed.

Throws:
XAException - if an error occurs

rollback

public void rollback()
              throws XAException
Rollback the transaction identified by this context. Rolls back changes on all resources. Throws exception at the end if errors were found.

Throws:
XAException - if an error occurs

run

public void run()
Rolls back the transaction if still prepared and marks the transaction rolled back.

Specified by:
run in interface Runnable
Specified by:
run in class TimerTask

isSuspended

public boolean isSuspended()
Return a flag indicating whether the association is suspended.

Returns:
true if the association is suspended; false otherwise

setSuspended

public void setSuspended(boolean suspended)
Set a flag indicating whether the association is suspended.

Parameters:
suspended - flag whether that the association is suspended.

getCurrentXid

public static Xid getCurrentXid()
Returns the Xid bind to the CURRENT_XID ThreadLocal

Returns:
current Xid or null

getCurrentThreadId

public static Object getCurrentThreadId()
Returns the current thread identifier. The identifier is either the current thread instance or the global transaction identifier when running under a transaction.

Returns:
current thread identifier

isSameThreadId

public static boolean isSameThreadId(Object a,
                                     Object b)
Compares the given thread identifiers for equality.

See Also:
getCurrentThreadId()


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.