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:podd.dataaccess.hibernate.HibernateSessionHelper.java

public static void closeSession(SessionFactory sessionFactory) {
    // Release the session
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    SessionFactoryUtils.releaseSession(sessionHolder.getSession(), sessionFactory);
}

From source file:com.rajesh.common.BaseHibernateTest.java

@After
public void after() {

    tx.commit();/*  ww w  .  j  a va  2 s  .co  m*/
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(getSessionFactory());

    sessionHolder.getSession().close();

    LOG.debug("Closed HBN Session");
}

From source file:com.brienwheeler.lib.db.DbTestUtils.java

public static <T> T doInHibernateSession(ApplicationContext applicationContext, Callable<T> work) {
    EntityManagerFactory entityManagerFactory = applicationContext
            .getBean("com.brienwheeler.lib.db.appEntityManagerFactory", EntityManagerFactory.class);

    EntityManagerHolder entityManagerHolder = (EntityManagerHolder) TransactionSynchronizationManager
            .getResource(entityManagerFactory);

    boolean created = entityManagerHolder == null;
    if (created) {
        entityManagerHolder = new EntityManagerHolder(entityManagerFactory.createEntityManager());
        TransactionSynchronizationManager.bindResource(entityManagerFactory, entityManagerHolder);
    }/*www. j av a 2 s . com*/

    try {
        return work.call();
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (created)
            TransactionSynchronizationManager.unbindResource(entityManagerFactory);
    }
}

From source file:org.grails.datastore.mapping.transactions.support.SpringSessionSynchronization.java

public void suspend() {
    if (holderActive) {
        TransactionSynchronizationManager.unbindResource(datastore);
        getCurrentSession().disconnect();
    }
}

From source file:org.jbpm.instance.migration.HibernateTestSupport.java

public void tearDown() throws Exception {
    SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
    Session session = holder.getSession();
    TransactionSynchronizationManager.unbindResource(getSessionFactory());
    session.close();/*from   ww  w. ja  v a2 s . c o  m*/
}

From source file:org.iwethey.forums.db.test.HibernateTestHarness.java

public void tearDown() throws Exception {
    SessionFactory sf = (SessionFactory) this.context.getBean("sessionFactory");
    SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
    Session s = holder.getSession();//from   w  w  w .  ja va2 s. com
    s.flush();
    TransactionSynchronizationManager.unbindResource(sf);
    //SessionFactoryUtils.closeSessionIfNecessary(s, sf);
    SessionFactoryUtils.releaseSession(s, sf);
}

From source file:org.guzz.web.context.spring.SpringSessionSynchronization.java

public void suspend() {
    if (this.holderActive) {
        TransactionSynchronizationManager.unbindResource(this.transactionManager);
        //         // Eagerly disconnect the Session here, to make release mode "on_close" work on JBoss.
        //         getCurrentSession().disconnect();

        //TODO: ??????????
    }//www.ja  va  2  s  . c  o  m
}

From source file:org.codehaus.groovy.grails.plugins.quartz.listeners.SessionBinderJobListener.java

public void jobWasExecuted(JobExecutionContext context, JobExecutionException exception) {
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    if (!FlushMode.MANUAL.equals(sessionHolder.getSession().getFlushMode())) {
        sessionHolder.getSession().flush();
    }/* w ww .j a  va 2s.  com*/
    SessionFactoryUtils.closeSession(sessionHolder.getSession());
    if (LOG.isDebugEnabled())
        LOG.debug("Hibernate Session is unbounded from Job thread and closed");
}

From source file:net.sf.mmm.orient.db.impl.OrientTx.java

/**
 * Disposes this transaction and performs a cleanup to free resources.
 *///from  w w w  .  j a v  a 2 s .  c  o m
public void dispose() {

    if ((this.resource != null) && (!this.resource.isClosed())) {
        this.resource.close();
    }
    TransactionSynchronizationManager.unbindResource(this.database);
    this.database = null;
    this.resource = null;
}

From source file:hsa.awp.common.util.OpenEntityManagerTimerTaskFactory.java

/**
 * Closes the previously created {@link EntityManager}.
 *///from   ww  w.j  ava 2s .  co m
private void closeEntityManager() {

    log.trace("Unbinding EntityManager from thread '{}'", Thread.currentThread().getName());
    EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.unbindResource(emf);

    log.debug("Closing EntityManager");
    EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager());
}