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.orm.jpa.hibernate; 018 019import javax.transaction.TransactionManager; 020import javax.transaction.UserTransaction; 021 022import org.hibernate.engine.transaction.jta.platform.internal.AbstractJtaPlatform; 023 024import org.springframework.transaction.jta.JtaTransactionManager; 025import org.springframework.util.Assert; 026 027/** 028 * Generic Hibernate {@link AbstractJtaPlatform} implementation that simply resolves the 029 * JTA {@link UserTransaction} and {@link TransactionManager} from the Spring-configured 030 * {@link JtaTransactionManager} implementation. 031 * 032 * @author Josh Long 033 * @author Phillip Webb 034 * @since 1.2.0 035 */ 036public class SpringJtaPlatform extends AbstractJtaPlatform { 037 038 private static final long serialVersionUID = 1L; 039 040 private final JtaTransactionManager transactionManager; 041 042 public SpringJtaPlatform(JtaTransactionManager transactionManager) { 043 Assert.notNull(transactionManager, "TransactionManager must not be null"); 044 this.transactionManager = transactionManager; 045 } 046 047 @Override 048 protected TransactionManager locateTransactionManager() { 049 return this.transactionManager.getTransactionManager(); 050 } 051 052 @Override 053 protected UserTransaction locateUserTransaction() { 054 return this.transactionManager.getUserTransaction(); 055 } 056 057}