001/*
002 * Copyright 2002-2016 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 */
045@FunctionalInterface
046public interface RowCallbackHandler {
047
048        /**
049         * Implementations must implement this method to process each row of data
050         * in the ResultSet. This method should not call {@code next()} on
051         * the ResultSet; it is only supposed to extract values of the current row.
052         * <p>Exactly what the implementation chooses to do is up to it:
053         * A trivial implementation might simply count rows, while another
054         * implementation might build an XML document.
055         * @param rs the ResultSet to process (pre-initialized for the current row)
056         * @throws SQLException if an SQLException is encountered getting
057         * column values (that is, there's no need to catch SQLException)
058         */
059        void processRow(ResultSet rs) throws SQLException;
060
061}