/** * Delegates to handleNoRowFound, handleMultipleRowsFound and streamData, * according to the ResultSet state. Converts an IOException thrown by * streamData to a LobRetrievalFailureException. * @see #handleNoRowFound * @see #handleMultipleRowsFound * @see #streamData * @see org.springframework.jdbc.LobRetrievalFailureException */ @Override @Nullable public final T extractData(ResultSet rs) throws SQLException, DataAccessException { if (!rs.next()) { handleNoRowFound(); } else { try { streamData(rs); if (rs.next()) { handleMultipleRowsFound(); } } catch (IOException ex) { throw new LobRetrievalFailureException("Couldn't stream LOB content", ex); } } return null; }
@Test public void testAbstractLobStreamingResultSetExtractorNoRows() throws SQLException { ResultSet rset = mock(ResultSet.class); AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false); thrown.expect(IncorrectResultSizeDataAccessException.class); try { lobRse.extractData(rset); } finally { verify(rset).next(); } }
@Test public void testAbstractLobStreamingResultSetExtractorCorrectException() throws SQLException { ResultSet rset = mock(ResultSet.class); given(rset.next()).willReturn(true); AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(true); thrown.expect(LobRetrievalFailureException.class); lobRse.extractData(rset); }
/** * Delegates to handleNoRowFound, handleMultipleRowsFound and streamData, * according to the ResultSet state. Converts an IOException thrown by * streamData to a LobRetrievalFailureException. * @see #handleNoRowFound * @see #handleMultipleRowsFound * @see #streamData * @see org.springframework.jdbc.LobRetrievalFailureException */ public final Object extractData(ResultSet rs) throws SQLException, DataAccessException { if (!rs.next()) { handleNoRowFound(); } else { try { streamData(rs); if (rs.next()) { handleMultipleRowsFound(); } } catch (IOException ex) { throw new LobRetrievalFailureException("Couldn't stream LOB content", ex); } } return null; }
@Test public void testAbstractLobStreamingResultSetExtractorOneRow() throws SQLException { ResultSet rset = mock(ResultSet.class); given(rset.next()).willReturn(true, false); AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false); lobRse.extractData(rset); verify(rset).clearWarnings(); }
/** * Delegates to handleNoRowFound, handleMultipleRowsFound and streamData, * according to the ResultSet state. Converts an IOException thrown by * streamData to a LobRetrievalFailureException. * @see #handleNoRowFound * @see #handleMultipleRowsFound * @see #streamData * @see org.springframework.jdbc.LobRetrievalFailureException */ @Override @Nullable public final T extractData(ResultSet rs) throws SQLException, DataAccessException { if (!rs.next()) { handleNoRowFound(); } else { try { streamData(rs); if (rs.next()) { handleMultipleRowsFound(); } } catch (IOException ex) { throw new LobRetrievalFailureException("Couldn't stream LOB content", ex); } } return null; }
@Test public void testAbstractLobStreamingResultSetExtractorMultipleRows() throws SQLException { ResultSet rset = mock(ResultSet.class); given(rset.next()).willReturn(true, true, false); AbstractLobStreamingResultSetExtractor<Void> lobRse = getResultSetExtractor(false); thrown.expect(IncorrectResultSizeDataAccessException.class); try { lobRse.extractData(rset); } finally { verify(rset).clearWarnings(); } }