use of org.teiid.adminapi.impl.ModelMetaData 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.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testFilterNull.
@Test
public void testFilterNull() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("vw");
mmd.addSourceMetadata("ddl", "create view x (a string primary key, b integer) as " + "select 'xyz', 123 union all " + "select 'abc', null;");
mmd.setModelType(Model.Type.VIRTUAL);
teiid.deployVDB("northwind", mmd);
Properties props = new Properties();
localClient = getClient(teiid.getDriver(), "northwind", props);
ContentResponse response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("b eq null"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"abc\",\"b\":null}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataIntegration method testIndexingOfStringFunctions.
@Test
public void testIndexingOfStringFunctions() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("vw");
mmd.addSourceMetadata("ddl", "create view x (a string primary key, b integer) as " + "select 'xyz', 123 union all select 'abc', 456;");
mmd.setModelType(Model.Type.VIRTUAL);
teiid.deployVDB("northwind", mmd);
Properties props = new Properties();
localClient = getClient(teiid.getDriver(), "northwind", props);
ContentResponse response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("indexof(a,'y') eq 1"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("indexof(a,'y') eq 2"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[]}", response.getContentAsString());
response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("substring(a,1) eq 'yz'"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("substring(a,1,2) eq 'yz'"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
response = http.GET(baseURL + "/northwind/vw/x?$filter=" + Encoder.encode("substring(a,0,1) eq 'a'"));
assertEquals(200, response.getStatus());
assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"abc\",\"b\":456}]}", response.getContentAsString());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.adminapi.impl.ModelMetaData 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.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestDataEntitySchemaBuilder method getNorthwindMetadataFromODataXML.
static TransformationMetadata getNorthwindMetadataFromODataXML() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("northwind.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return metadata;
}
Aggregations