Search in sources :

Example 31 with TranslationUtility

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

the class TestModeShapeSqlTranslator method setUp.

@BeforeClass
public static void setUp() throws TranslatorException {
    TRANSLATOR = new ModeShapeExecutionFactory();
    TRANSLATOR.setUseBindVariables(false);
    TRANSLATOR.start();
    UTIL = new TranslationUtility(getMetadata());
    TranslationHelper.loadUDFs(UDF, UTIL);
}
Also used : TranslationUtility(org.teiid.cdk.api.TranslationUtility) BeforeClass(org.junit.BeforeClass)

Example 32 with TranslationUtility

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

the class TestSqlServerConversionVisitor method testUniqueidentifier.

@Test
public void testUniqueidentifier() throws Exception {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema foo = RealMetadataFactory.createPhysicalModel("foo", metadataStore);
    // $NON-NLS-1$
    Table table = RealMetadataFactory.createPhysicalGroup("bar", foo);
    String[] elemNames = new String[] { // $NON-NLS-1$
    "x" };
    String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING };
    List<Column> cols = RealMetadataFactory.createElements(table, elemNames, elemTypes);
    Column obj = cols.get(0);
    // $NON-NLS-1$
    obj.setNativeType("uniqueidentifier");
    CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
    QueryMetadataInterface metadata = new TransformationMetadata(null, store, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
    TranslationUtility tu = new TranslationUtility(metadata);
    // $NON-NLS-1$
    Command command = tu.parseCommand("select max(x) from bar");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT MAX(bar.x) FROM bar", trans, command);
    // $NON-NLS-1$
    command = tu.parseCommand("select * from (select max(x) as max from bar) x");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(bar.x) AS max FROM bar) x", trans, command);
    // $NON-NLS-1$
    command = tu.parseCommand("insert into bar (x) values ('a')");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("INSERT INTO bar (x) VALUES ('a')", trans, command);
    trans = new SQLServerExecutionFactory();
    trans.setDatabaseVersion(SQLServerExecutionFactory.V_2000);
    trans.start();
    // $NON-NLS-1$
    command = tu.parseCommand("select max(x) from bar");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT MAX(cast(bar.x as char(36))) FROM bar", trans, command);
    // $NON-NLS-1$
    command = tu.parseCommand("select * from (select max(x) as max from bar) x");
    // $NON-NLS-1$
    TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(cast(bar.x as char(36))) AS max FROM bar) x", trans, command);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataStore(org.teiid.metadata.MetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Column(org.teiid.metadata.Column) Command(org.teiid.language.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 33 with TranslationUtility

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

the class TestOracleTranslator method helpTestVisitor.

private void helpTestVisitor(String vdb, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput, boolean correctNaming) throws TranslatorException {
    // Convert from sql to objects
    TranslationUtility util = new TranslationUtility(vdb);
    Command obj = util.parseCommand(input, correctNaming, true);
    this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) TranslationUtility(org.teiid.cdk.api.TranslationUtility)

Example 34 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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 35 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility 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)

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