Définition d'un Nom de tâche à l'aide de l'API TaskNameAccessor
Utilisez l'API TaskNameAccessor pour définir la Nom de tâche JPA (Java™ Persistence API) lors de la phase d'exécution.
Pourquoi et quand exécuter cette tâche
Dans le conteneur Enterprise JavaBeans (EJB), un nom de tâche est automatiquement défini par défaut lors du démarrage d'une transaction. Cette action est réalisée lorsqu'un composant ou une méthode applicative est appelé dans le bean d'une session CMT ou lorsqu'une application appelle sessionContext.getTransaction().begin() dans le bean d'une session BMT. Ce Nom de tâche est composé d'une concaténation du type de bean session habilité du module complet, un point et le nom de la méthode. Par exemple : com.acme.MyCmtSessionBean.methodABC.
Si vous utilisez JPA dans le contexte du conteneur web, une application doit utiliser l'API TaskNameAccessor afin de définir le Nom de tâche dans l'unité d'exécution actuelle.

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
}
}