use of org.teiid.language.Command in project teiid by teiid.
the class TestJDBCDirectQueryExecution method testSelectExecution.
@Test
public void testSelectExecution() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('select * from Source')");
Connection connection = Mockito.mock(Connection.class);
Statement stmt = Mockito.mock(Statement.class);
ResultSet rs = Mockito.mock(ResultSet.class);
ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
Mockito.stub(stmt.getUpdateCount()).toReturn(-1);
Mockito.stub(stmt.getResultSet()).toReturn(rs);
Mockito.stub(rs.getMetaData()).toReturn(rsm);
Mockito.stub(rsm.getColumnCount()).toReturn(2);
// $NON-NLS-1$
Mockito.stub(connection.createStatement()).toReturn(stmt);
Mockito.stub(stmt.execute("select * from Source")).toReturn(true);
Mockito.stub(rs.next()).toReturn(true);
Mockito.stub(rs.getObject(1)).toReturn(5);
Mockito.stub(rs.getObject(2)).toReturn("five");
DatabaseMetaData dbmd = Mockito.mock(DatabaseMetaData.class);
Mockito.stub(connection.getMetaData()).toReturn(dbmd);
JDBCExecutionFactory ef = new JDBCExecutionFactory();
ef.setSupportsDirectQueryProcedure(true);
ResultSetExecution execution = (ResultSetExecution) ef.createExecution(command, Mockito.mock(ExecutionContext.class), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] { 5, "five" }, (Object[]) execution.next().get(0));
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestJDBCProcedureExecution method testProcedureExecution1.
@Test
public void testProcedureExecution1() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "exec pm2.spTest8(1)");
Connection connection = Mockito.mock(Connection.class);
CallableStatement cs = Mockito.mock(CallableStatement.class);
Mockito.stub(cs.getUpdateCount()).toReturn(-1);
Mockito.stub(cs.getInt(2)).toReturn(5);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall("{call spTest8(?,?)}")).toReturn(cs);
JDBCExecutionFactory config = new JDBCExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), config);
procedureExecution.execute();
assertEquals(Arrays.asList(5), procedureExecution.getOutputParameterValues());
Mockito.verify(cs, Mockito.times(1)).registerOutParameter(2, Types.INTEGER);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestJDBCProcedureExecution method testProcedureExecution.
@Test
public void testProcedureExecution() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "exec pm2.spTest8a()");
Connection connection = Mockito.mock(Connection.class);
CallableStatement cs = Mockito.mock(CallableStatement.class);
Mockito.stub(cs.getUpdateCount()).toReturn(-1);
Mockito.stub(cs.getInt(1)).toReturn(5);
// $NON-NLS-1$
Mockito.stub(connection.prepareCall("{call spTest8a(?)}")).toReturn(cs);
JDBCExecutionFactory ef = new JDBCExecutionFactory();
JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
procedureExecution.execute();
assertEquals(Arrays.asList(5), procedureExecution.getOutputParameterValues());
Mockito.verify(cs, Mockito.times(1)).registerOutParameter(1, Types.INTEGER);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSqlServerConversionVisitor method testRecursiveCTEWithTypeMatching.
@Test
public void testRecursiveCTEWithTypeMatching() throws Exception {
String input = "with a (intkey, stringkey, bigintegervalue) as (select intkey, NULL as stringkey, bigintegervalue from bqt1.smalla where intkey = 1 " + "union all " + " select n.intkey, n.stringkey, 1 from bqt1.smalla n inner join a rcte on n.intkey = rcte.intkey + 1) " + "select * from a";
String output = "WITH a (intkey, stringkey, bigintegervalue) AS (SELECT cast(g_2.IntKey AS int) AS c_0, cast(NULL AS char) AS c_1, cast(g_2.BigIntegerValue AS numeric(38, 0)) AS c_2 FROM SmallA g_2 WHERE g_2.IntKey = 1 UNION ALL SELECT cast(g_0.IntKey AS int) AS c_0, g_0.StringKey AS c_1, cast(1 AS numeric(38, 0)) AS c_2 FROM SmallA g_0 INNER JOIN a g_1 ON g_0.IntKey = (g_1.intkey + 1)) SELECT g_3.intkey, g_3.stringkey, g_3.bigintegervalue FROM a g_3";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, trans, obj);
}
use of org.teiid.language.Command in project teiid by teiid.
the class TestSqlServerConversionVisitor method testParseFormat.
@Test
public void testParseFormat() throws Exception {
// $NON-NLS-1$
String input = "select parsetimestamp(smalla.timestampvalue, 'yyyy.MM.dd'), formattimestamp(smalla.timestampvalue, 'yy.MM.dd') from bqt1.smalla";
// $NON-NLS-1$
String output = "SELECT CONVERT(DATETIME, convert(varchar, g_0.TimestampValue, 21), 102), CONVERT(VARCHAR, g_0.TimestampValue, 2) FROM SmallA g_0";
CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand(input, true, true);
TranslationHelper.helpTestVisitor(output, trans, obj);
}
Aggregations