use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestJDBCDirectQueryExecution method testPrepareExecution.
@Test
public void testPrepareExecution() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('select * from Source where e1 = ?', 2)");
Connection connection = Mockito.mock(Connection.class);
PreparedStatement stmt = Mockito.mock(PreparedStatement.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(stmt.execute()).toReturn(true);
Mockito.stub(rs.getMetaData()).toReturn(rsm);
Mockito.stub(rsm.getColumnCount()).toReturn(2);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("select * from Source where e1 = ?")).toReturn(stmt);
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, new FakeExecutionContextImpl(), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
Mockito.verify(stmt).setObject(1, 2);
assertArrayEquals(new Object[] { 5, "five" }, (Object[]) execution.next().get(0));
}
use of org.teiid.translator.ResultSetExecution 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.translator.ResultSetExecution in project teiid by teiid.
the class TestJDBCDirectQueryExecution method testPrepareUpdateCount.
@Test
public void testPrepareUpdateCount() throws Exception {
// $NON-NLS-1$
Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('update source set e1=? where e2 = ?', 2, 'foo')");
Connection connection = Mockito.mock(Connection.class);
PreparedStatement stmt = Mockito.mock(PreparedStatement.class);
ResultSet rs = Mockito.mock(ResultSet.class);
ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
Mockito.stub(stmt.getUpdateCount()).toReturn(-1);
Mockito.stub(stmt.getUpdateCount()).toReturn(5);
Mockito.stub(stmt.execute()).toReturn(false);
Mockito.stub(rs.getMetaData()).toReturn(rsm);
Mockito.stub(rsm.getColumnCount()).toReturn(2);
// $NON-NLS-1$
Mockito.stub(connection.prepareStatement("update source set e1=? where e2 = ?")).toReturn(stmt);
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, new FakeExecutionContextImpl(), Mockito.mock(RuntimeMetadata.class), connection);
execution.execute();
assertArrayEquals(new Object[] { 5 }, (Object[]) execution.next().get(0));
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestMongoDBDirectQueryExecution method testShellDirect.
@Test
public void testShellDirect() throws Exception {
Command cmd = this.utility.parseCommand("SELECT * FROM Customers");
MongoDBConnection connection = Mockito.mock(MongoDBConnection.class);
ExecutionContext context = Mockito.mock(ExecutionContext.class);
DBCollection dbCollection = Mockito.mock(DBCollection.class);
DB db = Mockito.mock(DB.class);
Mockito.stub(db.getCollection("MyTable")).toReturn(dbCollection);
Mockito.stub(db.collectionExists(Mockito.anyString())).toReturn(true);
Mockito.stub(connection.getDatabase()).toReturn(db);
Argument arg = new Argument(Direction.IN, null, String.class, null);
arg.setArgumentValue(new Literal("$ShellCmd;MyTable;remove;{ qty: { $gt: 20 }}", String.class));
ResultSetExecution execution = this.translator.createDirectExecution(Arrays.asList(arg), cmd, context, this.utility.createRuntimeMetadata(), connection);
execution.execute();
Mockito.verify(dbCollection).remove(QueryBuilder.start("qty").greaterThan(20).get());
}
use of org.teiid.translator.ResultSetExecution in project teiid by teiid.
the class TestODataQueryExecution method testExpandBasedInnerJoin.
@Test
public void testExpandBasedInnerJoin() throws Exception {
String query = "select p.UserName, pf.UserName from People p JOIN People_Friends pf " + "ON p.UserName = pf.People_UserName WHERE p.UserName= 'russellwhyte'";
String expectedURL = "People?$select=UserName&$filter=UserName eq 'russellwhyte'" + "&$expand=Friends($select=UserName)";
FileReader reader = new FileReader(UnitTestUtil.getTestDataFile("russel-friends.json"));
ResultSetExecution excution = helpExecute(TestODataMetadataProcessor.tripPinMetadata(), query, ObjectConverterUtil.convertToString(reader), expectedURL);
reader.close();
assertArrayEquals(new Object[] { "russellwhyte", "scottketchum" }, excution.next().toArray(new Object[2]));
assertArrayEquals(new Object[] { "russellwhyte", "ronaldmundy" }, excution.next().toArray(new Object[2]));
assertArrayEquals(new Object[] { "russellwhyte", "javieralfred" }, excution.next().toArray(new Object[2]));
assertArrayEquals(new Object[] { "russellwhyte", "angelhuffman" }, excution.next().toArray(new Object[2]));
}
Aggregations