View Javadoc
1   /*
2    * Copyright 2002-2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.jdbc.core.namedparam;
18  
19  import org.springframework.jdbc.support.JdbcUtils;
20  
21  /**
22   * Interface that defines common functionality for objects that can
23   * offer parameter values for named SQL parameters, serving as argument
24   * for {@link NamedParameterJdbcTemplate} operations.
25   *
26   * <p>This interface allows for the specification of SQL type in addition
27   * to parameter values. All parameter values and types are identified by
28   * specifying the name of the parameter.
29   *
30   * <p>Intended to wrap various implementations like a Map or a JavaBean
31   * with a consistent interface.
32   *
33   * @author Thomas Risberg
34   * @author Juergen Hoeller
35   * @since 2.0
36   * @see NamedParameterJdbcOperations
37   * @see NamedParameterJdbcTemplate
38   * @see MapSqlParameterSource
39   * @see BeanPropertySqlParameterSource
40   */
41  public interface SqlParameterSource {
42  
43  	/**
44  	 * Constant that indicates an unknown (or unspecified) SQL type.
45  	 * To be returned from {@code getType} when no specific SQL type known.
46  	 * @see #getSqlType
47  	 * @see java.sql.Types
48  	 */
49  	int TYPE_UNKNOWN = JdbcUtils.TYPE_UNKNOWN;
50  
51  
52  	/**
53  	 * Determine whether there is a value for the specified named parameter.
54  	 * @param paramName the name of the parameter
55  	 * @return whether there is a value defined
56  	 */
57  	boolean hasValue(String paramName);
58  
59  	/**
60  	 * Return the parameter value for the requested named parameter.
61  	 * @param paramName the name of the parameter
62  	 * @return the value of the specified parameter
63  	 * @throws IllegalArgumentException if there is no value for the requested parameter
64  	 */
65  	Object getValue(String paramName) throws IllegalArgumentException;
66  
67  	/**
68  	 * Determine the SQL type for the specified named parameter.
69  	 * @param paramName the name of the parameter
70  	 * @return the SQL type of the specified parameter,
71  	 * or {@code TYPE_UNKNOWN} if not known
72  	 * @see #TYPE_UNKNOWN
73  	 */
74  	int getSqlType(String paramName);
75  
76  	/**
77  	 * Determine the type name for the specified named parameter.
78  	 * @param paramName the name of the parameter
79  	 * @return the type name of the specified parameter,
80  	 * or {@code null} if not known
81  	 */
82  	String getTypeName(String paramName);
83  
84  }