01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
18:
19: /**
20: * Object to represent a SQL parameter value, including parameter metadata
21: * such as the SQL type and the scale for numeric values.
22: *
23: * <p>Designed for use with {@link JdbcTemplate}'s operations that take an array of
24: * argument values: Each such argument value may be a <code>SqlParameterValue</code>,
25: * indicating the SQL type (and optionally the scale) instead of letting the
26: * template guess a default type. Note that this only applies to the operations with
27: * a 'plain' argument array, not to the overloaded variants with an explicit type array.
28: *
29: * @author Juergen Hoeller
30: * @since 2.0.5
31: * @see java.sql.Types
32: * @see JdbcTemplate#query(String, Object[], ResultSetExtractor)
33: * @see JdbcTemplate#query(String, Object[], RowCallbackHandler)
34: * @see JdbcTemplate#query(String, Object[], RowMapper)
35: * @see JdbcTemplate#update(String, Object[])
36: */
37: public class SqlParameterValue extends SqlParameter {
38:
39: private final Object value;
40:
41: /**
42: * Create a new SqlParameterValue, supplying the SQL type.
43: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
44: * @param value the value object
45: */
46: public SqlParameterValue(int sqlType, Object value) {
47: super (sqlType);
48: this .value = value;
49: }
50:
51: /**
52: * Create a new SqlParameterValue, supplying the SQL type.
53: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
54: * @param typeName the type name of the parameter (optional)
55: * @param value the value object
56: */
57: public SqlParameterValue(int sqlType, String typeName, Object value) {
58: super (sqlType, typeName);
59: this .value = value;
60: }
61:
62: /**
63: * Create a new SqlParameterValue, supplying the SQL type.
64: * @param sqlType SQL type of the parameter according to <code>java.sql.Types</code>
65: * @param scale the number of digits after the decimal point
66: * (for DECIMAL and NUMERIC types)
67: * @param value the value object
68: */
69: public SqlParameterValue(int sqlType, int scale, Object value) {
70: super (sqlType, scale);
71: this .value = value;
72: }
73:
74: /**
75: * Create a new SqlParameterValue based on the given SqlParameter declaration.
76: * @param declaredParam the declared SqlParameter to define a value for
77: * @param value the value object
78: */
79: public SqlParameterValue(SqlParameter declaredParam, Object value) {
80: super (declaredParam);
81: this .value = value;
82: }
83:
84: /**
85: * Return the value object that this parameter value holds.
86: */
87: public Object getValue() {
88: return this.value;
89: }
90:
91: }
|