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