KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > mapping > parameter > BasicParameterMapping


1 /*
2  * Copyright 2004 Clinton Begin
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 package com.ibatis.sqlmap.engine.mapping.parameter;
17
18 import com.ibatis.sqlmap.client.SqlMapException;
19 import com.ibatis.sqlmap.engine.type.JdbcTypeRegistry;
20 import com.ibatis.sqlmap.engine.type.TypeHandler;
21
22 public class BasicParameterMapping implements ParameterMapping {
23
24   private static final String JavaDoc MODE_INOUT = "INOUT";
25   private static final String JavaDoc MODE_OUT = "OUT";
26   private static final String JavaDoc MODE_IN = "IN";
27
28   private String JavaDoc propertyName;
29   private TypeHandler typeHandler;
30   private String JavaDoc typeName; // this is used for REF types or user-defined types
31
private int jdbcType;
32   private String JavaDoc jdbcTypeName;
33   private String JavaDoc nullValue;
34   private String JavaDoc mode;
35   private boolean inputAllowed;
36   private boolean outputAllowed;
37   private Class JavaDoc javaType;
38
39   private String JavaDoc errorString;
40
41   public BasicParameterMapping() {
42     mode = "IN";
43     inputAllowed = true;
44     outputAllowed = false;
45   }
46
47   public String JavaDoc getNullValue() {
48     return nullValue;
49   }
50
51   public void setNullValue(String JavaDoc nullValue) {
52     this.nullValue = nullValue;
53   }
54
55   public String JavaDoc getPropertyName() {
56     return propertyName;
57   }
58
59   public void setPropertyName(String JavaDoc propertyName) {
60     this.errorString = "Check the parameter mapping for the '" + propertyName + "' property.";
61     this.propertyName = propertyName;
62   }
63
64   public String JavaDoc getErrorString() {
65     return errorString;
66   }
67
68   public TypeHandler getTypeHandler() {
69     return typeHandler;
70   }
71
72   public void setTypeHandler(TypeHandler typeHandler) {
73     this.typeHandler = typeHandler;
74   }
75
76   public Class JavaDoc getJavaType() {
77     return javaType;
78   }
79
80   public void setJavaType(Class JavaDoc javaType) {
81     this.javaType = javaType;
82   }
83
84   public String JavaDoc getJavaTypeName() {
85     if (javaType == null) {
86       return null;
87     } else {
88       return javaType.getName();
89     }
90   }
91
92   public void setJavaTypeName(String JavaDoc javaTypeName) {
93     try {
94       if (javaTypeName == null) {
95         this.javaType = null;
96       } else {
97         this.javaType = Class.forName(javaTypeName);
98       }
99     } catch (ClassNotFoundException JavaDoc e) {
100       throw new SqlMapException("Error setting javaType property of ParameterMap. Cause: " + e, e);
101     }
102   }
103
104   public int getJdbcType() {
105     return jdbcType;
106   }
107
108   public String JavaDoc getJdbcTypeName() {
109     return jdbcTypeName;
110   }
111
112   public void setJdbcTypeName(String JavaDoc jdbcTypeName) {
113     this.jdbcTypeName = jdbcTypeName;
114     this.jdbcType = JdbcTypeRegistry.getType(jdbcTypeName);
115   }
116
117   public String JavaDoc getMode() {
118     return mode;
119   }
120
121   public void setMode(String JavaDoc mode) {
122     this.mode = mode;
123     inputAllowed = MODE_IN.equals(mode) || MODE_INOUT.equals(mode);
124     outputAllowed = MODE_OUT.equals(mode) || MODE_INOUT.equals(mode);
125   }
126
127   public boolean isInputAllowed() {
128     return inputAllowed;
129   }
130
131   public boolean isOutputAllowed() {
132     return outputAllowed;
133   }
134
135   /**
136    * user-defined or REF types
137    * @return
138    */

139   public String JavaDoc getTypeName() {
140     return typeName;
141   }
142
143   /**
144    * for user-defined or REF types
145    * @param typeName
146    */

147   public void setTypeName(String JavaDoc typeName) {
148     this.typeName = typeName;
149   }
150
151 }
152
Popular Tags