List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager unbindResource
public static Object unbindResource(Object key) throws IllegalStateException
From source file:org.guzz.web.context.spring.GuzzTransactionManager.java
@Override protected void doCleanupAfterCompletion(Object transaction) { GuzzTransactionObject txObject = (GuzzTransactionObject) transaction; // Remove the session holder from the thread. if (txObject.isNewWriteTranSessionHolder()) { TransactionSynchronizationManager.unbindResource(getTransactionManager()); }//from w w w .j a va 2s .c o m WriteTranSession session = txObject.getSessionHolder().getWriteTranSession(); if (txObject.getIsolationsSavePointer() != null) { session.resetTransactionIsolationTo(txObject.getIsolationsSavePointer()); } if (txObject.isNewWriteTranSession()) { if (logger.isDebugEnabled()) { logger.debug("Closing Guzz WriteTranSession [" + TransactionManagerUtils.toString(session) + "] after transaction"); } TransactionManagerUtils.closeSession(session); } else { if (logger.isDebugEnabled()) { logger.debug("Not closing pre-bound Guzz WriteTranSession [" + TransactionManagerUtils.toString(session) + "] after transaction"); } } txObject.getSessionHolder().clear(); }
From source file:com._4dconcept.springframework.data.marklogic.datasource.ContentSourceTransactionManager.java
@Override protected void doCleanupAfterCompletion(Object transaction) { ContentSourceTransactionObject txObject = (ContentSourceTransactionObject) transaction; // Remove the session holder from the thread, if exposed. if (txObject.isNewSessionHolder()) { TransactionSynchronizationManager.unbindResource(this.contentSource); }/*ww w. j a v a2 s. c o m*/ // Reset session. Session ses = txObject.getSessionHolder().getSession(); try { ContentSourceUtils.resetSessionAfterTransaction(ses, txObject.getPreviousIsolationLevel()); } catch (Throwable ex) { logger.debug("Could not reset XDBC Session after transaction", ex); } if (txObject.isNewSessionHolder()) { if (logger.isDebugEnabled()) { logger.debug("Releasing XDBC Session [" + ses + "] after transaction"); } ContentSourceUtils.releaseSession(ses, this.contentSource); } txObject.getSessionHolder().clear(); }
From source file:org.grails.datastore.mapping.core.DatastoreUtils.java
/** * Unbinds and closes a session. If it's the only session in the SessionHolder, unbinds * the SessionHolder, otherwise just removes the session from the holder's list. * @param session the session//from w w w .j a va 2 s . c om */ public static void unbindSession(final Session session) { SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager .getResource(session.getDatastore()); if (sessionHolder == null) { logger.warn("Cannot unbind session, there's no SessionHolder registered"); return; } if (!sessionHolder.containsSession(session)) { logger.warn("Cannot unbind session, it's not registered in a SessionHolder"); return; } if (sessionHolder.size() > 1) { sessionHolder.removeSession(session); } else { TransactionSynchronizationManager.unbindResource(session.getDatastore()); } closeSessionOrRegisterDeferredClose(session, session.getDatastore()); }
From source file:com.turbospaces.spaces.AbstractJSpace.java
@Override public Object unbindTransactionHolder(final SpaceTransactionHolder transactionHolder) { return TransactionSynchronizationManager.unbindResource(this); }
From source file:no.abmu.finances.domain.AbstractLocalHibernate3Test.java
protected void tearDown() throws Exception { TransactionSynchronizationManager.unbindResource(sessionFactory); SessionFactoryUtils.releaseSession(session, sessionFactory); SessionFactoryUtils.releaseSession(session2, sessionFactory); }
From source file:ome.tools.hibernate.SessionStatus.java
public void cleanThread() { if (TransactionSynchronizationManager.hasResource(factory)) { SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(factory); if (holder == null) { throw new IllegalStateException("Can't be null."); } else if (holder == DUMMY) { TransactionSynchronizationManager.unbindResource(factory); } else {/* w w w . j a v a 2s . c o m*/ throw new IllegalStateException("Thread corrupted."); } } }
From source file:ome.tools.hibernate.SessionStatus.java
private void bindSession(Session session) { debug("Binding session to thread."); SessionHolder sessionHolder = new SessionHolder(session); sessionHolder.setTransaction(sessionHolder.getSession().beginTransaction()); // FIXME TODO // If we reach this point, it's ok to bind the new SessionHolder, // however the DUMMY EmptySessionHolder may be present so unbind // just in case. if (TransactionSynchronizationManager.hasResource(factory)) { TransactionSynchronizationManager.unbindResource(factory); }//from w w w . j av a2s .co m TransactionSynchronizationManager.bindResource(factory, sessionHolder); if (!TransactionSynchronizationManager.isSynchronizationActive()) { throw new InternalException("Synchronization not active for " + "TransactionSynchronizationManager"); } }
From source file:ome.tools.hibernate.SessionStatus.java
private void resetThreadSession() { if (isSessionBoundToThread()) { debug("Session bound to thread. Reseting."); TransactionSynchronizationManager.unbindResource(factory); TransactionSynchronizationManager.bindResource(factory, DUMMY); } else {//from ww w .j a v a 2s. c o m debug("Session not bound to thread. No need to reset."); } }
From source file:org.broadleafcommerce.common.util.tenant.IdentityExecutionUtils.java
private static TransactionContainer establishTransaction(PlatformTransactionManager transactionManager) { Map<Object, Object> usedResources = new HashMap<Object, Object>(); Map<Object, Object> resources = TransactionSynchronizationManager.getResourceMap(); for (Map.Entry<Object, Object> entry : resources.entrySet()) { if ((entry.getKey() instanceof EntityManagerFactory || entry.getKey() instanceof DataSource) && TransactionSynchronizationManager.hasResource(entry.getKey())) { usedResources.put(entry.getKey(), entry.getValue()); }//from w w w .j a va 2 s . com } for (Map.Entry<Object, Object> entry : usedResources.entrySet()) { TransactionSynchronizationManager.unbindResource(entry.getKey()); } TransactionStatus status; try { status = TransactionUtils.createTransaction(TransactionDefinition.PROPAGATION_REQUIRES_NEW, transactionManager, false); } catch (RuntimeException e) { throw e; } return new TransactionContainer(status, usedResources); }
From source file:org.codehaus.groovy.grails.orm.hibernate.support.HibernatePersistenceContextInterceptor.java
public void destroy() { DeferredBindingActions.clear();//ww w . ja v a2 s . c o m if (decNestingCount() > 0 || getParticipate()) { return; } try { // single session mode SessionHolder holder = (SessionHolder) TransactionSynchronizationManager .unbindResource(getSessionFactory()); LOG.debug("Closing single Hibernate session in GrailsDispatcherServlet"); try { SessionFactoryUtils.closeSession(holder.getSession()); } catch (RuntimeException ex) { LOG.error("Unexpected exception on closing Hibernate Session", ex); } } finally { AbstractSavePersistentMethod.clearDisabledValidations(); } }