Java Code Examples for org.springframework.orm.hibernate4.SessionFactoryUtils#closeSession()
The following examples show how to use
org.springframework.orm.hibernate4.SessionFactoryUtils#closeSession() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenSessionInterceptor.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sf = getSessionFactory(); if (!TransactionSynchronizationManager.hasResource(sf)) { // New Session to be bound for the current method's scope... Session session = openSession(); try { TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session)); return invocation.proceed(); } finally { SessionFactoryUtils.closeSession(session); TransactionSynchronizationManager.unbindResource(sf); } } else { // Pre-bound Session found -> simply proceed. return invocation.proceed(); } }
Example 2
Source File: OpenSessionInterceptor.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sf = getSessionFactory(); if (!TransactionSynchronizationManager.hasResource(sf)) { // New Session to be bound for the current method's scope... Session session = openSession(); try { TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session)); return invocation.proceed(); } finally { SessionFactoryUtils.closeSession(session); TransactionSynchronizationManager.unbindResource(sf); } } else { // Pre-bound Session found -> simply proceed. return invocation.proceed(); } }
Example 3
Source File: OpenSessionInViewInterceptor.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Unbind the Hibernate {@code Session} from the thread and close it). * @see org.springframework.transaction.support.TransactionSynchronizationManager */ @Override public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException { if (!decrementParticipateCount(request)) { SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory()); logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor"); SessionFactoryUtils.closeSession(sessionHolder.getSession()); } }
Example 4
Source File: OpenSessionInViewInterceptor.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Unbind the Hibernate {@code Session} from the thread and close it). * @see org.springframework.transaction.support.TransactionSynchronizationManager */ @Override public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException { if (!decrementParticipateCount(request)) { SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory()); logger.debug("Closing Hibernate Session in OpenSessionInViewInterceptor"); SessionFactoryUtils.closeSession(sessionHolder.getSession()); } }
Example 5
Source File: AsyncRequestInterceptor.java From lams with GNU General Public License v2.0 | 4 votes |
private void closeAfterTimeout() { if (this.timeoutInProgress) { logger.debug("Closing Hibernate Session after async request timeout"); SessionFactoryUtils.closeSession(this.sessionHolder.getSession()); } }
Example 6
Source File: AsyncRequestInterceptor.java From spring4-understanding with Apache License 2.0 | 4 votes |
private void closeAfterTimeout() { if (this.timeoutInProgress) { logger.debug("Closing Hibernate Session after async request timeout"); SessionFactoryUtils.closeSession(this.sessionHolder.getSession()); } }