Top Description Inners Fields Constructors Methods
org.springframework.transaction.interceptor

public abstract Class TransactionAspectSupport

extends Object
implements BeanFactoryAware, InitializingBean
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware
Known Direct Subclasses
org.springframework.transaction.interceptor.TransactionInterceptor
Imports
java.lang.reflect.Method, java.util.Properties, java.util.concurrent.ConcurrentMap, .ExecutionException, .Future, io.vavr.control.Try, kotlin.coroutines.Continuation, kotlin.coroutines.CoroutineContext, kotlinx.coroutines.Job, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, .InitializingBean, org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils, org.springframework.core.CoroutinesUtils, .KotlinDetector, .MethodParameter, .NamedThreadLocal, .ReactiveAdapter, .ReactiveAdapterRegistry, org.springframework.lang.Nullable, org.springframework.transaction.NoTransactionException, .PlatformTransactionManager, .ReactiveTransaction, .ReactiveTransactionManager, .TransactionManager, .TransactionStatus, .TransactionSystemException, org.springframework.transaction.reactive.TransactionContextManager, org.springframework.transaction.support.CallbackPreferringPlatformTransactionManager, org.springframework.util.Assert, .ClassUtils, .ConcurrentReferenceHashMap, .StringUtils

Base class for transactional aspects, such as the TransactionInterceptor or an AspectJ aspect.

This enables the underlying Spring transaction infrastructure to be used easily to implement an aspect for any aspect system.

Subclasses are responsible for calling methods in this class in the correct order.

If no transaction name has been specified in the TransactionAttribute, the exposed name will be the fully-qualified class name + "." + method name (by default).

Uses the Strategy design pattern. A PlatformTransactionManager or ReactiveTransactionManager implementation will perform the actual transaction management, and a TransactionAttributeSource (e.g. annotation-based) is used for determining transaction definitions for a particular class or method.

A transaction aspect is serializable if its TransactionManager and TransactionAttributeSource are serializable.

Authors
Rod Johnson, Juergen Hoeller, Stéphane Nicoll, Sam Brannen, Mark Paluch, Sebastien Deleuze, Enric Sala
Since
1.1
See Also
PlatformTransactionManager, ReactiveTransactionManager, setTransactionManager, setTransactionAttributes, setTransactionAttributeSource

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static interface
TransactionAspectSupport.CoroutinesInvocationCallback

Coroutines-supporting extension of the callback interface.

protected static interface
TransactionAspectSupport.InvocationCallback

Simple callback interface for proceeding with the target invocation.

private static class
TransactionAspectSupport.KotlinDelegate

Inner class to avoid a hard dependency on Kotlin at runtime.

private static class
TransactionAspectSupport.ReactiveTransactionInfo

Opaque object used to hold transaction information for reactive methods.

private class
TransactionAspectSupport.ReactiveTransactionSupport

Delegate for Reactor-based management of transactional methods with a reactive return type.

private static class
TransactionAspectSupport.ThrowableHolder

Internal holder class for a Throwable in a callback transaction model.

private static class
TransactionAspectSupport.ThrowableHolderException

Internal holder class for a Throwable, used as a RuntimeException to be thrown from a TransactionCallback (and subsequently unwrapped again).

protected static class
TransactionAspectSupport.TransactionInfo

Opaque object used to hold transaction information.

private static class
TransactionAspectSupport.VavrDelegate

Inner class to avoid a hard dependency on the Vavr library at runtime.

Field Summary

Modifier and TypeField and Description
private BeanFactory
private static final String
private static final Object
DEFAULT_TRANSACTION_MANAGER_KEY

Key to use to store the default transaction manager.

protected final Log
private final ReactiveAdapterRegistry
private static final boolean
reactiveStreamsPresent

Reactive Streams API present on the classpath?

private TransactionAttributeSource
private static final ThreadLocal<TransactionAspectSupport.TransactionInfo>
transactionInfoHolder

Holder to support the currentTransactionStatus() method, and to support communication between different cooperating advices (e.g. before and after advice) if the aspect involves more than a single method (as will be the case for around advice).

private TransactionManager
private String
private final ConcurrentMap<Object, TransactionManager>
private final ConcurrentMap<Method, TransactionAspectSupport.ReactiveTransactionSupport>
private static final boolean
vavrPresent

Vavr library present on the classpath?

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
private PlatformTransactionManager
protected void
cleanupTransactionInfo(TransactionAspectSupport.TransactionInfo
information about the current transaction (may be null)
txInfo
)

Reset the TransactionInfo ThreadLocal.

protected void
clearTransactionManagerCache()

Clear the transaction manager cache.

protected void
commitTransactionAfterReturning(TransactionAspectSupport.TransactionInfo
information about the current transaction
txInfo
)

Execute after successful completion of call, but not after an exception was handled.

protected void
completeTransactionAfterThrowing(TransactionAspectSupport.TransactionInfo
information about the current transaction
txInfo
,
Throwable
throwable encountered
ex
)

Handle a throwable, completing the transaction.

protected TransactionAspectSupport.TransactionInfo

Returns:

a TransactionInfo object, whether a transaction was created. The hasTransaction() method on TransactionInfo can be used to tell if there was a transaction created.
createTransactionIfNecessary
(PlatformTransactionManager tm, TransactionAttribute
the TransactionAttribute (may be null)
txAttr
,
final String
the fully qualified method name (used for monitoring and logging purposes)
joinpointIdentification
)

Create a transaction if necessary based on the given TransactionAttribute.

protected static TransactionAspectSupport.TransactionInfo

Returns:

the TransactionInfo bound to this thread, or null if none
currentTransactionInfo
()

Subclasses can use this to return the current TransactionInfo.

public static TransactionStatus
currentTransactionStatus()

Return the transaction status of the current method invocation.

private TransactionManager
protected TransactionManager
determineTransactionManager(TransactionAttribute txAttr)

Determine the specific transaction manager to use for the given transaction.

protected final BeanFactory
getBeanFactory()

Return the BeanFactory to use for retrieving TransactionManager beans.

public TransactionAttributeSource
getTransactionAttributeSource()

Return the transaction attribute source.

public TransactionManager
getTransactionManager()

Return the default transaction manager, or null if unknown.

protected final String
getTransactionManagerBeanName()

Return the name of the default transaction manager bean.

protected Object

Returns:

the return value of the method, if any
invokeWithinTransaction
(Method
the Method being invoked
method
,
Class<?>
the target class that we're invoking the method on
targetClass
,
final TransactionAspectSupport.InvocationCallback
the callback to use for proceeding with the target invocation
invocation
)

General delegate for around-advice-based subclasses, delegating to several other template methods on this class.

private String
methodIdentification(Method method, Class<?> targetClass, TransactionAttribute txAttr)

protected String

Returns:

a String representation identifying this method
methodIdentification
(Method
the method we're interested in
method
,
Class<?>
the class that the method is being invoked on
targetClass
)

Convenience method to return a String representation of this Method for use in logging.

protected TransactionAspectSupport.TransactionInfo

Returns:

the prepared TransactionInfo object
prepareTransactionInfo
(PlatformTransactionManager tm, TransactionAttribute
the TransactionAttribute (may be null)
txAttr
,
String
the fully qualified method name (used for monitoring and logging purposes)
joinpointIdentification
,
TransactionStatus
the TransactionStatus for the current transaction
status
)

Prepare a TransactionInfo for the given attribute and status object.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Set the BeanFactory to use for retrieving TransactionManager beans.
public void
setTransactionAttributes(Properties transactionAttributes)

Set properties with method names as keys and transaction attribute descriptors (parsed via TransactionAttributeEditor) as values: e.g. key = "myMethod", value = "PROPAGATION_REQUIRED,readOnly".

public void
setTransactionAttributeSource(TransactionAttributeSource transactionAttributeSource)

Set the transaction attribute source which is used to find transaction attributes.

public void
setTransactionAttributeSources(TransactionAttributeSource... transactionAttributeSources)

Set multiple transaction attribute sources which are used to find transaction attributes.

public void
setTransactionManager(TransactionManager transactionManager)

Specify the default transaction manager to use to drive transactions.

public void
setTransactionManagerBeanName(String transactionManagerBeanName)

Specify the name of the default transaction manager bean.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait