use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestOracleTranslator method testConcat2.
@Test
public void testConcat2() throws Exception {
// $NON-NLS-1$
String input = "select concat2(stringnum, stringkey) from bqt1.Smalla";
// $NON-NLS-1$
String output = "SELECT (g_0.StringNum || g_0.StringKey) FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestOracleTranslator method testNativeQueryProcPreparedExecution.
@Test
public void testNativeQueryProcPreparedExecution() throws Exception {
CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
Command command = commandBuilder.getCommand("call proc(2)");
Connection connection = Mockito.mock(Connection.class);
CallableStatement cs = Mockito.mock(CallableStatement.class);
Mockito.stub(cs.getUpdateCount()).toReturn(-1);
ResultSet rs = Mockito.mock(ResultSet.class);
Mockito.stub(cs.getObject(1)).toReturn(rs);
Mockito.stub(cs.getInt(3)).toReturn(4);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall("select x from y where z = ?")).toReturn(cs);
OracleExecutionFactory ef = new OracleExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
Mockito.verify(cs, Mockito.never()).registerOutParameter(1, OracleExecutionFactory.CURSOR_TYPE);
Mockito.verify(cs, Mockito.never()).getObject(1);
Mockito.verify(cs, Mockito.times(1)).setObject(1, 2, Types.INTEGER);
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestOracleTranslator method helpTestVisitor.
/**
* Helper method takes a QueryMetadataInterface impl instead of a VDB filename
* @throws TranslatorException
*/
private Command helpTestVisitor(QueryMetadataInterface metadata, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws TranslatorException {
// Convert from sql to objects
CommandBuilder commandBuilder = new CommandBuilder(metadata);
Command obj = commandBuilder.getCommand(input);
this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
return obj;
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestOracleTranslator method testConcat2_useLiteral.
@Test
public void testConcat2_useLiteral() throws Exception {
// $NON-NLS-1$
String input = "select concat2(stringnum,'_xx') from bqt1.Smalla";
// $NON-NLS-1$
String output = "SELECT (g_0.StringNum || '_xx') FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
use of org.teiid.cdk.CommandBuilder in project teiid by teiid.
the class TestOracleTranslator method testArrayComparison.
@Test
public void testArrayComparison() throws Exception {
// $NON-NLS-1$
String input = "select intkey from bqt1.smalla where intkey = 5";
// $NON-NLS-1$
String output = "SELECT g_0.IntKey FROM SmallA g_0 WHERE (g_0.IntKey, g_0.IntKey) = ((5, 2))";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Select obj = (Select) commandBuilder.getCommand(input, true, true);
Comparison comp = (Comparison) obj.getWhere();
// modify to an array comparison, since there is not yet parsing support
comp.setLeftExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getLeftExpression(), comp.getLeftExpression())));
comp.setRightExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getRightExpression(), new Literal(2, TypeFacility.RUNTIME_TYPES.INTEGER))));
TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Aggregations