Search in sources :

Example 11 with AtomicResultsMessage

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

the class TestConnectorWorkItem method testLobs.

@Test
public void testLobs() throws Exception {
    BufferManager bm = BufferManagerFactory.getStandaloneBufferManager();
    final List<Object> result = Arrays.asList(AutoGenDataService.CLOB_VAL);
    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 {
            return new ResultSetExecution() {

                private boolean returned;

                @Override
                public void execute() throws TranslatorException {
                }

                @Override
                public void close() {
                }

                @Override
                public void cancel() throws TranslatorException {
                }

                @Override
                public List<?> next() throws TranslatorException, DataNotAvailableException {
                    if (returned) {
                        return null;
                    }
                    returned = true;
                    return result;
                }
            };
        }
    };
    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 CLOB_COLUMN FROM LOB_TESTING_ONE", EXAMPLE_BQT));
    requestMsg.setBufferManager(bm);
    ConnectorWorkItem cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    AtomicResultsMessage message = cwi.more();
    List[] resutls = message.getResults();
    List<?> tuple = resutls[0];
    ClobType clob = (ClobType) tuple.get(0);
    assertEquals(StorageMode.MEMORY, InputStreamFactory.getStorageMode(clob));
    assertTrue(message.supportsImplicitClose());
    result.set(0, AutoGenDataService.CLOB_VAL);
    ef.setCopyLobs(false);
    cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    message = cwi.more();
    resutls = message.getResults();
    tuple = resutls[0];
    clob = (ClobType) tuple.get(0);
    assertEquals(StorageMode.OTHER, InputStreamFactory.getStorageMode(clob));
    assertFalse(message.supportsImplicitClose());
    result.set(0, new ClobImpl(new InputStreamFactory() {

        @Override
        public InputStream getInputStream() throws IOException {
            return new ByteArrayInputStream(new byte[0]);
        }

        @Override
        public StorageMode getStorageMode() {
            // TODO: introduce an explicit streaming
            return StorageMode.FREE;
        }
    }, -1));
    requestMsg.setCopyStreamingLobs(true);
    cwi = new ConnectorWorkItem(requestMsg, cm);
    cwi.execute();
    message = cwi.more();
    resutls = message.getResults();
    tuple = resutls[0];
    clob = (ClobType) tuple.get(0);
    // switched from FREE to PERSISTENT
    assertEquals(StorageMode.PERSISTENT, InputStreamFactory.getStorageMode(clob));
    assertFalse(message.supportsImplicitClose());
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) BufferManager(org.teiid.common.buffer.BufferManager) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) InputStreamFactory(org.teiid.core.types.InputStreamFactory) ClobType(org.teiid.core.types.ClobType) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) List(java.util.List) ArrayList(java.util.ArrayList) QueryExpression(org.teiid.language.QueryExpression) ClobImpl(org.teiid.core.types.ClobImpl) AtomicRequestMessage(org.teiid.dqp.message.AtomicRequestMessage) Test(org.junit.Test)

Example 12 with AtomicResultsMessage

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

the class TestConnectorWorkItem method testExecutionWarning.

@Test
public void testExecutionWarning() throws Throwable {
    AtomicResultsMessage results = helpExecuteUpdate(false, false);
    assertEquals(1, results.getWarnings().size());
}
Also used : AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) Test(org.junit.Test)

Example 13 with AtomicResultsMessage

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

the class TestConnectorWorkItem method testBatchUpdateExecutionSingleResult.

@Test
public void testBatchUpdateExecutionSingleResult() throws Throwable {
    AtomicResultsMessage results = helpExecuteUpdate(true, true);
    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)

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