Package org.apache.jackrabbit.data.core
Class TransactionContext
- java.lang.Object
-
- org.apache.jackrabbit.data.core.TransactionContext
-
public class TransactionContext extends java.lang.Object
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.data.core.TransactionContext)
method, are eventually unlocked.
-
-
Constructor Summary
Constructors Constructor Description TransactionContext(javax.transaction.xa.Xid xid, InternalXAResource[] resources)
Create a new instance of this class.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
commit()
Commit the transaction identified by this context.java.lang.Object
getAttribute(java.lang.String name)
Return an attribute value on this transaction.static java.lang.Object
getCurrentThreadId()
Returns the current thread identifier.static boolean
isSameThreadId(java.lang.Object a, java.lang.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(java.lang.String name)
Remove an attribute on this transaction.void
rollback()
Rollback the transaction identified by this context.void
setAttribute(java.lang.String name, java.lang.Object value)
Set an attribute on this transaction.void
setSuspended(boolean suspended)
Set a flag indicating whether the association is suspended.
-
-
-
Constructor Detail
-
TransactionContext
public TransactionContext(javax.transaction.xa.Xid xid, InternalXAResource[] resources)
Create a new instance of this class.- Parameters:
xid
- associated xidresources
- transactional resources
-
-
Method Detail
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.Object value)
Set an attribute on this transaction. If the value specified isnull
, it is semantically equivalent toremoveAttribute(java.lang.String)
.- Parameters:
name
- attribute namevalue
- attribute value
-
getAttribute
public java.lang.Object getAttribute(java.lang.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(java.lang.String name)
Remove an attribute on this transaction.- Parameters:
name
- attribute name
-
prepare
public void prepare() throws javax.transaction.xa.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:
javax.transaction.xa.XAException
- if an error occurs
-
commit
public void commit() throws javax.transaction.xa.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:
javax.transaction.xa.XAException
- if an error occurs
-
rollback
public void rollback() throws javax.transaction.xa.XAException
Rollback the transaction identified by this context. Rolls back changes on all resources. Throws exception at the end if errors were found.- Throws:
javax.transaction.xa.XAException
- if an error occurs
-
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.
-
getCurrentThreadId
public static java.lang.Object getCurrentThreadId()
Returns the current thread identifier. The identifier is either the current thread instance or the global transaction identifier wrapped in aTransactionContext.XidWrapper
, when running under a transaction.- Returns:
- current thread identifier
-
isSameThreadId
public static boolean isSameThreadId(java.lang.Object a, java.lang.Object b)
Compares the given thread identifiers for equality.- See Also:
getCurrentThreadId()
-
-