Search in sources :

Example 1 with DataSource

use of org.teiid.test.framework.datasource.DataSource in project teiid by teiid.

the class ConnectionStrategy method createDriverConnection.

// protected void setupVDBConnectorBindings(Admin api) throws
// QueryTestFailedException {
// 
// try {
// 
// VDB vdb = null;
// Set<VDB> vdbs = api.getVDBs();
// if (vdbs == null || vdbs.isEmpty()) {
// throw new QueryTestFailedException(
// "AdminApi.GetVDBS returned no vdbs available");
// }
// 
// String urlString = this.env.getProperty(DriverConnection.DS_URL);
// JDBCURL url = new JDBCURL(urlString);
// TestLogger.logDebug("Trying to match VDB : " + url.getVDBName());
// 
// for (Iterator<VDB> iterator = vdbs.iterator(); iterator.hasNext();) {
// VDB v = (VDB) iterator.next();
// if (v.getName().equalsIgnoreCase(url.getVDBName())) {
// vdb = v;
// }
// 
// }
// if (vdbs == null) {
// throw new QueryTestFailedException(
// "GetVDBS did not return a vdb that matched "
// + url.getVDBName());
// }
// 
// List<Model> models = vdb.getModels();
// Iterator<Model> modelIt = models.iterator();
// while (modelIt.hasNext()) {
// Model m = modelIt.next();
// 
// if (!m.isSource())
// continue;
// 
// // get the mapping, if defined
// String mappedName = this.env.getProperty(m.getName());
// 
// String useName = m.getName();
// if (mappedName != null) {
// useName = mappedName;
// }
// 
// org.teiid.test.framework.datasource.DataSource ds =
// this.dsFactory.getDatasource(useName, m.getName());
// 
// if (ds != null) {
// 
// TestLogger.logInfo("Set up Connector Binding (model:mapping:type): " + m.getName() + ":" + useName + ":" + ds.getConnectorType()); //$NON-NLS-1$
// 
// api.addConnectorBinding(ds.getName(),ds.getConnectorType(),
// ds.getProperties());
// 
// api.assignBindingToModel(vdb.getName(), vdb.getVersion(), m.getName(),
// ds.getName(), ds.getProperty("jndi-name"));
// 
// api.startConnectorBinding(api.getConnectorBinding(ds.getName()));
// } else {
// throw new QueryTestFailedException(
// "Error: Unable to create binding to map to model : "
// + m.getName() + ", the mapped name "
// + useName
// + " had no datasource properties defined");
// }
// 
// }
// 
// } catch (QueryTestFailedException qt) {
// throw qt;
// } catch (Exception t) {
// t.printStackTrace();
// throw new QueryTestFailedException(t);
// }
// 
// 
// }
public synchronized Connection createDriverConnection(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);
    }
    Connection conn = ds.getConnection();
    if (conn != null)
        return conn;
    ConnectionStrategy cs = null;
    if (identifier == null) {
        cs = new DriverConnection(ds.getProperties());
    } else {
        cs = new DriverConnection(ds.getProperties());
    }
    // conn = cs.getConnection();
    // 
    // conn = (Connection) Proxy.newProxyInstance(Thread.currentThread()
    // .getContextClassLoader(),
    // new Class[] { java.sql.Connection.class },
    // new CloseInterceptor(conn));
    ds.setConnection(cs.getConnection());
    return ds.getConnection();
}
Also used : TransactionRuntimeException(org.teiid.test.framework.exception.TransactionRuntimeException) Connection(java.sql.Connection) XAConnection(javax.sql.XAConnection) DataSource(org.teiid.test.framework.datasource.DataSource)

Example 2 with DataSource

use of org.teiid.test.framework.datasource.DataSource 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)

Aggregations

XAConnection (javax.sql.XAConnection)2 DataSource (org.teiid.test.framework.datasource.DataSource)2 TransactionRuntimeException (org.teiid.test.framework.exception.TransactionRuntimeException)2 Connection (java.sql.Connection)1