Example #1
0
  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);
  }
Example #2
0
 public void test_0() throws Exception {
   String text = "CREATE TABLE customer (a INT, b CHAR (20), INDEX (a));";
   Assert.assertEquals(
       "CREATE TABLE customer (\n"
           + //
           "\ta INT, \n"
           + //
           "\tb CHAR(20), \n"
           + //
           "\tINDEX(a)\n"
           + //
           ");",
       SQLUtils.format(text, JdbcUtils.MYSQL));
 }