001/*
002 * Copyright 2002-2012 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.jdbc.core;
018
019import java.sql.ResultSet;
020import java.sql.SQLException;
021
022/**
023 * An interface used by {@link JdbcTemplate} for processing rows of a
024 * {@link java.sql.ResultSet} on a per-row basis. Implementations of
025 * this interface perform the actual work of processing each row
026 * but don't need to worry about exception handling.
027 * {@link java.sql.SQLException SQLExceptions} will be caught and handled
028 * by the calling JdbcTemplate.
029 *
030 * <p>In contrast to a {@link ResultSetExtractor}, a RowCallbackHandler
031 * object is typically stateful: It keeps the result state within the
032 * object, to be available for later inspection. See
033 * {@link RowCountCallbackHandler} for a usage example.
034 *
035 * <p>Consider using a {@link RowMapper} instead if you need to map
036 * exactly one result object per row, assembling them into a List.
037 *
038 * @author Rod Johnson
039 * @author Juergen Hoeller
040 * @see JdbcTemplate
041 * @see RowMapper
042 * @see ResultSetExtractor
043 * @see RowCountCallbackHandler
044 */
045public interface RowCallbackHandler {
046
047        /**
048         * Implementations must implement this method to process each row of data
049         * in the ResultSet. This method should not call {@code next()} on
050         * the ResultSet; it is only supposed to extract values of the current row.
051         * <p>Exactly what the implementation chooses to do is up to it:
052         * A trivial implementation might simply count rows, while another
053         * implementation might build an XML document.
054         * @param rs the ResultSet to process (pre-initialized for the current row)
055         * @throws SQLException if a SQLException is encountered getting
056         * column values (that is, there's no need to catch SQLException)
057         */
058        void processRow(ResultSet rs) throws SQLException;
059
060}