use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestConnectorWorkItem method testConversionError.
@Test
public void testConversionError() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<String> list1 = new ArrayList<String>();
list1.add("1");
List<String> list2 = new ArrayList<String>();
list2.add("a");
final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
ef.setCopyLobs(true);
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(-1, message.getFinalRow());
try {
cwi.more();
fail();
} catch (TranslatorException e) {
// should throw the conversion error
}
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestConnectorWorkItem method testUnmodifibleList.
@Test
public void testUnmodifibleList() throws Exception {
BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<String> list1 = Collections.singletonList("1");
final Iterator<List<String>> iter = Arrays.asList(list1).iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (iter.hasNext()) {
return iter.next();
}
return null;
}
};
}
};
ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
"FakeConnector") {
public ExecutionFactory getExecutionFactory() {
return ef;
}
public Object getConnectionFactory() {
return null;
}
};
cm.start();
AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
// $NON-NLS-1$
requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
requestMsg.setBufferManager(bm);
ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
cwi.execute();
AtomicResultsMessage message = cwi.more();
List[] results = message.getResults();
assertEquals(1, results.length);
List<?> tuple = results[0];
assertEquals(1, tuple.get(0));
assertEquals(1, message.getFinalRow());
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestDynamicImportedMetaData method testMultipleFK.
@Test
public void testMultipleFK() throws Exception {
ModelMetaData mmd = new ModelMetaData();
mmd.addSourceMetadata("ddl", "create foreign table x (y integer, z integer, primary key (y, z));" + "create foreign table z (y integer, z integer, y1 integer, z1 integer, foreign key (y, z) references x (y, z), foreign key (y1, z1) references x (y, z))");
mmd.setName("foo");
mmd.addSourceMapping("x", "x", "x");
server.addTranslator("x", new ExecutionFactory());
server.deployVDB("vdb", mmd);
// $NON-NLS-1$
Connection conn = server.createConnection("jdbc:teiid:vdb");
Properties importProperties = new Properties();
importProperties.setProperty("importer.importKeys", "true");
MetadataFactory mf = getMetadata(importProperties, conn);
Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
List<ForeignKey> fks = t.getForeignKeys();
assertEquals(2, fks.size());
}
use of org.teiid.translator.ExecutionFactory 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());
}
use of org.teiid.translator.ExecutionFactory in project teiid by teiid.
the class TestEmbeddedServer method testImportExcept.
@Ignore("limit to/exclude not yet implemented")
@Test
public void testImportExcept() throws Exception {
es.start(new EmbeddedConfiguration());
es.addMetadataRepository("x", new MetadataRepository() {
@Override
public void loadMetadata(MetadataFactory factory, ExecutionFactory executionFactory, Object connectionFactory, String text) throws TranslatorException {
assertEquals("helloworld1,other", factory.getModelProperties().get("importer.excludeTables"));
Table t = factory.addTable("helloworld");
t.setVirtual(true);
factory.addColumn("col", "string", t);
t.setSelectTransformation("select 'HELLO WORLD'");
}
});
String externalDDL = "CREATE DATABASE test VERSION '1';" + "USE DATABASE test VERSION '1';" + "CREATE VIRTUAL SCHEMA test2;" + "IMPORT FOREIGN SCHEMA public except (helloworld1, other) FROM REPOSITORY x INTO test2;";
es.deployVDB(new ByteArrayInputStream(externalDDL.getBytes(Charset.forName("UTF-8"))), true);
ResultSet rs = es.getDriver().connect("jdbc:teiid:test", null).createStatement().executeQuery("select * from helloworld");
rs.next();
assertEquals("HELLO WORLD", rs.getString(1));
}
Aggregations