Source Code Cross Referenced for ConvertTraceFile.java in  » Database-DBMS » h2database » org » h2 » tools » 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.tools 
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.tools;
007:
008:        import java.io.IOException;
009:        import java.io.LineNumberReader;
010:        import java.io.PrintWriter;
011:        import java.sql.SQLException;
012:
013:        import org.h2.message.Message;
014:        import org.h2.util.FileUtils;
015:        import org.h2.util.IOUtils;
016:
017:        /**
018:         * Convert a trace file to a java class.
019:         * This is required because the find command truncates lines.
020:         */
021:        public class ConvertTraceFile {
022:
023:            private void showUsage() {
024:                System.out
025:                        .println("java "
026:                                + getClass().getName()
027:                                + " [-traceFile <trace file name>] [-javaClass <java class name>] [-script <sql script file>]");
028:                System.out
029:                        .println("See also http://h2database.com/javadoc/org/h2/tools/ConvertTraceFile.html");
030:            }
031:
032:            /**
033:             * The command line interface for this tool. The options must be split into
034:             * strings like this: "-traceFile", "test.trace.db",... Options are case
035:             * sensitive. The following options are supported:
036:             * <ul>
037:             * <li>-help or -? (print the list of options) </li>
038:             * <li>-traceFile filename (the default is test.trace.db) </li>
039:             * <li>-script filename (the default is test.sql) </li>
040:             * <li>-javaClass className (the default is Test) </li>
041:             * </ul>
042:             * 
043:             * @param args the command line arguments
044:             * @throws Exception
045:             */
046:            public static void main(String[] args) throws SQLException {
047:                new ConvertTraceFile().run(args);
048:            }
049:
050:            private void run(String[] args) throws SQLException {
051:                String traceFile = "test.trace.db";
052:                String javaClass = "Test";
053:                String script = "test.sql";
054:                for (int i = 0; args != null && i < args.length; i++) {
055:                    if (args[i].equals("-traceFile")) {
056:                        traceFile = args[++i];
057:                    } else if (args[i].equals("-javaClass")) {
058:                        javaClass = args[++i];
059:                    } else if (args[i].equals("-script")) {
060:                        script = args[++i];
061:                    } else {
062:                        showUsage();
063:                        return;
064:                    }
065:                }
066:                try {
067:                    convertFile(traceFile, javaClass, script);
068:                } catch (IOException e) {
069:                    throw Message.convertIOException(e, traceFile);
070:                }
071:            }
072:
073:            /**
074:             * Converts a trace file to a Java class file and a script file.
075:             *
076:             * @param traceFileName
077:             * @param javaClassName
078:             * @throws IOException
079:             */
080:            private void convertFile(String traceFileName,
081:                    String javaClassName, String script) throws IOException,
082:                    SQLException {
083:                LineNumberReader reader = new LineNumberReader(
084:                        IOUtils.getReader(FileUtils
085:                                .openFileInputStream(traceFileName)));
086:                PrintWriter javaWriter = new PrintWriter(FileUtils
087:                        .openFileWriter(javaClassName + ".java", false));
088:                PrintWriter scriptWriter = new PrintWriter(FileUtils
089:                        .openFileWriter(script, false));
090:                javaWriter.println("import java.io.*;");
091:                javaWriter.println("import java.sql.*;");
092:                javaWriter.println("import java.math.*;");
093:                javaWriter.println("import java.util.Calendar;");
094:                javaWriter.println("public class " + javaClassName + " {");
095:                javaWriter
096:                        .println("    public static void main(String[] args) throws Exception {");
097:                javaWriter.println("        Class.forName(\"org.h2.Driver\");");
098:                while (true) {
099:                    String line = reader.readLine();
100:                    if (line == null) {
101:                        break;
102:                    }
103:                    if (line.startsWith("/**/")) {
104:                        line = "        " + line.substring(4);
105:                        javaWriter.println(line);
106:                    } else if (line.startsWith("/*SQL*/")) {
107:                        line = line.substring("/*SQL*/".length());
108:                        scriptWriter.println(line);
109:                    }
110:                }
111:                javaWriter.println("    }");
112:                javaWriter.println("}");
113:                reader.close();
114:                javaWriter.close();
115:                scriptWriter.close();
116:            }
117:
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.