Search in sources :

Example 11 with HardCodedExecutionFactory

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");
    }
}
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 HardCodedExecutionFactory

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");
    }
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.query.sql.lang.Command) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) StringContentProvider(org.eclipse.jetty.client.util.StringContentProvider) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) GeneratedKeys(org.teiid.GeneratedKeys) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 13 with HardCodedExecutionFactory

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");
    }
}
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 14 with HardCodedExecutionFactory

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");
    }
}
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 HardCodedExecutionFactory

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());
}
Also used : FakeServer(org.teiid.jdbc.FakeServer) InetSocketAddress(java.net.InetSocketAddress) SocketConfiguration(org.teiid.transport.SocketConfiguration) EmbeddedConfiguration(org.teiid.runtime.EmbeddedConfiguration) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) SSLConfiguration(org.teiid.transport.SSLConfiguration) SocketListener(org.teiid.transport.SocketListener) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) ArrayList(java.util.ArrayList) List(java.util.List) QueryExpression(org.teiid.language.QueryExpression) BeforeClass(org.junit.BeforeClass)

Aggregations

HardCodedExecutionFactory (org.teiid.runtime.HardCodedExecutionFactory)46 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)43 Test (org.junit.Test)40 Properties (java.util.Properties)27 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)27 StringContentProvider (org.eclipse.jetty.client.util.StringContentProvider)10 Connection (java.sql.Connection)8 ResultSet (java.sql.ResultSet)8 Statement (java.sql.Statement)7 CallableStatement (java.sql.CallableStatement)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 FakeServer (org.teiid.jdbc.FakeServer)4 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 Table (org.teiid.metadata.Table)3 EmbeddedConfiguration (org.teiid.runtime.EmbeddedConfiguration)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 BeforeClass (org.junit.BeforeClass)2 AbstractQueryTest (org.teiid.jdbc.AbstractQueryTest)2