static StatementImpl createMockStatement(int cursorType) throws SQLException { return createMockStatement(cursorType, withSettings()); }
@Before public void setUp() throws Exception { statement = TestResultSet.createMockStatement(TYPE_SCROLL_SENSITIVE); }
private ResultSetImpl helpGetResultSetImpl(int type) throws SQLException { ResultsMessage rsMsg = exampleResultsMsg2(); statement = TestResultSet.createMockStatement(type); ResultSetImpl rs = new ResultSetImpl(rsMsg, statement); return rs; }
private ResultSetImpl helpGetNoResults(int type) throws SQLException { ResultsMessage rsMsg = exampleResultsMsg3(); statement = TestResultSet.createMockStatement(type); ResultSetImpl rs = new ResultSetImpl(rsMsg, statement); return rs; }
private ResultSetImpl helpExecuteQuery(int fetchSize, int totalResults, int cursorType) throws SQLException, TeiidProcessingException { StatementImpl statement = createMockStatement(cursorType, withSettings().stubOnly()); return TestAllResultsImpl.helpTestBatching(statement, fetchSize, Math.min(fetchSize, totalResults), totalResults); }
@Test public void testForwardOnlyPrefetchSmallFetchSize() throws Exception { StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY); ResultSetImpl cs = TestAllResultsImpl.helpTestBatching(statement, 10, 128, 256, true); for (int i = 0; i < 256; i++) { cs.next(); cs.getObject(1); } Mockito.verify(statement.getDQP(), Mockito.atMost(1)).processCursorRequest(TestAllResultsImpl.REQUEST_ID, 11, 10); assertFalse(cs.next()); assertTrue(cs.isAfterLast()); cs.close(); }
@Test public void testXML() throws Exception { StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY); ResultsFuture<LobChunk> future = new ResultsFuture<LobChunk>(); future.getResultsReceiver().receiveResults(new LobChunk("<a/>".getBytes(Charset.forName("UTF-8")), true)); XMLType result = new XMLType(); Mockito.stub(statement.getDQP().requestNextLobChunk(0, 0, result.getReferenceStreamId())).toReturn(future); ResultsMessage resultsMsg = new ResultsMessage(); result.setEncoding("UTF-8"); resultsMsg.setResults(new List<?>[] {Arrays.asList(result)}); resultsMsg.setLastRow(1); resultsMsg.setFirstRow(1); resultsMsg.setFinalRow(1); resultsMsg.setColumnNames(new String[] {"x"}); //$NON-NLS-1$ resultsMsg.setDataTypes(new String[] {"xml"}); //$NON-NLS-1$ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement); cs.next(); assertEquals("<a/>", cs.getString(1)); }
@Test public void testOutputParameter() throws Exception { StatementImpl statement = createMockStatement(ResultSet.TYPE_FORWARD_ONLY); ResultsMessage resultsMsg = new ResultsMessage(); resultsMsg.setResults(new List<?>[] {Arrays.asList(1, null, null), Arrays.asList(null, 2, 3)}); resultsMsg.setLastRow(2); resultsMsg.setFirstRow(1); resultsMsg.setFinalRow(2); resultsMsg.setColumnNames(new String[] {"x", "out1", "out2"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ resultsMsg.setDataTypes(new String[] {"integer", "integer", "integer"}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ResultSetImpl cs = new ResultSetImpl(resultsMsg, statement, null, 2); int count = 0; while (cs.next()) { cs.getObject(1); count++; } assertEquals(1, count); assertTrue(cs.isAfterLast()); assertEquals(2, cs.getOutputParamValue(2)); assertEquals(3, cs.getOutputParamValue(3)); }