public class TransactionManager extends java.lang.Object implements Interceptor, java.io.Serializable
Note that RequiredNew is not fully supported since TransactionManager
does not know how to suspend transactions.
Transaction policy must be provided in the invocationContext in the "transactionPolicy" field. If it is not provided the Supprts policy is used.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
POLICY_CONTEXT_KEY |
static java.lang.String |
USER_TRANSACTION_JNDI |
Constructor and Description |
---|
TransactionManager()
Creates a new instance of the
TransactionManager with the
default (Supports) policy. |
TransactionManager(TransactionPolicy policy)
Creates a new instance of the
TransactionManager with the
given policy. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object obj)
Returns true if the given object is of the same type and
it has the same transaction policy.
|
TransactionPolicy |
getPolicy()
Returns the currently set transaction policy.
|
static javax.transaction.UserTransaction |
getUserTransaction()
Returns UserTransaction object.
|
protected boolean |
handlePolicy(TransactionPolicy policy,
java.lang.Object targetObj,
java.lang.reflect.Method method,
java.lang.Object[] args)
Performs the actions necessary to handle the transaction policy
according to the spec.
|
int |
hashCode() |
void |
intercept(InvocationContext invocationContext)
Begins, commits and rolls back the transaction according to the currently
set policy and EJB spec.
|
protected void |
log(java.lang.String message) |
void |
setPolicy(TransactionPolicy policy)
Sets the transaction policy.
|
void |
setUserTransaction(javax.transaction.UserTransaction userTransaction)
Sets the shared instance of UserTransaction that will be used by MockEJB.
|
public static final java.lang.String USER_TRANSACTION_JNDI
public static final java.lang.String POLICY_CONTEXT_KEY
public TransactionManager(TransactionPolicy policy)
TransactionManager
with the
given policy.policy
- transaction policypublic TransactionManager()
TransactionManager
with the
default (Supports) policy.public TransactionPolicy getPolicy()
public void setPolicy(TransactionPolicy policy)
policy
- policy to set.public void intercept(InvocationContext invocationContext) throws java.lang.Exception
intercept
in interface Interceptor
invocationContext
- provides the info about this call. Also calls interceptors in
turn according to their order in the chain. invocationContext provides access to the return value
and thrown exceptions of this call.java.lang.Exception
protected boolean handlePolicy(TransactionPolicy policy, java.lang.Object targetObj, java.lang.reflect.Method method, java.lang.Object[] args) throws javax.transaction.SystemException, javax.naming.NamingException
policy
- policy of this invokertargetObj
- bean being calledmethod
- method being calledargs
- parameter values of the method being calledjavax.transaction.SystemException
javax.naming.NamingException
public static javax.transaction.UserTransaction getUserTransaction()
setUserTransaction()
was called, will return the object that was set by this method.
Otherwise, tries to obtain UserTransaction object from JNDI.public void setUserTransaction(javax.transaction.UserTransaction userTransaction)
protected void log(java.lang.String message)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object