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