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 22 /** 23 * Defines how to process columns when constructing a bean from a {@link ResultSet}. Instances do the work of retrieving data from a {@code ResultSet}. 24 * 25 * @param <T> The return type. 26 */ 27 public interface ColumnHandler<T> { 28 29 /** 30 * Retrieves the current row's column value from a {@link ResultSet} and stores it into an instance of {@code propType}. This method is only called if 31 * {@link #match(Class)} returns true. 32 * 33 * @param resultSet The source result set. This must be on the correct row. 34 * @param columnIndex The position of the column to retrieve, a 1-based index. 35 * @return The converted value or the original value if something doesn't work out. 36 * @throws SQLException if the columnIndex is not valid; if a database access error occurs or this method is called on a closed result set 37 */ 38 T apply(ResultSet resultSet, int columnIndex) throws SQLException; 39 40 /** 41 * Tests whether to handle a column targeted for a value type matching {@code propType}. 42 * 43 * @param propType The type of the target parameter. 44 * @return true is this property handler handles this {@code propType}; false otherwise. 45 */ 46 boolean match(Class<?> propType); 47 }