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:fr.certu.chouette.command.Command.java

/**
 * @param factory/*from w  w  w.j a va  2  s.c o  m*/
 */
public static void closeDao() {
    if (dao) {
        ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
        SessionFactory sessionFactory = (SessionFactory) factory.getBean("sessionFactory");
        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
                .unbindResource(sessionFactory);
        SessionFactoryUtils.closeSession(sessionHolder.getSession());
    }
}

From source file:org.springextensions.neodatis.NeoDatisTransactionManager.java

@Override
protected void doCleanupAfterCompletion(Object transaction) {
    NeoDatisTransactionObject transactionObject = (NeoDatisTransactionObject) transaction;
    //Remove SessionHolder from the Thread.
    TransactionSynchronizationManager.unbindResource(getOdb());
    transactionObject.getODBHolder().clear();
}

From source file:com.mobileman.filter.OpenSessionFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {

    if (webApplicationContext == null) {
        HttpServletRequest rq1 = (HttpServletRequest) request;
        String requestURI = rq1.getRequestURI();
        if (!requestURI.endsWith(INIT_SERVLET_URI)) {
            request.getRequestDispatcher(INIT_SERVLET_URI).forward(request, response);
            return;
        }//from w w  w.  j  a va2s  .c o  m
    }

    SessionFactory sessionFactory = lookupSessionFactory();
    boolean participate = false;

    if (sessionFactory != null) {
        if (isSingleSession()) {
            // single session mode
            if (TransactionSynchronizationManager.hasResource(sessionFactory)) {
                // Do not modify the Session: just set the participate flag.
                participate = true;
            } else {
                Session session = getSession(sessionFactory);
                TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
            }
        } else {
            // deferred close mode
            if (SessionFactoryUtils.isDeferredCloseActive(sessionFactory)) {
                // Do not modify deferred close: just set the participate
                // flag.
                participate = true;
            } else {
                SessionFactoryUtils.initDeferredClose(sessionFactory);
            }
        }
    }

    try {
        filterChain.doFilter(request, response);
    }

    finally {
        if (sessionFactory != null) {
            if (!participate) {
                if (isSingleSession()) {
                    // single session mode
                    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
                            .unbindResource(sessionFactory);
                    closeSession(sessionHolder.getSession(), sessionFactory);
                } else {
                    // deferred close mode
                    SessionFactoryUtils.processDeferredClose(sessionFactory);
                }
            }
        }
    }
}

From source file:org.grails.datastore.mapping.transactions.DatastoreTransactionManager.java

@Override
protected void doCleanupAfterCompletion(Object transaction) {
    TransactionObject txObject = (TransactionObject) transaction;

    // Un-bind the session holder from the thread.
    if (txObject.isNewSessionHolder()) {
        TransactionSynchronizationManager.unbindResource(getDatastore());
    }/*from  w w w  . ja v a 2  s  .c om*/
    txObject.getSessionHolder().setSynchronizedWithTransaction(false);

}

From source file:com.wavemaker.runtime.data.spring.SpringDataServiceManager.java

@Override
public void commit() {

    if (txLogger.isInfoEnabled()) {
        txLogger.info("commit");
    }/*from  w w  w .  j a v  a  2s  .  c om*/

    ThreadContext.Context ctx = ThreadContext.getContext(this.metaData.getName());

    if (ctx == null) {
        if (txLogger.isWarnEnabled()) {
            txLogger.warn("ignoring commit - no tx in progress");
            if (txLogger.isDebugEnabled()) {
                logStackTrace();
            }
        }
        return;
    }

    TransactionStatus txStatus = ctx.getTransactionStatus();

    try {
        if (txStatus == null) {
            if (txLogger.isWarnEnabled()) {
                txLogger.warn("ignoring commit - no tx status");
                if (txLogger.isDebugEnabled()) {
                    logStackTrace();
                }
            }
        } else {
            this.txMgr.commit(txStatus);
        }
    } finally {
        ctx.setTransactionStatus(null);
        ThreadContext.unsetContext(this.metaData.getName());
        HashMap<String, ThreadContext.Context> contextHash = ThreadContext.getThreadLocalHash();

        if (contextHash != null && contextHash.size() > 0) {
            if (!TransactionSynchronizationManager.isSynchronizationActive()) {
                TransactionSynchronizationManager.initSynchronization();
            }
        } else {
            if (TransactionSynchronizationManager.isSynchronizationActive()) {
                TransactionSynchronizationManager.clear();
                Map map = TransactionSynchronizationManager.getResourceMap();
                for (Object entry : map.keySet()) {
                    TransactionSynchronizationManager.unbindResource(entry);
                }
            }
        }
    }
}

From source file:org.fornax.cartridges.sculptor.framework.web.jpa.JpaFlowExecutionListener.java

private void unbind(EntityManager em) {
    if (TransactionSynchronizationManager.hasResource(entityManagerFactory)) {
        TransactionSynchronizationManager.unbindResource(entityManagerFactory);
    }//from   w  w  w  .  ja v  a2s .  c  o m
}

From source file:org.springextensions.db4o.Db4oTransactionManager.java

protected void doCleanupAfterCompletion(Object transaction) {
    Db4oTransactionObject txObject = (Db4oTransactionObject) transaction;

    // Remove the session holder from the thread.
    TransactionSynchronizationManager.unbindResource(getObjectContainer());

    /*//from   w  w  w .  j av a2 s  .c  om
       ObjectContainer container = txObject.getObjectContainerHolder().getObjectContainer();
       if (txObject.isNewContainerHolder()) {
       if (logger.isDebugEnabled()) {
       logger.debug("Cleaning up db4o object container [" + container + "] after transaction");
       }
       // do nothing
       }
       else {
       if (logger.isDebugEnabled()) {
       logger.debug("Not closing pre-bound db4o object container [" + container + "] after transaction");
       }
       }
       */
    txObject.getObjectContainerHolder().clear();
}

From source file:fr.certu.chouette.gui.command.Command.java

/**
 * @param factory// w  w  w . j  av a  2 s .  c o  m
 */
public static void closeDao() {

    ConfigurableBeanFactory factory = applicationContext.getBeanFactory();
    SessionFactory sessionFactory = (SessionFactory) factory.getBean("sessionFactory");
    SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
            .unbindResource(sessionFactory);
    SessionFactoryUtils.closeSession(sessionHolder.getSession());

}

From source file:org.cfr.capsicum.datasource.CayenneTransactionManager.java

@Override
protected Object doSuspend(Object transaction) {
    CayenneTransactionObject txObject = (CayenneTransactionObject) transaction;
    txObject.setConnectionHolder(null);//ww w .  j  a  v  a  2 s. com
    ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager
            .unbindResource(this.dataSource);
    return conHolder;
}