1 package com.imcode.db.mock;
2
3 import org.apache.commons.lang.NotImplementedException;
4 import org.apache.commons.dbutils.ResultSetHandler;
5
6 import java.sql.*;
7 import java.util.Map;
8 import java.util.Calendar;
9 import java.util.SortedMap;
10 import java.util.TreeMap;
11 import java.io.InputStream;
12 import java.io.Reader;
13 import java.math.BigDecimal;
14 import java.net.URL;
15
16 import com.imcode.db.commands.SqlQueryCommand;
17
18 public class MockConnection implements Connection {
19
20 private final MockDatabase database;
21
22 public MockConnection(MockDatabase database) {
23 this.database = database;
24 }
25
26 public int getTransactionIsolation() {
27 throw new NotImplementedException( MockConnection.class );
28 }
29
30 public void setTypeMap(Map map) {
31 throw new NotImplementedException( MockConnection.class );
32 }
33
34 public int getHoldability() throws SQLException {
35 throw new NotImplementedException( MockConnection.class );
36 }
37
38 public void clearWarnings() throws SQLException {
39 throw new NotImplementedException( MockConnection.class );
40 }
41
42 public void close() throws SQLException {
43 }
44
45 public void commit() throws SQLException {}
46
47 public void rollback() throws SQLException {}
48
49 public boolean getAutoCommit() throws SQLException {
50 throw new NotImplementedException( MockConnection.class );
51 }
52
53 public boolean isClosed() throws SQLException {
54 throw new NotImplementedException( MockConnection.class );
55 }
56
57 public boolean isReadOnly() throws SQLException {
58 throw new NotImplementedException( MockConnection.class );
59 }
60
61 public void setHoldability( int holdability ) throws SQLException {
62 throw new NotImplementedException( MockConnection.class );
63 }
64
65 public void setTransactionIsolation( int level ) throws SQLException {
66 }
67
68 public void setAutoCommit( boolean autoCommit ) throws SQLException {
69 }
70
71 public void setReadOnly( boolean readOnly ) throws SQLException {
72 throw new NotImplementedException( MockConnection.class );
73 }
74
75 public String getCatalog() throws SQLException {
76 throw new NotImplementedException( MockConnection.class );
77 }
78
79 public void setCatalog( String catalog ) throws SQLException {
80 throw new NotImplementedException( MockConnection.class );
81 }
82
83 public DatabaseMetaData getMetaData() throws SQLException {
84 throw new NotImplementedException( MockConnection.class );
85 }
86
87 public SQLWarning getWarnings() throws SQLException {
88 throw new NotImplementedException( MockConnection.class );
89 }
90
91 public Savepoint setSavepoint() throws SQLException {
92 throw new NotImplementedException( MockConnection.class );
93 }
94
95 public void releaseSavepoint( Savepoint savepoint ) throws SQLException {
96 throw new NotImplementedException( MockConnection.class );
97 }
98
99 public void rollback( Savepoint savepoint ) throws SQLException {
100 throw new NotImplementedException( MockConnection.class );
101 }
102
103 public Statement createStatement() throws SQLException {
104 throw new NotImplementedException( MockConnection.class );
105 }
106
107 public Statement createStatement( int resultSetType, int resultSetConcurrency )
108 throws SQLException {
109 throw new NotImplementedException( MockConnection.class );
110 }
111
112 public Statement createStatement( int resultSetType, int resultSetConcurrency,
113 int resultSetHoldability ) throws SQLException {
114 throw new NotImplementedException( MockConnection.class );
115 }
116
117 public Map getTypeMap() throws SQLException {
118 throw new NotImplementedException( MockConnection.class );
119 }
120
121 public String nativeSQL( String sql ) throws SQLException {
122 throw new NotImplementedException( MockConnection.class );
123 }
124
125 public CallableStatement prepareCall( String sql ) throws SQLException {
126 throw new NotImplementedException( MockConnection.class );
127 }
128
129 public CallableStatement prepareCall( String sql, int resultSetType,
130 int resultSetConcurrency ) throws SQLException {
131 throw new NotImplementedException( MockConnection.class );
132 }
133
134 public CallableStatement prepareCall( String sql, int resultSetType,
135 int resultSetConcurrency,
136 int resultSetHoldability ) throws SQLException {
137 throw new NotImplementedException( MockConnection.class );
138 }
139
140 public PreparedStatement prepareStatement( String sql )
141 throws SQLException {
142 return new MockPreparedStatement(database, sql);
143 }
144
145 public PreparedStatement prepareStatement( String sql, int autoGeneratedKeys )
146 throws SQLException {
147 throw new NotImplementedException( MockConnection.class );
148 }
149
150 public PreparedStatement prepareStatement( String sql, int resultSetType,
151 int resultSetConcurrency )
152 throws SQLException {
153 throw new NotImplementedException( MockConnection.class );
154 }
155
156 public PreparedStatement prepareStatement( String sql, int resultSetType,
157 int resultSetConcurrency, int resultSetHoldability )
158 throws SQLException {
159 throw new NotImplementedException( MockConnection.class );
160 }
161
162 public PreparedStatement prepareStatement( String sql, int columnIndexes[] )
163 throws SQLException {
164 throw new NotImplementedException( MockConnection.class );
165 }
166
167 public Savepoint setSavepoint( String name ) throws SQLException {
168 throw new NotImplementedException( MockConnection.class );
169 }
170
171 public PreparedStatement prepareStatement( String sql, String columnNames[] )
172 throws SQLException {
173 throw new NotImplementedException( MockConnection.class );
174 }
175
176 private static class MockPreparedStatement implements PreparedStatement {
177
178 private final MockDatabase database;
179 private SortedMap parameters = new TreeMap();
180 private final String sql;
181
182 public MockPreparedStatement(MockDatabase database, String sql) {
183 this.database = database;
184 this.sql = sql;
185 }
186
187 public int executeUpdate() throws SQLException {
188 throw new NotImplementedException(".executeUpdate");
189 }
190
191 public void addBatch() throws SQLException {
192 throw new NotImplementedException(".addBatch");
193 }
194
195 public void clearParameters() throws SQLException {
196 throw new NotImplementedException(".clearParameters");
197 }
198
199 public boolean execute() throws SQLException {
200 throw new NotImplementedException(".execute");
201 }
202
203 public void setByte(int parameterIndex, byte x) throws SQLException {
204 throw new NotImplementedException(".setByte");
205 }
206
207 public void setDouble(int parameterIndex, double x) throws SQLException {
208 throw new NotImplementedException(".setDouble");
209 }
210
211 public void setFloat(int parameterIndex, float x) throws SQLException {
212 throw new NotImplementedException(".setFloat");
213 }
214
215 public void setInt(int parameterIndex, int x) throws SQLException {
216 setObject(parameterIndex, new Integer(x)) ;
217 }
218
219 public void setNull(int parameterIndex, int sqlType) throws SQLException {
220 throw new NotImplementedException(".setNull");
221 }
222
223 public void setLong(int parameterIndex, long x) throws SQLException {
224 throw new NotImplementedException(".setLong");
225 }
226
227 public void setShort(int parameterIndex, short x) throws SQLException {
228 throw new NotImplementedException(".setShort");
229 }
230
231 public void setBoolean(int parameterIndex, boolean x) throws SQLException {
232 throw new NotImplementedException(".setBoolean");
233 }
234
235 public void setBytes(int parameterIndex, byte x[]) throws SQLException {
236 throw new NotImplementedException(".setBytes");
237 }
238
239 public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
240 throw new NotImplementedException(".setAsciiStream");
241 }
242
243 public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
244 throw new NotImplementedException(".setBinaryStream");
245 }
246
247 public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
248 throw new NotImplementedException(".setUnicodeStream");
249 }
250
251 public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
252 throw new NotImplementedException(".setCharacterStream");
253 }
254
255 public void setObject(int parameterIndex, Object x) throws SQLException {
256 parameters.put(new Integer(parameterIndex), x) ;
257 }
258
259 public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
260 throw new NotImplementedException(".setObject");
261 }
262
263 public void setObject(int parameterIndex, Object x, int targetSqlType, int scale) throws SQLException {
264 throw new NotImplementedException(".setObject");
265 }
266
267 public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
268 throw new NotImplementedException(".setNull");
269 }
270
271 public void setString(int parameterIndex, String x) throws SQLException {
272 throw new NotImplementedException(".setString");
273 }
274
275 public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
276 throw new NotImplementedException(".setBigDecimal");
277 }
278
279 public void setURL(int parameterIndex, URL x) throws SQLException {
280 throw new NotImplementedException(".setURL");
281 }
282
283 public void setArray(int i, Array x) throws SQLException {
284 throw new NotImplementedException(".setArray");
285 }
286
287 public void setBlob(int i, Blob x) throws SQLException {
288 throw new NotImplementedException(".setBlob");
289 }
290
291 public void setClob(int i, Clob x) throws SQLException {
292 throw new NotImplementedException(".setClob");
293 }
294
295 public void setDate(int parameterIndex, Date x) throws SQLException {
296 throw new NotImplementedException(".setDate");
297 }
298
299 public ParameterMetaData getParameterMetaData() throws SQLException {
300 throw new NotImplementedException(".getParameterMetaData");
301 }
302
303 public void setRef(int i, Ref x) throws SQLException {
304 throw new NotImplementedException(".setRef");
305 }
306
307 public ResultSet executeQuery() throws SQLException {
308 Object[] parameterArray = parameters.values().toArray();
309 return (ResultSet) database.execute(new SqlQueryCommand(sql, parameterArray, new ResultSetHandler() {
310 public Object handle(ResultSet resultSet) {
311 return resultSet;
312 }
313 })) ;
314 }
315
316 public ResultSetMetaData getMetaData() throws SQLException {
317 throw new NotImplementedException(".getMetaData");
318 }
319
320 public void setTime(int parameterIndex, Time x) throws SQLException {
321 throw new NotImplementedException(".setTime");
322 }
323
324 public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
325 throw new NotImplementedException(".setTimestamp");
326 }
327
328 public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
329 throw new NotImplementedException(".setDate");
330 }
331
332 public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
333 throw new NotImplementedException(".setTime");
334 }
335
336 public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
337 throw new NotImplementedException(".setTimestamp");
338 }
339
340 public int getFetchDirection() throws SQLException {
341 throw new NotImplementedException(".getFetchDirection");
342 }
343
344 public int getFetchSize() throws SQLException {
345 throw new NotImplementedException(".getFetchSize");
346 }
347
348 public int getMaxFieldSize() throws SQLException {
349 throw new NotImplementedException(".getMaxFieldSize");
350 }
351
352 public int getMaxRows() throws SQLException {
353 throw new NotImplementedException(".getMaxRows");
354 }
355
356 public int getQueryTimeout() throws SQLException {
357 throw new NotImplementedException(".getQueryTimeout");
358 }
359
360 public int getResultSetConcurrency() throws SQLException {
361 throw new NotImplementedException(".getResultSetConcurrency");
362 }
363
364 public int getResultSetHoldability() throws SQLException {
365 throw new NotImplementedException(".getResultSetHoldability");
366 }
367
368 public int getResultSetType() throws SQLException {
369 throw new NotImplementedException(".getResultSetType");
370 }
371
372 public int getUpdateCount() throws SQLException {
373 throw new NotImplementedException(".getUpdateCount");
374 }
375
376 public void cancel() throws SQLException {
377 throw new NotImplementedException(".cancel");
378 }
379
380 public void clearBatch() throws SQLException {
381 throw new NotImplementedException(".clearBatch");
382 }
383
384 public void clearWarnings() throws SQLException {
385 throw new NotImplementedException(".clearWarnings");
386 }
387
388 public void close() throws SQLException {
389 }
390
391 public boolean getMoreResults() throws SQLException {
392 throw new NotImplementedException(".getMoreResults");
393 }
394
395 public int[] executeBatch() throws SQLException {
396 throw new NotImplementedException(".executeBatch");
397 }
398
399 public void setFetchDirection(int direction) throws SQLException {
400 throw new NotImplementedException(".setFetchDirection");
401 }
402
403 public void setFetchSize(int rows) throws SQLException {
404 throw new NotImplementedException(".setFetchSize");
405 }
406
407 public void setMaxFieldSize(int max) throws SQLException {
408 throw new NotImplementedException(".setMaxFieldSize");
409 }
410
411 public void setMaxRows(int max) throws SQLException {
412 throw new NotImplementedException(".setMaxRows");
413 }
414
415 public void setQueryTimeout(int seconds) throws SQLException {
416 throw new NotImplementedException(".setQueryTimeout");
417 }
418
419 public boolean getMoreResults(int current) throws SQLException {
420 throw new NotImplementedException(".getMoreResults");
421 }
422
423 public void setEscapeProcessing(boolean enable) throws SQLException {
424 throw new NotImplementedException(".setEscapeProcessing");
425 }
426
427 public int executeUpdate(String sql) throws SQLException {
428 throw new NotImplementedException(".executeUpdate");
429 }
430
431 public void addBatch(String sql) throws SQLException {
432 throw new NotImplementedException(".addBatch");
433 }
434
435 public void setCursorName(String name) throws SQLException {
436 throw new NotImplementedException(".setCursorName");
437 }
438
439 public boolean execute(String sql) throws SQLException {
440 throw new NotImplementedException(".execute");
441 }
442
443 public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
444 throw new NotImplementedException(".executeUpdate");
445 }
446
447 public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
448 throw new NotImplementedException(".execute");
449 }
450
451 public int executeUpdate(String sql, int columnIndexes[]) throws SQLException {
452 throw new NotImplementedException(".executeUpdate");
453 }
454
455 public boolean execute(String sql, int columnIndexes[]) throws SQLException {
456 throw new NotImplementedException(".execute");
457 }
458
459 public Connection getConnection() throws SQLException {
460 throw new NotImplementedException(".getConnection");
461 }
462
463 public ResultSet getGeneratedKeys() throws SQLException {
464 throw new NotImplementedException(".getGeneratedKeys");
465 }
466
467 public ResultSet getResultSet() throws SQLException {
468 throw new NotImplementedException(".getResultSet");
469 }
470
471 public SQLWarning getWarnings() throws SQLException {
472 throw new NotImplementedException(".getWarnings");
473 }
474
475 public int executeUpdate(String sql, String columnNames[]) throws SQLException {
476 throw new NotImplementedException(".executeUpdate");
477 }
478
479 public boolean execute(String sql, String columnNames[]) throws SQLException {
480 throw new NotImplementedException(".execute");
481 }
482
483 public ResultSet executeQuery(String sql) throws SQLException {
484 throw new NotImplementedException(".executeQuery");
485 }
486 }
487 }