001/* 002 * Copyright 2002-2019 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.transaction.reactive; 018 019import org.reactivestreams.Publisher; 020 021import org.springframework.transaction.ReactiveTransaction; 022 023/** 024 * Callback interface for reactive transactional code. Used with {@link TransactionalOperator}'s 025 * {@code execute} method, often as anonymous class within a method implementation. 026 * 027 * <p>Typically used to assemble various calls to transaction-unaware data access 028 * services into a higher-level service method with transaction demarcation. As an 029 * alternative, consider the use of declarative transaction demarcation (e.g. through 030 * Spring's {@link org.springframework.transaction.annotation.Transactional} annotation). 031 * 032 * @author Mark Paluch 033 * @author Juergen Hoeller 034 * @since 5.2 035 * @see TransactionalOperator 036 * @param <T> the result type 037 */ 038@FunctionalInterface 039public interface TransactionCallback<T> { 040 041 /** 042 * Gets called by {@link TransactionalOperator} within a transactional context. 043 * Does not need to care about transactions itself, although it can retrieve and 044 * influence the status of the current transaction via the given status object, 045 * e.g. setting rollback-only. 046 * @param status associated transaction status 047 * @return a result publisher 048 * @see TransactionalOperator#transactional 049 */ 050 Publisher<T> doInTransaction(ReactiveTransaction status); 051 052}