1 package com.mockobjects.sql; 2 3 import com.mockobjects.ExpectationCounter; 4 import com.mockobjects.MockObject; 5 import com.mockobjects.ReturnObjectBag; 6 7 import java.sql.*; 8 9 12 abstract class CommonMockStatement extends MockObject implements Statement { 13 protected final ExpectationCounter myCloseCalls = new ExpectationCounter("CommonMockStatement.closeCalls"); 14 private final ReturnObjectBag executeQueryResults = new ReturnObjectBag("executeQuery"); 15 private final ReturnObjectBag executeUpdateResults = new ReturnObjectBag("executeUpdate"); 16 private final ReturnObjectBag executeResults = new ReturnObjectBag("execute"); 17 18 private int myUpdateCount = 0; 19 private SQLException myExecuteException = null; 20 21 private Connection myConnection = null; 22 23 public void addExpectedExecuteQuery(String queryString, ResultSet resultSet) { 24 executeQueryResults.putObjectToReturn(queryString, resultSet); 25 } 26 27 public void addExpectedExecuteUpdate(String queryString, int updateCount) { 28 executeUpdateResults.putObjectToReturn(queryString, updateCount); 29 } 30 31 public void addExpectedExecute(String queryString, boolean success) { 32 executeResults.putObjectToReturn(queryString, success); 33 } 34 35 public void setExpectedCloseCalls(int callCount) { 36 myCloseCalls.setExpected(callCount); 37 } 38 39 public void setupConnection(Connection conn) { 40 myConnection = conn; 41 } 42 43 public void setupThrowExceptionOnExecute(SQLException exception) { 44 myExecuteException = exception; 45 } 46 47 public void setupUpdateCount(int updateCount) { 48 myUpdateCount = updateCount; 49 } 50 51 protected void innerExecute() throws SQLException { 52 if (null != myExecuteException) { 53 throw myExecuteException; 54 } 55 } 56 57 public void close() throws SQLException { 58 myCloseCalls.inc(); 59 } 60 61 public boolean execute(String sql) throws SQLException { 62 innerExecute(); 63 return executeResults.getNextReturnBoolean(sql); 64 } 65 66 public ResultSet executeQuery(String sql) throws SQLException { 67 innerExecute(); 68 return (ResultSet) executeQueryResults.getNextReturnObject(sql); 69 } 70 71 public int executeUpdate(String sql) throws SQLException { 72 innerExecute(); 73 return executeUpdateResults.getNextReturnInt(sql); 74 } 75 76 public int getMaxFieldSize() throws SQLException { 77 notImplemented(); 78 return 0; 79 } 80 81 public void setMaxFieldSize(int max) throws SQLException { 82 notImplemented(); 83 } 84 85 public int getMaxRows() throws SQLException { 86 notImplemented(); 87 return 0; 88 } 89 90 public void setMaxRows(int max) throws SQLException { 91 notImplemented(); 92 } 93 94 public void setEscapeProcessing(boolean enable) throws SQLException { 95 notImplemented(); 96 } 97 98 public int getQueryTimeout() throws SQLException { 99 notImplemented(); 100 return 0; 101 } 102 103 public void setQueryTimeout(int seconds) throws SQLException { 104 notImplemented(); 105 } 106 107 public void cancel() throws SQLException { 108 notImplemented(); 109 } 110 111 public SQLWarning getWarnings() throws SQLException { 112 notImplemented(); 113 return null; 114 } 115 116 public void clearWarnings() throws SQLException { 117 notImplemented(); 118 } 119 120 public void setCursorName(String name) throws SQLException { 121 notImplemented(); 122 } 123 124 public ResultSet getResultSet() throws SQLException { 125 notImplemented(); 126 return null; 127 } 128 129 public int getUpdateCount() throws SQLException { 130 return myUpdateCount; 131 } 132 133 public boolean getMoreResults() throws SQLException { 134 notImplemented(); 135 return false; 136 } 137 138 public void setFetchDirection(int direction) throws SQLException { 139 notImplemented(); 140 } 141 142 public int getFetchDirection() throws SQLException { 143 notImplemented(); 144 return 0; 145 } 146 147 public void setFetchSize(int rows) throws SQLException { 148 notImplemented(); 149 } 150 151 public int getFetchSize() throws SQLException { 152 notImplemented(); 153 return 0; 154 } 155 156 public int getResultSetConcurrency() throws SQLException { 157 notImplemented(); 158 return 0; 159 } 160 161 public int getResultSetType() throws SQLException { 162 notImplemented(); 163 return 0; 164 } 165 166 public void addBatch(String sql) throws SQLException { 167 notImplemented(); 168 } 169 170 public void clearBatch() throws SQLException { 171 notImplemented(); 172 } 173 174 public int[] executeBatch() throws SQLException { 175 notImplemented(); 176 return null; 177 } 178 179 public Connection getConnection() throws SQLException { 180 return myConnection; 181 } 182 } 183 | Popular Tags |