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:
parent
f071f95899
commit
563919befd
|
@ -412,7 +412,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 = cpptm.execute(txAttr, status -> {
|
result = cpptm.<@Nullable Object> 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();
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.transaction.reactive;
|
package org.springframework.transaction.reactive;
|
||||||
|
|
||||||
|
import org.jspecify.annotations.Nullable;
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
|
|
||||||
import org.springframework.transaction.ReactiveTransaction;
|
import org.springframework.transaction.ReactiveTransaction;
|
||||||
|
@ -36,7 +37,7 @@ import org.springframework.transaction.ReactiveTransaction;
|
||||||
* @see TransactionalOperator
|
* @see TransactionalOperator
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface TransactionCallback<T> {
|
public interface TransactionCallback<T extends @Nullable Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets called by {@link TransactionalOperator} within a transactional context.
|
* Gets called by {@link TransactionalOperator} within a transactional context.
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.transaction.reactive;
|
package org.springframework.transaction.reactive;
|
||||||
|
|
||||||
|
import org.jspecify.annotations.Nullable;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public interface TransactionalOperator {
|
||||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||||
* @throws RuntimeException if thrown by the TransactionCallback
|
* @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);
|
return execute(it -> flux);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ public interface TransactionalOperator {
|
||||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||||
* @throws RuntimeException if thrown by the TransactionCallback
|
* @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();
|
return execute(it -> mono).singleOrEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ public interface TransactionalOperator {
|
||||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||||
* @throws RuntimeException if thrown by the TransactionCallback
|
* @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
|
// Static builder methods
|
||||||
|
|
|
@ -55,7 +55,7 @@ public interface CallbackPreferringPlatformTransactionManager extends PlatformTr
|
||||||
* @throws TransactionException in case of initialization, rollback, or system errors
|
* @throws TransactionException in case of initialization, rollback, or system errors
|
||||||
* @throws RuntimeException if thrown by the TransactionCallback
|
* @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;
|
throws TransactionException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ import org.springframework.transaction.TransactionStatus;
|
||||||
* @see CallbackPreferringPlatformTransactionManager
|
* @see CallbackPreferringPlatformTransactionManager
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface TransactionCallback<T> {
|
public interface TransactionCallback<T extends @Nullable Object> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets called by {@link TransactionTemplate#execute} within a transactional context.
|
* Gets called by {@link TransactionTemplate#execute} within a transactional context.
|
||||||
|
@ -53,6 +53,6 @@ public interface TransactionCallback<T> {
|
||||||
* @see TransactionTemplate#execute
|
* @see TransactionTemplate#execute
|
||||||
* @see CallbackPreferringPlatformTransactionManager#execute
|
* @see CallbackPreferringPlatformTransactionManager#execute
|
||||||
*/
|
*/
|
||||||
@Nullable T doInTransaction(TransactionStatus status);
|
T doInTransaction(TransactionStatus status);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.springframework.transaction.TransactionStatus;
|
||||||
* @since 28.03.2003
|
* @since 28.03.2003
|
||||||
* @see TransactionTemplate
|
* @see TransactionTemplate
|
||||||
*/
|
*/
|
||||||
public abstract class TransactionCallbackWithoutResult implements TransactionCallback<Object> {
|
public abstract class TransactionCallbackWithoutResult implements TransactionCallback<@Nullable Object> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final @Nullable Object doInTransaction(TransactionStatus status) {
|
public final @Nullable Object doInTransaction(TransactionStatus status) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public interface TransactionOperations {
|
||||||
* @throws RuntimeException if thrown by the TransactionCallback
|
* @throws RuntimeException if thrown by the TransactionCallback
|
||||||
* @see #executeWithoutResult(Consumer)
|
* @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.
|
* Execute the action specified by the given {@link Runnable} within a transaction.
|
||||||
|
@ -64,7 +64,7 @@ public interface TransactionOperations {
|
||||||
* @see TransactionCallbackWithoutResult
|
* @see TransactionCallbackWithoutResult
|
||||||
*/
|
*/
|
||||||
default void executeWithoutResult(Consumer<TransactionStatus> action) throws TransactionException {
|
default void executeWithoutResult(Consumer<TransactionStatus> action) throws TransactionException {
|
||||||
execute(status -> {
|
this.<@Nullable Object> execute(status -> {
|
||||||
action.accept(status);
|
action.accept(status);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
|
@ -124,7 +124,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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");
|
Assert.state(this.transactionManager != null, "No PlatformTransactionManager set");
|
||||||
|
|
||||||
if (this.transactionManager instanceof CallbackPreferringPlatformTransactionManager cpptm) {
|
if (this.transactionManager instanceof CallbackPreferringPlatformTransactionManager cpptm) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ final class WithoutTransactionOperations implements TransactionOperations {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@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));
|
return action.doInTransaction(new SimpleTransactionStatus(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue