FileDocCategorySizeDatePackage
JTATransactionFactory.javaAPI DocHibernate 3.2.53741Thu Aug 24 10:07:04 BST 2006org.hibernate.transaction

JTATransactionFactory

public class JTATransactionFactory extends Object implements TransactionFactory
Factory for JTATransaction.
see
JTATransaction
author
Gavin King

Fields Summary
private static final Log
log
private static final String
DEFAULT_USER_TRANSACTION_NAME
protected InitialContext
context
protected String
utName
Constructors Summary
Methods Summary
public booleanareCallbacksLocalToHibernateTransactions()

		return false;
	
public voidconfigure(java.util.Properties props)


	      
		try {
			context = NamingHelper.getInitialContext(props);
		}
		catch (NamingException ne) {
			log.error("Could not obtain initial context", ne);
			throw new HibernateException( "Could not obtain initial context", ne );
		}

		utName = props.getProperty(Environment.USER_TRANSACTION);

		if (utName==null) {
			TransactionManagerLookup lookup = TransactionManagerLookupFactory.getTransactionManagerLookup(props);
			if (lookup!=null) utName = lookup.getUserTransactionName();
		}

		if (utName==null) utName = DEFAULT_USER_TRANSACTION_NAME;
	
public org.hibernate.TransactioncreateTransaction(org.hibernate.jdbc.JDBCContext jdbcContext, Context transactionContext)

		return new JTATransaction(context, utName, jdbcContext, transactionContext);
	
public org.hibernate.ConnectionReleaseModegetDefaultReleaseMode()

		return ConnectionReleaseMode.AFTER_STATEMENT;
	
public booleanisTransactionInProgress(org.hibernate.jdbc.JDBCContext jdbcContext, Context transactionContext, org.hibernate.Transaction transaction)

		try {
            // Essentially:
			// 1) If we have a local (Hibernate) transaction in progress
			//      and it already has the UserTransaction cached, use that
			//      UserTransaction to determine the status.
			// 2) If a transaction manager has been located, use
			//      that transaction manager to determine the status.
			// 3) Finally, as the last resort, try to lookup the
			//      UserTransaction via JNDI and use that to determine the
			//      status.
            if ( transaction != null ) {
				UserTransaction ut = ( ( JTATransaction ) transaction ).getUserTransaction();
                if ( ut != null ) {
                    return JTAHelper.isInProgress( ut.getStatus() );
                }
            }

            if ( jdbcContext.getFactory().getTransactionManager() != null ) {
                return JTAHelper.isInProgress( jdbcContext.getFactory().getTransactionManager().getStatus() );
            }
            else {
                try {
					UserTransaction ut = ( UserTransaction ) context.lookup( utName );
			        return ut != null && JTAHelper.isInProgress( ut.getStatus() );
				}
				catch ( NamingException ne ) {
					throw new TransactionException( "Unable to locate UserTransaction to check status", ne );
				}
            }
		}
		catch( SystemException se ) {
			throw new TransactionException( "Unable to check transaction status", se );
		}
	
public booleanisTransactionManagerRequired()

		return false;