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 */
017 package org.apache.commons.dbutils;
018
019 import java.sql.ResultSet;
020 import java.sql.SQLException;
021 import java.util.List;
022 import java.util.Map;
023
024 /**
025 * <code>RowProcessor</code> implementations convert
026 * <code>ResultSet</code> rows into various other objects. Implementations
027 * can extend <code>BasicRowProcessor</code> to protect themselves
028 * from changes to this interface.
029 *
030 * @see BasicRowProcessor
031 */
032 public interface RowProcessor {
033
034 /**
035 * Create an <code>Object[]</code> from the column values in one
036 * <code>ResultSet</code> row. The <code>ResultSet</code> 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</code>.
040 *
041 * @param rs 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 rs) throws SQLException;
046
047 /**
048 * Create a JavaBean from the column values in one <code>ResultSet</code>
049 * row. The <code>ResultSet</code> 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</code>.
052 * @param <T> The type of bean to create
053 * @param rs 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 rs, Class<T> type) throws SQLException;
059
060 /**
061 * Create a <code>List</code> of JavaBeans from the column values in all
062 * <code>ResultSet</code> rows. <code>ResultSet.next()</code> should
063 * <strong>not</strong> be called before passing it to this method.
064 * @param <T> The type of bean to create
065 * @param rs 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</code> of beans with the given type in the order
069 * they were returned by the <code>ResultSet</code>.
070 */
071 <T> List<T> toBeanList(ResultSet rs, Class<T> type) throws SQLException;
072
073 /**
074 * Create a <code>Map</code> from the column values in one
075 * <code>ResultSet</code> row. The <code>ResultSet</code> 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</code>.
079 *
080 * @param rs 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 rs) throws SQLException;
085
086 }