Top Description Fields Constructors Methods
org.hibernate.context.internal

public Class ManagedSessionContext

extends AbstractCurrentSessionContext
Class Inheritance
Imports
java.util.HashMap, .Map, org.hibernate.HibernateException, .Session, .SessionFactory, org.hibernate.context.spi.AbstractCurrentSessionContext, org.hibernate.engine.spi.SessionFactoryImplementor

Represents a org.hibernate.context.spi.CurrentSessionContext the notion of a contextual session is managed by some external entity (generally some form of interceptor, etc). This external manager is responsible for scoping these contextual sessions appropriately binding/unbinding them here for exposure to the application through SessionFactory#getCurrentSession calls.

Basically exposes two interfaces.

The underlying storage of the current sessions here is a static ThreadLocal-based map where the sessions are keyed by the owning session factory.

Author
Steve Ebersole

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<Map<SessionFactory, Session>>

Constructor Summary

AccessConstructor and Description
public
ManagedSessionContext(SessionFactoryImplementor
The factory this context will service
factory
)

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Constructs a new ManagedSessionContext

Method Summary

Modifier and TypeMethod and Description
public static Session

Returns:

Any previously bound session (should be null in most cases).
bind
(Session
The session to be bound.
session
)

Binds the given session to the current context for its session factory.

public Session
currentSession()

Implements org.hibernate.context.spi.CurrentSessionContext.currentSession.

Retrieve the current session according to the scoping defined by this implementation.
private static void
private static Session
public static boolean

Returns:

True if there is currently a session bound.
hasBind
(SessionFactory
The factory against which to check for a given session within the current thread.
factory
)

Check to see if there is already a session associated with the current thread for the given session factory.

protected static Map<SessionFactory, Session>
private static Map<SessionFactory, Session>
sessionMap(boolean createMap)

public static Session

Returns:

The bound session if one, else null.
unbind
(SessionFactory
The factory for which to unbind the current session.
factory
)

Unbinds the session (if one) current associated with the context for the given session.

Inherited from org.hibernate.context.spi.AbstractCurrentSessionContext:
baseSessionBuilderfactoryvalidateExistingSession

Field Detail

CONTEXT_TLback to summary
private static final ThreadLocal<Map<SessionFactory, Session>> CONTEXT_TL

Constructor Detail

ManagedSessionContextback to summary
public ManagedSessionContext(SessionFactoryImplementor factory)

Deprecated

as a consequence of SessionFactoryImplementor being deprecated. See corresponding docs for further information.

Constructs a new ManagedSessionContext

Parameters
factory:SessionFactoryImplementor

The factory this context will service

Method Detail

bindback to summary
public static Session bind(Session session)

Binds the given session to the current context for its session factory.

Parameters
session:Session

The session to be bound.

Returns:Session

Any previously bound session (should be null in most cases).

currentSessionback to summary
public Session currentSession()

Implements org.hibernate.context.spi.CurrentSessionContext.currentSession.

Doc from org.hibernate.context.spi.CurrentSessionContext.currentSession.

Retrieve the current session according to the scoping defined by this implementation.

Returns:Session

The current session.

Annotations
@Override
doCleanupback to summary
private static void doCleanup()
existingSessionback to summary
private static Session existingSession(SessionFactory factory)
hasBindback to summary
public static boolean hasBind(SessionFactory factory)

Check to see if there is already a session associated with the current thread for the given session factory.

Parameters
factory:SessionFactory

The factory against which to check for a given session within the current thread.

Returns:boolean

True if there is currently a session bound.

sessionMapback to summary
protected static Map<SessionFactory, Session> sessionMap()
sessionMapback to summary
private static Map<SessionFactory, Session> sessionMap(boolean createMap)
unbindback to summary
public static Session unbind(SessionFactory factory)

Unbinds the session (if one) current associated with the context for the given session.

Parameters
factory:SessionFactory

The factory for which to unbind the current session.

Returns:Session

The bound session if one, else null.