Search in sources :

Example 26 with RuntimeMetadata

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

the class TestSalesForceDirectQueryExecution method testCreate.

@Test
public void testCreate() throws Exception {
    String input = "exec native('create;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    ArgumentCaptor<DataPayload> payloadArgument = ArgumentCaptor.forClass(DataPayload.class);
    Mockito.stub(connection.create(payloadArgument.capture())).toReturn(23);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).create(payloadArgument.capture());
    assertEquals("pk", payloadArgument.getValue().getID());
    assertEquals("table", payloadArgument.getValue().getType());
    assertEquals(3, payloadArgument.getValue().getMessageElements().size());
    assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 27 with RuntimeMetadata

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

the class TestSalesForceDirectQueryExecution method testUpdate.

@Test
public void testUpdate() throws Exception {
    String input = "exec native('update;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    ArgumentCaptor<List> payloadArgument = ArgumentCaptor.forClass(List.class);
    Mockito.stub(connection.update(payloadArgument.capture())).toReturn(23);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).update(payloadArgument.capture());
    assertEquals(1, payloadArgument.getValue().size());
    assertEquals("pk", ((DataPayload) payloadArgument.getValue().get(0)).getID());
    assertEquals("table", ((DataPayload) payloadArgument.getValue().get(0)).getType());
    assertEquals(3, ((DataPayload) payloadArgument.getValue().get(0)).getMessageElements().size());
    assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) List(java.util.List) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 28 with RuntimeMetadata

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

the class TestVisitors method helpTest.

private void helpTest(String sql, String expected) throws Exception {
    Command command = translationUtility.parseCommand(sql);
    SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    ArgumentCaptor<String> queryArgument = ArgumentCaptor.forClass(String.class);
    QueryResult qr = Mockito.mock(QueryResult.class);
    Mockito.stub(connection.query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean())).toReturn(qr);
    Execution execution = factory.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).query(queryArgument.capture(), Mockito.anyInt(), Mockito.anyBoolean());
    assertEquals(expected, queryArgument.getValue().trim());
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) Execution(org.teiid.translator.Execution) Command(org.teiid.language.Command) SalesForceExecutionFactory(org.teiid.translator.salesforce.SalesForceExecutionFactory) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection)

Example 29 with RuntimeMetadata

use of org.teiid.metadata.RuntimeMetadata 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 30 with RuntimeMetadata

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

the class TestBaseDelegatingExecutionFactory method testExecution.

@Test
public void testExecution() throws TranslatorException {
    BaseDelegatingExecutionFactory<Void, Void> ef = new BaseDelegatingExecutionFactory<Void, Void>() {

        @Override
        public ResultSetExecution createResultSetExecution(QueryExpression command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
            return null;
        }
    };
    ef.setDelegate(new ExecutionFactory<Void, Void>() {

        @Override
        public Execution createExecution(Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Void connection) throws TranslatorException {
            throw new AssertionError();
        }
    });
    ef.createExecution(new Select(null, false, null, null, null, null, null), null, null, null);
}
Also used : RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Command(org.teiid.language.Command) Select(org.teiid.language.Select) QueryExpression(org.teiid.language.QueryExpression) 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