Search in sources :

Example 16 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class TransactionContainer method runTransaction.

public void runTransaction(TransactionQueryTestCase test) {
    this.testClassName = StringUtil.getLastToken(test.getClass().getName(), ".");
    try {
        debug("Start transaction test: " + test.getTestName());
        try {
            test.setup();
        } catch (TransactionRuntimeException tre) {
            if (!test.exceptionExpected()) {
                tre.printStackTrace();
            }
            throw tre;
        } catch (Throwable e) {
            if (!test.exceptionExpected()) {
                e.printStackTrace();
            }
            throw new TransactionRuntimeException(e.getMessage());
        }
        runTest(test);
        debug("Completed transaction test: " + test.getTestName());
    } finally {
        debug("	test.cleanup");
        test.cleanup();
    }
}
Also used : TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Example 17 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class ConnectionStrategy method createDataSourceConnection.

public synchronized XAConnection createDataSourceConnection(String identifier) throws QueryTestFailedException {
    DataSource ds = null;
    if (identifier != null) {
        ds = DataSourceMgr.getInstance().getDataSource(identifier);
    }
    if (ds == null) {
        throw new TransactionRuntimeException("Program Error: DataSource is not mapped to Identifier " + identifier);
    }
    XAConnection conn = ds.getXAConnection();
    if (conn != null)
        return conn;
    ConnectionStrategy cs = null;
    if (identifier == null) {
        cs = new DataSourceConnection(ds.getProperties());
    } else {
        cs = new DataSourceConnection(ds.getProperties());
    }
    // conn = cs.getXAConnection();
    // 
    // conn = (XAConnection) Proxy.newProxyInstance(Thread.currentThread()
    // .getContextClassLoader(),
    // new Class[] { javax.sql.XAConnection.class },
    // new CloseInterceptor(conn));
    ds.setXAConnection(cs.getXAConnection());
    return ds.getXAConnection();
}
Also used : TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) DataSource(org.teiid.test.framework.datasource.DataSource) XAConnection(javax.sql.XAConnection)

Example 18 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class ConnectionStrategyFactory method createConnectionStrategy.

public static ConnectionStrategy createConnectionStrategy() {
    ConfigPropertyLoader configLoader = ConfigPropertyLoader.getInstance();
    ConnectionStrategy strategy = null;
    Properties props = configLoader.getProperties();
    String type = props.getProperty(ConfigPropertyNames.CONNECTION_TYPE, ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION);
    if (type == null) {
        throw new TransactionRuntimeException("Property " + ConfigPropertyNames.CONNECTION_TYPE + " was specified");
    }
    try {
        if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DRIVER_CONNECTION)) {
            // pass in null to create new strategy
            strategy = new DriverConnection(props);
            TestLogger.logDebug("Created Driver Strategy");
        } else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.DATASOURCE_CONNECTION)) {
            strategy = new DataSourceConnection(props);
            TestLogger.logDebug("Created DataSource Strategy");
        } else if (type.equalsIgnoreCase(ConfigPropertyNames.CONNECTION_TYPES.JNDI_CONNECTION)) {
            strategy = new JEEConnection(props);
            TestLogger.logDebug("Created JEE Strategy");
        }
        if (strategy == null) {
            new TransactionRuntimeException("Invalid property value for " + ConfigPropertyNames.CONNECTION_TYPE + " is " + type);
        }
        // call configure here because this is creating the connection to Teiid
        // direct connections to the datasource use the static call directly to create strategy and don't need to configure
        strategy.configure();
        return strategy;
    } catch (Exception e) {
        throw new TransactionRuntimeException(e);
    }
}
Also used : ConfigPropertyLoader(org.teiid.test.framework.ConfigPropertyLoader) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) Properties(java.util.Properties) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Example 19 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class DriverConnection method validate.

public void validate() {
    String urlProp = this.getEnvironment().getProperty(DS_URL);
    if (urlProp == null || urlProp.length() == 0) {
        throw new TransactionRuntimeException("Property " + DS_URL + " was not specified");
    }
    StringBuffer urlSB = new StringBuffer(urlProp);
    String appl = this.getEnvironment().getProperty(DS_APPLICATION_NAME);
    if (appl != null) {
        urlSB.append(";");
        urlSB.append("ApplicationName").append("=").append(appl);
    }
    url = urlSB.toString();
    driver = this.getEnvironment().getProperty(DS_DRIVER);
    if (driver == null || driver.length() == 0) {
        throw new TransactionRuntimeException("Property " + DS_DRIVER + " was not specified");
    }
    // need both user variables because Teiid uses 'user' and connectors use
    // 'username'
    this.username = this.getEnvironment().getProperty(DS_USER);
    if (username == null) {
        this.username = this.getEnvironment().getProperty(DS_USERNAME);
    }
    this.pwd = this.getEnvironment().getProperty(DS_PASSWORD);
    try {
        // Load jdbc driver
        Class.forName(driver);
    } catch (ClassNotFoundException e) {
        throw new TransactionRuntimeException(e);
    }
}
Also used : TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Example 20 with TransactionRuntimeException

use of org.teiid.test.framework.exception.TransactionRuntimeException in project teiid by teiid.

the class DataSourceMgr method getDataSource.

@SuppressWarnings("deprecation")
public DataSource getDataSource(String modelname) {
    if (modelToDatasourceMap.containsKey(modelname)) {
        return modelToDatasourceMap.get(modelname);
    }
    try {
        DataSource ds = dsfactory.getDatasource(modelname);
        if (ds == null) {
            printAllDatasources();
            try {
                Thread.sleep(100000);
            } catch (InterruptedException e) {
            }
            Thread.currentThread().getThreadGroup().stop();
        // throw new QueryTestFailedException(
        // "Unable to assign a datasource for model "
        // + modelname );
        }
        modelToDatasourceMap.put(modelname, ds);
        return ds;
    } catch (QueryTestFailedException e) {
        throw new TransactionRuntimeException(e);
    }
}
Also used : QueryTestFailedException(org.teiid.test.framework.exception.QueryTestFailedException) TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException)

Aggregations

TransactionRuntimeException (org.teiid.test.framework.exception.TransactionRuntimeException)26 QueryTestFailedException (org.teiid.test.framework.exception.QueryTestFailedException)5 XAResource (javax.transaction.xa.XAResource)4 File (java.io.File)3 Properties (java.util.Properties)3 ConfigPropertyLoader (org.teiid.test.framework.ConfigPropertyLoader)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 XAConnection (javax.sql.XAConnection)2 TransactionContainer (org.teiid.test.framework.TransactionContainer)2 DataSource (org.teiid.test.framework.datasource.DataSource)2 InputStream (java.io.InputStream)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 Collection (java.util.Collection)1 InitialContext (javax.naming.InitialContext)1 Element (org.jdom.Element)1 JDOMException (org.jdom.JDOMException)1 JNDITransaction (org.teiid.test.framework.transaction.JNDITransaction)1 LocalTransaction (org.teiid.test.framework.transaction.LocalTransaction)1