Search in sources :

Example 6 with Execution

use of org.teiid.translator.Execution in project teiid by teiid.

the class ConnectorHost method executeCommand.

private List executeCommand(Command command, RuntimeMetadata runtimeMetadata, boolean close) throws TranslatorException {
    Execution exec = connector.createExecution(command, this.executionContext, runtimeMetadata, this.connectionFactory);
    exec.execute();
    List results = readResultsFromExecution(exec);
    if (close) {
        exec.close();
    }
    return results;
}
Also used : UpdateExecution(org.teiid.translator.UpdateExecution) Execution(org.teiid.translator.Execution) ResultSetExecution(org.teiid.translator.ResultSetExecution) ArrayList(java.util.ArrayList) List(java.util.List)

Example 7 with Execution

use of org.teiid.translator.Execution in project teiid by teiid.

the class TestLocalConnections method oneTimeSetup.

@SuppressWarnings("serial")
@BeforeClass
public static void oneTimeSetup() throws Exception {
    server.setUseCallingThread(true);
    server.setConnectorManagerRepository(new ConnectorManagerRepository() {

        @Override
        public ConnectorManager getConnectorManager(String connectorName) {
            return new ConnectorManager(connectorName, connectorName) {

                @Override
                public ExecutionFactory<Object, Object> getExecutionFactory() {
                    return new ExecutionFactory<Object, Object>() {

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

                        @Override
                        public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
                            return new ResultSetExecution() {

                                boolean returnedRow = false;

                                @Override
                                public void execute() throws TranslatorException {
                                    lock.lock();
                                    try {
                                        sourceCounter.release();
                                        if (!wait.await(5, TimeUnit.SECONDS)) {
                                            throw new RuntimeException();
                                        }
                                    } catch (InterruptedException e) {
                                        throw new RuntimeException(e);
                                    } finally {
                                        lock.unlock();
                                    }
                                }

                                @Override
                                public void close() {
                                }

                                @Override
                                public void cancel() throws TranslatorException {
                                }

                                @Override
                                public List<?> next() throws TranslatorException, DataNotAvailableException {
                                    if (returnedRow) {
                                        return null;
                                    }
                                    returnedRow = true;
                                    return new ArrayList<Object>(Collections.singleton(null));
                                }
                            };
                        }
                    };
                }

                @Override
                public Object getConnectionFactory() throws TranslatorException {
                    return null;
                }
            };
        }
    });
    FunctionMethod function = new FunctionMethod("foo", null, FunctionCategoryConstants.MISCELLANEOUS, PushDown.CANNOT_PUSHDOWN, TestLocalConnections.class.getName(), "blocking", null, new FunctionParameter("result", DataTypeManager.DefaultDataTypes.INTEGER), false, FunctionMethod.Determinism.NONDETERMINISTIC);
    HashMap<String, Collection<FunctionMethod>> udfs = new HashMap<String, Collection<FunctionMethod>>();
    udfs.put("test", Arrays.asList(function));
    server.deployVDB("PartsSupplier", UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb", new DeployVDBParameter(udfs, null));
}
Also used : HashMap(java.util.HashMap) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Execution(org.teiid.translator.Execution) ResultSetExecution(org.teiid.translator.ResultSetExecution) FunctionMethod(org.teiid.metadata.FunctionMethod) List(java.util.List) ArrayList(java.util.ArrayList) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) FunctionParameter(org.teiid.metadata.FunctionParameter) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) DeployVDBParameter(org.teiid.jdbc.FakeServer.DeployVDBParameter) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Collection(java.util.Collection) TranslatorException(org.teiid.translator.TranslatorException) BeforeClass(org.junit.BeforeClass)

Aggregations

Execution (org.teiid.translator.Execution)7 Command (org.teiid.language.Command)6 ExecutionContext (org.teiid.translator.ExecutionContext)6 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)4 ResultSetExecution (org.teiid.translator.ResultSetExecution)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 TranslationUtility (org.teiid.cdk.api.TranslationUtility)2 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)1 QueryResult (com.sforce.soap.partner.QueryResult)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LdapContext (javax.naming.ldap.LdapContext)1 BeforeClass (org.junit.BeforeClass)1 CommandContext (org.teiid.CommandContext)1 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)1 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)1 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)1 FunctionMethod (org.teiid.metadata.FunctionMethod)1