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 * Interface to define how implementations can interact with column handling when constructing a bean from a 024 * {@link java.sql.ResultSet}. ColumnHandlers do the work of retrieving data correctly from the {@code ResultSet}. 025 */ 026public interface ColumnHandler { 027 /** 028 * Test whether this {@code ColumnHandler} wants to handle a column targeted for a value type matching 029 * {@code propType}. 030 * 031 * @param propType The type of the target parameter. 032 * @return true is this property handler can/wants to handle this value; false otherwise. 033 */ 034 boolean match(Class<?> propType); 035 036 /** 037 * Do the work required to retrieve and store a column from {@code ResultSet} into something of type 038 * {@code propType}. This method is called only if this handler responded {@code true} after a call to 039 * {@link #match(Class)}. 040 * 041 * @param rs The result set to get data from. This should be moved to the correct row already. 042 * @param columnIndex The position of the column to retrieve. 043 * @return The converted value or the original value if something doesn't work out. 044 * @throws SQLException if the columnIndex is not valid; if a database access error occurs or this method is 045 * called on a closed result set 046 */ 047 Object apply(ResultSet rs, int columnIndex) throws SQLException; 048}