001/* 002 * Copyright 2002-2012 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.jdbc.core.namedparam; 018 019import org.springframework.jdbc.support.JdbcUtils; 020 021/** 022 * Interface that defines common functionality for objects that can 023 * offer parameter values for named SQL parameters, serving as argument 024 * for {@link NamedParameterJdbcTemplate} operations. 025 * 026 * <p>This interface allows for the specification of SQL type in addition 027 * to parameter values. All parameter values and types are identified by 028 * specifying the name of the parameter. 029 * 030 * <p>Intended to wrap various implementations like a Map or a JavaBean 031 * with a consistent interface. 032 * 033 * @author Thomas Risberg 034 * @author Juergen Hoeller 035 * @since 2.0 036 * @see NamedParameterJdbcOperations 037 * @see NamedParameterJdbcTemplate 038 * @see MapSqlParameterSource 039 * @see BeanPropertySqlParameterSource 040 */ 041public interface SqlParameterSource { 042 043 /** 044 * Constant that indicates an unknown (or unspecified) SQL type. 045 * To be returned from {@code getType} when no specific SQL type known. 046 * @see #getSqlType 047 * @see java.sql.Types 048 */ 049 int TYPE_UNKNOWN = JdbcUtils.TYPE_UNKNOWN; 050 051 052 /** 053 * Determine whether there is a value for the specified named parameter. 054 * @param paramName the name of the parameter 055 * @return whether there is a value defined 056 */ 057 boolean hasValue(String paramName); 058 059 /** 060 * Return the parameter value for the requested named parameter. 061 * @param paramName the name of the parameter 062 * @return the value of the specified parameter 063 * @throws IllegalArgumentException if there is no value for the requested parameter 064 */ 065 Object getValue(String paramName) throws IllegalArgumentException; 066 067 /** 068 * Determine the SQL type for the specified named parameter. 069 * @param paramName the name of the parameter 070 * @return the SQL type of the specified parameter, 071 * or {@code TYPE_UNKNOWN} if not known 072 * @see #TYPE_UNKNOWN 073 */ 074 int getSqlType(String paramName); 075 076 /** 077 * Determine the type name for the specified named parameter. 078 * @param paramName the name of the parameter 079 * @return the type name of the specified parameter, 080 * or {@code null} if not known 081 */ 082 String getTypeName(String paramName); 083 084}