当前位置: 首页>>代码示例>>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;未经允许,请勿转载。