Search in sources :

Example 1 with ExecutionContext

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

the class TestNativeCassandra method testDirect.

@Test
public void testDirect() throws TranslatorException {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    cef.setSupportsDirectQueryProcedure(true);
    String input = "call native('select $1', 'a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    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(rsf.isDone()).toReturn(true);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(rsf.getUninterruptibly()).toReturn(rs);
    Row row = Mockito.mock(Row.class);
    ColumnDefinitions cd = Mockito.mock(ColumnDefinitions.class);
    Mockito.stub(row.getColumnDefinitions()).toReturn(cd);
    Mockito.stub(rs.one()).toReturn(row).toReturn(null);
    Mockito.stub(connection.executeQuery("select 'a'")).toReturn(rsf);
    ResultSetExecution execution = (ResultSetExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    List<?> vals = execution.next();
    assertTrue(vals.get(0) instanceof Object[]);
}
Also used : ColumnDefinitions(com.datastax.driver.core.ColumnDefinitions) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) Test(org.junit.Test)

Example 2 with ExecutionContext

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

the class TestUpdates method testBulkUpdate.

@Test
public void testBulkUpdate() throws Exception {
    CassandraExecutionFactory cef = new CassandraExecutionFactory();
    String input = "insert into pm1.g1 (e1) values ('a')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    Insert insert = (Insert) command;
    Parameter p = new Parameter();
    p.setType(String.class);
    p.setValueIndex(0);
    ((ExpressionValueSource) insert.getValueSource()).getValues().set(0, p);
    insert.setParameterValues(Arrays.asList(Arrays.asList("a"), Arrays.asList("b")).iterator());
    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(Mockito.eq("INSERT INTO g1 (e1) VALUES (?)"), (List<Object[]>) Mockito.anyObject())).toReturn(rsf);
    UpdateExecution execution = (UpdateExecution) cef.createExecution(command, ec, rm, connection);
    execution.execute();
    assertArrayEquals(new int[] { 2 }, execution.getUpdateCounts());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ResultSetFuture(com.datastax.driver.core.ResultSetFuture) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Parameter(org.teiid.language.Parameter) UpdateExecution(org.teiid.translator.UpdateExecution) Insert(org.teiid.language.Insert) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 3 with ExecutionContext

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

the class TestSimpleDBExecution method testDeleteAll.

@Test
public void testDeleteAll() throws Exception {
    String query = "delete from item";
    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
    exec.execute();
    Mockito.verify(connection).deleteDomain("item");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 4 with ExecutionContext

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

the class TestSimpleDBExecution method testInsert.

@Test
public void testInsert() throws Exception {
    String query = "insert into item (\"itemName()\", attribute, somedate, strarray) values ('one', 'value', {ts '2014-04-04 10:50:45'}, ('1', '2'))";
    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    UpdateExecution exec = translator.createUpdateExecution(cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
    exec.execute();
    SimpleDBInsertVisitor visitor = new SimpleDBInsertVisitor();
    visitor.visitNode(cmd);
    ArgumentCaptor<Iterator> argument = ArgumentCaptor.forClass(Iterator.class);
    ArgumentCaptor<String> itemName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<ArrayList> columns = ArgumentCaptor.forClass(ArrayList.class);
    Mockito.verify(connection).performInsert(itemName.capture(), columns.capture(), argument.capture());
    assertEquals("item", itemName.getValue());
    List<?> values = (List<?>) argument.getValue().next();
    assertEquals("value", values.get(1));
    assertEquals("2014-04-04 10:50:45.0", values.get(2).toString());
    assertEquals("1,2,", arrayToStr((String[]) values.get(3)));
}
Also used : ArrayList(java.util.ArrayList) UpdateExecution(org.teiid.translator.UpdateExecution) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SimpleDBInsertVisitor(org.teiid.translator.simpledb.SimpleDBInsertVisitor) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 5 with ExecutionContext

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

the class TestSimpleDBExecution method testSelect.

@Test
public void testSelect() throws Exception {
    SelectResult result = new SelectResult();
    result.setItems(mockResult());
    String query = "select * from item where attribute > 'name'";
    Mockito.stub(connection.performSelect(Mockito.anyString(), Mockito.anyString())).toReturn(result);
    Command cmd = utility.parseCommand(query);
    ExecutionContext context = Mockito.mock(ExecutionContext.class);
    Mockito.stub(context.getBatchSize()).toReturn(10);
    ResultSetExecution exec = translator.createResultSetExecution((Select) cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
    exec.execute();
    exec.next();
    Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name' LIMIT 10", null);
    // cap at 2500
    Mockito.stub(context.getBatchSize()).toReturn(4000);
    exec = translator.createResultSetExecution((Select) cmd, context, Mockito.mock(RuntimeMetadata.class), connection);
    exec.execute();
    exec.next();
    Mockito.verify(connection).performSelect("SELECT attribute, somedate, strarray FROM item WHERE attribute > 'name' LIMIT 2500", null);
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) ResultSetExecution(org.teiid.translator.ResultSetExecution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) Select(org.teiid.language.Select) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) 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