Search in sources :

Example 36 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class ConnectorHost method executeCommand.

public List executeCommand(String query, boolean close) throws TranslatorException {
    Command command = getCommand(query);
    RuntimeMetadata runtimeMetadata = getRuntimeMetadata();
    return executeCommand(command, runtimeMetadata, close);
}
Also used : Command(org.teiid.language.Command) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata)

Example 37 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestODataIntegration method testErrorCodes.

@Test
public void testErrorCodes() throws Exception {
    HardCodedExecutionFactory hc = new HardCodedExecutionFactory() {

        @Override
        public ResultSetExecution createResultSetExecution(final QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<? extends List<?>> list = getData(command);
            if (list == null) {
                throw new RuntimeException(command.toString());
            }
            final Iterator<? extends List<?>> result = list.iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                    throw new TranslatorException(ODataPlugin.Event.TEIID16001, "execution failed");
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (result.hasNext()) {
                        return result.next();
                    }
                    return null;
                }
            };
        }
    };
    hc.addData("SELECT x.a, x.b FROM x", Arrays.asList(Arrays.asList("a", 1)));
    teiid.addTranslator("x1", hc);
    try {
        ModelMetaData mmd = new ModelMetaData();
        mmd.setName("m");
        mmd.addSourceMetadata("ddl", "create foreign table x (a string, b integer, primary key (a));");
        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("GET").send();
        assertEquals(400, response.getStatus());
        assertEquals("{\"error\":{\"code\":\"TEIID30504\"," + "\"message\":\"TEIID30504 x1: TEIID16001 execution failed\"}}", response.getContentAsString());
        response = http.newRequest(baseURL + "/northwind/m/x?$format=xml").method("GET").send();
        assertEquals(400, response.getStatus());
        assertEquals("<?xml version='1.0' encoding='UTF-8'?>" + "<error xmlns=\"http://docs.oasis-open.org/odata/ns/metadata\">" + "<code>TEIID30504</code>" + "<message>TEIID30504 x1: TEIID16001 execution failed</message>" + "</error>", response.getContentAsString());
    } finally {
        localClient = null;
        teiid.undeployVDB("northwind");
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Properties(java.util.Properties) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) HardCodedExecutionFactory(org.teiid.runtime.HardCodedExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Example 38 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestEmbeddedServer method testQueryTimeout.

@Test
public void testQueryTimeout() throws Exception {
    es.start(new EmbeddedConfiguration());
    es.addTranslator("foo", new ExecutionFactory() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
            }
            return super.createResultSetExecution(command, executionContext, metadata, connection);
        }
    });
    es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
    Connection c = es.getDriver().connect("jdbc:teiid:test", null);
    Statement s = c.createStatement();
    s.setQueryTimeout(1);
    try {
        s.execute("select * from x");
        fail();
    } catch (SQLException e) {
        assertEquals(SQLStates.QUERY_CANCELED, e.getSQLState());
    }
}
Also used : TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ExecutionFactory(org.teiid.translator.ExecutionFactory) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Example 39 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestEmbeddedServer method testSourceLobUnderTxn.

@Test
public void testSourceLobUnderTxn() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    ec.setMaxResultSetCacheStaleness(0);
    MockTransactionManager tm = new MockTransactionManager();
    ec.setTransactionManager(tm);
    ec.setUseDisk(false);
    es.start(ec);
    final AtomicBoolean closed = new AtomicBoolean();
    es.addTranslator("foo", new ExecutionFactory() {

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            return new ResultSetExecution() {

                private boolean returned;

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                    closed.set(true);
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (returned) {
                        return null;
                    }
                    returned = true;
                    ArrayList<Object> result = new ArrayList<Object>(1);
                    result.add(new SQLXMLImpl(new InputStreamFactory() {

                        @Override
                        public InputStream getInputStream() throws IOException {
                            // need to make it of a sufficient size to not be inlined
                            return new ByteArrayInputStream(new byte[DataTypeManager.MAX_LOB_MEMORY_BYTES + 1]);
                        }
                    }));
                    return result;
                }
            };
        }
    });
    es.deployVDB(new ByteArrayInputStream("<vdb name=\"test\" version=\"1\"><model name=\"test\"><source name=\"foo\" translator-name=\"foo\"/><metadata type=\"DDL\"><![CDATA[CREATE foreign table x (y xml);]]> </metadata></model></vdb>".getBytes()));
    Connection c = es.getDriver().connect("jdbc:teiid:test", null);
    c.setAutoCommit(false);
    Statement s = c.createStatement();
    ResultSet rs = s.executeQuery("select * from x");
    rs.next();
    assertFalse(closed.get());
    s.close();
    assertTrue(closed.get());
}
Also used : SQLXMLImpl(org.teiid.core.types.SQLXMLImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ExecutionFactory(org.teiid.translator.ExecutionFactory) IOException(java.io.IOException) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) InputStreamFactory(org.teiid.core.types.InputStreamFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) TranslatorException(org.teiid.translator.TranslatorException) List(java.util.List) ArrayList(java.util.ArrayList) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) QueryExpression(org.teiid.language.QueryExpression) Test(org.junit.Test)

Example 40 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.

the class TestEmbeddedServer method testDynamicUpdate.

@Test
public void testDynamicUpdate() throws Exception {
    EmbeddedConfiguration ec = new EmbeddedConfiguration();
    MockTransactionManager tm = new MockTransactionManager();
    ec.setTransactionManager(tm);
    ec.setUseDisk(false);
    es.start(ec);
    es.addTranslator("t", new ExecutionFactory<Void, Void>() {

        @Override
        public boolean supportsCompareCriteriaEquals() {
            return true;
        }

        @Override
        public boolean isSourceRequired() {
            return false;
        }

        @Override
        public UpdateExecution createUpdateExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
            Collection<Literal> values = CollectorVisitor.collectObjects(Literal.class, command);
            assertEquals(2, values.size());
            for (Literal literal : values) {
                assertFalse(literal.getValue() instanceof Reference);
            }
            return new UpdateExecution() {

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public int[] getUpdateCounts() throws DataNotAvailableException, TranslatorException {
                    return new int[] { 1 };
                }
            };
        }
    });
    ModelMetaData mmd1 = new ModelMetaData();
    mmd1.setName("accounts");
    mmd1.setSchemaSourceType("ddl");
    mmd1.setSchemaText(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("dynamic_update.sql")));
    mmd1.addSourceMapping("y", "t", null);
    es.deployVDB("vdb", mmd1);
    Connection c = es.getDriver().connect("jdbc:teiid:vdb", null);
    PreparedStatement ps = c.prepareStatement("update hello1 set SchemaName=? where Name=?");
    ps.setString(1, "test1223");
    ps.setString(2, "Columns");
    assertEquals(1, ps.executeUpdate());
}
Also used : Reference(org.teiid.query.sql.symbol.Reference) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Literal(org.teiid.language.Literal) Collection(java.util.Collection) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) Test(org.junit.Test)

Aggregations

RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)46 ExecutionContext (org.teiid.translator.ExecutionContext)40 Test (org.junit.Test)38 Command (org.teiid.language.Command)33 TranslationUtility (org.teiid.cdk.api.TranslationUtility)26 ResultSetExecution (org.teiid.translator.ResultSetExecution)14 QueryExpression (org.teiid.language.QueryExpression)11 TranslatorException (org.teiid.translator.TranslatorException)10 LdapContext (javax.naming.ldap.LdapContext)9 List (java.util.List)8 ExecutionFactory (org.teiid.translator.ExecutionFactory)8 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)7 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)7 ArrayList (java.util.ArrayList)6 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)5 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)4 SObject (com.sforce.soap.partner.sobject.SObject)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 EntityManager (javax.persistence.EntityManager)4 UpdateExecution (org.teiid.translator.UpdateExecution)4