Search in sources :

Example 26 with ExecutionContext

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

the class TestOracleTranslator method testOracleCommentPayload.

/**
 * Case 3744.  Test that an Oracle-specific db hint, delivered as a String via command
 * payload, is added to the translated SQL.
 *
 * @since 4.3
 */
@Test
public void testOracleCommentPayload() throws Exception {
    // $NON-NLS-1$
    String input = "SELECT part_name, rownum FROM parts";
    // $NON-NLS-1$
    String output = "SELECT /*+ ALL_ROWS */ PARTS.PART_NAME, ROWNUM FROM PARTS";
    // $NON-NLS-1$
    String hint = "/*+ ALL_ROWS */";
    // $NON-NLS-1$
    ExecutionContext context = new ExecutionContextImpl(null, 1, hint, null, "", 1, null, null);
    helpTestVisitor(getTestVDB(), input, context, null, output, false);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ExecutionContextImpl(org.teiid.dqp.internal.datamgr.ExecutionContextImpl) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Test(org.junit.Test)

Example 27 with ExecutionContext

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

the class TestOracleTranslator method testOracleCommentPayload1.

@Test
public void testOracleCommentPayload1() throws Exception {
    // $NON-NLS-1$
    String input = "SELECT part_name, rownum FROM parts";
    // $NON-NLS-1$
    String output = "SELECT PARTS.PART_NAME, ROWNUM FROM PARTS";
    // $NON-NLS-1$
    String hint = "/*+ ALL_ROWS */ something else";
    // $NON-NLS-1$
    ExecutionContext context = new ExecutionContextImpl(null, 1, hint, null, "", 1, null, null);
    helpTestVisitor(getTestVDB(), input, context, null, output, false);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) ExecutionContextImpl(org.teiid.dqp.internal.datamgr.ExecutionContextImpl) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Test(org.junit.Test)

Example 28 with ExecutionContext

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

the class TestLDAPDirectQueryExecution method testDelete.

@Test
public void testDelete() throws Exception {
    String input = "exec native('delete;uid=doe,ou=people,o=teiid.org')";
    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("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(ctx, Mockito.times(1)).destroySubcontext("uid=doe,ou=people,o=teiid.org");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) 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 29 with ExecutionContext

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

the class TestLDAPDirectQueryExecution method testCreateFail.

@Test(expected = TranslatorException.class)
public void testCreateFail() throws Exception {
    String input = "exec native('create;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one')";
    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("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) 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 30 with ExecutionContext

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

the class TestLDAPDirectQueryExecution method testSearch.

@Test
public void testSearch() throws Exception {
    String input = "exec native('search;context-name=corporate;filter=(objectClass=*);count-limit=5;timeout=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);
    LDAPDirectSearchQueryExecution execution = (LDAPDirectSearchQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    LDAPSearchDetails details = execution.getDelegate().getSearchDetails();
    assertEquals("corporate", details.getContextName());
    assertEquals("(objectClass=*)", details.getContextFilter());
    assertEquals(5, details.getCountLimit());
    assertEquals(6, details.getTimeLimit());
    assertEquals(1, details.getSearchScope());
    assertEquals(2, details.getElementList().size());
    assertEquals("uid", details.getElementList().get(0).getName());
    assertEquals("cn", details.getElementList().get(1).getName());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) 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)

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