Search in sources :

Example 46 with ExecutionContext

use of org.teiid.translator.ExecutionContext 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 47 with ExecutionContext

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

the class TestConnectorManager method testGetCapabilities.

@Test
public void testGetCapabilities() throws Exception {
    final Object cf = new Object();
    ExecutionFactory ef = new ExecutionFactory() {

        public boolean isSourceRequiredForCapabilities() {
            return true;
        }
    };
    final Object[] cfHolder = new Object[1];
    ConnectorManager cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    ef) {

        public Object getConnectionFactory() {
            return cfHolder[0];
        }
    };
    cm.start();
    try {
        cm.getCapabilities();
        fail();
    } catch (TranslatorException e) {
    }
    ef = new ExecutionFactory() {

        public boolean isSourceRequiredForCapabilities() {
            return true;
        }

        @Override
        public Object getConnection(Object factory, ExecutionContext executionContext) throws TranslatorException {
            assertEquals(cf, factory);
            return factory;
        }

        @Override
        public void closeConnection(Object connection, Object factory) {
        }
    };
    cm = new // $NON-NLS-1$ //$NON-NLS-2$
    ConnectorManager(// $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    "FakeConnector", // $NON-NLS-1$ //$NON-NLS-2$
    ef) {

        public Object getConnectionFactory() {
            return cfHolder[0];
        }
    };
    cfHolder[0] = cf;
    cm.getCapabilities();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ExecutionFactory(org.teiid.translator.ExecutionFactory) TranslatorException(org.teiid.translator.TranslatorException) Test(org.junit.Test)

Example 48 with ExecutionContext

use of org.teiid.translator.ExecutionContext 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 49 with ExecutionContext

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

the class TestNativeCassandra method testNativeQuery.

@Test
public void testNativeQuery() throws Exception {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    cef.setSupportsDirectQueryProcedure(true);
    String input = "call proc('a', 1)";
    TransformationMetadata metadata = RealMetadataFactory.fromDDL("create foreign procedure proc (in x string, in y integer) options (\"teiid_rel:native-query\" 'delete from $1 where $2')", "x", "y");
    TranslationUtility util = new TranslationUtility(metadata);
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(connection.executeQuery("delete from 'a' where 1")).toReturn(rsf);
    Execution execution = cef.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).executeQuery("delete from 'a' where 1");
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Execution(org.teiid.translator.Execution) ResultSetExecution(org.teiid.translator.ResultSetExecution) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 50 with ExecutionContext

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

the class TestUpdates method testBatchedUpdate.

@Test
public void testBatchedUpdate() throws TranslatorException {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    String input = "insert into pm1.g1 (e1) values ('a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    Command command1 = util.parseCommand("update pm1.g1 set e1 = 'b'");
    command = new BatchedUpdates(Arrays.asList(command, command1));
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    CassandraConnection connection = Mockito.mock(CassandraConnection.class);
    ResultSetFuture rsf = Mockito.mock(ResultSetFuture.class);
    Mockito.stub(rsf.isDone()).toReturn(true);
    Mockito.stub(connection.executeBatch(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"))).toReturn(rsf);
    UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
    Mockito.verify(connection).executeBatch(Arrays.asList("INSERT INTO g1 (e1) VALUES ('a')", "UPDATE g1 SET e1 = 'b'"));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) BatchedUpdates(org.teiid.language.BatchedUpdates) Test(org.junit.Test)

Aggregations

ExecutionContext (org.teiid.translator.ExecutionContext)65 Test (org.junit.Test)50 Command (org.teiid.language.Command)49 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)48 TranslationUtility (org.teiid.cdk.api.TranslationUtility)32 ResultSetExecution (org.teiid.translator.ResultSetExecution)23 List (java.util.List)17 UpdateExecution (org.teiid.translator.UpdateExecution)14 TranslatorException (org.teiid.translator.TranslatorException)11 ArrayList (java.util.ArrayList)10 QueryExpression (org.teiid.language.QueryExpression)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 LdapContext (javax.naming.ldap.LdapContext)9 ExecutionFactory (org.teiid.translator.ExecutionFactory)9 SalesforceConnection (org.teiid.translator.salesforce.SalesforceConnection)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 HashMap (java.util.HashMap)6 DataSource (javax.activation.DataSource)6 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)6 WSConnection (org.teiid.translator.WSConnection)6