KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > sql > CommonMockResultSetMetaData


1 package com.mockobjects.sql;
2
3 import com.mockobjects.MockObject;
4 import com.mockobjects.ReturnObjectList;
5 import com.mockobjects.ExpectationList;
6
7 import java.sql.ResultSetMetaData JavaDoc;
8 import java.sql.SQLException JavaDoc;
9
10 /**
11  * @version $Revision: 1.3 $
12  */

13 class CommonMockResultSetMetaData extends MockObject implements ResultSetMetaData JavaDoc {
14     private final ReturnObjectList myNames =
15         new ReturnObjectList("MockResultSetMetaData.columnNames");
16     private final ReturnObjectList myTypes =
17         new ReturnObjectList("MockResultSetMetaData.columnTypes");
18     private final ReturnObjectList myClassNames =
19         new ReturnObjectList("MockResultSetMetaData.columnClassNames");
20     private int myColumnCount;
21     private final ExpectationList myColumnTypeIndexes =
22         new ExpectationList("Column Type Indexes");
23     private final ExpectationList myColumnNameIndexes =
24         new ExpectationList("Column Name Indexes");
25     private final ExpectationList myColumnClassNameIndexes =
26         new ExpectationList("Column Class Name Indexes");
27
28     /**
29      * Value to return from getColumnCount.
30      */

31     public void setupGetColumnCount(int aColumnCount) {
32         myColumnCount = aColumnCount;
33     }
34
35     /**
36      * An array of column names in the order they appear in the
37      * resultSet.
38      */

39     public void setupAddColumnNames(String JavaDoc[] allNames) {
40         if (allNames != null) {
41             for (int i = 0; i < allNames.length; i++) {
42                 setupAddColumnName(allNames[i]);
43             }
44         }
45     }
46
47     /**
48      * The next column name in the resultSet.
49      */

50     public void setupAddColumnName(String JavaDoc aName) {
51         this.myNames.addObjectToReturn(aName);
52     }
53
54     /**
55      * An array of column SQL types in the order they appear in the
56      * resultSet.
57      */

58     public void setupAddColumnTypes(int[] allTypes) {
59         if (allTypes != null) {
60             for (int i = 0; i < allTypes.length; i++) {
61                 setupAddColumnType(allTypes[i]);
62             }
63         }
64     }
65
66     /**
67      * The next column's SQL type in the resultSet as an int.
68      */

69     public void setupAddColumnType(int aType) {
70         this.myTypes.addObjectToReturn(aType);
71     }
72
73     /**
74      * Returns value passed to setupGetColumnCount.
75      * @see ResultSetMetaData#getColumnCount()
76      */

77     public int getColumnCount() throws SQLException JavaDoc {
78         return myColumnCount;
79     }
80
81     /**
82      * Returns the column name.
83      * DOES NOT SUPPORT THE aColumnIndex PARAMETER.
84      * You must call getColumnName in order, first to last.
85      * Column names may be added with setupAddColumnName.
86      * or setupAddColumnNames.
87      * @see ResultSetMetaData#getColumnName(int)
88      */

89     public String JavaDoc getColumnName(int aColumnIndex) throws SQLException JavaDoc {
90         myColumnNameIndexes.addActual(aColumnIndex);
91         return (String JavaDoc) myNames.nextReturnObject();
92     }
93
94     /**
95      * Adds an expectation for a column index to be passed to getColumnName
96      * @see MockResultSetMetaData#getColumnName(int)
97      */

98     public void addExpectedColumnNameIndex(int aColumnIndex){
99         myColumnNameIndexes.addExpected(aColumnIndex);
100     }
101
102     /**
103      * Returns the column SQL type.
104      * DOES NOT SUPPORT THE aColumnIndex PARAMETER.
105      * You must call getColumnType in order, first to last.
106      * Column SQL types may be added with setupAddColumnType.
107      * @see ResultSetMetaData#getColumnType(int)
108      */

109     public int getColumnType(int aColumnIndex) throws SQLException JavaDoc {
110         myColumnTypeIndexes.addActual(aColumnIndex);
111         return ((Integer JavaDoc) myTypes.nextReturnObject()).intValue();
112     }
113
114     /**
115      * Adds an expectation for a column index to be passed to getColumnType
116      * @see MockResultSetMetaData#getColumnType(int)
117      */

118     public void addExpectedColumnTypeIndex(int aColumnIndex){
119         myColumnTypeIndexes.addExpected(aColumnIndex);
120     }
121
122     /**
123      * Calls notImplemented. Returns false.
124      * @see ResultSetMetaData#isAutoIncrement(int)
125      */

126     public boolean isAutoIncrement(int arg0) throws SQLException JavaDoc {
127         notImplemented();
128         return false;
129     }
130
131     /**
132      * Calls notImplemented. Returns false.
133      * @see ResultSetMetaData#isCaseSensitive(int)
134      */

135     public boolean isCaseSensitive(int arg0) throws SQLException JavaDoc {
136         notImplemented();
137         return false;
138     }
139
140     /**
141      * Calls notImplemented. Returns false.
142      * @see ResultSetMetaData#isSearchable(int)
143      */

144     public boolean isSearchable(int arg0) throws SQLException JavaDoc {
145         notImplemented();
146         return false;
147     }
148
149     /**
150      * Calls notImplemented. Returns false.
151      * @see ResultSetMetaData#isCurrency(int)
152      */

153     public boolean isCurrency(int arg0) throws SQLException JavaDoc {
154         notImplemented();
155         return false;
156     }
157
158     /**
159      * Calls notImplemented. Returns false.
160      * @see ResultSetMetaData#isNullable(int)
161      */

162     public int isNullable(int arg0) throws SQLException JavaDoc {
163         notImplemented();
164         return 0;
165     }
166
167     /**
168      * Calls notImplemented. Returns false.
169      * @see ResultSetMetaData#isSigned(int)
170      */

171     public boolean isSigned(int arg0) throws SQLException JavaDoc {
172         notImplemented();
173         return false;
174     }
175
176     /**
177      * Calls notImplemented. Returns 0.
178      * @see ResultSetMetaData#getColumnDisplaySize(int)
179      */

180     public int getColumnDisplaySize(int arg0) throws SQLException JavaDoc {
181         notImplemented();
182         return 0;
183     }
184
185     /**
186      * Calls notImplemented. Returns null.
187      * @see ResultSetMetaData#getColumnLabel(int)
188      */

189     public String JavaDoc getColumnLabel(int arg0) throws SQLException JavaDoc {
190         notImplemented();
191         return null;
192     }
193
194     /**
195      * Calls notImplemented. Returns null.
196      * @see ResultSetMetaData#getColumnTypeName(int)
197      */

198     public String JavaDoc getColumnTypeName(int arg0) throws SQLException JavaDoc {
199         notImplemented();
200         return null;
201     }
202
203     /**
204      * Calls notImplemented. Returns null.
205      * @see ResultSetMetaData#getSchemaName(int)
206      */

207     public String JavaDoc getSchemaName(int arg0) throws SQLException JavaDoc {
208         notImplemented();
209         return null;
210     }
211
212     /**
213      * Calls notImplemented. Returns 0.
214      * @see ResultSetMetaData#getPrecision(int)
215      */

216     public int getPrecision(int arg0) throws SQLException JavaDoc {
217         notImplemented();
218         return 0;
219     }
220
221     /**
222      * Calls notImplemented. Returns 0.
223      * @see ResultSetMetaData#getScale(int)
224      */

225     public int getScale(int arg0) throws SQLException JavaDoc {
226         notImplemented();
227         return 0;
228     }
229
230     /**
231      * Calls notImplemented. Returns null.
232      * @see ResultSetMetaData#getTableName(int)
233      */

234     public String JavaDoc getTableName(int arg0) throws SQLException JavaDoc {
235         notImplemented();
236         return null;
237     }
238
239     /**
240      * Calls notImplemented. Returns null.
241      * @see ResultSetMetaData#getCatalogName(int)
242      */

243     public String JavaDoc getCatalogName(int arg0) throws SQLException JavaDoc {
244         notImplemented();
245         return null;
246     }
247
248     /**
249      * Calls notImplemented. Returns false.
250      * @see ResultSetMetaData#isReadOnly(int)
251      */

252     public boolean isReadOnly(int arg0) throws SQLException JavaDoc {
253         notImplemented();
254         return false;
255     }
256
257     /**
258      * Calls notImplemented. Returns false.
259      * @see ResultSetMetaData#isWritable(int)
260      */

261     public boolean isWritable(int arg0) throws SQLException JavaDoc {
262         notImplemented();
263         return false;
264     }
265
266     /**
267      * Calls notImplemented. Returns false.
268      * @see ResultSetMetaData#isDefinitelyWritable(int)
269      */

270     public boolean isDefinitelyWritable(int arg0) throws SQLException JavaDoc {
271         notImplemented();
272         return false;
273     }
274
275     /**
276      * An array of column class names in the order they appear in the
277      * resultSet.
278      */

279     public void setupAddColumnClassNames(String JavaDoc[] allNames) {
280         if (allNames != null) {
281             for (int i = 0; i < allNames.length; i++) {
282                 setupAddColumnClassName(allNames[i]);
283             }
284         }
285     }
286
287     /**
288      * The next column class name in the resultSet.
289      */

290     public void setupAddColumnClassName(String JavaDoc aName) {
291         this.myClassNames.addObjectToReturn(aName);
292     }
293
294     /**
295      * Returns the column class name.
296      * DOES NOT SUPPORT THE aColumnIndex PARAMETER.
297      * You must call getColumnClassName in order, first to last.
298      * Column class names may be added with setupAddColumnClassName.
299      * or setupAddColumnClassNames.
300      * @see ResultSetMetaData#getColumnClassName(int)
301      */

302     public String JavaDoc getColumnClassName(int aColumnIndex) throws SQLException JavaDoc {
303         myColumnClassNameIndexes.addActual(aColumnIndex);
304         return (String JavaDoc) myClassNames.nextReturnObject();
305     }
306
307     /**
308      * Adds an expectation for a column index to be passed to getColumnClassName
309      * @see MockResultSetMetaData#getColumnClassName(int)
310      */

311     public void addExpectedColumnClassNameIndex(int aColumnIndex){
312         myColumnClassNameIndexes.addExpected(aColumnIndex);
313     }
314
315 }
316
Popular Tags