001    package com.mockrunner.mock.jdbc;
002    
003    import java.sql.ResultSetMetaData;
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>ResultSetMetaData</code>.
011     */
012    public class MockResultSetMetaData implements ResultSetMetaData
013    {
014        private int columnCount;
015        private Map columnDisplaySizeMap;
016        private Map columnTypeMap;
017        private Map precisionMap;
018        private Map scaleMap;
019        private Map isNullableMap;
020        private Map isAutoIncrementMap;
021        private Map isCaseSensitiveMap;
022        private Map isCurrencyMap;
023        private Map isDefinitelyWritableMap;
024        private Map isReadOnlyMap;
025        private Map isSearchableMap;
026        private Map isSignedMap;
027        private Map isWritableMap;
028        private Map catalogNameMap;
029        private Map columnClassNameMap;
030        private Map columnLabelMap;
031        private Map columnNameMap;
032        private Map columnTypeNameMap;
033        private Map schemaNameMap;
034        private Map tableNameMap;
035        
036        public MockResultSetMetaData()
037        {
038            columnCount = 0;
039            columnDisplaySizeMap = new HashMap();
040            columnTypeMap = new HashMap();
041            precisionMap = new HashMap();
042            scaleMap = new HashMap();
043            isNullableMap = new HashMap();
044            isAutoIncrementMap = new HashMap();
045            isCaseSensitiveMap = new HashMap();
046            isCurrencyMap = new HashMap();
047            isDefinitelyWritableMap = new HashMap();;
048            isReadOnlyMap = new HashMap();
049            isSearchableMap = new HashMap();
050            isSignedMap = new HashMap();
051            isWritableMap = new HashMap();
052            catalogNameMap = new HashMap();
053            columnClassNameMap = new HashMap();
054            columnLabelMap = new HashMap();
055            columnNameMap = new HashMap();
056            columnTypeNameMap = new HashMap();
057            schemaNameMap = new HashMap();
058            tableNameMap = new HashMap();
059        }
060        
061        public void setColumnCount(int columnCount)
062        {
063            this.columnCount = columnCount;
064        }
065        
066        public void setColumnDisplaySize(int column, int displaySize)
067        {
068            columnDisplaySizeMap.put(new Integer(column), new Integer(displaySize));
069        }
070        
071        public void setColumnType(int column, int columnType)
072        {
073            columnTypeMap.put(new Integer(column), new Integer(columnType));
074        }
075        
076        public void setPrecision(int column, int precision)
077        {
078            precisionMap.put(new Integer(column), new Integer(precision));
079        }
080        
081        public void setScale(int column, int scale)
082        {
083            scaleMap.put(new Integer(column), new Integer(scale));
084        }
085        
086        public void setNullable(int column, int nullable)
087        {
088            isNullableMap.put(new Integer(column), new Integer(nullable));
089        }
090        
091        public void setAutoIncrement(int column, boolean autoIncrement)
092        {
093            isAutoIncrementMap.put(new Integer(column), new Boolean(autoIncrement));
094        }
095        
096        public void setCaseSensitive(int column, boolean caseSensitive)
097        {
098            isCaseSensitiveMap.put(new Integer(column), new Boolean(caseSensitive));
099        }
100        
101        public void setCurrency(int column, boolean currency)
102        {
103            isCurrencyMap.put(new Integer(column), new Boolean(currency));
104        }
105        
106        public void setDefinitelyWritable(int column, boolean definitelyWritable)
107        {
108            isDefinitelyWritableMap.put(new Integer(column), new Boolean(definitelyWritable));
109        }
110        
111        public void setReadOnly(int column, boolean readOnly)
112        {
113            isReadOnlyMap.put(new Integer(column), new Boolean(readOnly));
114        }
115        
116        public void setSearchable(int column, boolean searchable)
117        {
118            isSearchableMap.put(new Integer(column), new Boolean(searchable));
119        }
120        
121        public void setSigned(int column, boolean signed)
122        {
123            isSignedMap.put(new Integer(column), new Boolean(signed));
124        }
125        
126        public void setWritable(int column, boolean writable)
127        {
128            isWritableMap.put(new Integer(column), new Boolean(writable));
129        }
130        
131        public void setCatalogName(int column, String catalogName)
132        {
133            catalogNameMap.put(new Integer(column), catalogName);
134        }
135        
136        public void setColumnClassName(int column, String columnClassName)
137        {
138            columnClassNameMap.put(new Integer(column), columnClassName);
139        }
140        
141        public void setColumnLabel(int column, String columnLabel)
142        {
143            columnLabelMap.put(new Integer(column), columnLabel);
144        }
145        
146        public void setColumnName(int column, String columnName)
147        {
148            columnNameMap.put(new Integer(column), columnName);
149        }
150        
151        public void setColumnTypeName(int column, String columnTypeName)
152        {
153            columnTypeNameMap.put(new Integer(column), columnTypeName);
154        }
155        
156        public void setSchemaName(int column, String schemaName)
157        {
158            schemaNameMap.put(new Integer(column), schemaName);
159        }
160        
161        public void setTableName(int column, String tableName)
162        {
163            tableNameMap.put(new Integer(column), tableName);
164        }
165        
166        public int getColumnCount() throws SQLException
167        {
168            return columnCount;
169        }
170    
171        public int getColumnDisplaySize(int column) throws SQLException
172        {
173            Integer columnDisplaySize = (Integer)columnDisplaySizeMap.get(new Integer(column));
174            if(null == columnDisplaySize) return getColumnCount();
175            return columnDisplaySize.intValue();
176        }
177    
178        public int getColumnType(int column) throws SQLException
179        {
180            Integer columnType = (Integer)columnTypeMap.get(new Integer(column));
181            if(null == columnType) return Types.OTHER;
182            return columnType.intValue();
183        }
184    
185        public int getPrecision(int column) throws SQLException
186        {
187            Integer precision = (Integer)precisionMap.get(new Integer(column));
188            if(null == precision) return 0;
189            return precision.intValue();
190        }
191    
192        public int getScale(int column) throws SQLException
193        {
194            Integer scale = (Integer)scaleMap.get(new Integer(column));
195            if(null == scale) return 0;
196            return scale.intValue();
197        }
198    
199        public int isNullable(int column) throws SQLException
200        {
201            Integer isNullable = (Integer)isNullableMap.get(new Integer(column));
202            if(null == isNullable) return columnNullable;
203            return isNullable.intValue();
204        }
205    
206        public boolean isAutoIncrement(int column) throws SQLException
207        {
208            Boolean isAutoIncrement = (Boolean)isAutoIncrementMap.get(new Integer(column));
209            if(null == isAutoIncrement) return false;
210            return isAutoIncrement.booleanValue();
211        }
212    
213        public boolean isCaseSensitive(int column) throws SQLException
214        {
215            Boolean isCaseSensitive = (Boolean)isCaseSensitiveMap.get(new Integer(column));
216            if(null == isCaseSensitive) return true;
217            return isCaseSensitive.booleanValue();
218        }
219    
220        public boolean isCurrency(int column) throws SQLException
221        {
222            Boolean isCurrency = (Boolean)isCurrencyMap.get(new Integer(column));
223            if(null == isCurrency) return false;
224            return isCurrency.booleanValue();
225        }
226    
227        public boolean isDefinitelyWritable(int column) throws SQLException
228        {
229            Boolean isDefinitelyWritable = (Boolean)isDefinitelyWritableMap.get(new Integer(column));
230            if(null == isDefinitelyWritable) return true;
231            return isDefinitelyWritable.booleanValue();
232        }
233    
234        public boolean isReadOnly(int column) throws SQLException
235        {
236            Boolean isReadOnly = (Boolean)isReadOnlyMap.get(new Integer(column));
237            if(null == isReadOnly) return false;
238            return isReadOnly.booleanValue();
239        }
240    
241        public boolean isSearchable(int column) throws SQLException
242        {
243            Boolean isSearchable = (Boolean)isSearchableMap.get(new Integer(column));
244            if(null == isSearchable) return true;
245            return isSearchable.booleanValue();
246        }
247    
248        public boolean isSigned(int column) throws SQLException
249        {
250            Boolean isSigned = (Boolean)isSignedMap.get(new Integer(column));
251            if(null == isSigned) return false;
252            return isSigned.booleanValue();
253        }
254    
255        public boolean isWritable(int column) throws SQLException
256        {
257            Boolean isWritable = (Boolean)isWritableMap.get(new Integer(column));
258            if(null == isWritable) return true;
259            return isWritable.booleanValue();
260        }
261    
262        public String getCatalogName(int column) throws SQLException
263        {
264            String catalogName = (String)catalogNameMap.get(new Integer(column));
265            if(null == catalogName) return "";
266            return catalogName;
267        }
268    
269        public String getColumnClassName(int column) throws SQLException
270        {
271            String columnClassName = (String)columnClassNameMap.get(new Integer(column));
272            if(null == columnClassName) return Object.class.getName();
273            return columnClassName;
274        }
275    
276        public String getColumnLabel(int column) throws SQLException
277        {
278            String columnLabel = (String)columnLabelMap.get(new Integer(column));
279            if(null == columnLabel) return getColumnName(column);
280            return columnLabel;
281        }
282    
283        public String getColumnName(int column) throws SQLException
284        {
285            String columnName = (String)columnNameMap.get(new Integer(column));
286            if(null == columnName) return "";
287            return columnName;
288        }
289    
290        public String getColumnTypeName(int column) throws SQLException
291        {
292            String columnTypeName = (String)columnTypeNameMap.get(new Integer(column));
293            if(null == columnTypeName) return "";
294            return columnTypeName;
295        }
296    
297        public String getSchemaName(int column) throws SQLException
298        {
299            String schemaName = (String)schemaNameMap.get(new Integer(column));
300            if(null == schemaName) return "";
301            return schemaName;
302        }
303    
304        public String getTableName(int column) throws SQLException
305        {
306            String tableName = (String)tableNameMap.get(new Integer(column));
307            if(null == tableName) return "";
308            return tableName;
309        }
310    }