List of usage examples for org.springframework.transaction.support TransactionSynchronizationManager unbindResource
public static Object unbindResource(Object key) throws IllegalStateException
From source file:ar.edu.utn.sigmaproject.webflow.Hibernate4FlowExecutionListener.java
private void unbind(Session session) { if (TransactionSynchronizationManager.hasResource(sessionFactory)) { TransactionSynchronizationManager.unbindResource(sessionFactory); }// w w w . j a v a2 s. c o m }
From source file:org.guzz.web.context.spring.GuzzTransactionManager.java
@Override protected Object doSuspend(Object transaction) { GuzzTransactionObject txObject = (GuzzTransactionObject) transaction; txObject.setWriteTranSessionHolder(null); WriteTranSessionHolder writeTranSessionHolder = (WriteTranSessionHolder) TransactionSynchronizationManager .unbindResource(getTransactionManager()); return new SuspendedResourcesHolder(writeTranSessionHolder); }
From source file:org.guzz.web.context.spring.GuzzTransactionManager.java
@Override protected void doResume(Object transaction, Object suspendedResources) { SuspendedResourcesHolder resourcesHolder = (SuspendedResourcesHolder) suspendedResources; if (TransactionSynchronizationManager.hasResource(getTransactionManager())) { // From non-transactional code running in active transaction synchronization // -> can be safely removed, will be closed on transaction completion. TransactionSynchronizationManager.unbindResource(getTransactionManager()); }/*w ww. j a va 2 s . com*/ TransactionSynchronizationManager.bindResource(getTransactionManager(), resourcesHolder.getSessionHolder()); }
From source file:com._4dconcept.springframework.data.marklogic.datasource.ContentSourceTransactionManager.java
@Override protected Object doSuspend(Object transaction) { ContentSourceTransactionObject txObject = (ContentSourceTransactionObject) transaction; txObject.setSessionHolder(null);/* ww w. j ava 2 s .c o m*/ SessionHolder sesHolder = (SessionHolder) TransactionSynchronizationManager .unbindResource(this.contentSource); return sesHolder; }
From source file:com.github.rholder.spring.transaction.TransactionBindingSupport.java
/** * Cleans out transaction resources if present *///from w w w . ja v a 2 s . c om private static void clearSynchronization() { if (TransactionSynchronizationManager.hasResource(RESOURCE_KEY_TXN_SYNCH)) { Object txnSynch = TransactionSynchronizationManager.unbindResource(RESOURCE_KEY_TXN_SYNCH); // done if (logger.isDebugEnabled()) { logger.debug("Unbound txn synch:" + txnSynch); } } }
From source file:org.grails.datastore.mapping.core.DatastoreUtils.java
/** * Execute the closure in the current session if it exists, or create a new one and close it otherwise. * @param datastore the datastore//from w ww .jav a 2s . c o m * @param c the closure to execute * @return the return value from the closure */ public static Object doWithSession(final Datastore datastore, final Closure c) { boolean existing = datastore.hasCurrentSession(); Session session = existing ? datastore.getCurrentSession() : bindSession(datastore.connect()); try { return c.call(session); } finally { if (!existing) { TransactionSynchronizationManager.unbindResource(session.getDatastore()); closeSessionOrRegisterDeferredClose(session, datastore); } } }
From source file:ch.algotrader.service.LookupServiceTest.java
@Override @After/*www. ja va2 s .c o m*/ public void cleanup() throws Exception { ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("DROP ALL OBJECTS".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, dataSource); TransactionSynchronizationManager.unbindResource(sessionFactory); if (this.session != null) { if (this.session.isOpen()) { this.session.close(); } } cacheManager.clear(); }
From source file:org.grails.datastore.mapping.core.DatastoreUtils.java
/** * Execute the callback in the current session if it exists, or create a new one and close it otherwise. * @param <T> the return type//ww w. j a v a2 s .co m * @param datastore the datastore * @param callback the callback to execute * @return the return value from the callback */ public static <T> T execute(final Datastore datastore, final SessionCallback<T> callback) { boolean existing = datastore.hasCurrentSession(); Session session = existing ? datastore.getCurrentSession() : bindSession(datastore.connect()); try { return callback.doInSession(session); } finally { if (!existing) { TransactionSynchronizationManager.unbindResource(session.getDatastore()); closeSessionOrRegisterDeferredClose(session, datastore); } } }
From source file:org.cfr.capsicum.datasource.CayenneTransactionManager.java
@Override protected void doCleanupAfterCompletion(Object transaction) { CayenneTransactionObject txObject = (CayenneTransactionObject) transaction; // Remove the connection holder from the thread, if exposed. if (txObject.isNewConnectionHolder()) { TransactionSynchronizationManager.unbindResource(this.dataSource); }/*from w ww . j a v a 2 s. co m*/ // Reset connection. Connection con = txObject.getConnectionHolder().getConnection(); try { if (txObject.isMustRestoreAutoCommit()) { con.setAutoCommit(true); } DataSourceUtils.resetConnectionAfterTransaction(con, txObject.getPreviousIsolationLevel()); } catch (Throwable ex) { logger.debug("Could not reset JDBC Connection after transaction", ex); } if (txObject.isNewConnectionHolder()) { if (logger.isDebugEnabled()) { logger.debug("Releasing JDBC Connection [" + con + "] after transaction"); } DataSourceUtils.releaseConnection(con, this.dataSource); } txObject.getConnectionHolder().clear(); }
From source file:org.grails.datastore.mapping.core.DatastoreUtils.java
/** * Execute the callback in the current session if it exists, or create a new one and close it otherwise. * @param datastore the datastore/*from w ww .ja v a 2s .c o m*/ * @param callback the callback to execute */ public static void execute(final Datastore datastore, final VoidSessionCallback callback) { boolean existing = datastore.hasCurrentSession(); Session session = existing ? datastore.getCurrentSession() : bindSession(datastore.connect()); try { callback.doInSession(session); } finally { if (!existing) { TransactionSynchronizationManager.unbindResource(datastore); closeSessionOrRegisterDeferredClose(session, datastore); } } }