1 28 29 package com.caucho.sql.spy; 30 31 import com.caucho.log.Log; 32 import com.caucho.sql.SQLExceptionWrapper; 33 import com.caucho.util.L10N; 34 35 import java.io.InputStream ; 36 import java.io.Reader ; 37 import java.math.BigDecimal ; 38 import java.net.URL ; 39 import java.sql.*; 40 import java.util.Calendar ; 41 import java.util.logging.Logger ; 42 43 46 public class SpyPreparedStatement extends SpyStatement 47 implements java.sql.PreparedStatement { 48 protected final static Logger log = Log.open(SpyPreparedStatement.class); 49 protected static L10N L = new L10N(SpyPreparedStatement.class); 50 51 private String _sql; 52 protected PreparedStatement _pstmt; 53 54 SpyPreparedStatement(String id, Connection conn, 55 PreparedStatement stmt, String sql) 56 { 57 super(id, conn, stmt); 58 59 _pstmt = stmt; 60 _sql = sql; 61 } 62 63 public java.sql.ResultSet executeQuery() 64 throws SQLException 65 { 66 try { 67 log.info(_id + ":executeQuery(" + _sql + ")"); 68 69 ResultSet rs = _pstmt.executeQuery(); 70 71 return rs; 72 } catch (Throwable e) { 73 log.info(_id + ":exn-executeQuery(" + e + ")"); 74 75 throw SQLExceptionWrapper.create(e); 76 } 77 } 78 79 public int executeUpdate() 80 throws SQLException 81 { 82 try { 83 int result = _pstmt.executeUpdate(); 84 85 log.info(_id + ":executeUpdate(" + _sql + ") -> " + result); 86 87 return result; 88 } catch (Throwable e) { 89 log.info(_id + ":exn-executeUpdate(" + e + ")"); 90 91 throw SQLExceptionWrapper.create(e); 92 } 93 } 94 95 public boolean execute() 96 throws SQLException 97 { 98 try { 99 boolean result = _pstmt.execute(); 100 101 log.info(_id + ":execute(" + _sql + ") -> " + result); 102 103 return result; 104 } catch (Throwable e) { 105 log.info(_id + ":exn-execute(" + e + ")"); 106 107 throw SQLExceptionWrapper.create(e); 108 } 109 } 110 111 public void addBatch() 112 throws SQLException 113 { 114 try { 115 _pstmt.addBatch(); 116 117 log.info(_id + ":addBatch()"); 118 } catch (Throwable e) { 119 log.info(_id + ":exn-addBatch(" + e + ")"); 120 121 throw SQLExceptionWrapper.create(e); 122 } 123 } 124 125 public void clearParameters() 126 throws SQLException 127 { 128 try { 129 log.info(_id + ":clearParameters()"); 130 131 _pstmt.clearParameters(); 132 } catch (Throwable e) { 133 log.info(_id + ":exn-clearParameters(" + e + ")"); 134 135 throw SQLExceptionWrapper.create(e); 136 } 137 } 138 139 public ResultSetMetaData getMetaData() 140 throws SQLException 141 { 142 try { 143 ResultSetMetaData result = _pstmt.getMetaData(); 144 145 log.info(_id + ":getMetaData() -> " + result); 146 147 return result; 148 } catch (Throwable e) { 149 log.info(_id + ":exn-getMetaData(" + e + ")"); 150 151 throw SQLExceptionWrapper.create(e); 152 } 153 } 154 155 public ParameterMetaData getParameterMetaData() 156 throws SQLException 157 { 158 return _pstmt.getParameterMetaData(); 159 } 160 161 public void setNull(int parameterIndex, int sqlType) 162 throws SQLException 163 { 164 try { 165 log.info(_id + ":setNull(" + parameterIndex + ",type=" + sqlType + ")"); 166 167 _pstmt.setNull(parameterIndex, sqlType); 168 } catch (Throwable e) { 169 log.info(_id + ":exn-setNull(" + e + ")"); 170 171 throw SQLExceptionWrapper.create(e); 172 } 173 } 174 175 public void setNull(int parameterIndex, int sqlType, String typeName) 176 throws SQLException 177 { 178 try { 179 log.info(_id + ":setNull(" + parameterIndex + ",type=" + sqlType + 180 ",typeName=" + typeName + ")"); 181 182 _pstmt.setNull(parameterIndex, sqlType, typeName); 183 } catch (Throwable e) { 184 log.info(_id + ":exn-setNull(" + e + ")"); 185 186 throw SQLExceptionWrapper.create(e); 187 } 188 } 189 190 public void setBoolean(int index, boolean value) 191 throws SQLException 192 { 193 try { 194 log.info(_id + ":setBoolean(" + index + "," + value + ")"); 195 196 _pstmt.setBoolean(index, value); 197 } catch (Throwable e) { 198 log.info(_id + ":exn-setBoolean(" + e + ")"); 199 200 throw SQLExceptionWrapper.create(e); 201 } 202 } 203 204 public void setByte(int index, byte value) 205 throws SQLException 206 { 207 try { 208 log.info(_id + ":setByte(" + index + "," + value + ")"); 209 210 _pstmt.setByte(index, value); 211 } catch (Throwable e) { 212 log.info(_id + ":exn-setByte(" + e + ")"); 213 214 throw SQLExceptionWrapper.create(e); 215 } 216 } 217 218 public void setShort(int index, short value) 219 throws SQLException 220 { 221 try { 222 log.info(_id + ":setShort(" + index + "," + value + ")"); 223 224 _pstmt.setShort(index, value); 225 } catch (Throwable e) { 226 log.info(_id + ":exn-setShort(" + e + ")"); 227 228 throw SQLExceptionWrapper.create(e); 229 } 230 } 231 232 public void setInt(int index, int value) 233 throws SQLException 234 { 235 try { 236 log.info(_id + ":setInt(" + index + "," + value + ")"); 237 238 _pstmt.setInt(index, value); 239 } catch (Throwable e) { 240 log.info(_id + ":exn-setInt(" + e + ")"); 241 242 throw SQLExceptionWrapper.create(e); 243 } 244 } 245 246 public void setLong(int index, long value) 247 throws SQLException 248 { 249 try { 250 log.info(_id + ":setLong(" + index + "," + value + ")"); 251 252 _pstmt.setLong(index, value); 253 } catch (Throwable e) { 254 log.info(_id + ":exn-setLong(" + e + ")"); 255 256 throw SQLExceptionWrapper.create(e); 257 } 258 } 259 260 public void setFloat(int index, float value) 261 throws SQLException 262 { 263 try { 264 log.info(_id + ":setFloat(" + index + "," + value + ")"); 265 266 _pstmt.setFloat(index, value); 267 } catch (Throwable e) { 268 log.info(_id + ":exn-setFloat(" + e + ")"); 269 270 throw SQLExceptionWrapper.create(e); 271 } 272 } 273 274 public void setDouble(int index, double value) 275 throws SQLException 276 { 277 try { 278 log.info(_id + ":setDouble(" + index + "," + value + ")"); 279 280 _pstmt.setDouble(index, value); 281 } catch (Throwable e) { 282 log.info(_id + ":exn-setDouble(" + e + ")"); 283 284 throw SQLExceptionWrapper.create(e); 285 } 286 } 287 288 public void setBigDecimal(int index, BigDecimal value) 289 throws SQLException 290 { 291 try { 292 log.info(_id + ":setBigDecimal(" + index + "," + value + ")"); 293 294 _pstmt.setBigDecimal(index, value); 295 } catch (Throwable e) { 296 log.info(_id + ":exn-setBigDecimal(" + e + ")"); 297 298 throw SQLExceptionWrapper.create(e); 299 } 300 } 301 302 public void setString(int index, String value) 303 throws SQLException 304 { 305 try { 306 log.info(_id + ":setString(" + index + "," + value + ")"); 307 308 _pstmt.setString(index, value); 309 } catch (Throwable e) { 310 log.info(_id + ":exn-setString(" + e + ")"); 311 312 throw SQLExceptionWrapper.create(e); 313 } 314 } 315 316 public void setBytes(int index, byte []value) 317 throws SQLException 318 { 319 try { 320 if (value != null) 321 log.info(_id + ":setBytes(" + index + ",len=" + value.length + ")"); 322 else 323 log.info(_id + ":setBytes(" + index + ",null"); 324 325 _pstmt.setBytes(index, value); 326 } catch (Throwable e) { 327 log.info(_id + ":exn-setBytes(" + e + ")"); 328 329 throw SQLExceptionWrapper.create(e); 330 } 331 } 332 333 public void setDate(int index, Date value) 334 throws SQLException 335 { 336 try { 337 log.info(_id + ":setDate(" + index + "," + value + ")"); 338 339 _pstmt.setDate(index, value); 340 } catch (Throwable e) { 341 log.info(_id + ":exn-setDate(" + e + ")"); 342 343 throw SQLExceptionWrapper.create(e); 344 } 345 } 346 347 public void setDate(int index, Date value, Calendar cal) 348 throws SQLException 349 { 350 try { 351 log.info(_id + ":setDate(" + index + "," + value + ",cal=" + cal + ")"); 352 353 _pstmt.setDate(index, value, cal); 354 } catch (Throwable e) { 355 log.info(_id + ":exn-setDate(" + e + ")"); 356 357 throw SQLExceptionWrapper.create(e); 358 } 359 } 360 361 public void setTime(int index, Time value) 362 throws SQLException 363 { 364 try { 365 log.info(_id + ":setTime(" + index + "," + value + ")"); 366 367 _pstmt.setTime(index, value); 368 } catch (Throwable e) { 369 log.info(_id + ":exn-setTime(" + e + ")"); 370 371 throw SQLExceptionWrapper.create(e); 372 } 373 } 374 375 public void setTime(int index, Time value, Calendar cal) 376 throws SQLException 377 { 378 try { 379 log.info(_id + ":setTime(" + index + "," + value + ",cal=" + cal + ")"); 380 381 _pstmt.setTime(index, value, cal); 382 } catch (Throwable e) { 383 log.info(_id + ":exn-setTime(" + e + ")"); 384 385 throw SQLExceptionWrapper.create(e); 386 } 387 } 388 389 public void setTimestamp(int index, Timestamp value) 390 throws SQLException 391 { 392 try { 393 log.info(_id + ":setTimestamp(" + index + "," + value + ")"); 394 395 _pstmt.setTimestamp(index, value); 396 } catch (Throwable e) { 397 log.info(_id + ":exn-setTimestamp(" + e + ")"); 398 399 throw SQLExceptionWrapper.create(e); 400 } 401 } 402 403 public void setTimestamp(int index, Timestamp value, Calendar cal) 404 throws SQLException 405 { 406 try { 407 log.info(_id + ":setTimestamp(" + index + "," + value + ",cal=" + cal + ")"); 408 409 _pstmt.setTimestamp(index, value, cal); 410 } catch (Throwable e) { 411 log.info(_id + ":exn-setTimestamp(" + e + ")"); 412 413 throw SQLExceptionWrapper.create(e); 414 } 415 } 416 417 public void setAsciiStream(int index, InputStream value, int length) 418 throws SQLException 419 { 420 try { 421 log.info(_id + ":setAsciiStream(" + index + "," + value + ",len=" + length + ")"); 422 423 _pstmt.setAsciiStream(index, value, length); 424 } catch (Throwable e) { 425 log.info(_id + ":exn-setAsciiStream(" + e + ")"); 426 427 throw SQLExceptionWrapper.create(e); 428 } 429 } 430 431 public void setUnicodeStream(int index, InputStream value, int length) 432 throws SQLException 433 { 434 try { 435 log.info(_id + ":setUnicodeStream(" + index + "," + value + ",len=" + length + ")"); 436 437 _pstmt.setUnicodeStream(index, value, length); 438 } catch (Throwable e) { 439 log.info(_id + ":exn-setUnicodeStream(" + e + ")"); 440 441 throw SQLExceptionWrapper.create(e); 442 } 443 } 444 445 public void setBinaryStream(int index, InputStream value, int length) 446 throws SQLException 447 { 448 try { 449 log.info(_id + ":setBinaryStream(" + index + "," + value + ",len=" + length + ")"); 450 451 _pstmt.setBinaryStream(index, value, length); 452 } catch (Throwable e) { 453 log.info(_id + ":exn-setBinaryStream(" + e + ")"); 454 455 throw SQLExceptionWrapper.create(e); 456 } 457 } 458 459 public void setCharacterStream(int index, Reader value, int length) 460 throws SQLException 461 { 462 try { 463 log.info(_id + ":setCharacterStream(" + index + "," + value + ",len=" + length + ")"); 464 465 _pstmt.setCharacterStream(index, value, length); 466 } catch (Throwable e) { 467 log.info(_id + ":exn-setCharacterStream(" + e + ")"); 468 469 throw SQLExceptionWrapper.create(e); 470 } 471 } 472 473 public void setObject(int index, Object value, int type, int scale) 474 throws SQLException 475 { 476 try { 477 log.info(_id + ":setObject(" + index + "," + value + 478 ",type=" + type + ",scale=" + scale + ")"); 479 480 _pstmt.setObject(index, value, type, scale); 481 } catch (Throwable e) { 482 log.info(_id + ":exn-setObject(" + e + ")"); 483 484 throw SQLExceptionWrapper.create(e); 485 } 486 } 487 488 public void setObject(int index, Object value, int type) 489 throws SQLException 490 { 491 try { 492 log.info(_id + ":setObject(" + index + "," + value + 493 ",type=" + type + ")"); 494 495 _pstmt.setObject(index, value, type); 496 } catch (Throwable e) { 497 log.info(_id + ":exn-setObject(" + e + ")"); 498 499 throw SQLExceptionWrapper.create(e); 500 } 501 } 502 503 public void setObject(int index, Object value) 504 throws SQLException 505 { 506 try { 507 log.info(_id + ":setObject(" + index + "," + value + ")"); 508 509 _pstmt.setObject(index, value); 510 } catch (Throwable e) { 511 e.printStackTrace(); 512 513 log.info(_id + ":exn-setObject(" + e + ")"); 514 515 throw SQLExceptionWrapper.create(e); 516 } 517 } 518 519 public void setRef(int index, Ref value) 520 throws SQLException 521 { 522 try { 523 log.info(_id + ":setRef(" + index + "," + value + ")"); 524 525 _pstmt.setRef(index, value); 526 } catch (Throwable e) { 527 log.info(_id + ":exn-setRef(" + e + ")"); 528 529 throw SQLExceptionWrapper.create(e); 530 } 531 } 532 533 public void setBlob(int index, Blob value) 534 throws SQLException 535 { 536 try { 537 log.info(_id + ":setBlob(" + index + "," + value + ")"); 538 539 _pstmt.setBlob(index, value); 540 } catch (Throwable e) { 541 log.info(_id + ":exn-setBlob(" + e + ")"); 542 543 throw SQLExceptionWrapper.create(e); 544 } 545 } 546 547 public void setClob(int index, Clob value) 548 throws SQLException 549 { 550 try { 551 log.info(_id + ":setClob(" + index + "," + value + ")"); 552 553 _pstmt.setClob(index, value); 554 } catch (Throwable e) { 555 log.info(_id + ":exn-setClob(" + e + ")"); 556 557 throw SQLExceptionWrapper.create(e); 558 } 559 } 560 561 public void setArray(int index, Array value) 562 throws SQLException 563 { 564 try { 565 log.info(_id + ":setArray(" + index + "," + value + ")"); 566 567 _pstmt.setArray(index, value); 568 } catch (Throwable e) { 569 log.info(_id + ":exn-setArray(" + e + ")"); 570 571 throw SQLExceptionWrapper.create(e); 572 } 573 } 574 575 public void setURL(int index, URL value) 576 throws SQLException 577 { 578 throw new UnsupportedOperationException (); 579 } 580 } 581 | Popular Tags |