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