1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -192,7 +192,7 @@ protected TransactionAspectSupport() {
192
192
193
193
/**
194
194
* Specify the name of the default transaction manager bean.
195
- * This can either point to a traditional {@link PlatformTransactionManager} or a
195
+ * <p> This can either point to a traditional {@link PlatformTransactionManager} or a
196
196
* {@link ReactiveTransactionManager} for reactive transaction management.
197
197
*/
198
198
public void setTransactionManagerBeanName (@ Nullable String transactionManagerBeanName ) {
@@ -209,7 +209,7 @@ protected final String getTransactionManagerBeanName() {
209
209
210
210
/**
211
211
* Specify the <em>default</em> transaction manager to use to drive transactions.
212
- * This can either be a traditional {@link PlatformTransactionManager} or a
212
+ * <p> This can either be a traditional {@link PlatformTransactionManager} or a
213
213
* {@link ReactiveTransactionManager} for reactive transaction management.
214
214
* <p>The default transaction manager will be used if a <em>qualifier</em>
215
215
* has not been declared for a given transaction or if an explicit name for the
@@ -222,7 +222,7 @@ public void setTransactionManager(@Nullable TransactionManager transactionManage
222
222
223
223
/**
224
224
* Return the default transaction manager, or {@code null} if unknown.
225
- * This can either be a traditional {@link PlatformTransactionManager} or a
225
+ * <p> This can either be a traditional {@link PlatformTransactionManager} or a
226
226
* {@link ReactiveTransactionManager} for reactive transaction management.
227
227
*/
228
228
@ Nullable
@@ -375,7 +375,7 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
375
375
cleanupTransactionInfo (txInfo );
376
376
}
377
377
378
- if (vavrPresent && VavrDelegate .isVavrTry (retVal )) {
378
+ if (retVal != null && vavrPresent && VavrDelegate .isVavrTry (retVal )) {
379
379
// Set rollback-only in case of Vavr failure matching our rollback rules...
380
380
TransactionStatus status = txInfo .getTransactionStatus ();
381
381
if (status != null && txAttr != null ) {
@@ -388,15 +388,16 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
388
388
}
389
389
390
390
else {
391
+ Object result ;
391
392
final ThrowableHolder throwableHolder = new ThrowableHolder ();
392
393
393
394
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
394
395
try {
395
- Object result = ((CallbackPreferringPlatformTransactionManager ) ptm ).execute (txAttr , status -> {
396
+ result = ((CallbackPreferringPlatformTransactionManager ) ptm ).execute (txAttr , status -> {
396
397
TransactionInfo txInfo = prepareTransactionInfo (ptm , txAttr , joinpointIdentification , status );
397
398
try {
398
399
Object retVal = invocation .proceedWithInvocation ();
399
- if (vavrPresent && VavrDelegate .isVavrTry (retVal )) {
400
+ if (retVal != null && vavrPresent && VavrDelegate .isVavrTry (retVal )) {
400
401
// Set rollback-only in case of Vavr failure matching our rollback rules...
401
402
retVal = VavrDelegate .evaluateTryFailure (retVal , txAttr , status );
402
403
}
@@ -422,12 +423,6 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
422
423
cleanupTransactionInfo (txInfo );
423
424
}
424
425
});
425
-
426
- // Check result state: It might indicate a Throwable to rethrow.
427
- if (throwableHolder .throwable != null ) {
428
- throw throwableHolder .throwable ;
429
- }
430
- return result ;
431
426
}
432
427
catch (ThrowableHolderException ex ) {
433
428
throw ex .getCause ();
@@ -445,11 +440,17 @@ protected Object invokeWithinTransaction(Method method, @Nullable Class<?> targe
445
440
}
446
441
throw ex2 ;
447
442
}
443
+
444
+ // Check result state: It might indicate a Throwable to rethrow.
445
+ if (throwableHolder .throwable != null ) {
446
+ throw throwableHolder .throwable ;
447
+ }
448
+ return result ;
448
449
}
449
450
}
450
451
451
452
/**
452
- * Clear the cache.
453
+ * Clear the transaction manager cache.
453
454
*/
454
455
protected void clearTransactionManagerCache () {
455
456
this .transactionManagerCache .clear ();
@@ -780,6 +781,7 @@ public String toString() {
780
781
@ FunctionalInterface
781
782
protected interface InvocationCallback {
782
783
784
+ @ Nullable
783
785
Object proceedWithInvocation () throws Throwable ;
784
786
}
785
787
0 commit comments