1 16 17 package org.springframework.jdbc.core.support; 18 19 import java.io.IOException ; 20 import java.sql.ResultSet ; 21 import java.sql.SQLException ; 22 23 import org.springframework.dao.DataAccessException; 24 import org.springframework.dao.EmptyResultDataAccessException; 25 import org.springframework.dao.IncorrectResultSizeDataAccessException; 26 import org.springframework.jdbc.LobRetrievalFailureException; 27 import org.springframework.jdbc.core.ResultSetExtractor; 28 29 56 public abstract class AbstractLobStreamingResultSetExtractor implements ResultSetExtractor { 57 58 67 public final Object extractData(ResultSet rs) throws SQLException , DataAccessException { 68 if (!rs.next()) { 69 handleNoRowFound(); 70 } 71 else { 72 try { 73 streamData(rs); 74 if (rs.next()) { 75 handleMultipleRowsFound(); 76 } 77 } 78 catch (IOException ex) { 79 throw new LobRetrievalFailureException("Couldn't stream LOB content", ex); 80 } 81 } 82 return null; 83 } 84 85 91 protected void handleNoRowFound() throws DataAccessException { 92 throw new EmptyResultDataAccessException( 93 "LobStreamingResultSetExtractor did not find row in database", 1); 94 } 95 96 102 protected void handleMultipleRowsFound() throws DataAccessException { 103 throw new IncorrectResultSizeDataAccessException( 104 "LobStreamingResultSetExtractor found multiple rows in database", 1); 105 } 106 107 118 protected abstract void streamData(ResultSet rs) throws SQLException , IOException , DataAccessException; 119 120 } 121 | Popular Tags |