You can use the TaskNameAccessor API to set a Java Persistence API (JPA) TaskName at runtime.
In the Enterprise JavaBeans (EJB) container, a task name is automatically set by default when a transaction begins. This action is performed when a component or business method is invoked in a CMT session bean or when an application invokes the sessionContext.getTransaction().begin() in a BMT session bean. This TaskName consists of a concatenation of the fully package qualified session bean type, a dot character and the method name, for example: com.acme.MyCmtSessionBean.methodABC.
If you are using JPA in the context of the Web container, an application must use the TaskNameAccessor API to set the TaskName in the current thread of execution.
package com.ibm.websphere.persistence; public abstract class TaskNameAccessor { /** * Returns the current task name attached in the current thread context * @return current task name or null if none is found. */ public static String getTaskName (); /** . * Add a user-defined JPA access intent task name to the current thread * context. * * @param taskName * @return false if an existing task has already attached in the current * thread or Transaction Synchronization Registry (TSR) is not * available (for example, in JSE environment). */ public static boolean setTaskName(String taskName); }
package my.company; @Remote class Ejb1 { // assumer no tx from the caller @TransactionAttribute(Requires) public void caller_Method1() { // an implicit new transaction begins // TaskName "my.company.Ejb1.caller_Method1" set on TSR ejb1.callee_Method?(); } @TransactionAttribute(RequiredNew) public void callee_Method2() { // an implicit new transaction begins i.e. TxRequiredNew. // TaskName "my.company.Ejb1.callee_Method2" set on TSR } @TransactionAttribute(Requires) public void callee_Method3() { // In the caller transaction, hence TaskName remains // "my.company.Ejb1.caller_Method1" } @TransactionAttribute(NotSupported) public void callee_LocalTx () { // Unspecified transaction, a new local transaction implicitly started. // TaskName "my.company.Ejb1.callee_LocalTx" set on TSR } }
In this information ... | IBM Redbooks, demos, education, and more(Index) |