Source Code Cross Referenced for Player.java in  » Database-DBMS » h2database » org » h2 » test » trace » 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.test.trace 
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:         * (license2)
004:         */
005:        /*
006:         * Licensed to the Apache Software Foundation (ASF) under one or more
007:         * contributor license agreements.  See the NOTICE file distributed with
008:         * this work for additional information regarding copyright ownership.
009:         * The ASF licenses this file to You under the Apache License, Version 2.0
010:         * (the "License"); you may not use this file except in compliance with
011:         * the License.  You may obtain a copy of the License at
012:         *
013:         *      http://www.apache.org/licenses/LICENSE-2.0
014:         *
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:        package org.h2.test.trace;
022:
023:        import java.io.BufferedReader;
024:        import java.io.FileReader;
025:        import java.io.IOException;
026:        import java.io.LineNumberReader;
027:        import java.util.HashMap;
028:
029:        /**
030:         * This tool can re-run Java style log files. There is no size limit.
031:         */
032:        public class Player {
033:
034:            // TODO support InputStream;
035:            // TODO support Reader;
036:            // TODO support int[];
037:            // TODO support Blob and Clob;
038:            // TODO support Calendar
039:            // TODO support Object
040:            // TODO support Object[]
041:            // TODO support URL
042:            // TODO support Array
043:            // TODO support Ref
044:            // TODO support SQLInput, SQLOutput
045:            // TODO support Properties
046:            // TODO support Map
047:            // TODO support SQLXML
048:
049:            private boolean log;
050:            private static final String[] IMPORTED_PACKAGES = { "",
051:                    "java.lang.", "java.sql.", "javax.sql." };
052:            private HashMap objects = new HashMap();
053:
054:            /**
055:             * Execute a trace file using the command line. The log file name to execute
056:             * (replayed) must be specified as the last parameter. The following
057:             * optional command line parameters are supported:
058:             * <ul>
059:             * <li><code>-log</code> to enable logging the executed statement to
060:             * System.out
061:             * </ul>
062:             * 
063:             * @param args the arguments of the application
064:             */
065:            public static void main(String[] args) throws Exception {
066:                new Player().run(args);
067:            }
068:
069:            /**
070:             * Execute a trace file.
071:             * 
072:             * @param fileName
073:             * @param log print debug information
074:             * @param checkResult if the result of each method should be compared
075:             *            against the result in the file
076:             */
077:            public static void execute(String fileName, boolean log,
078:                    boolean checkResult) throws IOException {
079:                new Player().runFile(fileName, log);
080:            }
081:
082:            private void run(String[] args) throws IOException {
083:                String fileName = "test.log.db";
084:                try {
085:                    fileName = args[args.length - 1];
086:                    for (int i = 0; i < args.length - 1; i++) {
087:                        if ("-log".equals(args[i])) {
088:                            log = true;
089:                        } else {
090:                            throw new Error("Unknown setting: " + args[i]);
091:                        }
092:                    }
093:                } catch (Exception e) {
094:                    e.printStackTrace();
095:                    System.out.println("Usage: java " + getClass().getName()
096:                            + " [-log] <fileName>");
097:                    return;
098:                }
099:                runFile(fileName, log);
100:            }
101:
102:            private void runFile(String fileName, boolean log)
103:                    throws IOException {
104:                this .log = log;
105:                LineNumberReader reader = new LineNumberReader(
106:                        new BufferedReader(new FileReader(fileName)));
107:                while (true) {
108:                    String line = reader.readLine();
109:                    if (line == null) {
110:                        break;
111:                    }
112:                    runLine(line.trim());
113:                }
114:            }
115:
116:            void log(String s) {
117:                if (log) {
118:                    System.out.println(s);
119:                }
120:            }
121:
122:            private void runLine(String line) {
123:                if (!line.startsWith("/**/")) {
124:                    return;
125:                }
126:                line = line.substring("/**/".length()) + ";";
127:                Statement s = Parser.parseStatement(this , line);
128:                log("> " + s.toString());
129:                try {
130:                    s.execute();
131:                } catch (Exception e) {
132:                    e.printStackTrace();
133:                    log("error: " + e.toString());
134:                }
135:            }
136:
137:            static Class getClass(String className) {
138:                for (int i = 0; i < IMPORTED_PACKAGES.length; i++) {
139:                    try {
140:                        return Class.forName(IMPORTED_PACKAGES[i] + className);
141:                    } catch (ClassNotFoundException e) {
142:                    }
143:                }
144:                throw new Error("Class not found: " + className);
145:            }
146:
147:            void assign(String objectName, Object obj) {
148:                objects.put(objectName, obj);
149:            }
150:
151:            Object getObject(String name) {
152:                return objects.get(name);
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.