当前位置: 首页>>代码示例>>Java>>正文


Java TransactionSynchronizationManager.unbindResourceIfPossible方法代码示例

本文整理汇总了Java中org.springframework.transaction.support.TransactionSynchronizationManager.unbindResourceIfPossible方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionSynchronizationManager.unbindResourceIfPossible方法的具体用法?Java TransactionSynchronizationManager.unbindResourceIfPossible怎么用?Java TransactionSynchronizationManager.unbindResourceIfPossible使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.transaction.support.TransactionSynchronizationManager的用法示例。


在下文中一共展示了TransactionSynchronizationManager.unbindResourceIfPossible方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
public void afterCompletion(int status) {
	// If we haven't closed the Connection in beforeCompletion,
	// close it now. The holder might have been used for other
	// cleanup in the meantime, for example by a Hibernate Session.
	if (this.holderActive) {
		// The thread-bound ConnectionHolder might not be available anymore,
		// since afterCompletion might get called from a different thread.
		TransactionSynchronizationManager.unbindResourceIfPossible(this.dataSource);
		this.holderActive = false;
		if (this.connectionHolder.hasConnection()) {
			releaseConnection(this.connectionHolder.getConnection(), this.dataSource);
			// Reset the ConnectionHolder: It might remain bound to the thread.
			this.connectionHolder.setConnection(null);
		}
	}
	this.connectionHolder.reset();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:19,代码来源:DataSourceUtils.java

示例2: doCleanupAfterCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //导入方法依赖的package包/类
@Override
protected void doCleanupAfterCompletion(Object transaction) {
	JpaTransactionObject txObject = (JpaTransactionObject) transaction;

	// Remove the entity manager holder from the thread, if still there.
	// (Could have been removed by EntityManagerFactoryUtils in order
	// to replace it with an unsynchronized EntityManager).
	if (txObject.isNewEntityManagerHolder()) {
		TransactionSynchronizationManager.unbindResourceIfPossible(getEntityManagerFactory());
	}
	txObject.getEntityManagerHolder().clear();

	// Remove the JDBC connection holder from the thread, if exposed.
	if (txObject.hasConnectionHolder()) {
		TransactionSynchronizationManager.unbindResource(getDataSource());
		try {
			getJpaDialect().releaseJdbcConnection(txObject.getConnectionHolder().getConnectionHandle(),
					txObject.getEntityManagerHolder().getEntityManager());
		}
		catch (Exception ex) {
			// Just log it, to keep a transaction-related exception.
			logger.error("Could not close JDBC connection after transaction", ex);
		}
	}

	getJpaDialect().cleanupTransaction(txObject.getTransactionData());

	// Remove the entity manager holder from the thread.
	if (txObject.isNewEntityManagerHolder()) {
		EntityManager em = txObject.getEntityManagerHolder().getEntityManager();
		if (logger.isDebugEnabled()) {
			logger.debug("Closing JPA EntityManager [" + em + "] after transaction");
		}
		EntityManagerFactoryUtils.closeEntityManager(em);
	}
	else {
		logger.debug("Not closing pre-bound JPA EntityManager after transaction");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:40,代码来源:JpaTransactionManager.java


注:本文中的org.springframework.transaction.support.TransactionSynchronizationManager.unbindResourceIfPossible方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。