Package org.hibernate.transaction
Class JTATransactionFactory
java.lang.Object
org.hibernate.transaction.JTATransactionFactory
- All Implemented Interfaces:
TransactionFactory
Factory for
JTATransaction instances.
To be completely accurate to the JTA spec, JTA implementations should
publish their contextual UserTransaction reference into JNDI.
However, in practice there are quite a few stand-alone
implementations intended for use outside of J2EE/JEE containers and
which therefore do not publish their UserTransaction references
into JNDI but which otherwise follow the aspects of the JTA specification.
This TransactionFactory implementation can support both models.
For complete JTA implementations (including dependence on JNDI), the
UserTransaction reference is obtained by a call to
resolveInitialContext(java.util.Properties). Hibernate will then attempt to locate the
UserTransaction within this resolved
InitialContext based on the namespace returned by
resolveUserTransactionName(java.util.Properties).
For the so-called stand-alone implementations, we do not care at
all about the JNDI aspects just described. Here, the implementation would
have a specific manner to obtain a reference to its contextual
UserTransaction; usually this would be a static code reference, but
again it varies. Anyway, for each implementation the integration would need
to override the getUserTransaction() method and return the appropriate
thing.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.hibernate.transaction.TransactionFactory
TransactionFactory.Context -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAre all transaction callbacks local to Hibernate Transactions? Or can the callbacks originate from some other source (e.g.voidconfigure(Properties props) Configure this transaction factory.createTransaction(JDBCContext jdbcContext, TransactionFactory.Context transactionContext) Begin a transaction and return the associated Transaction instance.Get the default connection release mode.protected InitialContextGetter for property 'initialContext'.protected UserTransactionGet theUserTransactionreference.protected StringGetter for property 'userTransactionName'.booleanisTransactionInProgress(JDBCContext jdbcContext, TransactionFactory.Context transactionContext, Transaction transaction) Determine whether an underlying transaction is in progress.booleanDo we require access to the JTA TransactionManager for this strategy?protected final InitialContextresolveInitialContext(Properties properties) Given the lot of Hibernate configuration properties, resolve appropriate reference to JNDIInitialContext.protected final StringresolveUserTransactionName(Properties properties) Given the lot of Hibernate configuration properties, resolve appropriate JNDI namespace to use forUserTransactionresolution.
-
Field Details
-
DEFAULT_USER_TRANSACTION_NAME
- See Also:
-
initialContext
-
userTransactionName
-
-
Constructor Details
-
JTATransactionFactory
public JTATransactionFactory()
-
-
Method Details
-
configure
Configure this transaction factory. Specifically here we are attempting to resolve both anInitialContextas well as theJNDI namespacefor theUserTransaction.- Specified by:
configurein interfaceTransactionFactory- Parameters:
props- The configuration properties- Throws:
HibernateException
-
resolveInitialContext
Given the lot of Hibernate configuration properties, resolve appropriate reference to JNDIInitialContext. In general, the properties in which we are interested here all begin with hibernate.jndi. Especially important depending on your environment arehibernate.jndi.urlandhibernate.jndi.class- Parameters:
properties- The Hibernate config properties.- Returns:
- The resolved InitialContext.
-
resolveUserTransactionName
Given the lot of Hibernate configuration properties, resolve appropriate JNDI namespace to use forUserTransactionresolution. We determine the namespace to use by- Any specified
jta.UserTransactionconfig property - If a
TransactionManagerLookupwas indicated, use itsTransactionManagerLookup.getUserTransactionName() - finally, as a last resort, we use
DEFAULT_USER_TRANSACTION_NAME
- Parameters:
properties- The Hibernate config properties.- Returns:
- The resolved
UserTransactionnamespace
- Any specified
-
createTransaction
public Transaction createTransaction(JDBCContext jdbcContext, TransactionFactory.Context transactionContext) throws HibernateException Begin a transaction and return the associated Transaction instance.- Specified by:
createTransactionin interfaceTransactionFactory- Parameters:
jdbcContext- The jdbc context to which the transaction belongstransactionContext- The contract regarding the context in which this transaction will operate.- Returns:
- Transaction
- Throws:
HibernateException- Indicates a problem generating a transaction instance
-
getUserTransaction
Get theUserTransactionreference.- Returns:
- The appropriate
UserTransactionreference.
-
getInitialContext
Getter for property 'initialContext'.- Returns:
- Value for property 'initialContext'.
-
getUserTransactionName
Getter for property 'userTransactionName'. The algorithm here is- Returns:
- Value for property 'userTransactionName'.
-
getDefaultReleaseMode
Get the default connection release mode.- Specified by:
getDefaultReleaseModein interfaceTransactionFactory- Returns:
- The default release mode associated with this strategy
-
isTransactionManagerRequired
public boolean isTransactionManagerRequired()Do we require access to the JTA TransactionManager for this strategy?- Specified by:
isTransactionManagerRequiredin interfaceTransactionFactory- Returns:
- True if this strategy requires access to the JTA TransactionManager; false otherwise.
-
areCallbacksLocalToHibernateTransactions
public boolean areCallbacksLocalToHibernateTransactions()Are all transaction callbacks local to Hibernate Transactions? Or can the callbacks originate from some other source (e.g. a JTA Synchronization).- Specified by:
areCallbacksLocalToHibernateTransactionsin interfaceTransactionFactory- Returns:
- true if callbacks only ever originate from the Hibernate
Transaction; false otherwise.
-
isTransactionInProgress
public boolean isTransactionInProgress(JDBCContext jdbcContext, TransactionFactory.Context transactionContext, Transaction transaction) Determine whether an underlying transaction is in progress. Mainly this is used in determining whether to register a synchronization as well as whether or not to circumvent auto flushing outside transactions.- Specified by:
isTransactionInProgressin interfaceTransactionFactory- Parameters:
jdbcContext- The JDBC contexttransactionContext- The transaction contexttransaction- The Hibernate transaction- Returns:
- true if an underlying transaction is know to be in effect.
-