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.sql.Connection ; 36 import java.sql.ResultSet ; 37 import java.sql.SQLException ; 38 import java.sql.SQLWarning ; 39 import java.sql.Statement ; 40 import java.util.logging.Logger ; 41 42 45 public class SpyStatement implements java.sql.Statement { 46 protected final static Logger log = Log.open(SpyStatement.class); 47 protected final static L10N L = new L10N(SpyConnection.class); 48 49 protected String _id; 50 51 protected Connection _conn; 53 54 protected Statement _stmt; 56 57 SpyStatement(String id, Connection conn, Statement stmt) 58 { 59 _id = id; 60 61 _conn = conn; 62 _stmt = stmt; 63 } 64 65 public Statement getStatement() 66 { 67 return _stmt; 68 } 69 70 public void addBatch(String sql) 71 throws SQLException 72 { 73 try { 74 log.info(_id + ":addBatch(" + sql + ")"); 75 76 _stmt.addBatch(sql); 77 } catch (Throwable e) { 78 log.info(_id + ":exn-addBatch(" + e + ")"); 79 80 throw SQLExceptionWrapper.create(e); 81 } 82 } 83 84 public void cancel() 85 throws SQLException 86 { 87 try { 88 log.info(_id + ":cancel()"); 89 90 _stmt.cancel(); 91 } catch (Throwable e) { 92 log.info(_id + ":exn-cancel(" + e + ")"); 93 94 throw SQLExceptionWrapper.create(e); 95 } 96 } 97 98 public void clearBatch() 99 throws SQLException 100 { 101 try { 102 log.info(_id + ":clearBatch()"); 103 104 _stmt.clearBatch(); 105 } catch (Throwable e) { 106 log.info(_id + ":exn-clearBatch(" + e + ")"); 107 108 throw SQLExceptionWrapper.create(e); 109 } 110 } 111 112 public void clearWarnings() 113 throws SQLException 114 { 115 try { 116 log.info(_id + ":clearWarnings()"); 117 118 _stmt.clearWarnings(); 119 } catch (Throwable e) { 120 log.info(_id + ":exn-clearWarnings(" + e + ")"); 121 122 throw SQLExceptionWrapper.create(e); 123 } 124 } 125 126 public void close() 127 throws SQLException 128 { 129 try { 130 log.info(_id + ":close()"); 131 132 _stmt.close(); 133 } catch (Throwable e) { 134 log.info(_id + ":exn-close(" + e + ")"); 135 136 throw SQLExceptionWrapper.create(e); 137 } 138 } 139 140 public java.sql.ResultSet executeQuery(String sql) 141 throws SQLException 142 { 143 try { 144 log.info(_id + ":executeQuery(" + sql + ")"); 145 146 ResultSet rs = _stmt.executeQuery(sql); 147 148 return rs; 149 } catch (Throwable e) { 150 log.info(_id + ":exn-executeQuery(" + sql + ") -> " + e); 151 152 throw SQLExceptionWrapper.create(e); 153 } 154 } 155 156 public int executeUpdate(String sql) 157 throws SQLException 158 { 159 try { 160 int count = _stmt.executeUpdate(sql); 161 162 log.info(_id + ":executeUpdate(" + sql + ") -> " + count); 163 164 return count; 165 } catch (Throwable e) { 166 log.info(_id + ":exn-executeUpdate(" + sql + ") -> " + e); 167 168 throw SQLExceptionWrapper.create(e); 169 } 170 } 171 172 public boolean execute(String sql) 173 throws SQLException 174 { 175 try { 176 boolean hasResult = _stmt.execute(sql); 177 178 log.info(_id + ":execute(" + sql + ") -> " + hasResult); 179 180 return hasResult; 181 } catch (Throwable e) { 182 log.info(_id + ":exn-execute(" + sql + ") -> " + e); 183 184 throw SQLExceptionWrapper.create(e); 185 } 186 } 187 188 public int[]executeBatch() 189 throws SQLException 190 { 191 try { 192 int []result = _stmt.executeBatch(); 193 194 log.info(_id + ":executeBatch()"); 195 196 return result; 197 } catch (Throwable e) { 198 log.info(_id + ":exn-executeBatch(" + e + ")"); 199 200 throw SQLExceptionWrapper.create(e); 201 } 202 } 203 204 public java.sql.ResultSet getResultSet() 205 throws SQLException 206 { 207 try { 208 ResultSet result = _stmt.getResultSet(); 209 210 log.info(_id + ":getResultSet() -> " + result); 211 212 return result; 213 } catch (Throwable e) { 214 log.info(_id + ":exn-getResultSet(" + e + ")"); 215 216 throw SQLExceptionWrapper.create(e); 217 } 218 } 219 220 public int getUpdateCount() 221 throws SQLException 222 { 223 try { 224 int updateCount = _stmt.getUpdateCount(); 225 226 log.info(_id + ":getUpdateCount() -> " + updateCount); 227 228 return updateCount; 229 } catch (Throwable e) { 230 log.info(_id + ":exn-getUpdateCount(" + e + ")"); 231 232 throw SQLExceptionWrapper.create(e); 233 } 234 } 235 236 public java.sql.Connection getConnection() 237 throws SQLException 238 { 239 int updateCount = _stmt.getUpdateCount(); 240 241 log.info(_id + ":getConnection()"); 242 243 return _conn; 244 } 245 246 public int getFetchDirection() 247 throws SQLException 248 { 249 try { 250 int result = _stmt.getFetchDirection(); 251 252 log.info(_id + ":getFetchDirection() -> " + result); 253 254 return result; 255 } catch (Throwable e) { 256 log.info(_id + ":exn-getFetchDirection(" + e + ")"); 257 258 throw SQLExceptionWrapper.create(e); 259 } 260 } 261 262 public int getFetchSize() 263 throws SQLException 264 { 265 try { 266 int result = _stmt.getFetchSize(); 267 268 log.info(_id + ":getFetchSize() -> " + result); 269 270 return result; 271 } catch (Throwable e) { 272 log.info(_id + ":exn-getFetchSize(" + e + ")"); 273 274 throw SQLExceptionWrapper.create(e); 275 } 276 } 277 278 public int getMaxFieldSize() 279 throws SQLException 280 { 281 try { 282 int result = _stmt.getMaxFieldSize(); 283 284 log.info(_id + ":getMaxFieldSize() -> " + result); 285 286 return result; 287 } catch (Throwable e) { 288 log.info(_id + ":exn-getMaxFieldSize(" + e + ")"); 289 290 throw SQLExceptionWrapper.create(e); 291 } 292 } 293 294 public int getMaxRows() 295 throws SQLException 296 { 297 try { 298 int result = _stmt.getMaxRows(); 299 300 log.info(_id + ":getMaxRows() -> " + result); 301 302 return result; 303 } catch (Throwable e) { 304 log.info(_id + ":exn-getMaxRows(" + e + ")"); 305 306 throw SQLExceptionWrapper.create(e); 307 } 308 } 309 310 public void setMaxRows(int max) 311 throws SQLException 312 { 313 try { 314 log.info(_id + ":setMaxRows(" + max + ")"); 315 316 _stmt.setMaxRows(max); 317 } catch (Throwable e) { 318 log.info(_id + ":exn-setMaxRows(" + e + ")"); 319 320 throw SQLExceptionWrapper.create(e); 321 } 322 } 323 324 public boolean getMoreResults() 325 throws SQLException 326 { 327 try { 328 boolean result = _stmt.getMoreResults(); 329 330 log.info(_id + ":getMoreResults() -> " + result); 331 332 return result; 333 } catch (Throwable e) { 334 log.info(_id + ":exn-getMoreResults(" + e + ")"); 335 336 throw SQLExceptionWrapper.create(e); 337 } 338 } 339 340 public int getQueryTimeout() 341 throws SQLException 342 { 343 try { 344 int result = _stmt.getQueryTimeout(); 345 346 log.info(_id + ":getQueryTimeout() -> " + result); 347 348 return result; 349 } catch (Throwable e) { 350 log.info(_id + ":exn-getQueryTimeout(" + e + ")"); 351 352 throw SQLExceptionWrapper.create(e); 353 } 354 } 355 356 public int getResultSetConcurrency() 357 throws SQLException 358 { 359 try { 360 int result = _stmt.getResultSetConcurrency(); 361 362 log.info(_id + ":getResultSetConcurrency() -> " + result); 363 364 return result; 365 } catch (Throwable e) { 366 log.info(_id + ":exn-getResultSetConcurrency(" + e + ")"); 367 368 throw SQLExceptionWrapper.create(e); 369 } 370 } 371 372 public int getResultSetType() 373 throws SQLException 374 { 375 try { 376 int result = _stmt.getResultSetType(); 377 378 log.info(_id + ":getResultSetType() -> " + result); 379 380 return result; 381 } catch (Throwable e) { 382 log.info(_id + ":exn-getResultSetType(" + e + ")"); 383 384 throw SQLExceptionWrapper.create(e); 385 } 386 } 387 388 public SQLWarning getWarnings() 389 throws SQLException 390 { 391 try { 392 SQLWarning result = _stmt.getWarnings(); 393 394 log.info(_id + ":getWarnings() -> " + result); 395 396 return result; 397 } catch (Throwable e) { 398 log.info(_id + ":exn-getWarnings(" + e + ")"); 399 400 throw SQLExceptionWrapper.create(e); 401 } 402 } 403 404 public void setCursorName(String name) 405 throws SQLException 406 { 407 try { 408 log.info(_id + ":setCursorName(" + name + ")"); 409 410 _stmt.setCursorName(name); 411 } catch (Throwable e) { 412 log.info(_id + ":exn-setCursorName(" + e + ")"); 413 414 throw SQLExceptionWrapper.create(e); 415 } 416 } 417 418 public void setEscapeProcessing(boolean enable) 419 throws SQLException 420 { 421 try { 422 log.info(_id + ":setEscapeProcessing(" + enable + ")"); 423 424 _stmt.setEscapeProcessing(enable); 425 } catch (Throwable e) { 426 log.info(_id + ":exn-setEscapeProcessing(" + e + ")"); 427 428 throw SQLExceptionWrapper.create(e); 429 } 430 } 431 432 public void setFetchDirection(int direction) 433 throws SQLException 434 { 435 try { 436 log.info(_id + ":setFetchDirection(" + direction + ")"); 437 438 _stmt.setFetchDirection(direction); 439 } catch (Throwable e) { 440 log.info(_id + ":exn-setFetchDirection(" + e + ")"); 441 442 throw SQLExceptionWrapper.create(e); 443 } 444 } 445 446 public void setFetchSize(int rows) 447 throws SQLException 448 { 449 try { 450 log.info(_id + ":setFetchSize(" + rows + ")"); 451 452 _stmt.setFetchSize(rows); 453 } catch (Throwable e) { 454 log.info(_id + ":exn-setFetchSize(" + e + ")"); 455 456 throw SQLExceptionWrapper.create(e); 457 } 458 } 459 460 public void setMaxFieldSize(int max) 461 throws SQLException 462 { 463 try { 464 log.info(_id + ":setMaxFieldSize(" + max + ")"); 465 466 _stmt.setMaxFieldSize(max); 467 } catch (Throwable e) { 468 log.info(_id + ":exn-setMaxFieldSize(" + e + ")"); 469 470 throw SQLExceptionWrapper.create(e); 471 } 472 } 473 474 public void setQueryTimeout(int seconds) 475 throws SQLException 476 { 477 try { 478 log.info(_id + ":setQueryTimeout(" + seconds + ")"); 479 480 _stmt.setQueryTimeout(seconds); 481 } catch (Throwable e) { 482 log.info(_id + ":exn-setQueryTimeout(" + e + ")"); 483 484 throw SQLExceptionWrapper.create(e); 485 } 486 } 487 488 public boolean getMoreResults(int count) 490 throws SQLException 491 { 492 return _stmt.getMoreResults(count); 493 } 494 495 public java.sql.ResultSet getGeneratedKeys() 496 throws SQLException 497 { 498 return _stmt.getGeneratedKeys(); 499 } 500 501 public int executeUpdate(String query, int resultType) 502 throws SQLException 503 { 504 return _stmt.executeUpdate(query, resultType); 505 } 506 507 public int executeUpdate(String query, int []columns) 508 throws SQLException 509 { 510 return _stmt.executeUpdate(query, columns); 511 } 512 513 public int executeUpdate(String query, String []columns) 514 throws SQLException 515 { 516 return _stmt.executeUpdate(query, columns); 517 } 518 519 public boolean execute(String query, int resultType) 520 throws SQLException 521 { 522 return _stmt.execute(query, resultType); 523 } 524 525 public boolean execute(String query, int []columns) 526 throws SQLException 527 { 528 return _stmt.execute(query, columns); 529 } 530 531 public boolean execute(String query, String []columns) 532 throws SQLException 533 { 534 return _stmt.execute(query, columns); 535 } 536 537 public int getResultSetHoldability() 538 throws SQLException 539 { 540 return _stmt.getResultSetHoldability(); 541 } 542 } 543 | Popular Tags |