public class GrailsOpenSessionInViewInterceptor extends org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor
Extends the default Spring OSIV to support multiple datasources.
The default datasource's SessionFactory is managed by the parent class.
Additional (non-default) datasource SessionFactories are managed by this
subclass, which opens and closes sessions for each one alongside the
default session. As the parent class does for the default session, a request
that finds a session already bound, such as an include within a request that
opened one, uses that session and leaves it to the one that opened it. A
request that goes asynchronous takes the sessions it opened off the thread, so
that they do not stay bound to it for the next request that thread serves, and
they are closed when the asynchronous request completes. Which sessions a
request found bound is recorded by the identity of their factory, taken as
Spring's TransactionSynchronizationManager takes it, the target of an
InfrastructureProxy, not by how the factory prints: Object.toString()
is not unique.
| Modifiers | Name | Description |
|---|---|---|
protected org.hibernate.FlushMode |
hibernateFlushMode |
| Fields inherited from class | Fields |
|---|---|
class org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor |
PARTICIPATE_SUFFIX |
| Type Params | Return Type | Name and description |
|---|---|---|
|
public void |
afterCompletion(WebRequest request, java.lang.Exception ex)Closes the sessions this request opened, and counts down those it found bound. |
|
public void |
afterConcurrentHandlingStarted(WebRequest request)Called instead of postHandle and afterCompletion on the thread that started asynchronous handling. |
|
protected void |
applyFlushMode(org.hibernate.Session session) |
|
protected java.lang.String |
getParticipateAttributeName()
|
|
protected org.hibernate.Session |
openSession()Opens the default session as the parent class does, setting its flush mode to MANUAL, then applies its flush mode. |
|
public void |
postHandle(WebRequest request, ModelMap model) |
|
public void |
preHandle(WebRequest request) |
|
public void |
setHibernateDatastore(AbstractHibernateDatastore hibernateDatastore) |
| Methods inherited from class | Name |
|---|---|
class org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor |
org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#afterCompletion(org.springframework.web.context.request.WebRequest, java.lang.Exception), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#afterConcurrentHandlingStarted(org.springframework.web.context.request.WebRequest), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#equals(java.lang.Object), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#getClass(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#getSessionFactory(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#hashCode(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#notify(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#notifyAll(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#postHandle(org.springframework.web.context.request.WebRequest, org.springframework.ui.ModelMap), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#preHandle(org.springframework.web.context.request.WebRequest), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#setSessionFactory(org.hibernate.SessionFactory), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#toString(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#wait(), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#wait(long), org.grails.orm.hibernate.support.hibernate5.support.OpenSessionInViewInterceptor#wait(long, int) |
Closes the sessions this request opened, and counts down those it found bound. When the request failed, Spring passes the failure here and throws it on afterwards, so a failure to release a session is attached to it; without one, a failure to close a session is logged, as the parent class does.
Called instead of postHandle and afterCompletion on the thread that started asynchronous
handling. The sessions this interceptor opened for the other datasources are unbound here, so that the thread
goes back to its pool without them, and closed when the asynchronous request completes, whether a promise,
startAsync(), a Callable or a DeferredResult started it. Each is flushed first
when postHandle would flush it and Hibernate allows the flush: inside a transaction, or with
hibernate.allow_update_outside_transaction.
The parent class only unbinds the default session, and leaves closing it to the interceptors it registers for
a Callable or DeferredResult. A promise or startAsync() in a Grails controller starts
asynchronous handling without them, so the default session this interceptor opened is unbound here too, and
closed when the asynchronous request completes.
When a flush fails, that failure is thrown once every session is taken off the thread, and a failure to release one is attached to it. Without an asynchronous request to wait for, the sessions are closed here, and a failure to close one is attached to that failure too.
Opens the default session as the parent class does, setting its flush mode to MANUAL, then applies its flush mode. A org.hibernate.HibernateException from opening it or setting MANUAL is wrapped, as the parent class does; a failure of applyFlushMode is thrown on as it is.
The session is not bound yet, so when a step fails, it is closed here, before the failure is thrown on: any failure, as code written in Groovy can throw a checked exception it does not declare. A failure to close it is attached to the failure that is thrown. A session bound for the factory while this one was set up is left as it is, and this one is closed with an java.lang.IllegalStateException, instead of being bound over it.