01: /*
02: * Copyright 2002-2006 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.namedparam;
18:
19: import java.util.HashMap;
20: import java.util.Map;
21:
22: /**
23: * Abstract base class for SqlParameterSource implementations.
24: * Provides registration of SQL types per parameter.
25: *
26: * @author Juergen Hoeller
27: * @since 2.0
28: */
29: public abstract class AbstractSqlParameterSource implements
30: SqlParameterSource {
31:
32: private final Map sqlTypes = new HashMap();
33:
34: /**
35: * Register a SQL type for the given parameter.
36: * @param paramName the name of the parameter
37: * @param sqlType the SQL type of the parameter
38: */
39: public void registerSqlType(String paramName, int sqlType) {
40: this .sqlTypes.put(paramName, new Integer(sqlType));
41: }
42:
43: /**
44: * Return the SQL type for the given parameter, if registered.
45: * @param paramName the name of the parameter
46: * @return the SQL type of the parameter,
47: * or <code>TYPE_UNKNOWN</code> if not registered
48: */
49: public int getSqlType(String paramName) {
50: Integer sqlType = (Integer) this.sqlTypes.get(paramName);
51: if (sqlType != null) {
52: return sqlType.intValue();
53: } else {
54: return TYPE_UNKNOWN;
55: }
56: }
57:
58: }
|