use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class ConnectorHost method executeCommand.
public List executeCommand(String query, boolean close) throws TranslatorException {
Command command = getCommand(query);
RuntimeMetadata runtimeMetadata = getRuntimeMetadata();
return executeCommand(command, runtimeMetadata, close);
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestODataIntegration method testErrorCodes.
@Test
public void testErrorCodes() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public ResultSetExecution createResultSetExecution(final QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
List<? extends List<?>> list = getData(command);
if (list == null) {
throw new RuntimeException(command.toString());
}
final Iterator<? extends List<?>> result = list.iterator();
return new ResultSetExecution() {
@Override
public void execute() throws TranslatorException {
throw new TranslatorException(ODataPlugin.Event.TEIID16001, "execution failed");
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (result.hasNext()) {
return result.next();
}
return null;
}
};
}
};
hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("a", 1)));
teiid.addTranslator("x1", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b integer, primary key (a));");
mmd.addSourceMapping("x1", "x1", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("GET").send();
assertEquals(400, response.getStatus());
assertEquals("{\"error\":{\"code\":\"TEIID30504\"," + "\"message\":\"TEIID30504 x1: TEIID16001 execution failed\"}}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/x?$format=xml").method("GET").send();
assertEquals(400, response.getStatus());
assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + "<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">" + "<code>TEIID30504</code>" + "<message>TEIID30504 x1: TEIID16001 execution failed</message>" + "</error>", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestEmbeddedServer method testQueryTimeout.
@Test
public void testQueryTimeout() throws Exception {
es.start(new EmbeddedConfiguration());
es.addTranslator("foo", new ExecutionFactory() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
}
return super.createResultSetExecution(command, executionContext, metadata, connection);
}
});
es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:test", null);
Statement s = c.createStatement();
s.setQueryTimeout(1);
try {
s.execute("select * from x");
fail();
} catch (SQLException e) {
assertEquals(SQLStates.QUERY_CANCELED, e.getSQLState());
}
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestEmbeddedServer method testSourceLobUnderTxn.
@Test
public void testSourceLobUnderTxn() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
ec.setMaxResultSetCacheStaleness(0);
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
ec.setUseDisk(false);
es.start(ec);
final AtomicBoolean closed = new AtomicBoolean();
es.addTranslator("foo", new ExecutionFactory() {
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
return new ResultSetExecution() {
private boolean returned;
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
closed.set(true);
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public List<?> next() throws TranslatorException, DataNotAvailableException {
if (returned) {
return null;
}
returned = true;
ArrayList<Object> result = new ArrayList<Object>(1);
result.add(new SQLXMLImpl(new InputStreamFactory() {
@Override
public InputStream getInputStream() throws IOException {
// need to make it of a sufficient size to not be inlined
return new ByteArrayInputStream(new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1]);
}
}));
return result;
}
};
}
});
es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
Connection c = es.getDriver().connect("jdbc:teiid:test", null);
c.setAutoCommit(false);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from x");
rs.next();
assertFalse(closed.get());
s.close();
assertTrue(closed.get());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestEmbeddedServer method testDynamicUpdate.
@Test
public void testDynamicUpdate() throws Exception {
EmbeddedConfiguration ec = new EmbeddedConfiguration();
MockTransactionManager tm = new MockTransactionManager();
ec.setTransactionManager(tm);
ec.setUseDisk(false);
es.start(ec);
es.addTranslator("t", new ExecutionFactory<Void, Void>() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
@Override
public boolean isSourceRequired() {
return false;
}
@Override
public UpdateExecution createUpdateExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
Collection<Literal> values = CollectorVisitor.collectObjects(Literal.class, command);
assertEquals(2, values.size());
for (Literal literal : values) {
assertFalse(literal.getValue() instanceof Reference);
}
return new UpdateExecution() {
@Override
public void execute() throws TranslatorException {
}
@Override
public void close() {
}
@Override
public void cancel() throws TranslatorException {
}
@Override
public int[] getUpdateCounts() throws DataNotAvailableException, TranslatorException {
return new int[] { 1 };
}
};
}
});
ModelMetaData mmd1 = new ModelMetaData();
mmd1.setName("accounts");
mmd1.setSchemaSourceType("ddl");
mmd1.setSchemaText(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("dynamic_update.sql")));
mmd1.addSourceMapping("y", "t", null);
es.deployVDB("vdb", mmd1);
Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
PreparedStatement ps = c.prepareStatement("update hello1 set SchemaName=? where Name=?");
ps.setString(1, "test1223");
ps.setString(2, "Columns");
assertEquals(1, ps.executeUpdate());
}
Aggregations