spring-framework / org.springframework.transaction.support / CallbackPreferringPlatformTransactionManager

CallbackPreferringPlatformTransactionManager

interface CallbackPreferringPlatformTransactionManager : PlatformTransactionManager

Extension of the org.springframework.transaction.PlatformTransactionManager interface, exposing a method for executing a given callback within a transaction.

Implementors of this interface automatically express a preference for callbacks over programmatic getTransaction, commit and rollback calls. Calling code may check whether a given transaction manager implements this interface to choose to prepare a callback instead of explicit transaction demarcation control.

Spring's TransactionTemplate and org.springframework.transaction.interceptor.TransactionInterceptor detect and use this PlatformTransactionManager variant automatically.

Author
Juergen Hoeller

Since
2.0

See Also
TransactionTemplateorg.springframework.transaction.interceptor.TransactionInterceptor

Functions

execute

abstract fun <T : Any> execute(definition: TransactionDefinition, callback: TransactionCallback<T>): T

Execute the action specified by the given callback object within a transaction.

Allows for returning a result object created within the transaction, that is, a domain object or a collection of domain objects. A RuntimeException thrown by the callback is treated as a fatal exception that enforces a rollback. Such an exception gets propagated to the caller of the template.

Inheritors

WebSphereUowTransactionManager

open class WebSphereUowTransactionManager : JtaTransactionManager, CallbackPreferringPlatformTransactionManager

WebSphere-specific PlatformTransactionManager implementation that delegates to a com.ibm.wsspi.uow.UOWManager instance, obtained from WebSphere's JNDI environment. This allows Spring to leverage the full power of the WebSphere transaction coordinator, including transaction suspension, in a manner that is perfectly compliant with officially supported WebSphere API.

The CallbackPreferringPlatformTransactionManager interface implemented by this class indicates that callers should preferably pass in a TransactionCallback through the #execute method, which will be handled through the callback-based WebSphere UOWManager API instead of through standard JTA API (UserTransaction / TransactionManager). This avoids the use of the non-public javax.transaction.TransactionManager API on WebSphere, staying within supported WebSphere API boundaries.

This transaction manager implementation derives from Spring's standard JtaTransactionManager, inheriting the capability to support programmatic transaction demarcation via getTransaction / commit / rollback calls through a JTA UserTransaction handle, for callers that do not use the TransactionCallback-based #execute method. However, transaction suspension is not supported in this getTransaction style (unless you explicitly specify a #setTransactionManager reference, despite the official WebSphere recommendations). Use the #execute style for any code that might require transaction suspension.

This transaction manager is compatible with WebSphere 6.1.0.9 and above. The default JNDI location for the UOWManager is "java:comp/websphere/UOWManager". If the location happens to differ according to your WebSphere documentation, simply specify the actual location through this transaction manager's "uowManagerName" bean property.

NOTE: This JtaTransactionManager is intended to refine specific transaction demarcation behavior on Spring's side. It will happily co-exist with independently configured WebSphere transaction strategies in your persistence provider, with no need to specifically connect those setups in any way.