org.hibernate.transaction

Class JTATransactionFactory

Implemented Interfaces:
TransactionFactory

public class JTATransactionFactory
extends java.lang.Object
implements 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(Properties). Hibernate will then attempt to locate the UserTransaction within this resolved InitialContext based on the namespace returned by resolveUserTransactionName(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.

Authors:
Gavin King
Steve Ebersole
Les Hazlewood

Field Summary

static String
DEFAULT_USER_TRANSACTION_NAME
protected InitialContext
initialContext
protected String
userTransactionName

Method Summary

boolean
areCallbacksLocalToHibernateTransactions()
void
configure(Properties props)
Configure this transaction factory.
Transaction
createTransaction(JDBCContext jdbcContext, Context transactionContext)
ConnectionReleaseMode
getDefaultReleaseMode()
protected InitialContext
getInitialContext()
Getter for property 'initialContext'.
protected UserTransaction
getUserTransaction()
Get the UserTransaction reference.
protected String
getUserTransactionName()
Getter for property 'userTransactionName'.
boolean
isTransactionInProgress(JDBCContext jdbcContext, Context transactionContext, Transaction transaction)
boolean
isTransactionManagerRequired()
protected InitialContext
resolveInitialContext(Properties properties)
Given the lot of Hibernate configuration properties, resolve appropriate reference to JNDI InitialContext.
protected String
resolveUserTransactionName(Properties properties)
Given the lot of Hibernate configuration properties, resolve appropriate JNDI namespace to use for UserTransaction resolution.

Field Details

DEFAULT_USER_TRANSACTION_NAME

public static final String DEFAULT_USER_TRANSACTION_NAME

initialContext

protected InitialContext initialContext

userTransactionName

protected String userTransactionName

Method Details

areCallbacksLocalToHibernateTransactions

public boolean areCallbacksLocalToHibernateTransactions()
Specified by:
areCallbacksLocalToHibernateTransactions in interface TransactionFactory

configure

public void configure(Properties props)
            throws HibernateException
Configure this transaction factory. Specifically here we are attempting to resolve both an InitialContext as well as the JNDI namespace for the UserTransaction.
Specified by:
configure in interface TransactionFactory
Parameters:
props - The configuration properties

createTransaction

public Transaction createTransaction(JDBCContext jdbcContext,
                                     Context transactionContext)
            throws HibernateException

getDefaultReleaseMode

public ConnectionReleaseMode getDefaultReleaseMode()
Specified by:
getDefaultReleaseMode in interface TransactionFactory

getInitialContext

protected InitialContext getInitialContext()
Getter for property 'initialContext'.
Returns:
Value for property 'initialContext'.

getUserTransaction

protected UserTransaction getUserTransaction()
Get the UserTransaction reference.
Returns:
The appropriate UserTransaction reference.

getUserTransactionName

protected String getUserTransactionName()
Getter for property 'userTransactionName'. The algorithm here is
Returns:
Value for property 'userTransactionName'.

isTransactionInProgress

public boolean isTransactionInProgress(JDBCContext jdbcContext,
                                       Context transactionContext,
                                       Transaction transaction)

isTransactionManagerRequired

public boolean isTransactionManagerRequired()
Specified by:
isTransactionManagerRequired in interface TransactionFactory

resolveInitialContext

protected final InitialContext resolveInitialContext(Properties properties)
Parameters:
properties - The Hibernate config properties.
Returns:
The resolved InitialContext.

resolveUserTransactionName

protected final String resolveUserTransactionName(Properties properties)
Parameters:
properties - The Hibernate config properties.
Returns:
The resolved UserTransaction namespace