public String evaluate(String sql, String dbType) { List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType); SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType); for (SQLStatement stmt : statementList) { stmt.accept(visitor); } StringBuffer buf = new StringBuffer(); for (TableStat.Column column : visitor.getColumns()) { if (buf.length() != 0) { buf.append(','); } buf.append(column.toString()); } return buf.toString(); }
private String getSqlStat(Integer id) { Map<String, Object> map = statManagerFacade.getSqlStatData(id); if (map == null) { return returnJSONResult(RESULT_CODE_ERROR, null); } String dbType = (String) map.get("DbType"); String sql = (String) map.get("SQL"); map.put("formattedSql", SQLUtils.format(sql, dbType)); List<SQLStatement> statementList = SQLUtils.parseStatements(sql, dbType); if (!statementList.isEmpty()) { SQLStatement sqlStmt = statementList.get(0); SchemaStatVisitor visitor = SQLUtils.createSchemaStatVisitor(dbType); sqlStmt.accept(visitor); map.put("parsedTable", visitor.getTables().toString()); map.put("parsedFields", visitor.getColumns().toString()); map.put("parsedConditions", visitor.getConditions().toString()); map.put("parsedRelationships", visitor.getRelationships().toString()); map.put("parsedOrderbycolumns", visitor.getOrderByColumns().toString()); } DateFormat format = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS"); Date maxTimespanOccurTime = (Date) map.get("MaxTimespanOccurTime"); if (maxTimespanOccurTime != null) { map.put("MaxTimespanOccurTime", format.format(maxTimespanOccurTime)); } return returnJSONResult(map == null ? RESULT_CODE_ERROR : RESULT_CODE_SUCCESS, map); }