List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager bindResource
public static void bindResource(Object key, Object value) throws IllegalStateException
From source file:ar.edu.utn.sigmaproject.webflow.Hibernate4FlowExecutionListener.java
private void bind(Session session) { TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); }
From source file:org.cfr.capsicum.datasource.CayenneTransactionManager.java
@Override protected void doResume(Object transaction, Object suspendedResources) { CayenneConnectionHolder conHolder = (CayenneConnectionHolder) suspendedResources; TransactionSynchronizationManager.bindResource(this.dataSource, conHolder); BaseContext.bindThreadObjectContext(conHolder.getObjectContext()); }
From source file:com._4dconcept.springframework.data.marklogic.datasource.ContentSourceTransactionManager.java
/** * This implementation sets the isolation level but ignores the timeout. *///from www .j a v a2s. c o m @Override protected void doBegin(Object transaction, TransactionDefinition definition) { ContentSourceTransactionObject txObject = (ContentSourceTransactionObject) transaction; Session ses = null; try { if (txObject.getSessionHolder() == null || txObject.getSessionHolder().isSynchronizedWithTransaction()) { Session newSes = this.contentSource.newSession(); if (logger.isDebugEnabled()) { logger.debug("Acquired Session [" + newSes + "] for XDBC transaction"); } txObject.setSessionHolder(new SessionHolder(newSes), true); } txObject.getSessionHolder().setSynchronizedWithTransaction(true); ses = txObject.getSessionHolder().getSession(); Integer previousIsolationLevel = ContentSourceUtils.prepareSessionForTransaction(ses, definition); txObject.setPreviousIsolationLevel(previousIsolationLevel); txObject.getSessionHolder().setTransactionActive(true); int timeout = determineTimeout(definition); if (timeout != TransactionDefinition.TIMEOUT_DEFAULT) { txObject.getSessionHolder().setTimeoutInSeconds(timeout); } // Bind the session holder to the thread. if (txObject.isNewSessionHolder()) { TransactionSynchronizationManager.bindResource(getContentSource(), txObject.getSessionHolder()); } } catch (Throwable ex) { if (txObject.isNewSessionHolder()) { ContentSourceUtils.releaseSession(ses, this.contentSource); txObject.setSessionHolder(null, false); } throw new CannotCreateTransactionException("Could not open XDBC Session for transaction", ex); } }
From source file:com.github.rholder.spring.transaction.TransactionBindingSupport.java
/** * Binds the Alfresco-specific to the transaction resources * /*from www . j a va 2 s. c o m*/ * @return Returns the current or new synchronization implementation */ private static TransactionSynchronizationImpl registerSynchronizations() { /* * No thread synchronization or locking required as the resources are all threadlocal */ if (!TransactionSynchronizationManager.isSynchronizationActive()) { Thread currentThread = Thread.currentThread(); throw new RuntimeException( "Transaction must be active and synchronization is required: " + currentThread); } TransactionSynchronizationImpl txnSynch = (TransactionSynchronizationImpl) TransactionSynchronizationManager .getResource(RESOURCE_KEY_TXN_SYNCH); if (txnSynch != null) { // synchronization already registered return txnSynch; } // we need a unique ID for the transaction String txnId = UUID.randomUUID().toString(); // register the synchronization txnSynch = new TransactionSynchronizationImpl(txnId); TransactionSynchronizationManager.registerSynchronization(txnSynch); // register the resource that will ensure we don't duplication the synchronization TransactionSynchronizationManager.bindResource(RESOURCE_KEY_TXN_SYNCH, txnSynch); // done if (logger.isDebugEnabled()) { logger.debug("Bound txn synch: " + txnSynch); } return txnSynch; }
From source file:org.guzz.web.context.spring.GuzzTransactionManager.java
@Override protected void doResume(Object transaction, Object suspendedResources) { SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder) suspendedResources; if (TransactionSynchronizationManager.hasResource(getTransactionManager())) { // From non-transactional code running in active transaction synchronization // -> can be safely removed, will be closed on transaction completion. TransactionSynchronizationManager.unbindResource(getTransactionManager()); }/*from ww w .j av a 2 s .c om*/ TransactionSynchronizationManager.bindResource(getTransactionManager(), resourcesHolder.getSessionHolder()); }
From source file:ch.algotrader.service.LookupServiceTest.java
@Override @Before// w w w. j av a 2 s.co m public void setup() throws Exception { ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ClassPathResource("/db/h2/h2.sql")); DatabasePopulatorUtils.execute(dbPopulator, dataSource); this.session = sessionFactory.openSession(); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(this.session)); }
From source file:com._4dconcept.springframework.data.marklogic.datasource.ContentSourceTransactionManager.java
@Override protected void doResume(Object transaction, Object suspendedResources) { SessionHolder sesHolder = (SessionHolder) suspendedResources; TransactionSynchronizationManager.bindResource(this.contentSource, sesHolder); }
From source file:com.github.rholder.spring.transaction.TransactionBindingSupport.java
/** * Helper method to rebind the synchronization to the transaction * // w ww . j a va 2s . c o m * @param txnSynch */ private static void rebindSynchronization(TransactionSynchronizationImpl txnSynch) { TransactionSynchronizationManager.bindResource(RESOURCE_KEY_TXN_SYNCH, txnSynch); if (logger.isDebugEnabled()) { logger.debug("Bound txn synch: " + txnSynch); } }
From source file:org.grails.datastore.mapping.core.DatastoreUtils.java
/** * Bind the session to the thread with a SessionHolder keyed by its Datastore. * @param session the session/*ww w . j a v a 2 s . c om*/ * @return the session (for method chaining) */ public static Session bindSession(final Session session) { TransactionSynchronizationManager.bindResource(session.getDatastore(), new SessionHolder(session)); return session; }
From source file:com.turbospaces.spaces.AbstractJSpace.java
@Override public void bindTransactionHolder(final SpaceTransactionHolder transactionHolder) { TransactionSynchronizationManager.bindResource(this, transactionHolder); }