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.CleanupSynch
JTA transaction synch used for cleanup of the internal session map. |
| private class |
| Modifier and Type | Field and Description |
|---|---|
| private static final ThreadLocal | context
A ThreadLocal maintaining current sessions for the given execution thread. |
| protected final SessionFactoryImplementor | |
| private static final Logger | |
| private static final Class |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | |
| protected ThreadLocalSessionContext. | |
| protected Session | Returns: the built or (re)obtained session.Strictly provided for subclassing purposes; specifically to allow long-session support. |
| private static void | |
| public final Session | currentSession()
Implements org. |
| private static void | |
| private static Session | |
| private static Session | |
| protected ConnectionReleaseMode | Returns: The connection release mode for any built sessions.Mainly for subclass usage. |
| protected SessionFactoryImplementor | |
| 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 transaction completion.Mainly for subclass usage. |
| private boolean | |
| protected static Map | |
| public static Session | Returns: The session which was unbound.Unassociate a previously bound session from the current thread of execution. |
| protected Session |
| context | back to summary |
|---|---|
| private static final ThreadLocal<T> context 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 SessionFactorys being used during execution of the given thread. | |
| factory | back to summary |
|---|---|
| protected final SessionFactoryImplementor factory | |
| log | back to summary |
|---|---|
| private static final Logger log | |
| SESSION_PROXY_INTERFACES | back to summary |
|---|---|
| private static final Class<T>[] SESSION_PROXY_INTERFACES | |
| ThreadLocalSessionContext | back to summary |
|---|---|
| public ThreadLocalSessionContext(SessionFactoryImplementor factory) | |
| 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 subclassing purposes; specifically to allow long-session support. This implementation always just opens a new session.
| |
| cleanupAnyOrphanedSession | back to summary |
|---|---|
| private static void cleanupAnyOrphanedSession(SessionFactory factory) | |
| 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, boolean releaseMapIfEmpty) | |
| existingSession | back to summary |
|---|---|
| private static Session existingSession(SessionFactory factory) | |
| getConnectionReleaseMode | back to summary |
|---|---|
| protected ConnectionReleaseMode getConnectionReleaseMode() Mainly for subclass usage. This impl always returns after_transaction.
| |
| getFactory | back to summary |
|---|---|
| protected SessionFactoryImplementor getFactory() 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 | |
| unbind | back to summary |
|---|---|
| public static Session unbind(SessionFactory factory) Unassociate 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 javax. |
| public void | beforeCompletion()
Implements javax. |
| factory | back to summary |
|---|---|
| protected final SessionFactory factory | |
| CleanupSynch | back to summary |
|---|---|
| public CleanupSynch(SessionFactory factory) | |
| 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. | |
| 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 | |