01: package com.mockrunner.mock.jdbc;
02:
03: import java.io.PrintWriter;
04: import java.sql.Connection;
05: import java.sql.SQLException;
06:
07: import javax.sql.DataSource;
08:
09: /**
10: * Mock implementation of <code>DataSource</code>.
11: */
12: public class MockDataSource implements DataSource {
13: private Connection connection = null;
14: private int loginTimeout = 0;
15: private PrintWriter logWriter = null;
16:
17: /**
18: * Set up the connection.
19: * @param connection the connection
20: */
21: public void setupConnection(Connection connection) {
22: this .connection = connection;
23: }
24:
25: /**
26: * Returns the {@link com.mockrunner.mock.jdbc.MockConnection}.
27: * If the underlying connection is not an instance of
28: * {@link com.mockrunner.mock.jdbc.MockConnection},
29: * <code>null</code> is returned.
30: * @return the {@link com.mockrunner.mock.jdbc.MockConnection}
31: */
32: public MockConnection getMockConnection() {
33: if (connection instanceof MockConnection) {
34: return (MockConnection) connection;
35: }
36: return null;
37: }
38:
39: public int getLoginTimeout() throws SQLException {
40: return loginTimeout;
41: }
42:
43: public void setLoginTimeout(int seconds) throws SQLException {
44: loginTimeout = seconds;
45: }
46:
47: public PrintWriter getLogWriter() throws SQLException {
48: return logWriter;
49: }
50:
51: public void setLogWriter(PrintWriter out) throws SQLException {
52: logWriter = out;
53: }
54:
55: public Connection getConnection() throws SQLException {
56: return connection;
57: }
58:
59: public Connection getConnection(String username, String password)
60: throws SQLException {
61: return connection;
62: }
63:
64: public boolean isWrapperFor(Class iface) throws SQLException {
65: return false;
66: }
67:
68: public Object unwrap(Class iface) throws SQLException {
69: throw new SQLException("No object found for " + iface);
70: }
71: }
|