Search in sources :

Example 1 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class AutoGenDataService method registerRequest.

@Override
public ConnectorWork registerRequest(AtomicRequestMessage message) throws TeiidComponentException {
    List projectedSymbols = (message.getCommand()).getProjectedSymbols();
    List[] results = createResults(projectedSymbols, rows, useIntCounter);
    if (RelationalNodeUtil.isUpdate(message.getCommand())) {
        results = new List[] { Arrays.asList(1) };
    }
    final AtomicResultsMessage msg = ConnectorWorkItem.createResultsMessage(results);
    msg.setFinalRow(rows);
    return new ConnectorWork() {

        boolean returnedInitial;

        @Override
        public boolean isDataAvailable() {
            return dataAvailable;
        }

        @Override
        public AtomicResultsMessage more() throws TranslatorException {
            if (dataNotAvailable != null) {
                int delay = dataNotAvailable;
                dataNotAvailable = null;
                DataNotAvailableException dnae = new DataNotAvailableException(delay);
                dnae.setStrict(strict);
                throw dnae;
            }
            if (addWarning) {
                msg.setWarnings(Arrays.asList(new Exception()));
            }
            if (!returnedInitial) {
                returnedInitial = true;
                return msg;
            }
            // $NON-NLS-1$
            throw new RuntimeException("Should not be called");
        }

        @Override
        public void execute() throws TranslatorException {
            executeCount.incrementAndGet();
            if (sleep > 0) {
                try {
                    Thread.sleep(sleep);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (latch != null) {
                try {
                    latch.countDown();
                    latch.await();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            if (throwExceptionOnExecute) {
                // $NON-NLS-1$
                throw new TranslatorException("Connector Exception");
            }
        }

        @Override
        public void close() {
            closeCount.incrementAndGet();
        }

        @Override
        public void cancel(boolean abnormal) {
        }

        @Override
        public CacheDirective getCacheDirective() {
            return cacheDirective;
        }

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

        @Override
        public boolean isThreadBound() {
            return threadBound;
        }

        @Override
        public AtomicRequestID getId() {
            return null;
        }
    };
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) ConnectorWork(org.teiid.dqp.internal.datamgr.ConnectorWork) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) TeiidComponentException(org.teiid.core.TeiidComponentException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) IOException(java.io.IOException)

Example 2 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class TestConnectorWorkItem method testUpdateExecution.

@Test
public void testUpdateExecution() throws Throwable {
    AtomicResultsMessage results = helpExecuteUpdate(false, true);
    assertEquals(Integer.valueOf(1), results.getResults()[0].get(0));
}
Also used : AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) Test(org.junit.Test)

Example 3 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class TestConnectorWorkItem method testBatchUpdateExecution.

@Test
public void testBatchUpdateExecution() throws Throwable {
    AtomicResultsMessage results = helpExecuteUpdate(true, false);
    assertEquals(2, results.getResults().length);
    assertEquals(Integer.valueOf(1), results.getResults()[0].get(0));
    assertEquals(1, results.getResults()[1].get(0));
}
Also used : AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) Test(org.junit.Test)

Example 4 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class TestConnectorWorkItem method testConversionError.

@Test
public void testConversionError() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

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

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<String> list1 = new ArrayList<String>();
            list1.add("1");
            List<String> list2 = new ArrayList<String>();
            list2.add("a");
            final Iterator<List<String>> iter = Arrays.asList(list1, list2).iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (iter.hasNext()) {
                        return iter.next();
                    }
                    return null;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    ef.setCopyLobs(true);
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] results = message.getResults();
    assertEquals(1, results.length);
    List<?> tuple = results[0];
    assertEquals(1, tuple.get(0));
    assertEquals(-1, message.getFinalRow());
    try {
        cwi.more();
        fail();
    } catch (TranslatorException e) {
    // should throw the conversion error
    }
}
Also used : ArrayList(java.util.ArrayList) ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) List(java.util.List) ArrayList(java.util.ArrayList) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) QueryExpression(org.teiid.language.QueryExpression) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 5 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class TestConnectorWorkItem method testUnmodifibleList.

@Test
public void testUnmodifibleList() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final ExecutionFactory<Object, Object> ef = new ExecutionFactory<Object, Object>() {

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

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Object connection) throws TranslatorException {
            List<String> list1 = Collections.singletonList("1");
            final Iterator<List<String>> iter = Arrays.asList(list1).iterator();
            return new ResultSetExecution() {

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (iter.hasNext()) {
                        return iter.next();
                    }
                    return null;
                }
            };
        }
    };
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector") {

        public ExecutionFactory getExecutionFactory() {
            return ef;
        }

        public Object getConnectionFactory() {
            return null;
        }
    };
    cm.start();
    AtomicRequestMessage requestMsg = createNewAtomicRequestMessage(1, 1);
    // $NON-NLS-1$
    requestMsg.setCommand(helpGetCommand("SELECT intkey FROM bqt1.smalla", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] results = message.getResults();
    assertEquals(1, results.length);
    List<?> tuple = results[0];
    assertEquals(1, tuple.get(0));
    assertEquals(1, message.getFinalRow());
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) List(java.util.List) ArrayList(java.util.ArrayList) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) QueryExpression(org.teiid.language.QueryExpression) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Aggregations

AtomicResultsMessage (org.teiid.dqp.message.AtomicResultsMessage)13 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 TranslatorException (org.teiid.translator.TranslatorException)5 BufferManager (org.teiid.common.buffer.BufferManager)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)3 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)3 ExecutionContext (org.teiid.translator.ExecutionContext)3 ExecutionFactory (org.teiid.translator.ExecutionFactory)3 ResultSetExecution (org.teiid.translator.ResultSetExecution)3 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1