Class TransactionSynchronizationRegistryImpl
- java.lang.Object
-
- com.sun.enterprise.transaction.TransactionSynchronizationRegistryImpl
-
- All Implemented Interfaces:
jakarta.transaction.TransactionSynchronizationRegistry
@Service @ContractsProvided({TransactionSynchronizationRegistryImpl.class,jakarta.transaction.TransactionSynchronizationRegistry.class}) public class TransactionSynchronizationRegistryImpl extends Object implements jakarta.transaction.TransactionSynchronizationRegistry
-
-
Constructor Summary
Constructors Constructor Description TransactionSynchronizationRegistryImpl()TransactionSynchronizationRegistryImpl(jakarta.transaction.TransactionManager t)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectgetResource(Object key)Get an object from the map of resources being managed for the current transaction.booleangetRollbackOnly()Get therollbackOnlystatus of the transaction bound to the current thread.ObjectgetTransactionKey()Return an opaque object to represent the transaction bound to the current thread at the time this method is called.intgetTransactionStatus()Returns the status of the transaction bound to the current thread.voidputResource(Object key, Object value)Add an object to the map of resources being managed for the current transaction.voidregisterInterposedSynchronization(jakarta.transaction.Synchronization sync)Register aSynchronizationinstance with special ordering semantics.voidsetRollbackOnly()Set therollbackOnlystatus of the transaction bound to the current thread.
-
-
-
Method Detail
-
getTransactionKey
public Object getTransactionKey()
Return an opaque object to represent the transaction bound to the current thread at the time this method is called. The returned object overrideshashCodeandequalsmethods to allow its use as the key in ajava.util.HashMapfor use by the caller. If there is no transaction currently active, null is returned.The returned object will return the same
hashCodeand compare equal to all other objects returned by calling this method from any component executing in the same transaction context in the same application server.The
toStringmethod returns aStringthat might be usable by a human reader to usefully understand the transaction context. The result of thetoStringmethod is otherwise not defined. Specifically, there is no forward or backward compatibility guarantee for the result returned by thetoStringmethod.The object is not necessarily serializable, and is not useful outside the virtual machine from which it was obtained.
- Specified by:
getTransactionKeyin interfacejakarta.transaction.TransactionSynchronizationRegistry- Returns:
- An object representing the current transaction, or null if no transaction is active.
-
putResource
public void putResource(Object key, Object value)
Add an object to the map of resources being managed for the current transaction. The supplied key must be of a caller- defined class so as not to conflict with other users. The class of the key must guarantee that thehashCodeandequalsmethods are suitable for keys in a map. The key and value are not examined or used by the implementation.- Specified by:
putResourcein interfacejakarta.transaction.TransactionSynchronizationRegistry- Parameters:
key- The key for looking up the associated value object.value- The value object to keep track of.- Throws:
IllegalStateException- Thrown if the current thread is not associated with a transaction.
-
getResource
public Object getResource(Object key)
Get an object from the map of resources being managed for the current transaction. The key must have been supplied earlier by a call toputResoucein the same transaction. If the key cannot be found in the current resource map, null is returned.- Specified by:
getResourcein interfacejakarta.transaction.TransactionSynchronizationRegistry- Parameters:
key- The key for looking up the associated value object.- Returns:
- The value object, or null if not found.
- Throws:
IllegalStateException- Thrown if the current thread is not associated with a transaction.
-
registerInterposedSynchronization
public void registerInterposedSynchronization(jakarta.transaction.Synchronization sync)
Register aSynchronizationinstance with special ordering semantics. ThebeforeCompletionmethod on the registeredSynchronizationwill be called after all user and system componentbeforeCompletioncallbacks, but before the 2-phase commit process starts. This allows user and system components to flush state changes to the caching manager, during theirSessionSynchronizationcallbacks, and allows managers to flush state changes to Connectors, during the callbacks registered with this method. Similarly, theafterCompletioncallback will be called after 2-phase commit completes but before any user and systemafterCompletioncallbacks.The
beforeCompletioncallback will be invoked in the transaction context of the current transaction bound to the thread of the caller of this method, which is the same transaction context active at the time this method is called. Allowable methods include access to resources, for example, Connectors. No access is allowed to user components, for example, timer services or bean methods, as these might change the state of POJOs, or plain old Java objects, being managed by the caching manager.The
afterCompletioncallback will be invoked in an undefined transaction context. No access is permitted to resources or user components as defined above. Resources can be closed, but no transactional work can be performed with them.Other than the transaction context, no component J2EE context is active during either of the callbacks.
- Specified by:
registerInterposedSynchronizationin interfacejakarta.transaction.TransactionSynchronizationRegistry- Parameters:
sync- The synchronization callback object.- Throws:
IllegalStateException- Thrown if the current thread is not associated with a transaction.
-
getTransactionStatus
public int getTransactionStatus()
Returns the status of the transaction bound to the current thread. This is the result of executinggetStatusmethod on theTransactionManager, in the current transaction context.- Specified by:
getTransactionStatusin interfacejakarta.transaction.TransactionSynchronizationRegistry- Returns:
- The status of the current transaction.
-
setRollbackOnly
public void setRollbackOnly()
Set therollbackOnlystatus of the transaction bound to the current thread.- Specified by:
setRollbackOnlyin interfacejakarta.transaction.TransactionSynchronizationRegistry- Throws:
IllegalStateException- Thrown if the current thread is not associated with a transaction.
-
getRollbackOnly
public boolean getRollbackOnly()
Get therollbackOnlystatus of the transaction bound to the current thread.- Specified by:
getRollbackOnlyin interfacejakarta.transaction.TransactionSynchronizationRegistry- Returns:
- true, if the current transaction is marked for rollback only.
- Throws:
IllegalStateException- Thrown if the current thread is not associated with a transaction.
-
-