1 16 17 package org.springframework.jdbc.core; 18 19 import java.sql.ResultSet ; 20 import java.sql.SQLException ; 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import org.springframework.util.Assert; 25 26 60 public class RowMapperResultSetExtractor implements ResultSetExtractor { 61 62 private final RowMapper rowMapper; 63 64 private final int rowsExpected; 65 66 67 71 public RowMapperResultSetExtractor(RowMapper rowMapper) { 72 this(rowMapper, 0); 73 } 74 75 81 public RowMapperResultSetExtractor(RowMapper rowMapper, int rowsExpected) { 82 Assert.notNull(rowMapper, "RowMapper is required"); 83 this.rowMapper = rowMapper; 84 this.rowsExpected = rowsExpected; 85 } 86 87 88 public Object extractData(ResultSet rs) throws SQLException { 89 List results = (this.rowsExpected > 0 ? new ArrayList (this.rowsExpected) : new ArrayList ()); 90 int rowNum = 0; 91 while (rs.next()) { 92 results.add(this.rowMapper.mapRow(rs, rowNum++)); 93 } 94 return results; 95 } 96 97 } 98 | Popular Tags |