List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager unbindResource
public static Object unbindResource(Object key) throws IllegalStateException
From source file:org.grails.datastore.gorm.support.DatastorePersistenceContextInterceptor.java
public void destroy() { if (participate) { return;/*w ww. j a v a 2 s . c o m*/ } // single session mode if (TransactionSynchronizationManager.getResource(datastore) != null) { SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.unbindResource(datastore); LOG.debug("Closing single Datastore session in DatastorePersistenceContextInterceptor"); try { Session session = holder.getSession(); DatastoreUtils.closeSession(session); } catch (RuntimeException ex) { LOG.error("Unexpected exception on closing Datastore Session", ex); } } }
From source file:org.grails.datastore.mapping.core.AbstractAttributeStoringSession.java
/** * Performs clear up. Subclasses should always call into this super * implementation.// ww w . j av a 2s. c om */ public void disconnect() { connected = false; try { clear(); attributes.clear(); } finally { SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager .getResource(getDatastore()); if (sessionHolder != null) { sessionHolder.removeSession(this); if (sessionHolder.isEmpty()) { try { TransactionSynchronizationManager.unbindResource(getDatastore()); } catch (IllegalStateException e) { // ignore session disconnected by a another thread } } } } }
From source file:hsa.awp.common.test.OpenEntityManagerInTest.java
/** * Closes the previously created {@link EntityManager}. *///from w ww . j ava 2s .com @After public final void closeEntityManager() { if (create) { log.trace("Unbinding EntityManager from thread '{}'", Thread.currentThread().getName()); EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager .unbindResource(emf); log.debug("Closing EntityManager"); EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager()); } else { log.debug("Don't close EntityManager because of @Transactional annotation"); } }
From source file:ch.algotrader.hibernate.InMemoryDBTest.java
@After public void cleanup() throws Exception { ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("DROP ALL OBJECTS".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, EmbeddedTestDB.DATABASE.getDataSource()); if (this.sessionFactory != null) { TransactionSynchronizationManager.unbindResource(EmbeddedTestDB.DATABASE.getSessionFactory()); }/*from ww w.j a v a2 s .c o m*/ if (this.session != null) { if (this.session.isOpen()) { this.session.close(); } } }
From source file:org.grails.datastore.mapping.transactions.support.SpringSessionSynchronization.java
public void beforeCompletion() { if (newSession) { // Default behavior: unbind and close the thread-bound Hibernate Session. TransactionSynchronizationManager.unbindResource(datastore); holderActive = false;//from w w w . j av a 2 s . co m } }
From source file:org.openeos.services.ui.vaadin.internal.OpenSessionInViewListener.java
@Override public void onTransactionEnd(IUnoVaadinApplication application) { if (tlSession.get() != null) { LOG.debug("Open session in view is binding... closing it."); SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager .unbindResource(sessionFactory); SessionFactoryUtils.closeSession(sessionHolder.getSession()); tlSession.set(null);//from ww w . ja v a 2 s . c o m } }
From source file:gov.nih.nci.protexpress.test.ProtExpressBaseHibernateTest.java
/** * {@inheritDoc}//from w ww .j a v a2 s . com */ @Override protected void onTearDown() throws Exception { TransactionSynchronizationManager.unbindResource(this.theSessionFactory); SessionFactoryUtils.closeSession(this.theSession); UserHolder.setUser(null); super.onTearDown(); }
From source file:org.guzz.web.context.spring.SpringSessionSynchronization.java
public void beforeCompletion() { // We'll only get here if there was no specific JTA transaction to handle. if (this.newSession) { // Default behavior: unbind and close the thread-bound Hibernate Session. TransactionSynchronizationManager.unbindResource(this.transactionManager); this.holderActive = false; }/* w w w .ja v a2 s .co m*/ }
From source file:corner.orm.gae.impl.EntityManagerSourceImpl.java
@Override public void threadDidCleanup() { if (!participate) { EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager .unbindResource(entityManagerFactory); logger.debug("Closing JPA EntityManager in EntityManagerSourceImpl"); EntityManagerFactoryUtils.closeEntityManager(emHolder.getEntityManager()); }//w ww . ja v a 2s.c om }
From source file:ar.com.zauber.commons.repository.closures.OpenSessionClosure.java
/** @see Closure#execute(Object) */ public final void execute(final T t) { if (dryrun) { //permite evitar que se hagan commit() en el ambiente de test target.execute(t);/*w ww. j ava2s . c o m*/ } else { final Session session = SessionFactoryUtils.getSession(sessionFactory, true); TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session)); Transaction transaction = null; try { transaction = session.beginTransaction(); target.execute(t); session.flush(); transaction.commit(); } catch (final Throwable e) { if (transaction != null && transaction.isActive()) { transaction.rollback(); } throw new UnhandledException(e); } finally { TransactionSynchronizationManager.unbindResource(sessionFactory); SessionFactoryUtils.closeSession(session); } } }