CurrentSessionContext which scopes the notion
of a current session to a JTA transaction. Because JTA gives us a nice
tie-in to clean up after ourselves, this implementation will generate
Sessions as needed provided a JTA transaction is in effect. If a session
is not already associated with the current JTA transaction at the time
currentSession() is called, a new session will be opened and it
will be associated with that JTA transaction.
Note that the sessions returned from this method are automatically configured with
both the auto-flush and
auto-close attributes set to
true, meaning that the Session will be automatically flushed and closed
as part of the lifecycle for the JTA transaction to which it is associated.
Additionally, it will also be configured to aggressively release JDBC
connections after each statement is executed. These settings are governed
by the isAutoFlushEnabled(), isAutoCloseEnabled(), and
getConnectionReleaseMode() methods; these are provided (along with
the buildOrObtainSession() method) for easier subclassing for custom
JTA-based session tracking logic (like maybe long-session semantics).
| Modifier and Type | Class and Description |
|---|---|
| protected static class | JTASessionContext.CleanupSynch
JTA transaction synch used for cleanup of the internal session map. |
| Modifier and Type | Field and Description |
|---|---|
| private transient Map | |
| protected final SessionFactoryImplementor | |
| private static final Logger |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private JTASessionContext. | Returns: The cleanup synch.The transaction identifier under which the current session is registered. transactionIdentifier)Builds a |
| protected Session | Returns: the built or (re)obtained session.Strictly provided for subclassing purposes; specifically to allow long-session support. |
| public Session | currentSession()
Implements org. |
| protected ConnectionReleaseMode | Returns: The connection release mode for any built sessions.Mainly for subclass usage. |
| 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. |
| currentSessionMap | back to summary |
|---|---|
| private transient Map<K, V> currentSessionMap | |
| factory | back to summary |
|---|---|
| protected final SessionFactoryImplementor factory | |
| log | back to summary |
|---|---|
| private static final Logger log | |
| JTASessionContext | back to summary |
|---|---|
| public JTASessionContext(SessionFactoryImplementor factory) | |
| buildCleanupSynch | back to summary |
|---|---|
| private JTASessionContext. Builds a
| |
| 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.
| |
| currentSession | back to summary |
|---|---|
| public Session currentSession() throws HibernateException Implements org. Doc from org. Retrieve the current session according to the scoping defined by this implementation.
| |
| getConnectionReleaseMode | back to summary |
|---|---|
| protected ConnectionReleaseMode getConnectionReleaseMode() Mainly for subclass usage. This impl always returns after_statement.
| |
| 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.
| |
| Modifier and Type | Field and Description |
|---|---|
| private JTASessionContext | |
| private Object |
| 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. |
| context | back to summary |
|---|---|
| private JTASessionContext context | |
| transactionIdentifier | back to summary |
|---|---|
| private Object transactionIdentifier | |
| CleanupSynch | back to summary |
|---|---|
| public CleanupSynch(Object transactionIdentifier, JTASessionContext context) | |
| 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. | |