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.support; 018 019/** 020 * A simple {@link org.springframework.transaction.TransactionStatus} 021 * implementation. Derives from {@link AbstractTransactionStatus} and 022 * adds an explicit {@link #isNewTransaction() "newTransaction"} flag. 023 * 024 * <p>This class is not used by any of Spring's pre-built 025 * {@link org.springframework.transaction.PlatformTransactionManager} 026 * implementations. It is mainly provided as a start for custom transaction 027 * manager implementations and as a static mock for testing transactional 028 * code (either as part of a mock {@code PlatformTransactionManager} or 029 * as argument passed into a {@link TransactionCallback} to be tested). 030 * 031 * @author Juergen Hoeller 032 * @since 1.2.3 033 * @see TransactionCallback#doInTransaction 034 */ 035public class SimpleTransactionStatus extends AbstractTransactionStatus { 036 037 private final boolean newTransaction; 038 039 040 /** 041 * Create a new {@code SimpleTransactionStatus} instance, 042 * indicating a new transaction. 043 */ 044 public SimpleTransactionStatus() { 045 this(true); 046 } 047 048 /** 049 * Create a new {@code SimpleTransactionStatus} instance. 050 * @param newTransaction whether to indicate a new transaction 051 */ 052 public SimpleTransactionStatus(boolean newTransaction) { 053 this.newTransaction = newTransaction; 054 } 055 056 057 @Override 058 public boolean isNewTransaction() { 059 return this.newTransaction; 060 } 061 062}