001/* 002 * Copyright 2002-2012 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.orm.hibernate3; 018 019import java.util.Properties; 020 021import org.hibernate.ConnectionReleaseMode; 022import org.hibernate.Transaction; 023import org.hibernate.jdbc.JDBCContext; 024import org.hibernate.transaction.JDBCTransaction; 025import org.hibernate.transaction.TransactionFactory; 026 027import org.springframework.transaction.support.TransactionSynchronizationManager; 028 029/** 030 * Spring-aware implementation of the Hibernate TransactionFactory interface, aware of 031 * Spring-synchronized transactions (in particular Spring-managed JTA transactions) 032 * and asking for default release mode ON_CLOSE. Otherwise identical to Hibernate's 033 * default {@link org.hibernate.transaction.JDBCTransactionFactory} implementation. 034 * 035 * @author Juergen Hoeller 036 * @since 2.5.4 037 * @see org.springframework.transaction.support.TransactionSynchronizationManager 038 * @see org.hibernate.transaction.JDBCTransactionFactory 039 * @deprecated as of Spring 4.3, in favor of Hibernate 4.x/5.x 040 */ 041@Deprecated 042public class SpringTransactionFactory implements TransactionFactory { 043 044 /** 045 * Sets connection release mode "on_close" as default. 046 * <p>This was the case for Hibernate 3.0; Hibernate 3.1 changed 047 * it to "auto" (i.e. "after_statement" or "after_transaction"). 048 * However, for Spring's resource management (in particular for 049 * HibernateTransactionManager), "on_close" is the better default. 050 */ 051 @Override 052 public ConnectionReleaseMode getDefaultReleaseMode() { 053 return ConnectionReleaseMode.ON_CLOSE; 054 } 055 056 @Override 057 public Transaction createTransaction(JDBCContext jdbcContext, Context transactionContext) { 058 return new JDBCTransaction(jdbcContext, transactionContext); 059 } 060 061 @Override 062 public void configure(Properties props) { 063 } 064 065 @Override 066 public boolean isTransactionManagerRequired() { 067 return false; 068 } 069 070 @Override 071 public boolean areCallbacksLocalToHibernateTransactions() { 072 return true; 073 } 074 075 @Override 076 public boolean isTransactionInProgress( 077 JDBCContext jdbcContext, Context transactionContext, Transaction transaction) { 078 079 return (transaction != null && transaction.isActive()) || 080 TransactionSynchronizationManager.isActualTransactionActive(); 081 } 082 083}