List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager bindResource
public static void bindResource(Object key, Object value) throws IllegalStateException
From source file:org.springmodules.workflow.jbpm30.JbpmSessionFactoryUtils.java
/** * Returns a jBPM session. It is aware of and will return the thread-bound session if one is found. * jBPM exceptions will not be translated. * /*from w w w . jav a 2 s.c o m*/ * @param sessionFactory * @param allowCreate * @return */ public static JbpmSession doGetSession(JbpmSessionFactory sessionFactory, boolean allowCreate) { Assert.notNull(sessionFactory, "No JbpmSessionFactory specified"); JbpmSessionHolder jbpmSessionHolder = (JbpmSessionHolder) TransactionSynchronizationManager .getResource(sessionFactory); if (jbpmSessionHolder != null && jbpmSessionHolder.getJbpmSession() != null) { return jbpmSessionHolder.getJbpmSession(); } JbpmSession jbpmSession = sessionFactory.openJbpmSession(); jbpmSessionHolder = new JbpmSessionHolder(jbpmSession); if (TransactionSynchronizationManager.isSynchronizationActive()) { TransactionSynchronizationManager.registerSynchronization( new SpringJbpmSessionSynchronization(jbpmSessionHolder, sessionFactory)); TransactionSynchronizationManager.bindResource(sessionFactory, jbpmSessionHolder); } return jbpmSession; }
From source file:test.eryansky.HibernateTest.java
@Before public void init() { Session s = sessionFactory.openSession(); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(s)); }