001/* 002 * Copyright 2012-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 * http://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.boot.autoconfigure.transaction; 018 019import org.springframework.boot.context.properties.ConfigurationProperties; 020import org.springframework.transaction.support.AbstractPlatformTransactionManager; 021 022/** 023 * Configuration properties that can be applied to an 024 * {@link AbstractPlatformTransactionManager}. 025 * 026 * @author Kazuki Shimizu 027 * @author Phillip Webb 028 * @since 1.5.0 029 */ 030@ConfigurationProperties(prefix = "spring.transaction") 031public class TransactionProperties implements 032 PlatformTransactionManagerCustomizer<AbstractPlatformTransactionManager> { 033 034 /** 035 * Default transaction timeout in seconds. 036 */ 037 private Integer defaultTimeout; 038 039 /** 040 * Perform the rollback on commit failures. 041 */ 042 private Boolean rollbackOnCommitFailure; 043 044 public Integer getDefaultTimeout() { 045 return this.defaultTimeout; 046 } 047 048 public void setDefaultTimeout(Integer defaultTimeout) { 049 this.defaultTimeout = defaultTimeout; 050 } 051 052 public Boolean getRollbackOnCommitFailure() { 053 return this.rollbackOnCommitFailure; 054 } 055 056 public void setRollbackOnCommitFailure(Boolean rollbackOnCommitFailure) { 057 this.rollbackOnCommitFailure = rollbackOnCommitFailure; 058 } 059 060 @Override 061 public void customize(AbstractPlatformTransactionManager transactionManager) { 062 if (this.defaultTimeout != null) { 063 transactionManager.setDefaultTimeout(this.defaultTimeout); 064 } 065 if (this.rollbackOnCommitFailure != null) { 066 transactionManager.setRollbackOnCommitFailure(this.rollbackOnCommitFailure); 067 } 068 } 069 070}