public class JTATransactionFactory extends java.lang.Object implements TransactionFactory
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.TransactionFactory.Context| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_USER_TRANSACTION_NAME |
protected javax.naming.InitialContext |
initialContext |
protected java.lang.String |
userTransactionName |
| Constructor and Description |
|---|
JTATransactionFactory() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
areCallbacksLocalToHibernateTransactions()
Are all transaction callbacks local to Hibernate Transactions?
Or can the callbacks originate from some other source (e.g.
|
void |
configure(java.util.Properties props)
Configure this transaction factory.
|
Transaction |
createTransaction(JDBCContext jdbcContext,
TransactionFactory.Context transactionContext)
Begin a transaction and return the associated Transaction instance.
|
ConnectionReleaseMode |
getDefaultReleaseMode()
Get the default connection release mode.
|
protected javax.naming.InitialContext |
getInitialContext()
Getter for property 'initialContext'.
|
protected javax.transaction.UserTransaction |
getUserTransaction()
Get the
UserTransaction reference. |
protected java.lang.String |
getUserTransactionName()
Getter for property 'userTransactionName'.
|
boolean |
isTransactionInProgress(JDBCContext jdbcContext,
TransactionFactory.Context transactionContext,
Transaction transaction)
Determine whether an underlying transaction is in progress.
|
boolean |
isTransactionManagerRequired()
Do we require access to the JTA TransactionManager for
this strategy?
|
protected javax.naming.InitialContext |
resolveInitialContext(java.util.Properties properties)
Given the lot of Hibernate configuration properties, resolve appropriate
reference to JNDI
InitialContext. |
protected java.lang.String |
resolveUserTransactionName(java.util.Properties properties)
Given the lot of Hibernate configuration properties, resolve appropriate
JNDI namespace to use for
UserTransaction resolution. |
public static final java.lang.String DEFAULT_USER_TRANSACTION_NAME
protected javax.naming.InitialContext initialContext
protected java.lang.String userTransactionName
public void configure(java.util.Properties props)
throws HibernateException
InitialContext as well as the
JNDI namespace for the UserTransaction.configure in interface TransactionFactoryprops - The configuration propertiesHibernateExceptionprotected final javax.naming.InitialContext resolveInitialContext(java.util.Properties properties)
InitialContext.
In general, the properties in which we are interested here all begin with
hibernate.jndi. Especially important depending on your
environment are hibernate.jndi.url and
hibernate.jndi.classproperties - The Hibernate config properties.protected final java.lang.String resolveUserTransactionName(java.util.Properties properties)
UserTransaction resolution.
We determine the namespace to use byjta.UserTransaction config propertyTransactionManagerLookup was indicated, use its
TransactionManagerLookup.getUserTransactionName()DEFAULT_USER_TRANSACTION_NAMEproperties - The Hibernate config properties.UserTransaction namespacepublic Transaction createTransaction(JDBCContext jdbcContext, TransactionFactory.Context transactionContext) throws HibernateException
createTransaction in interface TransactionFactoryjdbcContext - The jdbc context to which the transaction belongstransactionContext - The contract regarding the context in which this transaction will operate.HibernateException - Indicates a problem generating a transaction instanceprotected javax.transaction.UserTransaction getUserTransaction()
UserTransaction reference.UserTransaction reference.protected javax.naming.InitialContext getInitialContext()
protected java.lang.String getUserTransactionName()
public ConnectionReleaseMode getDefaultReleaseMode()
getDefaultReleaseMode in interface TransactionFactorypublic boolean isTransactionManagerRequired()
isTransactionManagerRequired in interface TransactionFactorypublic boolean areCallbacksLocalToHibernateTransactions()
areCallbacksLocalToHibernateTransactions in interface TransactionFactoryTransaction; false otherwise.public boolean isTransactionInProgress(JDBCContext jdbcContext, TransactionFactory.Context transactionContext, Transaction transaction)
isTransactionInProgress in interface TransactionFactoryjdbcContext - The JDBC contexttransactionContext - The transaction contexttransaction - The Hibernate transactionCopyright © 2013. All Rights Reserved.