001/* 002 * Copyright 2002-2018 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; 018 019import java.io.Flushable; 020 021/** 022 * Representation of the status of a transaction. 023 * 024 * <p>Transactional code can use this to retrieve status information, 025 * and to programmatically request a rollback (instead of throwing 026 * an exception that causes an implicit rollback). 027 * 028 * <p>Includes the {@link SavepointManager} interface to provide access 029 * to savepoint management facilities. Note that savepoint management 030 * is only available if supported by the underlying transaction manager. 031 * 032 * @author Juergen Hoeller 033 * @since 27.03.2003 034 * @see #setRollbackOnly() 035 * @see PlatformTransactionManager#getTransaction 036 * @see org.springframework.transaction.support.TransactionCallback#doInTransaction 037 * @see org.springframework.transaction.interceptor.TransactionInterceptor#currentTransactionStatus() 038 */ 039public interface TransactionStatus extends SavepointManager, Flushable { 040 041 /** 042 * Return whether the present transaction is new; otherwise participating 043 * in an existing transaction, or potentially not running in an actual 044 * transaction in the first place. 045 */ 046 boolean isNewTransaction(); 047 048 /** 049 * Return whether this transaction internally carries a savepoint, 050 * that is, has been created as nested transaction based on a savepoint. 051 * <p>This method is mainly here for diagnostic purposes, alongside 052 * {@link #isNewTransaction()}. For programmatic handling of custom 053 * savepoints, use the operations provided by {@link SavepointManager}. 054 * @see #isNewTransaction() 055 * @see #createSavepoint() 056 * @see #rollbackToSavepoint(Object) 057 * @see #releaseSavepoint(Object) 058 */ 059 boolean hasSavepoint(); 060 061 /** 062 * Set the transaction rollback-only. This instructs the transaction manager 063 * that the only possible outcome of the transaction may be a rollback, as 064 * alternative to throwing an exception which would in turn trigger a rollback. 065 * <p>This is mainly intended for transactions managed by 066 * {@link org.springframework.transaction.support.TransactionTemplate} or 067 * {@link org.springframework.transaction.interceptor.TransactionInterceptor}, 068 * where the actual commit/rollback decision is made by the container. 069 * @see org.springframework.transaction.support.TransactionCallback#doInTransaction 070 * @see org.springframework.transaction.interceptor.TransactionAttribute#rollbackOn 071 */ 072 void setRollbackOnly(); 073 074 /** 075 * Return whether the transaction has been marked as rollback-only 076 * (either by the application or by the transaction infrastructure). 077 */ 078 boolean isRollbackOnly(); 079 080 /** 081 * Flush the underlying session to the datastore, if applicable: 082 * for example, all affected Hibernate/JPA sessions. 083 * <p>This is effectively just a hint and may be a no-op if the underlying 084 * transaction manager does not have a flush concept. A flush signal may 085 * get applied to the primary resource or to transaction synchronizations, 086 * depending on the underlying resource. 087 */ 088 @Override 089 void flush(); 090 091 /** 092 * Return whether this transaction is completed, that is, 093 * whether it has already been committed or rolled back. 094 * @see PlatformTransactionManager#commit 095 * @see PlatformTransactionManager#rollback 096 */ 097 boolean isCompleted(); 098 099}