Source Code Cross Referenced for LogWriter.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » client » am » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.client.am 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:
0003:           Derby - Class org.apache.derby.client.am.LogWriter
0004:
0005:           Licensed to the Apache Software Foundation (ASF) under one or more
0006:           contributor license agreements.  See the NOTICE file distributed with
0007:           this work for additional information regarding copyright ownership.
0008:           The ASF licenses this file to You under the Apache License, Version 2.0
0009:           (the "License"); you may not use this file except in compliance with
0010:           the License.  You may obtain a copy of the License at
0011:
0012:              http://www.apache.org/licenses/LICENSE-2.0
0013:
0014:           Unless required by applicable law or agreed to in writing, software
0015:           distributed under the License is distributed on an "AS IS" BASIS,
0016:           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017:           See the License for the specific language governing permissions and
0018:           limitations under the License.
0019:
0020:         */
0021:
0022:        package org.apache.derby.client.am;
0023:
0024:        import java.sql.SQLException;
0025:        import java.util.Enumeration;
0026:        import java.util.Properties;
0027:
0028:        import javax.naming.NamingException;
0029:        import javax.naming.RefAddr;
0030:        import javax.naming.Reference;
0031:        import org.apache.derby.jdbc.ClientBaseDataSource;
0032:
0033:        import org.apache.derby.jdbc.ClientDataSource;
0034:        import org.apache.derby.shared.common.reference.Attribute;
0035:        import org.apache.derby.shared.common.reference.SQLState;
0036:
0037:        public class LogWriter {
0038:            protected java.io.PrintWriter printWriter_;
0039:            protected int traceLevel_;
0040:            private boolean driverConfigurationHasBeenWrittenToJdbc1Stream_ = false;
0041:            private boolean driverConfigurationHasBeenWrittenToJdbc2Stream_ = false;
0042:
0043:            // It is assumed that this constructor is never called when logWriter is null.
0044:            public LogWriter(java.io.PrintWriter printWriter, int traceLevel) {
0045:                printWriter_ = printWriter;
0046:                traceLevel_ = traceLevel;
0047:            }
0048:
0049:            final protected boolean loggingEnabled(int traceLevel) {
0050:                // It is an invariant that the printWriter is never null, so remove the
0051:                return printWriter_ != null && (traceLevel & traceLevel_) != 0;
0052:            }
0053:
0054:            final protected boolean traceSuspended() {
0055:                return org.apache.derby.client.am.Configuration.traceSuspended__;
0056:            }
0057:
0058:            // When garbage collector doesn't kick in in time
0059:            // to close file descriptors, "Too many open files"
0060:            // exception may occur (currently found on Linux).
0061:            // To minimize the chance of this problem happening,
0062:            // the print writer needs to be closed (after this
0063:            // DNC log writer is closed) when each connection has
0064:            // its own trace file (i.e. traceDirectory is specified).
0065:            public boolean printWriterNeedsToBeClosed_;
0066:
0067:            void close() {
0068:                if (printWriterNeedsToBeClosed_) {
0069:                    printWriter_.close();
0070:                    printWriterNeedsToBeClosed_ = false;
0071:                }
0072:                // printWriter_ = null; // help GC.
0073:            }
0074:
0075:            // ---------------------------------------------------------------------------
0076:
0077:            public void dncprintln(String s) {
0078:                synchronized (printWriter_) {
0079:                    printWriter_.println("[derby] " + s);
0080:                    printWriter_.flush();
0081:                }
0082:            }
0083:
0084:            private void dncprint(String s) {
0085:                synchronized (printWriter_) {
0086:                    printWriter_.print("[derby] " + s);
0087:                    printWriter_.flush();
0088:                }
0089:            }
0090:
0091:            private void dncprintln(String header, String s) {
0092:                synchronized (printWriter_) {
0093:                    printWriter_.println("[derby]" + header + " " + s);
0094:                    printWriter_.flush();
0095:                }
0096:            }
0097:
0098:            private void dncprint(String header, String s) {
0099:                synchronized (printWriter_) {
0100:                    printWriter_.print("[derby]" + header + " " + s);
0101:                    printWriter_.flush();
0102:                }
0103:            }
0104:
0105:            // ------------------------ tracepoint api -----------------------------------
0106:
0107:            public void tracepoint(String component, int tracepoint,
0108:                    String message) {
0109:                if (traceSuspended()) {
0110:                    return;
0111:                }
0112:                dncprintln(component, "[time:" + System.currentTimeMillis()
0113:                        + "]" + "[thread:" + Thread.currentThread().getName()
0114:                        + "]" + "[tracepoint:" + tracepoint + "]" + message);
0115:            }
0116:
0117:            public void tracepoint(String component, int tracepoint,
0118:                    String classContext, String methodContext) {
0119:                if (traceSuspended()) {
0120:                    return;
0121:                }
0122:                String staticContextTracepointRecord = component + "[time:"
0123:                        + System.currentTimeMillis() + "]" + "[thread:"
0124:                        + Thread.currentThread().getName() + "]"
0125:                        + "[tracepoint:" + tracepoint + "]" + "["
0126:                        + classContext + "." + methodContext + "]";
0127:                dncprintln(staticContextTracepointRecord);
0128:            }
0129:
0130:            public void tracepoint(String component, int tracepoint,
0131:                    Object instance, String classContext, String methodContext) {
0132:                if (traceSuspended()) {
0133:                    return;
0134:                }
0135:                String instanceContextTracepointRecord = component + "[time:"
0136:                        + System.currentTimeMillis() + "]" + "[thread:"
0137:                        + Thread.currentThread().getName() + "]"
0138:                        + "[tracepoint:" + tracepoint + "]" + "["
0139:                        + classContext + "@"
0140:                        + Integer.toHexString(instance.hashCode()) + "."
0141:                        + methodContext + "]";
0142:                dncprintln(instanceContextTracepointRecord);
0143:            }
0144:
0145:            public void tracepoint(String component, int tracepoint,
0146:                    String classContext, String methodContext,
0147:                    java.util.Map memory) {
0148:                if (traceSuspended()) {
0149:                    return;
0150:                }
0151:                String staticContextTracepointRecord = component + "[time:"
0152:                        + System.currentTimeMillis() + "]" + "[thread:"
0153:                        + Thread.currentThread().getName() + "]"
0154:                        + "[tracepoint:" + tracepoint + "]" + "["
0155:                        + classContext + "." + methodContext + "]";
0156:                dncprintln(staticContextTracepointRecord
0157:                        + getMemoryMapDisplay(memory));
0158:            }
0159:
0160:            public void tracepoint(String component, int tracepoint,
0161:                    Object instance, String classContext, String methodContext,
0162:                    java.util.Map memory) {
0163:                if (traceSuspended()) {
0164:                    return;
0165:                }
0166:                String instanceContextTracepointRecord = component + "[time:"
0167:                        + System.currentTimeMillis() + "]" + "[thread:"
0168:                        + Thread.currentThread().getName() + "]"
0169:                        + "[tracepoint:" + tracepoint + "]" + "["
0170:                        + classContext + "@"
0171:                        + Integer.toHexString(instance.hashCode()) + "."
0172:                        + methodContext + "]";
0173:                dncprintln(instanceContextTracepointRecord
0174:                        + getMemoryMapDisplay(memory));
0175:            }
0176:
0177:            private String getMemoryMapDisplay(java.util.Map memory) {
0178:                return memory.toString(); // need to loop thru all keys in the map and print values
0179:            }
0180:
0181:            // ------------- API entry and exit trace methods ----------------------------
0182:            // Entry and exit are be traced separately because input arguments need
0183:            // to be traced before any potential exception can occur.
0184:            // Exit tracing is only performed on methods that return values.
0185:            // Entry tracing is only performed on methods that update state,
0186:            // so entry tracing is not performed on simple getter methods.
0187:            // We could decide in the future to restrict entry tracing only to methods with input arguments.
0188:
0189:            private void traceExternalMethod(Object instance, String className,
0190:                    String methodName) {
0191:                if (traceSuspended()) {
0192:                    return;
0193:                }
0194:                dncprint(buildExternalMethodHeader(instance, className),
0195:                        methodName);
0196:            }
0197:
0198:            private void traceExternalDeprecatedMethod(Object instance,
0199:                    String className, String methodName) {
0200:                if (traceSuspended()) {
0201:                    return;
0202:                }
0203:                dncprint(buildExternalMethodHeader(instance, className),
0204:                        "Deprecated " + methodName);
0205:            }
0206:
0207:            private String buildExternalMethodHeader(Object instance,
0208:                    String className) {
0209:                return "[Time:" + System.currentTimeMillis() + "]" + "[Thread:"
0210:                        + Thread.currentThread().getName() + "]" + "["
0211:                        + className + "@"
0212:                        + Integer.toHexString(instance.hashCode()) + "]";
0213:            }
0214:
0215:            private String getClassNameOfInstanceIfTraced(Object instance) {
0216:                if (instance == null) // this prevents NPE from instance.getClass() used below
0217:                {
0218:                    return null;
0219:                } else if (instance instanceof  Connection
0220:                        && loggingEnabled(ClientDataSource.TRACE_CONNECTION_CALLS)) {
0221:                    return "Connection";
0222:                } else if (instance instanceof  ResultSet
0223:                        && loggingEnabled(ClientDataSource.TRACE_RESULT_SET_CALLS)) {
0224:                    return "ResultSet";
0225:                } else if (instance instanceof  CallableStatement
0226:                        && loggingEnabled(ClientDataSource.TRACE_STATEMENT_CALLS)) {
0227:                    return "CallableStatement";
0228:                } else if (instance instanceof  PreparedStatement
0229:                        && loggingEnabled(ClientDataSource.TRACE_STATEMENT_CALLS)) {
0230:                    return "PreparedStatement";
0231:                } else if (instance instanceof  Statement
0232:                        && loggingEnabled(ClientDataSource.TRACE_STATEMENT_CALLS)) {
0233:                    return "Statement";
0234:                }
0235:                // Not yet externalizing Blob tracing, except for trace_all
0236:                else if (instance instanceof  Blob
0237:                        && loggingEnabled(ClientDataSource.TRACE_ALL)) // add a trace level for lobs !!
0238:                {
0239:                    return "Blob";
0240:                }
0241:                // Not yet externalizing Clob tracing, except for trace_all
0242:                else if (instance instanceof  Clob
0243:                        && loggingEnabled(ClientDataSource.TRACE_ALL)) // add a trace level for bobs !!
0244:                {
0245:                    return "Clob";
0246:                }
0247:                // Not yet externalizing dbmd catalog call tracing, except for trace_all
0248:                else if (instance instanceof  DatabaseMetaData
0249:                        && loggingEnabled(ClientDataSource.TRACE_ALL)) // add a trace level for dbmd ??
0250:                {
0251:                    return "DatabaseMetaData";
0252:                }
0253:                // we don't use instanceof javax.transaction.XAResource to avoid dependency on j2ee.jar
0254:                else if (loggingEnabled(ClientDataSource.TRACE_XA_CALLS)
0255:                        && instance.getClass().getName().startsWith(
0256:                                "org.apache.derby.client.net.NetXAResource")) {
0257:                    return "NetXAResource";
0258:                } else if (loggingEnabled(ClientDataSource.TRACE_ALL)
0259:                        && instance
0260:                                .getClass()
0261:                                .getName()
0262:                                .equals(
0263:                                        "org.apache.derby.client.ClientPooledConnection")) {
0264:                    return "ClientPooledConnection";
0265:                } else if (loggingEnabled(ClientDataSource.TRACE_ALL)
0266:                        && instance
0267:                                .getClass()
0268:                                .getName()
0269:                                .equals(
0270:                                        "org.apache.derby.jdbc.ClientConnectionPoolDataSource")) {
0271:                    return "ClientConnectionPoolDataSource";
0272:                } else if (loggingEnabled(ClientDataSource.TRACE_ALL)
0273:                        && instance.getClass().getName().equals(
0274:                                "org.apache.derby.client.ClientXAConnection")) {
0275:                    return "ClientXAConnection";
0276:                } else if (loggingEnabled(ClientDataSource.TRACE_ALL)
0277:                        && instance.getClass().getName().equals(
0278:                                "org.apache.derby.jdbc.ClientDataSource")) {
0279:                    return "ClientDataSource";
0280:                } else if (loggingEnabled(ClientDataSource.TRACE_ALL)
0281:                        && instance.getClass().getName().equals(
0282:                                "org.apache.derby.jdbc.ClientXADataSource")) {
0283:                    return "ClientXADataSource";
0284:                } else {
0285:                    return instance.getClass().getName();
0286:                }
0287:            }
0288:
0289:            // --------------------------- method exit tracing --------------------------
0290:
0291:            public void traceExit(Object instance, String methodName,
0292:                    Object returnValue) {
0293:                if (traceSuspended()) {
0294:                    return;
0295:                }
0296:                String className = getClassNameOfInstanceIfTraced(instance);
0297:                if (className == null) {
0298:                    return;
0299:                }
0300:                synchronized (printWriter_) {
0301:                    traceExternalMethod(instance, className, methodName);
0302:                    printWriter_.println(" () returned " + returnValue);
0303:                    printWriter_.flush();
0304:                }
0305:            }
0306:
0307:            public void traceDeprecatedExit(Object instance, String methodName,
0308:                    Object returnValue) {
0309:                if (traceSuspended()) {
0310:                    return;
0311:                }
0312:                String className = getClassNameOfInstanceIfTraced(instance);
0313:                if (className == null) {
0314:                    return;
0315:                }
0316:                synchronized (printWriter_) {
0317:                    traceExternalDeprecatedMethod(instance, className,
0318:                            methodName);
0319:                    printWriter_.println(" () returned " + returnValue);
0320:                    printWriter_.flush();
0321:                }
0322:            }
0323:
0324:            public void traceExit(Object instance, String methodName,
0325:                    ResultSet resultSet) {
0326:                if (traceSuspended()) {
0327:                    return;
0328:                }
0329:                String returnValue = (resultSet == null) ? "ResultSet@null"
0330:                        : "ResultSet@"
0331:                                + Integer.toHexString(resultSet.hashCode());
0332:                traceExit(instance, methodName, returnValue);
0333:            }
0334:
0335:            public void traceExit(Object instance, String methodName,
0336:                    CallableStatement returnValue) {
0337:                if (traceSuspended()) {
0338:                    return;
0339:                }
0340:                traceExit(instance, methodName, "CallableStatement@"
0341:                        + Integer.toHexString(returnValue.hashCode()));
0342:            }
0343:
0344:            public void traceExit(Object instance, String methodName,
0345:                    PreparedStatement returnValue) {
0346:                if (traceSuspended()) {
0347:                    return;
0348:                }
0349:                traceExit(instance, methodName, "PreparedStatement@"
0350:                        + Integer.toHexString(returnValue.hashCode()));
0351:            }
0352:
0353:            public void traceExit(Object instance, String methodName,
0354:                    Statement returnValue) {
0355:                if (traceSuspended()) {
0356:                    return;
0357:                }
0358:                traceExit(instance, methodName, "Statement@"
0359:                        + Integer.toHexString(returnValue.hashCode()));
0360:            }
0361:
0362:            public void traceExit(Object instance, String methodName, Blob blob) {
0363:                if (traceSuspended()) {
0364:                    return;
0365:                }
0366:                String returnValue = (blob == null) ? "Blob@null" : "Blob@"
0367:                        + Integer.toHexString(blob.hashCode());
0368:                traceExit(instance, methodName, returnValue);
0369:            }
0370:
0371:            public void traceExit(Object instance, String methodName, Clob clob) {
0372:                if (traceSuspended()) {
0373:                    return;
0374:                }
0375:                String returnValue = (clob == null) ? "Clob@null" : "Clob@"
0376:                        + Integer.toHexString(clob.hashCode());
0377:                traceExit(instance, methodName, returnValue);
0378:            }
0379:
0380:            public void traceExit(Object instance, String methodName,
0381:                    DatabaseMetaData returnValue) {
0382:                if (traceSuspended()) {
0383:                    return;
0384:                }
0385:                traceExit(instance, methodName, "DatabaseMetaData@"
0386:                        + Integer.toHexString(returnValue.hashCode()));
0387:            }
0388:
0389:            public void traceExit(Object instance, String methodName,
0390:                    Connection returnValue) {
0391:                if (traceSuspended()) {
0392:                    return;
0393:                }
0394:                traceExit(instance, methodName, "Connection@"
0395:                        + Integer.toHexString(returnValue.hashCode()));
0396:            }
0397:
0398:            public void traceExit(Object instance, String methodName,
0399:                    ColumnMetaData returnValue) {
0400:                if (traceSuspended()) {
0401:                    return;
0402:                }
0403:                traceExit(instance, methodName, "MetaData@"
0404:                        + (returnValue != null ? Integer
0405:                                .toHexString(returnValue.hashCode()) : null));
0406:            }
0407:
0408:            public void traceExit(Object instance, String methodName,
0409:                    byte[] returnValue) {
0410:                if (traceSuspended()) {
0411:                    return;
0412:                }
0413:                traceExit(instance, methodName, Utils
0414:                        .getStringFromBytes(returnValue));
0415:            }
0416:
0417:            public void traceExit(Object instance, String methodName,
0418:                    int[] returnValue) {
0419:                if (traceSuspended()) {
0420:                    return;
0421:                }
0422:                traceExit(instance, methodName, Utils
0423:                        .getStringFromInts(returnValue));
0424:            }
0425:
0426:            public void traceDeprecatedExit(Object instance, String methodName,
0427:                    byte[] returnValue) {
0428:                if (traceSuspended()) {
0429:                    return;
0430:                }
0431:                traceDeprecatedExit(instance, methodName, Utils
0432:                        .getStringFromBytes(returnValue));
0433:            }
0434:
0435:            public void traceExit(Object instance, String methodName,
0436:                    byte returnValue) {
0437:                if (traceSuspended()) {
0438:                    return;
0439:                }
0440:                traceExit(instance, methodName, "0x"
0441:                        + Integer.toHexString(returnValue & 0xff));
0442:            }
0443:
0444:            public void traceExit(Object instance, String methodName,
0445:                    int returnValue) {
0446:                if (traceSuspended()) {
0447:                    return;
0448:                }
0449:                traceExit(instance, methodName, String.valueOf(returnValue));
0450:            }
0451:
0452:            public void traceExit(Object instance, String methodName,
0453:                    boolean returnValue) {
0454:                if (traceSuspended()) {
0455:                    return;
0456:                }
0457:                traceExit(instance, methodName, String.valueOf(returnValue));
0458:            }
0459:
0460:            public void traceExit(Object instance, String methodName,
0461:                    long returnValue) {
0462:                if (traceSuspended()) {
0463:                    return;
0464:                }
0465:                traceExit(instance, methodName, String.valueOf(returnValue));
0466:            }
0467:
0468:            public void traceExit(Object instance, String methodName,
0469:                    float returnValue) {
0470:                if (traceSuspended()) {
0471:                    return;
0472:                }
0473:                traceExit(instance, methodName, String.valueOf(returnValue));
0474:            }
0475:
0476:            public void traceExit(Object instance, String methodName,
0477:                    double returnValue) {
0478:                if (traceSuspended()) {
0479:                    return;
0480:                }
0481:                traceExit(instance, methodName, String.valueOf(returnValue));
0482:            }
0483:
0484:            // --------------------------- method entry tracing --------------------------
0485:
0486:            private void traceEntryAllArgs(Object instance, String methodName,
0487:                    String argList) {
0488:                if (traceSuspended()) {
0489:                    return;
0490:                }
0491:                String className = getClassNameOfInstanceIfTraced(instance);
0492:                if (className == null) {
0493:                    return;
0494:                }
0495:                synchronized (printWriter_) {
0496:                    traceExternalMethod(instance, className, methodName);
0497:                    printWriter_.println(" " + argList + " called");
0498:                    printWriter_.flush();
0499:                }
0500:            }
0501:
0502:            private void traceDeprecatedEntryAllArgs(Object instance,
0503:                    String methodName, String argList) {
0504:                if (traceSuspended()) {
0505:                    return;
0506:                }
0507:                String className = getClassNameOfInstanceIfTraced(instance);
0508:                if (className == null) {
0509:                    return;
0510:                }
0511:                synchronized (printWriter_) {
0512:                    traceExternalDeprecatedMethod(instance, className,
0513:                            methodName);
0514:                    printWriter_.println(" " + argList + " called");
0515:                    printWriter_.flush();
0516:                }
0517:            }
0518:
0519:            // ---------------------- trace entry of methods w/ no args ------------------
0520:
0521:            public void traceEntry(Object instance, String methodName) {
0522:                if (traceSuspended()) {
0523:                    return;
0524:                }
0525:                traceEntryAllArgs(instance, methodName, "()");
0526:            }
0527:
0528:            // ---------------------- trace entry of methods w/ 1 arg --------------------
0529:
0530:            public void traceEntry(Object instance, String methodName,
0531:                    Object argument) {
0532:                if (traceSuspended()) {
0533:                    return;
0534:                }
0535:                traceEntryAllArgs(instance, methodName, "(" + argument + ")");
0536:            }
0537:
0538:            public void traceEntry(Object instance, String methodName,
0539:                    boolean argument) {
0540:                if (traceSuspended()) {
0541:                    return;
0542:                }
0543:                traceEntryAllArgs(instance, methodName, "(" + argument + ")");
0544:            }
0545:
0546:            public void traceEntry(Object instance, String methodName,
0547:                    int argument) {
0548:                if (traceSuspended()) {
0549:                    return;
0550:                }
0551:                traceEntryAllArgs(instance, methodName, "(" + argument + ")");
0552:            }
0553:
0554:            public void traceDeprecatedEntry(Object instance,
0555:                    String methodName, int argument) {
0556:                if (traceSuspended()) {
0557:                    return;
0558:                }
0559:                traceDeprecatedEntryAllArgs(instance, methodName, "("
0560:                        + argument + ")");
0561:            }
0562:
0563:            public void traceDeprecatedEntry(Object instance,
0564:                    String methodName, Object argument) {
0565:                if (traceSuspended()) {
0566:                    return;
0567:                }
0568:                traceDeprecatedEntryAllArgs(instance, methodName, "("
0569:                        + argument + ")");
0570:            }
0571:
0572:            // ---------------------- trace entry of methods w/ 2 args -------------------
0573:
0574:            public void traceEntry(Object instance, String methodName,
0575:                    Object arg1, Object arg2) {
0576:                if (traceSuspended()) {
0577:                    return;
0578:                }
0579:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0580:                        + arg2 + ")");
0581:            }
0582:
0583:            public void traceEntry(Object instance, String methodName,
0584:                    int arg1, Object arg2) {
0585:                if (traceSuspended()) {
0586:                    return;
0587:                }
0588:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0589:                        + arg2 + ")");
0590:            }
0591:
0592:            public void traceEntry(Object instance, String methodName,
0593:                    int arg1, byte[] arg2) {
0594:                if (traceSuspended()) {
0595:                    return;
0596:                }
0597:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0598:                        + Utils.getStringFromBytes(arg2) + ")");
0599:            }
0600:
0601:            public void traceDeprecatedEntry(Object instance,
0602:                    String methodName, int arg1, int arg2) {
0603:                if (traceSuspended()) {
0604:                    return;
0605:                }
0606:                traceDeprecatedEntryAllArgs(instance, methodName, "(" + arg1
0607:                        + ", " + arg2 + ")");
0608:            }
0609:
0610:            public void traceDeprecatedEntry(Object instance,
0611:                    String methodName, Object arg1, int arg2) {
0612:                if (traceSuspended()) {
0613:                    return;
0614:                }
0615:                traceDeprecatedEntryAllArgs(instance, methodName, "(" + arg1
0616:                        + ", " + arg2 + ")");
0617:            }
0618:
0619:            public void traceEntry(Object instance, String methodName,
0620:                    int arg1, boolean arg2) {
0621:                if (traceSuspended()) {
0622:                    return;
0623:                }
0624:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0625:                        + arg2 + ")");
0626:            }
0627:
0628:            public void traceEntry(Object instance, String methodName,
0629:                    int arg1, byte arg2) {
0630:                if (traceSuspended()) {
0631:                    return;
0632:                }
0633:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", 0x"
0634:                        + Integer.toHexString(arg2 & 0xff) + ")");
0635:            }
0636:
0637:            public void traceEntry(Object instance, String methodName,
0638:                    int arg1, short arg2) {
0639:                if (traceSuspended()) {
0640:                    return;
0641:                }
0642:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0643:                        + arg2 + ")");
0644:            }
0645:
0646:            public void traceEntry(Object instance, String methodName,
0647:                    int arg1, int arg2) {
0648:                if (traceSuspended()) {
0649:                    return;
0650:                }
0651:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0652:                        + arg2 + ")");
0653:            }
0654:
0655:            public void traceEntry(Object instance, String methodName,
0656:                    int arg1, long arg2) {
0657:                if (traceSuspended()) {
0658:                    return;
0659:                }
0660:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0661:                        + arg2 + ")");
0662:            }
0663:
0664:            public void traceEntry(Object instance, String methodName,
0665:                    int arg1, float arg2) {
0666:                if (traceSuspended()) {
0667:                    return;
0668:                }
0669:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0670:                        + arg2 + ")");
0671:            }
0672:
0673:            public void traceEntry(Object instance, String methodName,
0674:                    int arg1, double arg2) {
0675:                if (traceSuspended()) {
0676:                    return;
0677:                }
0678:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0679:                        + arg2 + ")");
0680:            }
0681:
0682:            public void traceEntry(Object instance, String methodName,
0683:                    Object arg1, boolean arg2) {
0684:                if (traceSuspended()) {
0685:                    return;
0686:                }
0687:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0688:                        + arg2 + ")");
0689:            }
0690:
0691:            public void traceEntry(Object instance, String methodName,
0692:                    Object arg1, byte arg2) {
0693:                if (traceSuspended()) {
0694:                    return;
0695:                }
0696:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", 0x"
0697:                        + Integer.toHexString(arg2 & 0xff) + ")");
0698:            }
0699:
0700:            public void traceEntry(Object instance, String methodName,
0701:                    Object arg1, short arg2) {
0702:                if (traceSuspended()) {
0703:                    return;
0704:                }
0705:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0706:                        + arg2 + ")");
0707:            }
0708:
0709:            public void traceEntry(Object instance, String methodName,
0710:                    Object arg1, int arg2) {
0711:                if (traceSuspended()) {
0712:                    return;
0713:                }
0714:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0715:                        + arg2 + ")");
0716:            }
0717:
0718:            public void traceEntry(Object instance, String methodName,
0719:                    Object arg1, long arg2) {
0720:                if (traceSuspended()) {
0721:                    return;
0722:                }
0723:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0724:                        + arg2 + ")");
0725:            }
0726:
0727:            public void traceEntry(Object instance, String methodName,
0728:                    Object arg1, float arg2) {
0729:                if (traceSuspended()) {
0730:                    return;
0731:                }
0732:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0733:                        + arg2 + ")");
0734:            }
0735:
0736:            public void traceEntry(Object instance, String methodName,
0737:                    Object arg1, double arg2) {
0738:                if (traceSuspended()) {
0739:                    return;
0740:                }
0741:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0742:                        + arg2 + ")");
0743:            }
0744:
0745:            // ---------------------- trace entry of methods w/ 3 args -------------------
0746:
0747:            public void traceEntry(Object instance, String methodName,
0748:                    Object arg1, Object arg2, Object arg3) {
0749:                if (traceSuspended()) {
0750:                    return;
0751:                }
0752:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0753:                        + arg2 + ", " + arg3 + ")");
0754:            }
0755:
0756:            public void traceEntry(Object instance, String methodName,
0757:                    int arg1, Object arg2, Object arg3) {
0758:                if (traceSuspended()) {
0759:                    return;
0760:                }
0761:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0762:                        + arg2 + ", " + arg3 + ")");
0763:            }
0764:
0765:            public void traceEntry(Object instance, String methodName,
0766:                    Object arg1, Object arg2, int arg3) {
0767:                if (traceSuspended()) {
0768:                    return;
0769:                }
0770:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0771:                        + arg2 + ", " + arg3 + ")");
0772:            }
0773:
0774:            public void traceEntry(Object instance, String methodName,
0775:                    int arg1, Object arg2, int arg3) {
0776:                if (traceSuspended()) {
0777:                    return;
0778:                }
0779:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0780:                        + arg2 + ", " + arg3 + ")");
0781:            }
0782:
0783:            public void traceDeprecatedEntry(Object instance,
0784:                    String methodName, int arg1, Object arg2, int arg3) {
0785:                if (traceSuspended()) {
0786:                    return;
0787:                }
0788:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0789:                        + arg2 + ", " + arg3 + ")");
0790:            }
0791:
0792:            public void traceEntry(Object instance, String methodName,
0793:                    int arg1, int arg2, Object arg3) {
0794:                if (traceSuspended()) {
0795:                    return;
0796:                }
0797:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0798:                        + arg2 + ", " + arg3 + ")");
0799:            }
0800:
0801:            public void traceEntry(Object instance, String methodName,
0802:                    int arg1, int arg2, int arg3) {
0803:                if (traceSuspended()) {
0804:                    return;
0805:                }
0806:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0807:                        + arg2 + ", " + arg3 + ")");
0808:            }
0809:
0810:            public void traceEntry(Object instance, String methodName,
0811:                    Object arg1, int arg2, int arg3) {
0812:                if (traceSuspended()) {
0813:                    return;
0814:                }
0815:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0816:                        + arg2 + ", " + arg3 + ")");
0817:            }
0818:
0819:            public void traceEntry(Object instance, String methodName,
0820:                    Object arg1, int arg2, Object arg3) {
0821:                if (traceSuspended()) {
0822:                    return;
0823:                }
0824:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0825:                        + arg2 + ", " + arg3 + ")");
0826:            }
0827:
0828:            public void traceEntry(Object instance, String methodName,
0829:                    Object arg1, boolean arg2, boolean arg3) {
0830:                if (traceSuspended()) {
0831:                    return;
0832:                }
0833:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0834:                        + arg2 + ", " + arg3 + ")");
0835:            }
0836:
0837:            public void traceEntry(Object instance, String methodName,
0838:                    Object arg1, boolean arg2, int arg3) {
0839:                if (traceSuspended()) {
0840:                    return;
0841:                }
0842:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0843:                        + arg2 + ", " + arg3 + ")");
0844:            }
0845:
0846:            // ---------------------- trace entry of methods w/ 4 args -------------------
0847:
0848:            public void traceEntry(Object instance, String methodName,
0849:                    Object arg1, Object arg2, Object arg3, Object arg4) {
0850:                if (traceSuspended()) {
0851:                    return;
0852:                }
0853:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0854:                        + arg2 + ", " + arg3 + ", " + arg4 + ")");
0855:            }
0856:
0857:            public void traceEntry(Object instance, String methodName,
0858:                    int arg1, Object arg2, Object arg3, Object arg4) {
0859:                if (traceSuspended()) {
0860:                    return;
0861:                }
0862:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0863:                        + arg2 + ", " + arg3 + ", " + arg4 + ")");
0864:            }
0865:
0866:            public void traceEntry(Object instance, String methodName,
0867:                    int arg1, Object arg2, int arg3, int arg4) {
0868:                if (traceSuspended()) {
0869:                    return;
0870:                }
0871:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0872:                        + arg2 + ", " + arg3 + ", " + arg4 + ")");
0873:            }
0874:
0875:            public void traceEntry(Object instance, String methodName,
0876:                    Object arg1, int arg2, int arg3, int arg4) {
0877:                if (traceSuspended()) {
0878:                    return;
0879:                }
0880:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0881:                        + arg2 + ", " + arg3 + ", " + arg4 + ")");
0882:            }
0883:
0884:            public void traceEntry(Object instance, String methodName,
0885:                    Object arg1, Object arg2, int arg3, int arg4) {
0886:                if (traceSuspended()) {
0887:                    return;
0888:                }
0889:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0890:                        + arg2 + ", " + arg3 + ", " + arg4 + ")");
0891:            }
0892:
0893:            // ---------------------- trace entry of methods w/ 5 args -------------------
0894:
0895:            public void traceEntry(Object instance, String methodName,
0896:                    Object arg1, Object arg2, Object arg3, int arg4,
0897:                    boolean arg5) {
0898:                if (traceSuspended()) {
0899:                    return;
0900:                }
0901:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0902:                        + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5 + ")");
0903:            }
0904:
0905:            public void traceEntry(Object instance, String methodName,
0906:                    Object arg1, Object arg2, Object arg3, boolean arg4,
0907:                    boolean arg5) {
0908:                if (traceSuspended()) {
0909:                    return;
0910:                }
0911:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0912:                        + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5 + ")");
0913:            }
0914:
0915:            // ---------------------- trace entry of methods w/ 6 args -------------------
0916:
0917:            public void traceEntry(Object instance, String methodName,
0918:                    Object arg1, Object arg2, Object arg3, Object arg4,
0919:                    Object arg5, Object arg6) {
0920:                if (traceSuspended()) {
0921:                    return;
0922:                }
0923:                traceEntryAllArgs(instance, methodName, "(" + arg1 + ", "
0924:                        + arg2 + ", " + arg3 + ", " + arg4 + ", " + arg5 + ", "
0925:                        + arg6 + ")");
0926:            }
0927:
0928:            // ---------------------------tracing exceptions and warnings-----------------
0929:
0930:            public void traceDiagnosable(SqlException e) {
0931:                if (traceSuspended()) {
0932:                    return;
0933:                }
0934:                if (!loggingEnabled(ClientDataSource.TRACE_DIAGNOSTICS)) {
0935:                    return;
0936:                }
0937:                synchronized (printWriter_) {
0938:                    dncprintln("BEGIN TRACE_DIAGNOSTICS");
0939:                    ExceptionFormatter.printTrace(e, printWriter_, "[derby]",
0940:                            true); // true means return tokens only
0941:                    dncprintln("END TRACE_DIAGNOSTICS");
0942:                }
0943:            }
0944:
0945:            public void traceDiagnosable(java.sql.SQLException e) {
0946:                if (traceSuspended()) {
0947:                    return;
0948:                }
0949:                if (!loggingEnabled(ClientDataSource.TRACE_DIAGNOSTICS)) {
0950:                    return;
0951:                }
0952:                synchronized (printWriter_) {
0953:                    dncprintln("BEGIN TRACE_DIAGNOSTICS");
0954:                    ExceptionFormatter.printTrace(e, printWriter_, "[derby]",
0955:                            true); // true means return tokens only
0956:                    dncprintln("END TRACE_DIAGNOSTICS");
0957:                }
0958:            }
0959:
0960:            public void traceDiagnosable(javax.transaction.xa.XAException e) {
0961:                if (traceSuspended()) {
0962:                    return;
0963:                }
0964:                if (!loggingEnabled(ClientDataSource.TRACE_DIAGNOSTICS)) {
0965:                    return;
0966:                }
0967:                synchronized (printWriter_) {
0968:                    dncprintln("BEGIN TRACE_DIAGNOSTICS");
0969:                    ExceptionFormatter.printTrace(e, printWriter_, "[derby]");
0970:                    dncprintln("END TRACE_DIAGNOSTICS");
0971:                }
0972:            }
0973:
0974:            // ------------------------ meta data tracing --------------------------------
0975:
0976:            public void traceParameterMetaData(Statement statement,
0977:                    ColumnMetaData columnMetaData) {
0978:                if (traceSuspended()) {
0979:                    return;
0980:                }
0981:                if (!loggingEnabled(ClientDataSource.TRACE_PARAMETER_META_DATA)
0982:                        || columnMetaData == null) {
0983:                    return;
0984:                }
0985:                synchronized (printWriter_) {
0986:                    String header = "[ParameterMetaData@"
0987:                            + Integer.toHexString(columnMetaData.hashCode())
0988:                            + "]";
0989:                    try {
0990:                        dncprintln(header, "BEGIN TRACE_PARAMETER_META_DATA");
0991:                        dncprintln(header,
0992:                                "Parameter meta data for statement Statement@"
0993:                                        + Integer.toHexString(statement
0994:                                                .hashCode()));
0995:                        dncprintln(header, "Number of parameter columns: "
0996:                                + columnMetaData.getColumnCount());
0997:                        traceColumnMetaData(header, columnMetaData);
0998:                        dncprintln(header, "END TRACE_PARAMETER_META_DATA");
0999:                    } catch (SQLException e) {
1000:                        dncprintln(header,
1001:                                "Encountered an SQL exception while trying to trace parameter meta data");
1002:                        dncprintln(header, "END TRACE_PARAMETER_META_DATA");
1003:                    }
1004:                }
1005:            }
1006:
1007:            public void traceResultSetMetaData(Statement statement,
1008:                    ColumnMetaData columnMetaData) {
1009:                if (traceSuspended()) {
1010:                    return;
1011:                }
1012:                if (!loggingEnabled(ClientDataSource.TRACE_RESULT_SET_META_DATA)
1013:                        || columnMetaData == null) {
1014:                    return;
1015:                }
1016:                synchronized (printWriter_) {
1017:                    String header = "[ResultSetMetaData@"
1018:                            + Integer.toHexString(columnMetaData.hashCode())
1019:                            + "]";
1020:                    try {
1021:                        dncprintln(header, "BEGIN TRACE_RESULT_SET_META_DATA");
1022:                        dncprintln(header,
1023:                                "Result set meta data for statement Statement@"
1024:                                        + Integer.toHexString(statement
1025:                                                .hashCode()));
1026:                        dncprintln(header, "Number of result set columns: "
1027:                                + columnMetaData.getColumnCount());
1028:                        traceColumnMetaData(header, columnMetaData);
1029:                        dncprintln(header, "END TRACE_RESULT_SET_META_DATA");
1030:                    } catch (SQLException e) {
1031:                        dncprintln(header,
1032:                                "Encountered an SQL exception while trying to trace result set meta data");
1033:                        dncprintln(header, "END TRACE_RESULT_SET_META_DATA");
1034:                    }
1035:                }
1036:            }
1037:
1038:            //-----------------------------transient state--------------------------------
1039:
1040:            private void traceColumnMetaData(String header,
1041:                    ColumnMetaData columnMetaData) {
1042:                if (traceSuspended()) {
1043:                    return;
1044:                }
1045:                try {
1046:                    synchronized (printWriter_) {
1047:
1048:                        for (int column = 1; column <= columnMetaData
1049:                                .getColumnCount(); column++) {
1050:                            dncprint(header, "Column " + column + ": { ");
1051:                            printWriter_.print("label="
1052:                                    + columnMetaData.getColumnLabel(column)
1053:                                    + ", ");
1054:                            printWriter_.print("name="
1055:                                    + columnMetaData.getColumnName(column)
1056:                                    + ", ");
1057:                            printWriter_.print("type name="
1058:                                    + columnMetaData.getColumnTypeName(column)
1059:                                    + ", ");
1060:                            printWriter_.print("type="
1061:                                    + columnMetaData.getColumnType(column)
1062:                                    + ", ");
1063:                            printWriter_.print("nullable="
1064:                                    + columnMetaData.isNullable(column) + ", ");
1065:                            printWriter_.print("precision="
1066:                                    + columnMetaData.getPrecision(column)
1067:                                    + ", ");
1068:                            printWriter_.print("scale="
1069:                                    + columnMetaData.getScale(column) + ", ");
1070:                            printWriter_.print("schema name="
1071:                                    + columnMetaData.getSchemaName(column)
1072:                                    + ", ");
1073:                            printWriter_.print("table name="
1074:                                    + columnMetaData.getTableName(column)
1075:                                    + ", ");
1076:                            printWriter_.print("writable="
1077:                                    + columnMetaData.isWritable(column) + ", ");
1078:                            printWriter_
1079:                                    .print("sqlPrecision="
1080:                                            + (columnMetaData.sqlPrecision_ == null ? "<null>"
1081:                                                    : ""
1082:                                                            + columnMetaData.sqlPrecision_[column - 1])
1083:                                            + ", ");
1084:                            printWriter_
1085:                                    .print("sqlScale="
1086:                                            + (columnMetaData.sqlScale_ == null ? "<null>"
1087:                                                    : ""
1088:                                                            + columnMetaData.sqlScale_[column - 1])
1089:                                            + ", ");
1090:                            printWriter_
1091:                                    .print("sqlLength="
1092:                                            + (columnMetaData.sqlLength_ == null ? "<null>"
1093:                                                    : ""
1094:                                                            + columnMetaData.sqlLength_[column - 1])
1095:                                            + ", ");
1096:                            printWriter_
1097:                                    .print("sqlType="
1098:                                            + (columnMetaData.sqlType_ == null ? "<null>"
1099:                                                    : ""
1100:                                                            + columnMetaData.sqlType_[column - 1])
1101:                                            + ", ");
1102:                            printWriter_
1103:                                    .print("sqlCcsid="
1104:                                            + (columnMetaData.sqlCcsid_ == null ? "<null>"
1105:                                                    : ""
1106:                                                            + columnMetaData.sqlCcsid_[column - 1])
1107:                                            + ", ");
1108:                            printWriter_
1109:                                    .print("sqlName="
1110:                                            + (columnMetaData.sqlName_ == null ? "<null>"
1111:                                                    : columnMetaData.sqlName_[column - 1])
1112:                                            + ", ");
1113:                            printWriter_
1114:                                    .print("sqlLabel="
1115:                                            + (columnMetaData.sqlLabel_ == null ? "<null>"
1116:                                                    : columnMetaData.sqlLabel_[column - 1])
1117:                                            + ", ");
1118:                            printWriter_
1119:                                    .print("sqlUnnamed="
1120:                                            + (columnMetaData.sqlUnnamed_ == null ? "<null>"
1121:                                                    : ""
1122:                                                            + columnMetaData.sqlUnnamed_[column - 1])
1123:                                            + ", ");
1124:                            printWriter_
1125:                                    .print("sqlComment="
1126:                                            + (columnMetaData.sqlComment_ == null ? "<null>"
1127:                                                    : columnMetaData.sqlComment_[column - 1])
1128:                                            + ", ");
1129:                            printWriter_
1130:                                    .print("sqlxKeymem="
1131:                                            + (columnMetaData.sqlxKeymem_ == null ? "<null>"
1132:                                                    : ""
1133:                                                            + columnMetaData.sqlxKeymem_[column - 1])
1134:                                            + ", ");
1135:                            printWriter_
1136:                                    .print("sqlxGenerated="
1137:                                            + (columnMetaData.sqlxGenerated_ == null ? "<null>"
1138:                                                    : ""
1139:                                                            + columnMetaData.sqlxGenerated_[column - 1])
1140:                                            + ", ");
1141:                            printWriter_
1142:                                    .print("sqlxParmmode="
1143:                                            + (columnMetaData.sqlxParmmode_ == null ? "<null>"
1144:                                                    : ""
1145:                                                            + columnMetaData.sqlxParmmode_[column - 1])
1146:                                            + ", ");
1147:                            printWriter_
1148:                                    .print("sqlxCorname="
1149:                                            + (columnMetaData.sqlxCorname_ == null ? "<null>"
1150:                                                    : columnMetaData.sqlxCorname_[column - 1])
1151:                                            + ", ");
1152:                            printWriter_
1153:                                    .print("sqlxName="
1154:                                            + (columnMetaData.sqlxName_ == null ? "<null>"
1155:                                                    : columnMetaData.sqlxName_[column - 1])
1156:                                            + ", ");
1157:                            printWriter_
1158:                                    .print("sqlxBasename="
1159:                                            + (columnMetaData.sqlxBasename_ == null ? "<null>"
1160:                                                    : columnMetaData.sqlxBasename_[column - 1])
1161:                                            + ", ");
1162:                            printWriter_
1163:                                    .print("sqlxUpdatable="
1164:                                            + (columnMetaData.sqlxUpdatable_ == null ? "<null>"
1165:                                                    : ""
1166:                                                            + columnMetaData.sqlxUpdatable_[column - 1])
1167:                                            + ", ");
1168:                            printWriter_
1169:                                    .print("sqlxSchema="
1170:                                            + (columnMetaData.sqlxSchema_ == null ? "<null>"
1171:                                                    : columnMetaData.sqlxSchema_[column - 1])
1172:                                            + ", ");
1173:                            printWriter_
1174:                                    .print("sqlxRdbnam="
1175:                                            + (columnMetaData.sqlxRdbnam_ == null ? "<null>"
1176:                                                    : columnMetaData.sqlxRdbnam_[column - 1])
1177:                                            + ", ");
1178:                            printWriter_.print("internal type="
1179:                                    + columnMetaData.types_[column - 1] + ", ");
1180:                            printWriter_.println(" }");
1181:                        }
1182:                        dncprint(header, "{ ");
1183:                        printWriter_.print("sqldHold="
1184:                                + columnMetaData.sqldHold_ + ", ");
1185:                        printWriter_.print("sqldReturn="
1186:                                + columnMetaData.sqldReturn_ + ", ");
1187:                        printWriter_.print("sqldScroll="
1188:                                + columnMetaData.sqldScroll_ + ", ");
1189:                        printWriter_.print("sqldSensitive="
1190:                                + columnMetaData.sqldSensitive_ + ", ");
1191:                        printWriter_.print("sqldFcode="
1192:                                + columnMetaData.sqldFcode_ + ", ");
1193:                        printWriter_.print("sqldKeytype="
1194:                                + columnMetaData.sqldKeytype_ + ", ");
1195:                        printWriter_.print("sqldRdbnam="
1196:                                + columnMetaData.sqldRdbnam_ + ", ");
1197:                        printWriter_.print("sqldSchema="
1198:                                + columnMetaData.sqldSchema_);
1199:                        printWriter_.println(" }");
1200:                        printWriter_.flush();
1201:                    }
1202:                } catch (SQLException e) {
1203:                    dncprintln(header,
1204:                            "Encountered an SQL exception while trying to trace column meta data");
1205:                }
1206:            }
1207:
1208:            // ---------------------- 3-way tracing connects -----------------------------
1209:            // Including protocol manager levels, and driver configuration
1210:
1211:            // Jdbc 2
1212:            public void traceConnectEntry(ClientBaseDataSource dataSource) {
1213:                if (traceSuspended()) {
1214:                    return;
1215:                }
1216:                if (loggingEnabled(ClientDataSource.TRACE_DRIVER_CONFIGURATION)) {
1217:                    traceDriverConfigurationJdbc2();
1218:                }
1219:                if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) {
1220:                    traceConnectsEntry(dataSource);
1221:                }
1222:            }
1223:
1224:            // Jdbc 1
1225:            public void traceConnectEntry(String server, int port,
1226:                    String database, java.util.Properties properties) {
1227:                if (traceSuspended()) {
1228:                    return;
1229:                }
1230:                if (loggingEnabled(ClientDataSource.TRACE_DRIVER_CONFIGURATION)) {
1231:                    traceDriverConfigurationJdbc1();
1232:                }
1233:                if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) {
1234:                    traceConnectsEntry(server, port, database, properties);
1235:                }
1236:            }
1237:
1238:            public void traceConnectResetEntry(Object instance,
1239:                    LogWriter logWriter, String user, ClientBaseDataSource ds) {
1240:                if (traceSuspended()) {
1241:                    return;
1242:                }
1243:                traceEntry(instance, "reset", logWriter, user, "<escaped>", ds);
1244:                if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) {
1245:                    traceConnectsResetEntry(ds);
1246:                }
1247:            }
1248:
1249:            public void traceConnectExit(Connection connection) {
1250:                if (traceSuspended()) {
1251:                    return;
1252:                }
1253:                if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) {
1254:                    traceConnectsExit(connection);
1255:                }
1256:            }
1257:
1258:            public void traceConnectResetExit(Connection connection) {
1259:                if (traceSuspended()) {
1260:                    return;
1261:                }
1262:                if (loggingEnabled(ClientDataSource.TRACE_CONNECTS)) {
1263:                    traceConnectsResetExit(connection);
1264:                }
1265:            }
1266:
1267:            // ---------------------- tracing connects -----------------------------------
1268:
1269:            private void traceConnectsResetEntry(ClientBaseDataSource dataSource) {
1270:                try {
1271:                    if (traceSuspended()) {
1272:                        return;
1273:                    }
1274:                    traceConnectsResetEntry(dataSource.getServerName(),
1275:                            dataSource.getPortNumber(), dataSource
1276:                                    .getDatabaseName(),
1277:                            getProperties(dataSource));
1278:                } catch (SqlException se) {
1279:                    dncprintln("Encountered an SQL exception while trying to trace connection reset entry");
1280:                }
1281:            }
1282:
1283:            private void traceConnectsEntry(ClientBaseDataSource dataSource) {
1284:                try {
1285:                    if (traceSuspended()) {
1286:                        return;
1287:                    }
1288:                    traceConnectsEntry(dataSource.getServerName(), dataSource
1289:                            .getPortNumber(), dataSource.getDatabaseName(),
1290:                            getProperties(dataSource));
1291:                } catch (SqlException se) {
1292:                    dncprintln("Encountered an SQL exception while trying to trace connection entry");
1293:                }
1294:
1295:            }
1296:
1297:            private void traceConnectsResetEntry(String server, int port,
1298:                    String database, java.util.Properties properties) {
1299:                if (traceSuspended()) {
1300:                    return;
1301:                }
1302:                dncprintln("BEGIN TRACE_CONNECT_RESET");
1303:                dncprintln("Connection reset requested for " + server + ":"
1304:                        + port + "/" + database);
1305:                dncprint("Using properties: ");
1306:                writeProperties(properties);
1307:                dncprintln("END TRACE_CONNECT_RESET");
1308:            }
1309:
1310:            private void traceConnectsEntry(String server, int port,
1311:                    String database, java.util.Properties properties) {
1312:                if (traceSuspended()) {
1313:                    return;
1314:                }
1315:                synchronized (printWriter_) {
1316:                    dncprintln("BEGIN TRACE_CONNECTS");
1317:                    dncprintln("Attempting connection to " + server + ":"
1318:                            + port + "/" + database);
1319:                    dncprint("Using properties: ");
1320:                    writeProperties(properties);
1321:                    dncprintln("END TRACE_CONNECTS");
1322:                }
1323:            }
1324:
1325:            // Specialized by NetLogWriter.traceConnectsExit()
1326:            public void traceConnectsExit(Connection c) {
1327:                if (traceSuspended()) {
1328:                    return;
1329:                }
1330:                synchronized (printWriter_) {
1331:                    String header = "[Connection@"
1332:                            + Integer.toHexString(c.hashCode()) + "]";
1333:                    try {
1334:                        dncprintln(header, "BEGIN TRACE_CONNECTS");
1335:                        dncprintln(header, "Successfully connected to server "
1336:                                + c.databaseMetaData_.getURL());
1337:                        dncprintln(header, "User: "
1338:                                + c.databaseMetaData_.getUserName());
1339:                        dncprintln(header, "Database product name: "
1340:                                + c.databaseMetaData_.getDatabaseProductName());
1341:                        dncprintln(header, "Database product version: "
1342:                                + c.databaseMetaData_
1343:                                        .getDatabaseProductVersion());
1344:                        dncprintln(header, "Driver name: "
1345:                                + c.databaseMetaData_.getDriverName());
1346:                        dncprintln(header, "Driver version: "
1347:                                + c.databaseMetaData_.getDriverVersion());
1348:                        dncprintln(header, "END TRACE_CONNECTS");
1349:                    } catch (java.sql.SQLException e) {
1350:                        dncprintln(header,
1351:                                "Encountered an SQL exception while trying to trace connection exit");
1352:                        dncprintln(header, "END TRACE_CONNECTS");
1353:                    }
1354:                }
1355:            }
1356:
1357:            public void traceConnectsResetExit(
1358:                    org.apache.derby.client.am.Connection c) {
1359:                if (traceSuspended()) {
1360:                    return;
1361:                }
1362:                synchronized (printWriter_) {
1363:                    String header = "[Connection@"
1364:                            + Integer.toHexString(c.hashCode()) + "]";
1365:                    try {
1366:                        dncprintln(header, "BEGIN TRACE_CONNECT_RESET");
1367:                        dncprintln(header,
1368:                                "Successfully reset connection to server "
1369:                                        + c.databaseMetaData_.getURL());
1370:                        dncprintln(header, "User: "
1371:                                + c.databaseMetaData_.getUserName());
1372:                        dncprintln(header, "Database product name: "
1373:                                + c.databaseMetaData_.getDatabaseProductName());
1374:                        dncprintln(header, "Database product version: "
1375:                                + c.databaseMetaData_
1376:                                        .getDatabaseProductVersion());
1377:                        dncprintln(header, "Driver name: "
1378:                                + c.databaseMetaData_.getDriverName());
1379:                        dncprintln(header, "Driver version: "
1380:                                + c.databaseMetaData_.getDriverVersion());
1381:                        dncprintln(header, "END TRACE_CONNECT_RESET");
1382:                    } catch (java.sql.SQLException e) {
1383:                        dncprintln(header,
1384:                                "Encountered an SQL exception while trying to trace connection reset exit");
1385:                        dncprintln(header, "END TRACE_CONNECT_RESET");
1386:                    }
1387:                }
1388:            }
1389:
1390:            // properties.toString() will print out passwords,
1391:            // so this method was written to escape the password property value.
1392:            // printWriter_ synchronized by caller.
1393:            private void writeProperties(java.util.Properties properties) {
1394:                printWriter_.print("{ ");
1395:                for (java.util.Iterator i = properties.entrySet().iterator(); i
1396:                        .hasNext();) {
1397:                    java.util.Map.Entry e = (java.util.Map.Entry) (i.next());
1398:                    if ("password".equals(e.getKey())) {
1399:                        printWriter_.print("password="
1400:                                + escapePassword((String) e.getValue()));
1401:                    } else {
1402:                        printWriter_.print(e.getKey() + "=" + e.getValue());
1403:                    }
1404:                    if (i.hasNext()) {
1405:                        printWriter_.print(", ");
1406:                    }
1407:                }
1408:                printWriter_.println(" }");
1409:                printWriter_.flush();
1410:            }
1411:
1412:            private String escapePassword(String pw) {
1413:                StringBuffer sb = new StringBuffer(pw);
1414:                for (int j = 0; j < pw.length(); j++) {
1415:                    sb.setCharAt(j, '*');
1416:                }
1417:                return sb.toString();
1418:            }
1419:
1420:            //-------------------------tracing driver configuration-----------------------
1421:
1422:            private void traceDriverConfigurationJdbc2() {
1423:                if (traceSuspended()) {
1424:                    return;
1425:                }
1426:                synchronized (printWriter_) {
1427:                    if (!driverConfigurationHasBeenWrittenToJdbc2Stream_) {
1428:                        writeDriverConfiguration();
1429:                        driverConfigurationHasBeenWrittenToJdbc2Stream_ = true;
1430:                    }
1431:                }
1432:            }
1433:
1434:            private void traceDriverConfigurationJdbc1() {
1435:                if (traceSuspended()) {
1436:                    return;
1437:                }
1438:                synchronized (printWriter_) {
1439:                    if (!driverConfigurationHasBeenWrittenToJdbc1Stream_) {
1440:                        writeDriverConfiguration();
1441:                        driverConfigurationHasBeenWrittenToJdbc1Stream_ = true;
1442:                    }
1443:                }
1444:            }
1445:
1446:            public void writeDriverConfiguration() {
1447:                org.apache.derby.client.am.Version
1448:                        .writeDriverConfiguration(printWriter_);
1449:            }
1450:
1451:            public static java.io.PrintWriter getPrintWriter(String fileName,
1452:                    boolean fileAppend) throws SqlException {
1453:                try {
1454:                    java.io.PrintWriter printWriter = null;
1455:                    String fileCanonicalPath = new java.io.File(fileName)
1456:                            .getCanonicalPath();
1457:                    printWriter = new java.io.PrintWriter(
1458:                            new java.io.BufferedOutputStream(
1459:                                    new java.io.FileOutputStream(
1460:                                            fileCanonicalPath, fileAppend),
1461:                                    4096), true);
1462:                    return printWriter;
1463:                } catch (java.io.IOException e) {
1464:                    throw new SqlException(null, new ClientMessageId(
1465:                            SQLState.UNABLE_TO_OPEN_FILE), new Object[] {
1466:                            fileName, e.getMessage() }, e);
1467:                }
1468:            }
1469:
1470:            /**
1471:             * Obtain a set of Properties for the ClientBaseDataSource
1472:             */
1473:            private Properties getProperties(ClientBaseDataSource cds)
1474:                    throws SqlException {
1475:
1476:                Properties properties = new Properties();
1477:
1478:                try {
1479:                    Reference ref = cds.getReference();
1480:
1481:                    for (Enumeration e = ref.getAll(); e.hasMoreElements();) {
1482:
1483:                        RefAddr attribute = (RefAddr) e.nextElement();
1484:
1485:                        String propertyKey = attribute.getType();
1486:                        String value = (String) attribute.getContent();
1487:
1488:                        // Don't display the password or even its length
1489:                        if (Attribute.PASSWORD_ATTR.equals(propertyKey)) {
1490:                            value = "********";
1491:                        }
1492:
1493:                        if (value != null)
1494:                            properties.setProperty(propertyKey, value);
1495:                    }
1496:                } catch (NamingException e) {
1497:                    throw new SqlException(this , new ClientMessageId(
1498:                            SQLState.JAVA_EXCEPTION), e.getClass().getName(), e
1499:                            .getMessage(), e);
1500:                }
1501:
1502:                return properties;
1503:            }
1504:
1505:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.