use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testReverseNavigation.
@Test
public void testReverseNavigation() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
hc.addData("SELECT Customers.id, Customers.name FROM Customers", Arrays.asList(Arrays.asList(1, "customer1"), Arrays.asList(2, "customer2"), Arrays.asList(3, "customer3"), Arrays.asList(4, "customer4")));
hc.addData("SELECT Customers.id FROM Customers", Arrays.asList(Arrays.asList(1), Arrays.asList(2), Arrays.asList(3), Arrays.asList(4)));
hc.addData("SELECT Orders.id, Orders.customerid FROM Orders", Arrays.asList(Arrays.asList(1, 1), Arrays.asList(2, 1), Arrays.asList(3, 1), Arrays.asList(4, 1), Arrays.asList(5, 2), Arrays.asList(6, 2), Arrays.asList(7, 3), Arrays.asList(8, 3)));
hc.addData("SELECT Orders.id, Orders.customerid, Orders.place FROM Orders", Arrays.asList(Arrays.asList(1, 1, "town"), Arrays.asList(2, 1, "state"), Arrays.asList(3, 1, "country"), Arrays.asList(4, 1, "abroad"), Arrays.asList(5, 2, "state"), Arrays.asList(6, 2, "country"), Arrays.asList(7, 3, "town"), Arrays.asList(8, 3, "town")));
hc.addData("SELECT Orders.customerid, Orders.id, Orders.place FROM Orders", Arrays.asList(Arrays.asList(1, 1, "town"), Arrays.asList(1, 2, "state"), Arrays.asList(1, 3, "country"), Arrays.asList(1, 4, "abroad"), Arrays.asList(2, 5, "state"), Arrays.asList(2, 6, "country"), Arrays.asList(3, 7, "town"), Arrays.asList(3, 8, "town")));
teiid.addTranslator("x12", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "CREATE FOREIGN TABLE Customers (\n" + " id integer PRIMARY KEY OPTIONS (NAMEINSOURCE 'id'),\n" + " name varchar(10));\n" + "CREATE FOREIGN TABLE Orders (\n" + " id integer PRIMARY KEY OPTIONS (NAMEINSOURCE 'id'),\n" + " customerid integer,\n" + " place varchar(10),\n" + " CONSTRAINT Customer FOREIGN KEY (customerid) REFERENCES Customers(id));");
mmd.addSourceMapping("x12", "x12", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = null;
response = http.newRequest(baseURL + "/northwind/m/Orders(1)/Customer").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers/$entity\"," + "\"id\":1,\"name\":\"customer1\"}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Orders(1)?$expand=Customer").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Orders/$entity\"," + "\"id\":1,\"customerid\":1,\"place\":\"town\"," + "\"Customer\":{\"id\":1,\"name\":\"customer1\"}}", response.getContentAsString());
response = http.newRequest(baseURL + "/northwind/m/Orders(1)/Customer/Orders_Customer").method("GET").send();
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#Customers\"," + "\"value\":[{\"id\":1,\"customerid\":1,\"place\":\"town\"}," + "{\"id\":2,\"customerid\":1,\"place\":\"state\"}," + "{\"id\":3,\"customerid\":1,\"place\":\"country\"}," + "{\"id\":4,\"customerid\":1,\"place\":\"abroad\"}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testCheckGeneratedColumns.
@Test
public void testCheckGeneratedColumns() throws Exception {
HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {
@Override
public UpdateExecution createUpdateExecution(org.teiid.language.Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(new String[] { "a" }, new Class[] { String.class });
keys.addKey(Arrays.asList("ax"));
return super.createUpdateExecution(command, executionContext, metadata, connection);
}
@Override
public boolean supportsCompareCriteriaEquals() {
return true;
}
};
hc.addUpdate("INSERT INTO x (b, c) VALUES ('b', 5)", new int[] { 1 });
// this gets called right after insert.
hc.addData("SELECT x.a, x.b, x.c FROM x WHERE x.a = 'ax'", Arrays.asList(Arrays.asList("a", "b", 2)));
teiid.addTranslator("x", 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)) options (updatable true);");
mmd.addSourceMapping("x", "x", 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("{\"b\":\"b\", \"c\":5}"), "application/json").send();
assertEquals(201, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testArrayUpdateResults.
@Test
public void testArrayUpdateResults() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("UPDATE x SET b = (1, 2, 3) WHERE x.a = 'x'", new int[] { 1 });
teiid.addTranslator("x6", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("DDL", "create foreign table x (a string primary key, b integer[], c string[][]) OPTIONS (updatable true);");
mmd.setModelType(Model.Type.PHYSICAL);
mmd.addSourceMapping("x6", "x6", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x('x')").method("PATCH").content(new StringContentProvider("{\"a\":\"x\",\"b\":[1,2,3]}"), "application/json").send();
assertEquals(204, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestODataIntegration method testNavigationLinks.
@Test
public void testNavigationLinks() throws Exception {
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
hc.addUpdate("UPDATE y SET b = 'a' WHERE y.a = 'a'", new int[] { 1 });
teiid.addTranslator("x4", hc);
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMetadata("ddl", "create foreign table x (" + " a string, " + " b string, " + " primary key (a)" + ") options (updatable true);" + "create foreign table y (" + " a string, " + " b string, " + " primary key (a)," + " CONSTRAINT FKX FOREIGN KEY (b) REFERENCES x(a)" + ") options (updatable true);");
mmd.addSourceMapping("x4", "x4", null);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.newRequest(baseURL + "/northwind/m/x('a')/y_FKX/$ref").method("GET").send();
assertEquals(200, response.getStatus());
String url = baseURL + "/northwind/m/";
assertEquals("{\"@odata.context\":\"$metadata#Collection($ref)\"," + "\"value\":[{\"@odata.id\":\"" + url + "y('ABCDEFG')\"}]}", response.getContentAsString());
// update to collection based reference
String payload = "{\n" + "\"@odata.id\": \"/odata4/northwind/m/y('a')\"\n" + "}";
response = http.newRequest(baseURL + "/northwind/m/x('a')/y_FKX/$ref").method("POST").content(new StringContentProvider(payload), ContentType.APPLICATION_JSON.toString()).send();
assertEquals(204, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.runtime.HardCodedExecutionFactory in project teiid by teiid.
the class TestJDBCSocketPerformance method oneTimeSetup.
@BeforeClass
public static void oneTimeSetup() throws Exception {
SocketConfiguration config = new SocketConfiguration();
config.setSSLConfiguration(new SSLConfiguration());
addr = new InetSocketAddress(0);
config.setBindAddress(addr.getHostName());
config.setPortNumber(0);
EmbeddedConfiguration dqpConfig = new EmbeddedConfiguration();
dqpConfig.setMaxActivePlans(2);
server = new FakeServer(false);
server.start(dqpConfig);
ModelMetaData mmd = new ModelMetaData();
mmd.setName("x");
mmd.setModelType(Type.PHYSICAL);
mmd.addSourceMapping("x", "hc", null);
mmd.setSchemaSourceType("ddl");
StringBuffer ddl = new StringBuffer("create foreign table x (col0 string");
for (int i = 1; i < 10; i++) {
ddl.append(",").append(" col").append(i).append(" string");
}
ddl.append(");");
mmd.setSchemaText(ddl.toString());
server.addTranslator("hc", new HardCodedExecutionFactory() {
@Override
protected List<? extends List<?>> getData(QueryExpression command) {
List<List<String>> result = new ArrayList<List<String>>();
int size = command.getProjectedQuery().getDerivedColumns().size();
for (int i = 0; i < 64; i++) {
List<String> row = new ArrayList<String>(size);
for (int j = 0; j < size; j++) {
row.add("abcdefghi" + j);
}
result.add(row);
}
return result;
}
});
server.deployVDB("x", mmd);
jdbcTransport = new SocketListener(addr, config, server.getClientServiceRegistry(), BufferManagerFactory.getStandaloneBufferManager());
}
Aggregations