Class SessionFactoryManagerImpl
java.lang.Object
ch.tocco.nice2.persist.core.impl.hibernate.session.SessionFactoryManagerImpl
- All Implemented Interfaces:
ThreadHandlerListener,SessionFactoryManager
@Component
public class SessionFactoryManagerImpl
extends Object
implements SessionFactoryManager, ThreadHandlerListener
This class manages the
Session lifecycle for both the old (ContextManagerAdapter) and
new (PersistenceServiceImpl) persistence API.
This makes it possible to use both APIs together.
This class contains the 'implicit' session in a ThreadLocal. The implicit session
is created automatically when the persistence API is accessed for the first time in a thread
(unless another session is opened explicitly before that).
At the end of each request, the implicit session is closed and removed using a ThreadHandlerListener.
Sessions created by this class are always bound to the current thread. Also a SessionEventListener is added
which detaches the new session from the thread and re-attached the previous session (if present) when the new session
is closed.-
Constructor Summary
ConstructorsConstructorDescriptionSessionFactoryManagerImpl(org.slf4j.Logger logger, org.hibernate.SessionFactory sessionFactory, ThreadHandlerManager threadHandlerManager, CacheControlFactory cacheControlFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(SessionFactoryManagerListener listener) voidBind the givenSessionto the current thread.voidvoidInvokesSessionFactoryManagerListenerinstances and then closes theSession.Creates and returns a newSession.createNewSession(@Nullable Integer queryTimeout) createNewSession(@Nullable Connection connection) createNewSession(@Nullable Connection connection, @Nullable Integer queryTimeout) voidDetach the givenSessionfrom the current thread.Returns theSessionthat is bound to the current thread.@Nullable PersistenceSessionImplementorReturns the implicitSessionfor the current thread.booleanloadEntityClassByName(String entityName) voidremoveListener(SessionFactoryManagerListener listener) voidsetDefaultQueryTimeout(int defaultQueryTimeout) voidsetListeners(org.springframework.beans.factory.ObjectProvider<SessionFactoryManagerListener> listeners) void
-
Constructor Details
-
SessionFactoryManagerImpl
public SessionFactoryManagerImpl(org.slf4j.Logger logger, org.hibernate.SessionFactory sessionFactory, ThreadHandlerManager threadHandlerManager, CacheControlFactory cacheControlFactory)
-
-
Method Details
-
setListeners
@Autowired public void setListeners(org.springframework.beans.factory.ObjectProvider<SessionFactoryManagerListener> listeners) -
threadIsCleaningUp
public void threadIsCleaningUp()- Specified by:
threadIsCleaningUpin interfaceThreadHandlerListener
-
getCurrentSession
Description copied from interface:SessionFactoryManagerReturns theSessionthat is bound to the current thread. If no session is bound to the current thread, the implicit session is created (if it does not exist yet) and returned.- Specified by:
getCurrentSessionin interfaceSessionFactoryManager
-
clearImplicitSession
public void clearImplicitSession()- Specified by:
clearImplicitSessionin interfaceSessionFactoryManager
-
getImplicitSession
Description copied from interface:SessionFactoryManagerReturns the implicitSessionfor the current thread. This may return null if the implicit session has not been initialized yet.- Specified by:
getImplicitSessionin interfaceSessionFactoryManager
-
createNewSession
Description copied from interface:SessionFactoryManagerCreates and returns a newSession. The new session will automatically bound to the current thread. If this session will be closed, it will automatically be detached from the current thread and it is attempted to re-attach the previous session.- Specified by:
createNewSessionin interfaceSessionFactoryManager
-
createNewSession
- Specified by:
createNewSessionin interfaceSessionFactoryManager
-
createNewSession
- Specified by:
createNewSessionin interfaceSessionFactoryManager
-
createNewSession
public PersistenceSessionImplementor createNewSession(@Nullable @Nullable Connection connection, @Nullable @Nullable Integer queryTimeout) - Specified by:
createNewSessionin interfaceSessionFactoryManager
-
attachSessionToThread
Description copied from interface:SessionFactoryManagerBind the givenSessionto the current thread.- Specified by:
attachSessionToThreadin interfaceSessionFactoryManager
-
detachSessionFromThread
Description copied from interface:SessionFactoryManagerDetach the givenSessionfrom the current thread.- Specified by:
detachSessionFromThreadin interfaceSessionFactoryManager
-
isAttachedToThread
- Specified by:
isAttachedToThreadin interfaceSessionFactoryManager- Returns:
- true if the given
Sessionis bound to the current thread.
-
closeSession
Description copied from interface:SessionFactoryManagerInvokesSessionFactoryManagerListenerinstances and then closes theSession. All sessions should be closed through this method.- Specified by:
closeSessionin interfaceSessionFactoryManager
-
addListener
- Specified by:
addListenerin interfaceSessionFactoryManager
-
removeListener
- Specified by:
removeListenerin interfaceSessionFactoryManager
-
loadEntityClassByName
- Specified by:
loadEntityClassByNamein interfaceSessionFactoryManager
-
setDefaultQueryTimeout
@Value("${nice2.persist.defaultQueryTimeout}") public void setDefaultQueryTimeout(int defaultQueryTimeout)
-