001/*
002 * Copyright 2002-2017 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.TransactionStatus;
020
021/**
022 * Simple convenience class for TransactionCallback implementation.
023 * Allows for implementing a doInTransaction version without result,
024 * i.e. without the need for a return statement.
025 *
026 * @author Juergen Hoeller
027 * @since 28.03.2003
028 * @see TransactionTemplate
029 */
030public abstract class TransactionCallbackWithoutResult implements TransactionCallback<Object> {
031
032        @Override
033        public final Object doInTransaction(TransactionStatus status) {
034                doInTransactionWithoutResult(status);
035                return null;
036        }
037
038        /**
039         * Gets called by {@code TransactionTemplate.execute} within a transactional
040         * context. Does not need to care about transactions itself, although it can retrieve
041         * and influence the status of the current transaction via the given status object,
042         * e.g. setting rollback-only.
043         * <p>A RuntimeException thrown by the callback is treated as application
044         * exception that enforces a rollback. An exception gets propagated to the
045         * caller of the template.
046         * <p>Note when using JTA: JTA transactions only work with transactional
047         * JNDI resources, so implementations need to use such resources if they
048         * want transaction support.
049         * @param status associated transaction status
050         * @see TransactionTemplate#execute
051         */
052        protected abstract void doInTransactionWithoutResult(TransactionStatus status);
053
054}