|
|
|
@ -343,7 +343,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init |
|
|
|
final TransactionAttribute txAttr = (tas != null ? tas.getTransactionAttribute(method, targetClass) : null); |
|
|
|
final TransactionAttribute txAttr = (tas != null ? tas.getTransactionAttribute(method, targetClass) : null); |
|
|
|
final TransactionManager tm = determineTransactionManager(txAttr); |
|
|
|
final TransactionManager tm = determineTransactionManager(txAttr); |
|
|
|
|
|
|
|
|
|
|
|
if (this.reactiveAdapterRegistry != null && tm instanceof ReactiveTransactionManager) { |
|
|
|
if (this.reactiveAdapterRegistry != null && tm instanceof ReactiveTransactionManager rtm) { |
|
|
|
boolean isSuspendingFunction = KotlinDetector.isSuspendingFunction(method); |
|
|
|
boolean isSuspendingFunction = KotlinDetector.isSuspendingFunction(method); |
|
|
|
boolean hasSuspendingFlowReturnType = isSuspendingFunction && |
|
|
|
boolean hasSuspendingFlowReturnType = isSuspendingFunction && |
|
|
|
COROUTINES_FLOW_CLASS_NAME.equals(new MethodParameter(method, -1).getParameterType().getName()); |
|
|
|
COROUTINES_FLOW_CLASS_NAME.equals(new MethodParameter(method, -1).getParameterType().getName()); |
|
|
|
@ -367,7 +367,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init |
|
|
|
if (corInv != null) { |
|
|
|
if (corInv != null) { |
|
|
|
callback = () -> KotlinDelegate.invokeSuspendingFunction(method, corInv); |
|
|
|
callback = () -> KotlinDelegate.invokeSuspendingFunction(method, corInv); |
|
|
|
} |
|
|
|
} |
|
|
|
Object result = txSupport.invokeWithinTransaction(method, targetClass, callback, txAttr, (ReactiveTransactionManager) tm); |
|
|
|
Object result = txSupport.invokeWithinTransaction(method, targetClass, callback, txAttr, rtm); |
|
|
|
if (corInv != null) { |
|
|
|
if (corInv != null) { |
|
|
|
Publisher<?> pr = (Publisher<?>) result; |
|
|
|
Publisher<?> pr = (Publisher<?>) result; |
|
|
|
return (hasSuspendingFlowReturnType ? KotlinDelegate.asFlow(pr) : |
|
|
|
return (hasSuspendingFlowReturnType ? KotlinDelegate.asFlow(pr) : |
|
|
|
@ -379,7 +379,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init |
|
|
|
PlatformTransactionManager ptm = asPlatformTransactionManager(tm); |
|
|
|
PlatformTransactionManager ptm = asPlatformTransactionManager(tm); |
|
|
|
final String joinpointIdentification = methodIdentification(method, targetClass, txAttr); |
|
|
|
final String joinpointIdentification = methodIdentification(method, targetClass, txAttr); |
|
|
|
|
|
|
|
|
|
|
|
if (txAttr == null || !(ptm instanceof CallbackPreferringPlatformTransactionManager)) { |
|
|
|
if (txAttr == null || !(ptm instanceof CallbackPreferringPlatformTransactionManager cpptm)) { |
|
|
|
// Standard transaction demarcation with getTransaction and commit/rollback calls.
|
|
|
|
// Standard transaction demarcation with getTransaction and commit/rollback calls.
|
|
|
|
TransactionInfo txInfo = createTransactionIfNecessary(ptm, txAttr, joinpointIdentification); |
|
|
|
TransactionInfo txInfo = createTransactionIfNecessary(ptm, txAttr, joinpointIdentification); |
|
|
|
|
|
|
|
|
|
|
|
@ -416,7 +416,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init |
|
|
|
|
|
|
|
|
|
|
|
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
|
|
|
|
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
|
|
|
|
try { |
|
|
|
try { |
|
|
|
result = ((CallbackPreferringPlatformTransactionManager) ptm).execute(txAttr, status -> { |
|
|
|
result = cpptm.execute(txAttr, status -> { |
|
|
|
TransactionInfo txInfo = prepareTransactionInfo(ptm, txAttr, joinpointIdentification, status); |
|
|
|
TransactionInfo txInfo = prepareTransactionInfo(ptm, txAttr, joinpointIdentification, status); |
|
|
|
try { |
|
|
|
try { |
|
|
|
Object retVal = invocation.proceedWithInvocation(); |
|
|
|
Object retVal = invocation.proceedWithInvocation(); |
|
|
|
@ -429,8 +429,8 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init |
|
|
|
catch (Throwable ex) { |
|
|
|
catch (Throwable ex) { |
|
|
|
if (txAttr.rollbackOn(ex)) { |
|
|
|
if (txAttr.rollbackOn(ex)) { |
|
|
|
// A RuntimeException: will lead to a rollback.
|
|
|
|
// A RuntimeException: will lead to a rollback.
|
|
|
|
if (ex instanceof RuntimeException rex) { |
|
|
|
if (ex instanceof RuntimeException runtimeException) { |
|
|
|
throw rex; |
|
|
|
throw runtimeException; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
throw new ThrowableHolderException(ex); |
|
|
|
throw new ThrowableHolderException(ex); |
|
|
|
@ -524,8 +524,11 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
@Nullable |
|
|
|
private PlatformTransactionManager asPlatformTransactionManager(@Nullable Object transactionManager) { |
|
|
|
private PlatformTransactionManager asPlatformTransactionManager(@Nullable Object transactionManager) { |
|
|
|
if (transactionManager == null || transactionManager instanceof PlatformTransactionManager) { |
|
|
|
if (transactionManager == null) { |
|
|
|
return (PlatformTransactionManager) transactionManager; |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (transactionManager instanceof PlatformTransactionManager ptm) { |
|
|
|
|
|
|
|
return ptm; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
throw new IllegalStateException( |
|
|
|
throw new IllegalStateException( |
|
|
|
|