Restore TransactionOperations Kotlin API compatibilty
This commit renames the Runnable variant to executeWithoutResult and uses a Consumer<TransactionStatus> parameter for better consistency with TransactionCallbackWithoutResult. Closes gh-23724
This commit is contained in:
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.springframework.transaction.support;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
/**
|
||||
* Interface specifying basic transaction execution operations.
|
||||
@@ -40,6 +43,7 @@ public interface TransactionOperations {
|
||||
* @return a result object returned by the callback, or {@code null} if none
|
||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||
* @throws RuntimeException if thrown by the TransactionCallback
|
||||
* @see #executeWithoutResult(Consumer)
|
||||
*/
|
||||
@Nullable
|
||||
<T> T execute(TransactionCallback<T> action) throws TransactionException;
|
||||
@@ -59,9 +63,9 @@ public interface TransactionOperations {
|
||||
* @see #execute(TransactionCallback)
|
||||
* @see TransactionCallbackWithoutResult
|
||||
*/
|
||||
default void execute(Runnable action) throws TransactionException {
|
||||
default void executeWithoutResult(Consumer<TransactionStatus> action) throws TransactionException {
|
||||
execute(status -> {
|
||||
action.run();
|
||||
action.accept(status);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.springframework.transaction.support;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.transaction.TransactionException;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
/**
|
||||
* A {@link TransactionOperations} implementation which executes a given
|
||||
@@ -43,8 +46,8 @@ final class WithoutTransactionOperations implements TransactionOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(Runnable action) throws TransactionException {
|
||||
action.run();
|
||||
public void executeWithoutResult(Consumer<TransactionStatus> action) throws TransactionException {
|
||||
action.accept(new SimpleTransactionStatus(false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user