Example usage for org.springframework.transaction.support TransactionSynchronizationManager unbindResource

List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager unbindResource

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionSynchronizationManager unbindResource.

Prototype

public static Object unbindResource(Object key) throws IllegalStateException 

Source Link

Document

Unbind a resource for the given key from the current thread.

Usage

From source file:org.grails.datastore.mapping.web.support.OpenSessionInViewInterceptor.java

public void afterCompletion(WebRequest webRequest, Exception e) throws Exception {
    if (!hasSessionBound()) {
        return;/*ww w. ja  v a  2 s .c  o m*/
    }

    // single session mode
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(getDatastore());
    LOG.debug("Closing single Datastore Session in OpenSessionInViewInterceptor");
    DatastoreUtils.closeSession(sessionHolder.getSession());
}

From source file:org.tsm.concharto.OpenSessionInViewIntegrationTest.java

@After
public void postProcessTransactionFactory() {
    // single session mode
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    SessionFactoryUtils.closeSession(sessionHolder.getSession());
}

From source file:org.motechproject.server.omod.sdsched.TxSyncManWrapperImpl.java

public void unbindResource(String resourceName) {
    TransactionSynchronizationManager.unbindResource(resourceName);
}

From source file:org.codehaus.groovy.grails.plugins.springsecurity.GrailsWebApplicationObjectSupport.java

/**
 * Release Session./*from www . j  av  a2  s.c o  m*/
 */
protected void releaseSession(final SessionContainer session) {
    if (session._existingSession) {
        return;
    }

    SessionFactory sessionFactory = getSessionFactory();
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
    logger.debug("Session released");
}

From source file:org.jtalks.poulpe.web.osod.OpenSessions.java

/**
 * Unbinds (removes from the {@link ThreadLocal} variables of the thread) the session which means that Spring
 * Transaction related classes won't have access to the session anymore. This usually should be done when request
 * processing is finished. This doesn't close the session, it still there and is associated with desktop id.
 *///from   w w w . j  a v a  2 s  .com
public void unbindSession() {
    TransactionSynchronizationManager.unbindResource(sessionFactory);
}

From source file:corner.orm.hibernate.impl.SpringSessionManagerImpl.java

@Override
public void threadDidCleanup() {
    if (!participate) {
        // single session mode
        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
                .unbindResource(sessionFactory);
        logger.debug("Closing single Hibernate Session in OpenSessionInViewFilter");
        closeSession(sessionHolder.getSession(), sessionFactory);
    }/*  ww  w .j a  v  a  2  s. co  m*/
}

From source file:org.codehaus.groovy.grails.plugins.acegi.GrailsWebApplicationObjectSupport.java

/**
 * Release Session/*from  w  w w  .  j  a  v a2  s .c  o  m*/
 */
protected void releaseSession() {
    if (!containerManagedSession) {
        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
                .unbindResource(sessionFactory);
        SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
        logger.debug("Session released");
    }
}

From source file:org.jasig.jpa.OpenEntityManagerAspect.java

@Around("anyPublicMethod() && @annotation(openEntityManager)")
public Object openEntityManager(ProceedingJoinPoint pjp, OpenEntityManager openEntityManager) throws Throwable {
    final EntityManagerFactory emf = getEntityManagerFactory(openEntityManager);

    EntityManager em = getTransactionalEntityManager(emf);
    boolean isNewEm = false;
    if (em == null) {
        logger.debug("Opening JPA EntityManager in OpenEntityManagerAspect");
        em = createEntityManager(emf);/*from   ww w.  java  2  s.c  om*/
        isNewEm = true;
        TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));
    } else {
        logger.debug("Using Existing JPA EntityManager in OpenEntityManagerAspect");
    }
    try {
        return pjp.proceed();
    } finally {
        if (isNewEm) {
            logger.debug("Closing JPA EntityManager in OpenEntityManagerAspect");
            TransactionSynchronizationManager.unbindResource(emf);
            EntityManagerFactoryUtils.closeEntityManager(em);
        }
    }
}

From source file:com.autentia.wuija.persistence.impl.hibernate.HibernateTestUtils.java

/**
 * Mtodo pensado para usar en los test, de forma que para la ejecucin tengamos una nica sesin. Sera similar a
 * clases como <code>penSessionInViewFilter</code>. La idea es invocar este mtodo en un <code>@After</code>.
 * <p>/*from w  ww .  j a v a 2 s  . c o  m*/
 * Este mtodo se debera invocar una nica vez.
 * <p>
 * Este mtodo se encarga de cerra la sessin que est "attacha" al contexto, y que se abri con el mtodo
 * {@link #openSessionAndAttachToContext()}.
 */
public void closeSessionFromContext() {
    Assert.state(sessionAlreadyOpened != null,
            "There is not opened session. You have to call openSessionAndAttachToContext() method before this one");

    if (log.isTraceEnabled()) {
        log.trace("Closing session with SessionFactory: " + ObjectUtils.identityToString(sessionFactory));
    }

    final SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    final Session session = sessionHolder.getSession();

    Assert.state(sessionAlreadyOpened == session, "You are trying to close session: "
            + ObjectUtils.identityToString(session) + ", but this is not de actual opened session");
    sessionAlreadyOpened = null;

    SessionFactoryUtils.closeSession(session);

    if (log.isDebugEnabled()) {
        log.debug("Closed Session: " + ObjectUtils.identityToString(session));
    }
}

From source file:podd.dataaccess.AbstractDAOUnitTest.java

public void tearDown() throws Exception {

    // Release the session
    SessionFactory sessionFactory = PODD_CONTEXT.getSessionFactory();
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
}