KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > jdbc > core > namedparam > AbstractSqlParameterSource


1 /*
2  * Copyright 2002-2006 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 java.util.HashMap JavaDoc;
20 import java.util.Map JavaDoc;
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 SqlParameterSource {
30
31     private final Map JavaDoc sqlTypes = new HashMap JavaDoc();
32
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 JavaDoc paramName, int sqlType) {
40         this.sqlTypes.put(paramName, new Integer JavaDoc(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 JavaDoc paramName) {
50         Integer JavaDoc sqlType = (Integer JavaDoc) this.sqlTypes.get(paramName);
51         if (sqlType != null) {
52             return sqlType.intValue();
53         }
54         else {
55             return TYPE_UNKNOWN;
56         }
57     }
58
59 }
60
Popular Tags