1 package net.jaekl.squelch.sql;
5 import java.sql.CallableStatement;
7 import java.sql.Connection;
8 import java.sql.DatabaseMetaData;
10 import java.sql.PreparedStatement;
11 import java.sql.SQLClientInfoException;
12 import java.sql.SQLException;
13 import java.sql.SQLWarning;
14 import java.sql.SQLXML;
15 import java.sql.Savepoint;
16 import java.sql.Statement;
17 import java.sql.Struct;
18 import java.util.ArrayList;
20 import java.util.Properties;
21 import java.util.concurrent.Executor;
24 public class ConnectionMock implements Connection {
25 private ArrayList<String> mock_executedQueries;
26 private DatabaseMetaDataMock mock_databaseMetaData;
28 public ConnectionMock() {
29 mock_executedQueries = new ArrayList<String>();
30 mock_databaseMetaData = new DatabaseMetaDataMock();
33 public ResultSetMock mock_executeQuery(PreparedStatementMock psm)
35 mock_executedQueries.add(psm.toString());
36 return new ResultSetMock();
39 public boolean mock_queryWasExecuted(String sql) {
40 // There's an assumption here that we don't try a large number of queries in a single test.
41 // If that assumption is false, then we should change this to be more efficient.
42 return mock_executedQueries.contains(sql);
45 public void mock_setDatabaseMetaData(DatabaseMetaDataMock dbmdm)
47 mock_databaseMetaData = dbmdm;
51 public boolean isWrapperFor(Class<?> arg0) throws SQLException {
52 // TODO Auto-generated method stub
57 public <T> T unwrap(Class<T> arg0) throws SQLException {
58 // TODO Auto-generated method stub
63 public void abort(Executor executor) throws SQLException {
64 // TODO Auto-generated method stub
69 public void clearWarnings() throws SQLException {
70 // TODO Auto-generated method stub
75 public void close() throws SQLException {
76 // TODO Auto-generated method stub
81 public void commit() throws SQLException {
82 // TODO Auto-generated method stub
87 public Array createArrayOf(String typeName, Object[] elements)
89 // TODO Auto-generated method stub
94 public Blob createBlob() throws SQLException {
95 // TODO Auto-generated method stub
100 public Clob createClob() throws SQLException {
101 // TODO Auto-generated method stub
106 public NClob createNClob() throws SQLException {
107 // TODO Auto-generated method stub
112 public SQLXML createSQLXML() throws SQLException {
113 // TODO Auto-generated method stub
118 public Statement createStatement() throws SQLException {
119 // TODO Auto-generated method stub
124 public Statement createStatement(int resultSetType, int resultSetConcurrency)
125 throws SQLException {
126 // TODO Auto-generated method stub
131 public Statement createStatement(int resultSetType,
132 int resultSetConcurrency, int resultSetHoldability)
133 throws SQLException {
134 // TODO Auto-generated method stub
139 public Struct createStruct(String typeName, Object[] attributes)
140 throws SQLException {
141 // TODO Auto-generated method stub
146 public boolean getAutoCommit() throws SQLException {
147 // TODO Auto-generated method stub
152 public String getCatalog() throws SQLException {
153 // TODO Auto-generated method stub
158 public Properties getClientInfo() throws SQLException {
159 // TODO Auto-generated method stub
164 public String getClientInfo(String name) throws SQLException {
165 // TODO Auto-generated method stub
170 public int getHoldability() throws SQLException {
171 // TODO Auto-generated method stub
176 public DatabaseMetaData getMetaData() throws SQLException {
177 return mock_databaseMetaData;
181 public int getNetworkTimeout() throws SQLException {
182 // TODO Auto-generated method stub
187 public String getSchema() throws SQLException {
188 // TODO Auto-generated method stub
193 public int getTransactionIsolation() throws SQLException {
194 // TODO Auto-generated method stub
199 public Map<String, Class<?>> getTypeMap() throws SQLException {
200 // TODO Auto-generated method stub
205 public SQLWarning getWarnings() throws SQLException {
206 // TODO Auto-generated method stub
211 public boolean isClosed() throws SQLException {
212 // TODO Auto-generated method stub
217 public boolean isReadOnly() throws SQLException {
218 // TODO Auto-generated method stub
223 public boolean isValid(int timeout) throws SQLException {
224 // TODO Auto-generated method stub
229 public String nativeSQL(String sql) throws SQLException {
230 // TODO Auto-generated method stub
235 public CallableStatement prepareCall(String sql) throws SQLException {
236 // TODO Auto-generated method stub
241 public CallableStatement prepareCall(String sql, int resultSetType,
242 int resultSetConcurrency) throws SQLException {
243 // TODO Auto-generated method stub
248 public CallableStatement prepareCall(String sql, int resultSetType,
249 int resultSetConcurrency, int resultSetHoldability)
250 throws SQLException {
251 // TODO Auto-generated method stub
256 public PreparedStatement prepareStatement(String sql) throws SQLException {
257 return new PreparedStatementMock(this, sql);
261 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
262 throws SQLException {
263 // TODO Auto-generated method stub
268 public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
269 throws SQLException {
270 // TODO Auto-generated method stub
275 public PreparedStatement prepareStatement(String sql, String[] columnNames)
276 throws SQLException {
277 // TODO Auto-generated method stub
282 public PreparedStatement prepareStatement(String sql, int resultSetType,
283 int resultSetConcurrency) throws SQLException {
284 // TODO Auto-generated method stub
289 public PreparedStatement prepareStatement(String sql, int resultSetType,
290 int resultSetConcurrency, int resultSetHoldability)
291 throws SQLException {
292 // TODO Auto-generated method stub
297 public void releaseSavepoint(Savepoint savepoint) throws SQLException {
298 // TODO Auto-generated method stub
303 public void rollback() throws SQLException {
304 // TODO Auto-generated method stub
309 public void rollback(Savepoint savepoint) throws SQLException {
310 // TODO Auto-generated method stub
315 public void setAutoCommit(boolean autoCommit) throws SQLException {
316 // TODO Auto-generated method stub
321 public void setCatalog(String catalog) throws SQLException {
322 // TODO Auto-generated method stub
327 public void setClientInfo(Properties properties)
328 throws SQLClientInfoException {
329 // TODO Auto-generated method stub
334 public void setClientInfo(String name, String value)
335 throws SQLClientInfoException {
336 // TODO Auto-generated method stub
341 public void setHoldability(int holdability) throws SQLException {
342 // TODO Auto-generated method stub
347 public void setNetworkTimeout(Executor executor, int milliseconds)
348 throws SQLException {
349 // TODO Auto-generated method stub
354 public void setReadOnly(boolean readOnly) throws SQLException {
355 // TODO Auto-generated method stub
360 public Savepoint setSavepoint() throws SQLException {
361 // TODO Auto-generated method stub
366 public Savepoint setSavepoint(String name) throws SQLException {
367 // TODO Auto-generated method stub
372 public void setSchema(String schema) throws SQLException {
373 // TODO Auto-generated method stub
378 public void setTransactionIsolation(int level) throws SQLException {
379 // TODO Auto-generated method stub
384 public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
385 // TODO Auto-generated method stub