View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.dbutils;
18  
19  import java.sql.ResultSet;
20  import java.sql.SQLException;
21  import java.util.List;
22  import java.util.Map;
23  
24  /**
25   * {@code RowProcessor} implementations convert
26   * {@code ResultSet} rows into various other objects.  Implementations
27   * can extend {@code BasicRowProcessor} to protect themselves
28   * from changes to this interface.
29   *
30   * @see BasicRowProcessor
31   */
32  public interface RowProcessor {
33  
34      /**
35       * Create an {@code Object[]} from the column values in one
36       * {@code ResultSet} row.  The {@code ResultSet} should be
37       * positioned on a valid row before passing it to this method.
38       * Implementations of this method must not alter the row position of
39       * the {@code ResultSet}.
40       *
41       * @param resultSet ResultSet that supplies the array data
42       * @throws SQLException if a database access error occurs
43       * @return the newly created array
44       */
45      Object[] toArray(ResultSet resultSet) throws SQLException;
46  
47      /**
48       * Create a JavaBean from the column values in one {@code ResultSet}
49       * row.  The {@code ResultSet} should be positioned on a valid row before
50       * passing it to this method.  Implementations of this method must not
51       * alter the row position of the {@code ResultSet}.
52       * @param <T> The type of bean to create
53       * @param resultSet ResultSet that supplies the bean data
54       * @param type Class from which to create the bean instance
55       * @throws SQLException if a database access error occurs
56       * @return the newly created bean
57       */
58      <T> T toBean(ResultSet resultSet, Class<? extends T> type) throws SQLException;
59  
60      /**
61       * Create a {@code List} of JavaBeans from the column values in all
62       * {@code ResultSet} rows.  {@code ResultSet.next()} should
63       * <strong>not</strong> be called before passing it to this method.
64       * @param <T> The type of bean to create
65       * @param resultSet ResultSet that supplies the bean data
66       * @param type Class from which to create the bean instance
67       * @throws SQLException if a database access error occurs
68       * @return A {@code List} of beans with the given type in the order
69       * they were returned by the {@code ResultSet}.
70       */
71      <T> List<T> toBeanList(ResultSet resultSet, Class<? extends T> type) throws SQLException;
72  
73      /**
74       * Create a {@code Map} from the column values in one
75       * {@code ResultSet} row.  The {@code ResultSet} should be
76       * positioned on a valid row before
77       * passing it to this method.  Implementations of this method must not
78       * alter the row position of the {@code ResultSet}.
79       *
80       * @param resultSet ResultSet that supplies the map data
81       * @throws SQLException if a database access error occurs
82       * @return the newly created Map
83       */
84      Map<String, Object> toMap(ResultSet resultSet) throws SQLException;
85  
86  }