use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestMatViews method testInternalWriteThroughMativew.
@Test
public void testInternalWriteThroughMativew() throws Exception {
ModelMetaData mmd2 = new ModelMetaData();
mmd2.setName("m");
mmd2.setModelType(Type.PHYSICAL);
mmd2.addSourceMapping("x", "x", null);
mmd2.addSourceMetadata("DDL", "CREATE foreign TABLE t (col string, colx string) options (updatable true); " + "CREATE VIEW v1 (col1 string, col2 string, primary key (col1)) " + "OPTIONS (updatable true, MATERIALIZED true, \"teiid_rel:MATVIEW_WRITE_THROUGH\" true) AS /*+ cache(updatable) */ select col, colx from t;");
HardCodedExecutionFactory hcef = new HardCodedExecutionFactory() {
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hcef.addData("SELECT t.col, t.colx FROM t", Arrays.asList(Arrays.asList("a", "ax")));
hcef.addData("SELECT t.col, t.colx FROM t WHERE t.col = 'b'", Arrays.asList(Arrays.asList("b", "d")));
hcef.addUpdate("INSERT INTO t (col, colx) VALUES ('b', 'd')", new int[] { 1 });
server.addTranslator("x", hcef);
server.deployVDB("comp", mmd2);
Connection c = server.getDriver().connect("jdbc:teiid:comp", null);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select * from v1");
rs.next();
assertEquals("a", rs.getString(1));
s.execute("insert into v1 (col1, col2) values ('b', 'd')");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(2, rs.getInt(1));
hcef.addUpdate("DELETE FROM t WHERE t.col = 'b'", new int[] { 1 });
hcef.addData("SELECT t.col, t.colx FROM t WHERE t.col = 'b'", new ArrayList<List<?>>());
s.execute("delete from v1 where v1.col1 = 'b'");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select count(*) from v1");
rs.next();
assertEquals(1, rs.getInt(1));
hcef.addUpdate("UPDATE t SET colx = 'bx' WHERE t.colx = 'ax'", new int[] { 1 });
hcef.addData("SELECT t.col, t.colx FROM t WHERE t.col = 'a'", Arrays.asList(Arrays.asList("a", "ax")));
s.execute("update v1 set col2 = 'bx' where col2 = 'ax'");
assertEquals(1, s.getUpdateCount());
rs = s.executeQuery("select col2, col1 from v1");
rs.next();
assertEquals("ax", rs.getString(1));
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testCompositeKeyTimestamp.
@Test
public void testCompositeKeyTimestamp() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addData("SELECT x.a, x.b, x.c FROM x WHERE x.a = 'a' AND x.b = {ts '2011-09-11T00:00:00'}", Arrays.asList(Arrays.asList("a", TimestampUtil.createTimestamp(111, 8, 11, 0, 0, 0, 0), 1)));
hc.addUpdate("INSERT INTO x (a, b) VALUES ('b', {ts '2000-02-02 22:22:22.0'})", new int[] { 1 });
teiid.addTranslator("x1", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b timestamp, c integer, " + "primary key (a, b)) options (updatable true);");
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("POST").content(new StringContentProvider("{\"a\":\"b\", \"b\":\"2000-02-02T22:22:22Z\"}"), "application/json").send();
assertEquals(201, response.getStatus());
response = http.newRequest(baseURL + "/northwind/m/x(a='a',b=2011-09-11T00:00:00Z)").method("GET").send();
assertEquals(200, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testPutFailure.
@Test
public void testPutFailure() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
teiid.addTranslator("x1", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (a string, b string, c integer, " + "primary key (a, b)) options (updatable true);");
mmd.addSourceMapping("x1", "x1", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
localClient.setThrowUpdateException(true);
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x(a='a',b='b')").method("PUT").content(new StringContentProvider("{\"a\":\"a\", \"b\":\"b\", \"c\":5}"), "application/json").send();
assertEquals(500, response.getStatus());
assertTrue(localClient.isRollback());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testExpandComplexSelf.
@Test
public void testExpandComplexSelf() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("SELECT tree.a, tree.b, tree.c FROM tree", Arrays.asList(Arrays.asList("1", "null", "x"), Arrays.asList("2", "1", "y"), Arrays.asList("3", "1", "z")));
hc.addData("SELECT tree.b, tree.a, tree.c FROM tree", Arrays.asList(Arrays.asList("null", "1", "x"), Arrays.asList("1", "2", "y"), Arrays.asList("1", "3", "z")));
teiid.addTranslator("x7", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table tree (" + " a string, " + " b string, " + " c string, " + " primary key (a)," + " CONSTRAINT parent FOREIGN KEY (b) REFERENCES tree(a)" + ");");
mmd.addSourceMapping("x7", "x7", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = null;
response = http.newRequest(baseURL + "/northwind/m/tree?$expand=tree_parent($filter=$it/c%20eq%20%27x%27)").method("GET").send();
assertEquals(response.getContentAsString(), 200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#tree\",\"value\":[" + "{\"a\":\"1\",\"b\":\"null\",\"c\":\"x\",\"tree_parent\":[{\"a\":\"2\",\"b\":\"1\",\"c\":\"y\"},{\"a\":\"3\",\"b\":\"1\",\"c\":\"z\"}]}," + "{\"a\":\"2\",\"b\":\"1\",\"c\":\"y\",\"tree_parent\":[]}," + "{\"a\":\"3\",\"b\":\"1\",\"c\":\"z\",\"tree_parent\":[]}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/tree?$expand=parent($filter=$it/c%20eq%20%27x%27)").method("GET").send();
assertEquals(response.getContentAsString(), 200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#tree\",\"value\":[{\"a\":\"1\",\"b\":\"null\",\"c\":\"x\",\"parent\":null}," + "{\"a\":\"2\",\"b\":\"1\",\"c\":\"y\",\"parent\":null}," + "{\"a\":\"3\",\"b\":\"1\",\"c\":\"z\",\"parent\":null}]}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/tree?$expand=parent($filter=$it/c%20eq%20%27y%27)").method("GET").send();
assertEquals(response.getContentAsString(), 200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#tree\",\"value\":[{\"a\":\"1\",\"b\":\"null\",\"c\":\"x\",\"parent\":null}," + "{\"a\":\"2\",\"b\":\"1\",\"c\":\"y\",\"parent\":{\"a\":\"1\",\"b\":\"null\",\"c\":\"x\"}}," + "{\"a\":\"3\",\"b\":\"1\",\"c\":\"z\",\"parent\":null}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testJsonProcedureResultSet.
@Test
public void testJsonProcedureResultSet() throws Exception {
try {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("EXEC x()", Arrays.asList(Arrays.asList("x"), Arrays.asList("y")));
teiid.addTranslator("x2", hc);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign procedure x () returns table(y string) OPTIONS(UPDATECOUNT 0);");
mmd.addSourceMapping("x2", "x2", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.GET(baseURL + "/northwind/m/x()?$format=json");
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Collection(northwind.1.m.x_RSParam)\"," + "\"value\":[{\"y\":\"x\"},{\"y\":\"y\"}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
Aggregations