SpringTransactionFactory.java 2.7 KB
Newer Older
A
Arjen Poutsma 已提交
1
/*
2
 * Copyright 2002-2012 the original author or authors.
A
Arjen Poutsma 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.orm.hibernate3;

import java.util.Properties;

import org.hibernate.ConnectionReleaseMode;
import org.hibernate.Transaction;
import org.hibernate.jdbc.JDBCContext;
import org.hibernate.transaction.JDBCTransaction;
import org.hibernate.transaction.TransactionFactory;

import org.springframework.transaction.support.TransactionSynchronizationManager;

/**
 * Spring-aware implementation of the Hibernate TransactionFactory interface, aware of
 * Spring-synchronized transactions (in particular Spring-managed JTA transactions)
 * and asking for default release mode ON_CLOSE. Otherwise identical to Hibernate's
 * default {@link org.hibernate.transaction.JDBCTransactionFactory} implementation.
 *
 * @author Juergen Hoeller
 * @since 2.5.4
 * @see org.springframework.transaction.support.TransactionSynchronizationManager
 * @see org.hibernate.transaction.JDBCTransactionFactory
J
Juergen Hoeller 已提交
39
 * @deprecated as of Spring 4.3, in favor of Hibernate 4.x/5.x
A
Arjen Poutsma 已提交
40
 */
J
Juergen Hoeller 已提交
41
@Deprecated
A
Arjen Poutsma 已提交
42 43 44 45 46 47 48 49 50
public class SpringTransactionFactory implements TransactionFactory {

	/**
	 * Sets connection release mode "on_close" as default.
	 * <p>This was the case for Hibernate 3.0; Hibernate 3.1 changed
	 * it to "auto" (i.e. "after_statement" or "after_transaction").
	 * However, for Spring's resource management (in particular for
	 * HibernateTransactionManager), "on_close" is the better default.
	 */
51
	@Override
A
Arjen Poutsma 已提交
52 53 54 55
	public ConnectionReleaseMode getDefaultReleaseMode() {
		return ConnectionReleaseMode.ON_CLOSE;
	}

56
	@Override
A
Arjen Poutsma 已提交
57 58 59 60
	public Transaction createTransaction(JDBCContext jdbcContext, Context transactionContext) {
		return new JDBCTransaction(jdbcContext, transactionContext);
	}

61
	@Override
A
Arjen Poutsma 已提交
62 63 64
	public void configure(Properties props) {
	}

65
	@Override
A
Arjen Poutsma 已提交
66 67 68 69
	public boolean isTransactionManagerRequired() {
		return false;
	}

70
	@Override
A
Arjen Poutsma 已提交
71 72 73 74
	public boolean areCallbacksLocalToHibernateTransactions() {
		return true;
	}

75
	@Override
A
Arjen Poutsma 已提交
76 77 78 79 80 81 82 83
	public boolean isTransactionInProgress(
			JDBCContext jdbcContext, Context transactionContext, Transaction transaction) {

		return (transaction != null && transaction.isActive()) ||
				TransactionSynchronizationManager.isActualTransactionActive();
	}

}