Search in sources :

Example 1 with TeiidExecutionFactory

use of org.teiid.translator.jdbc.teiid.TeiidExecutionFactory in project teiid by teiid.

the class TestDynamicImportedMetaData method getMetadata.

private MetadataFactory getMetadata(Properties importProperties, Connection conn) throws TranslatorException {
    MetadataFactory mf = createMetadataFactory("test", importProperties);
    TeiidExecutionFactory tef = new TeiidExecutionFactory();
    tef.getMetadata(mf, conn);
    return mf;
}
Also used : TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) MetadataFactory(org.teiid.metadata.MetadataFactory)

Example 2 with TeiidExecutionFactory

use of org.teiid.translator.jdbc.teiid.TeiidExecutionFactory in project teiid by teiid.

the class TestDynamicImportedMetaData method testMultiSource.

@Test
public void testMultiSource() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    TeiidExecutionFactory tef = new TeiidExecutionFactory() {

        @Override
        public void closeConnection(Connection connection, DataSource factory) {
        }
    };
    tef.setSupportsDirectQueryProcedure(true);
    tef.start();
    server.addTranslator("teiid", tef);
    DataSource ds = Mockito.mock(DataSource.class);
    Mockito.stub(ds.getConnection()).toReturn(server.getDriver().connect("jdbc:teiid:vdb", null));
    server.addConnectionFactory("teiid1", ds);
    server.addConnectionFactory("teiid2", ds);
    server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("multi.xml")));
    Connection c = server.createConnection("jdbc:teiid:multi", null);
    Statement s = c.createStatement();
    s.execute("call native('select ?', 'b')");
    ResultSet rs = s.getResultSet();
    assertTrue(rs.next());
    assertTrue(rs.next());
    assertFalse(rs.next());
    s.execute("call native(request=>'select ?', variable=>('b',), target=>'teiid1')");
    rs = s.getResultSet();
    assertTrue(rs.next());
    Object[] result = (Object[]) rs.getArray(1).getArray();
    assertArrayEquals(new Object[] { "b" }, result);
    assertFalse(rs.next());
}
Also used : TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) FileInputStream(java.io.FileInputStream) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 3 with TeiidExecutionFactory

use of org.teiid.translator.jdbc.teiid.TeiidExecutionFactory in project teiid by teiid.

the class TestDynamicImportedMetaData method testMultiSourceImportError.

@Test
public void testMultiSourceImportError() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer primary key);");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    TeiidExecutionFactory tef = new TeiidExecutionFactory() {

        @Override
        public void closeConnection(Connection connection, DataSource factory) {
        }
    };
    tef.start();
    server.addTranslator("teiid", tef);
    DataSource ds = Mockito.mock(DataSource.class);
    Connection c = server.getDriver().connect("jdbc:teiid:vdb", null);
    // bad databasemetadata
    DatabaseMetaData dbmd = (DatabaseMetaData) SimpleMock.createSimpleMock(new Object[] { new BadMetadata(), c.getMetaData() }, new Class[] { DatabaseMetaData.class });
    Connection mock = Mockito.mock(Connection.class);
    Mockito.stub(mock.getMetaData()).toReturn(dbmd);
    Mockito.stub(ds.getConnection()).toReturn(mock);
    DataSource ds1 = Mockito.mock(DataSource.class);
    Mockito.stub(ds1.getConnection()).toReturn(server.getDriver().connect("jdbc:teiid:vdb", null));
    server.addConnectionFactory("teiid1", ds);
    server.addConnectionFactory("teiid2", ds1);
    server.deployVDB(new FileInputStream(UnitTestUtil.getTestDataFile("multi.xml")));
}
Also used : TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Connection(java.sql.Connection) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) DatabaseMetaData(java.sql.DatabaseMetaData) FileInputStream(java.io.FileInputStream) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Aggregations

TeiidExecutionFactory (org.teiid.translator.jdbc.teiid.TeiidExecutionFactory)3 FileInputStream (java.io.FileInputStream)2 Connection (java.sql.Connection)2 DataSource (javax.sql.DataSource)2 Test (org.junit.Test)2 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)2 ExecutionFactory (org.teiid.translator.ExecutionFactory)2 OracleExecutionFactory (org.teiid.translator.jdbc.oracle.OracleExecutionFactory)2 DatabaseMetaData (java.sql.DatabaseMetaData)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 MetadataFactory (org.teiid.metadata.MetadataFactory)1