001: package com.mockrunner.mock.jdbc;
002:
003: import java.sql.ParameterMetaData;
004: import java.sql.SQLException;
005: import java.sql.Types;
006: import java.util.HashMap;
007: import java.util.Map;
008:
009: /**
010: * Mock implementation of <code>ParameterMetaData</code>.
011: */
012: public class MockParameterMetaData implements ParameterMetaData {
013: private int parameterCount;
014: private Map parameterModeMap;
015: private Map parameterTypeMap;
016: private Map precisionMap;
017: private Map scaleMap;
018: private Map isNullableMap;
019: private Map isSignedMap;
020: private Map parameterClassNameMap;
021: private Map parameterTypeNameMap;
022:
023: public MockParameterMetaData() {
024: parameterCount = 0;
025: parameterModeMap = new HashMap();
026: parameterTypeMap = new HashMap();
027: precisionMap = new HashMap();
028: scaleMap = new HashMap();
029: isNullableMap = new HashMap();
030: isSignedMap = new HashMap();
031: parameterClassNameMap = new HashMap();
032: parameterTypeNameMap = new HashMap();
033: }
034:
035: public void setParameterCount(int count) {
036: parameterCount = count;
037: }
038:
039: public void setParameterMode(int param, int parameterMode) {
040: parameterModeMap.put(new Integer(param), new Integer(
041: parameterMode));
042: }
043:
044: public void setParameterType(int param, int parameterType) {
045: parameterTypeMap.put(new Integer(param), new Integer(
046: parameterType));
047: }
048:
049: public void setPrecision(int param, int precision) {
050: precisionMap.put(new Integer(param), new Integer(precision));
051: }
052:
053: public void setScale(int param, int scale) {
054: scaleMap.put(new Integer(param), new Integer(scale));
055: }
056:
057: public void setNullable(int param, int nullable) {
058: isNullableMap.put(new Integer(param), new Integer(nullable));
059: }
060:
061: public void setSigned(int param, boolean signed) {
062: isSignedMap.put(new Integer(param), new Boolean(signed));
063: }
064:
065: public void setParameterClassName(int param,
066: String parameterClassName) {
067: parameterClassNameMap.put(new Integer(param),
068: parameterClassName);
069: }
070:
071: public void setParameterTypeName(int param, String parameterTypeName) {
072: parameterTypeNameMap.put(new Integer(param), parameterTypeName);
073: }
074:
075: public int getParameterCount() throws SQLException {
076: return parameterCount;
077: }
078:
079: public int getParameterMode(int param) throws SQLException {
080: Integer parameterMode = (Integer) parameterModeMap
081: .get(new Integer(param));
082: if (null == parameterMode)
083: return parameterModeUnknown;
084: return parameterMode.intValue();
085: }
086:
087: public int getParameterType(int param) throws SQLException {
088: Integer parameterType = (Integer) parameterTypeMap
089: .get(new Integer(param));
090: if (null == parameterType)
091: return Types.OTHER;
092: return parameterType.intValue();
093: }
094:
095: public int getPrecision(int param) throws SQLException {
096: Integer precision = (Integer) precisionMap.get(new Integer(
097: param));
098: if (null == precision)
099: return 0;
100: return precision.intValue();
101: }
102:
103: public int getScale(int param) throws SQLException {
104: Integer scale = (Integer) scaleMap.get(new Integer(param));
105: if (null == scale)
106: return 0;
107: return scale.intValue();
108: }
109:
110: public int isNullable(int param) throws SQLException {
111: Integer isNullable = (Integer) isNullableMap.get(new Integer(
112: param));
113: if (null == isNullable)
114: return parameterNullable;
115: return isNullable.intValue();
116: }
117:
118: public boolean isSigned(int param) throws SQLException {
119: Boolean isSigned = (Boolean) isSignedMap
120: .get(new Integer(param));
121: if (null == isSigned)
122: return false;
123: return isSigned.booleanValue();
124: }
125:
126: public String getParameterClassName(int param) throws SQLException {
127: String parameterClassName = (String) parameterClassNameMap
128: .get(new Integer(param));
129: if (null == parameterClassName)
130: return Object.class.getName();
131: return parameterClassName;
132: }
133:
134: public String getParameterTypeName(int param) throws SQLException {
135: String ParameterTypeName = (String) parameterTypeNameMap
136: .get(new Integer(param));
137: if (null == ParameterTypeName)
138: return Object.class.getName();
139: return ParameterTypeName;
140: }
141:
142: public boolean isWrapperFor(Class iface) throws SQLException {
143: return false;
144: }
145:
146: public Object unwrap(Class iface) throws SQLException {
147: throw new SQLException("No object found for " + iface);
148: }
149: }
|