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; 021 022/** 023 * Defines how to process columns when constructing a bean from a {@link ResultSet}. Instances do the work of retrieving data from a {@code ResultSet}. 024 * 025 * @param <T> The return type. 026 */ 027public interface ColumnHandler<T> { 028 029 /** 030 * 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 031 * {@link #match(Class)} returns true. 032 * 033 * @param resultSet The source result set. This must be on the correct row. 034 * @param columnIndex The position of the column to retrieve, a 1-based index. 035 * @return The converted value or the original value if something doesn't work out. 036 * @throws SQLException if the columnIndex is not valid; if a database access error occurs or this method is called on a closed result set 037 */ 038 T apply(ResultSet resultSet, int columnIndex) throws SQLException; 039 040 /** 041 * Tests whether to handle a column targeted for a value type matching {@code propType}. 042 * 043 * @param propType The type of the target parameter. 044 * @return true is this property handler handles this {@code propType}; false otherwise. 045 */ 046 boolean match(Class<?> propType); 047}