1 58 59 61 package com.mockobjects.sql; 62 63 import java.sql.*; 64 import java.util.Calendar ; 65 import java.io.Reader ; 66 import java.math.BigDecimal ; 67 import com.mockobjects.*; 68 69 78 abstract class CommonMockPreparedStatement 79 extends CommonMockStatement implements PreparedStatement { 80 81 private ExpectationSet mySetParameters = 82 new ExpectationSet("CommonMockPreparedStatement.setParameters"); 83 84 private ExpectationCounter myClearParametersCalls = 85 new ExpectationCounter 86 ("CommonMockPreparedStatement.clearParameters() calls"); 87 88 private ExpectationSet myTargetSQLTypes = 89 new ExpectationSet("CommonMockPreparedStatement.targetSQLTypes"); 90 private final ReturnObjectList myResultSets = new ReturnObjectList("result sets"); 91 private final ReturnObjectList executeUpdates = new ReturnObjectList("update count"); 92 93 public void addResultSet(MockResultSet aResultSet) { 94 myResultSets.addObjectToReturn(aResultSet); 95 } 96 97 public void addExpectedSetParameter(int parameterIndex, int intValue) { 98 addExpectedSetParameter(parameterIndex, new Integer (intValue)); 99 } 100 101 public void addExpectedSetParameter(int parameterIndex, 102 Object parameterValue) { 103 mySetParameters.addExpected(new MapEntry(new Integer (parameterIndex), 104 parameterValue)); 105 } 106 107 public void addExpectedSetParameters(Object [] parameters) { 108 for (int i = 0; i < parameters.length; ++i) { 109 addExpectedSetParameter(i + 1, parameters[i]); 110 } 111 } 112 113 public void addExpectedTargetSQLType(int aTargetSQLType){ 114 myTargetSQLTypes.addExpected(new Integer (aTargetSQLType)); 115 } 116 117 119 public void setExpectedClearParametersCalls(int callCount) { 120 myClearParametersCalls.setExpected(callCount); 121 } 122 123 public void setExpectingNoSetParameters() { 124 mySetParameters.setExpectNothing(); 125 } 126 127 129 public void clearParameters() throws SQLException { 130 myClearParametersCalls.inc(); 131 } 132 133 136 public boolean execute() throws SQLException { 137 innerExecute(); 138 return false; 139 } 140 141 144 public ResultSet executeQuery() throws SQLException { 145 innerExecute(); 146 return (ResultSet)myResultSets.nextReturnObject(); 147 } 148 149 154 public void addUpdateCount(int count){ 155 this.executeUpdates.addObjectToReturn(count); 156 } 157 158 162 public int executeUpdate() throws SQLException { 163 innerExecute(); 164 return ((Integer )executeUpdates.nextReturnObject()).intValue(); 165 } 166 167 public void setInt(int parameterIndex, int x) throws SQLException { 168 setObject(parameterIndex, new Integer (x)); 169 } 170 171 public void setString(int parameterIndex, String x) throws SQLException { 172 setObject(parameterIndex, x); 173 } 174 175 public void setTimestamp(int param, Timestamp timestamp) throws 176 SQLException { 177 setObject(param, timestamp); 178 } 179 180 public void setClob(int param, Clob clob) throws SQLException { 181 setObject(param, clob); 182 } 183 184 public void setLong(int param, long aLong) throws SQLException { 185 setObject(param, new Long (aLong)); 186 } 187 188 public void setNull(int param, int param1) throws SQLException { 189 setObject(param, null); 190 } 191 192 public void setArray(int param, Array array) throws SQLException { 193 setObject(param, array); 194 } 195 196 public void setShort(int param, short aShort) throws SQLException { 197 setObject(param, new Short (aShort)); 198 } 199 200 public void setTime(int param, Time time, Calendar calendar) throws 201 SQLException { 202 setObject(param, time); 203 } 204 205 public void setObject(int param, Object anObject, int aTargetSQLType) 206 throws SQLException { 207 setObject(param, anObject); 208 myTargetSQLTypes.addActual(new Integer (aTargetSQLType)); 209 } 210 211 public void setRef(int param, Ref ref) throws SQLException { 212 setObject(param, ref); 213 } 214 215 public void setDate(int param, Date date) throws SQLException { 216 setObject(param, date); 217 } 218 219 public void setFloat(int param, float aFloat) throws SQLException { 220 setObject(param, new Float (aFloat)); 221 } 222 223 public void setBlob(int param, Blob blob) throws SQLException { 224 setObject(param, blob); 225 } 226 227 public void setDate(int param, Date date, Calendar calendar) throws 228 SQLException { 229 setDate(param, date); 230 } 231 232 public void setBytes(int param, byte[] values) throws SQLException { 233 setObject(param, values); 234 } 235 236 public void setObject(int param, Object anObject) throws SQLException { 237 mySetParameters.addActual(new MapEntry(new Integer (param), anObject)); 238 } 239 240 public void setByte(int param, byte aByte) throws SQLException { 241 setObject(param, new Byte (aByte)); 242 } 243 244 public void setDouble(int param, double aDouble) throws SQLException { 245 setObject(param, new Double (aDouble)); 246 } 247 248 public void setTime(int param, Time time) throws SQLException { 249 setObject(param, time); 250 } 251 252 public void setBoolean(int param, boolean aBoolean) throws SQLException { 253 setObject(param, new Boolean (aBoolean)); 254 } 255 256 public void setBigDecimal(int param, BigDecimal bigDecimal) throws 257 SQLException { 258 setObject(param, bigDecimal); 259 } 260 261 263 266 public void addBatch() throws SQLException { 267 notImplemented(); 268 } 269 270 273 public void setObject(int param, Object anObject, int targetSqlType, 274 int scale) throws SQLException { 275 notImplemented(); 276 } 277 278 281 public void setCharacterStream(int param, Reader reader, int length) 282 throws SQLException { 283 notImplemented(); 284 } 285 286 289 public void setAsciiStream(int param, java.io.InputStream inputStream, 290 int length) throws SQLException { 291 notImplemented(); 292 } 293 294 297 public void setBinaryStream(int param, java.io.InputStream inputStream, 298 int length) throws SQLException { 299 notImplemented(); 300 } 301 302 305 public void setNull(int param, int param1, String typeName) throws 306 SQLException { 307 notImplemented(); 308 } 309 310 313 public void setUnicodeStream(int param, java.io.InputStream inputStream, 314 int length) throws SQLException { 315 notImplemented(); 316 } 317 318 321 public ResultSetMetaData getMetaData() throws SQLException { 322 notImplemented(); 323 return null; 324 } 325 326 329 public void setTimestamp(int param, Timestamp timestamp, Calendar 330 calendar) throws SQLException { 331 notImplemented(); 332 } 333 334 } | Popular Tags |