001/*
002 * Copyright 2002-2012 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.support;
018
019import org.springframework.transaction.TransactionException;
020
021/**
022 * Interface specifying basic transaction execution operations.
023 * Implemented by {@link TransactionTemplate}. Not often used directly,
024 * but a useful option to enhance testability, as it can easily be
025 * mocked or stubbed.
026 *
027 * @author Juergen Hoeller
028 * @since 2.0.4
029 */
030public interface TransactionOperations {
031
032        /**
033         * Execute the action specified by the given callback object within a transaction.
034         * <p>Allows for returning a result object created within the transaction, that is,
035         * a domain object or a collection of domain objects. A RuntimeException thrown
036         * by the callback is treated as a fatal exception that enforces a rollback.
037         * Such an exception gets propagated to the caller of the template.
038         * @param action the callback object that specifies the transactional action
039         * @return a result object returned by the callback, or {@code null} if none
040         * @throws TransactionException in case of initialization, rollback, or system errors
041         * @throws RuntimeException if thrown by the TransactionCallback
042         */
043        <T> T execute(TransactionCallback<T> action) throws TransactionException;
044
045}