Search in sources :

Example 46 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testSearch.

@Test
public void testSearch() throws Exception {
    String input = "exec native('search;SELECT Account.Id, Account.Type, Account.Name FROM Account')";
    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);
    QueryResult qr = Mockito.mock(QueryResult.class);
    Mockito.stub(qr.isDone()).toReturn(true);
    SObject[] results = new SObject[1];
    SObject s = new SObject();
    s.setType("Account");
    s.setId("The ID");
    results[0] = s;
    s.addField("Type", "The Type");
    s.addField("Name", "The Name");
    Mockito.stub(qr.getRecords()).toReturn(results);
    Mockito.stub(connection.query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false)).toReturn(qr);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).query("SELECT Account.Id, Account.Type, Account.Name FROM Account", 0, false);
    assertArrayEquals(new Object[] { "The ID", "The Type", "The Name" }, (Object[]) execution.next().get(0));
}
Also used : QueryResult(com.sforce.soap.partner.QueryResult) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SObject(com.sforce.soap.partner.sobject.SObject) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 47 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testDelete.

@Test
public void testDelete() throws Exception {
    String input = "exec native('delete;', 'id1','id2')";
    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<String[]> payloadArgument = ArgumentCaptor.forClass(String[].class);
    Mockito.stub(connection.delete(payloadArgument.capture())).toReturn(23);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).delete(payloadArgument.capture());
    assertEquals("id1", payloadArgument.getValue()[0]);
    assertEquals("id2", payloadArgument.getValue()[1]);
    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 48 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestYahooTranslation method helpTestTranslation.

public void helpTestTranslation(String sql, String expectedUrl) throws Exception {
    Command command = FakeTranslationFactory.getInstance().getYahooTranslationUtility().parseCommand(sql);
    String url = YahooExecution.translateIntoUrl((Select) command);
    // $NON-NLS-1$
    assertEquals("Did not get expected url", expectedUrl, url);
}
Also used : Command(org.teiid.language.Command)

Example 49 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestOracleTranslator method testConcat2.

@Test
public void testConcat2() throws Exception {
    // $NON-NLS-1$
    String input = "select concat2(stringnum, stringkey) from bqt1.Smalla";
    // $NON-NLS-1$
    String output = "SELECT (g_0.StringNum || g_0.StringKey) FROM SmallA g_0";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 50 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestOracleTranslator method testCursorResult.

@Test
public void testCursorResult() throws Exception {
    // $NON-NLS-1$
    String input = "call proc('foo')";
    // $NON-NLS-1$
    String output = "{call proc(?,?)}";
    String ddl = "create foreign procedure proc (in x string, out y object options (native_type 'REF CURSOR')) returns table (a string);";
    Command command = helpTestVisitor(RealMetadataFactory.fromDDL(ddl, "x", "y"), input, EMPTY_CONTEXT, null, output);
    Connection connection = Mockito.mock(Connection.class);
    CallableStatement cs = Mockito.mock(CallableStatement.class);
    Mockito.stub(cs.getUpdateCount()).toReturn(-1);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(cs.getObject(2)).toReturn(rs);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareCall(output)).toReturn(cs);
    OracleExecutionFactory ef = new OracleExecutionFactory();
    JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
    procedureExecution.execute();
    // TODO we may not want to actually return the resultset, but this ensures full compatibility
    assertEquals(Arrays.asList(rs), procedureExecution.getOutputParameterValues());
    Mockito.verify(cs, Mockito.times(1)).registerOutParameter(2, OracleExecutionFactory.CURSOR_TYPE);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCProcedureExecution(org.teiid.translator.jdbc.JDBCProcedureExecution) Test(org.junit.Test)

Aggregations

Command (org.teiid.language.Command)136 Test (org.junit.Test)99 ExecutionContext (org.teiid.translator.ExecutionContext)62 TranslationUtility (org.teiid.cdk.api.TranslationUtility)52 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)40 CommandBuilder (org.teiid.cdk.CommandBuilder)25 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)20 ResultSetExecution (org.teiid.translator.ResultSetExecution)18 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)17 UpdateExecution (org.teiid.translator.UpdateExecution)16 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 List (java.util.List)11 Connection (java.sql.Connection)10 LdapContext (javax.naming.ldap.LdapContext)9 Range (org.apache.accumulo.core.data.Range)9 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 MetadataFactory (org.teiid.metadata.MetadataFactory)8 ArrayList (java.util.ArrayList)7 FunctionTree (org.teiid.query.function.FunctionTree)7 UDFSource (org.teiid.query.function.UDFSource)7