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. import org.springframework.dao.DataAccessException;
  20. /**
  21. * Callback interface used by JdbcTemplate's query methods.
  22. * Implementations of this interface perform the actual work of extracting
  23. * results, but don't need to worry about exception handling. SQLExceptions
  24. * will be caught and handled correctly by the JdbcTemplate class.
  25. *
  26. * <p>This interface is mainly used within the JDBC framework.
  27. * A RowCallbackHandler is usually a simpler choice for ResultSet processing,
  28. * in particular a RowMapperResultReader in combination with a RowMapper.
  29. *
  30. * <p>Note: In contrast to a RowCallbackHandler, a ResultSetExtractor object
  31. * is typically stateless and thus reusable, as long as it doesn't access
  32. * stateful resources (like output streams when streaming LOB contents)
  33. * or keep result state within the object.
  34. *
  35. * @author Rod Johnson
  36. * @since April 24, 2003
  37. * @version $Id: ResultSetExtractor.java,v 1.6 2004/05/27 14:46:26 jhoeller Exp $
  38. * @see JdbcTemplate
  39. * @see RowCallbackHandler
  40. * @see RowMapperResultReader
  41. * @see org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor
  42. */
  43. public interface ResultSetExtractor {
  44. /**
  45. * Implementations must implement this method to process
  46. * all rows in the ResultSet.
  47. * @param rs ResultSet to extract data from. Implementations should
  48. * not close this: it will be closed by the JdbcTemplate.
  49. * @return an arbitrary result object, or null if none
  50. * (the extractor will typically be stateful in the latter case).
  51. * @throws SQLException if a SQLException is encountered getting column
  52. * values or navigating (that is, there's no need to catch SQLException)
  53. * @throws DataAccessException in case of custom exceptions
  54. */
  55. Object extractData(ResultSet rs) throws SQLException, DataAccessException;
  56. }