Source Code Cross Referenced for ScriptReader.java in  » Database-DBMS » h2database » org » h2 » util » 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.util 
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.util;
007:
008:        import java.io.IOException;
009:        import java.io.Reader;
010:        import java.sql.SQLException;
011:
012:        import org.h2.message.Message;
013:
014:        /**
015:         * This class can split SQL scripts to single SQL statements.
016:         * Each SQL statement ends with the character ';', however it is ignored
017:         * in comments and quotes.
018:         */
019:        public class ScriptReader {
020:            private Reader reader;
021:            private boolean end;
022:            private boolean insideRemark;
023:            private boolean blockRemark;
024:            private boolean skipRemarks;
025:
026:            public ScriptReader(Reader reader) {
027:                this .reader = reader;
028:            }
029:
030:            public void close() throws SQLException {
031:                try {
032:                    reader.close();
033:                } catch (IOException e) {
034:                    throw Message.convertIOException(e, null);
035:                }
036:            }
037:
038:            private int read() throws SQLException {
039:                try {
040:                    return reader.read();
041:                } catch (IOException e) {
042:                    throw Message.convertIOException(e, null);
043:                }
044:            }
045:
046:            public String readStatement() throws SQLException {
047:                if (end) {
048:                    return null;
049:                }
050:                StringBuffer buff = new StringBuffer(200);
051:                int c = read();
052:                while (true) {
053:                    if (c < 0) {
054:                        end = true;
055:                        return buff.length() == 0 ? null : buff.toString();
056:                    } else if (c == ';') {
057:                        break;
058:                    }
059:                    switch (c) {
060:                    case '\'':
061:                        buff.append((char) c);
062:                        while (true) {
063:                            c = read();
064:                            if (c < 0) {
065:                                break;
066:                            }
067:                            buff.append((char) c);
068:                            if (c == '\'') {
069:                                break;
070:                            }
071:                        }
072:                        c = read();
073:                        break;
074:                    case '"':
075:                        buff.append((char) c);
076:                        while (true) {
077:                            c = read();
078:                            if (c < 0) {
079:                                break;
080:                            }
081:                            buff.append((char) c);
082:                            if (c == '\"') {
083:                                break;
084:                            }
085:                        }
086:                        c = read();
087:                        break;
088:                    case '/': {
089:                        int last = c;
090:                        c = read();
091:                        if (c == '*') {
092:                            // block comment
093:                            insideRemark = true;
094:                            blockRemark = true;
095:                            if (!skipRemarks) {
096:                                buff.append((char) last);
097:                                buff.append((char) c);
098:                            }
099:                            while (true) {
100:                                c = read();
101:                                if (c < 0) {
102:                                    break;
103:                                }
104:                                if (!skipRemarks) {
105:                                    buff.append((char) c);
106:                                }
107:                                if (c == '*') {
108:                                    c = read();
109:                                    if (c < 0) {
110:                                        break;
111:                                    }
112:                                    if (!skipRemarks) {
113:                                        buff.append((char) c);
114:                                    }
115:                                    if (c == '/') {
116:                                        insideRemark = false;
117:                                        break;
118:                                    }
119:                                }
120:                            }
121:                            c = read();
122:                        } else if (c == '/') {
123:                            // single line comment
124:                            insideRemark = true;
125:                            blockRemark = false;
126:                            if (!skipRemarks) {
127:                                buff.append((char) last);
128:                                buff.append((char) c);
129:                            }
130:                            while (true) {
131:                                c = read();
132:                                if (c < 0) {
133:                                    break;
134:                                }
135:                                if (!skipRemarks) {
136:                                    buff.append((char) c);
137:                                }
138:                                if (c == '\r' || c == '\n') {
139:                                    insideRemark = false;
140:                                    break;
141:                                }
142:                            }
143:                            c = read();
144:                        } else {
145:                            buff.append((char) last);
146:                        }
147:                        break;
148:                    }
149:                    case '-': {
150:                        int last = c;
151:                        c = read();
152:                        if (c == '-') {
153:                            // single line comment
154:                            insideRemark = true;
155:                            blockRemark = false;
156:                            if (!skipRemarks) {
157:                                buff.append((char) last);
158:                                buff.append((char) c);
159:                            }
160:                            while (true) {
161:                                c = read();
162:                                if (c < 0) {
163:                                    break;
164:                                }
165:                                if (!skipRemarks) {
166:                                    buff.append((char) c);
167:                                }
168:                                if (c == '\r' || c == '\n') {
169:                                    insideRemark = false;
170:                                    break;
171:                                }
172:                            }
173:                            c = read();
174:                        } else {
175:                            buff.append((char) last);
176:                        }
177:                        break;
178:                    }
179:                    default:
180:                        buff.append((char) c);
181:                        c = read();
182:                    }
183:                }
184:                return buff.toString();
185:            }
186:
187:            public boolean isInsideRemark() {
188:                return insideRemark;
189:            }
190:
191:            public boolean isBlockRemark() {
192:                return blockRemark;
193:            }
194:
195:            public void setSkipRemarks(boolean skipRemarks) {
196:                this.skipRemarks = skipRemarks;
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.