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


Java TransactionSynchronizationManager.bindResource方法代碼示例

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


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

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

示例2: doGetConnection

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Actually obtain a CCI Connection from the given ConnectionFactory.
 * Same as {@link #getConnection}, but throwing the original ResourceException.
 * <p>Is aware of a corresponding Connection bound to the current thread, for example
 * when using {@link CciLocalTransactionManager}. Will bind a Connection to the thread
 * if transaction synchronization is active (e.g. if in a JTA transaction).
 * <p>Directly accessed by {@link TransactionAwareConnectionFactoryProxy}.
 * @param cf the ConnectionFactory to obtain Connection from
 * @return a CCI Connection from the given ConnectionFactory
 * @throws ResourceException if thrown by CCI API methods
 * @see #doReleaseConnection
 */
public static Connection doGetConnection(ConnectionFactory cf) throws ResourceException {
	Assert.notNull(cf, "No ConnectionFactory specified");

	ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(cf);
	if (conHolder != null) {
		return conHolder.getConnection();
	}

	logger.debug("Opening CCI Connection");
	Connection con = cf.getConnection();

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering transaction synchronization for CCI Connection");
		conHolder = new ConnectionHolder(con);
		conHolder.setSynchronizedWithTransaction(true);
		TransactionSynchronizationManager.registerSynchronization(new ConnectionSynchronization(conHolder, cf));
		TransactionSynchronizationManager.bindResource(cf, conHolder);
	}

	return con;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:ConnectionFactoryUtils.java

示例3: preHandle

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	if (TransactionSynchronizationManager.hasResource(getPersistenceManagerFactory())) {
		// Do not modify the PersistenceManager: just mark the request accordingly.
		String participateAttributeName = getParticipateAttributeName();
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening JDO PersistenceManager in OpenPersistenceManagerInViewInterceptor");
		PersistenceManager pm =
				PersistenceManagerFactoryUtils.getPersistenceManager(getPersistenceManagerFactory(), true);
		TransactionSynchronizationManager.bindResource(
				getPersistenceManagerFactory(), new PersistenceManagerHolder(pm));
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:OpenPersistenceManagerInViewInterceptor.java

示例4: rebindSynchronization

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Helper method to rebind the synchronization to the transaction
 *
 * @param txnSynch TransactionSynchronizationImpl
 */
private static void rebindSynchronization(TransactionSynchronizationImpl txnSynch)
{
    TransactionSynchronizationManager.bindResource(RESOURCE_KEY_TXN_SYNCH, txnSynch);
    if (logger.isDebugEnabled())
    {
        logger.debug("Bound (rebind) txn synch: " + txnSynch);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-core,代碼行數:14,代碼來源:TransactionSupportUtil.java

示例5: doBegin

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected void doBegin(Object transaction, TransactionDefinition definition) {
	Long txId = System.nanoTime();
    logger.info(" [LITX]開始事務 [TXID: " + txId + "]");
    super.doBegin(transaction, definition);
	TransactionContext transactionContext = new TransactionContext();
    TransactionSynchronizationManager.bindResource(LitxConstant.TRANSACTION_CONTEXT_KEY, transactionContext);
    TransactionSynchronizationManager.bindResource(LitxConstant.TRANSACTION_ID_KEY, txId);
}
 
開發者ID:thebeastshop,項目名稱:litx,代碼行數:10,代碼來源:LitTransactionManager.java

示例6: doGetConnection

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Actually obtain a JDBC Connection from the given DataSource.
 * Same as {@link #getConnection}, but throwing the original SQLException.
 * <p>Is aware of a corresponding Connection bound to the current thread, for example
 * when using {@link DataSourceTransactionManager}. Will bind a Connection to the thread
 * if transaction synchronization is active (e.g. if in a JTA transaction).
 * <p>Directly accessed by {@link TransactionAwareDataSourceProxy}.
 * @param dataSource the DataSource to obtain Connections from
 * @return a JDBC Connection from the given DataSource
 * @throws SQLException if thrown by JDBC methods
 * @see #doReleaseConnection
 */
public static Connection doGetConnection(DataSource dataSource) throws SQLException {
	Assert.notNull(dataSource, "No DataSource specified");

	ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
	if (conHolder != null && (conHolder.hasConnection() || conHolder.isSynchronizedWithTransaction())) {
		conHolder.requested();
		if (!conHolder.hasConnection()) {
			logger.debug("Fetching resumed JDBC Connection from DataSource");
			conHolder.setConnection(dataSource.getConnection());
		}
		return conHolder.getConnection();
	}
	// Else we either got no holder or an empty thread-bound holder here.

	logger.debug("Fetching JDBC Connection from DataSource");
	Connection con = dataSource.getConnection();

	if (TransactionSynchronizationManager.isSynchronizationActive()) {
		logger.debug("Registering transaction synchronization for JDBC Connection");
		// Use same Connection for further JDBC actions within the transaction.
		// Thread-bound object will get removed by synchronization at transaction completion.
		ConnectionHolder holderToUse = conHolder;
		if (holderToUse == null) {
			holderToUse = new ConnectionHolder(con);
		}
		else {
			holderToUse.setConnection(con);
		}
		holderToUse.requested();
		TransactionSynchronizationManager.registerSynchronization(
				new ConnectionSynchronization(holderToUse, dataSource));
		holderToUse.setSynchronizedWithTransaction(true);
		if (holderToUse != conHolder) {
			TransactionSynchronizationManager.bindResource(dataSource, holderToUse);
		}
	}

	return con;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:52,代碼來源:DataSourceUtils.java

示例7: preHandle

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public void preHandle(WebRequest request) throws DataAccessException {

	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applyCallableInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
		// do not modify the EntityManager: just mark the request accordingly
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
		try {
			EntityManager em = createEntityManager();
			EntityManagerHolder emHolder = new EntityManagerHolder(em);
			TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

			AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
		}
		catch (PersistenceException ex) {
			throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:35,代碼來源:OpenEntityManagerInViewInterceptor.java

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

示例9: doResume

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
protected void doResume(Object transaction, Object suspendedResources) {
	SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder) suspendedResources;
	TransactionSynchronizationManager.bindResource(
			getEntityManagerFactory(), resourcesHolder.getEntityManagerHolder());
	if (getDataSource() != null && resourcesHolder.getConnectionHolder() != null) {
		TransactionSynchronizationManager.bindResource(getDataSource(), resourcesHolder.getConnectionHolder());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:JpaTransactionManager.java

示例10: preHandle

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:46,代碼來源:OpenSessionInViewInterceptor.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;
	TransactionSynchronizationManager.bindResource(
			getPersistenceManagerFactory(), resourcesHolder.getPersistenceManagerHolder());
	if (getDataSource() != null && resourcesHolder.getConnectionHolder() != null) {
		TransactionSynchronizationManager.bindResource(getDataSource(), resourcesHolder.getConnectionHolder());
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:10,代碼來源:JdoTransactionManager.java

示例13: preHandle

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
/**
 * Open a new Hibernate {@code Session} according and bind it to the thread via the
 * {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor");
		Session session = openSession();
		SessionHolder sessionHolder = new SessionHolder(session);
		TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

		AsyncRequestInterceptor asyncRequestInterceptor =
				new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
		asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
		asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:34,代碼來源:OpenSessionInViewInterceptor.java

示例14: resume

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
@Override
public void resume() {
	if (this.holderActive) {
		TransactionSynchronizationManager.bindResource(this.sessionFactory, this.sessionHolder);
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:7,代碼來源:SpringSessionSynchronization.java

示例15: resume

import org.springframework.transaction.support.TransactionSynchronizationManager; //導入方法依賴的package包/類
public void resume() {
    TransactionSynchronizationManager.bindResource(this.sessionFactory,
            this.sessionHolder);
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:5,代碼來源:SpringSessionSynchronization.java


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