Skip to content

Commit 56fe655

Browse files
committed
added more tool functions to new tool class CCJSqlParserUtil
1 parent 71daa4c commit 56fe655

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (C) 2013 JSQLParser.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package net.sf.jsqlparser.parser;
20+
21+
import java.io.InputStream;
22+
import java.io.Reader;
23+
import java.io.StringReader;
24+
import net.sf.jsqlparser.JSQLParserException;
25+
import net.sf.jsqlparser.statement.Statement;
26+
27+
/**
28+
* Toolfunctions to start and use JSqlParser.
29+
* @author toben
30+
*/
31+
public class CCJSqlParserUtil {
32+
public static Statement parse(Reader statementReader) throws JSQLParserException {
33+
CCJSqlParser parser = new CCJSqlParser(statementReader);
34+
try {
35+
return parser.Statement();
36+
} catch (Throwable e) {
37+
throw new JSQLParserException(e);
38+
}
39+
}
40+
41+
public static Statement parse(String sql) throws JSQLParserException {
42+
CCJSqlParser parser = new CCJSqlParser(new StringReader(sql));
43+
try {
44+
return parser.Statement();
45+
} catch (Throwable e) {
46+
throw new JSQLParserException(e);
47+
}
48+
}
49+
50+
public static Statement parse(InputStream is) throws JSQLParserException {
51+
CCJSqlParser parser = new CCJSqlParser(is);
52+
try {
53+
return parser.Statement();
54+
} catch (Throwable e) {
55+
throw new JSQLParserException(e);
56+
}
57+
}
58+
59+
public static Statement parse(InputStream is, String encoding) throws JSQLParserException {
60+
CCJSqlParser parser = new CCJSqlParser(is,encoding);
61+
try {
62+
return parser.Statement();
63+
} catch (Throwable e) {
64+
throw new JSQLParserException(e);
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)