Skip to content

Commit

Permalink
Avoid misleading log message for commit-triggering exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller authored and xcl(徐程林) committed Aug 16, 2020
1 parent f27fdd9 commit 95c205e
Showing 1 changed file with 16 additions and 14 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -192,7 +192,7 @@ protected TransactionAspectSupport() {

/**
* Specify the name of the default transaction manager bean.
* This can either point to a traditional {@link PlatformTransactionManager} or a
* <p>This can either point to a traditional {@link PlatformTransactionManager} or a
* {@link ReactiveTransactionManager} for reactive transaction management.
*/
public void setTransactionManagerBeanName(@Nullable String transactionManagerBeanName) {
Expand All @@ -209,7 +209,7 @@ protected final String getTransactionManagerBeanName() {

/**
* Specify the <em>default</em> transaction manager to use to drive transactions.
* This can either be a traditional {@link PlatformTransactionManager} or a
* <p>This can either be a traditional {@link PlatformTransactionManager} or a
* {@link ReactiveTransactionManager} for reactive transaction management.
* <p>The default transaction manager will be used if a <em>qualifier</em>
* has not been declared for a given transaction or if an explicit name for the
Expand All @@ -222,7 +222,7 @@ public void setTransactionManager(@Nullable TransactionManager transactionManage

/**
* Return the default transaction manager, or {@code null} if unknown.
* This can either be a traditional {@link PlatformTransactionManager} or a
* <p>This can either be a traditional {@link PlatformTransactionManager} or a
* {@link ReactiveTransactionManager} for reactive transaction management.
*/
@Nullable
Expand Down Expand Up @@ -375,7 +375,7 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
cleanupTransactionInfo(txInfo);
}

if (vavrPresent && VavrDelegate.isVavrTry(retVal)) {
if (retVal != null && vavrPresent && VavrDelegate.isVavrTry(retVal)) {
// Set rollback-only in case of Vavr failure matching our rollback rules...
TransactionStatus status = txInfo.getTransactionStatus();
if (status != null && txAttr != null) {
Expand All @@ -388,15 +388,16 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
}

else {
Object result;
final ThrowableHolder throwableHolder = new ThrowableHolder();

// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
try {
Object result = ((CallbackPreferringPlatformTransactionManager) ptm).execute(txAttr, status -> {
result = ((CallbackPreferringPlatformTransactionManager) ptm).execute(txAttr, status -> {
TransactionInfo txInfo = prepareTransactionInfo(ptm, txAttr, joinpointIdentification, status);
try {
Object retVal = invocation.proceedWithInvocation();
if (vavrPresent && VavrDelegate.isVavrTry(retVal)) {
if (retVal != null && vavrPresent && VavrDelegate.isVavrTry(retVal)) {
// Set rollback-only in case of Vavr failure matching our rollback rules...
retVal = VavrDelegate.evaluateTryFailure(retVal, txAttr, status);
}
Expand All @@ -422,12 +423,6 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
cleanupTransactionInfo(txInfo);
}
});

// Check result state: It might indicate a Throwable to rethrow.
if (throwableHolder.throwable != null) {
throw throwableHolder.throwable;
}
return result;
}
catch (ThrowableHolderException ex) {
throw ex.getCause();
Expand All @@ -445,11 +440,17 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
}
throw ex2;
}

// Check result state: It might indicate a Throwable to rethrow.
if (throwableHolder.throwable != null) {
throw throwableHolder.throwable;
}
return result;
}
}

/**
* Clear the cache.
* Clear the transaction manager cache.
*/
protected void clearTransactionManagerCache() {
this.transactionManagerCache.clear();
Expand Down Expand Up @@ -780,6 +781,7 @@ public String toString() {
@FunctionalInterface
protected interface InvocationCallback {

@Nullable
Object proceedWithInvocation() throws Throwable;
}

Expand Down

0 comments on commit 95c205e

Please sign in to comment.