use of net.sf.jsqlparser.parser.CCJSqlParserManager in project JSqlParser by JSQLParser.
the class MemoryTest method main.
public static void main(String[] args) throws Exception {
System.gc();
System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
CCJSqlParserManager parserManager = new CCJSqlParserManager();
/*
* String longQuery = new String(
* "select * from ( SELECT intermediate.id as id , intermediate.date as " +
* "date FROM ( SELECT DISTINCT ( id ) FROM ( SELECT " +
* "wct_workflows.workflow_id as id , wct_transaction.date as date FROM " +
* "wct_audit_entry , wct_transaction , wct_workflows WHERE " +
* "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " +
* "'C' ) and wct_audit_entry.outcome = 't' and " +
* "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " +
* "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " +
* "wct_workflows.active_version_id ))) UNION SELECT wct_workflows.workflow_id as " +
* "id , wct_transaction.date as date FROM wct_audit_entry , " +
* "wct_transaction , wct_workflows WHERE ( wct_audit_entry.privilege = " +
* "'W' or wct_audit_entry.privilege = 'C' ) and wct_audit_entry.outcome " +
* "= 't' and wct_audit_entry.transaction_id = " +
* "wct_transaction.transaction_id and wct_transaction.user_id = 164 and " +
* "afdf= ( select wct_audit_entry.object_id from wct_audit_entry , " +
* "wct_workflow_archive where wct_audit_entry.object_id = " +
* "wct_workflow_archive.archive_id and wct_workflows.workflow_id = " +
* "wct_workflow_archive.workflow_id ) " +
* "UNION SELECT wct_workflows.workflow_id " +
* "as id , wct_transaction.date as date FROM wct_audit_entry , " +
* "wct_transaction , wct_workflows WHERE ( wct_audit_entry.privilege = " +
* "'W' OR wct_audit_entry.privilege = 'E' OR wct_audit_entry.privilege = " +
* "'A' ) and wct_audit_entry.outcome = 't' and " +
* "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " +
* "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " +
* "wct_workflows.workflow_id UNION SELECT * FROM interm2 , wct_workflow_docs WHERE " +
* "interm2.id = wct_workflow_docs.document_id ORDER BY id , date DESC ");
*/
String longQuery = "select * from k where ID > 4";
/*
* String longQuery = "select * from ( SELECT intermediate.id as id , intermediate.date as "
* + "date FROM ( SELECT DISTINCT ( id ) FROM ( SELECT " +
* "wct_workflows.workflow_id as id , wct_transaction.date as date FROM " +
* "wct_audit_entry , wct_transaction , wct_workflows WHERE " +
* "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " + "'C' ))))";
*/
/*
* String longQuery = "select * from d WHERE " +
* "( wct_audit_entry.privilege = 'W' or wct_audit_entry.privilege = " +
* "'C' ) and wct_audit_entry.outcome = 't' and " +
* "wct_audit_entry.transaction_id = wct_transaction.transaction_id and " +
* "wct_transaction.user_id = 164 and wct_audit_entry.object_id = " +
* "wct_workflows.active_version_id ";
*/
StringReader stringReader = new StringReader(longQuery);
Statement statement = parserManager.parse(stringReader);
// stringReader = new StringReader(longQuery);
// Statement statement2 = parserManager.parse(stringReader);
// stringReader = null;
// statement2 = null;
statement = null;
parserManager = null;
longQuery = null;
System.gc();
System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
}
use of net.sf.jsqlparser.parser.CCJSqlParserManager in project InformationSystem by ObeoNetwork.
the class ViewContentProvider method parseViewQuery.
/**
* Parse the query to find tables and columns used for the view.
* @param query
*/
public void parseViewQuery(String query) {
Statement statement;
CCJSqlParserManager pm = new CCJSqlParserManager();
try {
statement = pm.parse(new StringReader(query));
if (statement instanceof Select) {
Select selectStatement = (Select) statement;
ViewContentFinder viewContentFinder = new ViewContentFinder();
viewContentFinder.parseView(selectStatement);
for (Table table : viewContentFinder.getTables()) {
tables.add(table.getName());
}
columns = viewContentFinder.getColumns();
}
} catch (JSQLParserException e) {
// nothing to do
}
}
use of net.sf.jsqlparser.parser.CCJSqlParserManager in project yyl_example by Relucent.
the class JsqlparserExample method main.
public static void main(String[] args) throws Exception {
String sql = //
"update demo_table t1 set " + //
" column1 = '1' " + //
" ,column2 = '1' " + //
" ,column3 = '2' " + //
" ,column4 = '3' " + " where id=0";
CCJSqlParserManager pm = new CCJSqlParserManager();
Statement statement = pm.parse(new StringReader(sql));
if (statement instanceof Update) {
Update updateStatement = (Update) statement;
System.out.println(updateStatement.getTable());
Expression where = updateStatement.getWhere();
if (where instanceof BinaryExpression) {
BinaryExpression expression = (BinaryExpression) where;
System.out.println(expression.getLeftExpression());
System.out.println(expression.getStringExpression());
System.out.println(expression.getRightExpression());
}
}
}
use of net.sf.jsqlparser.parser.CCJSqlParserManager in project JSqlParser by JSQLParser.
the class CCJSqlParserManagerTest method testParse.
@Test
public void testParse() throws Exception {
CCJSqlParserManager parserManager = new CCJSqlParserManager();
BufferedReader in = new BufferedReader(new InputStreamReader(CreateTableTest.class.getResourceAsStream("/simple_parsing.txt")));
String statement = "";
while (true) {
try {
statement = CCJSqlParserManagerTest.getStatement(in);
if (statement == null) {
break;
}
parserManager.parse(new StringReader(statement));
} catch (JSQLParserException e) {
throw new TestException("impossible to parse statement: " + statement, e);
}
}
}
Aggregations