1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.jdbc.core;
  17. import java.sql.ResultSet;
  18. import java.sql.SQLException;
  19. /**
  20. * An interface used by JdbcTemplate for mapping returned result sets.
  21. * Implementations of this interface perform the actual work of mapping
  22. * rows, but don't need to worry about exception handling. SQLExceptions
  23. * will be caught and handled correctly by the JdbcTemplate class.
  24. *
  25. * <p>Typically used either for JdbcTemplate's query methods (with
  26. * RowMapperResultReader adapters) or for out parameters of stored procedures.
  27. * RowMapper objects are typically stateless and thus reusable; they are
  28. * ideal choices for implementing row-mapping logic in a single place.
  29. *
  30. * <p>Alternatively, consider subclassing MappingSqlQuery from the jdbc.object
  31. * package: Instead of working with separate JdbcTemplate and RowMapper objects,
  32. * you can have executable query objects (containing row-mapping logic) there.
  33. *
  34. * @author Thomas Risberg
  35. * @see JdbcTemplate
  36. * @see RowMapperResultReader
  37. * @see org.springframework.jdbc.object.MappingSqlQuery
  38. */
  39. public interface RowMapper {
  40. /**
  41. * Implementations must implement this method to map each row of data
  42. * in the ResultSet. This method should not call next() on the ResultSet,
  43. * but extract the current values.
  44. * @param rs the ResultSet to map
  45. * @param rowNum The number of the current row
  46. * @throws SQLException if a SQLException is encountered getting
  47. * column values (that is, there's no need to catch SQLException)
  48. */
  49. Object mapRow(ResultSet rs, int rowNum) throws SQLException;
  50. }