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