Source Code Cross Referenced for TraceObject.java in  » Database-DBMS » h2database » org » h2 » message » 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 » h2database » org.h2.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2004-2008 H2 Group. Licensed under the H2 License, Version 1.0
003:         * (http://h2database.com/html/license.html).
004:         * Initial Developer: H2 Group
005:         */
006:        package org.h2.message;
007:
008:        import java.io.PrintWriter;
009:        import java.io.Writer;
010:        import java.math.BigDecimal;
011:        import java.sql.SQLException;
012:        import java.util.Iterator;
013:        import java.util.Map;
014:
015:        import org.h2.constant.SysProperties;
016:        import org.h2.expression.ParameterInterface;
017:        import org.h2.util.ByteUtils;
018:        import org.h2.util.FileUtils;
019:        import org.h2.util.ObjectArray;
020:        import org.h2.util.StringUtils;
021:
022:        /**
023:         * The base class for objects that can print trace information about themselves.
024:         */
025:        public class TraceObject {
026:            public static final int CALLABLE_STATEMENT = 0, CONNECTION = 1,
027:                    DATABASE_META_DATA = 2, PREPARED_STATEMENT = 3,
028:                    RESULT_SET = 4, RESULT_SET_META_DATA = 5, SAVEPOINT = 6,
029:                    SQL_EXCEPTION = 7, STATEMENT = 8, BLOB = 9, CLOB = 10,
030:                    PARAMETER_META_DATA = 11;
031:            public static final int DATA_SOURCE = 12, XA_DATA_SOURCE = 13,
032:                    XID = 14, ARRAY = 15;
033:
034:            private static final int LAST = ARRAY + 1;
035:            private Trace trace;
036:            private static final int[] ID = new int[LAST];
037:            private static final String[] PREFIX = { "call", "conn", "dbMeta",
038:                    "prep", "rs", "rsMeta", "sp", "ex", "stat", "blob", "clob",
039:                    "pMeta", "ds", "xads", "xid", "ar" };
040:            private int type, id;
041:
042:            protected void setTrace(Trace trace, int type, int id) {
043:                this .trace = trace;
044:                this .type = type;
045:                this .id = id;
046:            }
047:
048:            protected int getTraceId() {
049:                return id;
050:            }
051:
052:            /**
053:             * INTERNAL
054:             */
055:            public String getTraceObjectName() {
056:                return PREFIX[type] + id;
057:            }
058:
059:            protected int getNextId(int type) {
060:                return ID[type]++;
061:            }
062:
063:            protected boolean debug() {
064:                return trace.debug();
065:            }
066:
067:            protected boolean info() {
068:                return trace.info();
069:            }
070:
071:            protected Trace getTrace() {
072:                return trace;
073:            }
074:
075:            protected void debugCodeAssign(String className, int type, int id,
076:                    String value) {
077:                if (trace.debug()) {
078:                    trace.debugCode(className + " " + PREFIX[type] + id + " = "
079:                            + getTraceObjectName() + "." + value + ";");
080:                }
081:            }
082:
083:            protected void debugCodeCall(String text) {
084:                if (trace.debug()) {
085:                    trace.debugCode(getTraceObjectName() + "." + text + "();");
086:                }
087:            }
088:
089:            protected void debugCodeCall(String text, long param) {
090:                if (trace.debug()) {
091:                    trace.debugCode(getTraceObjectName() + "." + text + "("
092:                            + param + ");");
093:                }
094:            }
095:
096:            protected void debugCodeCall(String text, String param) {
097:                if (trace.debug()) {
098:                    trace.debugCode(getTraceObjectName() + "." + text + "("
099:                            + quote(param) + ");");
100:                }
101:            }
102:
103:            protected void debugCode(String text) {
104:                if (trace.debug()) {
105:                    trace.debugCode(getTraceObjectName() + "." + text);
106:                }
107:            }
108:
109:            protected String quote(String s) {
110:                return StringUtils.quoteJavaString(s);
111:            }
112:
113:            protected String quoteTime(java.sql.Time x) {
114:                if (x == null) {
115:                    return "null";
116:                }
117:                return "Time.valueOf(\"" + x.toString() + "\")";
118:            }
119:
120:            protected String quoteTimestamp(java.sql.Timestamp x) {
121:                if (x == null) {
122:                    return "null";
123:                }
124:                return "Timestamp.valueOf(\"" + x.toString() + "\")";
125:            }
126:
127:            protected String quoteDate(java.sql.Date x) {
128:                if (x == null) {
129:                    return "null";
130:                }
131:                return "Date.valueOf(\"" + x.toString() + "\")";
132:            }
133:
134:            protected String quoteBigDecimal(BigDecimal x) {
135:                if (x == null) {
136:                    return "null";
137:                }
138:                return "new BigDecimal(\"" + x.toString() + "\")";
139:            }
140:
141:            protected String quoteBytes(byte[] x) {
142:                if (x == null) {
143:                    return "null";
144:                }
145:                return "org.h2.util.ByteUtils.convertStringToBytes(\""
146:                        + ByteUtils.convertBytesToString(x) + "\")";
147:            }
148:
149:            protected String quoteArray(String[] s) {
150:                return StringUtils.quoteJavaStringArray(s);
151:            }
152:
153:            protected String quoteIntArray(int[] s) {
154:                return StringUtils.quoteJavaIntArray(s);
155:            }
156:
157:            protected String quoteMap(Map map) {
158:                if (map == null) {
159:                    return "null";
160:                }
161:                if (map.size() == 0) {
162:                    return "new Map()";
163:                }
164:                StringBuffer buff = new StringBuffer("new Map() /* ");
165:                try {
166:                    // Map<String, Class>
167:                    for (Iterator it = map.entrySet().iterator(); it.hasNext();) {
168:                        Map.Entry entry = (Map.Entry) it.next();
169:                        String key = (String) entry.getKey();
170:                        buff.append(key);
171:                        buff.append(':');
172:                        Class clazz = (Class) entry.getValue();
173:                        buff.append(clazz.getName());
174:                    }
175:                } catch (Exception e) {
176:                    buff.append(e.toString() + ": " + map.toString());
177:                }
178:                buff.append("*/");
179:                return buff.toString();
180:            }
181:
182:            protected SQLException logAndConvert(Throwable e) {
183:                if (SysProperties.LOG_ALL_ERRORS) {
184:                    synchronized (TraceObject.class) {
185:                        // e.printStackTrace();
186:                        try {
187:                            Writer writer = FileUtils.openFileWriter(
188:                                    SysProperties.LOG_ALL_ERRORS_FILE, true);
189:                            PrintWriter p = new PrintWriter(writer);
190:                            e.printStackTrace(p);
191:                            p.close();
192:                            writer.close();
193:                        } catch (Exception e2) {
194:                            e2.printStackTrace();
195:                        }
196:                    }
197:                }
198:                if (trace == null) {
199:                    TraceSystem.traceThrowable(e);
200:                } else {
201:                    if (e instanceof  SQLException) {
202:                        trace.error("SQLException", e);
203:                        return (SQLException) e;
204:                    } else {
205:                        trace.error("Uncaught Exception", e);
206:                    }
207:                }
208:                return Message.convert(e);
209:            }
210:
211:            /**
212:             * INTERNAL
213:             */
214:            public static String toString(String sql, ObjectArray params) {
215:                StringBuffer buff = new StringBuffer(sql);
216:                if (params != null && params.size() > 0) {
217:                    buff.append(" {");
218:                    for (int i = 0; i < params.size(); i++) {
219:                        try {
220:                            ParameterInterface p = (ParameterInterface) params
221:                                    .get(i);
222:                            String s = p.getParamValue().getSQL();
223:                            if (i > 0) {
224:                                buff.append(", ");
225:                            }
226:                            buff.append(i + 1);
227:                            buff.append(": ");
228:                            buff.append(s);
229:                        } catch (SQLException e) {
230:                            buff.append("/* ");
231:                            buff.append(i + 1);
232:                            buff.append(": ");
233:                            buff.append(e.toString());
234:                            buff.append("*/ ");
235:                        }
236:                    }
237:                    buff.append("};");
238:                }
239:                return buff.toString();
240:
241:            }
242:
243:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.