001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.dbutils;
018
019import java.sql.ResultSet;
020import java.sql.SQLException;
021import java.util.List;
022import java.util.Map;
023
024/**
025 * {@code RowProcessor} implementations convert
026 * {@code ResultSet} rows into various other objects.  Implementations
027 * can extend {@code BasicRowProcessor} to protect themselves
028 * from changes to this interface.
029 *
030 * @see BasicRowProcessor
031 */
032public interface RowProcessor {
033
034    /**
035     * Create an {@code Object[]} from the column values in one
036     * {@code ResultSet} row.  The {@code ResultSet} should be
037     * positioned on a valid row before passing it to this method.
038     * Implementations of this method must not alter the row position of
039     * the {@code ResultSet}.
040     *
041     * @param resultSet ResultSet that supplies the array data
042     * @throws SQLException if a database access error occurs
043     * @return the newly created array
044     */
045    Object[] toArray(ResultSet resultSet) throws SQLException;
046
047    /**
048     * Create a JavaBean from the column values in one {@code ResultSet}
049     * row.  The {@code ResultSet} should be positioned on a valid row before
050     * passing it to this method.  Implementations of this method must not
051     * alter the row position of the {@code ResultSet}.
052     * @param <T> The type of bean to create
053     * @param resultSet ResultSet that supplies the bean data
054     * @param type Class from which to create the bean instance
055     * @throws SQLException if a database access error occurs
056     * @return the newly created bean
057     */
058    <T> T toBean(ResultSet resultSet, Class<? extends T> type) throws SQLException;
059
060    /**
061     * Create a {@code List} of JavaBeans from the column values in all
062     * {@code ResultSet} rows.  {@code ResultSet.next()} should
063     * <strong>not</strong> be called before passing it to this method.
064     * @param <T> The type of bean to create
065     * @param resultSet ResultSet that supplies the bean data
066     * @param type Class from which to create the bean instance
067     * @throws SQLException if a database access error occurs
068     * @return A {@code List} of beans with the given type in the order
069     * they were returned by the {@code ResultSet}.
070     */
071    <T> List<T> toBeanList(ResultSet resultSet, Class<? extends T> type) throws SQLException;
072
073    /**
074     * Create a {@code Map} from the column values in one
075     * {@code ResultSet} row.  The {@code ResultSet} should be
076     * positioned on a valid row before
077     * passing it to this method.  Implementations of this method must not
078     * alter the row position of the {@code ResultSet}.
079     *
080     * @param resultSet ResultSet that supplies the map data
081     * @throws SQLException if a database access error occurs
082     * @return the newly created Map
083     */
084    Map<String, Object> toMap(ResultSet resultSet) throws SQLException;
085
086}