001/* 002 * Copyright 2002-2017 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; 018 019/** 020 * Object to represent a SQL parameter value, including parameter meta-data 021 * such as the SQL type and the scale for numeric values. 022 * 023 * <p>Designed for use with {@link JdbcTemplate}'s operations that take an array of 024 * argument values: Each such argument value may be a {@code SqlParameterValue}, 025 * indicating the SQL type (and optionally the scale) instead of letting the 026 * template guess a default type. Note that this only applies to the operations with 027 * a 'plain' argument array, not to the overloaded variants with an explicit type array. 028 * 029 * @author Juergen Hoeller 030 * @since 2.0.5 031 * @see java.sql.Types 032 * @see JdbcTemplate#query(String, Object[], ResultSetExtractor) 033 * @see JdbcTemplate#query(String, Object[], RowCallbackHandler) 034 * @see JdbcTemplate#query(String, Object[], RowMapper) 035 * @see JdbcTemplate#update(String, Object[]) 036 */ 037public class SqlParameterValue extends SqlParameter { 038 039 private final Object value; 040 041 042 /** 043 * Create a new SqlParameterValue, supplying the SQL type. 044 * @param sqlType SQL type of the parameter according to {@code java.sql.Types} 045 * @param value the value object 046 */ 047 public SqlParameterValue(int sqlType, Object value) { 048 super(sqlType); 049 this.value = value; 050 } 051 052 /** 053 * Create a new SqlParameterValue, supplying the SQL type. 054 * @param sqlType SQL type of the parameter according to {@code java.sql.Types} 055 * @param typeName the type name of the parameter (optional) 056 * @param value the value object 057 */ 058 public SqlParameterValue(int sqlType, String typeName, Object value) { 059 super(sqlType, typeName); 060 this.value = value; 061 } 062 063 /** 064 * Create a new SqlParameterValue, supplying the SQL type. 065 * @param sqlType SQL type of the parameter according to {@code java.sql.Types} 066 * @param scale the number of digits after the decimal point 067 * (for DECIMAL and NUMERIC types) 068 * @param value the value object 069 */ 070 public SqlParameterValue(int sqlType, int scale, Object value) { 071 super(sqlType, scale); 072 this.value = value; 073 } 074 075 /** 076 * Create a new SqlParameterValue based on the given SqlParameter declaration. 077 * @param declaredParam the declared SqlParameter to define a value for 078 * @param value the value object 079 */ 080 public SqlParameterValue(SqlParameter declaredParam, Object value) { 081 super(declaredParam); 082 this.value = value; 083 } 084 085 086 /** 087 * Return the value object that this parameter value holds. 088 */ 089 public Object getValue() { 090 return this.value; 091 } 092 093}