Search in sources :

Example 1 with Execution

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

the class TestLDAPDirectQueryExecution method testWithoutMarker.

@Test(expected = TranslatorException.class)
public void testWithoutMarker() throws Exception {
    String input = "exec native('context-name=corporate;filter=(objectClass=*);count-limit=5;timout=6;search-scope=ONELEVEL_SCOPE;attributes=uid,cn')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("corporate")).toReturn(ctx);
    Execution execution = TRANSLATOR.createExecution(command, ec, rm, connection);
    assertTrue(!(execution instanceof LDAPDirectSearchQueryExecution));
    execution.execute();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Execution(org.teiid.translator.Execution) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 2 with Execution

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

the class TestEmbeddedMongoExecution method executeCmd.

private Execution executeCmd(String sql) throws Exception {
    Command cmd = utility.parseCommand(sql);
    CommandContext cc = Mockito.mock(CommandContext.class);
    Mockito.stub(cc.isReturnAutoGeneratedKeys()).toReturn(false);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    Mockito.stub(ec.getCommandContext()).toReturn(cc);
    Execution exec = translator.createExecution(cmd, ec, utility.createRuntimeMetadata(), this.connection);
    exec.execute();
    return exec;
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Execution(org.teiid.translator.Execution) CommandContext(org.teiid.CommandContext) Command(org.teiid.language.Command)

Example 3 with Execution

use of org.teiid.translator.Execution 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 4 with Execution

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

the class TestAccumuloQueryExecution method executeCmd.

private Execution executeCmd(String sql) throws TranslatorException {
    Command cmd = TestAccumuloQueryExecution.utility.parseCommand(sql);
    Execution exec = translator.createExecution(cmd, Mockito.mock(ExecutionContext.class), utility.createRuntimeMetadata(), TestAccumuloQueryExecution.connection);
    exec.execute();
    return exec;
}
Also used : Execution(org.teiid.translator.Execution) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command)

Example 5 with Execution

use of org.teiid.translator.Execution 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)

Aggregations

Execution (org.teiid.translator.Execution)7 Command (org.teiid.language.Command)6 ExecutionContext (org.teiid.translator.ExecutionContext)6 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)4 ResultSetExecution (org.teiid.translator.ResultSetExecution)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Test (org.junit.Test)2 TranslationUtility (org.teiid.cdk.api.TranslationUtility)2 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)1 QueryResult (com.sforce.soap.partner.QueryResult)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 LdapContext (javax.naming.ldap.LdapContext)1 BeforeClass (org.junit.BeforeClass)1 CommandContext (org.teiid.CommandContext)1 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)1 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)1 DeployVDBParameter (org.teiid.jdbc.FakeServer.DeployVDBParameter)1 FunctionMethod (org.teiid.metadata.FunctionMethod)1