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 org.hibernate.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,
getConnectionReleaseMode, 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.
Deprecated
as a consequence of
Strictly provided for sub-classing purposes; specifically to allow long-session
support.
Session being deprecated.
|
| public final Session | currentSession()
Implements org.
Deprecated
as a consequence of
Retrieve the current session according to the scoping defined
by this implementation.
Session being deprecated.
|
| private static void | doBind(Session session, SessionFactory factory)
Deprecated
as a consequence of
Session and SessionFactory being deprecated.
|
| private static Session | doUnbind(SessionFactory factory, boolean releaseMapIfEmpty)
Deprecated
as a consequence of
SessionFactory and Session being deprecated.
|
| private static Session | existingSession(SessionFactory factory)
Deprecated
as a consequence of
SessionFactory and Session being deprecated.
|
| protected ConnectionReleaseMode | 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 or not the the session should be closed by transaction completion.Mainly for subclass usage. |
| protected boolean | Returns: Whether or not the 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)
Deprecated
as a consequence of
Disassociates a previously bound session from the current thread of execution.
SessionFactory and Session being deprecated.
|
| 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<T>[] 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)
Deprecated as a consequence of Associates the given session with the current thread of execution.
| |
| buildCleanupSynch | back to summary |
|---|---|
| protected ThreadLocalSessionContext. | |
| buildOrObtainSession | back to summary |
|---|---|
| protected Session buildOrObtainSession()
Deprecated as a consequence of 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. Deprecated as a consequence of Retrieve the current session according to the scoping defined by this implementation.
| |
| doBind | back to summary |
|---|---|
| private static void doBind(Session session, SessionFactory factory)
Deprecated as a consequence of
| |
| doUnbind | back to summary |
|---|---|
| private static Session doUnbind(SessionFactory factory, boolean releaseMapIfEmpty)
Deprecated as a consequence of | |
| existingSession | back to summary |
|---|---|
| private static Session existingSession(SessionFactory factory)
Deprecated as a consequence of | |
| getConnectionReleaseMode | back to summary |
|---|---|
| protected ConnectionReleaseMode getConnectionReleaseMode() 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)
Deprecated as a consequence of | |
| sessionMap | back to summary |
|---|---|
| protected static Map | |
| terminateOrphanedSession | back to summary |
|---|---|
| private static void terminateOrphanedSession(Session orphan)
Deprecated as a consequence of | |
| unbind | back to summary |
|---|---|
| public static Session unbind(SessionFactory factory)
Deprecated as a consequence of Disassociates a previously bound session from the current thread of execution.
| |
| wrap | back to summary |
|---|---|
| protected Session wrap(Session session)
Deprecated as a consequence of | |
| Modifier and Type | Field and Description |
|---|---|
| protected final SessionFactory | factory
Deprecated
as a consequence of
SessionFactory being deprecated.
|
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterCompletion(int
The status of the transaction completion. i)Implements javax. |
| public void | beforeCompletion()
Implements javax. |
| factory | back to summary |
|---|---|
| protected final SessionFactory factory
Deprecated as a consequence of | |
| CleanupSync | back to summary |
|---|---|
| public CleanupSync(SessionFactory factory)
Deprecated as a consequence of | |
| afterCompletion | back to summary |
|---|---|
| public void afterCompletion(int i) Implements javax. Doc from javax. This method is called by the transaction manager after the transaction is committed or rolled back.
| |
| beforeCompletion | back to summary |
|---|---|
| public void beforeCompletion() Implements javax. Doc from javax. 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.
| |
| Modifier and Type | Field and Description |
|---|---|
| private final Session | realSession
Deprecated
as a consequence of
Session being deprecated.
|
| private Session | wrappedSession
Deprecated
as a consequence of
Session being deprecated.
|
| Access | Constructor and Description |
|---|---|
| public | TransactionProtectionWrapper(Session realSession)
Deprecated
as a consequence of
Session being deprecated.
|
| 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 | setWrapped(Session
Value to set for property 'wrapped'. wrapped)
Deprecated
as a consequence of
Setter for property 'wrapped'.
Session being deprecated.
|
| private void |
| realSession | back to summary |
|---|---|
| private final Session realSession
Deprecated as a consequence of | |
| wrappedSession | back to summary |
|---|---|
| private Session wrappedSession
Deprecated as a consequence of | |
| TransactionProtectionWrapper | back to summary |
|---|---|
| public TransactionProtectionWrapper(Session realSession)
Deprecated as a consequence of | |
| 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)
Deprecated as a consequence of Setter for property 'wrapped'.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(ObjectOutputStream oos) throws IOException | |