Using the TaskNameAccessor API to set Java Persistence API (JPA) TaskName at runtime.
In the Enterprise JavaBeans (EJB) container, a task name is automatically set by default upon a transaction begins. This action is performed when a component or business method is invoked in a CMT session bean or when an application invoke 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 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 (i.e. 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 caller's 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) |