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> m_executedQueries;
27 public ConnectionMock() {
28 m_executedQueries = new ArrayList<String>();
31 public ResultSetMock mock_executeQuery(PreparedStatementMock psm)
33 m_executedQueries.add(psm.toString());
34 return new ResultSetMock();
37 public boolean mock_queryWasExecuted(String sql) {
38 // There's an assumption here that we don't try a large number of queries in a single test.
39 // If that assumption is false, then we should change this to be more efficient.
40 return m_executedQueries.contains(sql);
44 public boolean isWrapperFor(Class<?> arg0) throws SQLException {
45 // TODO Auto-generated method stub
50 public <T> T unwrap(Class<T> arg0) throws SQLException {
51 // TODO Auto-generated method stub
56 public void abort(Executor executor) throws SQLException {
57 // TODO Auto-generated method stub
62 public void clearWarnings() throws SQLException {
63 // TODO Auto-generated method stub
68 public void close() throws SQLException {
69 // TODO Auto-generated method stub
74 public void commit() throws SQLException {
75 // TODO Auto-generated method stub
80 public Array createArrayOf(String typeName, Object[] elements)
82 // TODO Auto-generated method stub
87 public Blob createBlob() throws SQLException {
88 // TODO Auto-generated method stub
93 public Clob createClob() throws SQLException {
94 // TODO Auto-generated method stub
99 public NClob createNClob() throws SQLException {
100 // TODO Auto-generated method stub
105 public SQLXML createSQLXML() throws SQLException {
106 // TODO Auto-generated method stub
111 public Statement createStatement() throws SQLException {
112 // TODO Auto-generated method stub
117 public Statement createStatement(int resultSetType, int resultSetConcurrency)
118 throws SQLException {
119 // TODO Auto-generated method stub
124 public Statement createStatement(int resultSetType,
125 int resultSetConcurrency, int resultSetHoldability)
126 throws SQLException {
127 // TODO Auto-generated method stub
132 public Struct createStruct(String typeName, Object[] attributes)
133 throws SQLException {
134 // TODO Auto-generated method stub
139 public boolean getAutoCommit() throws SQLException {
140 // TODO Auto-generated method stub
145 public String getCatalog() throws SQLException {
146 // TODO Auto-generated method stub
151 public Properties getClientInfo() throws SQLException {
152 // TODO Auto-generated method stub
157 public String getClientInfo(String name) throws SQLException {
158 // TODO Auto-generated method stub
163 public int getHoldability() throws SQLException {
164 // TODO Auto-generated method stub
169 public DatabaseMetaData getMetaData() throws SQLException {
170 DatabaseMetaData result = new DatabaseMetaDataMock();
175 public int getNetworkTimeout() throws SQLException {
176 // TODO Auto-generated method stub
181 public String getSchema() throws SQLException {
182 // TODO Auto-generated method stub
187 public int getTransactionIsolation() throws SQLException {
188 // TODO Auto-generated method stub
193 public Map<String, Class<?>> getTypeMap() throws SQLException {
194 // TODO Auto-generated method stub
199 public SQLWarning getWarnings() throws SQLException {
200 // TODO Auto-generated method stub
205 public boolean isClosed() throws SQLException {
206 // TODO Auto-generated method stub
211 public boolean isReadOnly() throws SQLException {
212 // TODO Auto-generated method stub
217 public boolean isValid(int timeout) throws SQLException {
218 // TODO Auto-generated method stub
223 public String nativeSQL(String sql) throws SQLException {
224 // TODO Auto-generated method stub
229 public CallableStatement prepareCall(String sql) throws SQLException {
230 // TODO Auto-generated method stub
235 public CallableStatement prepareCall(String sql, int resultSetType,
236 int resultSetConcurrency) throws SQLException {
237 // TODO Auto-generated method stub
242 public CallableStatement prepareCall(String sql, int resultSetType,
243 int resultSetConcurrency, int resultSetHoldability)
244 throws SQLException {
245 // TODO Auto-generated method stub
250 public PreparedStatement prepareStatement(String sql) throws SQLException {
251 return new PreparedStatementMock(this, sql);
255 public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
256 throws SQLException {
257 // TODO Auto-generated method stub
262 public PreparedStatement prepareStatement(String sql, int[] columnIndexes)
263 throws SQLException {
264 // TODO Auto-generated method stub
269 public PreparedStatement prepareStatement(String sql, String[] columnNames)
270 throws SQLException {
271 // TODO Auto-generated method stub
276 public PreparedStatement prepareStatement(String sql, int resultSetType,
277 int resultSetConcurrency) throws SQLException {
278 // TODO Auto-generated method stub
283 public PreparedStatement prepareStatement(String sql, int resultSetType,
284 int resultSetConcurrency, int resultSetHoldability)
285 throws SQLException {
286 // TODO Auto-generated method stub
291 public void releaseSavepoint(Savepoint savepoint) throws SQLException {
292 // TODO Auto-generated method stub
297 public void rollback() throws SQLException {
298 // TODO Auto-generated method stub
303 public void rollback(Savepoint savepoint) throws SQLException {
304 // TODO Auto-generated method stub
309 public void setAutoCommit(boolean autoCommit) throws SQLException {
310 // TODO Auto-generated method stub
315 public void setCatalog(String catalog) throws SQLException {
316 // TODO Auto-generated method stub
321 public void setClientInfo(Properties properties)
322 throws SQLClientInfoException {
323 // TODO Auto-generated method stub
328 public void setClientInfo(String name, String value)
329 throws SQLClientInfoException {
330 // TODO Auto-generated method stub
335 public void setHoldability(int holdability) throws SQLException {
336 // TODO Auto-generated method stub
341 public void setNetworkTimeout(Executor executor, int milliseconds)
342 throws SQLException {
343 // TODO Auto-generated method stub
348 public void setReadOnly(boolean readOnly) throws SQLException {
349 // TODO Auto-generated method stub
354 public Savepoint setSavepoint() throws SQLException {
355 // TODO Auto-generated method stub
360 public Savepoint setSavepoint(String name) throws SQLException {
361 // TODO Auto-generated method stub
366 public void setSchema(String schema) throws SQLException {
367 // TODO Auto-generated method stub
372 public void setTransactionIsolation(int level) throws SQLException {
373 // TODO Auto-generated method stub
378 public void setTypeMap(Map<String, Class<?>> map) throws SQLException {
379 // TODO Auto-generated method stub