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
022import org.springframework.dao.DataAccessException;
023
024/**
025 * Callback interface used by {@link JdbcTemplate}'s query methods.
026 * Implementations of this interface perform the actual work of extracting
027 * results from a {@link java.sql.ResultSet}, but don't need to worry
028 * about exception handling. {@link java.sql.SQLException SQLExceptions}
029 * will be caught and handled by the calling JdbcTemplate.
030 *
031 * <p>This interface is mainly used within the JDBC framework itself.
032 * A {@link RowMapper} is usually a simpler choice for ResultSet processing,
033 * mapping one result object per row instead of one result object for
034 * the entire ResultSet.
035 *
036 * <p>Note: In contrast to a {@link RowCallbackHandler}, a ResultSetExtractor
037 * object is typically stateless and thus reusable, as long as it doesn't
038 * access stateful resources (such as output streams when streaming LOB
039 * contents) or keep result state within the object.
040 *
041 * @author Rod Johnson
042 * @author Juergen Hoeller
043 * @since April 24, 2003
044 * @see JdbcTemplate
045 * @see RowCallbackHandler
046 * @see RowMapper
047 * @see org.springframework.jdbc.core.support.AbstractLobStreamingResultSetExtractor
048 */
049public interface ResultSetExtractor<T> {
050
051        /**
052         * Implementations must implement this method to process the entire ResultSet.
053         * @param rs ResultSet to extract data from. Implementations should
054         * not close this: it will be closed by the calling JdbcTemplate.
055         * @return an arbitrary result object, or {@code null} if none
056         * (the extractor will typically be stateful in the latter case).
057         * @throws SQLException if a SQLException is encountered getting column
058         * values or navigating (that is, there's no need to catch SQLException)
059         * @throws DataAccessException in case of custom exceptions
060         */
061        T extractData(ResultSet rs) throws SQLException, DataAccessException;
062
063}