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);
}
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);
}
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);
}
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");
}
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();
}
Aggregations