Java Code Examples for org.springframework.orm.hibernate3.SessionFactoryUtils#closeSession()
The following examples show how to use
org.springframework.orm.hibernate3.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 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 2
Source File: OpenSessionInViewInterceptor.java From spring4-understanding with Apache License 2.0 | 6 votes |
/** * Unbind the Hibernate {@code Session} from the thread and close it (in * single session mode), or process deferred close for all sessions that have * been opened during the current request (in deferred close mode). * @see org.springframework.transaction.support.TransactionSynchronizationManager */ @Override public void afterCompletion(WebRequest request, Exception ex) throws DataAccessException { if (!decrementParticipateCount(request)) { if (isSingleSession()) { // single session mode SessionHolder sessionHolder = (SessionHolder) TransactionSynchronizationManager.unbindResource(getSessionFactory()); logger.debug("Closing single Hibernate Session in OpenSessionInViewInterceptor"); SessionFactoryUtils.closeSession(sessionHolder.getSession()); } else { // deferred close mode SessionFactoryUtils.processDeferredClose(getSessionFactory()); } } }
Example 3
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()); } }
Example 4
Source File: OpenSessionInViewFilter.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Close the given Session. * Note that this just applies in single session mode! * <p>Can be overridden in subclasses, e.g. for flushing the Session before * closing it. See class-level javadoc for a discussion of flush handling. * Note that you should also override getSession accordingly, to set * the flush mode to something else than NEVER. * @param session the Session used for filtering * @param sessionFactory the SessionFactory that this filter uses */ protected void closeSession(Session session, SessionFactory sessionFactory) { SessionFactoryUtils.closeSession(session); }