Search in sources :

Example 6 with TransactionalDriver

use of com.arjuna.ats.jdbc.TransactionalDriver in project narayana by jbosstm.

the class TransactionServiceFactory method start.

/**
 * Makes the transaction service available by bind various transaction related object into the default
 * JNDI tree.
 * @param startRecoveryService set to true to start the recovery service.
 * @throws InitializationException if no usable InitialContext is available
 */
public static synchronized void start(boolean startRecoveryService) throws InitializationException {
    if (initialized)
        return;
    try {
        initialContext = new InitialContext();
        replacedJndiProperties = jdbcPropertyManager.getJDBCEnvironmentBean().getJndiProperties().size() == 0;
        if (replacedJndiProperties)
            jdbcPropertyManager.getJDBCEnvironmentBean().setJndiProperties(initialContext.getEnvironment());
        DriverManager.registerDriver(new TransactionalDriver());
    } catch (NamingException e) {
        if (tsLogger.logger.isInfoEnabled())
            tsLogger.logger.info("TransactionServiceFactory error:", e);
        throw new InitializationException("No suitable JNDI provider available", e);
    } catch (SQLException e) {
        if (tsLogger.logger.isInfoEnabled())
            tsLogger.logger.info("TransactionServiceFactory error:", e);
        throw new InitializationException("Cannot initialize TransactionalDriver", e);
    }
    registerJndiBindings(initialContext);
    initialized = true;
    if (startRecoveryService)
        startRecoveryService();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            TransactionServiceFactory.stop();
        }
    });
}
Also used : SQLException(java.sql.SQLException) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver)

Aggregations

TransactionalDriver (com.arjuna.ats.jdbc.TransactionalDriver)6 Properties (java.util.Properties)4 Driver (org.h2.Driver)4 SQLException (java.sql.SQLException)3 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)3 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)2 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)2 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)2 BMRule (org.jboss.byteman.contrib.bmunit.BMRule)2 Before (org.junit.Before)2 Test (org.junit.Test)2 PropertyFileDynamicClass (com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass)1 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 XAResource (javax.transaction.xa.XAResource)1