mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-25 16:29:28 +00:00
Revise nullability of Transaction[Callback|Operations|Operator]
This commit revises the nullability declarations in TransactionCallback, TransactionOperations, and TransactionalOperator. Closes gh-35561
This commit is contained in:
+1
-1
@@ -412,7 +412,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init
|
||||
|
||||
// It's a CallbackPreferringPlatformTransactionManager: pass a TransactionCallback in.
|
||||
try {
|
||||
result = cpptm.execute(txAttr, status -> {
|
||||
result = cpptm.<@Nullable Object> execute(txAttr, status -> {
|
||||
TransactionInfo txInfo = prepareTransactionInfo(ptm, txAttr, joinpointIdentification, status);
|
||||
try {
|
||||
Object retVal = invocation.proceedWithInvocation();
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.transaction.reactive;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import org.springframework.transaction.ReactiveTransaction;
|
||||
@@ -36,7 +37,7 @@ import org.springframework.transaction.ReactiveTransaction;
|
||||
* @see TransactionalOperator
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TransactionCallback<T> {
|
||||
public interface TransactionCallback<T extends @Nullable Object> {
|
||||
|
||||
/**
|
||||
* Gets called by {@link TransactionalOperator} within a transactional context.
|
||||
|
||||
+4
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.transaction.reactive;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@@ -59,7 +60,7 @@ public interface TransactionalOperator {
|
||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||
* @throws RuntimeException if thrown by the TransactionCallback
|
||||
*/
|
||||
default <T> Flux<T> transactional(Flux<T> flux) {
|
||||
default <T extends @Nullable Object> Flux<T> transactional(Flux<T> flux) {
|
||||
return execute(it -> flux);
|
||||
}
|
||||
|
||||
@@ -70,7 +71,7 @@ public interface TransactionalOperator {
|
||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||
* @throws RuntimeException if thrown by the TransactionCallback
|
||||
*/
|
||||
default <T> Mono<T> transactional(Mono<T> mono) {
|
||||
default <T extends @Nullable Object> Mono<T> transactional(Mono<T> mono) {
|
||||
return execute(it -> mono).singleOrEmpty();
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ public interface TransactionalOperator {
|
||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||
* @throws RuntimeException if thrown by the TransactionCallback
|
||||
*/
|
||||
<T> Flux<T> execute(TransactionCallback<T> action) throws TransactionException;
|
||||
<T extends @Nullable Object> Flux<T> execute(TransactionCallback<T> action) throws TransactionException;
|
||||
|
||||
|
||||
// Static builder methods
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public interface CallbackPreferringPlatformTransactionManager extends PlatformTr
|
||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||
* @throws RuntimeException if thrown by the TransactionCallback
|
||||
*/
|
||||
<T> @Nullable T execute(@Nullable TransactionDefinition definition, TransactionCallback<T> callback)
|
||||
<T extends @Nullable Object> T execute(@Nullable TransactionDefinition definition, TransactionCallback<T> callback)
|
||||
throws TransactionException;
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -36,7 +36,7 @@ import org.springframework.transaction.TransactionStatus;
|
||||
* @see CallbackPreferringPlatformTransactionManager
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface TransactionCallback<T> {
|
||||
public interface TransactionCallback<T extends @Nullable Object> {
|
||||
|
||||
/**
|
||||
* Gets called by {@link TransactionTemplate#execute} within a transactional context.
|
||||
@@ -53,6 +53,6 @@ public interface TransactionCallback<T> {
|
||||
* @see TransactionTemplate#execute
|
||||
* @see CallbackPreferringPlatformTransactionManager#execute
|
||||
*/
|
||||
@Nullable T doInTransaction(TransactionStatus status);
|
||||
T doInTransaction(TransactionStatus status);
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ import org.springframework.transaction.TransactionStatus;
|
||||
* @since 28.03.2003
|
||||
* @see TransactionTemplate
|
||||
*/
|
||||
public abstract class TransactionCallbackWithoutResult implements TransactionCallback<Object> {
|
||||
public abstract class TransactionCallbackWithoutResult implements TransactionCallback<@Nullable Object> {
|
||||
|
||||
@Override
|
||||
public final @Nullable Object doInTransaction(TransactionStatus status) {
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ public interface TransactionOperations {
|
||||
* @throws RuntimeException if thrown by the TransactionCallback
|
||||
* @see #executeWithoutResult(Consumer)
|
||||
*/
|
||||
<T> @Nullable T execute(TransactionCallback<T> action) throws TransactionException;
|
||||
<T extends @Nullable Object> T execute(TransactionCallback<T> action) throws TransactionException;
|
||||
|
||||
/**
|
||||
* Execute the action specified by the given {@link Runnable} within a transaction.
|
||||
@@ -64,7 +64,7 @@ public interface TransactionOperations {
|
||||
* @see TransactionCallbackWithoutResult
|
||||
*/
|
||||
default void executeWithoutResult(Consumer<TransactionStatus> action) throws TransactionException {
|
||||
execute(status -> {
|
||||
this.<@Nullable Object> execute(status -> {
|
||||
action.accept(status);
|
||||
return null;
|
||||
});
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition
|
||||
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T execute(TransactionCallback<T> action) throws TransactionException {
|
||||
public <T extends @Nullable Object> T execute(TransactionCallback<T> action) throws TransactionException {
|
||||
Assert.state(this.transactionManager != null, "No PlatformTransactionManager set");
|
||||
|
||||
if (this.transactionManager instanceof CallbackPreferringPlatformTransactionManager cpptm) {
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ final class WithoutTransactionOperations implements TransactionOperations {
|
||||
|
||||
|
||||
@Override
|
||||
public <T> @Nullable T execute(TransactionCallback<T> action) throws TransactionException {
|
||||
public <T extends @Nullable Object> T execute(TransactionCallback<T> action) throws TransactionException {
|
||||
return action.doInTransaction(new SimpleTransactionStatus(false));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user