Search in sources :

Example 41 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestTeradataTranslator method testPositionalOrderByUnion1.

@Test
public void testPositionalOrderByUnion1() throws Exception {
    String input = "SELECT a as b from (SELECT intkey as a, stringkey as b from BQT1.smalla union SELECT intkey as a, stringkey as b from BQT1.smalla) as x order by x.b";
    String output = "SELECT v_0.c_0 FROM (SELECT g_1.IntKey AS c_0, g_1.StringKey AS c_1 FROM SmallA AS g_1 UNION SELECT g_0.IntKey AS c_0, g_0.StringKey AS c_1 FROM SmallA AS g_0) AS v_0 ORDER BY v_0.c_1";
    TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
    Command command = tu.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
}
Also used : Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 42 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestTeradataTranslator method testPositionalOrderBy.

@Test
public void testPositionalOrderBy() throws Exception {
    String input = "SELECT INTKEY, BIGDECIMALVALUE FROM BQT1.SmallA ORDER BY intkey";
    String output = "SELECT g_0.IntKey AS c_0, g_0.BigDecimalValue AS c_1 FROM SmallA AS g_0 ORDER BY 1";
    TranslationUtility tu = TranslationHelper.getTranslationUtility(TranslationHelper.BQT_VDB, null);
    Command command = tu.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, command);
}
Also used : Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Test(org.junit.Test)

Example 43 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestJPADirectQueryExecution method testWithoutMarker.

@Test
public void testWithoutMarker() throws Exception {
    String input = "exec native('jpa query')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    EntityManager connection = Mockito.mock(EntityManager.class);
    try {
        JPQLDirectQueryExecution execution = (JPQLDirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
        execution.execute();
        fail("the above should have thrown exception");
    } catch (TranslatorException e) {
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) TranslatorException(org.teiid.translator.TranslatorException) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 44 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestJPADirectQueryExecution method testCreate.

@Test
public void testCreate() throws Exception {
    String input = "exec native('create;', 'one')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    EntityManager connection = Mockito.mock(EntityManager.class);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    Mockito.stub(connection.merge(argument.capture())).toReturn(new String("one"));
    JPQLDirectQueryExecution execution = (JPQLDirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).merge(argument.capture());
    assertEquals("one", argument.getValue());
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Example 45 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestJPADirectQueryExecution method testDelete.

@Test
public void testDelete() throws Exception {
    String input = "exec native('delete;delete-query')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    EntityManager connection = Mockito.mock(EntityManager.class);
    Query query = Mockito.mock(Query.class);
    Mockito.stub(query.executeUpdate()).toReturn(12);
    Mockito.stub(connection.createQuery("delete-query")).toReturn(query);
    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    JPQLDirectQueryExecution execution = (JPQLDirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection, Mockito.times(1)).createQuery(argument.capture());
    assertEquals("delete-query", argument.getValue());
    assertArrayEquals(new Object[] { 12 }, (Object[]) execution.next().get(0));
}
Also used : EntityManager(javax.persistence.EntityManager) ExecutionContext(org.teiid.translator.ExecutionContext) Query(javax.persistence.Query) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) Test(org.junit.Test)

Aggregations

TranslationUtility (org.teiid.cdk.api.TranslationUtility)76 Command (org.teiid.language.Command)52 Test (org.junit.Test)45 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 ExecutionContext (org.teiid.translator.ExecutionContext)33 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)26 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 MetadataFactory (org.teiid.metadata.MetadataFactory)13 FunctionTree (org.teiid.query.function.FunctionTree)11 UDFSource (org.teiid.query.function.UDFSource)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 Before (org.junit.Before)10 LdapContext (javax.naming.ldap.LdapContext)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 List (java.util.List)7 ResultSetExecution (org.teiid.translator.ResultSetExecution)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataSource (javax.activation.DataSource)6 WSConnection (org.teiid.translator.WSConnection)6