1 21 22 package org.apache.derby.client.am; 23 24 import java.sql.SQLException ; 25 import java.util.Enumeration ; 26 import java.util.Properties ; 27 28 import javax.naming.NamingException ; 29 import javax.naming.RefAddr ; 30 import javax.naming.Reference ; 31 import org.apache.derby.jdbc.ClientBaseDataSource; 32 33 import org.apache.derby.jdbc.ClientDataSource; 34 import org.apache.derby.shared.common.reference.Attribute; 35 import org.apache.derby.shared.common.reference.SQLState; 36 37 public class LogWriter { 38 protected java.io.PrintWriter printWriter_; 39 protected int traceLevel_; 40 private boolean driverConfigurationHasBeenWrittenToJdbc1Stream_ = false; 41 private boolean driverConfigurationHasBeenWrittenToJdbc2Stream_ = false; 42 43 public LogWriter(java.io.PrintWriter printWriter, int traceLevel) { 45 printWriter_ = printWriter; 46 traceLevel_ = traceLevel; 47 } 48 49 final protected boolean loggingEnabled(int traceLevel) { 50 return printWriter_ != null && (traceLevel & traceLevel_) != 0; 52 } 53 54 final protected boolean traceSuspended() { 55 return org.apache.derby.client.am.Configuration.traceSuspended__; 56 } 57 58 public boolean printWriterNeedsToBeClosed_; 66 67 void close() { 68 if (printWriterNeedsToBeClosed_) { 69 printWriter_.close(); 70 printWriterNeedsToBeClosed_ = false; 71 } 72 } 74 75 77 public void dncprintln(String s) { 78 synchronized (printWriter_) { 79 printWriter_.println("[derby] " + s); 80 printWriter_.flush(); 81 } 82 } 83 84 private void dncprint(String s) { 85 synchronized (printWriter_) { 86 printWriter_.print("[derby] " + s); 87 printWriter_.flush(); 88 } 89 } 90 91 private void dncprintln(String header, String s) { 92 synchronized (printWriter_) { 93 printWriter_.println("[derby]" + header + " " + s); 94 printWriter_.flush(); 95 } 96 } 97 98 private void dncprint(String header, String s) { 99 synchronized (printWriter_) { 100 printWriter_.print("[derby]" + header + " " + s); 101 printWriter_.flush(); 102 } 103 } 104 105 107 public void tracepoint(String component, int tracepoint, String message) { 108 if (traceSuspended()) { 109 return; 110 } 111 dncprintln(component, 112 "[time:" + System.currentTimeMillis() + "]" + 113 "[thread:" + Thread.currentThread().getName() + "]" + 114 "[tracepoint:" + tracepoint + "]" + 115 message); 116 } 117 118 public void tracepoint(String component, int tracepoint, 119 String classContext, String methodContext) { 120 if (traceSuspended()) { 121 return; 122 } 123 String staticContextTracepointRecord = 124 component + 125 "[time:" + System.currentTimeMillis() + "]" + 126 "[thread:" + Thread.currentThread().getName() + "]" + 127 "[tracepoint:" + tracepoint + "]" + 128 "[" + classContext + "." + methodContext + "]"; 129 dncprintln(staticContextTracepointRecord); 130 } 131 132 public void tracepoint(String component, int tracepoint, 133 Object instance, String classContext, String methodContext) { 134 if (traceSuspended()) { 135 return; 136 } 137 String instanceContextTracepointRecord = 138 component + 139 "[time:" + System.currentTimeMillis() + "]" + 140 "[thread:" + Thread.currentThread().getName() + "]" + 141 "[tracepoint:" + tracepoint + "]" + 142 "[" + classContext + "@" + Integer.toHexString(instance.hashCode()) + "." + methodContext + "]"; 143 dncprintln(instanceContextTracepointRecord); 144 } 145 146 public void tracepoint(String component, int tracepoint, 147 String classContext, String methodContext, 148 java.util.Map memory) { 149 if (traceSuspended()) { 150 return; 151 } 152 String staticContextTracepointRecord = 153 component + 154 "[time:" + System.currentTimeMillis() + "]" + 155 "[thread:" + Thread.currentThread().getName() + "]" + 156 "[tracepoint:" + tracepoint + "]" + 157 "[" + classContext + "." + methodContext + "]"; 158 dncprintln(staticContextTracepointRecord + getMemoryMapDisplay(memory)); 159 } 160 161 public void tracepoint(String component, int tracepoint, 162 Object instance, String classContext, String methodContext, 163 java.util.Map memory) { 164 if (traceSuspended()) { 165 return; 166 } 167 String instanceContextTracepointRecord = 168 component + 169 "[time:" + System.currentTimeMillis() + "]" + 170 "[thread:" + Thread.currentThread().getName() + "]" + 171 "[tracepoint:" + tracepoint + "]" + 172 "[" + classContext + "@" + Integer.toHexString(instance.hashCode()) + "." + methodContext + "]"; 173 dncprintln(instanceContextTracepointRecord + getMemoryMapDisplay(memory)); 174 } 175 176 private String getMemoryMapDisplay(java.util.Map memory) { 177 return memory.toString(); } 179 180 188 private void traceExternalMethod(Object instance, String className, String methodName) { 189 if (traceSuspended()) { 190 return; 191 } 192 dncprint(buildExternalMethodHeader(instance, className), methodName); 193 } 194 195 private void traceExternalDeprecatedMethod(Object instance, String className, String methodName) { 196 if (traceSuspended()) { 197 return; 198 } 199 dncprint(buildExternalMethodHeader(instance, className), "Deprecated " + methodName); 200 } 201 202 private String buildExternalMethodHeader(Object instance, String className) { 203 return 204 "[Time:" + System.currentTimeMillis() + "]" + 205 "[Thread:" + Thread.currentThread().getName() + "]" + 206 "[" + className + "@" + Integer.toHexString(instance.hashCode()) + "]"; 207 } 208 209 private String getClassNameOfInstanceIfTraced(Object instance) { 210 if (instance == null) { 212 return null; 213 } else if (instance instanceof Connection && loggingEnabled(ClientDataSource.TRACE_CONNECTION_CALLS)) { 214 return "Connection"; 215 } else if (instance instanceof ResultSet && loggingEnabled(ClientDataSource.TRACE_RESULT_SET_CALLS)) { 216 return "ResultSet"; 217 } else if (instance instanceof CallableStatement && loggingEnabled(ClientDataSource.TRACE_STATEMENT_CALLS)) { 218 return "CallableStatement"; 219 } else if (instance instanceof PreparedStatement && loggingEnabled(ClientDataSource.TRACE_STATEMENT_CALLS)) { 220 return "PreparedStatement"; 221 } else if (instance instanceof Statement && loggingEnabled(ClientDataSource.TRACE_STATEMENT_CALLS)) { 222 return "Statement"; 223 } 224 else if (instance instanceof Blob && loggingEnabled(ClientDataSource.TRACE_ALL)) { 227 return "Blob"; 228 } 229 else if (instance instanceof Clob && loggingEnabled(ClientDataSource.TRACE_ALL)) { 232 return "Clob"; 233 } 234 else if (instance instanceof DatabaseMetaData && loggingEnabled(ClientDataSource.TRACE_ALL)) { 237 return "DatabaseMetaData"; 238 } 239 else if (loggingEnabled(ClientDataSource.TRACE_XA_CALLS) && 241 instance.getClass().getName().startsWith("org.apache.derby.client.net.NetXAResource")) { 242 return "NetXAResource"; 243 } else if (loggingEnabled(ClientDataSource.TRACE_ALL) && 244 instance.getClass().getName().equals("org.apache.derby.client.ClientPooledConnection")) { 245 return "ClientPooledConnection"; 246 } else if (loggingEnabled(ClientDataSource.TRACE_ALL) && 247 instance.getClass().getName().equals("org.apache.derby.jdbc.ClientConnectionPoolDataSource")) { 248 return "ClientConnectionPoolDataSource"; 249 } else if (loggingEnabled(ClientDataSource.TRACE_ALL) && 250 instance.getClass().getName().equals("org.apache.derby.client.ClientXAConnection")) { 251 return "ClientXAConnection"; 252 } else if (loggingEnabled(ClientDataSource.TRACE_ALL) && 253 instance.getClass().getName().equals("org.apache.derby.jdbc.ClientDataSource")) { 254 return "ClientDataSource"; 255 } else if (loggingEnabled(ClientDataSource.TRACE_ALL) && 256 instance.getClass().getName().equals("org.apache.derby.jdbc.ClientXADataSource")) { 257 return "ClientXADataSource"; 258 } else { 259 return instance.getClass().getName(); 260 } 261 } 262 263 265 public void traceExit(Object instance, String methodName, Object returnValue) { 266 if (traceSuspended()) { 267 return; 268 } 269 String className = getClassNameOfInstanceIfTraced(instance); 270 if (className == null) { 271 return; 272 } 273 synchronized (printWriter_) { 274 traceExternalMethod(instance, className, methodName); 275 printWriter_.println(" () returned " + returnValue); 276 printWriter_.flush(); 277 } 278 } 279 280 public void traceDeprecatedExit(Object instance, String methodName, Object returnValue) { 281 if (traceSuspended()) { 282 return; 283 } 284 String className = getClassNameOfInstanceIfTraced(instance); 285 if (className == null) { 286 return; 287 } 288 synchronized (printWriter_) { 289 traceExternalDeprecatedMethod(instance, className, methodName); 290 printWriter_.println(" () returned " + returnValue); 291 printWriter_.flush(); 292 } 293 } 294 295 public void traceExit(Object instance, String methodName, ResultSet resultSet) { 296 if (traceSuspended()) { 297 return; 298 } 299 String returnValue = (resultSet == null) ? "ResultSet@null" : "ResultSet@" + Integer.toHexString(resultSet.hashCode()); 300 traceExit(instance, methodName, returnValue); 301 } 302 303 public void traceExit(Object instance, String methodName, CallableStatement returnValue) { 304 if (traceSuspended()) { 305 return; 306 } 307 traceExit(instance, methodName, "CallableStatement@" + Integer.toHexString(returnValue.hashCode())); 308 } 309 310 public void traceExit(Object instance, String methodName, PreparedStatement returnValue) { 311 if (traceSuspended()) { 312 return; 313 } 314 traceExit(instance, methodName, "PreparedStatement@" + Integer.toHexString(returnValue.hashCode())); 315 } 316 317 public void traceExit(Object instance, String methodName, Statement returnValue) { 318 if (traceSuspended()) { 319 return; 320 } 321 traceExit(instance, methodName, "Statement@" + Integer.toHexString(returnValue.hashCode())); 322 } 323 324 public void traceExit(Object instance, String methodName, Blob blob) { 325 if (traceSuspended()) { 326 return; 327 } 328 String returnValue = (blob == null) ? "Blob@null" : "Blob@" + Integer.toHexString(blob.hashCode()); 329 traceExit(instance, methodName, returnValue); 330 } 331 332 public void traceExit(Object instance, String methodName, Clob clob) { 333 if (traceSuspended()) { 334 return; 335 } 336 String returnValue = (clob == null) ? "Clob@null" : "Clob@" + Integer.toHexString(clob.hashCode()); 337 traceExit(instance, methodName, returnValue); 338 } 339 340 public void traceExit(Object instance, String methodName, DatabaseMetaData returnValue) { 341 if (traceSuspended()) { 342 return; 343 } 344 traceExit(instance, methodName, "DatabaseMetaData@" + Integer.toHexString(returnValue.hashCode())); 345 } 346 347 public void traceExit(Object instance, String methodName, Connection returnValue) { 348 if (traceSuspended()) { 349 return; 350 } 351 traceExit(instance, methodName, "Connection@" + Integer.toHexString(returnValue.hashCode())); 352 } 353 354 public void traceExit(Object instance, String methodName, ColumnMetaData returnValue) { 355 if (traceSuspended()) { 356 return; 357 } 358 traceExit(instance, methodName, "MetaData@" + (returnValue != null ? Integer.toHexString(returnValue.hashCode()) : null)); 359 } 360 361 public void traceExit(Object instance, String methodName, byte[] returnValue) { 362 if (traceSuspended()) { 363 return; 364 } 365 traceExit(instance, methodName, Utils.getStringFromBytes(returnValue)); 366 } 367 368 public void traceExit(Object instance, String methodName, int[] returnValue) { 369 if (traceSuspended()) { 370 return; 371 } 372 traceExit(instance, methodName, Utils.getStringFromInts(returnValue)); 373 } 374 375 public void traceDeprecatedExit(Object instance, String methodName, byte[] returnValue) { 376 if (traceSuspended()) { 377 return; 378 } 379 traceDeprecatedExit(instance, methodName, Utils.getStringFromBytes(returnValue)); 380 } 381 382 public void traceExit(Object instance, String methodName, byte returnValue) { 383 if (traceSuspended()) { 384 return; 385 } 386 traceExit(instance, methodName, "0x" + Integer.toHexString(returnValue & 0xff)); 387 } 388 389 public void traceExit(Object instance, String methodName, int returnValue) { 390 if (traceSuspended()) { 391 return; 392 } 393 traceExit(instance, methodName, String.valueOf(returnValue)); 394 } 395 396 public void traceExit(Object instance, String methodName, boolean returnValue) { 397 if (traceSuspended()) { 398 return; 399 } 400 traceExit(instance, methodName, String.valueOf(returnValue)); 401 } 402 403 public void traceExit(Object instance, String methodName, long returnValue) { 404 if (traceSuspended()) { 405 return; 406 } 407 traceExit(instance, methodName, String.valueOf(returnValue)); 408 } 409 410 public void traceExit(Object instance, String methodName, float returnValue) { 411 if (traceSuspended()) { 412 return; 413 } 414 traceExit(instance, methodName, String.valueOf(returnValue)); 415 } 416 417 public void traceExit(Object instance, String methodName, double returnValue) { 418 if (traceSuspended()) { 419 return; 420 } 421 traceExit(instance, methodName, String.valueOf(returnValue)); 422 } 423 424 426 private void traceEntryAllArgs(Object instance, String methodName, String argList) { 427 if (traceSuspended()) { 428 return; 429 } 430 String className = getClassNameOfInstanceIfTraced(instance); 431 if (className == null) { 432 return; 433 } 434 synchronized (printWriter_) { 435 traceExternalMethod(instance, className, methodName); 436 printWriter_.println(" " + argList + " called"); 437 printWriter_.flush(); 438 } 439 } 440 441 private void traceDeprecatedEntryAllArgs(Object instance, String methodName, String argList) { 442 if (traceSuspended()) { 443 return; 444 } 445 String className = getClassNameOfInstanceIfTraced(instance); 446 if (className == null) { 447 return; 448 } 449 synchronized (printWriter_) { 450 traceExternalDeprecatedMethod(instance, className, methodName); 451 printWriter_.println(" " + argList + " called"); 452 printWriter_.flush(); 453 } 454 } 455 456 458 public void traceEntry(Object instance, String methodName) { 459 if (traceSuspended()) { 460 return; 461 } 462 traceEntryAllArgs(instance, methodName, "()"); 463 } 464 465 467 public void traceEntry(Object instance, String methodName, Object argument) { 468 if (traceSuspended()) { 469 return; 470 } 471 traceEntryAllArgs(instance, methodName, 472 "(" + argument + ")"); 473 } 474 475 public void traceEntry(Object instance, String methodName, boolean argument) { 476 if (traceSuspended()) { 477 return; 478 } 479 traceEntryAllArgs(instance, methodName, 480 "(" + argument + ")"); 481 } 482 483 public void traceEntry(Object instance, String methodName, int argument) { 484 if (traceSuspended()) { 485 return; 486 } 487 traceEntryAllArgs(instance, methodName, 488 "(" + argument + ")"); 489 } 490 491 public void traceDeprecatedEntry(Object instance, String methodName, int argument) { 492 if (traceSuspended()) { 493 return; 494 } 495 traceDeprecatedEntryAllArgs(instance, methodName, 496 "(" + argument + ")"); 497 } 498 499 public void traceDeprecatedEntry(Object instance, String methodName, Object argument) { 500 if (traceSuspended()) { 501 return; 502 } 503 traceDeprecatedEntryAllArgs(instance, methodName, 504 "(" + argument + ")"); 505 } 506 507 509 public void traceEntry(Object instance, String methodName, Object arg1, Object arg2) { 510 if (traceSuspended()) { 511 return; 512 } 513 traceEntryAllArgs(instance, methodName, 514 "(" + arg1 + ", " + arg2 + ")"); 515 } 516 517 public void traceEntry(Object instance, String methodName, int arg1, Object arg2) { 518 if (traceSuspended()) { 519 return; 520 } 521 traceEntryAllArgs(instance, methodName, 522 "(" + arg1 + ", " + arg2 + ")"); 523 } 524 525 public void traceEntry(Object instance, String methodName, int arg1, byte[] arg2) { 526 if (traceSuspended()) { 527 return; 528 } 529 traceEntryAllArgs(instance, methodName, 530 "(" + arg1 + ", " + Utils.getStringFromBytes(arg2) + ")"); 531 } 532 533 public void traceDeprecatedEntry(Object instance, String methodName, int arg1, int arg2) { 534 if (traceSuspended()) { 535 return; 536 } 537 traceDeprecatedEntryAllArgs(instance, methodName, 538 "(" + arg1 + ", " + arg2 + ")"); 539 } 540 541 public void traceDeprecatedEntry(Object instance, String methodName, Object arg1, int arg2) { 542 if (traceSuspended()) { 543 return; 544 } 545 traceDeprecatedEntryAllArgs(instance, methodName, 546 "(" + arg1 + ", " + arg2 + ")"); 547 } 548 549 public void traceEntry(Object instance, String methodName, int arg1, boolean arg2) { 550 if (traceSuspended()) { 551 return; 552 } 553 traceEntryAllArgs(instance, methodName, 554 "(" + arg1 + ", " + arg2 + ")"); 555 } 556 557 public void traceEntry(Object instance, String methodName, int arg1, byte arg2) { 558 if (traceSuspended()) { 559 return; 560 } 561 traceEntryAllArgs(instance, methodName, 562 "(" + arg1 + ", 0x" + Integer.toHexString(arg2 & 0xff) + ")"); 563 } 564 565 public void traceEntry(Object instance, String methodName, int arg1, short arg2) { 566 if (traceSuspended()) { 567 return; 568 } 569 traceEntryAllArgs(instance, methodName, 570 "(" + arg1 + ", " + arg2 + ")"); 571 } 572 573 public void traceEntry(Object instance, String methodName, int arg1, int arg2) { 574 if (traceSuspended()) { 575 return; 576 } 577 traceEntryAllArgs(instance, methodName, 578 "(" + arg1 + ", " + arg2 + ")"); 579 } 580 581 public void traceEntry(Object instance, String methodName, int arg1, long arg2) { 582 if (traceSuspended()) { 583 return; 584 } 585 traceEntryAllArgs(instance, methodName, 586 "(" + arg1 + ", " + arg2 + ")"); 587 } 588 589 public void traceEntry(Object instance, String methodName, int arg1, float arg2) { 590 if (traceSuspended()) { 591 return; 592 } 593 traceEntryAllArgs(instance, methodName, 594 "(" + arg1 + ", " + arg2 + ")"); 595 } 596 597 public void traceEntry(Object instance, String methodName, int arg1, double arg2) { 598 if (traceSuspended()) { 599 return; 600 } 601 traceEntryAllArgs(instance, methodName, 602 "(" + arg1 + ", " + arg2 + ")"); 603 } 604 605 public void traceEntry(Object instance, String methodName, Object arg1, boolean arg2) { 606 if (traceSuspended()) { 607 return; 608 } 609 traceEntryAllArgs(instance, methodName, 610 "(" + arg1 + ", " + arg2 + ")"); 611 } 612 613 public void traceEntry(Object instance, String methodName, Object arg1, byte arg2) { 614 if (traceSuspended()) { 615 return; 616 } 617 traceEntryAllArgs(instance, methodName, 618 "(" + arg1 + ", 0x" + Integer.toHexString(arg2 & 0xff) + ")"); 619 } 620 621 public void traceEntry(Object instance, String methodName, Object arg1, short arg2) { 622 if (traceSuspended()) { 623 return; 624 } 625 traceEntryAllArgs(instance, methodName, 626 "(" + arg1 + ", " + arg2 + ")"); 627 } 628 629 public void traceEntry(Object instance, String methodName, Object arg1, int arg2) { 630 if (traceSuspended()) { 631 return; 632 } 633 traceEntryAllArgs(instance, methodName, 634 "(" + arg1 + ", " + arg2 + ")"); 635 } 636 637 public void traceEntry(Object instance, String methodName, Object arg1, long arg2) { 638 if (traceSuspended()) { 639 return; 640 } 641 traceEntryAllArgs(instance, methodName, 642 "(" + arg1 + ", " + arg2 + ")"); 643 } 644 645 public void traceEntry(Object instance, String methodName, Object arg1, float arg2) { 646 if (traceSuspended()) { 647 return; 648 } 649 traceEntryAllArgs(instance, methodName, 650 "(" + arg1 + ", " + arg2 + ")"); 651 } 652 653 public void traceEntry(Object instance, String methodName, Object arg1, double arg2) { 654 if (traceSuspended()) { 655 return; 656 } 657 traceEntryAllArgs(instance, methodName, 658 "(" + arg1 + ", " + arg2 + ")"); 659 } 660 661 663 public void traceEntry(Object instance, String methodName, 664 Object arg1, Object arg2, Object arg3) { 665 if (traceSuspended()) { 666 return; 667 } 668 traceEntryAllArgs(instance, methodName, 669 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 670 } 671 672 public void traceEntry(Object instance, String methodName, 673 int arg1, Object arg2, Object arg3) { 674 if (traceSuspended()) { 675 return; 676 } 677 traceEntryAllArgs(instance, methodName, 678 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 679 } 680 681 public void traceEntry(Object instance, String methodName, 682 Object arg1, Object arg2, int arg3) { 683 if (traceSuspended()) { 684 return; 685 } 686 traceEntryAllArgs(instance, methodName, 687 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 688 } 689 690 public void traceEntry(Object instance, String methodName, 691 int arg1, Object arg2, int arg3) { 692 if (traceSuspended()) { 693 return; 694 } 695 traceEntryAllArgs(instance, methodName, 696 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 697 } 698 699 public void traceDeprecatedEntry(Object instance, String methodName, 700 int arg1, Object arg2, int arg3) { 701 if (traceSuspended()) { 702 return; 703 } 704 traceEntryAllArgs(instance, methodName, 705 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 706 } 707 708 public void traceEntry(Object instance, String methodName, 709 int arg1, int arg2, Object arg3) { 710 if (traceSuspended()) { 711 return; 712 } 713 traceEntryAllArgs(instance, methodName, 714 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 715 } 716 717 public void traceEntry(Object instance, String methodName, 718 int arg1, int arg2, int arg3) { 719 if (traceSuspended()) { 720 return; 721 } 722 traceEntryAllArgs(instance, methodName, 723 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 724 } 725 726 public void traceEntry(Object instance, String methodName, 727 Object arg1, int arg2, int arg3) { 728 if (traceSuspended()) { 729 return; 730 } 731 traceEntryAllArgs(instance, methodName, 732 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 733 } 734 735 public void traceEntry(Object instance, String methodName, 736 Object arg1, int arg2, Object arg3) { 737 if (traceSuspended()) { 738 return; 739 } 740 traceEntryAllArgs(instance, methodName, 741 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 742 } 743 744 public void traceEntry(Object instance, String methodName, 745 Object arg1, boolean arg2, boolean arg3) { 746 if (traceSuspended()) { 747 return; 748 } 749 traceEntryAllArgs(instance, methodName, 750 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 751 } 752 753 public void traceEntry(Object instance, String methodName, 754 Object arg1, boolean arg2, int arg3) { 755 if (traceSuspended()) { 756 return; 757 } 758 traceEntryAllArgs(instance, methodName, 759 "(" + arg1 + ", " + arg2 + ", " + arg3 + ")"); 760 } 761 762 764 public void traceEntry(Object instance, String methodName, 765 Object arg1, Object arg2, Object arg3, Object arg4) { 766 if (traceSuspended()) { 767 return; 768 } 769 traceEntryAllArgs(instance, methodName, 770 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ")"); 771 } 772 773 public void traceEntry(Object instance, String methodName, 774 int arg1, Object arg2, Object arg3, Object arg4) { 775 if (traceSuspended()) { 776 return; 777 } 778 traceEntryAllArgs(instance, methodName, 779 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ")"); 780 } 781 782 public void traceEntry(Object instance, String methodName, 783 int arg1, Object arg2, int arg3, int arg4) { 784 if (traceSuspended()) { 785 return; 786 } 787 traceEntryAllArgs(instance, methodName, 788 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ")"); 789 } 790 791 public void traceEntry(Object instance, String methodName, 792 Object arg1, int arg2, int arg3, int arg4) { 793 if (traceSuspended()) { 794 return; 795 } 796 traceEntryAllArgs(instance, methodName, 797 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ")"); 798 } 799 800 public void traceEntry(Object instance, String methodName, 801 Object arg1, Object arg2, int arg3, int arg4) { 802 if (traceSuspended()) { 803 return; 804 } 805 traceEntryAllArgs(instance, methodName, 806 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ")"); 807 } 808 809 811 public void traceEntry(Object instance, String methodName, 812 Object arg1, Object arg2, Object arg3, int arg4, boolean arg5) { 813 if (traceSuspended()) { 814 return; 815 } 816 traceEntryAllArgs(instance, methodName, 817 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5 + ")"); 818 } 819 820 public void traceEntry(Object instance, String methodName, 821 Object arg1, Object arg2, Object arg3, boolean arg4, boolean arg5) { 822 if (traceSuspended()) { 823 return; 824 } 825 traceEntryAllArgs(instance, methodName, 826 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5 + ")"); 827 } 828 829 831 public void traceEntry(Object instance, String methodName, 832 Object arg1, Object arg2, Object arg3, Object arg4, Object arg5, Object arg6) { 833 if (traceSuspended()) { 834 return; 835 } 836 traceEntryAllArgs(instance, methodName, 837 "(" + arg1 + ", " + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5 + ", " + arg6 + ")"); 838 } 839 840 842 public void traceDiagnosable(SqlException e) { 843 if (traceSuspended()) { 844 return; 845 } 846 if (!loggingEnabled(ClientDataSource.TRACE_DIAGNOSTICS)) { 847 return; 848 } 849 synchronized (printWriter_) { 850 dncprintln("BEGIN TRACE_DIAGNOSTICS"); 851 ExceptionFormatter.printTrace(e, printWriter_, "[derby]", true); dncprintln("END TRACE_DIAGNOSTICS"); 853 } 854 } 855 public void traceDiagnosable(java.sql.SQLException e) { 856 if (traceSuspended()) { 857 return; 858 } 859 if (!loggingEnabled(ClientDataSource.TRACE_DIAGNOSTICS)) { 860 return; 861 } 862 synchronized (printWriter_) { 863 dncprintln("BEGIN TRACE_DIAGNOSTICS"); 864 ExceptionFormatter.printTrace(e, printWriter_, "[derby]", true); dncprintln("END TRACE_DIAGNOSTICS"); 866 } 867 } 868 869 public void traceDiagnosable(javax.transaction.xa.XAException e) { 870 if (traceSuspended()) { 871 return; 872 } 873 if (!loggingEnabled(ClientDataSource.TRACE_DIAGNOSTICS)) { 874 return; 875 } 876 synchronized (printWriter_) { 877 dncprintln("BEGIN TRACE_DIAGNOSTICS"); 878 ExceptionFormatter.printTrace(e, printWriter_, "[derby]"); 879 dncprintln("END TRACE_DIAGNOSTICS"); 880 } 881 } 882 884 public void traceParameterMetaData(Statement statement, ColumnMetaData columnMetaData) { 885 if (traceSuspended()) { 886 return; 887 } 888 if (!loggingEnabled(ClientDataSource.TRACE_PARAMETER_META_DATA) || columnMetaData == null) { 889 return; 890 } 891 synchronized (printWriter_) { 892 String header = "[ParameterMetaData@" + Integer.toHexString(columnMetaData.hashCode()) + "]"; 893 try { 894 dncprintln(header, "BEGIN TRACE_PARAMETER_META_DATA"); 895 dncprintln(header, "Parameter meta data for statement Statement@" + Integer.toHexString(statement.hashCode())); 896 dncprintln(header, "Number of parameter columns: " + columnMetaData.getColumnCount()); 897 traceColumnMetaData(header, columnMetaData); 898 dncprintln(header, "END TRACE_PARAMETER_META_DATA"); 899 } catch (SQLException e) { 900 dncprintln(header, "Encountered an SQL exception while trying to trace parameter meta data"); 901 dncprintln(header, "END TRACE_PARAMETER_META_DATA"); 902 } 903 } 904 } 905 906 public void traceResultSetMetaData(Statement statement, ColumnMetaData columnMetaData) { 907 if (traceSuspended()) { 908 return; 909 } 910 if (!loggingEnabled(ClientDataSource.TRACE_RESULT_SET_META_DATA) || columnMetaData == null) { 911 return; 912 } 913 synchronized (printWriter_) { 914 String header = "[ResultSetMetaData@" + Integer.toHexString(columnMetaData.hashCode()) + "]"; 915 try { 916 dncprintln(header, "BEGIN TRACE_RESULT_SET_META_DATA"); 917 dncprintln(header, "Result set meta data for statement Statement@" + Integer.toHexString(statement.hashCode())); 918 dncprintln(header, "Number of result set columns: " + columnMetaData.getColumnCount()); 919 traceColumnMetaData(header, columnMetaData); 920 dncprintln(header, "END TRACE_RESULT_SET_META_DATA"); 921 } catch (SQLException e) { 922 dncprintln(header, "Encountered an SQL exception while trying to trace result set meta data"); 923 dncprintln(header, "END TRACE_RESULT_SET_META_DATA"); 924 } 925 } 926 } 927 928 930 private void traceColumnMetaData(String header, ColumnMetaData columnMetaData) { 931 if (traceSuspended()) { 932 return; 933 } 934 try { 935 synchronized (printWriter_) { 936 937 for (int column = 1; column <= columnMetaData.getColumnCount(); column++) { 938 dncprint(header, "Column " + column + ": { "); 939 printWriter_.print("label=" + columnMetaData.getColumnLabel(column) + ", "); 940 printWriter_.print("name=" + columnMetaData.getColumnName(column) + ", "); 941 printWriter_.print("type name=" + columnMetaData.getColumnTypeName(column) + ", "); 942 printWriter_.print("type=" + columnMetaData.getColumnType(column) + ", "); 943 printWriter_.print("nullable=" + columnMetaData.isNullable(column) + ", "); 944 printWriter_.print("precision=" + columnMetaData.getPrecision(column) + ", "); 945 printWriter_.print("scale=" + columnMetaData.getScale(column) + ", "); 946 printWriter_.print("schema name=" + columnMetaData.getSchemaName(column) + ", "); 947 printWriter_.print("table name=" + columnMetaData.getTableName(column) + ", "); 948 printWriter_.print("writable=" + columnMetaData.isWritable(column) + ", "); 949 printWriter_.print("sqlPrecision=" + (columnMetaData.sqlPrecision_ == null ? "<null>" : "" + columnMetaData.sqlPrecision_[column - 1]) + ", "); 950 printWriter_.print("sqlScale=" + (columnMetaData.sqlScale_ == null ? "<null>" : "" + columnMetaData.sqlScale_[column - 1]) + ", "); 951 printWriter_.print("sqlLength=" + (columnMetaData.sqlLength_ == null ? "<null>" : "" + columnMetaData.sqlLength_[column - 1]) + ", "); 952 printWriter_.print("sqlType=" + (columnMetaData.sqlType_ == null ? "<null>" : "" + columnMetaData.sqlType_[column - 1]) + ", "); 953 printWriter_.print("sqlCcsid=" + (columnMetaData.sqlCcsid_ == null ? "<null>" : "" + columnMetaData.sqlCcsid_[column - 1]) + ", "); 954 printWriter_.print("sqlName=" + (columnMetaData.sqlName_ == null ? "<null>" : columnMetaData.sqlName_[column - 1]) + ", "); 955 printWriter_.print("sqlLabel=" + (columnMetaData.sqlLabel_ == null ? "<null>" : columnMetaData.sqlLabel_[column - 1]) + ", "); 956 printWriter_.print("sqlUnnamed=" + (columnMetaData.sqlUnnamed_ == null ? "<null>" : "" + columnMetaData.sqlUnnamed_[column - 1]) + ", "); 957 printWriter_.print("sqlComment=" + (columnMetaData.sqlComment_ == null ? "<null>" : columnMetaData.sqlComment_[column - 1]) + ", "); 958 printWriter_.print("sqlxKeymem=" + (columnMetaData.sqlxKeymem_ == null ? "<null>" : "" + columnMetaData.sqlxKeymem_[column - 1]) + ", "); 959 printWriter_.print("sqlxGenerated=" + (columnMetaData.sqlxGenerated_ == null ? "<null>" : "" + columnMetaData.sqlxGenerated_[column - 1]) + ", "); 960 printWriter_.print("sqlxParmmode=" + (columnMetaData.sqlxParmmode_ == null ? "<null>" : "" + columnMetaData.sqlxParmmode_[column - 1]) + ", "); 961 printWriter_.print("sqlxCorname=" + (columnMetaData.sqlxCorname_ == null ? "<null>" : columnMetaData.sqlxCorname_[column - 1]) + ", "); 962 printWriter_.print("sqlxName=" + (columnMetaData.sqlxName_ == null ? "<null>" : columnMetaData.sqlxName_[column - 1]) + ", "); 963 printWriter_.print("sqlxBasename=" + (columnMetaData.sqlxBasename_ == null ? "<null>" : columnMetaData.sqlxBasename_[column - 1]) + ", "); 964 printWriter_.print("sqlxUpdatable=" + (columnMetaData.sqlxUpdatable_ == null ? "<null>" : "" + columnMetaData.sqlxUpdatable_[column - 1]) + ", "); 965 printWriter_.print("sqlxSchema=" + (columnMetaData.sqlxSchema_ == null ? "<null>" : columnMetaData.sqlxSchema_[column - 1]) + ", "); 966 printWriter_.print("sqlxRdbnam=" + (columnMetaData.sqlxRdbnam_ == null ? "<null>" : columnMetaData.sqlxRdbnam_[column - 1]) + ", "); 967 printWriter_.print("internal type=" + columnMetaData.types_[column - 1] + ", "); 968 printWriter_.println(" }"); 969 } 970 dncprint(header, "{ "); 971 printWriter_.print("sqldHold=" + columnMetaData.sqldHold_ + ", "); 972 printWriter_.print("sqldReturn=" + columnMetaData.sqldReturn_ + ", "); 973 printWriter_.print("sqldScroll=" + columnMetaData.sqldScroll_ + ", "); 974 printWriter_.print("sqldSensitive=" + columnMetaData.sqldSensitive_ + ", "); 975 printWriter_.print("sqldFcode=" + columnMetaData.sqldFcode_ + ", "); 976 printWriter_.print("sqldKeytype=" + columnMetaData.sqldKeytype_ + ", "); 977 printWriter_.print("sqldRdbnam=" + columnMetaData.sqldRdbnam_ + ", "); 978 printWriter_.print("sqldSchema=" + columnMetaData.sqldSchema_); 979 printWriter_.println(" }"); 980 printWriter_.flush(); 981 } 982 } catch (SQLException e) { 983 dncprintln(header, "Encountered an SQL exception while trying to trace column meta data"); 984 } 985 } 986 987 990 public void traceConnectEntry(ClientBaseDataSource dataSource) { 992 if (traceSuspended()) { 993 return; 994 } 995 if (loggingEnabled(ClientDataSource.TRACE_DRIVER_CONFIGURATION)) { 996 traceDriverConfigurationJdbc2(); 997 } 998 if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) { 999 traceConnectsEntry(dataSource); 1000 } 1001 } 1002 1003 public void traceConnectEntry(String server, 1005 int port, 1006 String database, 1007 java.util.Properties properties) { 1008 if (traceSuspended()) { 1009 return; 1010 } 1011 if (loggingEnabled(ClientDataSource.TRACE_DRIVER_CONFIGURATION)) { 1012 traceDriverConfigurationJdbc1(); 1013 } 1014 if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) { 1015 traceConnectsEntry(server, port, database, properties); 1016 } 1017 } 1018 1019 public void traceConnectResetEntry(Object instance, LogWriter logWriter, 1020 String user, ClientBaseDataSource ds) { 1021 if (traceSuspended()) { 1022 return; 1023 } 1024 traceEntry(instance, "reset", logWriter, user, "<escaped>", ds); 1025 if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) { 1026 traceConnectsResetEntry(ds); 1027 } 1028 } 1029 1030 public void traceConnectExit(Connection connection) { 1031 if (traceSuspended()) { 1032 return; 1033 } 1034 if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) { 1035 traceConnectsExit(connection); 1036 } 1037 } 1038 1039 public void traceConnectResetExit(Connection connection) { 1040 if (traceSuspended()) { 1041 return; 1042 } 1043 if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) { 1044 traceConnectsResetExit(connection); 1045 } 1046 } 1047 1048 1049 1051 private void traceConnectsResetEntry(ClientBaseDataSource dataSource) { 1052 try { 1053 if (traceSuspended()) { 1054 return; 1055 } 1056 traceConnectsResetEntry(dataSource.getServerName(), 1057 dataSource.getPortNumber(), 1058 dataSource.getDatabaseName(), 1059 getProperties(dataSource)); 1060 } catch ( SqlException se ) { 1061 dncprintln("Encountered an SQL exception while trying to trace connection reset entry"); 1062 } 1063 } 1064 1065 private void traceConnectsEntry(ClientBaseDataSource dataSource) { 1066 try { 1067 if (traceSuspended()) { 1068 return; 1069 } 1070 traceConnectsEntry(dataSource.getServerName(), 1071 dataSource.getPortNumber(), 1072 dataSource.getDatabaseName(), 1073 getProperties(dataSource)); 1074 } catch ( SqlException se ) { 1075 dncprintln("Encountered an SQL exception while trying to trace connection entry"); 1076 } 1077 1078 } 1079 1080 private void traceConnectsResetEntry(String server, 1081 int port, 1082 String database, 1083 java.util.Properties properties) { 1084 if (traceSuspended()) { 1085 return; 1086 } 1087 dncprintln("BEGIN TRACE_CONNECT_RESET"); 1088 dncprintln("Connection reset requested for " + server + ":" + port + "/" + database); 1089 dncprint("Using properties: "); 1090 writeProperties(properties); 1091 dncprintln("END TRACE_CONNECT_RESET"); 1092 } 1093 1094 private void traceConnectsEntry(String server, 1095 int port, 1096 String database, 1097 java.util.Properties properties) { 1098 if (traceSuspended()) { 1099 return; 1100 } 1101 synchronized (printWriter_) { 1102 dncprintln("BEGIN TRACE_CONNECTS"); 1103 dncprintln("Attempting connection to " + server + ":" + port + "/" + database); 1104 dncprint("Using properties: "); 1105 writeProperties(properties); 1106 dncprintln("END TRACE_CONNECTS"); 1107 } 1108 } 1109 1110 public void traceConnectsExit(Connection c) { 1112 if (traceSuspended()) { 1113 return; 1114 } 1115 synchronized (printWriter_) { 1116 String header = "[Connection@" + Integer.toHexString(c.hashCode()) + "]"; 1117 try { 1118 dncprintln(header, "BEGIN TRACE_CONNECTS"); 1119 dncprintln(header, "Successfully connected to server " + c.databaseMetaData_.getURL()); 1120 dncprintln(header, "User: " + c.databaseMetaData_.getUserName()); 1121 dncprintln(header, "Database product name: " + c.databaseMetaData_.getDatabaseProductName()); 1122 dncprintln(header, "Database product version: " + c.databaseMetaData_.getDatabaseProductVersion()); 1123 dncprintln(header, "Driver name: " + c.databaseMetaData_.getDriverName()); 1124 dncprintln(header, "Driver version: " + c.databaseMetaData_.getDriverVersion()); 1125 dncprintln(header, "END TRACE_CONNECTS"); 1126 } catch (java.sql.SQLException e) { 1127 dncprintln(header, "Encountered an SQL exception while trying to trace connection exit"); 1128 dncprintln(header, "END TRACE_CONNECTS"); 1129 } 1130 } 1131 } 1132 1133 public void traceConnectsResetExit(org.apache.derby.client.am.Connection c) { 1134 if (traceSuspended()) { 1135 return; 1136 } 1137 synchronized (printWriter_) { 1138 String header = "[Connection@" + Integer.toHexString(c.hashCode()) + "]"; 1139 try { 1140 dncprintln(header, "BEGIN TRACE_CONNECT_RESET"); 1141 dncprintln(header, "Successfully reset connection to server " + c.databaseMetaData_.getURL()); 1142 dncprintln(header, "User: " + c.databaseMetaData_.getUserName()); 1143 dncprintln(header, "Database product name: " + c.databaseMetaData_.getDatabaseProductName()); 1144 dncprintln(header, "Database product version: " + c.databaseMetaData_.getDatabaseProductVersion()); 1145 dncprintln(header, "Driver name: " + c.databaseMetaData_.getDriverName()); 1146 dncprintln(header, "Driver version: " + c.databaseMetaData_.getDriverVersion()); 1147 dncprintln(header, "END TRACE_CONNECT_RESET"); 1148 } catch (java.sql.SQLException e) { 1149 dncprintln(header, "Encountered an SQL exception while trying to trace connection reset exit"); 1150 dncprintln(header, "END TRACE_CONNECT_RESET"); 1151 } 1152 } 1153 } 1154 1155 1156 private void writeProperties(java.util.Properties properties) { 1160 printWriter_.print("{ "); 1161 for (java.util.Iterator i = properties.entrySet().iterator(); i.hasNext();) { 1162 java.util.Map.Entry e = (java.util.Map.Entry) (i.next()); 1163 if ("password".equals(e.getKey())) { 1164 printWriter_.print("password=" + escapePassword((String ) e.getValue())); 1165 } else { 1166 printWriter_.print(e.getKey() + "=" + e.getValue()); 1167 } 1168 if (i.hasNext()) { 1169 printWriter_.print(", "); 1170 } 1171 } 1172 printWriter_.println(" }"); 1173 printWriter_.flush(); 1174 } 1175 1176 private String escapePassword(String pw) { 1177 StringBuffer sb = new StringBuffer (pw); 1178 for (int j = 0; j < pw.length(); j++) { 1179 sb.setCharAt(j, '*'); 1180 } 1181 return sb.toString(); 1182 } 1183 1185 private void traceDriverConfigurationJdbc2() { 1186 if (traceSuspended()) { 1187 return; 1188 } 1189 synchronized (printWriter_) { 1190 if (!driverConfigurationHasBeenWrittenToJdbc2Stream_) { 1191 writeDriverConfiguration(); 1192 driverConfigurationHasBeenWrittenToJdbc2Stream_ = true; 1193 } 1194 } 1195 } 1196 1197 private void traceDriverConfigurationJdbc1() { 1198 if (traceSuspended()) { 1199 return; 1200 } 1201 synchronized (printWriter_) { 1202 if (!driverConfigurationHasBeenWrittenToJdbc1Stream_) { 1203 writeDriverConfiguration(); 1204 driverConfigurationHasBeenWrittenToJdbc1Stream_ = true; 1205 } 1206 } 1207 } 1208 1209 public void writeDriverConfiguration() { 1210 org.apache.derby.client.am.Version.writeDriverConfiguration(printWriter_); 1211 } 1212 1213 public static java.io.PrintWriter getPrintWriter(String fileName, boolean fileAppend) throws SqlException { 1214 try { 1215 java.io.PrintWriter printWriter = null; 1216 String fileCanonicalPath = new java.io.File (fileName).getCanonicalPath(); 1217 printWriter = 1218 new java.io.PrintWriter (new java.io.BufferedOutputStream (new java.io.FileOutputStream (fileCanonicalPath, fileAppend), 4096), true); 1219 return printWriter; 1220 } catch (java.io.IOException e) { 1221 throw new SqlException(null, 1222 new ClientMessageId(SQLState.UNABLE_TO_OPEN_FILE), 1223 new Object [] { fileName, e.getMessage() }, 1224 e); 1225 } 1226 } 1227 1228 1231 private Properties getProperties(ClientBaseDataSource cds) 1232 throws SqlException { 1233 1234 Properties properties = new Properties (); 1235 1236 try { 1237 Reference ref = cds.getReference(); 1238 1239 for (Enumeration e = ref.getAll(); e.hasMoreElements();) { 1240 1241 RefAddr attribute = (RefAddr ) e.nextElement(); 1242 1243 String propertyKey = attribute.getType(); 1244 String value = (String ) attribute.getContent(); 1245 1246 if (Attribute.PASSWORD_ATTR.equals(propertyKey)) { 1248 value = "********"; 1249 } 1250 1251 if(value != null) 1252 properties.setProperty(propertyKey, value); 1253 } 1254 } catch (NamingException e) { 1255 throw new SqlException(this, 1256 new ClientMessageId(SQLState.JAVA_EXCEPTION), 1257 e.getClass().getName(), e.getMessage(), e); 1258 } 1259 1260 return properties; 1261 } 1262 1263} 1264 | Popular Tags |