org.hibernate.context.spi.CurrentSessionContext impl which scopes the notion of current
session by the current thread of execution. Unlike the JTA counterpart, threads do not give us a nice
hook to perform any type of cleanup making it questionable for this impl to actually generate Session
instances. In the interest of usability, it was decided to have this default impl actually generate
a session upon first request and then clean it up after the Transaction
associated with that session is committed/rolled-back. In order for ensuring that happens, the
sessions generated here are unusable until after Session#beginTransaction() has been
called. If close() is called on a session managed by this class, it will be automatically
unbound.
Additionally, the static bind and unbind methods are provided to allow application
code to explicitly control opening and closing of these sessions. This, with some from of interception,
is the preferred approach. It also allows easy framework integration and one possible approach for
implementing long-sessions.
The buildOrObtainSession, isAutoCloseEnabled, isAutoFlushEnabled,
getConnectionHandlingMode, and buildCleanupSynch methods are all provided to allow easy
subclassing (for long-running session scenarios, for example).
| Modifier and Type | Class and Description |
|---|---|
| protected static class | ThreadLocalSessionContext.CleanupSync
Transaction sync used for cleanup of the internal session map. |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final ThreadLocal | CONTEXT_TL
A ThreadLocal maintaining current sessions for the given execution thread. |
| private static final CoreMessageLogger | |
| private static final Class |
| Access | Constructor and Description |
|---|---|
| public | ThreadLocalSessionContext(SessionFactoryImplementor
The factory this context will service factory)
Deprecated
as a consequence of
Constructs a ThreadLocal
SessionFactoryImplementor being deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
| public static void | |
| protected ThreadLocalSessionContext. | |
| protected Session | Returns: the built or (re)obtained session.Strictly provided for sub-classing purposes; specifically to allow long-session support. |
| public final Session | currentSession()
Implements org. |
| private static void | |
| private static Session | |
| private static Session | |
| protected PhysicalConnectionHandlingMode | Returns: The connection release mode for any built sessions.Mainly for subclass usage. |
| protected SessionFactoryImplementor | Returns: Value for property 'factory'.
Deprecated
as a consequence of
Getter for property 'factory'.
SessionFactoryImplementor being deprecated.
|
| protected boolean | Returns: Whether the session should be closed by transaction completion.Mainly for subclass usage. |
| protected boolean | Returns: Whether the session should be flushed prior to transaction completion.Mainly for subclass usage. |
| private boolean | |
| protected static Map | |
| private static void | |
| public static Session | Returns: The session which was unbound.The factory for which the session should be unbound. factory)Disassociates a previously bound session from the current thread of execution. |
| protected Session |
| CONTEXT_TL | back to summary |
|---|---|
| private static final ThreadLocal<Map<SessionFactory, Session>> CONTEXT_TL A ThreadLocal maintaining current sessions for the given execution thread. The actual ThreadLocal variable is a java.util.Map to account for the possibility for multiple SessionFactory instances being used during execution of the given thread. | |
| LOG | back to summary |
|---|---|
| private static final CoreMessageLogger LOG | |
| SESSION_PROXY_INTERFACES | back to summary |
|---|---|
| private static final Class<?>[] SESSION_PROXY_INTERFACES | |
| ThreadLocalSessionContext | back to summary |
|---|---|
| public ThreadLocalSessionContext(SessionFactoryImplementor factory)
Deprecated as a consequence of Constructs a ThreadLocal
| |
| bind | back to summary |
|---|---|
| public static void bind(Session session) Associates the given session with the current thread of execution.
| |
| buildCleanupSynch | back to summary |
|---|---|
| protected ThreadLocalSessionContext. | |
| buildOrObtainSession | back to summary |
|---|---|
| protected Session buildOrObtainSession() Strictly provided for sub-classing purposes; specifically to allow long-session support. This implementation always just opens a new session.
| |
| currentSession | back to summary |
|---|---|
| public final Session currentSession() throws HibernateException Implements org. Doc from org. Retrieve the current session according to the scoping defined by this implementation.
| |
| doBind | back to summary |
|---|---|
| private static void doBind(Session session, SessionFactory factory) | |
| doUnbind | back to summary |
|---|---|
| private static Session doUnbind(SessionFactory factory) | |
| existingSession | back to summary |
|---|---|
| private static Session existingSession(SessionFactory factory) | |
| getConnectionHandlingMode | back to summary |
|---|---|
| protected PhysicalConnectionHandlingMode getConnectionHandlingMode() Mainly for subclass usage. This impl always returns after_transaction.
| |
| getFactory | back to summary |
|---|---|
| protected SessionFactoryImplementor getFactory()
Deprecated as a consequence of Getter for property 'factory'.
| |
| isAutoCloseEnabled | back to summary |
|---|---|
| protected boolean isAutoCloseEnabled() Mainly for subclass usage. This impl always returns true.
| |
| isAutoFlushEnabled | back to summary |
|---|---|
| protected boolean isAutoFlushEnabled() Mainly for subclass usage. This impl always returns true.
| |
| needsWrapping | back to summary |
|---|---|
| private boolean needsWrapping(Session session) | |
| sessionMap | back to summary |
|---|---|
| protected static Map | |
| terminateOrphanedSession | back to summary |
|---|---|
| private static void terminateOrphanedSession(Session orphan) | |
| unbind | back to summary |
|---|---|
| public static Session unbind(SessionFactory factory) Disassociates a previously bound session from the current thread of execution.
| |
| wrap | back to summary |
|---|---|
| protected Session wrap(Session session) | |
| Modifier and Type | Field and Description |
|---|---|
| protected final SessionFactory |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterCompletion(int
The status of the transaction completion. i)Implements jakarta. |
| public void | beforeCompletion()
Implements jakarta. |
| factory | back to summary |
|---|---|
| protected final SessionFactory factory | |
| CleanupSync | back to summary |
|---|---|
| public CleanupSync(SessionFactory factory) | |
| afterCompletion | back to summary |
|---|---|
| public void afterCompletion(int i) Implements jakarta. Doc from jakarta. This method is called by the transaction manager after the transaction is committed or rolled back.
| |
| beforeCompletion | back to summary |
|---|---|
| public void beforeCompletion() Implements jakarta. Doc from jakarta. The beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process. This call is executed with the transaction context of the transaction that is being committed.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Object | invoke(Object
the proxy instance that the method was invoked on proxy, Method the method, Object[] Method instance corresponding to
the interface method invoked on the proxy instance. The declaring
class of the Method object will be the interface that
the method was declared in, which may be a superinterface of the
proxy interface that the proxy class inherits the method through.an array of objects containing the values of the
arguments passed in the method invocation on the proxy instance,
or args)null if interface method takes no arguments.
Arguments of primitive types are wrapped in instances of the
appropriate primitive wrapper class, such as
java.lang.Integer or java.lang.Boolean.Implements java. |
| private void | |
| public void | |
| private void |
| realSession | back to summary |
|---|---|
| private final Session realSession | |
| wrappedSession | back to summary |
|---|---|
| private Session wrappedSession | |
| TransactionProtectionWrapper | back to summary |
|---|---|
| public TransactionProtectionWrapper(Session realSession) | |
| invoke | back to summary |
|---|---|
| public Object invoke(Object proxy, Method method, Object[] args) throws Throwable Implements java. Doc from java. Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException | |
| setWrapped | back to summary |
|---|---|
| public void setWrapped(Session wrapped) Setter for property 'wrapped'.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream oos) throws IOException | |