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. * Callback interface used by JdbcTemplate's query methods.
  21. * Implementations of this interface perform the actual work of extracting
  22. * results, but don't need to worry about exception handling. SQLExceptions
  23. * will be caught and handled correctly by the JdbcTemplate class.
  24. *
  25. * <p>In contrast to a ResultSetExtractor, a RowCallbackHandler object is
  26. * typically stateful: It keeps the result state within the object, to be
  27. * available for later inspection. See RowCountCallbackHandler's javadoc
  28. * for a usage example with JdbcTemplate.
  29. *
  30. * <p>The ResultReader subinterface allows to make a results list available
  31. * in a uniform manner. JdbcTemplate's query methods will return the results
  32. * list in that case, else returning null (-> result state is solely
  33. * available from RowCallbackHandler object).
  34. *
  35. * <p>A convenient out-of-the-box implementation of RowCallbackHandler is the
  36. * RowMapperResultReader adapter which delegates row mapping to a RowMapper.
  37. * Note that a RowMapper object is typically stateless and thus reusable;
  38. * just the RowMapperResultReader adapter is stateful.
  39. *
  40. * @author Rod Johnson
  41. * @see ResultSetExtractor
  42. * @see RowCountCallbackHandler
  43. * @see ResultReader
  44. * @see RowMapperResultReader
  45. * @see RowMapper
  46. */
  47. public interface RowCallbackHandler {
  48. /**
  49. * Implementations must implement this method to process each row of data
  50. * in the ResultSet. This method should not call next() on the ResultSet,
  51. * but extract the current values. Exactly what the implementation chooses
  52. * to do is up to it; a trivial implementation might simply count rows,
  53. * while another implementation might build an XML document.
  54. * @param rs the ResultSet to process
  55. * @throws SQLException if a SQLException is encountered getting
  56. * column values (that is, there's no need to catch SQLException)
  57. */
  58. void processRow(ResultSet rs) throws SQLException;
  59. }