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

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

Introduction

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

Prototype

@Nullable
public static Object getResource(Object key) 

Source Link

Document

Retrieve a resource for the given key that is bound to the current thread.

Usage

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

public void testBindResource() {
    final String resourceName = "A Resource";
    final String resourceValue = "A Resource value";
    Object retVal = txTempl.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
            try {
                txSyncManWrapper.bindResource(resourceName, resourceValue);
                return TransactionSynchronizationManager.getResource(resourceName);
            } finally {
                TransactionSynchronizationManager.unbindResourceIfPossible(resourceName);
            }//from   w w  w .j a  v a 2 s .com
        }
    });
    assertEquals(resourceValue, retVal);
}

From source file:org.mybatis.spring.transaction.SpringManagedTransaction.java

/**
 * {@inheritDoc}/* w w w  . j a v  a  2  s.  c  om*/
 */
@Override
public Integer getTimeout() throws SQLException {
    ConnectionHolder holder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
    if (holder != null && holder.hasTimeout()) {
        return holder.getTimeToLiveInSeconds();
    }
    return null;
}

From source file:com.rainy.redis.connection.RedisConnectionUtils.java

/**
 * Return whether the given Redis connection is transactional, that is,
 * bound to the current thread by Spring's transaction facilities.
 * //from ww  w.j av  a 2  s  .com
 * @param conn Redis connection to check
 * @param connFactory Redis connection factory that the connection was
 *        created with
 * @return whether the connection is transactional or not
 */
public static boolean isConnectionTransactional(IRedisConnection conn, IRedisConnectionFactory connFactory) {
    if (connFactory == null) {
        return false;
    }
    RedisConnectionHolder connHolder = (RedisConnectionHolder) TransactionSynchronizationManager
            .getResource(connFactory);
    return (connHolder != null && conn == connHolder.getConnection());
}

From source file:com.jaspersoft.jasperserver.test.CoreDataCreateTestNG.java

@AfterClass()
public void onTearDown() {
    m_logger.info("onTearDown() called");

    SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(m_sessionFactory);
    Session s = holder.getSession();/*from  ww w .j  a v a2  s.  c o m*/
    s.flush();
    TransactionSynchronizationManager.unbindResource(m_sessionFactory);
    SessionFactoryUtils.releaseSession(s, m_sessionFactory);
}

From source file:com.busimu.core.dao.impl.UserMngDaoPolicyJpaImpl.java

/**
 * {@inheritDoc}/*from  w w w  .  j a v  a 2 s. c o  m*/
 */
@Override
public boolean isExistedLicense(String licenseCode) {
    EntityManager em = ((EntityManagerHolder) TransactionSynchronizationManager.getResource(emf))
            .getEntityManager();
    return getLicenseByCode(em, licenseCode) != null;
}

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

@Override
protected Object doGetTransaction() throws TransactionException {
    NeoDatisTransactionObject transactionObject = new NeoDatisTransactionObject();
    ODBHolder odbHolder = (ODBHolder) TransactionSynchronizationManager.getResource(getOdb());
    transactionObject.setODBHolder(odbHolder);
    return transactionObject;
}

From source file:org.grails.webflow.persistence.SessionAwareHibernateFlowExecutionListener.java

private void obtainCurrentSession(RequestContext context) {
    MutableAttributeMap flowScope = context.getFlowScope();
    if (flowScope.get(PERSISTENCE_CONTEXT_ATTRIBUTE) != null) {
        return;/* www  . j  av a2 s . co m*/
    }

    Session session = null;
    if (hibernate3Present) {
        org.springframework.orm.hibernate3.SessionHolder sessionHolder = (org.springframework.orm.hibernate3.SessionHolder) TransactionSynchronizationManager
                .getResource(localSessionFactory);
        if (sessionHolder != null)
            session = sessionHolder.getSession();
    } else {
        SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager
                .getResource(localSessionFactory);
        if (sessionHolder != null)
            session = sessionHolder.getSession();
    }
    flowScope.put(PERSISTENCE_CONTEXT_ATTRIBUTE, session);
}

From source file:org.exitcode.spring.torque.tx.SpringTransactionManagerAdapter.java

private Connection getSpringTxConnection() {
    Connection conn = ((ConnectionHolder) TransactionSynchronizationManager.getResource(springDataSource))
            .getConnection();/*  w w  w . j a v  a2  s . c o m*/
    if (conn == null) {
        throw new IllegalStateException("No connection associated with running transaction!");
    }

    return conn;
}

From source file:com.busimu.core.dao.impl.UserMngDaoPolicyJpaImpl.java

/**
 * {@inheritDoc}/*  w  w  w . j a  v a2 s  .  c o  m*/
 */
@Override
public void storeLicenses(Set<License> licenses) {
    EntityManager em = ((EntityManagerHolder) TransactionSynchronizationManager.getResource(emf))
            .getEntityManager();
    EntityTransaction tx = em.getTransaction();
    if (!tx.isActive()) {
        tx.begin();
    }
    for (License l : licenses) {
        em.persist(l);
    }
    tx.commit();
}