當前位置: 首頁>>代碼示例>>Java>>正文


Java TransactionSynchronizationManager.unbindResource方法代碼示例

本文整理匯總了Java中org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource方法的典型用法代碼示例。如果您正苦於以下問題:Java TransactionSynchronizationManager.unbindResource方法的具體用法?Java TransactionSynchronizationManager.unbindResource怎麽用?Java TransactionSynchronizationManager.unbindResource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.transaction.support.TransactionSynchronizationManager的用法示例。


在下文中一共展示了TransactionSynchronizationManager.unbindResource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: afterCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();
	Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
	if (count != null) {
		// Do not modify the PersistenceManager: just clear the marker.
		if (count > 1) {
			request.setAttribute(participateAttributeName, count - 1, WebRequest.SCOPE_REQUEST);
		}
		else {
			request.removeAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		}
	}
	else {
		PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
				TransactionSynchronizationManager.unbindResource(getPersistenceManagerFactory());
		logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManagerFactoryUtils.releasePersistenceManager(
				pmHolder.getPersistenceManager(), getPersistenceManagerFactory());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:OpenPersistenceManagerInViewInterceptor.java

示例2: afterCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Unbind the Hibernate {@code Session} from the thread and close it (in
 * single session mode), or process deferred close for all sessions that have
 * been opened during the current request (in deferred close mode).
 * @see org.springframework.transaction.support.TransactionSynchronizationManager
 */
@Override
public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException {
	if (!decrementParticipateCount(request)) {
		if (isSingleSession()) {
			// single session mode
			SessionHolder sessionHolder =
					(SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory());
			logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor");
			SessionFactoryUtils.closeSession(sessionHolder.getSession());
		}
		else {
			// deferred close mode
			SessionFactoryUtils.processDeferredClose(getSessionFactory());
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:OpenSessionInViewInterceptor.java

示例3: 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

示例4: invoke

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
	SessionFactory sf = getSessionFactory();
	if (!TransactionSynchronizationManager.hasResource(sf)) {
		// New Session to be bound for the current method's scope...
		Session session = openSession();
		try {
			TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
			return invocation.proceed();
		}
		finally {
			SessionFactoryUtils.closeSession(session);
			TransactionSynchronizationManager.unbindResource(sf);
		}
	}
	else {
		// Pre-bound Session found -> simply proceed.
		return invocation.proceed();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:OpenSessionInterceptor.java

示例5: clearSynchronization

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Cleans out transaction resources if present
 */
private static void clearSynchronization()
{
    if (TransactionSynchronizationManager.hasResource(RESOURCE_KEY_TXN_SYNCH))
    {
        Object txnSynch = TransactionSynchronizationManager.unbindResource(RESOURCE_KEY_TXN_SYNCH);
        // done
        if (logger.isDebugEnabled())
        {
            logger.debug("Unbound txn synch:" + txnSynch);
        }
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:16,代碼來源:TransactionSupportUtil.java

示例6: doCleanupAfterCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected void doCleanupAfterCompletion(Object transaction) {
    // Remove the connection holder from the thread, if exposed.
    if (checkNewConnectionHolder(transaction)&&null!= TransactionSynchronizationManager.getResource(getDataSource())) {
        TransactionSynchronizationManager.unbindResource(getDataSource());
    }
}
 
開發者ID:zhangkewei,項目名稱:dubbo-transaction,代碼行數:8,代碼來源:DubboTransactionDataSourceTransactonManager.java

示例7: doCleanupAfterCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected void doCleanupAfterCompletion(Object transaction) {
	long txId = getTransactionId();
    logger.info(" [LITX]結束事務 [TX ID: " + txId + "]");
    super.doCleanupAfterCompletion(transaction);
    TransactionSynchronizationManager.unbindResource(LitxConstant.TRANSACTION_CONTEXT_KEY);
    TransactionSynchronizationManager.unbindResource(LitxConstant.TRANSACTION_ID_KEY);
}
 
開發者ID:thebeastshop,項目名稱:litx,代碼行數:9,代碼來源:LitTransactionManager.java

示例8: suspend

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public void suspend() {
	if (this.holderActive) {
		TransactionSynchronizationManager.unbindResource(this.sessionFactory);
		// Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss.
		getCurrentSession().disconnect();
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:SpringSessionSynchronization.java

示例9: doSuspend

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected Object doSuspend(Object transaction) {
	DataSourceTransactionObject txObject = (DataSourceTransactionObject) transaction;
	txObject.setConnectionHolder(null);
	ConnectionHolder conHolder = (ConnectionHolder)
			TransactionSynchronizationManager.unbindResource(this.dataSource);
	return conHolder;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:9,代碼來源:DataSourceTransactionManager.java

示例10: beforeCompletion

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public void beforeCompletion() {
	// Release Connection early if the holder is not open anymore
	// (that is, not used by another resource like a Hibernate Session
	// that has its own cleanup via transaction synchronization),
	// to avoid issues with strict JTA implementations that expect
	// the close call before transaction completion.
	if (!this.connectionHolder.isOpen()) {
		TransactionSynchronizationManager.unbindResource(this.dataSource);
		this.holderActive = false;
		if (this.connectionHolder.hasConnection()) {
			releaseConnection(this.connectionHolder.getConnection(), this.dataSource);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:16,代碼來源:DataSourceUtils.java

示例11: doFilterInternal

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected void doFilterInternal(
		HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
		throws ServletException, IOException {

	PersistenceManagerFactory pmf = lookupPersistenceManagerFactory(request);
	boolean participate = false;

	if (TransactionSynchronizationManager.hasResource(pmf)) {
		// Do not modify the PersistenceManager: just set the participate flag.
		participate = true;
	}
	else {
		logger.debug("Opening JDO PersistenceManager in OpenPersistenceManagerInViewFilter");
		PersistenceManager pm = PersistenceManagerFactoryUtils.getPersistenceManager(pmf, true);
		TransactionSynchronizationManager.bindResource(pmf, new PersistenceManagerHolder(pm));
	}

	try {
		filterChain.doFilter(request, response);
	}

	finally {
		if (!participate) {
			PersistenceManagerHolder pmHolder = (PersistenceManagerHolder)
					TransactionSynchronizationManager.unbindResource(pmf);
			logger.debug("Closing JDO PersistenceManager in OpenPersistenceManagerInViewFilter");
			PersistenceManagerFactoryUtils.releasePersistenceManager(pmHolder.getPersistenceManager(), pmf);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:32,代碼來源:OpenPersistenceManagerInViewFilter.java

示例12: doResume

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected void doResume(Object transaction, Object suspendedResources) {
	SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder) suspendedResources;
	if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
		// From non-transactional code running in active transaction synchronization
		// -> can be safely removed, will be closed on transaction completion.
		TransactionSynchronizationManager.unbindResource(getSessionFactory());
	}
	TransactionSynchronizationManager.bindResource(getSessionFactory(), resourcesHolder.getSessionHolder());
	if (getDataSource() != null) {
		TransactionSynchronizationManager.bindResource(getDataSource(), resourcesHolder.getConnectionHolder());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:14,代碼來源:HibernateTransactionManager.java

示例13: unbindLogProcessContext

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
private void unbindLogProcessContext(){
	TransactionSynchronizationManager.unbindResource(LOG_PROCESS_CONTEXT);
}
 
開發者ID:QNJR-GROUP,項目名稱:EasyTransaction,代碼行數:4,代碼來源:EasyTransSynchronizer.java

示例14: postProcess

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public <T> void postProcess(NativeWebRequest request, Callable<T> task, Object concurrentResult) {
	TransactionSynchronizationManager.unbindResource(this.sessionFactory);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:5,代碼來源:AsyncRequestInterceptor.java

示例15: doSuspend

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected Object doSuspend(Object transaction) {
	CciLocalTransactionObject txObject = (CciLocalTransactionObject) transaction;
	txObject.setConnectionHolder(null);
	return TransactionSynchronizationManager.unbindResource(getConnectionFactory());
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:CciLocalTransactionManager.java


注:本文中的org.springframework.transaction.support.TransactionSynchronizationManager.unbindResource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。