Search in sources :

Example 11 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestODataIntegration method testExpandSimple2.

@Test
public void testExpandSimple2() throws Exception {
    HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
    hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("xa1", "xb"), Arrays.asList("xa2", "xb2")));
    hc.addData("SELECT y.b, y.a FROM y", Arrays.asList(Arrays.asList("xa1", "ya1"), Arrays.asList("xa1", "ya2")));
    teiid.addTranslator("x7", 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);" + "create foreign table z (" + " a string, " + " b string, " + " primary key (a)," + " CONSTRAINT FKX FOREIGN KEY (a) REFERENCES x(a)" + ") options (updatable true);");
        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/x?$expand=" + Encoder.encode("y_FKX($filter=b eq 'xa1')")).method("GET").send();
        assertEquals(200, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x\"," + "\"value\":[" + "{\"a\":\"xa1\",\"b\":\"xb\"," + "\"y_FKX\":[{\"a\":\"ya1\",\"b\":\"xa1\"}," + "{\"a\":\"ya2\",\"b\":\"xa1\"}]}," + "{\"a\":\"xa2\",\"b\":\"xb2\"," + "\"y_FKX\":[]}]}", response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 12 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestODataIntegration method testBasicTypes.

@Test
public void testBasicTypes() throws Exception {
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("m");
        mmd.addSourceMapping("x3", "x3", null);
        MetadataStore ms = RealMetadataFactory.exampleBQTStore();
        Schema s = ms.getSchema("BQT1");
        KeyRecord pk = new KeyRecord(KeyRecord.Type.Primary);
        Table smalla = s.getTable("SmallA");
        pk.setName("pk");
        pk.addColumn(smalla.getColumnByName("IntKey"));
        smalla.setPrimaryKey(pk);
        String ddl = DDLStringVisitor.getDDLString(s, EnumSet.allOf(SchemaObjectType.class), "SmallA");
        mmd.addSourceMetadata("DDL", ddl);
        HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
        teiid.addTranslator("x3", hc);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        ContentResponse response = http.GET(baseURL + "/northwind/m/SmallA?$format=json&$select=TimeValue");
        assertEquals(200, response.getStatus());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Schema(org.teiid.metadata.Schema) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) SchemaObjectType(org.teiid.adminapi.Admin.SchemaObjectType) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 13 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestODataIntegration method testSkipToken.

@Test
public void testSkipToken() 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();
        props.setProperty("batch-size", "1");
        localClient = getClient(teiid.getDriver(), "northwind", props);
        ContentResponse response = http.GET(baseURL + "/northwind/vw/x?$format=json");
        assertEquals(200, response.getStatus());
        String starts = "{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"abc\",\"b\":456}]," + "\"@odata.nextLink\":\"" + baseURL + "/northwind/vw/x?$format=json&$skiptoken=";
        String ends = ",1\"}";
        assertTrue(response.getContentAsString(), response.getContentAsString().startsWith(starts));
        assertTrue(response.getContentAsString(), response.getContentAsString().endsWith(ends));
        JsonNode node = getJSONNode(response);
        String nextLink = node.get("@odata.nextLink").asText();
        response = http.GET(nextLink);
        assertEquals(200, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x\",\"value\":[{\"a\":\"xyz\",\"b\":123}]}", response.getContentAsString());
        CacheStatistics stats = teiid.getAdmin().getCacheStats(Admin.Cache.QUERY_SERVICE_RESULT_SET_CACHE.name()).iterator().next();
        // first query misses, second hits
        assertEquals(50, stats.getHitRatio(), 0);
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : CacheStatistics(org.teiid.adminapi.CacheStatistics) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 14 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestODataIntegration method testInsert.

@Test
public void testInsert() throws Exception {
    HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
    hc.addUpdate("INSERT INTO x (a, b) VALUES ('teiid', 'dv')", new int[] { 1 });
    teiid.addTranslator("x10", 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);");
        mmd.addSourceMapping("x10", "x10", null);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        String payload = "{\n" + "  \"a\":\"teiid\",\n" + "  \"b\":\"dv\"\n" + "}";
        ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider(payload)).header("Content-Type", "application/json").header("Prefer", "return=minimal").send();
        assertEquals(204, response.getStatus());
        assertTrue(response.getHeaders().get("OData-EntityId").endsWith("northwind/m/x('ABCDEFG')"));
    // assertEquals("ABCDEFGHIJ",response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 15 with ModelMetaData

use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.

the class TestODataIntegration method testDeepInsert.

@Test
public void testDeepInsert() throws Exception {
    HardCodedExecutionFactory hc = new HardCodedExecutionFactory();
    hc.addUpdate("INSERT INTO x (a, b) VALUES ('teiid', 'dv')", new int[] { 1 });
    hc.addUpdate("INSERT INTO y (a, b) VALUES ('odata', 'teiid')", new int[] { 1 });
    hc.addUpdate("INSERT INTO y (a, b) VALUES ('odata4', 'teiid')", new int[] { 1 });
    hc.addUpdate("INSERT INTO z (a, b) VALUES ('odata', 'teiid')", new int[] { 1 });
    hc.addUpdate("INSERT INTO z (a, b) VALUES ('odata4', 'olingo4')", new int[] { 1 });
    hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("teiid", "dv")));
    hc.addData("SELECT y.b, y.a FROM y", Arrays.asList(Arrays.asList("teiid", "odata"), Arrays.asList("teiid", "odata4")));
    hc.addData("SELECT z.b, z.a FROM z", Arrays.asList(Arrays.asList("teiid", "odata"), Arrays.asList("olingo4", "odata4")));
    teiid.addTranslator("x10", 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);" + "create foreign table z (" + " a string, " + " b string, " + " primary key (a)," + " CONSTRAINT FKX FOREIGN KEY (b) REFERENCES x(a)" + ") options (updatable true);");
        mmd.addSourceMapping("x10", "x10", null);
        teiid.deployVDB("northwind", mmd);
        localClient = getClient(teiid.getDriver(), "northwind", new Properties());
        // update to collection based reference
        String payload = "{\n" + "  \"a\":\"teiid\",\n" + "  \"b\":\"dv\",\n" + "     \"y_FKX\": [\n" + "        {" + "          \"a\":\"odata\",\n" + "          \"b\":\"teiid\"\n" + "        },\n" + "        {\n" + "          \"a\":\"odata4\",\n" + "          \"b\":\"teiid\"\n" + "        }\n" + "     ]\n" + "}";
        ContentResponse response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider(payload), ContentType.APPLICATION_JSON.toString()).header("Prefer", "return=representation").send();
        assertEquals(201, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x\",\"a\":\"teiid\",\"b\":\"dv\"}", response.getContentAsString());
        // update to collection based reference
        payload = "{\n" + "  \"a\":\"teiid\",\n" + "  \"b\":\"dv\",\n" + "    \"y_FKX\": [\n" + "        {" + "          \"a\":\"odata\",\n" + "          \"b\":\"teiid\"\n" + "        },\n" + "        {\n" + "          \"a\":\"odata4\",\n" + "          \"b\":\"teiid\"\n" + "        }\n" + "     ],\n" + "    \"z_FKX\": [\n" + "        {" + "          \"a\":\"odata\",\n" + "          \"b\":\"teiid\"\n" + "        },\n" + "        {\n" + "          \"a\":\"odata4\",\n" + "          \"b\":\"olingo4\"\n" + "        }\n" + "     ]\n" + "}";
        response = http.newRequest(baseURL + "/northwind/m/x").method("POST").content(new StringContentProvider(payload), ContentType.APPLICATION_JSON.toString()).header("Prefer", "return=representation").send();
        assertEquals(201, response.getStatus());
        assertEquals("{\"@odata.context\":\"$metadata#x\",\"a\":\"teiid\",\"b\":\"dv\"}", response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Aggregations

ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)191 Test (org.junit.Test)131 Properties (java.util.Properties)50 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)45 HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)43 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)36 Connection (java.sql.Connection)23 MetadataFactory (org.teiid.metadata.MetadataFactory)21 Statement (java.sql.Statement)19 ResultSet (java.sql.ResultSet)18 CallableStatement (java.sql.CallableStatement)16 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)15 ArrayList (java.util.ArrayList)13 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)11 SourceMappingMetadata (org.teiid.adminapi.impl.SourceMappingMetadata)11 Table (org.teiid.metadata.Table)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 List (java.util.List)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)9