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 SummaryConstructorsConstructorDescriptionSessionFactoryManagerImpl(org.slf4j.Logger logger, org.hibernate.SessionFactory sessionFactory, ThreadHandlerManager threadHandlerManager, CacheControlFactory cacheControlFactory) 
- 
Method SummaryModifier 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- 
SessionFactoryManagerImplpublic 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) 
- 
threadIsCleaningUppublic void threadIsCleaningUp()- Specified by:
- threadIsCleaningUpin interface- ThreadHandlerListener
 
- 
getCurrentSessionDescription 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 interface- SessionFactoryManager
 
- 
clearImplicitSessionpublic void clearImplicitSession()- Specified by:
- clearImplicitSessionin interface- SessionFactoryManager
 
- 
getImplicitSessionDescription 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 interface- SessionFactoryManager
 
- 
createNewSessionDescription 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 interface- SessionFactoryManager
 
- 
createNewSession- Specified by:
- createNewSessionin interface- SessionFactoryManager
 
- 
createNewSession- Specified by:
- createNewSessionin interface- SessionFactoryManager
 
- 
createNewSessionpublic PersistenceSessionImplementor createNewSession(@Nullable @Nullable Connection connection, @Nullable @Nullable Integer queryTimeout) - Specified by:
- createNewSessionin interface- SessionFactoryManager
 
- 
attachSessionToThreadDescription copied from interface:SessionFactoryManagerBind the givenSessionto the current thread.- Specified by:
- attachSessionToThreadin interface- SessionFactoryManager
 
- 
detachSessionFromThreadDescription copied from interface:SessionFactoryManagerDetach the givenSessionfrom the current thread.- Specified by:
- detachSessionFromThreadin interface- SessionFactoryManager
 
- 
isAttachedToThread- Specified by:
- isAttachedToThreadin interface- SessionFactoryManager
- Returns:
- true if the given Sessionis bound to the current thread.
 
- 
closeSessionDescription copied from interface:SessionFactoryManagerInvokesSessionFactoryManagerListenerinstances and then closes theSession. All sessions should be closed through this method.- Specified by:
- closeSessionin interface- SessionFactoryManager
 
- 
addListener- Specified by:
- addListenerin interface- SessionFactoryManager
 
- 
removeListener- Specified by:
- removeListenerin interface- SessionFactoryManager
 
- 
loadEntityClassByName- Specified by:
- loadEntityClassByNamein interface- SessionFactoryManager
 
- 
setDefaultQueryTimeout@Value("${nice2.persist.defaultQueryTimeout}") public void setDefaultQueryTimeout(int defaultQueryTimeout) 
 
-