use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestAllResultsImpl method exampleMessage.
private ResultsMessage exampleMessage(List<Object>[] results, String[] columnNames, String[] datatypes) {
RequestMessage request = new RequestMessage();
request.setExecutionId(REQUEST_ID);
ResultsMessage resultsMsg = new ResultsMessage();
resultsMsg.setResults(results);
resultsMsg.setColumnNames(columnNames);
resultsMsg.setDataTypes(datatypes);
resultsMsg.setFinalRow(results.length);
resultsMsg.setLastRow(results.length);
resultsMsg.setFirstRow(1);
return resultsMsg;
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestAllResultsImpl method testGetters.
@Test
public void testGetters() throws SQLException {
// $NON-NLS-1$
TimeZone.setDefault(TimeZone.getTimeZone("GMT-05:00"));
ResultsMessage message = exampleMessage(// $NON-NLS-1$
new List[] { Arrays.asList(1, TimestampUtil.createTime(0, 0, 0), TimestampUtil.createDate(1, 1, 1), TimestampUtil.createTimestamp(1, 1, 1, 1, 1, 1, 1), "<root/>") }, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
new String[] { "int", "time", "date", "timestamp", "sqlxml" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.TIME, DataTypeManager.DefaultDataTypes.DATE, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.STRING });
// $NON-NLS-1$
TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("GMT-06:00"));
ResultSetImpl rs = new ResultSetImpl(message, statement);
assertTrue(rs.next());
assertEquals(Boolean.TRUE.booleanValue(), rs.getBoolean(1));
assertEquals(1, rs.getShort(1));
assertEquals(1, rs.getInt(1));
assertEquals(1l, rs.getLong(1));
assertEquals(1f, rs.getFloat(1), 0);
assertEquals(1d, rs.getDouble(1), 0);
// $NON-NLS-1$
assertEquals("1", rs.getString(1));
assertEquals(Integer.valueOf(1), rs.getObject(1));
// the mock statement is in GMT-6 the server results are from GMT-5, so we expect them to display the same
assertEquals(TimestampUtil.createTime(0, 0, 0), rs.getTime(2));
assertEquals(TimestampUtil.createDate(1, 1, 1), rs.getDate(3));
assertEquals(TimestampUtil.createTimestamp(1, 1, 1, 1, 1, 1, 1), rs.getTimestamp(4));
// $NON-NLS-1$
assertEquals("<root/>", rs.getSQLXML(5).getString());
try {
rs.getSQLXML(1);
} catch (SQLException e) {
// $NON-NLS-1$
assertEquals("Unable to transform the column value 1 to a SQLXML.", e.getMessage());
}
assertFalse(rs.next());
TimestampWithTimezone.resetCalendar(null);
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestAllResultsImpl method testResultsMessageException.
@Test(expected = TeiidSQLException.class)
public void testResultsMessageException() throws Exception {
// $NON-NLS-1$
ResultsMessage resultsMsg = exampleMessage(exampleResults1(1), new String[] { "IntNum" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
resultsMsg.setFinalRow(-1);
ResultsMessage next = new ResultsMessage();
next.setException(new Throwable());
ResultsFuture<ResultsMessage> rf = new ResultsFuture<ResultsMessage>();
rf.getResultsReceiver().receiveResults(next);
Mockito.stub(statement.getDQP().processCursorRequest(0, 2, 0)).toReturn(rf);
ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2);
cs.next();
cs.next();
}
use of org.teiid.client.ResultsMessage in project teiid by teiid.
the class TestCallableStatement method testGetOutputParameter.
@Test
public void testGetOutputParameter() throws Exception {
CallableStatementImpl mmcs = getCallableStatement();
RequestMessage request = new RequestMessage();
request.setExecutionId(1);
ResultsMessage resultsMsg = new ResultsMessage();
List<?>[] results = new List[] { Arrays.asList(null, null, null), Arrays.asList(null, 1, 2) };
resultsMsg.setResults(results);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
resultsMsg.setColumnNames(new String[] { "IntNum", "Out1", "Out2" });
resultsMsg.setDataTypes(new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.INTEGER });
resultsMsg.setFinalRow(results.length);
resultsMsg.setLastRow(results.length);
resultsMsg.setFirstRow(1);
resultsMsg.setParameters(Arrays.asList(new ParameterInfo(ParameterInfo.RESULT_SET, 1), new ParameterInfo(ParameterInfo.OUT, 1), new ParameterInfo(ParameterInfo.OUT, 1)));
mmcs.createResultSet(resultsMsg);
assertEquals(1, mmcs.getInt(1));
assertEquals(2, mmcs.getInt(2));
assertEquals(1, mmcs.getInt("Out1"));
assertEquals(2, mmcs.getInt("Out2"));
}
Aggregations