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

public Class JTASessionContext

extends AbstractCurrentSessionContext
Class Inheritance
Imports
java.util.Map, java.util.concurrent.ConcurrentHashMap, javax.transaction.Synchronization, .Transaction, .TransactionManager, org.hibernate.ConnectionReleaseMode, .HibernateException, .Session, org.hibernate.context.spi.AbstractCurrentSessionContext, org.hibernate.engine.spi.SessionFactoryImplementor, org.hibernate.engine.transaction.internal.jta.JtaStatusHelper, org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform, org.hibernate.internal.CoreMessageLogger, org.jboss.logging.Logger

An implementation of org.hibernate.context.spi.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).
Author
Steve Ebersole

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class
JTASessionContext.CleanupSync

JTA transaction sync used for cleanup of the internal session map.

Field Summary

Modifier and TypeField and Description
private transient Map<Object, Session>
private static final CoreMessageLogger

Constructor Summary

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

Deprecated as a consequence of SessionFactoryImplementor being deprecated.
Constructs a JTASessionContext

Method Summary

Modifier and TypeMethod and Description
private JTASessionContext.CleanupSync

Returns:

The cleanup synch.
buildCleanupSynch
(Object
The transaction identifier under which the current session is registered.
transactionIdentifier
)

Builds a org.hibernate.context.internal.JTASessionContext.CleanupSync capable of cleaning up the the current session map as an after transaction callback.

protected Session

Returns:

the built or (re)obtained session.
buildOrObtainSession
()

Deprecated as a consequence of Session being deprecated.
Strictly provided for subclassing purposes; specifically to allow long-session support.
public Session
currentSession()

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

Deprecated as a consequence of Session being deprecated.
Retrieve the current session according to the scoping defined by this implementation.
protected ConnectionReleaseMode

Returns:

The connection release mode for any built sessions.
getConnectionReleaseMode
()

Mainly for subclass usage.

protected boolean

Returns:

Whether or not the the session should be closed by transaction completion.
isAutoCloseEnabled
()

Mainly for subclass usage.

protected boolean

Returns:

Whether or not the the session should be flushed prior transaction completion.
isAutoFlushEnabled
()

Mainly for subclass usage.

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

Field Detail

currentSessionMapback to summary
private transient Map<Object, Session> currentSessionMap
LOGback to summary
private static final CoreMessageLogger LOG

Constructor Detail

JTASessionContextback to summary
public JTASessionContext(SessionFactoryImplementor factory)

Deprecated

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

Constructs a JTASessionContext

Parameters
factory:SessionFactoryImplementor

The factory this context will service

Method Detail

buildCleanupSynchback to summary
private JTASessionContext.CleanupSync buildCleanupSynch(Object transactionIdentifier)

Builds a org.hibernate.context.internal.JTASessionContext.CleanupSync capable of cleaning up the the current session map as an after transaction callback.

Parameters
transactionIdentifier:Object

The transaction identifier under which the current session is registered.

Returns:JTASessionContext.CleanupSync

The cleanup synch.

buildOrObtainSessionback to summary
protected Session buildOrObtainSession()

Deprecated

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

Strictly provided for subclassing purposes; specifically to allow long-session support. This implementation always just opens a new session.

Returns:Session

the built or (re)obtained session.

Annotations
@SuppressWarnings:deprecation
currentSessionback to summary
public Session currentSession() throws HibernateException

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

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

Deprecated

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

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

Returns:Session

The current session.

Annotations
@Override
Exceptions
HibernateException:
Typically indicates an issue locating or creating the current session.
getConnectionReleaseModeback to summary
protected ConnectionReleaseMode getConnectionReleaseMode()

Mainly for subclass usage. This impl always returns after_statement.

Returns:ConnectionReleaseMode

The connection release mode for any built sessions.

isAutoCloseEnabledback to summary
protected boolean isAutoCloseEnabled()

Mainly for subclass usage. This impl always returns true.

Returns:boolean

Whether or not the the session should be closed by transaction completion.

isAutoFlushEnabledback to summary
protected boolean isAutoFlushEnabled()

Mainly for subclass usage. This impl always returns true.

Returns:boolean

Whether or not the the session should be flushed prior transaction completion.

org.hibernate.context.internal back to summary

protected Class JTASessionContext.CleanupSync

extends Object
implements Synchronization
Class Inheritance
All Implemented Interfaces
javax.transaction.Synchronization

JTA transaction sync used for cleanup of the internal session map.

Field Summary

Modifier and TypeField and Description
private JTASessionContext
private Object

Constructor Summary

AccessConstructor and Description
public
CleanupSync(Object transactionIdentifier, JTASessionContext context)

Method Summary

Modifier and TypeMethod and Description
public void
afterCompletion(int
The status of the transaction completion.
i
)

Implements javax.transaction.Synchronization.afterCompletion.

This method is called by the transaction manager after the transaction is committed or rolled back.
public void
beforeCompletion()

Implements javax.transaction.Synchronization.beforeCompletion.

The beforeCompletion method is called by the transaction manager prior to the start of the two-phase transaction commit process.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextback to summary
private JTASessionContext context
transactionIdentifierback to summary
private Object transactionIdentifier

Constructor Detail

CleanupSyncback to summary
public CleanupSync(Object transactionIdentifier, JTASessionContext context)

Method Detail

afterCompletionback to summary
public void afterCompletion(int i)

Implements javax.transaction.Synchronization.afterCompletion.

Doc from javax.transaction.Synchronization.afterCompletion.

This method is called by the transaction manager after the transaction is committed or rolled back.

Parameters
i:int

The status of the transaction completion.

Annotations
@Override
beforeCompletionback to summary
public void beforeCompletion()

Implements javax.transaction.Synchronization.beforeCompletion.

Doc from javax.transaction.Synchronization.beforeCompletion.

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.

Annotations
@Override